-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathfunctions.inc.php
140 lines (124 loc) · 3.9 KB
/
functions.inc.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
<?php
/* $Id: */
if (!defined('FREEPBX_IS_AUTH')) { die('No direct script access allowed'); }
// License for all code of this FreePBX module can be found in the license file inside the module directory
// Copyright 2013 Schmooze Com Inc.
//
//Both of these are used for switch on config.php
function restart_get_config($engine) {
global $db;
global $ext;
global $core_conf;
switch($engine) {
case "asterisk":
if (isset($core_conf) && is_a($core_conf, "core_conf")) {
$core_conf->addSipNotify('polycom-check-cfg',array('Event' => 'check-sync'));
$core_conf->addSipNotify('sipura-check-cfg',array('Event' => 'resync'));
$core_conf->addSipNotify('grandstream-check-cfg',array('Event' => 'check-sync'));
$core_conf->addSipNotify('cisco-check-cfg',array('Event' => 'check-sync'));
$core_conf->addSipNotify('reboot-snom',array('Event' => 'reboot'));
$core_conf->addSipNotify('aastra-check-cfg',array('Event' => 'check-sync'));
$core_conf->addSipNotify('aastra-xml',array('Event' => 'aastra-xml'));
$core_conf->addSipNotify('spa-reboot',array('Event' => 'reboot'));
$core_conf->addSipNotify('linksys-cold-restart',array('Event' => 'reboot_now'));
$core_conf->addSipNotify('linksys-warm-restart',array('Event' => 'restart_now'));
$core_conf->addSipNotify('reboot-yealink',array('Event' => 'check-sync\;reboot=false'));
$core_conf->addSipNotify('panasonic-check-cfg',array('Event' => 'check-sync'));
$core_conf->addSipNotify('audiocodes-check-cfg',array('Event' => 'check-sync'));
$core_conf->addSipNotify('algo-check-cfg',array('Event' => 'check-sync'));
$core_conf->addSipNotify('cyberdata-check-cfg',array('Event' => 'check-sync'));
}
break;
}
}
function restart_get_devices($grp) {
global $db;
$sql = "SELECT * FROM devices";
$results = $db->getAll($sql);
if(DB::IsError($results))
$results = null;
foreach ($results as $val)
$tmparray[] = $val[0];
return $tmparray;
}
function get_device_useragent($device) {
global $astman;
$response = $astman->send_request('Command',array('Command'=>"sip show peer $device"));
$astout = explode("\n",$response['data']);
$ua = "";
foreach($astout as $entry) {
if(strstr(strtolower($entry), "useragent") !== false) {
list(,$value) = preg_split("/:/",$entry);
$ua = trim($value);
}
}
if($ua) {
if(stristr($ua,"Aastra")) {
return "aastra";
}
if(stristr($ua,"Grandstream")) {
return "grandstream";
}
if(stristr($ua,"snom")) {
return "snom";
}
if(stristr($ua,"Cisco")) {
return "cisco";
}
if(stristr($ua,"Polycom")) {
return "polycom";
}
if(stristr($ua,"Yealink")) {
return "yealink";
}
}
return null;
}
function restart_device($device) {
$ua = get_device_useragent($device);
switch($ua) {
case "aastra":
sip_notify("aastra-check-cfg",$device);
break;
case "grandstream":
sip_notify("grandstream-check-cfg",$device);
break;
case "snom":
sip_notify("reboot-snom",$device);
break;
case "cisco":
sip_notify("cisco-check-cfg",$device);
break;
case "polycom":
sip_notify("polycom-check-cfg",$device);
break;
case "yealink":
sip_notify("reboot-yealink",$device);
break;
default:
break;
}
}
function sip_notify($event,$device) {
global $astman;
$command = 'sip notify '.$event;
$command .= ' '.$device;
// Send command
$res = $astman->Command($command);
}
function restart_module_install_check_callback($mods = array()) {
global $active_modules;
$ret = array();
$current_mod = 'restart';
$conflicting_mods = array('endpointman','endpoint');
foreach($mods as $k => $v) {
if (in_array($k, $conflicting_mods) && !in_array($active_modules[$current_mod]['status'],array(MODULE_STATUS_NOTINSTALLED,MODULE_STATUS_BROKEN))) {
$ret[] = $v['name'];
}
}
if (!empty($ret)) {
$modules = implode(',',$ret);
return _('Failed to install ' . $modules . ' due to the following conflicting module(s): ' . $active_modules[$current_mod]['displayname']);
}
return TRUE;
}