forked from tsawyer/allmon
-
Notifications
You must be signed in to change notification settings - Fork 0
/
connect.php
66 lines (59 loc) · 1.86 KB
/
connect.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
<?php
include('allmon.inc.php');
// Filter and validate user input
$node = @trim(strip_tags($_POST['node']));
$perm = @trim(strip_tags($_POST['perm']));
$button = @trim(strip_tags($_POST['button']));
$localnode = @trim(strip_tags($_POST['localnode']));
if (! preg_match("/^\d+$/",$node)) {
die("Please provide node number to connect.\n");
}
if (! preg_match("/^\d+$/",$localnode)) {
die("Please provide local node number.\n");
}
// Read configuration file
if (!file_exists('allmon.ini')) {
die("Couldn't load ini file.\n");
}
$config = parse_ini_file('allmon.ini', true);
#print "<pre>"; print_r($config); print "</pre>";
// Open a socket to Asterisk Manager
$fp = connect($config[$localnode]['host']);
login($fp, $config[$localnode]['user'], $config[$localnode]['passwd']);
// Which ilink command?
if ($button == 'connect') {
if ($perm == 'on') {
$ilink = 13;
print "<b>Permanent Connecting $node to $localnode</b>";
} else {
$ilink = 3;
print "<b>Connecting $node to $localnode</b>";
}
} elseif ($button == 'monitor') {
if ($perm == 'on') {
$ilink = 12;
print "<b>Permanent Monitoring $node from $localnode</b>";
} else {
$ilink = 2;
print "<b>Monitoring $node from $localnode</b>";
}
} elseif ($button == 'localmonitor') {
if ($perm == 'on') {
$ilink = 18;
print "<b>Permanent Local Monitoring $node from $localnode</b>";
} else {
$ilink = 8;
print "<b>Local Monitoring $node from $localnode</b>";
}
}
// Do it
if ((@fwrite($fp,"ACTION: COMMAND\r\nCOMMAND: rpt cmd $localnode ilink $ilink $node\r\n\r\n")) > 0 ) {
// Get response, but do nothing with it
$rptStatus = get_response($fp);
#print "<pre>===== start =====\n";
#print_r($rptStatus);
#print "===== end =====\n</pre>";
} else {
die("Command failed!\n");
}
?>