Beispiel #1
0
<?php

include "../include/common.php";
include "../config.php";
include "../include/session.php";
include "../include/dbconnect.php";
include "../include/account.php";
include "../include/garena.php";
if (isset($_SESSION['account_id']) && isset($_REQUEST['id']) && is_numeric($_REQUEST['id']) && isset($_SESSION['is_' . $_REQUEST['id'] . '_garena'])) {
    if (isset($_POST['action']) && $_POST['action'] == "update") {
        //create array of configurations we are updating
        $array = garenaGetConfigFromRequest(garenaGetParameters($_REQUEST['id']), $_REQUEST);
        garenaReconfigure($_REQUEST['id'], $array);
        if (!isset($_SESSION['noredirect'])) {
            header("Location: config_garena.php?id=" . $_REQUEST['id']);
            return;
        }
    }
    $gconfig = garenaGetConfiguration($_REQUEST['id']);
    get_page("config_garena", "garena", array('service_id' => $_REQUEST['id'], 'gconfig' => $gconfig, 'parameters' => $garenaParameters));
} else {
    header("Location: ../panel/");
}
Beispiel #2
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;
}