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

Revision 13211, 15.1 kB (checked in by p_lindheimer, 1 year ago)

fixes #5523 make sure summary screen displayed if nothing specified

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