printLogAndDie("User is not defined");
} else {
    if (!isset($options['pass'])) {
        // Check if password defined. Login and Pass is checked later with MD5 checksum
        printLogAndDie("Password is not defined");
    } else {
        if (!isset($options['status']) || !preg_match('/^\\d+\\.txt$/', $options['status'])) {
            // Check if status file defined
            printLogAndDie("Status file is not defined or incorrect");
        }
    }
}
removeOldStat();
// Remove old stat files here
// Check login/password
if (calcCheckSum($options['user'], $options['pass']) != $config['main']['MD5check']) {
    // Password incorrect
    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
         $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);
             //      $log->message("Started process status: $res. output: ".var_export($output,1));
         } catch (Exception $e) {
             //