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

Revision 4626, 11.1 kB (checked in by p_lindheimer, 5 years ago)

#2187 fix for Asterisk 1.4 changes, thx robert

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