forked from web-cyradm/web-cyradm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmanageaccount.php
374 lines (340 loc) · 10.7 KB
/
manageaccount.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
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
<?php
if (!defined('WC_BASE')) define('WC_BASE', dirname(__FILE__));
$ref=WC_BASE."/index.php";
if ($ref!=$_SERVER['SCRIPT_FILENAME']){
header("Location: index.php");
exit();
}
?>
<!-- #################### manageaccount.php start #################### -->
<tr>
<td width="10"> </td>
<td valign="top">
<?php
if ($authorized) {
$cyr_conn = new cyradm;
$error = $cyr_conn->imap_login();
if ($error != 0) {
die ("Error: " . $error);
}
if (empty($_POST['confirmed'])) {
$imap_checked="";
$pop_checked="";
$sieve_checked="";
$smtpauth_checked="";
$smtp_checked="";
$_sep = '.';
if ($DOMAIN_AS_PREFIX) {
$_sep = '/';
}
$q = $cyr_conn->getquota("user" . $_sep . $_GET['username']);
$query = "SELECT * FROM accountuser WHERE username ='".$_GET['username']."'";
$result = $handle->query($query);
if (DB::isError($result)) {
die (_("Database error"));
}
$cnt = $result->numRows($result);
if ($cnt) {
$row = $result->fetchRow(DB_FETCHMODE_ASSOC, 0);
if ($row['imap']) {
$imap_checked="checked";
}
if ($row['pop']) {
$pop_checked="checked";
}
if ($row['sieve']) {
$sieve_checked="checked";
}
if ($row['smtpauth']) {
$smtpauth_checked="checked";
}
}
$query = "SELECT status FROM virtual WHERE username ='".$_GET['username']."' LIMIT 1";
$result = $handle->query($query);
if (DB::isError($result)) {
die (_("Database error"));
}
$cnt = $result->numRows($result);
if ($cnt) {
$row = $result->fetchRow(DB_FETCHMODE_ASSOC, 0);
if ($row['status']) {
$smtp_checked="checked";
}
}
?>
<form action="index.php" method="POST">
<input type="hidden" name="action" value="manageaccount">
<input type="hidden" name="confirmed" value="true">
<input type="hidden" name="domain" value="<?php echo $_GET['domain'];?>">
<input type="hidden" name="username" value="<?php echo $_GET['username'];?>">
<!--
<h3>
<?php print _("Additional information for account");?>
<span style="color: red;">
<?php echo $_GET['username'];?>
</span>
</h3>
<table>
<tr>
<td width="150">
<?php print _("First name");?>:
</td>
<td>
<input class="inputfield" type="password" size="30" name="firstname" readonly>
</td>
</tr>
<tr>
<td width="150">
<?php print _("Last name");?>:
</td>
<td>
<input class="inputfield" type="password" size="30" name="lastname" readonly>
</td>
</tr>
</table>
-->
<h3>
<?php print _("Change password for account");?>
<span style="color: red;">
<?php echo $_GET['username'];?>
</span>
</h3>
<table>
<tr>
<td width="150">
<?php print _("New password");?>:
</td>
<td>
<input class="inputfield" type="password" size="30" name="new_password">
</td>
</tr>
<tr>
<td width="150">
<?php print _("Confirm new password")?>:
</td>
<td>
<input class="inputfield" type="password" size="30" name="confirm_password">
</td>
</tr>
</table>
<h3>
<?php print _("Setting individual Quota for user");?>:
<span style="color: red;">
<?php echo $_GET['username'];?>
</span>
</h3>
<table>
<tr>
<td width="150">
<?php print _("Quota")?>:
</td>
<td>
<input class="inputfield" type="text" size="10" name="quota" value="<?php print $q_total = $q['qmax']; ?>" > Kbytes
</td>
</tr>
</table>
<h3>
<?php print _("Edit services for user");?>
<span style="color: red;">
<?php echo $username;?>
</span>
</h3>
<table>
<tr>
<th><?php print _("Service");?></th>
<th><?php print _("Status");?></th>
</tr>
<tr>
<td><?php print _("Fetch mail via IMAP client");?></td>
<td><input name="imap" value="1" type="checkbox" <?php print $imap_checked?>></td>
</tr>
<tr>
<td><?php print _("Fetch mail via POP client");?></td>
<td><input name="pop" value="1" type="checkbox" <?php print $pop_checked?>></td>
</tr>
<tr>
<td><?php print _("Set vacation message and filter rules with sieve");?></td>
<td><input name="sieve" value="1" type="checkbox" <?php print $sieve_checked; ?>></td>
</tr>
<tr>
<td><?php print _("Send E-Mails via smtp authentication");?></td>
<td><input name="smtpauth" value="1" type="checkbox" <?php print $smtpauth_checked; ?>></td>
</tr>
<tr>
<td><?php print _("Receive E-Mails via smtp");?></td>
<td><input name="smtp" value="1" type="checkbox" <?php print $smtp_checked; ?>></td>
</tr>
<tr>
<td height="10"> </td>
</tr>
<tr>
<td colspan="2" align="center">
<input class="button" type="submit" value="<?php print _("Submit");?>">
<input class="button" type="submit" name="cancel" value="<?php print _("Cancel"); ?>">
</td>
</tr>
</table>
</form>
<?php
} elseif (!empty($_POST['cancel'])) {
$_GET['domain'] = $_POST['domain'];
include WC_BASE . "/browseaccounts.php";
} else {
// Change password
if (!empty($_POST['new_password']) && !empty($_POST['confirm_password'])) {
$query = "SELECT password FROM accountuser WHERE username='".$_POST['username']."'";
$result = $handle->query($query);
if (DB::isError($result)) {
die (_("Database error"));
}
$row = $result->fetchRow(DB_FETCHMODE_ASSOC, 0);
$password = $row['password'];
if ($PASSWORD_CHANGE_METHOD=="sql"){
$pwd = new password;
$new_password = $pwd->encrypt($_POST['new_password'], $CRYPT);
$query = "UPDATE accountuser SET password='$new_password' WHERE username='".$_POST['username']."'";
$result = $handle->query($query);
if (DB::isError($result)) {
die (_("Database error"));
} else {
print "<h3>"._("Password changed")."</h3>";
}
} elseif ($PASSWORD_CHANGE_METHOD=="poppassd") {
require WC_BASE . '/lib/poppassd.php';
$daemon = new poppassd;
if ($daemon->change_password($_POST['username'], $password, $_POST['new_password'])) {
print "<h3>"._("Password changed")."</h3>";
} else {
print $daemon->$err_str;
print "<h3>"._("Failure in changing password.")."</h3>";
}
}
}
// Change services
if (empty($_POST['imap'])) {
$_POST['imap'] = 0;
}
if (empty($_POST['pop'])) {
$_POST['pop'] = 0;
}
if (empty($_POST['sieve'])) {
$_POST['sieve'] = 0;
}
if (empty($_POST['smtpauth'])) {
$_POST['smtpauth'] = 0;
}
if (empty($_POST['smtp'])) {
$_POST['smtp'] = 0;
}
$query = "UPDATE accountuser SET imap='".$_POST['imap']."', pop='".$_POST['pop']."', sieve='".$_POST['sieve']."', smtpauth='".$_POST['smtpauth']."' WHERE username='".$_POST['username']."'";
$result1 = $handle->query($query);
$query = "UPDATE virtual SET status='".$_POST['smtp']."' WHERE username='".$_POST['username']."'";
$result2 = $handle->query($query);
if ($result1 && $result2) {
print "<h3>"._("Services successfully changed")."</h3>";
} else {
print "<h3>"._("Services NOT changed")."</h3>";
}
// Change quota
$_sep = '.';
if ($DOMAIN_AS_PREFIX) {
$_sep = '/';
}
$q = $cyr_conn->getquota("user" . $_sep . $_POST['username']);
if ($q['qmax']!=$_POST['quota']) {
$query = "SELECT prefix,domainquota FROM domain WHERE domain_name='".$_POST['domain']."'";
$result = $handle->query($query);
if (DB::isError($result)) {
die (_("Database error"));
}
$row = $result->fetchRow(DB_FETCHMODE_ASSOC, 0);
$prefix = $row['prefix'];
$domain_quota = $row['domainquota'];
// for change bigger->smaler or none->set we don't want domain quota checks
if ($domain_quota!=0 && $q['qmax']<(int)$_POST['quota'] && $q['qmax']!="NOT-SET") {
$used_domain_quota = 0;
$query = "SELECT username FROM accountuser WHERE prefix='$prefix' ORDER BY username";
$result = $handle->query($query);
if (DB::isError($result)) {
die (_("Database error"));
}
$cnt = $result->numRows($result);
for ($c = 0; $c < $cnt; $c++) {
$row = $result->fetchRow(DB_FETCHMODE_ASSOC, $c);
$user_quota = $cyr_conn->getquota("user" . $_sep . $row['username']);
if ($user_quota['qmax'] != "NOT-SET"){
$used_domain_quota += $user_quota['qmax'];
}
}
# All space - space used by all accounts + space used changed account
$quota_left = $domain_quota - $used_domain_quota + $q['qmax'];
if ($quota_left>0) {
if ($_POST['quota'] > $quota_left){
$_POST['quota'] = $quota_left;
?>
<h3>
<?php print _("Quota exeeded");?>
<span style="color: red;">
<?php print _("New quota is");?>:
</span>
<span style="font-weight: bolder;">
<?php echo $_POST['quota'];?>
</span>
</h3>
<?php
}
$cyr_conn->setmbquota("user" . $_sep . $_POST['username'], $_POST['quota']);
?>
<h3>
<?php print _("Quote for user");?>
<span style="color: red;">
<?php echo $_POST['username'];?>
</span>
<?php print _("changed to");?>
<span style="color: red;">
<?php echo $_POST['quota'];?>
</span>
</h3>
<?php
} else {
?>
<h3>
<span style="color: red;">
<?php print _("Quota exeeded");?>
<br>
<?php print _("Quota NOT changed");?>
</span>
</h3>
<?php
} // End of if ($quota_left>0)
} else { // if ($domain_quota!=0 && $q['qmax']<$_POST['quota'] && $q['qmax']!="NOT-SET")
$cyr_conn->setmbquota("user" . $_sep . $_POST['username'], $_POST['quota']);
?>
<h3>
<?php print _("Quote for user");?>
<span style="color: red;">
<?php echo $_POST['username'];?>
</span>
<?php print _("changed to");?>
<span style="color: red;">
<?php echo $_POST['quota'];?>
</span>
</h3>
<?php
} // End of if ($domain_quota!=0 && $q['qmax']<$_POST['quota'] && $q['qmax']!="NOT-SET")
}
$_GET['domain'] = $_POST['domain'];
include WC_BASE . "/browseaccounts.php";
} // End of if (empty($_POST['confirmed']))
} else {
?>
<h3>
<?php print $err_msg; ?>
</h3>
<a href="index.php?action=accounts&domain=<?php echo $_GET['domain'];?>"><?php print _("Back");?></a>
<?php
} // End of if ($authorized)
?>
</td>
</tr>
<!-- #################### editeccountnew.php end #################### -->