| 1 |
<?php |
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
|
|---|
| 19 |
|
|---|
| 20 |
|
|---|
| 21 |
function routepermissions_configpageinit($pagename) { |
|---|
| 22 |
global $currentcomponent; |
|---|
| 23 |
|
|---|
| 24 |
$action = isset($_REQUEST['action'])?$_REQUEST['action']:null; |
|---|
| 25 |
$extdisplay = isset($_REQUEST['extdisplay'])?$_REQUEST['extdisplay']:null; |
|---|
| 26 |
$extension = isset($_REQUEST['extension'])?$_REQUEST['extension']:null; |
|---|
| 27 |
$tech_hardware = isset($_REQUEST['tech_hardware'])?$_REQUEST['tech_hardware']:null; |
|---|
| 28 |
|
|---|
| 29 |
|
|---|
| 30 |
if ($pagename != 'users' && $pagename != 'extensions') |
|---|
| 31 |
return true; |
|---|
| 32 |
|
|---|
| 33 |
if ($tech_hardware != null || $pagename == 'users') { |
|---|
| 34 |
rp_applyhooks(); |
|---|
| 35 |
$currentcomponent->addprocessfunc('rp_configprocess', 5); |
|---|
| 36 |
} elseif ($action=="add") { |
|---|
| 37 |
|
|---|
| 38 |
$currentcomponent->addprocessfunc('rp_configprocess', 5); |
|---|
| 39 |
} elseif ($extdisplay != '') { |
|---|
| 40 |
|
|---|
| 41 |
rp_applyhooks(); |
|---|
| 42 |
$currentcomponent->addprocessfunc('rp_configprocess', 5); |
|---|
| 43 |
} |
|---|
| 44 |
} |
|---|
| 45 |
|
|---|
| 46 |
|
|---|
| 47 |
function routepermissions_hookGet_config($engine) { |
|---|
| 48 |
global $ext; |
|---|
| 49 |
global $version; |
|---|
| 50 |
switch($engine) { |
|---|
| 51 |
case "asterisk": |
|---|
| 52 |
$context="macro-dialout-trunk"; |
|---|
| 53 |
$ext->splice($context, 's', 1 ,new ext_agi('checkperms.agi')); |
|---|
| 54 |
$ext->add($context, 'barred', '', new ext_noop('Route administratively banned for this user.')); |
|---|
| 55 |
break; |
|---|
| 56 |
} |
|---|
| 57 |
} |
|---|
| 58 |
|
|---|
| 59 |
function rp_applyhooks() { |
|---|
| 60 |
global $currentcomponent; |
|---|
| 61 |
|
|---|
| 62 |
|
|---|
| 63 |
$currentcomponent->addoptlistitem('rpyn', 'YES', _('yes')); |
|---|
| 64 |
$currentcomponent->addoptlistitem('rpyn', 'NO', _('no')); |
|---|
| 65 |
$currentcomponent->setoptlistopts('rpyn', 'sort', false); |
|---|
| 66 |
|
|---|
| 67 |
|
|---|
| 68 |
$currentcomponent->addguifunc('rp_configpageload'); |
|---|
| 69 |
} |
|---|
| 70 |
|
|---|
| 71 |
function rp_configpageload() { |
|---|
| 72 |
global $currentcomponent; |
|---|
| 73 |
|
|---|
| 74 |
|
|---|
| 75 |
$action = isset($_REQUEST['action'])?$_REQUEST['action']:null; |
|---|
| 76 |
$extdisplay = isset($_REQUEST['extdisplay'])?$_REQUEST['extdisplay']:null; |
|---|
| 77 |
|
|---|
| 78 |
|
|---|
| 79 |
if ($action != 'del') { |
|---|
| 80 |
$section = _('Outbound Route Permssions'); |
|---|
| 81 |
$routes = rp_get_routes(); |
|---|
| 82 |
foreach ($routes as $route) { |
|---|
| 83 |
$currentcomponent->addguielem($section, new gui_radio("rp_$route", $currentcomponent->getoptlist('rpyn'), rp_get_perm($extdisplay,$route), $route, "" , null)); |
|---|
| 84 |
} |
|---|
| 85 |
} |
|---|
| 86 |
} |
|---|
| 87 |
|
|---|
| 88 |
function rp_configprocess() { |
|---|
| 89 |
|
|---|
| 90 |
$action = isset($_REQUEST['action'])?$_REQUEST['action']:null; |
|---|
| 91 |
$extdisplay = isset($_REQUEST['extdisplay'])?$_REQUEST['extdisplay']:null; |
|---|
| 92 |
|
|---|
| 93 |
foreach ($_REQUEST as $r=>$val) { |
|---|
| 94 |
if (!strncmp($_REQUEST[$r], "rp_", 3)) { |
|---|
| 95 |
$rps[substr($r, 3)]=$val; |
|---|
| 96 |
} |
|---|
| 97 |
} |
|---|
| 98 |
|
|---|
| 99 |
switch ($action) { |
|---|
| 100 |
case "add": |
|---|
| 101 |
case "edit": |
|---|
| 102 |
rp_purge_ext($extdisplay); |
|---|
| 103 |
rp_set_perm($extdisplay, $rps); |
|---|
| 104 |
break; |
|---|
| 105 |
case "del": |
|---|
| 106 |
rp_purge_ext($extdisplay); |
|---|
| 107 |
break; |
|---|
| 108 |
} |
|---|
| 109 |
} |
|---|
| 110 |
|
|---|
| 111 |
|
|---|
| 112 |
|
|---|
| 113 |
function rp_get_perm($ext, $route) { |
|---|
| 114 |
global $db; |
|---|
| 115 |
$Sext = mysql_real_escape_string($ext); |
|---|
| 116 |
$Sroute = mysql_real_escape_string($route); |
|---|
| 117 |
$sql = "SELECT allowed FROM routepermissions WHERE routename='$Sroute' AND exten='$Sext'"; |
|---|
| 118 |
$res = $db->getRow($sql); |
|---|
| 119 |
if (PEAR::isError($res)) { die($res->getMessage()); } |
|---|
| 120 |
if (isset($res[0])) { |
|---|
| 121 |
return $res[0]; |
|---|
| 122 |
} else { |
|---|
| 123 |
return "YES"; |
|---|
| 124 |
} |
|---|
| 125 |
} |
|---|
| 126 |
|
|---|
| 127 |
function rp_set_perm($ext, $rps) { |
|---|
| 128 |
global $db; |
|---|
| 129 |
$Sext = mysql_real_escape_string($ext); |
|---|
| 130 |
foreach($rps as $r=>$p) { |
|---|
| 131 |
$val = explode("=", $p); |
|---|
| 132 |
$Sr =mysql_real_escape_string($r); |
|---|
| 133 |
$Sval =mysql_real_escape_string($val[1]); |
|---|
| 134 |
$sql = "INSERT INTO routepermissions (exten, routename, allowed) VALUES ('$Sext', '$Sr', '$Sval')"; |
|---|
| 135 |
sql($sql); |
|---|
| 136 |
} |
|---|
| 137 |
} |
|---|
| 138 |
|
|---|
| 139 |
function rp_purge_ext($ext) { |
|---|
| 140 |
global $db; |
|---|
| 141 |
$Sext = mysql_real_escape_string($ext); |
|---|
| 142 |
$sql = "DELETE FROM routepermissions WHERE exten='$Sext'"; |
|---|
| 143 |
sql($sql); |
|---|
| 144 |
} |
|---|
| 145 |
|
|---|
| 146 |
|
|---|
| 147 |
|
|---|
| 148 |
|
|---|
| 149 |
|
|---|
| 150 |
function rp_get_routes() { |
|---|
| 151 |
global $db; |
|---|
| 152 |
$sql = "SELECT DISTINCT context FROM extensions WHERE context LIKE 'outrt%';"; |
|---|
| 153 |
$res = $db->getAll($sql); |
|---|
| 154 |
foreach ($res as $r) { |
|---|
| 155 |
|
|---|
| 156 |
$arr[] = substr($r[0], 10); |
|---|
| 157 |
} |
|---|
| 158 |
return $arr; |
|---|
| 159 |
} |
|---|
| 160 |
|
|---|
| 161 |
?> |
|---|
| 162 |
|
|---|