root/modules/branches/2.10/restart/functions.inc.php

Revision 11665, 3.2 kB (checked in by p_lindheimer, 2 years ago)

remove most eregi() re #4001

Line 
1 <?php
2 /* $Id: */
3 //Copyright (C) 2009 Ethan Schreoder (ethan.schroeder@schmoozecom.com)
4 //
5 //This program is free software; you can redistribute it and/or
6 //modify it under the terms of version 2 of the GNU General Public
7 //License as published by the Free Software Foundation.
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 //Both of these are used for switch on config.php
15
16 function restart_get_config($engine) {
17   global $db;
18   global $ext;
19   global $core_conf;
20   switch($engine) {
21     case "asterisk":
22         if (isset($core_conf) && is_a($core_conf, "core_conf")) {
23             $core_conf->addSipNotify('polycom-check-cfg',array('Event' => 'check-sync','Content-Length' => '0'));
24             $core_conf->addSipNotify('sipura-check-cfg',array('Event' => 'resync','Content-Length' => '0'));
25             $core_conf->addSipNotify('grandstream-check-cfg',array('Event' => 'sys-control'));
26             $core_conf->addSipNotify('cisco-check-cfg',array('Event' => 'check-sync','Content-Length' => '0'));
27             $core_conf->addSipNotify('reboot-snom',array('Event' => 'reboot','Content-Length' => '0'));
28             $core_conf->addSipNotify('aastra-check-cfg',array('Event' => 'check-sync','Content-Length' => '0'));
29             $core_conf->addSipNotify('aastra-xml',array('Event' => 'aastra-xml','Content-Length' => '0'));
30             $core_conf->addSipNotify('reboot-yealink',array('Event' => 'check-sync\;reboot=true','Content-Length' => '0'));
31         }
32
33     break;
34   }
35 }
36
37 function restart_get_devices($grp) {
38     global $db;
39
40     $sql = "SELECT * FROM devices";
41     $results = $db->getAll($sql);
42     if(DB::IsError($results))
43         $results = null;
44     foreach ($results as $val)
45         $tmparray[] = $val[0];
46     return $tmparray;
47 }
48
49 function get_device_useragent($device)  {
50     global $astman;
51     $response = $astman->send_request('Command',array('Command'=>"sip show peer $device"));
52     $astout = explode("\n",$response['data']);
53     $ua = "";
54     foreach($astout as $entry)  {
55     if(strstr(strtolower($entry), "useragent") !== false) {
56             list(,$value) = preg_split("/:/",$entry);
57             $ua = trim($value);
58         }
59     }
60     if($ua)  {
61
62         if(stristr($ua,"Aastra")) {
63             return "aastra";
64         }
65         if(stristr($ua,"Grandstream")) {
66             return "grandstream";
67         }
68         if(stristr($ua,"snom"))  {
69             return "snom";
70         }
71         if(stristr($ua,"Cisco"))  {
72             return "cisco";
73         }
74         if(stristr($ua,"Polycom"))  {
75             return "polycom";
76         }
77         if(stristr($ua,"Yealink"))  {
78             return "yealink";
79         }
80
81     }
82     return null;
83 }
84 function restart_device($device)  {
85     $ua = get_device_useragent($device);
86     switch($ua)  {
87         case "aastra":
88             sip_notify("aastra-check-cfg",$device);
89             break;
90         case "grandstream":
91             sip_notify("grandstream-check-cfg",$device);
92             break;
93         case "snom":
94             sip_notify("reboot-snom",$device);
95             break;
96         case "cisco":
97             sip_notify("cisco-check-cfg",$device);
98             break;
99         case "polycom":
100             sip_notify("polycom-check-cfg",$device);
101             break;
102         case "yealink":
103             sip_notify("reboot-yealink",$device);
104             break;
105         default:
106             break;
107
108     }
109 }
110 function sip_notify($event,$device)  {
111     global $astman;
112
113     $command = 'sip notify '.$event;
114     $command .= ' '.$device;
115
116     // Send command
117     $res = $astman->Command($command);
118 }
119
120 ?>
121
Note: See TracBrowser for help on using the browser.