refactor: remove controls for the IRC bot and proxy scanner

This commit is contained in:
Emmanuel BENOîT 2024-12-31 15:02:30 +01:00
parent a80d211a41
commit 46df0f2d61
Signed by: Emmanuel BENOîT
SSH key fingerprint: SHA256:l7PFUUF5TCDsvYeQC9OnTNz08dFY7Fvf4Hv3neIqYpg
5 changed files with 8 additions and 207 deletions

View file

@ -1,78 +0,0 @@
<?php
include('config.inc');
include('../scripts/config.inc');
include('as_manager.inc');
include('as_log.inc');
function redirect() {
?>
<html>
<head>
<title>LegacyWorlds Beta 5 > Administration > IRC bot</title>
</head>
<body>
<h1><a href="index.html">LWB5 > Administration</a> > IRC bot</h1>
<h2>Operation in progress...</h2>
<p>
A system operation is in progress. Please wait, the page will update in a few seconds.
</p>
<script language="JavaScript">
window.setTimeout('window.location="bot.php"', 1000);
</script>
</body>
</html>
<?php
exit(0);
}
function sendCommand($cmd) {
global $aConfig;
$fName = $aConfig['ctrlFifo'];
if (!file_exists($fName)) {
return false;
}
$fifo = fopen($fName, "w");
fwrite($fifo, "$cmd\n");
fclose($fifo);
redirect();
}
if ($_GET['c'] == 'kb') {
__logAdmin("is stopping the IRC bot");
sendCommand("BOTOFF");
} elseif ($_GET['c'] == 'sb') {
__logAdmin("is starting the IRC bot");
sendCommand("BOTON");
}
$running = file_exists($config['cs_path'] . "/ircbot.pid");
?>
<html>
<head>
<title>LegacyWorlds Beta 5 > Administration > IRC bot</title>
</head>
<body>
<h1><a href="index.html">LWB5 > Administration</a> > IRC bot</h1>
<?php
if ($running) {
?>
<p>
IRC bot is (probably) running. <a href="?c=kb">Kill bot</a>
</p>
<?php
} else {
?>
<p>
IRC bot is not running. <a href="?c=sb">Start bot</a>
</p>
<?php
}
?>
</body>
</html>

View file

@ -16,10 +16,8 @@
<h2>Server management</h2>
<ul>
<li><a href="ticks.php">Ticks</a>: enable / disable the tick manager, run ticks manually</li>
<li><a href="proxy.php">Proxy detector</a>: control the detector's status and manually check for open proxies</li>
<li><a href="maintenance.php">Maintenance</a>: activate / de-activate maintenance mode</li>
<li><a href="maps.php">Maps management</a>: manage maps used for <i>Kings of the Hill</i> games</li>
<li><a href="bot.php">IRC bot</a>: control the IRC bot</li>
</ul>
</body>
</html>

View file

@ -1,126 +0,0 @@
<?php
include('config.inc');
include('../scripts/config.inc');
include('as_manager.inc');
include('as_log.inc');
function redirect() {
?>
<html>
<head>
<title>LegacyWorlds Beta 5 > Administration > Proxy detector</title>
</head>
<body>
<h1><a href="index.html">LWB5 > Administration</a> > Proxy detector</h1>
<h2>Operation in progress...</h2>
<p>
A system operation is in progress. Please wait, the page will update in 5 seconds.
</p>
<script language="JavaScript">
window.setTimeout('window.location="proxy.php"', 5000);
</script>
</body>
</html>
<?php
exit(0);
}
function startDetector() {
__logAdmin("is starting the proxy detector");
__sendControl("PCON");
redirect();
}
function stopDetector() {
__logAdmin("is stopping the proxy detector");
__sendControl("PCOFF");
redirect();
}
$oldDir = getcwd();
chdir("../scripts");
$__loader = array(
'log', 'classloader',
'version', 'game', 'tick',
'config', 'pcheck'
);
require_once("loader.inc");
chdir($oldDir);
$isRunning = pcheck::isRunning();
if ($_GET['c'] == 'sd') {
startDetector();
} elseif ($_GET['c'] == 'kd') {
stopDetector();
} elseif ($_GET['ip'] != '') {
$ip = $_GET['ip'];
$status = "";
if (preg_match('/^\d{1,3}(\.\d{1,3}){3}$/', $ip)) {
if ($ip == "127.0.0.1") {
$status = "Host not allowed";
} else {
$addr = explode('.', $ip);
foreach ($addr as $piece) {
if ($piece > 254) {
$status = "Invalid IP address";
break;
}
}
if ($status == "") {
try {
$result = pcheck::check(array($ip));
$status = "$ip - ";
switch ($result[$ip]) {
case -1: $status .= "detection failed"; break;
case 0: $status .= "no proxy detected"; break;
case 1: $status .= "OPEN PROXY DETECTED!"; break;
}
} catch (Exception $e) {
$status = $e->getMessage();
}
}
}
} else {
$status = "Invalid IP address";
}
} else {
$status = $ip = "";
}
?>
<html>
<head>
<title>LegacyWorlds Beta 5 > Administration > Proxy detector</title>
</head>
<body>
<h1><a href="index.html">LWB5 > Administration</a> > Proxy detector</h1>
<?php
if ($isRunning) {
?>
<p>
Proxy detector is <b>running</b>; process ID #<?=$isRunning?>. <a href="?c=kd">Stop detector</a>
</p>
<form action="?" method="GET">
<p>
Manually check address <input type="text" size="16" maxlength="15" name="ip" value="<?=htmlentities($ip, ENT_QUOTES)?>" />
<input type="submit" value="Scan" />
<?=($status != '') ? ('<br/><b>' . $status . '</b>') : ''?>
</p>
</form>
<?php
} else {
?>
<p>
Proxy detector is <b>not running</b>. <a href="?c=sd">Start detector</a>
</p>
<?php
}
?>
</body>
</html>

View file

@ -38,6 +38,12 @@ class config {
private static function writeCache($cObj) {
$config = &config::$main;
umask(0007);
if (!is_dir(config::$main['cachedir']) && !@mkdir(config::$main['cachedir'], 0770)) {
l::warn("CONFIG: failed to create cache directory");
return;
}
$text = serialize($cObj);
$mask = umask(0002);
$w = @file_put_contents("{$config['cachedir']}/config.ser", $text, LOCK_EX);

View file

@ -56,7 +56,8 @@ function addRawResource($type, $text) {
/** This function generates the cached output for a set of resources.
*/
function generateResourceCache($type, $md5) {
if (!is_dir(config::$main['cachedir']) && !@mkdir(config::$main['cachedir'])) {
umask(0007);
if (!is_dir(config::$main['cachedir']) && !@mkdir(config::$main['cachedir'], 0770)) {
l::warn("Could not create cache dir " . config::$main['cachedir']);
return false;
}