-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapi.php
106 lines (86 loc) · 3.14 KB
/
api.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
<?php
/**
* Webmanager API
*/
$IDENT_FILE = "./id.conf";
$STATUS_FILE = "./status";
$NETSTAT_FILE = "./netconfig.dat";
$NETSTAT_SCRIPT = "./netconfig.sh";
$CONFIG_FILE = "./xhfc.conf";
$CONFIG_SCRIPT = "./xhfc.sh";
$COUNTER_SCRIPT = "./aclr.sh";
if (!isset($_REQUEST['task'])) die('{"status":"Parameter error"}');
$func = $_REQUEST['task'];
$res = "";
switch ($func) {
case "cps": // copy state
$file = fopen($STATUS_FILE, "r") or die('{"status":"Unable to read '.$STATUS_FILE.'!"}');
fclose($file);
echo file_get_contents($STATUS_FILE);
return;
case "clrcntrs": // clear counters
//shell_exec("echo clear=1 > ".$STATUS_FILE);
if (shell_exec($COUNTER_SCRIPT) == null) {
die('{"status":"Script execution error !!!!"}');
}
break;
case "rident": // read Identification
case "rnetset": // read NetSettings
case "rconfig": // read Configuration
$ret = (object)array();
if ($func == "rident")
$f = $IDENT_FILE;
else
if ($func == "rnetset")
$f = $NETSTAT_FILE;
else
$f = $CONFIG_FILE;
$file = fopen($f, "r") or die('{"status":"Unable to read '.$f.'!"}');
while(!feof($file)) {
$line = trim(fgets($file));
if ($line == "" || ($line[0] == "[" && $line[strlen($line) - 1] == "]")) continue;
$r = explode("=", $line);
$ret->$r[0] = $r[1];
}
fclose($file);
echo json_encode($ret);
return;
case "wnetset": // submit NetSettings
case "wconfig": // submit Configuration
$txt = "";
if ($func == "wnetset") {
$f = $NETSTAT_FILE;
$s = $NETSTAT_SCRIPT;
$txt .= "hostname=" . $_REQUEST['hn'] . "\n";
$txt .= "ip=" . $_REQUEST['ip'] . "\n";
$txt .= "gateway=" . $_REQUEST['gateway'] . "\n";
$txt .= "mask=" . $_REQUEST['mask'] . "\n";
$txt .= "dns=" . $_REQUEST['dns'] . "\n";
} else {
$f = $CONFIG_FILE;
$s = $CONFIG_SCRIPT;
$txt .= "[default]\n";
$txt .= "modes=" . $_REQUEST['modes'] . "\n";
$txt .= "ip_target=" . $_REQUEST['ip_target'] . "\n";
$txt .= "send_ms=" . $_REQUEST['send_ms'] . "\n";
$txt .= "jbuf=" . $_REQUEST['jbuf'] . "\n";
$txt .= "redu=" . $_REQUEST['redu'] . "\n";
$txt .= "billing=" . $_REQUEST['billing'] . "\n";
$txt .= "level_b=" . $_REQUEST['level_b'] . "\n";
$txt .= "ilim=" . $_REQUEST['ilim'] . "\n";
$txt .= "imp=" . $_REQUEST['imp'] . "\n";
$txt .= "rxgain=" . $_REQUEST['rxgain'] . "\n";
$txt .= "txgain=" . $_REQUEST['txgain'] . "\n";
}
$file = fopen($f, "w") or die('{"status":"Unable to open '.$f.'!"}');
fwrite($file, $txt);
fclose($file);
if (shell_exec("$s") == null) {
die('{"status":"'.$s.' - script execution error !!!!"}');
}
break;
default: die('{"status":"Unable to process command '.$func.'!"}');
}
$res = ($res == "") ? "OK" : $res;
echo '{"status":"'.$res.'"}';
?>