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
<?php
function color($string)
{
$string = iconv('ASCII', 'UTF-8//IGNORE', $string);
$pattern = '/([0-9]{3})([0-9]{3})([0-9]{3})/i';
$replacement = '<span style="color: rgb(${1}, ${2}, ${3});">';
$html = preg_replace($pattern, $replacement, $string);
if (!$html) {
return $string;
} else {
return $html . '</span>';
}
}
function readByteFast()
{
global $d;
global $dOS;
$byte = ord(substr($d, $dOS, 1));
$dOS++;
return $byte;
}
function send_commands($addr, $rcon, $cmds)
{
global $d;
global $dOS;
$output = "";
$pieces = explode(":", $addr);
$ip = $pieces[0];
$port = $pieces[1];
// Send multiple copies of the request packet, because cs2d likes to just ignore them randomly
for ($i = 0; $i < 3; $i++) {
$fp = fsockopen("udp://$ip", $port, $errno, $errstr);
$string = chr(1) . chr(0) . chr(242) . chr(strlen($rcon)) . $rcon . pack("S", strlen($cmds)) . $cmds;
fwrite($fp, $string);
stream_set_timeout($fp, 1);
$d = fread($fp, 4096);
$dOS = 0;
fclose($fp);
if (!empty($d)) {
break;
}
}
readByteFast(); // 1
readByteFast(); // 0
readByteFast(); // 240
readByteFast(); // 0
readByteFast(); // 3
$size = readByteFast();
while ($size >= 1) {
readByteFast();
$arr[] = readByteFast();
if ($size == 1) {
$string = implode(array_map("chr", $arr));
$output .= color($string) . "<br>";
unset($arr);
readByteFast();
readByteFast();
readByteFast();
readByteFast();
$size = readByteFast();
continue;
}
$size
}
return $output;
}
?>
<!DOCTYPE html>
<html>
<body>
<?php
if (isset($_POST['cmds']) && !empty($_POST['cmds'])) {
$addr = $_POST['addr'];
$rcon = $_POST['rcon'];
$cmds = $_POST['cmds'];
print(send_commands($addr, $rcon, $cmds));
}
?>
<form method="POST">
<label for="addr">addr:</label><br>
<input type="text" id="addr" name="addr"><br>
<label for="rcon">rcon:</label><br>
<input type="text" id="rcon" name="rcon"><br>
<label for="rcon">cmds:</label><br>
<input type="text" id="cmds" name="cmds"><br><br>
<input type="submit" value="Submit">
</form>
</body>
</html>