This repository has been archived by the owner on Feb 20, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
check_mail.php
204 lines (185 loc) · 7.18 KB
/
check_mail.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
<?php
/*
* \brief Check and show/edit email account data
*
* \author Quentin Comte-Gaz <quentin@comte-gaz.com>
* \date 18 July 2016
* \license MIT License (contact me if too restrictive)
* \copyright Copyright (c) 2016 Quentin Comte-Gaz
* \version 1.0
*/
?>
<?php
require_once(dirname(__FILE__).'/config.php');
require_once(dirname(__FILE__).'/imap_utility.php');
require_once(dirname(__FILE__).'/ovh_utility.php');
$errors = array();
$passwordmail = '';
$email_name = '';
$email = '';
$need_login = true;
$success = '';
if (!empty($_POST) && isset($_POST['passwordmail']) && isset($_POST['email']) && isset($_POST['domain'])) {
$passwordmail = htmlentities($_POST['passwordmail']) ;
$email_name = htmlentities($_POST['email']);
$domain = htmlentities($_POST['domain']);
}
$email = $email_name .'@'. $domain;
if ($imap_server != "" && $email_name != "" && $domain != "" && $passwordmail != "") {
if (!canLoginEmailAccount($imap_server, $email, $passwordmail)) {
$need_login = true;
if (!empty($_POST)) {
$errors[] = "Impossible to connect, please try again";
}
} else {
$need_login = false;
// Filter data
foreach ($_REQUEST as $key => $val) {
$val = preg_replace("/[\'\"\\\?\~]/i",'', $val);
$_REQUEST[$key] = $val;
}
$newpass = '';
$newpass2 = '';
if (isset($_POST['newpass'])) {
$newpass = htmlentities($_POST["newpass"]);
}
if (isset($_POST['newpass2'])) {
$newpass2 = htmlentities($_POST["newpass2"]);
}
if (strlen($newpass) >= 8 && strlen($newpass) <= 12 && $newpass == $newpass2 && htmlentities($_POST["newpass"])==$newpass) {
// Check new password is valid for OVH API use and send password change request to OVH server
$password_changed = changeEmailAccountPassword($api, $domain, $email_name, $newpass);
if (!$password_changed) {
$errors[] = "Error : Can't change the password, try again later";
} else {
$success = "<span style=\"color:green\">Your ".$email." password is updated. It will be taken into account in less than five minutes.</span>";
}
} elseif (strlen($newpass) > 0 && $newpass != $newpass2) {
$errors[] = "Both passwords are not the same.";
} elseif (strlen($newpass) > 0 && (strlen($newpass) < 8 || strlen($newpass) > 12)) {
$errors[] = "Password must have between 8 and 12 characters.";
} elseif (isset($_POST['newpass'])) {
if (htmlentities($_POST["newpass"])!=$newpass) {
$errors[] = "The password contains at least one invalid character from this list: <ul><li>'</li><li>\"</li><li>\\</li><li>?</li><li>~</li></ul>";
}
}
}
}
?>
<div id="login-form">
<div class="boxcontent">
<?php
if ($need_login) {
//---------NOT LOGGED IN-----------
?>
<h1>Manage your email account</h1>
Please connect to check or configure your email account:<br/>
<?php
// Show login errors
if (!empty($errors)) {
$error_text = '<span style="color:red">Identification error:<br/><ul class="error-list">';
foreach($errors as $err) {
$error_text .= '<li>'.$err.'</li>';
}
$error_text .= '</ul></span>';
echo $error_text;
}
?>
<form name="form" action="index.php" method="post">
<table summary="" border="0">
<tbody>
<tr>
<td class="title"><label for="email">Email address</label></td>
<td>
<input name="email" id="email" type="text" />@
<select name="domain" id="domain" onchange="this.form.submit()">
<?php foreach ($domains as $d) { ?>
<option value=<?php echo $d; ?> <?php if ($domain==$d) echo "selected"; ?> ><?php echo $d; ?>
<?php } ?>
</select>
</td>
</tr>
<tr>
<td class="title"><label for="password">Password</label></td>
<td><input type="password" name="passwordmail" id="password" /></td>
</tr>
</tbody>
</table>
<p style="text-align:center;"><input type="submit" class="medium blue button" value="Login" /></p>
</form>
<?php
} else {
// ----------LOGGED IN-------------
echo "<h1>Manage your ".$email." email account</h1>";
try {
// Retrieve data from the account
$account_info = getEmailAccountInfo($api, $domain, $email_name);
if ($account_info['isBlocked']) {
echo '<a class="medium orange button" href="contact.php">Blocked email address, contact admin to unblock it ('.$admin_email_address.')</a>';
} else {
echo '<a class="medium green button">Your email address is not blocked</a>';
}
echo "<br/>";
$account_usage_info = getEmailAccountUsage($api, $domain, $email_name);
// Show account quota
$remaining_size = $account_info['size'] - $account_usage_info['quota'];
$percent_remaining = 100 * $remaining_size / $account_info['size'];
$color_bar = "green";
if ($percent_remaining > 40 && $percent_remaining < 60) {
$color_bar = "orange";
} elseif ($percent_remaining < 40) {
$color_bar = "red";
}
echo "<b>Mailbox usage (free space):</b>
<div class='loading win' id='progressbar1'>
<div class='text'><span>0%</span></div>
<div class='process vista".$color_bar." lightanimated'> </div>
</div>
<script>processbar('progressbar1', ".$percent_remaining.");</script>";
echo " ".number_format(($account_usage_info['quota']/1000000), 2)." MB / ".($account_info['size']/1000000)." MB used<br/>";
echo "<br/>";
echo "<b>Total emails in your mailbox:</b> ".$account_usage_info['emailCount']."<br/>";
echo "<br/>";
} catch (Exception $e) {
echo "<span style=\"color:red\">Impossible to get ".$email_name." account information: Please try later.</span><br/>";
}
// Change password
echo "<b>Change your password:</b><br/>";
if (strlen($success) > 0 && empty($errors)) {
echo "<br/>".$success."<br/><br/>";
}
if (!empty($errors)) {
$error_text = '<br/><span style="color:red">Impossible to change the password:<br/><ul class="error-list">';
foreach($errors as $err) {
$error_text .= '<li>'.$err.'</li>';
}
$error_text .= '</ul></span>';
echo $error_text;
}
?>
<form name="form "action="index.php" method="post">
<input type="hidden" name="passwordmail" value="<?php echo $passwordmail; ?>">
<input type="hidden" name="email" value="<?php echo $email_name; ?>">
<input type="hidden" name="domain" value="<?php echo $domain; ?>">
<table summary="" border="0">
<tbody>
<tr>
<td class="title"><label for="newpass">New password</label></td>
<td><input pattern=".{8,12}" name="newpass" id="newpass" type="password" /></td>
</tr>
<tr>
<td class="title"><label for="newpass2">Confirm new password</label></td>
<td><input pattern=".{8,12}" name="newpass2" id="newpass2" type="password" /></td>
</tr>
</tbody>
</table>
<p style="text-align:center;"><input type="submit" class="medium blue button" value="Send" /></p>
</form>
<form name="form "action="index.php" method="post">
<input type="submit" class="medium blue button" value="Quit session" />
</form>
<?php
}
?>
</div>
</div>