Esempio n. 1
0
function rootJail($service_id, $username)
{
    global $config;
    //get the identifier
    $id = stripAlphaNumeric(getServiceParam($service_id, "id"));
    if ($id === false) {
        die("Error: identifier for this service has not been set!\n");
    }
    //make sure it hasn't been jailed yet
    if (getServiceParam($service_id, "jail") !== false || getServiceParam($service_id, "jail_user") !== false || getServiceParam($service_id, "jail_path") !== false) {
        die("Error: target service already has jail settings!\n");
    }
    //get service type
    $type = getServiceType($service_id);
    if ($type !== "ghost" && $type !== "minecraft" && $type !== "garena" && $type !== "channel") {
        //not a process-based service, seems like it can't be jailed?
        die("Error: service doesn't seem to be process-based (type={$type})!\n");
    }
    //add the system user if not exists
    if (!file_exists("/home/{$username}/")) {
        rexec('adduser --disabled-password --gecos "" ' . escapeshellarg($username));
    }
    //copy to own directory, and set permissions of result so that username is owner
    //we use cp to ensure proper handling of symlinks (PHP documentation doesn't guarantee this)
    $source_path = $config[$type . "_path"] . $id . "/";
    $target_path = "/home/{$username}/{$id}/";
    rexec("cp -r " . escapeshellarg($source_path) . " " . escapeshellarg($target_path));
    rexec("chown -R  " . escapeshellarg($username . ":" . $username) . " " . escapeshellarg($target_path));
    //also, depending on the service, user might need to access files in the service_path directory
    //so set permissions on that as well
    rexec("chown -R " . escapeshellarg(":" . $username) . " " . escapeshellarg($source_path));
    rexec("chmod -R 770 " . escapeshellarg($source_path));
    //depending on the service type, we may wish to rewrite some configuration files
    if ($type == "ghost") {
        //the "maps" and "replays" directory should be changed over to use absolute path to the subdirectory of source
        // (since this is how include/ghost.php handles it)
        $escaped_source_path = str_replace(array('$', '/', '['), array('\\$', '\\/', '\\['), $source_path);
        rexec("sed -i " . escapeshellarg("s/bot_mappath = maps/bot_mappath = {$escaped_source_path}maps/") . " " . escapeshellarg($target_path . "default.cfg"));
        rexec("sed -i " . escapeshellarg("s/bot_replaypath = replays/bot_replaypath = {$escaped_source_path}replays/") . " " . escapeshellarg($target_path . "default.cfg"));
    }
    //update the jail settings
    setServiceParam($service_id, "jail", "1");
    setServiceParam($service_id, "jail_user", $username);
    setServiceParam($service_id, "jail_path", $target_path);
}
Esempio n. 2
0
function minecraftStop($service_id, $restart = false)
{
    global $config;
    //get the identifier
    $id = stripAlphaNumeric(getServiceParam($service_id, "id"));
    if ($id === false) {
        return "Error: failed to find identifier. Perhaps this isn't a minecraft service?";
    }
    //make sure we are allowed to stop the bot
    if (!$restart) {
        $nostop = getServiceParam($service_id, "nostop");
        if ($nostop) {
            return "Error: you are not allowed to stop this server. Use restart instead.";
        }
    }
    //get the pid
    $pid = stripAlphaNumeric(getServiceParam($service_id, "pid"));
    if ($pid === false || $pid == 0) {
        if ($restart) {
            return true;
        } else {
            return "Error: the server is already offline.";
        }
    }
    //stop the bot
    $jail = jailEnabled($service_id);
    if ($jail) {
        jailExecute($service_id, "kill {$pid}");
    } else {
        //make sure PID is still of pychop
        $result = exec("cat /proc/{$pid}/cmdline");
        if (stripos($result, 'minecraft') !== false) {
            exec("kill {$pid}");
        }
    }
    //reset the pid
    setServiceParam($service_id, "pid", 0);
    return true;
}
Esempio n. 3
0
                     include "../include/garena.php";
                     $result = garenaAddService($account_id, $_POST['name'], $_POST['description'], $_POST['identifier']);
                     if (is_integer($result)) {
                         setServiceParam($result, "due", $_POST['due']);
                         setServiceParam($result, "price", $_POST['price']);
                         $message = "Garena service has been setup successfully.";
                     } else {
                         header("Location: account.php?id={$account_id}&message=" . urlencode($result));
                     }
                 } else {
                     if ($type == "database") {
                         include "../include/database.php";
                         $result = databaseAddService($account_id, $_POST['name'], $_POST['description'], $_POST['identifier']);
                         if (is_integer($result)) {
                             setServiceParam($result, "due", $_POST['due']);
                             setServiceParam($result, "price", $_POST['price']);
                             $message = "Database service has been setup successfully. Note that the database settings and tables are not automatically configured and created. Create the database manually, set the database settings by clicking on the service and setting parameters, and then setup the tables there as well.";
                         } else {
                             header("Location: account.php?id={$account_id}&message=" . urlencode("Error occurred while setting up database."));
                         }
                     }
                 }
             }
         }
     }
 } else {
     if ($_POST['action'] == "delete" && isset($_POST['delete_id'])) {
         removeService($_POST['delete_id']);
         $message = "The service has been removed. Note that no service-related files or databases have been erased.";
     }
 }
Esempio n. 4
0
function garenaStop($service_id, $force = false, $restart = false)
{
    global $config;
    //get the identifier
    $id = stripAlphaNumeric(getServiceParam($service_id, "id"));
    if ($id === false) {
        return "Error: failed to find identifier. Perhaps this isn't a Garena service?";
    }
    if ($force) {
        //get the pid
        $pid = stripAlphaNumeric(getServiceParam($service_id, "pid"));
        if ($pid === false || $pid == 0) {
            if ($restart) {
                return true;
            } else {
                return "Error: the bot is already offline.";
            }
        }
        //stop the bot
        $jail = jailEnabled($service_id);
        if ($jail) {
            jailExecute($service_id, "kill {$pid}");
        } else {
            //make sure PID is still of garena
            $result = exec("cat /proc/{$pid}/cmdline");
            if (stripos($result, 'java') !== false) {
                exec("kill {$pid}");
            }
        }
    } else {
        //try to send an rcon stop command
        $config = garenaGetConfiguration($service_id, false);
        $fail = true;
        if (isset($config['gcb_rcon']) && isset($config['rcon_password']) && isset($config['rcon_port']) && ($config['gcb_rcon'] == "true" || $config['gcb_rcon'] == "1")) {
            $socket = @fsockopen("localhost", $config['rcon_port'], $errno, $errstr, 5);
            if ($socket) {
                $status = @fwrite($socket, $config['rcon_password'] . "\n");
                if ($status !== false) {
                    fwrite($socket, "exit nicely\n");
                    sleep(1);
                    socket_close($socket);
                    $fail = false;
                }
            }
        }
        //if we failed to send, then force stop it
        if ($fail) {
            garenaStop($service_id, true, $restart);
        }
    }
    //reset the pid
    setServiceParam($service_id, "pid", 0);
    return true;
}
Esempio n. 5
0
function databaseSetCronConfig($service_id, $array)
{
    foreach ($array as $k => $v) {
        if (isset($GLOBALS['cronParameters'][$k])) {
            $v = databaseConfEscape($GLOBALS['cronParameters'][$k][0], $GLOBALS['cronParameters'][$k][1], $GLOBALS['cronParameters'][$k][2], $v);
            setServiceParam($service_id, "cron_" . $k, $v);
        }
    }
}
Esempio n. 6
0
include "../include/session.php";
include "../include/dbconnect.php";
include "../include/account.php";
if (isset($_SESSION['admin']) && isset($_REQUEST['id'])) {
    $service_id = $_REQUEST['id'];
    $message = "";
    if (isset($_REQUEST['message'])) {
        $message = htmlentities($_REQUEST['message']);
    }
    if (isset($_POST['action'])) {
        if ($_POST['action'] == "set" && isset($_POST['k']) && isset($_POST['v'])) {
            $delete = isset($_POST['delete']) && $_POST['delete'] == "delete";
            if ($delete) {
                setServiceParam($service_id, $_POST['k'], false);
            } else {
                setServiceParam($service_id, $_POST['k'], $_POST['v']);
            }
        } else {
            if ($_POST['action'] == "setup") {
                include "../include/database.php";
                $result = databaseSetup($_REQUEST['id']);
                if ($result !== true) {
                    $message = $result;
                } else {
                    $message = "Database setup successfully.";
                }
            } else {
                if ($_POST['action'] == "ghostdb" && isset($_POST['db_id'])) {
                    include "../include/database.php";
                    include "../include/ghost.php";
                    $db_settings = databaseSettings($_POST['db_id']);
Esempio n. 7
0
function executeCronOther($service_id, $type, $params)
{
    global $config, $db;
    if (!isset($params['id'])) {
        return;
    }
    echo "Executing for service {$service_id} ({$type})\n";
    echo "logcron\n";
    //log cron
    if (!isset($params['last_logcron']) || time() - $params['last_logcron'] > 3600 * 24) {
        $logname = "ghost";
        if ($type == "channel") {
            $logname = "chop";
        } else {
            if ($type == "garena") {
                $logname = "gcb";
            }
        }
        if (isset($params['jail']) && $params['jail'] == 1) {
            require_once "include/jail.php";
            jailFileMove($service_id, "{$logname}.log", "{$logname}.log_");
        } else {
            rename($config['ghost_path'] . $params['id'] . "/{$logname}.log", $config['ghost_path'] . $params['id'] . "/{$logname}.log_");
        }
        setServiceParam($service_id, "last_logcron", time());
    } else {
        if ($type == "ghost") {
            require_once "include/ghost.php";
            $statusArray = ghostGetStatus($service_id);
        } else {
            require_once "include/channel.php";
            $statusArray = channelGetStatus($service_id);
        }
        if (!isset($GLOBALS['status_updates'])) {
            $GLOBALS['status_updates'] = array();
        }
        $problems = $statusArray['err'];
        sort($problems);
        if (count($problems) > 0) {
            $problemString = implode("\n", $problems);
            $result = $db->query("SELECT id, message FROM cron_problems WHERE service_id = '{$service_id}'");
            if ($result && ($row = $result->fetch_array())) {
                if ($row[1] != $problemString) {
                    $db->query("UPDATE cron_problems SET message = '" . escape($problemString) . "' WHERE id = '{$row[0]}'");
                    foreach ($problems as $problem) {
                        //$GLOBALS['status_updates'][] = $service_id . ": " . $problem;
                    }
                }
            } else {
                foreach ($problems as $problem) {
                    //$GLOBALS['status_updates'][] = $service_id . ": " . $problem;
                }
                $db->query("INSERT INTO cron_problems (service_id, message) VALUES ('{$service_id}', '" . escape($problemString) . "')");
            }
        } else {
            $result = $db->query("SELECT id FROM cron_problems WHERE service_id = '{$service_id}'");
            if ($result && ($row = $result->fetch_array())) {
                $db->query("DELETE FROM cron_problems WHERE id = '{$row[0]}'");
                //$GLOBALS['status_updates'][] = "$service_id: recovery!";
            }
        }
    }
    if ($type == "ghost") {
        echo "replaycron\n";
        //replay cron
        $path = $config['ghost_path'] . $params['id'] . '/replays';
        if (isset($params['replay_path'])) {
            $path = $params['replay_path'];
        }
        $info = dirInfo($path);
        //delete everything older than fourteen days
        foreach ($info as $filePath => $array) {
            if (getExtension($filePath) == "w3g" && time() - $array[1] > 14 * 60 * 60 * 24) {
                unlink($filePath);
                unset($info[$filePath]);
            }
        }
    }
}