| 1 |
<?php /* $Id$ */ |
|---|
| 2 |
// routing.php Copyright (C) 2004 Greg MacLellan (greg@mtechsolutions.ca) |
|---|
| 3 |
// Asterisk Management Portal Copyright (C) 2004 Coalescent Systems Inc. (info@coalescentsystems.ca) |
|---|
| 4 |
// |
|---|
| 5 |
//This program is free software; you can redistribute it and/or |
|---|
| 6 |
//modify it under the terms of the GNU General Public License |
|---|
| 7 |
//as published by the Free Software Foundation; either version 2 |
|---|
| 8 |
//of the License, or (at your option) any later version. |
|---|
| 9 |
// |
|---|
| 10 |
//This program is distributed in the hope that it will be useful, |
|---|
| 11 |
//but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 12 |
//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 13 |
//GNU General Public License for more details. |
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
$userdisplay = isset($_REQUEST['userdisplay'])?$_REQUEST['userdisplay']:''; |
|---|
| 17 |
$action = isset($_REQUEST['action'])?$_REQUEST['action']:''; |
|---|
| 18 |
$tech = isset($_REQUEST['tech'])?$_REQUEST['tech']:''; |
|---|
| 19 |
|
|---|
| 20 |
// populate some global variables from the request string |
|---|
| 21 |
$set_globals = array("username","password","extension_high","extension_low","deptname"); |
|---|
| 22 |
foreach ($set_globals as $var) { |
|---|
| 23 |
if (isset($_REQUEST[$var])) { |
|---|
| 24 |
$$var = stripslashes( $_REQUEST[$var] ); |
|---|
| 25 |
} |
|---|
| 26 |
} |
|---|
| 27 |
|
|---|
| 28 |
//Search ALL active modules while generating admin access list |
|---|
| 29 |
$active_modules = module_getinfo(false, MODULE_STATUS_ENABLED); |
|---|
| 30 |
|
|---|
| 31 |
if(is_array($active_modules)){ |
|---|
| 32 |
foreach($active_modules as $key => $module) { |
|---|
| 33 |
//create an array of module sections to display |
|---|
| 34 |
if (isset($module['items']) && is_array($module['items'])) { |
|---|
| 35 |
foreach($module['items'] as $itemKey => $item) { |
|---|
| 36 |
$listKey = (!empty($item['display']) ? $item['display'] : $itemKey); |
|---|
| 37 |
$module_list[ $listKey ] = $item; |
|---|
| 38 |
} |
|---|
| 39 |
} |
|---|
| 40 |
} |
|---|
| 41 |
} |
|---|
| 42 |
|
|---|
| 43 |
// extensions vs device/users ... module_list setting |
|---|
| 44 |
if (isset($amp_conf["AMPEXTENSIONS"]) && ($amp_conf["AMPEXTENSIONS"] == "deviceanduser")) { |
|---|
| 45 |
unset($module_list["extensions"]); |
|---|
| 46 |
} else { |
|---|
| 47 |
unset($module_list["devices"]); |
|---|
| 48 |
unset($module_list["users"]); |
|---|
| 49 |
} |
|---|
| 50 |
|
|---|
| 51 |
// no more adding the APPLY Changes bar to module list because array_multisort messes up integer array keys |
|---|
| 52 |
// $module_list['99'] = array('category' => NULL, 'name' => _("Apply Changes Bar")); |
|---|
| 53 |
|
|---|
| 54 |
// changed from $module_name to $admin_module_name because the former is used by framework |
|---|
| 55 |
foreach ($module_list as $key => $row) { |
|---|
| 56 |
$module_category[$key] = $row['category']; |
|---|
| 57 |
$admin_module_name[$key] = $row['name']; |
|---|
| 58 |
} |
|---|
| 59 |
array_multisort($module_category, SORT_ASC, $admin_module_name, SORT_ASC, $module_list); |
|---|
| 60 |
|
|---|
| 61 |
$sections = array(); |
|---|
| 62 |
if (isset($_REQUEST["sections"])) { |
|---|
| 63 |
if (is_array($_REQUEST["sections"])) { |
|---|
| 64 |
$sections = $_REQUEST["sections"]; |
|---|
| 65 |
} else { |
|---|
| 66 |
//TODO do we even need this?? |
|---|
| 67 |
$sections = explode(";",$_REQUEST["sections"]); |
|---|
| 68 |
} |
|---|
| 69 |
} |
|---|
| 70 |
|
|---|
| 71 |
//if submitting form, update database |
|---|
| 72 |
switch ($action) { |
|---|
| 73 |
case "addampuser": |
|---|
| 74 |
core_ampusers_add($username, $password, $extension_low, $extension_high, $deptname, $sections); |
|---|
| 75 |
//indicate 'need reload' link in footer.php |
|---|
| 76 |
needreload(); |
|---|
| 77 |
redirect_standard(); |
|---|
| 78 |
break; |
|---|
| 79 |
case "editampuser": |
|---|
| 80 |
core_ampusers_del($userdisplay); |
|---|
| 81 |
core_ampusers_add($username, $password, $extension_low, $extension_high, $deptname, $sections); |
|---|
| 82 |
//indicate 'need reload' link in footer.php |
|---|
| 83 |
needreload(); |
|---|
| 84 |
redirect_standard('userdisplay'); |
|---|
| 85 |
break; |
|---|
| 86 |
case "delampuser": |
|---|
| 87 |
core_ampusers_del($userdisplay); |
|---|
| 88 |
//indicate 'need reload' link in footer.php |
|---|
| 89 |
needreload(); |
|---|
| 90 |
$userdisplay = ""; // go "add" screen |
|---|
| 91 |
redirect_standard(); |
|---|
| 92 |
break; |
|---|
| 93 |
} |
|---|
| 94 |
|
|---|
| 95 |
?> |
|---|
| 96 |
</div> |
|---|
| 97 |
|
|---|
| 98 |
<div class="rnav"> |
|---|
| 99 |
<ul> |
|---|
| 100 |
<li><a <?php echo ($userdisplay=='' ? 'class="current"':'') ?> href="config.php?display=<?php echo urlencode($display)?>"><?php echo _("Add User")?></a></li> |
|---|
| 101 |
<?php |
|---|
| 102 |
//get existing trunk info |
|---|
| 103 |
$tresults = core_ampusers_list(); |
|---|
| 104 |
|
|---|
| 105 |
foreach ($tresults as $tresult) { |
|---|
| 106 |
echo "\t<li><a ".($userdisplay==$tresult[0] ? 'class="current"':'')." href=\"config.php?display=".urlencode($display)."&userdisplay=".urlencode($tresult[0])."\">".$tresult[0]."</a></li>\n"; |
|---|
| 107 |
} |
|---|
| 108 |
?> |
|---|
| 109 |
</ul> |
|---|
| 110 |
</div> |
|---|
| 111 |
|
|---|
| 112 |
<div class="content"> |
|---|
| 113 |
|
|---|
| 114 |
<?php |
|---|
| 115 |
|
|---|
| 116 |
if ($userdisplay) { |
|---|
| 117 |
echo "<h2>"._("Edit Administrator")."</h2>"; |
|---|
| 118 |
|
|---|
| 119 |
$user = getAmpUser($userdisplay); |
|---|
| 120 |
|
|---|
| 121 |
$username = $user["username"]; |
|---|
| 122 |
$password = $user["password"]; |
|---|
| 123 |
$extension_high = $user["extension_high"]; |
|---|
| 124 |
$extension_low = $user["extension_low"]; |
|---|
| 125 |
$deptname = $user["deptname"]; |
|---|
| 126 |
$sections = $user["sections"]; |
|---|
| 127 |
|
|---|
| 128 |
?> |
|---|
| 129 |
<p><a href="config.php?display=<?php echo urlencode($display) ?>&userdisplay=<?php echo urlencode($userdisplay) ?>&action=delampuser"><?php echo _("Delete User")?> <?php echo $userdisplay; ?></a></p> |
|---|
| 130 |
<?php |
|---|
| 131 |
|
|---|
| 132 |
} else { |
|---|
| 133 |
// set defaults |
|---|
| 134 |
$username = ""; |
|---|
| 135 |
$password = ""; |
|---|
| 136 |
$deptname = ""; |
|---|
| 137 |
|
|---|
| 138 |
$extension_low = ""; |
|---|
| 139 |
$extension_high = ""; |
|---|
| 140 |
|
|---|
| 141 |
$sections = array("*"); |
|---|
| 142 |
|
|---|
| 143 |
|
|---|
| 144 |
echo "<h2>"._("Add Administrator")."</h2>"; |
|---|
| 145 |
} |
|---|
| 146 |
?> |
|---|
| 147 |
|
|---|
| 148 |
<form autocomplete="off" name="ampuserEdit" action="config.php" method="get"> |
|---|
| 149 |
<input type="hidden" name="display" value="<?php echo $display?>"/> |
|---|
| 150 |
<input type="hidden" name="userdisplay" value="<?php echo $userdisplay ?>"/> |
|---|
| 151 |
<input type="hidden" name="action" value=""/> |
|---|
| 152 |
<input type="hidden" name="tech" value="<?php echo $tech?>"/> |
|---|
| 153 |
<table> |
|---|
| 154 |
<tr> |
|---|
| 155 |
<td colspan="2"> |
|---|
| 156 |
<h4><?php echo _("General Settings")?></h4> |
|---|
| 157 |
</td> |
|---|
| 158 |
</tr> |
|---|
| 159 |
<?php if ($amp_conf["AUTHTYPE"] != "database") { ?> |
|---|
| 160 |
<tr> |
|---|
| 161 |
<td colspan="2"> |
|---|
| 162 |
<?php echo '<b>'._("NOTE:").'</b>'._("AUTHTYPE is not set to 'database' in /etc/amportal.conf - note that this module is not currently providing access control, and changing passwords here or adding users will have no effect unless AUTHTYPE is set to 'database'.") ?><br /><br /> |
|---|
| 163 |
</td> |
|---|
| 164 |
</tr> |
|---|
| 165 |
<?php } ?> |
|---|
| 166 |
<tr> |
|---|
| 167 |
<td> |
|---|
| 168 |
<a href=# class="info"><?php echo _("Username<span>Create a unique username for this new user</span>")?></a>: |
|---|
| 169 |
</td><td> |
|---|
| 170 |
<input type="text" size="20" name="username" value="<?php echo $username;?>"/> |
|---|
| 171 |
</td> |
|---|
| 172 |
</tr> |
|---|
| 173 |
<tr> |
|---|
| 174 |
<td> |
|---|
| 175 |
<a href=# class="info"><?php echo _("Password<span>Create a password for this new user</span>")?></a>: |
|---|
| 176 |
</td><td> |
|---|
| 177 |
<input type="password" size="20" name="password" value="<?php echo $password;?>"/> |
|---|
| 178 |
</td> |
|---|
| 179 |
</tr> |
|---|
| 180 |
<tr> |
|---|
| 181 |
<td colspan="2"> |
|---|
| 182 |
<br> |
|---|
| 183 |
<h4><?php echo _("Access Restrictions")?></h4> |
|---|
| 184 |
</td> |
|---|
| 185 |
</tr> |
|---|
| 186 |
<tr> |
|---|
| 187 |
<td> |
|---|
| 188 |
<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>: |
|---|
| 189 |
</td><td> |
|---|
| 190 |
<input type="text" size="20" name="deptname" value="<?php echo htmlspecialchars($deptname);?>"/> |
|---|
| 191 |
</td> |
|---|
| 192 |
</tr> |
|---|
| 193 |
<tr> |
|---|
| 194 |
<td> |
|---|
| 195 |
<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>: |
|---|
| 196 |
</td><td> |
|---|
| 197 |
<input type="text" size="5" name="extension_low" value="<?php echo htmlspecialchars($extension_low);?>"/> |
|---|
| 198 |
to |
|---|
| 199 |
<input type="text" size="5" name="extension_high" value="<?php echo htmlspecialchars($extension_high);?>"/> |
|---|
| 200 |
</td> |
|---|
| 201 |
</tr> |
|---|
| 202 |
<tr> |
|---|
| 203 |
<td valign="top"> |
|---|
| 204 |
<a href=# class="info"><?php echo _("Admin Access<span>Select the Admin Sections this user should have access to.</span>")?></a>: |
|---|
| 205 |
</td><td> |
|---|
| 206 |
<select multiple name="sections[]"> |
|---|
| 207 |
<option /> |
|---|
| 208 |
<?php |
|---|
| 209 |
$prev_category = NULL; |
|---|
| 210 |
foreach ($module_list as $key => $row) { |
|---|
| 211 |
if ($row['category'] != $prev_category) { |
|---|
| 212 |
if ($prev_category) |
|---|
| 213 |
echo "</optgroup>\n"; |
|---|
| 214 |
echo "<optgroup label=\""._($row['category'])."\">\n"; |
|---|
| 215 |
$prev_category = $row['category']; |
|---|
| 216 |
} |
|---|
| 217 |
|
|---|
| 218 |
echo "<option value=\"".$key."\""; |
|---|
| 219 |
if (in_array($key, $sections)) echo " SELECTED"; |
|---|
| 220 |
echo ">"._($row['name'])."</option>\n"; |
|---|
| 221 |
} |
|---|
| 222 |
echo "</optgroup>\n"; |
|---|
| 223 |
|
|---|
| 224 |
// Apply Changes Bar |
|---|
| 225 |
echo "<option value=\"99\""; |
|---|
| 226 |
if (in_array("99", $sections)) echo " SELECTED"; |
|---|
| 227 |
echo ">"._("Apply Changes Bar")."</option>\n"; |
|---|
| 228 |
|
|---|
| 229 |
// All Sections |
|---|
| 230 |
echo "<option value=\"*\""; |
|---|
| 231 |
if (in_array("*", $sections)) echo " SELECTED"; |
|---|
| 232 |
echo ">"._("ALL SECTIONS")."</option>\n"; |
|---|
| 233 |
?> |
|---|
| 234 |
</select> |
|---|
| 235 |
</td> |
|---|
| 236 |
</tr> |
|---|
| 237 |
|
|---|
| 238 |
<tr> |
|---|
| 239 |
<td colspan="2"> |
|---|
| 240 |
<h6><input name="Submit" type="button" value="<?php echo _("Submit Changes")?>" onclick="checkAmpUser(ampuserEdit, '<?php echo ($userdisplay ? "editampuser" : "addampuser") ?>')"></h6> |
|---|
| 241 |
</td> |
|---|
| 242 |
</tr> |
|---|
| 243 |
</table> |
|---|
| 244 |
</form> |
|---|
| 245 |
|
|---|
| 246 |
<script language="javascript"> |
|---|
| 247 |
<!-- |
|---|
| 248 |
|
|---|
| 249 |
function checkAmpUser(theForm, action) { |
|---|
| 250 |
$username = theForm.username.value; |
|---|
| 251 |
$deptname = theForm.deptname.value; |
|---|
| 252 |
|
|---|
| 253 |
if ($username == "") { |
|---|
| 254 |
<?php echo "alert('"._("Username must not be blank")."')"?>; |
|---|
| 255 |
} else if (!$username.match('^[a-zA-Z][a-zA-Z0-9]+$')) { |
|---|
| 256 |
<?php echo "alert('"._("Username cannot start with a number, and can only contain letters and numbers")."')"?>; |
|---|
| 257 |
} else if ($deptname == "default") { |
|---|
| 258 |
<?php echo "alert('"._("For security reasons, you cannot use the department name default")."')"?>; |
|---|
| 259 |
} else if ($deptname != "" && !$deptname.match('^[a-zA-Z0-9]+$')) { |
|---|
| 260 |
<?php echo "alert('"._("Department name cannot have a space")."')"?>; |
|---|
| 261 |
} else { |
|---|
| 262 |
theForm.action.value = action; |
|---|
| 263 |
theForm.submit(); |
|---|
| 264 |
} |
|---|
| 265 |
} |
|---|
| 266 |
|
|---|
| 267 |
//--> |
|---|
| 268 |
</script> |
|---|