root/modules/branches/2.7/asteriskinfo/page.asteriskinfo.php

Revision 7792, 12.2 kB (checked in by xrobau, 4 years ago)

Add 'tabindex' variables to any module that references it, to avoid undefined variable warnings.

Line 
1 <?php /* $Id: page.asteriskinfo.php 2243 2006-08-12 17:13:17Z p_lindheimer $ */
2 //This file is part of FreePBX.
3 //
4 //    FreePBX is free software: you can redistribute it and/or modify
5 //    it under the terms of the GNU General Public License as published by
6 //    the Free Software Foundation, either version 2 of the License, or
7 //    (at your option) any later version.
8 //
9 //    FreePBX 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 //    You should have received a copy of the GNU General Public License
15 //    along with FreePBX.  If not, see <http://www.gnu.org/licenses/>.
16 //
17 //    Copyright (C) 2006 Astrogen LLC
18 //
19 $dispnum = 'asteriskinfo'; //used for switch on config.php
20
21 $tabindex = 0;
22
23 $action = isset($_REQUEST['action'])?$_REQUEST['action']:'';
24 $extdisplay = isset($_REQUEST['extdisplay'])?$_REQUEST['extdisplay']:'summary';
25 $chan_dahdi = ast_with_dahdi();
26
27     $modesummary = _("Summary");
28     $moderegistries = _("Registries");
29     $modechannels = _("Channels");
30     $modepeers = _("Peers");
31     $modesip = _("Sip Info");
32     $modeiax = _("IAX Info");
33     $modeconferences = _("Conferences");
34     $modesubscriptions = _("Subscriptions");
35     $modeall = _("Full Report");
36     
37     $uptime = _("Uptime");
38     $activechannels = _("Active Channel(s)");
39     $sipchannels = _("Sip Channel(s)");
40     $iax2channels = _("IAX2 Channel(s)");
41     $iax2peers = _("IAX2 Peers");
42     $sipregistry = _("Sip Registry");
43     $sippeers = _("Sip Peers");
44     $iax2registry = _("IAX2 Registry");
45     $subscribenotify = _("Subscribe/Notify");
46     if ($chan_dahdi){
47         $zapteldriverinfo = _("DAHDI driver info");
48     } else {
49         $zapteldriverinfo = _("Zaptel driver info");
50     }
51     $conferenceinfo = _("Conference Info");
52     $voicemailusers = _("Voicemail Users");
53
54 $modes = array(
55     "summary" => $modesummary,
56     "registries" => $moderegistries,
57     "channels" => $modechannels,
58     "peers" => $modepeers,
59     "sip" => $modesip,
60     "iax" => $modeiax,
61     "conferences" => $modeconferences,
62     "subscriptions" => $modesubscriptions,
63     "voicemail" => $voicemailusers,
64     "all" => $modeall
65 );
66 $arr_all = array(
67     $uptime => "show uptime",
68     $activechannels => "show channels",
69     $sipchannels => "sip show channels",
70     $iax2channels => "iax2 show channels",
71     $sipregistry => "sip show registry",
72     $sippeers => "sip show peers",
73     $iax2registry => "iax2 show registry",
74     $iax2peers => "iax2 show peers",
75     $subscribenotify => "show hints",
76     $zapteldriverinfo => "zap show channels",
77     $conferenceinfo => "meetme",
78     $voicemailusers => "show voicemail users",
79 );
80 $arr_registries = array(
81     $sipregistry => "sip show registry",
82     $iax2registry => "iax2 show registry",
83 );
84 $arr_channels = array(
85     $activechannels => "show channels",
86     $sipchannels => "sip show channels",
87     $iax2channels => "iax2 show channels",
88 );
89 $arr_peers = array(
90     $sippeers => "sip show peers",
91     $iax2peers => "iax2 show peers",
92 );
93 $arr_sip = array(
94     $sipregistry => "sip show registry",
95     $sippeers => "sip show peers",
96 );
97 $arr_iax = array(
98     $iax2registry => "iax2 show registry",
99     $iax2peers => "iax2 show peers",
100 );
101 $arr_conferences = array(
102     $conferenceinfo => "meetme",
103 );
104 $arr_subscriptions = array(
105     $subscribenotify => "show hints"
106 );
107 $arr_voicemail = array(
108     $voicemailusers => "show voicemail users",
109 );
110
111 $engineinfo = engine_getinfo();
112 $astver $engineinfo['version'];
113
114 if (version_compare($astver, '1.4', 'ge')) {
115     $arr_all[$uptime]="core show uptime";
116     $arr_all[$activechannels]="core show channels";
117     $arr_all[$subscribenotify]="core show hints";
118     $arr_all[$voicemailusers]="voicemail show users";
119     $arr_channels[$activechannels]="core show channels";
120     $arr_subscriptions[$subscribenotify]="core show hints";
121     $arr_voicemail[$voicemailusers]="voicemail show users";
122 }
123
124 if ($chan_dahdi){
125     $arr_all[$zapteldriverinfo]="dahdi show channels";
126 }
127 if ($chan_dahdi){
128     $arr_all[$zapteldriverinfo]="dahdi show channels";
129 }
130 ?>
131 </div>
132
133 <div class="rnav"><ul>
134 <?php
135 foreach ($modes as $mode => $value) {
136     echo "<li><a id=\"".($extdisplay==$mode)."\" href=\"config.php?&type=".urlencode("tool")."&display=".urlencode($dispnum)."&extdisplay=".urlencode($mode)."\">"._($value)."</a></li>";
137 }
138 ?>
139 </ul></div>
140
141 <div class="content">
142 <h2><span class="headerHostInfo"><?php echo _("Asterisk (Ver. ").$astver."): "._($modes[$extdisplay])?></span></h2>
143
144 <form name="asteriskinfo" action="<?php  $_SERVER['PHP_SELF'] ?>" method="post">
145 <input type="hidden" name="display" value="asteriskinfo"/>
146 <input type="hidden" name="action" value="asteriskinfo"/>
147 <table>
148
149 <table class="box">
150 <?php
151 if (!$astman) {
152 ?>
153     <tr class="boxheader">
154         <td colspan="2" align="center"><h5><?php echo _("ASTERISK MANAGER ERROR")?><hr></h5></td>
155     </tr>
156         <tr class="boxbody">
157             <td>
158             <table border="0" >
159                 <tr>
160                     <td align="left">
161                             <?php
162                             echo "<br>"._("The module was unable to connect to the Asterisk manager.<br>Make sure Asterisk is running and your manager.conf settings are proper.<br><br>");
163                             ?>
164                     </td>
165                 </tr>
166             </table>
167             </td>
168         </tr>
169 <?php
170 } else {
171     if ($extdisplay != "summary") {
172         $arr="arr_".$extdisplay;
173         foreach ($$arr as $key => $value) {
174 ?>
175             <tr class="boxheader">
176                 <td colspan="2" align="center"><h5><?php echo _("$key")?><hr></h5></td>
177             </tr>
178             <tr class="boxbody">
179                 <td>
180                 <table border="0" >
181                     <tr>
182                         <td>
183                             <pre>
184                                 <?php
185                                 $response = $astman->send_request('Command',array('Command'=>$value));
186                                 $new_value = $response['data'];
187                                 echo ltrim($new_value,'Privilege: Command');
188                                 ?>
189                             </pre>
190                         </td>
191                     </tr>
192                 </table>
193                 </td>
194             </tr>
195         <?php
196             }
197         } else {
198     ?>
199             <tr class="boxheader">
200                 <td colspan="2" align="center"><h5><?php echo _("Summary")?><hr></h5></td>
201             </tr>
202             <tr class="boxbody">
203                 <td>
204                 <table border="0">
205                     <tr>
206                         <td>
207                             <?php echo buildAsteriskInfo(); ?>
208                         </td>
209                     </tr>
210                 </table>
211             </td>
212         </tr>
213 <?php
214     }
215 }
216 ?>
217     </table>
218 <tr>
219     <td colspan="2"><h6><input name="Submit" type="submit" value="<?php echo _("Refresh")?>" tabindex="<?php echo ++$tabindex;?>"></h6></td>
220 </tr>
221 </table>
222
223 <script language="javascript">
224 <!--
225 var theForm = document.asteriskinfo;
226 //-->
227 </script>
228 </form>
229
230 <?php
231
232 function convertActiveChannel($sipChannel, $channel = NULL){
233     if($channel == NULL){
234         print_r($sipChannel);
235         exit();
236         $sipChannel_arr = explode(' ', $sipChannel[1]);
237         if($sipChannel_arr[0] == 0){
238             return 0;
239         }else{
240             return count($sipChannel_arr[0]);
241         }
242     }elseif($channel == 'IAX2'){
243         $iaxChannel = $sipChannel;
244     }
245 }
246
247 function getActiveChannel($channel_arr, $channelType = NULL){
248     if(count($channel_arr) > 1){
249         if($channelType == NULL || $channelType == 'SIP'){
250             $sipChannel_arr = $channel_arr;
251             $sipChannel_arrCount = count($sipChannel_arr);
252             $sipChannel_string = $sipChannel_arr[$sipChannel_arrCount - 2];
253             $sipChannel = explode(' ', $sipChannel_string);
254             return $sipChannel[0];
255         }elseif($channelType == 'IAX2'){
256             $iax2Channel_arr = $channel_arr;
257             $iax2Channel_arrCount = count($iax2Channel_arr);
258             $iax2Channel_string = $iax2Channel_arr[$iax2Channel_arrCount - 2];
259             $iax2Channel = explode(' ', $iax2Channel_string);
260             return $iax2Channel[0];
261         }
262     }
263 }
264
265 function getRegistration($registration, $channelType = 'SIP'){
266     if($channelType == NULL || $channelType == 'SIP'){
267         $sipRegistration_arr = $registration;
268         $sipRegistration_count = count($sipRegistration_arr);
269         return $sipRegistration_count-3;
270         
271     }elseif($channelType == 'IAX2'){
272         $iax2Registration_arr = $registration;
273         $iax2Registration_count = count($iax2Registration_arr);
274         return $iax2Registration_count-3;
275     }
276 }
277
278 function getPeer($peer, $channelType = NULL){
279     global $astver_major, $astver_minor;
280     global $astver;
281     if(count($peer) > 1){   
282         if($channelType == NULL || $channelType == 'SIP'){
283             $sipPeer = $peer;
284             $sipPeer_count = count($sipPeer);
285             $sipPeerInfo_arr['sipPeer_count'] = $sipPeer_count -3;
286             $sipPeerInfo_string = $sipPeer[$sipPeer_count -2];
287             $sipPeerInfo_arr2 = explode('[',$sipPeerInfo_string);
288             $sipPeerInfo_arr3 = explode(' ',$sipPeerInfo_arr2[1]);
289             if (version_compare($astver, '1.4', 'ge')) {
290                 $sipPeerInfo_arr['online'] = $sipPeerInfo_arr3[1] + $sipPeerInfo_arr3[6];
291                 $sipPeerInfo_arr['offline'] = $sipPeerInfo_arr3[3] + $sipPeerInfo_arr3[8];
292             }else{
293                 $sipPeerInfo_arr['online'] = $sipPeerInfo_arr3[0];
294                 $sipPeerInfo_arr['offline'] = $sipPeerInfo_arr3[3];
295             }
296             return $sipPeerInfo_arr;
297             
298         }elseif($channelType == 'IAX2'){
299             $iax2Peer = $peer;
300             $iax2Peer_count = count($iax2Peer);
301             $iax2PeerInfo_arr['iax2Peer_count'] = $iax2Peer_count -3;
302             $iax2PeerInfo_string = $iax2Peer[$iax2Peer_count -2];
303             $iax2PeerInfo_arr2 = explode('[',$iax2PeerInfo_string);
304             $iax2PeerInfo_arr3 = explode(' ',$iax2PeerInfo_arr2[1]);
305             $iax2PeerInfo_arr['online'] = $iax2PeerInfo_arr3[0];
306             $iax2PeerInfo_arr['offline'] = $iax2PeerInfo_arr3[2];
307             $iax2PeerInfo_arr['unmonitored'] = $iax2PeerInfo_arr3[4];
308             return $iax2PeerInfo_arr;
309         }
310     }
311 }
312
313 function buildAsteriskInfo(){
314     global $astman;
315     global $astver;
316     $uptime = _("Uptime: ");
317     $activesipchannels = _("Active SIP Channel(s): ");
318     $activeiax2channels = _("Active IAX2 Channel(s): ");
319     $sipregistry = _("Sip Registry: ");
320     $iax2registry = _("IAX2 Registry: ");
321     $sippeers = _("Sip Peers: ");
322     $iax2peers = _("IAX2 Peers: ");
323
324     
325     $arr = array(
326         $uptime => "show uptime",
327         $activesipchannels => "sip show channels",
328         $activeiax2channels => "iax2 show channels",
329         $sipregistry => "sip show registry",
330         $iax2registry => "iax2 show registry",
331         $sippeers => "sip show peers",
332         $iax2peers => "iax2 show peers",   
333     );
334     
335     if (version_compare($astver, '1.4', 'ge')) {
336         $arr[$uptime] = 'core show uptime';
337     }
338     
339     $htmlOutput  = '<div style="color:#000000;font-size:12px;margin:10px;">';
340     $htmlOutput  .= '<table border="1" cellpadding="10">';
341
342     foreach ($arr as $key => $value) {
343     
344         $response = $astman->send_request('Command',array('Command'=>$value));
345         $astout = explode("\n",$response['data']);
346
347         switch ($key) {
348             case $uptime:
349                 $uptime = $astout;
350                 $htmlOutput .= '<tr><td colspan="2">'.$uptime[1]."<br />".$uptime[2]."<br /></td>";
351                 $htmlOutput .= '</tr>';
352             break;
353             case $activesipchannels:
354                 $activeSipChannel = $astout;
355                 $activeSipChannel_count = getActiveChannel($activeSipChannel, $channelType = 'SIP');
356                 $htmlOutput .= '<tr>';
357                 $htmlOutput .= "<td>".$key.$activeSipChannel_count."</td>";
358             break;
359             case $activeiax2channels:
360                 $activeIAX2Channel = $astout;
361                 $activeIAX2Channel_count = getActiveChannel($activeIAX2Channel, $channelType = 'IAX2');
362                 $htmlOutput .= "<td>".$key.$activeIAX2Channel_count."</td>";
363                 $htmlOutput .= '</tr>';
364             break;
365             break;
366             case $sipregistry:
367                 $sipRegistration = $astout;
368                 $sipRegistration_count = getRegistration($sipRegistration, $channelType = 'SIP');
369                 $htmlOutput .= '<tr>';
370                 $htmlOutput .= "<td>".$key.$sipRegistration_count."</td>";
371             break;
372             case $iax2registry:
373                 $iax2Registration = $astout;
374                 $iax2Registration_count = getRegistration($iax2Registration, $channelType = 'IAX2');
375                 $htmlOutput .= "<td>".$key.$iax2Registration_count."</td>";
376                 $htmlOutput .= '</tr>';
377             break;
378             case $sippeers:
379                 $sipPeer = $astout;
380                 $sipPeer_arr = getPeer($sipPeer, $channelType = 'SIP');
381                 if($sipPeer_arr['offline'] != 0){
382                     $sipPeerColor = 'red';
383                 }else{
384                     $sipPeerColor = '#000000';
385                 }
386                 $htmlOutput .= '<tr>';
387                 $htmlOutput .= "<td>".$key."<br />&nbsp;&nbsp;&nbsp;&nbsp;"._("Online: ").$sipPeer_arr['online']."<br />&nbsp;&nbsp;&nbsp;&nbsp;"._("Offline: ")."<span style=\"color:".$sipPeerColor.";font-weight:bold;\">".$sipPeer_arr['offline']."</span></td>";
388             break;
389             case $iax2peers:
390                 $iax2Peer = $astout;
391                 $iax2Peer_arr = getPeer($iax2Peer, $channelType = 'IAX2');
392                 if($iax2Peer_arr['offline'] != 0){
393                     $iax2PeerColor = 'red';
394                 }else{
395                     $iax2PeerColor = '#000000';
396                 }
397                 $htmlOutput .= "<td>".$key."<br />&nbsp;&nbsp;&nbsp;&nbsp;"._("Online: ").$iax2Peer_arr['online']."<br />&nbsp;&nbsp;&nbsp;&nbsp;"._("Offline: ")."<span style=\"color:".$iax2PeerColor.";font-weight:bold;\">".$iax2Peer_arr['offline']."</span><br />&nbsp;&nbsp;&nbsp;&nbsp;"._("Unmonitored: ").$iax2Peer_arr['unmonitored']."</td>";
398                 $htmlOutput .= '</tr>';
399             break;
400             default:
401             }
402         }
403     $htmlOutput .= '</table>';
404     return $htmlOutput."</div>";
405     }
406 ?>
407
Note: See TracBrowser for help on using the browser.