-
Notifications
You must be signed in to change notification settings - Fork 3
/
adminuserchangesubmit.php
186 lines (177 loc) · 6.04 KB
/
adminuserchangesubmit.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
<?php
include_once dirname(__FILE__) . '/config/variables.php';
include_once dirname(__FILE__) . '/config/authpostmaster.php';
include_once dirname(__FILE__) . '/config/functions.php';
include_once dirname(__FILE__) . '/config/httpheaders.php';
# confirm that the postmaster is updating a user they are permitted to change before going further
$query = "SELECT * FROM users WHERE user_id='{$_POST['user_id']}'
AND domain_id='{$_SESSION['domain_id']}'
AND (type='local' OR type='piped')";
$result = $db->query($query);
if ($result->numRows()<1) {
header ("Location: adminuser.php?failupdated={$_POST['localpart']}");
die();
}
# Fix the boolean values
$query = "SELECT spamassassin,pipe,uid,gid,quotas
FROM domains
WHERE domain_id='{$_SESSION['domain_id']}'";
$result = $db->query($query);
if (!DB::isError($result)) {
$row = $result->fetchRow();
}
if (isset($_POST['admin'])) {
$_POST['admin'] = 1;
} else {
$_POST['admin'] = 0;
}
if (isset($_POST['on_forward'])) {
$_POST['on_forward'] = 1;
} else {
$_POST['on_forward'] = 0;
}
if (isset($_POST['unseen'])) {
$_POST['unseen'] = 1;
} else {
$_POST['unseen'] = 0;
}
if (isset($_POST['on_vacation'])) {
$_POST['on_vacation'] = 1;
} else {
$_POST['on_vacation'] = 0;
}
if (isset($_POST['enabled'])) {
$_POST['enabled'] = 1;
} else {
$_POST['enabled'] = 0;
}
if ($postmasteruidgid == "yes"){
if (!isset($_POST['gid'])) {
$_POST['gid'] = $row['gid'];
}
if (!isset($_POST['uid'])) {
$_POST['uid'] = $row['uid'];
}
}else{
# customisation of the uid and gid is not permitted for postmasters, use the domain defaults
$_POST['uid'] = $row['uid'];
$_POST['gid'] = $row['gid'];
}
if (!isset($_POST['quota'])) {
$_POST['quota'] = $row['quotas'];
}
if (!isset($_POST['sa_refuse'])) {
$_POST['sa_refuse'] = "0";
}
if ($row['quotas'] != "0") {
if (($_POST['quota'] > $row['quotas']) || ($_POST['quota'] == "0")) {
header ("Location: adminuser.php?quotahigh={$row['quotas']}");
die;
}
}
# Do some checking, to make sure the user is ALLOWED to make these changes
if ((isset($_POST['on_piped'])) && ($row['pipe'] = 1)) {
$_POST['on_piped'] = 1;
} else {
$_POST['on_piped'] = 0;
}
if (((isset($_POST['on_spambox'])) == 1) && ((isset($_POST['on_spamassassin'])))){
$_POST['on_spambox'] = 1;
} else {
$_POST['on_spambox'] = 0;
}
if (isset($_POST['on_spamboxreport'])) {
$_POST['on_spamboxreport'] = 1;
} else {
$_POST['on_spamboxreport'] = 0;
}
if ((isset($_POST['on_spamassassin'])) && ($row['spamassassin'] = 1)) {
$_POST['on_spamassassin'] = 1;
} else {
$_POST['on_spamassassin'] = 0;
}
if (preg_match("/@/",$_POST['forwardmenu'])) {
$forwardaddr = $_POST['forwardmenu'];
} else {
$forwardaddr = $_POST['forward'];
}
# Big code block, to make sure we're not de-admining the last admin
$query = "SELECT COUNT(admin) AS count FROM users
WHERE admin=1 AND domain_id='{$_SESSION['domain_id']}'
AND (type='local' OR type='piped')";
$result = $db->query($query);
if ($result->numRows()) {
$row = $result->fetchRow();
}
if ($row['count'] == "1") {
$nxtquery = "SELECT admin FROM users WHERE localpart='{$_POST['localpart']}'
AND domain_id='{$_SESSION['domain_id']}' AND (type='local' OR type='piped')";
$nxtresult = $db->query($nxtquery);
if ($nxtresult->numRows()) {
$nxtrow = $nxtresult->fetchRow();
}
if (($nxtrow['admin'] == "1") && ($_POST['admin'] == "0")) {
header ("Location: adminuser.php?lastadmin={$_POST['localpart']}");
die;
}
}
# Set the appropriate maildirs
$query = "SELECT maildir FROM domains WHERE domain_id='{$_SESSION['domain_id']}'";
$result = $db->query($query);
$row = $result->fetchRow();
if (($_POST['on_piped'] == 1) && ($_POST['smtp'] != "")) {
$smtphomepath = $_POST['smtp'];
$pophomepath = "{$row['maildir']}/{$_POST['localpart']}";
$_POST['type'] = "piped";
} else {
$smtphomepath = "{$row['maildir']}/{$_POST['localpart']}/Maildir";
$pophomepath = "{$row['maildir']}/{$_POST['localpart']}";
$_POST['type'] = "local";
}
# Update the password, if the password was given
if (validate_password($_POST['clear'], $_POST['vclear'])) {
$cryptedpassword = crypt_password($_POST['clear']);
$query = "UPDATE users
SET crypt='$cryptedpassword', clear='{$_POST['clear']}'
WHERE localpart='{$_POST['localpart']}'
AND domain_id='{$_SESSION['domain_id']}'";
$result = $db->query($query);
if (!DB::isError($result)) {
if ($_POST['localpart'] == $_SESSION['localpart']) {
$_SESSION['crypt'] = $cryptedpassword;
}
} else {
header ("Location: adminuser.php?failupdated={$_POST['localpart']}");
die;
}
} else if ($_POST['clear'] != $_POST['vclear']) {
header ("Location: adminuser.php?badpass={$_POST['localpart']}");
die;
}
$query = "UPDATE users SET uid='{$_POST['uid']}',
gid='{$_POST['gid']}', smtp='$smtphomepath', pop='$pophomepath',
realname='{$_POST['realname']}',
admin='{$_POST['admin']}',
on_forward='{$_POST['on_forward']}',
on_piped='{$_POST['on_piped']}',
on_spamassassin='{$_POST['on_spamassassin']}',
on_spambox='{$_POST['on_spambox']}',
on_spamboxreport='{$_POST['on_spamboxreport']}',
on_vacation='{$_POST['on_vacation']}',
enabled='{$_POST['enabled']}',
forward='{$forwardaddr}',
maxmsgsize='{$_POST['maxmsgsize']}',
quota='{$_POST['quota']}',
sa_tag='" . ((isset($_POST['sa_tag'])) ? $_POST['sa_tag'] : 0) . "',
sa_refuse='" . ((isset($_POST['sa_refuse'])) ? $_POST['sa_refuse'] : 0) . "',
type='{$_POST['type']}',
vacation='" . (($_POST['vacation']) ? $_POST['vacation'] : '') . "',
unseen='{$_POST['unseen']}'
WHERE user_id='{$_POST['user_id']}'";
$result = $db->query($query);
if (!DB::isError($result)) {
header ("Location: adminuser.php?updated={$_POST['localpart']}");
} else {
header ("Location: adminuser.php?failupdated={$_POST['localpart']}");
}
?>