-
Notifications
You must be signed in to change notification settings - Fork 6
/
singlerestart.php
128 lines (114 loc) · 5.23 KB
/
singlerestart.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
<?
include("config.php");
include("lib/functions.php");
require_once 'lib/steam-condenser/lib/steam-condenser.php';
mysql_connect($host, $user, $pass) or die(mysql_error());
mysql_select_db($table) or die(mysql_error());
$settings = getsettings();
$servercfg = getserver($_GET['serverid']);
$servercfg = $servercfg['0'];
if ($_GET['forks'] == "yes") {
$timeout = '2';
$ip = $servercfg['ip'];
$port = $servercfg['port'];
$netconport = $servercfg['netconport'];
$netconpasswd = $servercfg['netconpasswd'];
$usenet = fsockopen($ip, $netconport, $errno, $errstr, $timeout);
if ($_GET['submit'] == "Shutdown ALL") {
// shutdown forks baby!
if(!$usenet) {
die();
} else {
// echo 'shit happens';
// echo "ip : $ip, port : $port, netconport : $netconport, netconpasswd: $netconpasswd";
fputs ($usenet, "PASS $netconpasswd\r\n");
fputs ($usenet, "shutdown\r\n");
mysql_query("UPDATE servers SET restartsend = 'optional', goingdown = 'yes' WHERE netconport = '" . $servercfg['netconport'] . "'") or die(mysql_error());
}
}
if ($_GET['submit'] == "Quit ALL") {
// quit all forks baby! dont need optional here since the restart instantly
if(!$usenet) {
die();
} else {
fputs ($usenet, "PASS $netconpasswd\r\n");
fputs ($usenet, "quit\r\n");
mysql_query("UPDATE servers SET restartsend='yes' WHERE netconport = '" . $servercfg['netconport'] . "'") or die(mysql_error());
}
}
header("Location: servers.php");
die();
}
if ($_GET['submit'] == "Restart when empty") {
$serverid = $_GET['serverid'];
mysql_query("UPDATE servers SET restartsend = 'optional', goingdown = 'yes', restartsend = 'emptyserver' WHERE serverid = '$serverid'") or die(mysql_error());
header("Location: servers.php");
die();
}
if ($_GET['submit'] == "Restart HARD") {
$serverid = $_GET['serverid'];
$ipnr = $_GET['ip'];
$port = $_GET['port'];
mysql_query("UPDATE servers SET restartsend = 'yes' WHERE serverid = '$serverid'") or die(mysql_error());
$call = file_get_contents("http://$ipnr:4337/ssms?password=$server_connect&port=$port&ip=$ipnr");
header("Location: servers.php");
die();
}
if ($_GET['update'] == "yes") {
$serverid = $_GET['serverid'];
$serverIP = $servercfg['ip'];
$port = $servercfg['port'];
$rconpass = $servercfg['rconpass'];
$server = new SourceServer($serverIP, $port);
try {
$server->rconAuth($rconpass);
$server->rconExec('_restart');
} catch (Exception $e) {
//trigger_error('Could not authenticate with the game server. Or it is down',E_USER_ERROR);
}
// have to do the update here, since this statement above is really buggy if you _restart it at the same time
mysql_query("UPDATE servers SET restartsend = 'restart', goingdown = 'yes' WHERE serverid = '$serverid'") or die(mysql_error());
header("Location: servers.php");
die();
}
?>
<body><div id="container">
<form action="singlerestart.php" class="niceform">
<fieldset>
<legend>Are you sure you want to Restart?</legend>
<b><? echo $servercfg['servername'];?></b><br/>
<? echo "IP: " . $servercfg['ip'] . ":" .$servercfg['port'] . "<br/><font size=+1 color=red> Currentplayers " . $servercfg['currentplayers'] . "/" . $servercfg['maxplayers'] . " Bots: " . $servercfg['currentbots'] . "</font><br/><br/>";?>
<input type="hidden" name="update" value="yes">
<input type="hidden" name="ip" value="<? echo $servercfg['ip'] ?>">
<input type="hidden" name="port" value="<? echo $servercfg['port'] ?>">
<input type="hidden" name="serverid" value="<? echo $_GET['serverid'];?>">
<input type="submit" name="submit" id="submit" value="Restart NOW" />
<input type="submit" name="submit" id="submit" value="Restart when empty" />
<input type="submit" name="submit" id="submit" value="Restart HARD" />
<input type="button" value="Cancel" align="right" onclick="$( '#serverall' ).dialog('close');">
</fieldset>
<?
if ($servercfg['type'] == 'left4dead' || $servercfg['type'] == 'left4dead2') {
if (!empty($servercfg['netconpasswd'])) {
echo '<fieldset><legend>Fork Restart options</legend>';?>
<input type="hidden" name="forks" value="yes">
<input type="hidden" name="serverid" value="<? echo $_GET['serverid'];?>">
<input type="submit" name="submit" id="submit" value="Shutdown ALL" />
<input type="submit" name="submit" id="submit" value="Quit ALL" /><?
echo "<br/><b>Forks involved for port " . $servercfg['netconport'] . "</b><br/>";
$result = mysql_query("SELECT servername from servers where netconport = '" . $servercfg['netconport'] . "'") or die(mysql_error());
// echo "This will restart the following servers:<br/>";
while($row = mysql_fetch_array( $result )) {
$servername = $row['servername'];
echo "$servername<br/>";
}
echo '</fieldset>';
}
}
?>
</form>
</div></body>
</html>
<?
mysql_close();
?>