This repository has been archived by the owner on Mar 21, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 16
/
allmon.inc.php
76 lines (68 loc) · 1.82 KB
/
allmon.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
<?php
error_reporting(0);
// Reads output lines from Asterisk Manager
function get_response($fp, $actionID) {
while (TRUE) {
$str = fgets($fp);
# Looking for our actionID
if ("ActionID: $actionID" == trim($str)) {
$response = $str;
while (TRUE) {
$str = fgets($fp);
#if (strlen(trim($str)) != 0 ) {
if ($str != "\r\n") {
$response .= $str;
} else {
return($response);
}
}
}
}
}
function AMIconnect($host) {
// Set default port if not provided
$arr = explode(":", $host);
$ip = $arr[0];
if (isset($arr[1])) {
$port = $arr[1];
} else {
$port = 5038;
}
// Open a manager socket.
$fp = @fsockopen($ip, $port, $errno, $errstr, 5);
#print "parms: $ip $port $errno $errstr";
return ($fp);
}
function AMIlogin($fp, $user, $password) {
// Login
$actionID = $user . $password;
fwrite($fp,"ACTION: LOGIN\r\nUSERNAME: $user\r\nSECRET: $password\r\nEVENTS: 0\r\nActionID: $actionID\r\n\r\n");
$login = get_response($fp, $actionID);
if (preg_match("/Authentication accepted/", $login) == 1) {
return(TRUE);
} else {
return(FALSE);
}
}
function getAstInfo($nodeNum, $node=array()) {
global $astdb;
#print '<pre>'; print_r($nodeNum); print '</pre>';
// Build info string
//if (array_key_exists($nodeNum, $astdb)) {
if (isset($astdb[$nodeNum])) {
$dbNode = $astdb[$nodeNum];
$info = $dbNode[1] . ' ' . $dbNode[2] . ' ' . $dbNode[3];
} elseif ($nodeNum > 3000000) {
$info = "Echolink";
} elseif (!empty($node['ip'])) {
if (strlen(trim($node['ip'])) > 3) {
$info = '(' . $node['ip'] . ')';
} else {
$info = ' ';
}
} else {
$info = ' ';
}
return $info;
}
?>