function statusDue($overdue = false) { global $db; $result = $db->query("SELECT service_id, v FROM service_params WHERE k = 'due'"); $dueArray = array(); while ($row = $result->fetch_array()) { if (empty($row[1]) || $row[1] == "N/A") { continue; } $service_id = escape($row[0]); $due = strtotime($row[1]); if ($overdue && time() > $due || !$overdue && time() <= $due && time() > $due - 3600 * 24 * 12) { $inner_result = $db->query("SELECT services.account_id, services.name, accounts.email, accounts.name FROM services LEFT JOIN accounts ON accounts.id = services.account_id WHERE services.id = '{$service_id}'"); if ($inner_row = $inner_result->fetch_array()) { $price = getServiceParam($service_id, 'price'); if ($price === false) { $price = "Unknown"; } $dueArray[] = array('due' => $due, 'service_id' => $service_id, 'account_id' => $inner_row[0], 'service' => $inner_row[1], 'email' => $inner_row[2], 'name' => $inner_row[3], 'price' => $price); } $inner_result->close(); } } $result->close(); usort($dueArray, "statusDueCompare"); return $dueArray; }
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); }
} } else { if ($_POST['action'] == "restart") { $result = minecraftRestart($service_id); if ($result === true) { $message = "Minecraft instance restarted successfully."; } else { $message = $result; } } else { if ($_POST['action'] == "stop") { $result = minecraftStop($service_id); if ($result === true) { $message = "Minecraft instance stopped successfully."; } else { $message = $result; } } } } if (!isset($_SESSION['noredirect'])) { header("Location: index.php?id=" . $service_id . "&message=" . urlencode($message)); } } $status = minecraftGetStatus($service_id); $botStatus = getServiceParam($service_id, "pid") != 0 ? "Online" : "Offline"; $resources = minecraftResources($service_id); get_page("status", "minecraft", array('service_id' => $service_id, 'status' => $status, 'message' => $message, 'botStatus' => $botStatus, 'resources' => $resources)); } else { header("Location: ../panel/"); }
<?php include "../include/common.php"; include "../config.php"; include "../include/session.php"; include "../include/dbconnect.php"; include "../include/account.php"; include "../include/database.php"; if (isset($_SESSION['account_id']) && isset($_REQUEST['id']) && is_numeric($_REQUEST['id']) && isset($_SESSION['is_' . $_REQUEST['id'] . '_database']) && isset($_REQUEST['gid']) && is_numeric($_REQUEST['gid'])) { $gid = $_REQUEST['gid']; $game = databaseGetGame($_REQUEST['id'], $gid); $replayBase = getServiceParam($_REQUEST['id'], 'replay_base'); get_page("game", "database", array('service_id' => $_REQUEST['id'], 'game' => $game, 'gid' => $gid, 'replay_base' => $replayBase)); } else { header("Location: ../panel/"); }
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; }
function channelSetDatabase($service_id, $db_settings) { global $config; //get the identifier $id = stripAlphaNumeric(getServiceParam($service_id, "id")); if ($id === false) { return false; } //reconfigure channelReconfigure($service_id, array('db_server' => $db_settings['server'], 'db_database' => $db_settings['name'], 'db_user' => $db_settings['username'], 'db_password' => $db_settings['password']), true); }
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; }
function databaseGetCronConfig($service_id) { $array = array(); foreach ($GLOBALS['cronParameters'] as $k => $v) { $setting = getServiceParam($service_id, "cron_" . $k); if ($setting === false) { $setting = $v[1]; } $array[$k] = $setting; } return $array; }
<?php include "../include/common.php"; include "../config.php"; include "../include/session.php"; include "../include/dbconnect.php"; include "../include/account.php"; include "../include/auth.php"; if (isset($_SESSION['account_id']) && isset($_REQUEST['id'])) { $service_id = $_REQUEST['id']; if (getServiceOwner($service_id) == $_SESSION['account_id']) { $service_info = getService($service_id); $_SESSION['is_' . $service_id . '_' . $service_info['type']] = true; //check if we need to redirect to a slave uxpanel instance $slaveRedirect = getServiceParam($service_id, "slave"); if (!$config['slave_enabled'] && $slaveRedirect != false) { //ok, register stuff into database and redirect to the other instance $ip = $_SERVER['REMOTE_ADDR']; $token = authRemoteRegister($_SESSION['account_id'], $service_id, $ip); header("Location: " . $slaveRedirect . "remote_login.php?user_id={$_SESSION['account_id']}&service_id={$service_id}&ip=" . urlencode($ip) . "&token={$token}"); } else { header("Location: ../{$service_info['type']}/?id={$service_id}"); } } } else { header("Location: ../"); }
function jailExecuteBackground($service_id, $command) { global $config; //get the identifier $id = stripAlphaNumeric(getServiceParam($service_id, "id")); if ($id === false) { return; } $jail_user = getServiceParam($service_id, "jail_user"); return execBackground("sudo -u " . escapeshellarg($jail_user) . " sh -c " . escapeshellarg($command)); }
function getServiceExtra($services) { $serviceExtra = array(); foreach ($services as $service) { $price = getServiceParam($service['id'], 'price'); if ($price === false) { $price = "Unknown"; } $due = getServiceParam($service['id'], 'due'); if ($due === false) { $due = "Unknown"; } $preLink = "service_redirect.php?"; if (($linkParam = getServiceParam($service['id'], 'link')) !== false) { $preLink = $linkParam; } $link = $preLink . "id=" . $service['id']; $serviceExtra[$service['id']] = array('price' => $price, 'due' => $due, 'link' => $link); } return $serviceExtra; }
function ghostSetDatabase($service_id, $db_settings) { global $config; //get the identifier $id = stripAlphaNumeric(getServiceParam($service_id, "id")); if ($id === false) { return false; } //read/write the configuration file $jail = jailEnabled($service_id); if ($jail) { jailFileOpen($service_id, "ghost", "default.cfg"); } $fin = fopen($config['ghost_path'] . $id . "/default.cfg", 'r'); $fout = fopen($config['ghost_path'] . $id . "/default.cfg_", 'w'); while (($buffer = fgets($fin, 4096)) !== false) { $buffer = trim($buffer); if (strpos($buffer, "db_mysql_database") !== false) { fwrite($fout, "db_mysql_database = {$db_settings['name']}\n"); } else { if (strpos($buffer, "db_mysql_server") !== false) { fwrite($fout, "db_mysql_server = {$db_settings['server']}\n"); } else { if (strpos($buffer, "db_mysql_user") !== false) { fwrite($fout, "db_mysql_user = {$db_settings['username']}\n"); } else { if (strpos($buffer, "db_mysql_password") !== false) { fwrite($fout, "db_mysql_password = {$db_settings['password']}\n"); } else { fwrite($fout, $buffer . "\n"); } } } } } fclose($fin); fclose($fout); rename($config['ghost_path'] . $id . "/default.cfg_", $config['ghost_path'] . $id . "/default.cfg"); if ($jail) { jailFileOpen($service_id, "ghost", "default.cfg", true); } }