forked from FreePBX/core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
page.ampusers.php
279 lines (245 loc) · 9.82 KB
/
page.ampusers.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
<?php /* $Id$ */
// License for all code of this FreePBX module can be found in the license file inside the module directory
// Copyright 2006-2014 Schmooze Com Inc.
//
if (!defined('FREEPBX_IS_AUTH')) { die('No direct script access allowed'); }
$userdisplay = isset($_REQUEST['userdisplay'])?$_REQUEST['userdisplay']:'';
$action = isset($_REQUEST['action'])?$_REQUEST['action']:'';
$tech = isset($_REQUEST['tech'])?$_REQUEST['tech']:'';
$tabindex = 0;
// populate some global variables from the request string
$set_globals = array("username","password","extension_high","extension_low","deptname");
foreach ($set_globals as $var) {
if (isset($_REQUEST[$var])) {
$$var = stripslashes( $_REQUEST[$var] );
}
}
$form_password_sha1 = stripslashes(isset($_REQUEST['password_sha1'])?$_REQUEST['password_sha1']:'');
//Search ALL active modules while generating admin access list
$active_modules = module_getinfo(false, MODULE_STATUS_ENABLED);
if(is_array($active_modules)){
foreach($active_modules as $key => $module) {
//create an array of module sections to display
if (isset($module['items']) && is_array($module['items'])) {
foreach($module['items'] as $itemKey => $item) {
$listKey = (!empty($item['display']) ? $item['display'] : $itemKey);
$item['rawname'] = $module['rawname'];
$module_list[ $listKey ] = $item;
}
}
}
}
// extensions vs device/users ... module_list setting
if (isset($amp_conf["AMPEXTENSIONS"]) && ($amp_conf["AMPEXTENSIONS"] == "deviceanduser")) {
unset($module_list["extensions"]);
} else {
unset($module_list["devices"]);
unset($module_list["users"]);
}
// no more adding the APPLY Changes bar to module list because array_multisort messes up integer array keys
// $module_list['99'] = array('category' => NULL, 'name' => _("Apply Changes Bar"));
// changed from $module_name to $admin_module_name because the former is used by framework
foreach ($module_list as $key => $row) {
$module_category[$key] = $row['category'];
$admin_module_name[$key] = $row['name'];
}
array_multisort($module_category, SORT_ASC, $admin_module_name, SORT_ASC, $module_list);
$sections = array();
if (isset($_REQUEST["sections"])) {
if (is_array($_REQUEST["sections"])) {
$sections = $_REQUEST["sections"];
} else {
//TODO do we even need this??
$sections = explode(";",$_REQUEST["sections"]);
}
}
//if submitting form, update database
switch ($action) {
case "addampuser":
core_ampusers_add($username, $password, $extension_low, $extension_high, $deptname, $sections);
//indicate 'need reload' link in footer.php
needreload();
redirect_standard();
break;
case "editampuser":
// Check to make sure the hidden var is sane, and that they haven't changed the password field
if (strlen($form_password_sha1)==40 && $password == "******") {
// Password unchanged
core_ampusers_del($userdisplay);
core_ampusers_add($username, $form_password_sha1, $extension_low, $extension_high, $deptname, $sections);
} elseif ($password != "******") {
// Password has been changed
core_ampusers_del($userdisplay);
core_ampusers_add($username, $password, $extension_low, $extension_high, $deptname, $sections);
}
//indicate 'need reload' link in footer.php
needreload();
redirect_standard('userdisplay');
break;
case "delampuser":
core_ampusers_del($userdisplay);
//indicate 'need reload' link in footer.php
needreload();
$userdisplay = ""; // go "add" screen
redirect_standard();
break;
}
?>
<div class="rnav">
<ul>
<li><a <?php echo ($userdisplay=='' ? 'class="current"':'') ?> href="config.php?display=<?php echo urlencode($display)?>"><?php echo _("Add User")?></a></li>
<?php
//get existing trunk info
$tresults = core_ampusers_list();
foreach ($tresults as $tresult) {
echo "\t<li><a ".($userdisplay==$tresult[0] ? 'class="current"':'')." href=\"config.php?display=".urlencode($display)."&userdisplay=".urlencode($tresult[0])."\">".$tresult[0]."</a></li>\n";
}
?>
</ul>
</div>
<?php
if ($userdisplay) {
echo "<h2>"._("Edit Administrator")."</h2>";
$user = getAmpUser($userdisplay);
$username = $user["username"];
$password = "******";
$password_sha1 = $user["password_sha1"];
$extension_high = $user["extension_high"];
$extension_low = $user["extension_low"];
$deptname = $user["deptname"];
$sections = $user["sections"];
$tlabel = sprintf(_("Delete User: %s"),$userdisplay);
$label = '<span><img width="16" height="16" border="0" title="'.$tlabel.'" alt="" src="images/core_delete.png"/> '.$tlabel.'</span>';
?>
<p><a href="config.php?display=<?php echo urlencode($display) ?>&userdisplay=<?php echo urlencode($userdisplay) ?>&action=delampuser"><?php echo $label ?></a></p>
<?php
} else {
// set defaults
$username = "";
$password = "";
$deptname = "";
$extension_low = "";
$extension_high = "";
$sections = array("*");
echo "<h2>"._("Add Administrator")."</h2>";
}
?>
<form autocomplete="off" name="ampuserEdit" action="config.php" method="get">
<input type="hidden" name="display" value="<?php echo $display?>"/>
<input type="hidden" name="userdisplay" value="<?php echo $userdisplay ?>"/>
<input type="hidden" name="action" value=""/>
<input type="hidden" name="tech" value="<?php echo $tech?>"/>
<input type="hidden" name="password_sha1" value="<?php echo $password_sha1 ?>"/>
<table>
<tr>
<td colspan="2">
<h4><?php echo _("General Settings")?></h4>
</td>
</tr>
<?php if (($amp_conf["AUTHTYPE"] != "database") && ($amp_conf["AUTHTYPE"] != "webserver")) { ?>
<tr>
<td colspan="2">
<?php echo '<b>'._("NOTE:").'</b>'._("Authorization Type is not set to 'database' in Advanced Setting - note that this module is not currently providing access control, and changing passwords here or adding users will have no effect unless Authorization Type is set to 'database'.") ?><br /><br />
</td>
</tr>
<?php } ?>
<tr>
<td>
<a href=# class="info"><?php echo _("Username<span>Create a unique username for this new user</span>")?></a>:
</td><td>
<input type="text" size="20" name="username" value="<?php echo $username;?>" tabindex="<?php echo ++$tabindex;?>"/>
</td>
</tr>
<tr>
<td>
<a href=# class="info"><?php echo _("Password<span>Create a password for this new user</span>")?></a>:
</td><td>
<input type="password" size="20" name="password" value="<?php echo $password; ?>" tabindex="<?php echo ++$tabindex;?>"/>
</td>
</tr>
<tr>
<td colspan="2">
<br>
<h4><?php echo _("Access Restrictions")?></h4>
</td>
</tr>
<tr>
<td>
<a href=# class="info"><?php echo _("Department Name<span>Restrict this user's view of Digital Receptionist menus and System Recordings to only those for this department.</span>")?></a>:
</td><td>
<input type="text" size="20" name="deptname" value="<?php echo htmlspecialchars($deptname);?>" tabindex="<?php echo ++$tabindex;?>"/>
</td>
</tr>
<tr>
<td>
<a href=# class="info"><?php echo _("Extension Range<span>Restrict this user's view to only Extensions, Ring Groups, and Queues within this range.</span>")?></a>:
</td><td>
<input type="text" size="5" name="extension_low" value="<?php echo htmlspecialchars($extension_low);?>" tabindex="<?php echo ++$tabindex;?>"/>
to
<input type="text" size="5" name="extension_high" value="<?php echo htmlspecialchars($extension_high);?>" tabindex="<?php echo ++$tabindex;?>"/>
</td>
</tr>
<tr>
<td valign="top">
<a href=# class="info"><?php echo _("Admin Access<span>Select the Admin Sections this user should have access to.</span>")?></a>:
</td><td>
<select multiple name="sections[]" tabindex="<?php echo ++$tabindex;?>" size="15">
<option></option>
<?php
$prev_category = NULL;
foreach ($module_list as $key => $row) {
if ($row['category'] != $prev_category) {
if ($prev_category)
echo "</optgroup>\n";
echo "<optgroup label=\""._($row['category'])."\">\n";
$prev_category = $row['category'];
}
echo "<option value=\"".$key."\"";
if (in_array($key, $sections)) echo " SELECTED";
$label = modgettext::_($row['name'],$row['rawname']);
echo ">"._($row['name'])."</option>\n";
}
echo "</optgroup>\n";
// Apply Changes Bar
echo "<option value=\"99\"";
if (in_array("99", $sections)) echo " SELECTED";
echo ">"._("Apply Changes Bar")."</option>\n";
// Apply Changes Bar
echo "<option value=\"999\"";
if (in_array("999", $sections)) echo " SELECTED";
echo ">".(($amp_conf['AMPEXTENSIONS'] == 'deviceanduser')?_("Add Device"):_("Add Extension"))."</option>\n";
// All Sections
echo "<option value=\"*\"";
if (in_array("*", $sections)) echo " SELECTED";
echo ">"._("ALL SECTIONS")."</option>\n";
?>
</select>
</td>
</tr>
<tr>
<td colspan="2">
<h6><input name="Submit" type="button" value="<?php echo _("Submit Changes")?>" onclick="checkAmpUser(ampuserEdit, '<?php echo ($userdisplay ? "editampuser" : "addampuser") ?>')" tabindex="<?php echo ++$tabindex;?>"></h6>
</td>
</tr>
</table>
</form>
<script language="javascript">
<!--
function checkAmpUser(theForm, action) {
$username = theForm.username.value;
$deptname = theForm.deptname.value;
if ($username == "") {
<?php echo "alert('"._("Username must not be blank")."')"?>;
} else if (!$username.match('^[a-zA-Z][a-zA-Z0-9]+$')) {
<?php echo "alert('"._("Username cannot start with a number, and can only contain letters and numbers")."')"?>;
} else if ($deptname == "default") {
<?php echo "alert('"._("For security reasons, you cannot use the department name default")."')"?>;
} else if ($deptname != "" && !$deptname.match('^[a-zA-Z0-9]+$')) {
<?php echo "alert('"._("Department name cannot have a space")."')"?>;
} else {
theForm.action.value = action;
theForm.submit();
}
}
//-->
</script>