-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathrcon.php
142 lines (96 loc) · 3.3 KB
/
rcon.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
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
<?php
include( "config.php" );
include( "lib/functions.php" );
require_once 'lib/steam-condenser/lib/steam-condenser.php';
error_reporting( E_ALL ); //} no error will slip past unnoticed
ini_set( "display_errors", 1) ;
mysql_connect( $host, $user, $pass ) or die( mysql_error() );
mysql_select_db( $table ) or die( mysql_error() );
if( !isset( $_GET[ 'serverid' ] ) ) die( "Server not set." );
if( isset( $_GET[ 'command' ] ) ) {
$settings = getsettings();
$servercfg = getserver($_GET['serverid']);
$servercfg = $servercfg['0'];
$serverIP = $servercfg['ip'];
$server = new SourceServer($serverIP, $servercfg['port']);
try {
$server->rconAuth($servercfg['rconpass']);
} catch(Exception $e) { $output = "> Unable to connect to Server"; }
if (empty($output)) {
try { $output = $server->rconExec($_GET[ 'command' ]); } catch(Exception $e) { $output = "> Server not Responding";}
}
if( isset( $_GET[ 'init' ] ) ) {
$output = explode( "\n\n", $output );
$output = $output[ 0 ] . "\n";
}
echo $output;
mysql_close();
die();
}
$start = head();
echo '<h2 style="margin-top: 0;">RCON: ' . mysql_result( mysql_query( "SELECT servername FROM servers where serverid = " . $_GET[ 'serverid' ] ), 0, "servername") . '</h2>';
?>
<script type="text/javascript">
var rcon = {
print: function( str ) {
var terminal = document.getElementById( "terminal" );
terminal.innerHTML += str;
terminal.scrollTop = terminal.scrollHeight;
},
handle: function( ) {
if ( xmlhttp.readyState == 4 ) {
if ( xmlhttp.status == 200 ) {
rcon.print( xmlhttp.responseText );
} else {
rcon.print( "Request failed. HTTP status code: " + xmlhttp.status );
}
}
},
send: function( command, auto ) {
if(! auto )
this.print( '\n> ' + command + '\n' );
if ( window.XMLHttpRequest ) { // Mozilla, Safari,...
xmlhttp = new XMLHttpRequest();
if ( xmlhttp.overrideMimeType )
xmlhttp.overrideMimeType( 'text/xml' );
} else if (window.ActiveXObject) { // IE
try {
xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e) {}
}
}
if (! xmlhttp ) {
this.print('Cannot create XMLHTTP instance.');
return false;
}
xmlhttp.onreadystatechange = rcon.handle;
xmlhttp.open( 'GET', '?serverid=<?php echo $_GET[ 'serverid' ]; ?>&command=' + command, true );
xmlhttp.send( null );
return false;
}
};
window.onload = function() {
rcon.send( "status&init", true );
document.getElementById( "input" ).focus();
};
</script>
<pre id="terminal">Requesting server status...
</pre>
<form onsubmit="rcon.send( this.command.value ); this.command.value = ''; return false;">
<table border="0" style="width: 100%;">
<tr>
<td>
<input type="text" id="input" style="background-color: lightgray; border: 1px black solid; width:100%;" name="command" >Type Command Here</input>
</td>
<td width="1px">
<input type="submit" value="Send" style="border: 1px black solid; background-color: lightgray;margin-bottom:20px;cursor:pointer;cursor:hand"/>
</td>
</tr>
</table>
</form>
<?php
bottom($start);
?>