forked from web-cyradm/web-cyradm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
newadminuser.php
195 lines (180 loc) · 4.4 KB
/
newadminuser.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
<?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();
}
?>
<!-- #################### newadminuser.php start #################### -->
<tr>
<td width="10"> </td>
<td valign="top">
<?php
if ($authorized){
if (empty($_POST['confirmed'])){
?>
<h3>
<?php print _("Add new administrator");?>:
</h3>
<form action="index.php" method="post">
<input type="hidden"
name="action"
value="newadminuser">
<input
type="hidden"
name="confirmed"
value="true">
<input
type="hidden"
name="domain"
value="<?php print $_GET['domain']; ?>">
<table>
<tr>
<td>
<?php print _("Accountname");?>
</td>
<td>
<input
class="inputfield"
type="text"
name="newadminuser"
onfocus="this.style.backgroundColor='#aaaaaa'"
>
</td>
</tr>
<tr>
<td>
<?php print _("Admin Type");?>
</td>
<td>
<select name="newadmintype">
<option value="0"><?php
print _("Superuser");
?></option>
<option selected value="1"><?php
print _("Domain Master");
?></option>
</select> <?php
print _("Select \"Superuser\" for all domains");
?>
</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 print _("Domain");?>
</td>
<td>
<input
class="inputfield"
type="text"
name="newdomain"
value="<?php print $_GET['domain']; ?>"
onfocus="this.style.backgroundColor='#aaaaaa'"
>
</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'])){
# Generate password for new admin
$pwd = new password;
$password = $pwd->encrypt($_POST['new_password'],$CRYPT);
# Save new admin into table
$query = "INSERT INTO adminuser (username , password , type ) VALUES ('".$_POST['newadminuser']."','".$password."','".$_POST['newadmintype']."')";
$result = $handle->query($query);
if (DB::isError($result)) {
die (_("Database error"));
}
# Save initial setup for new admin
$query = "INSERT INTO settings (username) VALUES ('".$_POST['newadminuser']."')";
$result = $handle->query($query);
if (DB::isError($result)) {
die (_("Database error"));
}
# Save domain which new admin will be responsible for
# If admin is superuser, he will be responsible for all domains
if ($_POST['newadmintype'] == 0){
$query = "INSERT INTO domainadmin (domain_name , adminuser) values ('*' , '".$_POST['newadminuser']."')";
$result = $handle->query($query);
if (DB::isError($result)) {
die (_("Database error"));
}
}
else if (!empty($_POST['newdomain'])){
$query = "INSERT INTO domainadmin (domain_name , adminuser) values ('".$_POST['newdomain']."' ,'".$_POST['newadminuser']."')";
$result = $handle->query($query);
if (DB::isError($result)) {
die (_("Database error"));
}
}
?>
<h3>
<?php
print _("successfully added to Database");
?>
:
<span style="color: red;">
<?php echo $_POST['newadminuser'];?>
</span>
as
<span style="color: red;">
<?php
if ($_POST['newadmintype'] == 0) {
print _("Superuser");
} else {
print _("Domain Master");
}
?>
</span>
</h3>
<?php
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>
<!-- #################### newadminuser.php end #################### -->