root/modules/branches/2.3/manager/page.manager.php

Revision 2968, 9.8 kB (checked in by qldrob, 7 years ago)

Wups. Left some debugging in there.

  • Property svn:mime-type set to text/html
  • Property svn:eol-style set to native
Line 
1 <?php
2 // Xavier Ourciere xourciere[at]propolys[dot]com
3 //
4 //This program is free software; you can redistribute it and/or
5 //modify it under the terms of the GNU General Public License
6 //as published by the Free Software Foundation; either version 2
7 //of the License, or (at your option) any later version.
8 //
9 //This program is distributed in the hope that it will be useful,
10 //but WITHOUT ANY WARRANTY; without even the implied warranty of
11 //MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 //GNU General Public License for more details.
13
14
15 $action = isset($_REQUEST['action'])?$_REQUEST['action']:'';
16 //the extension we are currently displaying
17 $managerdisplay = isset($_REQUEST['managerdisplay'])?$_REQUEST['managerdisplay']:'';
18 $name = isset($_REQUEST['name'])?$_REQUEST['name']:'';
19 $secret = isset($_REQUEST['secret'])?$_REQUEST['secret']:'';
20 $deny = isset($_REQUEST['deny'])?$_REQUEST['deny']:'';
21 $permit = isset($_REQUEST['permit'])?$_REQUEST['permit']:'';
22 $dispnum = "manager"; //used for switch on config.php
23
24 //if submitting form, update database
25 switch ($action) {
26   case "add":
27     $rights = manager_format_in($_REQUEST);
28     manager_add($name,$secret,$deny,$permit,$rights['read'],$rights['write']);
29     manager_gen_conf();
30     needreload();
31   break;
32   case "delete":
33     manager_del($managerdisplay);
34     manager_gen_conf();
35     needreload();
36   break;
37   case "edit":  //just delete and re-add
38     manager_del($name);
39     $rights = manager_format_in($_REQUEST);
40     manager_add($name,$secret,$deny,$permit,$rights['read'],$rights['write']);
41     manager_gen_conf();
42     needreload();
43   break;
44 }
45
46 $managers = manager_list();
47 ?>
48
49 </div>
50
51 <!-- right side menu -->
52 <div class="rnav"><ul>
53     <li><a id="<?php echo ($managerdisplay=='' ? 'current':'') ?>" href="config.php?type=tool&amp;display=<?php echo urlencode($dispnum)?>"><?php echo _("Add Manager")?></a></li>
54 <?php
55 if (isset($managers)) {
56   foreach ($managers as $manager) {
57     echo "<li><a id=\"".($managerdisplay==$manager['name'] ? 'current':'')."\" href=\"config.php?type=tool&amp;display=".urlencode($dispnum)."&managerdisplay=".$manager['name']."\">{$manager['name']}</a></li>";
58   }
59 }
60 ?>
61 <ul></div>
62
63
64 <div class="content">
65 <?php
66 if ($action == 'delete') {
67   echo '<br><h3>'._("Manager").' '.$managerdisplay.' '._("deleted").'!</h3><br><br><br><br><br><br><br><br>';
68 } else {
69   if ($managerdisplay){
70     //get details for this manager
71     $thisManager = manager_get($managerdisplay);
72     //create variables
73     extract(manager_format_out($thisManager));
74   }
75
76   $delURL = $_SERVER['PHP_SELF'].'?'.$_SERVER['QUERY_STRING'].'&action=delete';
77 ?>
78
79  
80 <?php   if ($managerdisplay){ ?>
81   <h2><?php echo _("Manager:")." ". $managerdisplay; ?></h2>
82   <p><a href="<?php echo $delURL ?>"><?php echo _("Delete Manager")?> <?php echo $managerdisplay; ?></a></p>
83 <?php   } else { ?>
84   <h2><?php echo _("Add Manager"); ?></h2>
85 <?php   }
86 ?>
87   <form autocomplete="off" name="editMan" action="<?php $_SERVER['PHP_SELF'] ?>" method="post" onsubmit="return checkConf();">
88   <input type="hidden" name="display" value="<?php echo $dispnum?>">
89   <input type="hidden" name="action" value="<?php echo ($managerdisplay ? 'edit' : 'add') ?>">
90   <table>
91   <tr><td colspan="2"><h5><?php echo ($managerdisplay ? _("Edit Manager") : _("Add Manager")) ?><hr></h5></td></tr>
92   <tr>
93     <td><a href="#" class="info"><?php echo _("Manager name:")?><span><?php echo _("Name of the manager without space.")?></span></a></td>
94     <td><input type="text" name="name" value="<?php echo (isset($name) ? $name : ''); ?>"></td>
95   </tr>
96   <tr>
97     <td><a href="#" class="info"><?php echo _("Manager secret:")?><span><?php echo _("Password for the manager.")?></span></a></td>
98     <td><input type="text" name="secret" value="<?php echo (isset($secret) ? $secret : ''); ?>"></td>
99   </tr>
100   <tr>
101     <td><a href="#" class="info"><?php echo _("Deny:")?><span><?php echo _("If you want to deny many hosts or networks, use & char as separator.<br/><br/>Example: 192.168.1.0/255.255.255.0&10.0.0.0/255.0.0.0")?></span></a></td>
102     <td><input size="56" type="text" name="deny" value="<?php echo (isset($deny) ? $deny : ''); ?>"></td>
103   </tr>
104   <tr>
105     <td><a href="#" class="info"><?php echo _("Permit:")?><span><?php echo _("If you want to permit many hosts or networks, use & char as separator. Look at deny example.")?></span></a></td>
106     <td><input size="56" type="text" name="permit" value="<?php echo (isset($permit) ? $permit : ''); ?>"></td>
107   </tr>
108   <tr>
109     <td colspan="2"><h5><?php echo _("Rights")?><hr></h5></td>
110   </tr>
111   <tr>
112     <td colspan="2">
113     <table>
114       <tr><th></th><th><?php echo _("Read")?></th><th><?php echo _("Write")?></th></tr>
115       <tr>
116         <td><a href="#" class="info">system<span><?php echo _("Check Asterisk documentation.")?></span></a></td>
117         <td><input type="checkbox" name="rsystem" <?php echo (isset($rsystem)?"checked":'');?>></input></td>
118         <td><input type="checkbox" name="wsystem" <?php echo (isset($wsystem)?"checked":'');?>></input></td>
119       </tr>
120       <tr>
121         <td><a href="#" class="info">call<span><?php echo _("Check Asterisk documentation.")?></span></a></td>
122         <td><input type="checkbox" name="rcall" <?php echo (isset($rcall)?"checked":'');?>></input></td>
123         <td><input type="checkbox" name="wcall" <?php echo (isset($wcall)?"checked":'');?>></input></td>
124       </tr>
125       <tr>
126         <td><a href="#" class="info">log<span><?php echo _("Check Asterisk documentation.")?></span></a></td>
127         <td><input type="checkbox" name="rlog" <?php echo (isset($rlog)?"checked":'');?>></input></td>
128         <td><input type="checkbox" name="wlog" <?php echo (isset($wlog)?"checked":'');?>></input></td>
129       </tr>
130       <tr>
131         <td><a href="#" class="info">verbose<span><?php echo _("Check Asterisk documentation.")?></span></a></td>
132         <td><input type="checkbox" name="rverbose" <?php echo (isset($rverbose)?"checked":'');?>></input></td>
133         <td><input type="checkbox" name="wverbose" <?php echo (isset($wverbose)?"checked":'');?>></input></td>
134       </tr>
135       <tr>
136         <td><a href="#" class="info">command<span><?php echo _("Check Asterisk documentation.")?></span></a></td>
137         <td><input type="checkbox" name="rcommand" <?php echo (isset($rcommand)?"checked":'');?>></input></td>
138         <td><input type="checkbox" name="wcommand" <?php echo (isset($wcommand)?"checked":'');?>></input></td>
139       </tr>
140       <tr>
141         <td><a href="#" class="info">agent<span><?php echo _("Check Asterisk documentation.")?></span></a></td>
142         <td><input type="checkbox" name="ragent" <?php echo (isset($ragent)?"checked":'');?>></input></td>
143         <td><input type="checkbox" name="wagent" <?php echo (isset($wagent)?"checked":'');?>></input></td>
144       </tr>
145       <tr>
146         <td><a href="#" class="info">user<span><?php echo _("Check Asterisk documentation.")?></span></a></td>
147         <td><input type="checkbox" name="ruser" <?php echo (isset($ruser)?"checked":'');?>></input></td>
148         <td><input type="checkbox" name="wuser" <?php echo (isset($wuser)?"checked":'');?>></input></td>
149       </tr>
150       <tr>
151         <td><a href="#" class="info">ALL<span><?php echo _("Check All/None.")?></span></a></td>
152         <td><input type="checkbox" name="rallnone" onclick="readCheck();"></input></td>
153         <td><input type="checkbox" name="wallnone" onclick="writeCheck();"></input></td>
154       </tr>
155     </table>
156     </td>
157   </tr>
158                
159   <tr>
160     <td colspan="2"><br><h6><input name="Submit" type="submit" value="<?php echo _("Submit Changes")?>"></h6></td>   
161   </tr>
162   </table>
163 <script language="javascript">
164 <!--
165
166 var theForm = document.editMan;
167
168 theForm.name.focus();
169
170 function writeCheck() {
171   if (theForm.wallnone.checked) {
172     theForm.wsystem.checked = true;
173     theForm.wcall.checked = true;
174     theForm.wlog.checked = true;
175     theForm.wverbose.checked = true;
176     theForm.wcommand.checked = true;
177     theForm.wagent.checked = true;
178     theForm.wuser.checked = true;
179   } else {
180     theForm.wsystem.checked = false;
181     theForm.wcall.checked = false;
182     theForm.wlog.checked = false;
183     theForm.wverbose.checked = false;
184     theForm.wcommand.checked = false;
185     theForm.wagent.checked = false;
186     theForm.wuser.checked = false;
187   }
188 }
189
190 function readCheck() {
191   if (theForm.rallnone.checked) {
192     theForm.rsystem.checked = true;
193     theForm.rcall.checked = true;
194     theForm.rlog.checked = true;
195     theForm.rverbose.checked = true;
196     theForm.rcommand.checked = true;
197     theForm.ragent.checked = true;
198     theForm.ruser.checked = true;
199   } else {
200     theForm.rsystem.checked = false;
201     theForm.rcall.checked = false;
202     theForm.rlog.checked = false;
203     theForm.rverbose.checked = false;
204     theForm.rcommand.checked = false;
205     theForm.ragent.checked = false;
206     theForm.ruser.checked = false;
207   }
208 }
209
210 function checkConf()
211 {
212   var errName = "<?php echo _('The manager name cannot be empty or may not have any space in it.'); ?>";
213   var errSecret = "<?php echo _('The manager secret cannot be empty.'); ?>";
214   var errReadWrite = "<?php echo _('The manager read and write properties cannot be empty.'); ?>";
215   var errDeny = "<?php echo _('The manager deny is not well formated.'); ?>";
216   var errPermit = "<?php echo _('The manager permit is not well formated.'); ?>";
217   var errRead = "<?php echo _('The manager read field is not well formated.'); ?>";
218   var errWrite = "<?php echo _('The manager write field is not well formated.'); ?>";
219
220   defaultEmptyOK = false;
221   if ((theForm.name.value.search(/\s/) >= 0) || (theForm.name.value.length == 0))
222     return warnInvalid(theForm.name, errName);
223   if (theForm.secret.value.length == 0)
224     return warnInvalid(theForm.name, errSecret);
225   if ((theForm.read.value.length == 0) || (theForm.write.value.length == 0))
226     return warnInvalid(theForm.name, errReadWrite);
227   // Only IP/MASK format are checked
228   if (theForm.deny.value.search(/\b(?:\d{1,3}\.){3}\d{1,3}\b\/\b(?:\d{1,3}\.){3}\d{1,3}\b(&\b(?:\d{1,3}\.){3}\d{1,3}\b\/\b(?:\d{1,3}\.){3}\d{1,3}\b)*$/))
229     return warnInvalid(theForm.name, errDeny);
230   if (theForm.permit.value.search(/\b(?:\d{1,3}\.){3}\d{1,3}\b\/\b(?:\d{1,3}\.){3}\d{1,3}\b(&\b(?:\d{1,3}\.){3}\d{1,3}\b\/\b(?:\d{1,3}\.){3}\d{1,3}\b)*$/))
231     return warnInvalid(theForm.name, errPermit);
232   return true;
233 }
234
235 //-->
236 </script>
237   </form>
238 <?php   
239 } //end if action == delGRP
240 ?>
Note: See TracBrowser for help on using the browser.