sleep($INVALID_PASS_SLEEP); updateStatusFile($options['status'], "Configuration error. Can't restart server"); printLogAndDie("Invalid login/password"); } // Define commands for FM server $cmd = $config['main']['fmsadmin_path'] . ' -u ' . $options['user'] . ' -p ' . $options['pass'] . ' -y '; $restartCmd = $cmd . ' restart server'; // Restart server command $startCmd = $cmd . ' start server'; // Start server command $checkCmd = $cmd . ' LIST FILES'; // Command to check if server alive $discCmd = $cmd . ' DISCONNECT CLIENT'; // Command to disconnect clients // Connect to server if required $log->message("Try to restart server. Status file: " . $options['status']); // Connect to server if ($config['main']['fms_server'] != 'LOCAL') { updateStatusFile($options['status'], "Connecting to server"); try { // Connect to remote server $ssh = new Net_SSH2($config['main']['fms_server']); if (array_key_exists('ssh_login', $config['main'])) { // Use login /pass to connect to distant server if (!$ssh->login($config['main']['ssh_login'], $config['main']['ssh_password'])) { printLogAndDie('Error connecting to server'); } } else { // Use RSA key authentication to connect to distant server $key = new Crypt_RSA(); if (!$key->loadKey(file_get_contents($config['main']['fms_public_key_path']))) {
// Show status page if (!array_key_exists('id', $_REQUEST) || !preg_match('/^\\d+\\.txt$/', $_REQUEST['id']) || !file_exists($config['main']['stat_dir'] . $_REQUEST['id'])) { $message = "Status file not found"; $action = ''; showPage($action, $message, ""); } showPage('status', file_get_contents($config['main']['stat_dir'] . $_REQUEST['id']), $_REQUEST['id'], ""); } else { if (($action == 'disconnect' || $action == 'restart') && array_key_exists('UserName', $_REQUEST) && array_key_exists('Password', $_REQUEST)) { if (!$ckStart->canStart()) { // Check if script is already running. Doesn't allow customer to send multiple restart requests showPage($action, "Script is already running.", ""); } if ($_SERVER['REQUEST_METHOD'] != 'POST') { // Allow only POST requests with login and password $log->message("Invalid request type: " . $_SERVER['REQUEST_METHOD']); showPage($action, "Invalid request type", ""); } if (calcCheckSum($_REQUEST['UserName'], $_REQUEST['Password']) != $config['main']['MD5check']) { // Password incorrect sleep($INVALID_PASS_SLEEP); $log->message("Invalid login/password"); showPage($action, "Invalid login/password", ""); } // Fork process to restart the server $log->message("Send request to server"); $statusFile = rand(0, 1000000) . '.txt'; $cmd = str_replace('PARAMETERS', '--action=' . $action . ' --user='******'UserName'] . ' --pass='******'Password'] . ' --status=' . $statusFile, $config['main']['exec_cmd']); try { pclose(popen($cmd, 'r')); // exec("$cmd > /dev/null 2>&1 &",$output,$res);