root/contributed_modules/modules/routepermissions/page.routepermissions.php

Revision 7720, 8.7 kB (checked in by wiseoldowl, 4 years ago)

Changed font size and color on empty redirect field error message to make it more obvious

Line 
1 <?php
2 /* $Id:$ */
3
4 // Original Release by Rob Thomas (xrobau@gmail.com)
5 // Copyright Rob Thomas (2009)
6 /*
7     This program is free software: you can redistribute it and/or modify
8     it under the terms of the GNU Affero General Public License as
9     published by the Free Software Foundation, either version 3 of the
10     License, or (at your option) any later version.
11
12     This program is distributed in the hope that it will be useful,
13     but WITHOUT ANY WARRANTY; without even the implied warranty of
14     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15     GNU Affero General Public License for more details.
16
17     You should have received a copy of the GNU Affero General Public License
18     along with this program.  If not, see <http://www.gnu.org/licenses/>.
19 */
20
21 $tabindex = 0;
22 // What are we doing..
23 isset($_REQUEST['action'])?$action = $_REQUEST['action']:$action='';
24
25 // Where we are
26 $dispnum = "routepermissions"; //used for switch on config.php
27
28
29 ?>
30
31 </div> <!-- end content div -->
32
33 <div class="content">
34 <?php
35     global $dispnum;
36 ?>
37     <h2 id='title'><?php echo _("Route Permissions") ?></h2></td>
38 <?php
39     // Has something been submitted?
40     if(isset($_POST['action'])) {
41         // Figure out which button has been pushed.
42         foreach ($_REQUEST as $r=>$val) {
43             if (!strncmp($r, "on_", 3)) {
44                 $route=substr($r,3);
45                 print "<h4>Route $route set to ALLOW for supplied range</h4>\n";
46                 rp_allow($route, $_REQUEST["range_$route"]);
47             }
48             if (!strncmp($r, "off_", 3)) {
49                 $route=substr($r,4);
50                 print "<h4>Route $route set to DENY for supplied range</h4>\n";
51                 rp_deny($route, $_REQUEST["range_$route"]);
52             }
53             if (!strncmp($r, "redirect_", 8)) {
54                 $route=substr($r,9);
55                 $redir=trim($_REQUEST["rp-redir_$route"]);
56                 // Make sure redirect field is not empty or whitespace only - could have better sanity checking
57                 if (strlen($redir)) {
58                     print "<h4>Route $route set to DENY for supplied range using redirect prefix $redir</h4>\n";
59                     rp_redir($route, $_REQUEST["range_$route"], $redir);
60                 } else {
61                     print "<h3><font color=#FF0000>Redirect selected but redirect prefix missing for route $route - no action taken</font></h3>\n";
62                 }
63             }
64             if ($r == 'update_dest') {
65                 $dest = $_REQUEST[$_REQUEST['gotofaildest'].'faildest'];
66                 $sdest = mysql_real_escape_string($dest);
67                 sql("DELETE FROM routepermissions WHERE EXTEN='-1'");
68                 sql("INSERT INTO routepermissions (exten, routename, faildest) VALUES ('-1', 'default', '".$dest."')");
69                 print "<h4>Default destination changed</h4>\n";
70             }
71         }
72     }
73 ?>
74  
75     <tr><td colspan=2><span id="instructions">
76     <p><h3>Instructions</h3></p>
77     <p>This module allows you to block access to certain routes from specified extensions. You can do
78     bulk changes on this page, and you can individually change access to routes on the extension's page.</p>
79     <p>Note that Asterisk is incapable of having two identical routes and trying to force calls to use
80     the other route if one of them is banned by this module. <b>It will not work.</b> You must have
81     unique outbound routes for the proper selection to work.</p>
82     <p>If you wish to emulate this functionality, you can use the 'Redirect' function. Any number you type
83     in the 'Redirect' range will be PREPENDED to the number dialed, and the call will then be sent through
84     the dialplan again. For example:</p>
85     <p><ul>
86         <li>Route 1: Zap/1 matches 0|.</li>
87         <li>Route 2: Sip/Foo matches 1|.</li>
88     </ul></p>
89     <p>If you wanted to stop extension 100 from using Zap/1 at all, and send all his calls through Sip/Foo,
90     you would need to DENY 100 access to Route1, and create a NEW route, Route3:</p>
91     <p><ul><li>Route 3: Sip/Foo matches 9990|.</li></ul></p>
92     <p>In the 'Redirect' field, type '999'. When extension 100 dials 0123456, they match Route 1. Route 1 FAILS,
93     and then system invisibly changes the number dialed to be 9990123456 (note the '0' he dialled
94     originally is preserved, and you then strip 9990 from the front in Route 3), which matches Route 3
95     and the call is then sent via Sip/Foo.</p>
96     <p>Redirect rules are only checked if the route is DENIED.</p>
97     <p>You can set a Default Destination if calls are denied. If you wish to use something other than the
98     default in a specific instance, you can use a Redirect prefix and a Misc. Application.  Example: set
99     the redirect prefix to 000123, then create a Misc. Application and set the Feature Code to <b>_000123.</b>
100     (note the underscore at the start and the period at the end of the Feature Code - both are necessary),
101     then make the destination of the Misc. Application whatever you wish.</p>
102 <?php
103     echo "<p><h3>"._("Bulk Changes"); echo "</h3></p> ";
104     echo "<p>"._("Select a route and press Allow or Deny to set all extensions. If you enter a redirect prefix and click Redirect, the route will automatically be set to DENIED.");
105     echo  _("You can enter any normal range - comma or hyphen seperated. For example '123,125,200-300' will select extensions 123, 125 and any extensions between 200 and 300.");
106     echo "</p>\n ";
107     echo "<p>"._("Note that there is NO UNDO and changes take effect IMMEDIATELY. Don't click Redirect unless you have correct data in both text fields! Be cautious.")."</p>";
108     
109
110     echo '<form autocomplete="off" name="edit" action="'.$_SERVER['PHP_SELF'].'" method="post">';
111     echo "<input type=\"hidden\" name=\"display\" value=\"{$dispnum}\">\n";
112     echo "<input type=\"hidden\" name=\"action\" value=\"edit\">\n";
113               
114     $routes = rp_get_routes();
115
116     echo "<table>\n";
117     foreach ($routes as $r) {
118         print "<tr>\n<td>$r</td><td><input type='text' size=15 name='range_$r' value='All' ";
119         print "tabindex='".++$tabindex."'></td>\n";
120         print "<td><input type='submit' name=on_$r value=Allow></td><td><input type='submit' ";
121         print "name=off_$r value=Deny></td>\n";
122         print "<td><input type='text' size=15 name='rp-redir_$r' value='' tabindex='".++$tabindex."'>";
123         print "</td>\n<td><input type='submit' name='redirect_$r' value='Redirect'></td></tr>\n";
124     }
125     echo "</table><table>";
126     echo '<tr><td colspan="6"><br><h5>'._("Default Destination if denied").':<hr></h5></td></tr>';
127     $res=sql("SELECT faildest FROM routepermissions where exten='-1'", "getRow");
128     if (isset($res[0])) {
129         echo drawselects($res[0], 'faildest');
130     } else {
131         echo drawselects(0, 'faildest');
132     }
133     echo '<tr><td><input type="submit" name="update_dest" value="Change Destination"></td></tr>';
134     echo "</table>\n";
135
136 function rp_allow($route, $range) {
137     $extens = rp_get_extens();
138     if ($range == "All") {
139         foreach ($extens as $r=>$foo) {
140             rp_do($route, $r, "YES");
141         }
142     } else {
143         $rangearray = rp_range($range);
144         foreach ($rangearray as $r) {
145             if ($extens[$r] == "ok") {
146                 rp_do($route, $r, "YES");
147             }
148         }
149     }
150 }
151
152 function rp_deny($route, $range) {
153     $extens = rp_get_extens();
154     if ($range == "All") {
155         foreach ($extens as $r=>$foo) {
156             rp_do($route, $r, "NO");
157         }
158     } else {
159         $rangearray = rp_range($range);
160         foreach ($rangearray as $r) {
161             if ($extens[$r] == "ok") {
162                 rp_do($route, $r, "NO");
163             }
164         }
165     }
166 }
167
168 function rp_redir($route, $range, $redir) {
169     $extens = rp_get_extens();
170     if ($range == "All") {
171         foreach ($extens as $r=>$foo) {
172             rp_doredir($route, $r, "NO", $redir);
173         }
174     } else {
175         $rangearray = rp_range($range);
176         foreach ($rangearray as $r) {
177             if ($extens[$r] == "ok") {
178                 rp_doredir($route, $r, "NO", $redir);
179             }
180         }
181     }
182 }
183
184 function rp_do($route, $ext, $perm) {
185     global $db;
186     $Sext = mysql_real_escape_string($ext);
187     $Sroute = mysql_real_escape_string($route);
188     sql("DELETE FROM routepermissions WHERE exten='$Sext' AND routename='$Sroute'");
189     sql("INSERT INTO routepermissions (exten, routename, allowed) VALUES ('$Sext', '$Sroute', '$perm')");
190 }
191
192 function rp_doredir($route, $ext, $perm, $redir) {
193     global $db;
194     $Sext = mysql_real_escape_string($ext);
195     $Sroute = mysql_real_escape_string($route);
196     $Sredir = mysql_real_escape_string($redir);
197     sql("DELETE FROM routepermissions WHERE exten='$Sext' AND routename='$Sroute'");
198     sql("INSERT INTO routepermissions (exten, routename, allowed, faildest) VALUES ('$Sext', '$Sroute', '$perm', '$Sredir')");
199 }
200
201 function rp_range($range_str) {
202     $range_out = array();
203     // Strip spaces
204     $ranges = explode(",", str_replace(" ", "", $range_str));
205
206     foreach($ranges as $range) {
207         if(is_numeric($range)) {
208             // Just a number; add it to the list.
209             $range_out[] = $range;
210             $last_num = $range;
211         } else if(is_string($range)) {
212             if (preg_match("/(\d+)-(\d+)/", $range, $selection)) {
213                 $start = $selection[1];
214                 $end = $selection[2];
215     
216                 if($start > $end) {
217                     for($i = $start; $i >= $end; $i--) {
218                         $range_out[] = $i;
219                     }
220                 } else {
221                     for($i = $start; $i <= $end; $i++) {
222                         $range_out[] = $i;
223                     }
224                 }
225             }
226         }
227     }
228     return $range_out;
229 }
230
231 function rp_get_extens() {
232     global $db;
233          $extens = core_users_list();
234     foreach ($extens as $e) {
235         $ret[$e[0]]="ok";
236     }
237     return $ret;
238 }
239 ?>
240
Note: See TracBrowser for help on using the browser.