forked from web-cyradm/web-cyradm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
editadminuser.php
265 lines (246 loc) · 7.48 KB
/
editadminuser.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
<?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();
}
?>
<!-- #################### editadminuser.php start #################### -->
<tr>
<td width="10"> </td>
<td valign="top">
<?php
if ($authorized){
if (empty($_POST['confirmed'])) {
$query = "SELECT type FROM adminuser WHERE username='".$_GET['username']."'";
$result = $handle->query($query);
if (DB::isError($result)) {
die (_("Database error (editadminuser 20)"));
}
$row = $result->fetchRow(DB_FETCHMODE_ASSOC, 0);
$type = $row['type'];
?>
<h3>
<?php print _("Change admin user for domain");?>
<span style="color: red;">
<?php print $_GET['domain']; ?>
</span>
</h3>
<form action="index.php" method="post">
<input type="hidden" name="action" value="editadminuser">
<input type="hidden" name="confirmed" value="true">
<input type="hidden" name="username" value="<?php print $_GET['username'];?>">
<input type="hidden" name="domain" value="<?php print $_GET['domain'];?>">
<table>
<tr>
<td>
<?php print _("Accountname");?>
</td>
<td>
<?php print $_GET['username'];?>
</td>
</tr>
<tr>
<td>
<?php print _("Admin Type");?>
</td>
<td>
<select class="selectfield" name="newtype">
<option value="0"
<?php
if ($type == 0) {
# This is NOT a i18n string!
echo "selected";
}
?>
><?php print _("Superuser");?>
</option>
<option value="1"
<?php
if ($type == 1) {
# This is NOT a i18n string!
echo "selected";
}
?>
><?php print _("Domain Master"); ?>
</option>
</select>
</td>
</tr>
<tr>
<td>
<?php print _("Password");?>
</td>
<td>
<input
class="inputfield"
type="password"
name="new_password"
onfocus="this.style.backgroundColor='#aaaaaa'"
>
</td>
</tr>
<tr>
<td>
<?php
print _("Confirm Password");
?>
</td>
<td>
<input
class="inputfield"
type="password"
name="confirm_password"
onfocus="this.style.backgroundColor='#aaaaaa'"
>
</td>
</tr>
<tr>
<td>
<?php
# For Superusers there is nothing to display
if ($type == 0) {
print "<p>";
print "<h4>";
print _("Responsible for all domains");
print "</h4>";
} else {
# Query for what domains this admin is already reponsible for
$query = "SELECT * FROM domainadmin WHERE adminuser='".$_GET['username']."'";
$result = $handle->query($query);
if (DB::isError($result)) {
die (_("Database error (editadminuser 123)"));
}
$cnt = $result->numRows();
if ($cnt > 0) {
print "<p>";
print "<h4>";
print _("Responsible for the following domains:");
print "</h4>";
print "</td></tr><tr>";
for ($i=0; $i<$cnt; $i++) {
$row = $result->fetchRow(DB_FETCHMODE_ASSOC, $i);
$resp_domain = $row['domain_name'];
print "<td>";
print $resp_domain;
print "</td>";
print "<td>";
print "<input type=\"checkbox\" name=\"resp_domain[$resp_domain]\" checked>";
print "</td>";
print "</tr>";
}
} else {
print "<p><h4>";
print _("No Domain assigned yet");
print "</h4>";
print "</td></tr>";
}
?>
<tr>
<td>
<?php print _("Add new domain to this admin");?>
</td>
<td><input
class="inputfield"
type="text"
name="newdomain"
value="<?php print $_GET['domain']; ?>"
onfocus="this.style.backgroundColor='#aaaaaa'">
<?php
} # End of if ($type == 0)
?>
</td>
</tr>
<tr>
<td colspan="2" align="center">
<input
class="inputfield"
type="submit"
value="<?php print _("Submit"); ?>"
>
</td>
</tr>
</table>
</form>
<?php
}
elseif (!empty($_POST['confirmed'])){
$query = "SELECT type FROM adminuser WHERE username='".$_POST['username']."'";
$result = $handle->query($query);
if (DB::isError($result)) {
die (_("Database error (editadminuser 185)"));
}
$row = $result->fetchRow(DB_FETCHMODE_ASSOC, 0);
$type = $row['type'];
if ($type != $_POST['newtype'] || $type = '1') {
# First delete and set new Domainresponsibilities
$query = "DELETE FROM domainadmin WHERE adminuser='".$_POST['username']."'";
$result = $handle->query($query);
if (DB::isError($result)) {
die (_("Database error (editadminuser 195)"));
}
}
# First admin user related thing we can do is updating the type of the admin
if ($type != $_POST['newtype']) {
# Update the type of this admin
$query = "UPDATE adminuser SET type='".$_POST['newtype']."' WHERE username='".$_POST['username']."'";
$result = $handle->query($query);
if (DB::isError($result)) {
die (_("Database error (editadminuser 205)"));
}
if ($_POST['newtype']==0){
# Set responsibility for all domains to superuser
$query = "INSERT INTO domainadmin (domain_name,adminuser) VALUES ('*','".$_POST['username']."')";
$result = $handle->query($query);
if (DB::isError($result)) {
die (_("Database error (editadminuser 213)"));
}
} else {
# no responsibility is set for domainadmins by default
}
} else { # if admin type remain the same
# Insert each key in the array "domain" into database again
if (!empty($_POST['resp_domain'])) {
foreach ($_POST['resp_domain'] as $key => $r_domain){
$query = "INSERT INTO domainadmin (domain_name,adminuser) VALUES('$key', '".$_POST['username']."')";
$result = $handle->query($query);
if (DB::isError($result)) {
die (_("Database error (editadminuser 225)"));
}
}
}
# If there is a new domain to add, lets insert it to the DB
if (!empty($_POST['newdomain'])){
$query = "INSERT INTO domainadmin (domain_name,adminuser) VALUES('".$_POST['newdomain']."','".$_POST['username']."')";
$result = $handle->query($query);
if (DB::isError($result)) {
die (_("Database error (editadminuser 235)"));
}
}
}
# If the password is empty, the password will not be changed at all, but it is not a error
if (!empty($_POST['new_password'])) {
$pwd = new password;
$new_password = $pwd->encrypt($_POST['new_password'], $CRYPT);
# If the new_password field is not empty and the password matches, update the password
$query = "UPDATE adminuser SET password='".$new_password."' WHERE username='".$_POST['username']."'";
$result = $handle->query($query);
if (DB::isError($result)) {
die (_("Database error (editadminuser 248)"));
}
}
$_GET['domain'] = $_POST['domain'];
include WC_BASE . "/adminuser.php";
} // End of if (empty($_POST['confirmed']))
} else { // if ($authorized)
?>
<h3>
<?php print $err_msg;?>
</h3>
<?php
} // End of if ($authorized)
?>
</td>
</tr>
<!-- #################### editadminuser.php end #################### -->