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

Revision 6558, 10.8 kB (checked in by p_lindheimer, 4 years ago)

re #3157 Merged revisions 6557 via svnmerge from
http://svn.freepbx.org/modules/branches/2.5

........

r6557 | p_lindheimer | 2008-09-04 07:12:30 -0700 (Thu, 04 Sep 2008) | 1 line


fixes #3157 sip info summary display wrong

........

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 (version_compare($astver, '1.4', 'ge')) {
80   $arr_all["Uptime"]="core show uptime";
81   $arr_all["Active Channel(s)"]="core show channels";
82   $arr_all["Subscribe/Notify"]="core show hints";
83   $arr_all["Voicemail users"]="voicemail show users";
84   $arr_channels["Active Channel(s)"]="core show channels";
85   $arr_subscriptions["Subscribe/Notify"]="core show hints";
86   $arr_voicemail["Voicemail users"]="voicemail show users";
87 }
88
89 ?>
90 </div>
91
92 <div class="rnav"><ul>
93 <?php 
94 foreach ($modes as $mode => $value) {
95   echo "<li><a id=\"".($extdisplay==$mode)."\" href=\"config.php?&type=".urlencode("tool")."&display=".urlencode($dispnum)."&extdisplay=".urlencode($mode)."\">"._($value)."</a></li>";
96 }
97 ?>
98 </ul></div>
99
100 <div class="content">
101 <h2><span class="headerHostInfo"><?php echo _("Asterisk (Ver. ").$astver."): "._($modes[$extdisplay])?></span></h2>
102
103 <form name="asteriskinfo" action="<?php  $_SERVER['PHP_SELF'] ?>" method="post">
104 <input type="hidden" name="display" value="asteriskinfo"/>
105 <input type="hidden" name="action" value="asteriskinfo"/>
106 <table>
107
108 <table class="box">
109 <?php
110 if (!$astman) {
111 ?>
112   <tr class="boxheader">
113     <td colspan="2" align="center"><h5><?php echo _("ASTERISK MANAGER ERROR")?><hr></h5></td>
114   </tr>
115     <tr class="boxbody">
116       <td>
117       <table border="0" >
118         <tr>
119           <td align="left">
120               <?php
121               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>";
122               ?>
123           </td>
124         </tr>
125       </table>
126       </td>
127     </tr>
128 <?php
129 } else {
130   if ($extdisplay != "summary") {
131     $arr="arr_".$extdisplay;
132     foreach ($$arr as $key => $value) {
133 ?>
134       <tr class="boxheader">
135         <td colspan="2" align="center"><h5><?php echo _("$key")?><hr></h5></td>
136       </tr>
137       <tr class="boxbody">
138         <td>
139         <table border="0" >
140           <tr>
141             <td>
142               <pre>
143                 <?php
144                 $response = $astman->send_request('Command',array('Command'=>$value));
145                 $new_value = $response['data'];
146                 echo ltrim($new_value,'Privilege: Command');
147                 ?>
148               </pre>
149             </td>
150           </tr>
151         </table>
152         </td>
153       </tr>
154     <?php
155       }
156     } else {
157   ?>
158       <tr class="boxheader">
159         <td colspan="2" align="center"><h5><?php echo _("Summary")?><hr></h5></td>
160       </tr>
161       <tr class="boxbody">
162         <td>
163         <table border="0">
164           <tr>
165             <td>
166               <?php echo buildAsteriskInfo(); ?>
167             </td>
168           </tr>
169         </table>
170       </td>
171     </tr>
172 <?php
173   }
174 }
175 ?>
176   </table>
177 <tr>
178   <td colspan="2"><h6><input name="Submit" type="submit" value="<?php echo _("Refresh")?>"></h6></td>
179 </tr>
180 </table>
181
182 <script language="javascript">
183 <!--
184 var theForm = document.asteriskinfo;
185 //-->
186 </script>
187 </form>
188
189 <?php
190
191 function convertActiveChannel($sipChannel, $channel = NULL){
192   if($channel == NULL){
193     print_r($sipChannel);
194     exit();
195     $sipChannel_arr = explode(' ', $sipChannel[1]);
196     if($sipChannel_arr[0] == 0){
197       return 0;
198     }else{
199       return count($sipChannel_arr[0]);
200     }
201   }elseif($channel == 'IAX2'){
202     $iaxChannel = $sipChannel;
203   }
204 }
205
206 function getActiveChannel($channel_arr, $channelType = NULL){
207   if(count($channel_arr) > 1){
208     if($channelType == NULL || $channelType == 'SIP'){
209       $sipChannel_arr = $channel_arr;
210       $sipChannel_arrCount = count($sipChannel_arr);
211       $sipChannel_string = $sipChannel_arr[$sipChannel_arrCount - 2];
212       $sipChannel = explode(' ', $sipChannel_string);
213       return $sipChannel[0];
214     }elseif($channelType == 'IAX2'){
215       $iax2Channel_arr = $channel_arr;
216       $iax2Channel_arrCount = count($iax2Channel_arr);
217       $iax2Channel_string = $iax2Channel_arr[$iax2Channel_arrCount - 2];
218       $iax2Channel = explode(' ', $iax2Channel_string);
219       return $iax2Channel[0];
220     }
221   }
222 }
223
224 function getRegistration($registration, $channelType = 'SIP'){
225   if($channelType == NULL || $channelType == 'SIP'){
226     $sipRegistration_arr = $registration;
227     $sipRegistration_count = count($sipRegistration_arr);
228     return $sipRegistration_count-3;
229    
230   }elseif($channelType == 'IAX2'){
231     $iax2Registration_arr = $registration;
232     $iax2Registration_count = count($iax2Registration_arr);
233     return $iax2Registration_count-3;
234   }
235 }
236
237 function getPeer($peer, $channelType = NULL){
238   global $astver_major, $astver_minor;
239   global $astver;
240   if(count($peer) > 1){
241     if($channelType == NULL || $channelType == 'SIP'){
242       $sipPeer = $peer;
243       $sipPeer_count = count($sipPeer);
244       $sipPeerInfo_arr['sipPeer_count'] = $sipPeer_count -3;
245       $sipPeerInfo_string = $sipPeer[$sipPeer_count -2];
246       $sipPeerInfo_arr2 = explode('[',$sipPeerInfo_string);
247       $sipPeerInfo_arr3 = explode(' ',$sipPeerInfo_arr2[1]);
248       if (version_compare($astver, '1.4', 'ge')) {
249         $sipPeerInfo_arr['online'] = $sipPeerInfo_arr3[1] + $sipPeerInfo_arr3[6];
250         $sipPeerInfo_arr['offline'] = $sipPeerInfo_arr3[3] + $sipPeerInfo_arr3[8];
251       }else{
252         $sipPeerInfo_arr['online'] = $sipPeerInfo_arr3[0];
253         $sipPeerInfo_arr['offline'] = $sipPeerInfo_arr3[3];
254       }
255       return $sipPeerInfo_arr;
256      
257     }elseif($channelType == 'IAX2'){
258       $iax2Peer = $peer;
259       $iax2Peer_count = count($iax2Peer);
260       $iax2PeerInfo_arr['iax2Peer_count'] = $iax2Peer_count -3;
261       $iax2PeerInfo_string = $iax2Peer[$iax2Peer_count -2];
262       $iax2PeerInfo_arr2 = explode('[',$iax2PeerInfo_string);
263       $iax2PeerInfo_arr3 = explode(' ',$iax2PeerInfo_arr2[1]);
264       $iax2PeerInfo_arr['online'] = $iax2PeerInfo_arr3[0];
265       $iax2PeerInfo_arr['offline'] = $iax2PeerInfo_arr3[2];
266       $iax2PeerInfo_arr['unmonitored'] = $iax2PeerInfo_arr3[4];
267       return $iax2PeerInfo_arr;
268     }
269   }
270 }
271
272 function buildAsteriskInfo(){
273   global $astman;
274   global $astver;
275  
276   $arr = array(
277     "Uptime" => "show uptime",
278     "Active SIP Channel(s)" => "sip show channels",
279     "Active IAX2 Channel(s)" => "iax2 show channels",
280     "Sip Registry" => "sip show registry",
281     "IAX2 Registry" => "iax2 show registry",
282     "Sip Peers" => "sip show peers", 
283     "IAX2 Peers" => "iax2 show peers",
284   );
285  
286   if (version_compare($astver, '1.4', 'ge')) {
287     $arr['Uptime'] = 'core show uptime';
288   }
289  
290   $htmlOutput  = '<div style="color:#000000;font-size:12px;margin:10px;">';
291   $htmlOutput  .= '<table border="1" cellpadding="10">';
292
293   foreach ($arr as $key => $value) {
294  
295     $response = $astman->send_request('Command',array('Command'=>$value));
296     $astout = explode("\n",$response['data']);
297
298     switch ($key) {
299       case 'Uptime':
300         $uptime = $astout;
301         $htmlOutput .= '<tr><td colspan="2">'.$uptime[1]."<br />".$uptime[2]."<br /></td>";
302         $htmlOutput .= '</tr>';
303       break;
304       case 'Active SIP Channel(s)':
305         $activeSipChannel = $astout;
306         $activeSipChannel_count = getActiveChannel($activeSipChannel, $channelType = 'SIP');
307         $htmlOutput .= '<tr>';
308         $htmlOutput .= "<td>Active Sip Channels: ".$activeSipChannel_count."</td>";
309       break;
310       case 'Active IAX2 Channel(s)':
311         $activeIAX2Channel = $astout;
312         $activeIAX2Channel_count = getActiveChannel($activeIAX2Channel, $channelType = 'IAX2');
313         $htmlOutput .= "<td>Active IAX2 Channels: ".$activeIAX2Channel_count."</td>";
314         $htmlOutput .= '</tr>';
315       break;
316       break;
317       case 'Sip Registry':
318         $sipRegistration = $astout;
319         $sipRegistration_count = getRegistration($sipRegistration, $channelType = 'SIP');
320         $htmlOutput .= '<tr>';
321         $htmlOutput .= "<td>SIP Registrations: ".$sipRegistration_count."</td>";
322       break;
323       case 'IAX2 Registry':
324         $iax2Registration = $astout;
325         $iax2Registration_count = getRegistration($iax2Registration, $channelType = 'IAX2');
326         $htmlOutput .= "<td>IAX2 Registrations: ".$iax2Registration_count."</td>";
327         $htmlOutput .= '</tr>';
328       break;
329       case 'Sip Peers':
330         $sipPeer = $astout;
331         $sipPeer_arr = getPeer($sipPeer, $channelType = 'SIP');
332         if($sipPeer_arr['offline'] != 0){
333           $sipPeerColor = 'red';
334         }else{
335           $sipPeerColor = '#000000';
336         }
337         $htmlOutput .= '<tr>';
338         $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>";
339       break;
340       case 'IAX2 Peers':
341         $iax2Peer = $astout;
342         $iax2Peer_arr = getPeer($iax2Peer, $channelType = 'IAX2');
343         if($iax2Peer_arr['offline'] != 0){
344           $iax2PeerColor = 'red';
345         }else{
346           $iax2PeerColor = '#000000';
347         }
348         $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>";
349         $htmlOutput .= '</tr>';
350       break;
351       default:
352       }
353     }
354   $htmlOutput .= '</table>';
355   return $htmlOutput."</div>";
356   }
357 ?>
Note: See TracBrowser for help on using the browser.