This repository was archived by the owner on Jul 27, 2024. It is now read-only.
Repository navigation
Expand file tree
/
Copy pathdata.php
More file actions
151 lines (134 loc) · 3.92 KB
/
Copy pathdata.php
File metadata and controls
151 lines (134 loc) · 3.92 KB
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
141
142
143
144
145
146
147
148
149
150
151
<?php
// Default secret for password test
$secret='$6$rounds=10000$YO2pGg47XU$AUgMTnkoPxJdvugNa7L78mYEymYmAJKFckoV/D8e3aqiiodAgYDi/DEE/dL4DLBHMn2NelH5IuhQ/sFb4NEsi1';
function rndstr()
{
$characters = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
$randstring = '';
for ($i = 0; $i < 10; $i++) {
$randstring .= $characters[rand(0, strlen($characters)-1)];
}
return $randstring;
}
function semi_hash_equals ($str1, $str2) {
// Insecure?
$res = 0;
if (strlen($str1) != strlen($str2)) { die("hash length mismatch"); }
for ($i=0; $i<strlen($str1); $i++) {
$res = $str1[$i] - $str2[$i];
}
return($res);
}
// Detect CLI mode
if (isset($argv)) {
if (!isset($argv[1])) {
echo("--password xxx : encrypt password\n");
exit(0);
}
if ($argv[1] == "--password" && isset($argv[2])) {
echo "\$secret='".crypt(trim($argv[2]),'$6$rounds=10000$'.rndstr().'$')."';\n";
exit(0);
}
exit(0);
}
function getsysint($path) {
$data = "";
$f = fopen($path, "r");
if ($f) {
$data = trim(fgets($f));
fclose($f);
}
return($data);
}
function checkauth() {
if (!isset($_SESSION{'authenticated'}) || $_SESSION{'authenticated'} != 1) {
die("Security violation");
}
}
function runcmd ($cmd) {
$arr = array();
$f = popen($cmd, "r");
if ($f) {
while(!feof($f)) {
$arr{'output'} .= fread($f, 1024);
}
pclose($f);
}
return($arr);
}
session_start();
header('Content-Type: application/json');
switch($_POST{'action'}) {
case 'prelogin':
$arr = array();
$arr{'action'} = "prelogin"; //debug
if (isset($_SESSION{'login'})) {
$arr{'login'} = $_SESSION{'login'};
}
if (isset($_SESSION{'authenticated'})) {
$arr{'authenticated'} = $_SESSION{'authenticated'};
}
echo json_encode($arr);
break;
case 'login':
$arr = array();
$arr{'status'} = "Login or password not set";
if (isset($_POST{'login'}) && isset($_POST{'password'})) {
// We should use hash_equals
if ($_POST{'login'} == "admin" && !semi_hash_equals(crypt($_POST{'password'}, $secret), $secret)) {
$arr{'status'} = "OK";
$_SESSION{'authenticated'} = 1;
$_SESSION{'login'} = $_POST{'login'};
} else {
$arr{'status'} = "Login incorrect";
}
}
echo json_encode($arr);
break;
case 'logout':
$arr = array();
unset($_SESSION{'authenticated'});
echo json_encode($arr);
break;
case 'stat':
checkauth();
$arr = runcmd('accel-cmd show stat');
echo json_encode($arr);
break;
case 'users':
checkauth();
$arr = runcmd('accel-cmd show sessions');
$output2 = preg_replace('/\n/m', "</td></tr>\n<tr><td>",$arr{'output'});
//$output2 = preg_replace('/^/m','<tr><td>',$output2);
$output2 = preg_replace('/\|/m','</td><td>',$output2);
$output2 = preg_replace('/<tr><td>$/','',$output2); // final
$final .= '<table id="tusers" class="cell-border"><tbody><tr><td>' . $output2 . '</tbody></table>';
$arr{'output'} = $final;
echo json_encode($arr);
break;
case 'killsoft':
checkauth();
$arr = runcmd('accel-cmd terminate if '.escapeshellcmd(trim($_POST{'interface'}))." soft");
echo json_encode($arr);
break;
case 'killhard':
checkauth();
$arr = runcmd('accel-cmd terminate if '.escapeshellcmd(trim($_POST{'interface'}))." hard");
echo json_encode($arr);
break;
case 'ifstat':
checkauth();
$arr = array();
$arr{'stamp'} = time()*1000;
$arr{'rxbytes'} = intval(getsysint("/sys/class/net/".escapeshellcmd(trim($_POST{'interface'}))."/statistics/rx_bytes"));
$arr{'txbytes'} = intval(getsysint("/sys/class/net/".escapeshellcmd(trim($_POST{'interface'}))."/statistics/tx_bytes"));
$arr{'rxpackets'} = intval(getsysint("/sys/class/net/".escapeshellcmd(trim($_POST{'interface'}))."/statistics/rx_packets"));
$arr{'txpackets'} = intval(getsysint("/sys/class/net/".escapeshellcmd(trim($_POST{'interface'}))."/statistics/tx_packets"));
echo json_encode($arr);
break;
default:
$arr{'status'} = "unknown command";
echo json_encode($arr);
break;
}
?>