示例#1
0
function minecraftRestoreWorld($service_id, $label)
{
    global $config;
    $label = stripAlphaNumeric($label);
    //get the identifier
    $id = stripAlphaNumeric(getServiceParam($service_id, "id"));
    if ($id === false) {
        return "Error: the identifier for this service is not set.";
    }
    //require stopped to restore
    $pid = getServiceParam($service_id, "pid");
    if ($pid !== false && $pid != 0) {
        return "Error: please stop the server before restoring the world.";
    }
    //check for existence
    $jail = jailEnabled($service_id);
    $filename = $label . ".uxbakzip";
    if ($jail) {
        $path = jailPath($service_id) . $filename;
    } else {
        $path = $config['minecraft_path'] . $id . "/" . $filename;
    }
    if ($jail && !jailFileExists($filename) || !$jail && !file_exists($path)) {
        return "Error: the requested backup doesn't appear to exist.";
    }
    //unzip and move the world directory
    if ($jail) {
        jailExecute($service_id, "unzip " . escapeshellarg(jailPath($service_id) . $label . ".uxbakzip") . " -d " . escapeshellarg(jailPath($service_id)));
        jailExecute($service_id, "rm -r " . escapeshellarg(jailPath($service_id) . "world"));
        jailFileMove($service_id, "world_tmp", "world");
    } else {
        exec("unzip " . escapeshellarg($config['minecraft_path'] . $id . "/" . $label . ".uxbakzip") . " -d " . escapeshellarg($config['minecraft_path'] . $id));
        delete_directory($config['minecraft_path'] . $id . "/world");
        rename($config['minecraft_path'] . $id . "/world_tmp", $config['minecraft_path'] . $id . "/world");
    }
    return true;
}
示例#2
0
function channelGetLogFast($service_id, $last_line)
{
    global $config;
    //sanity check on input
    if (strlen($last_line) > 2048) {
        return false;
    }
    //get the identifier
    if (!isset($_SESSION[$service_id . '_getlogfast_id'])) {
        $_SESSION[$service_id . '_getlogfast_id'] = stripAlphaNumeric(getServiceParam($service_id, "id"));
    }
    $id = $_SESSION[$service_id . '_getlogfast_id'];
    $log_file = $config['channel_path'] . $id . '/chop.log';
    $jail = jailEnabled($service_id);
    if ($jail && !jailFileExists($service_id, "chop.log") || !$jail && !file_exists($log_file)) {
        return false;
    }
    //read last lines of the log file that client hasn't received yet
    $output_array = array();
    if ($jail) {
        jailExecute($service_id, "tail -n 1000 " . escapeshellarg(jailPath($service_id) . "chop.log") . " | tac | fgrep -B 1000 -m 1 " . escapeshellarg($last_line) . " | tac", $output_array);
    } else {
        exec("tail -n 1000 " . escapeshellarg($log_file) . " | tac | fgrep -B 1000 -m 1 " . escapeshellarg($last_line) . " | tac", $output_array);
    }
    if (count($output_array) <= 1) {
        return false;
    } else {
        array_shift($output_array);
        return $output_array;
    }
}