コード例 #1
0
    $stmt->bindValue(':gsid', $GSID);
    $stmt->bindValue(':access_ip', $_SERVER['REMOTE_ADDR']);
    $stmt->bindValue(':local_ip', $LOCAL_IP);
    $stmt->bindValue(':title', $HOSTNAME);
    $stmt->bindValue(':current_time', phoromatic_server::current_time());
    $stmt->bindValue(':machine_self_id', $PTS_MACHINE_SELF_ID);
    $stmt->bindValue(':core_version', $CLIENT_CORE_VERSION);
    $result = $stmt->execute();
    $json['phoromatic']['response'] = 'Information Added; Waiting For Approval From Administrator.';
    echo json_encode($json);
    // Email notifications
    $stmt = phoromatic_server::$db->prepare('SELECT UserName, Email FROM phoromatic_users WHERE UserID IN (SELECT UserID FROM phoromatic_user_settings WHERE AccountID = :account_id AND NotifyOnNewSystems = 1) AND AccountID = :account_id');
    $stmt->bindValue(':account_id', ACCOUNT_ID);
    $result = $stmt->execute();
    while ($row = $result->fetchArray()) {
        phoromatic_server::send_email($row['Email'], 'Phoromatic New System Added', phoromatic_server::account_id_to_group_admin_email(ACCOUNT_ID), '<p><strong>' . $row['UserName'] . ':</strong></p><p>A new system is attempting to associate with a Phoromatic account for which you\'re associated.</p><p>Title: ' . $HOSTNAME . '<br />IP: ' . $LOCAL_IP . '<br />System Info: ' . $CLIENT_HARDWARE . ' ' . $CLIENT_SOFTWARE . '</p>');
    }
    exit;
}
define('SYSTEM_ID', $result['SystemID']);
define('SYSTEM_NAME', $result['Title']);
define('SYSTEM_GROUPS', $result['Groups']);
$SYSTEM_STATE = $result['State'];
define('GSID', $GSID);
define('SYSTEM_IN_MAINTENANCE_MODE', $result['MaintenanceMode'] == 1);
if (strtotime($result['LastCommunication']) < time() - 300) {
    // Avoid useless updates to the database if it's close to the same info in past 2 minutes
    $stmt = phoromatic_server::$db->prepare('UPDATE phoromatic_systems SET LastIP = :access_ip, LocalIP = :local_ip, LastCommunication = :current_time, Hardware = :client_hardware, Software = :client_software, ClientVersion = :client_version, MachineSelfID = :machine_self_id, NetworkMAC = :network_mac, NetworkWakeOnLAN = :network_wol, CoreVersion = :core_version WHERE AccountID = :account_id AND SystemID = :system_id');
    $stmt->bindValue(':account_id', $ACCOUNT_ID);
    $stmt->bindValue(':system_id', SYSTEM_ID);
    $stmt->bindValue(':client_hardware', $CLIENT_HARDWARE);
コード例 #2
0
function create_new_phoromatic_account($register_username, $register_password, $register_password_confirm, $register_email, $seed_accountid = null)
{
    // REGISTER NEW USER
    if (strlen($register_username) < 4 || strpos($register_username, ' ') !== false) {
        phoromatic_error_page('Oops!', 'Please go back and ensure the supplied username is at least four characters long and contains no spaces.');
        return false;
    }
    if (in_array(strtolower($register_username), array('admin', 'administrator', 'rootadmin'))) {
        phoromatic_error_page('Oops!', $register_username . ' is a reserved and common username that may be used for other purposes, please make a different selection.');
        return false;
    }
    if (strlen($register_password) < 6) {
        phoromatic_error_page('Oops!', 'Please go back and ensure the supplied password is at least six characters long.');
        return false;
    }
    if ($register_password != $register_password_confirm) {
        phoromatic_error_page('Oops!', 'Please go back and ensure the supplied password matches the password confirmation.');
        return false;
    }
    if ($register_email == null || filter_var($register_email, FILTER_VALIDATE_EMAIL) == false) {
        phoromatic_error_page('Oops!', 'Please enter a valid email address.');
        return false;
    }
    $valid_user_name_chars = '1234567890-_.abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
    for ($i = 0; $i < count($register_username); $i++) {
        if (strpos($valid_user_name_chars, substr($register_username, $i, 1)) === false) {
            phoromatic_error_page('Oops!', 'Please go back and ensure a valid user-name. The character <em>' . substr($register_username, $i, 1) . '</em> is not allowed.');
            return false;
        }
    }
    $matching_users = phoromatic_server::$db->querySingle('SELECT UserName FROM phoromatic_users WHERE UserName = \'' . SQLite3::escapeString($register_username) . '\'');
    if (!empty($matching_users)) {
        phoromatic_error_page('Oops!', 'The user-name is already taken.');
        return false;
    }
    if (phoromatic_server::read_setting('add_new_users_to_account') != null) {
        $account_id = phoromatic_server::read_setting('add_new_users_to_account');
        $is_new_account = false;
    } else {
        $id_tries = 0;
        do {
            if ($id_tries == 0 && $seed_accountid != null && isset($seed_accountid[5])) {
                $account_id = strtoupper(substr($seed_accountid, 0, 6));
            } else {
                $account_id = pts_strings::random_characters(6, true);
            }
            $matching_accounts = phoromatic_server::$db->querySingle('SELECT AccountID FROM phoromatic_accounts WHERE AccountID = \'' . $account_id . '\'');
            $id_tries++;
        } while (!empty($matching_accounts));
        $is_new_account = true;
    }
    $user_id = pts_strings::random_characters(4, true);
    if ($is_new_account) {
        pts_logger::add_to_log($_SERVER['REMOTE_ADDR'] . ' created a new account: ' . $user_id . ' - ' . $account_id);
        $account_salt = pts_strings::random_characters(12, true);
        $stmt = phoromatic_server::$db->prepare('INSERT INTO phoromatic_accounts (AccountID, ValidateID, CreatedOn, Salt) VALUES (:account_id, :validate_id, :current_time, :salt)');
        $stmt->bindValue(':account_id', $account_id);
        $stmt->bindValue(':validate_id', pts_strings::random_characters(4, true));
        $stmt->bindValue(':salt', $account_salt);
        $stmt->bindValue(':current_time', phoromatic_server::current_time());
        $result = $stmt->execute();
        $stmt = phoromatic_server::$db->prepare('INSERT INTO phoromatic_account_settings (AccountID) VALUES (:account_id)');
        $stmt->bindValue(':account_id', $account_id);
        $result = $stmt->execute();
        $stmt = phoromatic_server::$db->prepare('INSERT INTO phoromatic_user_settings (UserID, AccountID) VALUES (:user_id, :account_id)');
        $stmt->bindValue(':user_id', $user_id);
        $stmt->bindValue(':account_id', $account_id);
        $result = $stmt->execute();
    } else {
        pts_logger::add_to_log($_SERVER['REMOTE_ADDR'] . ' being added to an account: ' . $user_id . ' - ' . $account_id);
        $account_salt = phoromatic_server::$db->querySingle('SELECT Salt FROM phoromatic_accounts WHERE AccountID = \'' . $account_id . '\'');
    }
    $salted_password = hash('sha256', $account_salt . $register_password);
    $stmt = phoromatic_server::$db->prepare('INSERT INTO phoromatic_users (UserID, AccountID, UserName, Email, Password, CreatedOn, LastIP, AdminLevel) VALUES (:user_id, :account_id, :user_name, :email, :password, :current_time, :last_ip, :admin_level)');
    $stmt->bindValue(':user_id', $user_id);
    $stmt->bindValue(':account_id', $account_id);
    $stmt->bindValue(':user_name', $register_username);
    $stmt->bindValue(':email', $register_email);
    $stmt->bindValue(':password', $salted_password);
    $stmt->bindValue(':last_ip', $_SERVER['REMOTE_ADDR']);
    $stmt->bindValue(':current_time', phoromatic_server::current_time());
    $stmt->bindValue(':admin_level', $is_new_account ? 1 : 10);
    $result = $stmt->execute();
    pts_file_io::mkdir(phoromatic_server::phoromatic_account_path($account_id));
    phoromatic_server::send_email($register_email, 'Phoromatic Account Registration', ($e = phoromatic_server::read_setting('admin_support_email')) != null ? $e : '*****@*****.**', '<p><strong>' . $register_username . '</strong>:</p><p>Your Phoromatic account has been created and is now active.</p>');
    return true;
}
コード例 #3
0
//error_reporting(E_ALL | E_NOTICE | E_STRICT);
if (!function_exists('sqlite_escape_string')) {
    function sqlite_escape_string($str)
    {
        // TODO XXX SQLite3::escapeString
        return $str;
    }
}
/*
		$server_response = phoromatic::upload_to_remote_server(array(
			'test' => $test_run_request->test_profile->get_identifier(),
			'test_args' => $test_run_request->get_arguments_description()
			));
*/
$stmt = phoromatic_server::$db->prepare('INSERT INTO phoromatic_system_client_errors (AccountID, SystemID, UploadTime, ScheduleID, TriggerID, ErrorMessage, TestIdentifier, TestArguments) VALUES (:account_id, :system_id, :upload_time, :schedule_id, :trigger_id, :error_msg, :test_identifier, :test_arguments)');
$stmt->bindValue(':account_id', ACCOUNT_ID);
$stmt->bindValue(':system_id', SYSTEM_ID);
$stmt->bindValue(':upload_time', phoromatic_server::current_time());
$stmt->bindValue(':schedule_id', $SCHEDULE_ID);
$stmt->bindValue(':trigger_id', $TRIGGER_STRING);
$stmt->bindValue(':error_msg', $ERROR_MSG);
$stmt->bindValue(':test_identifier', $TEST_IDENTIFIER);
$stmt->bindValue(':test_arguments', $OTHER);
$result = $stmt->execute();
// Email notifications
$stmt = phoromatic_server::$db->prepare('SELECT UserName, Email FROM phoromatic_users WHERE UserID IN (SELECT UserID FROM phoromatic_user_settings WHERE AccountID = :account_id AND NotifyOnWarnings = 1) AND AccountID = :account_id');
$stmt->bindValue(':account_id', ACCOUNT_ID);
$result = $stmt->execute();
while ($row = $result->fetchArray()) {
    phoromatic_server::send_email($row['Email'], 'Phoromatic System Error/Warning', phoromatic_server::account_id_to_group_admin_email(ACCOUNT_ID), '<p><strong>' . $row['UserName'] . ':</strong></p><p>A warning or error has been reported by a system associated with the Phoromatic account.</p><p>System: ' . SYSTEM_NAME . '<br />Trigger String: ' . sqlite_escape_string($TRIGGER_STRING) . '<br />Test Identifier: ' . sqlite_escape_string($TEST_IDENTIFIER) . '<br />Message: ' . sqlite_escape_string($ERROR_MSG) . '</p>');
}
コード例 #4
0
 public function __construct()
 {
     $systems_already_reported = array();
     pts_client::fork(array('pts_phoromatic_event_server', 'ob_cache_run'), null);
     $is_first_run = true;
     while (true) {
         $hour = date('G');
         $minute = date('i');
         phoromatic_server::prepare_database();
         if ($is_first_run || $minute == 0) {
             if ($is_first_run || $hour == 8) {
                 pts_client::fork(array('pts_phoromatic_event_server', 'ob_cache_run'), null);
             }
             // Check for basic hung systems
             $stmt = phoromatic_server::$db->prepare('SELECT LastCommunication, CurrentTask, EstimatedTimeForTask, SystemID, AccountID, LastIP FROM phoromatic_systems WHERE State > 0 ORDER BY LastCommunication DESC');
             $result = $stmt ? $stmt->execute() : false;
             while ($result && ($row = $result->fetchArray())) {
                 $last_comm = strtotime($row['LastCommunication']);
                 if ($last_comm > time() - 3600) {
                     continue;
                 }
                 // if last comm time is less than an hour, still might be busy testing
                 if ($last_comm < time() - 3600 * 3 && !$is_first_run) {
                     continue;
                 }
                 // it's already been reported enough for now...
                 if (stripos($row['CurrentTask'], 'shutdown') !== false || stripos($row['CurrentTask'], 'shutting down') !== false) {
                     continue;
                 }
                 // if the system shutdown, no reason to report it
                 if (phoromatic_server::estimated_time_remaining_diff($row['EstimatedTimeForTask'], $row['LastCommunication']) > 0) {
                     continue;
                 }
                 // system task time didn't run out yet
                 // UPDATE SYSTEM STATUS TO "UNKNOWN"
                 $stmt_unknown = phoromatic_server::$db->prepare('UPDATE phoromatic_systems SET CurrentTask = :unknown_state WHERE AccountID = :account_id AND SystemID = :system_id');
                 $stmt_unknown->bindValue(':account_id', $row['AccountID']);
                 $stmt_unknown->bindValue(':system_id', $row['SystemID']);
                 $stmt_unknown->bindValue(':unknown_state', 'Unknown');
                 $stmt_unknown->execute();
                 $stmt_email = phoromatic_server::$db->prepare('SELECT UserName, Email FROM phoromatic_users WHERE UserID IN (SELECT UserID FROM phoromatic_user_settings WHERE AccountID = :account_id AND NotifyOnHungSystems = 1) AND AccountID = :account_id');
                 $stmt_email->bindValue(':account_id', $row['AccountID']);
                 $result_email = $stmt_email->execute();
                 while ($row_email = $result_email->fetchArray()) {
                     if (empty($row_email['Email'])) {
                         continue;
                     }
                     phoromatic_server::send_email($row_email['Email'], 'Phoromatic System Potential Hang: ' . phoromatic_server::system_id_to_name($row['SystemID'], $row['AccountID']), phoromatic_server::account_id_to_group_admin_email($row['AccountID']), '<p><strong>' . $row_email['UserName'] . ':</strong></p><p>One of the systems associated with your Phoromatic account has not been communicating with the Phoromatic Server in more than sixty minutes. Below is the system information details:</p><p><strong>System:</strong> ' . phoromatic_server::system_id_to_name($row['SystemID'], $row['AccountID']) . '<br /><strong>Last Communication:</strong> ' . phoromatic_server::user_friendly_timedate($row['LastCommunication']) . '<br /><strong>Last Task:</strong> ' . $row['CurrentTask'] . '<br /><strong>Local IP:</strong> ' . $row['LastIP'] . '</p>');
                 }
             }
         }
         if ($is_first_run || $minute % 2 == 0) {
             // Check for systems to wake
             $stmt = phoromatic_server::$db->prepare('SELECT LastCommunication, CurrentTask, SystemID, AccountID, NetworkMAC, LastIP, MaintenanceMode FROM phoromatic_systems WHERE State > 0 AND NetworkMAC NOT LIKE \'\' AND NetworkWakeOnLAN LIKE \'%g%\' ORDER BY LastCommunication DESC');
             $result = $stmt ? $stmt->execute() : false;
             while ($result && ($row = $result->fetchArray())) {
                 if (!isset($phoromatic_account_settings[$row['AccountID']])) {
                     $stmt1 = phoromatic_server::$db->prepare('SELECT NetworkPowerUpWhenNeeded, PowerOnSystemDaily FROM phoromatic_account_settings WHERE AccountID = :account_id');
                     $stmt1->bindValue(':account_id', $row['AccountID']);
                     $result1 = $stmt1->execute();
                     $phoromatic_account_settings[$row['AccountID']] = $result1->fetchArray(SQLITE3_ASSOC);
                 }
                 $last_comm = strtotime($row['LastCommunication']);
                 if ($last_comm < time() - 360 && $row['MaintenanceMode'] == 1) {
                     self::send_wol_wakeup($row['NetworkMAC'], $row['LastIP']);
                     continue;
                 }
                 if ($minute % 20 == 0 && $last_comm < time() - 3600 * 18 && $phoromatic_account_settings[$row['AccountID']]['PowerOnSystemDaily'] == 1) {
                     // Daily power on test if system hasn't communicated / powered on in a day
                     // XXX right now the "daily" power on test is 18 hours. change or make user value in future?
                     // Just doing this check every 20 minutes as not too vital
                     self::send_wol_wakeup($row['NetworkMAC'], $row['LastIP']);
                     continue;
                 }
                 if ($last_comm < time() - 600 || stripos($row['CurrentTask'], 'Shutdown') !== false) {
                     // System hasn't communicated in a number of minutes so it might be powered off
                     if (phoromatic_server::system_has_outstanding_jobs($row['AccountID'], $row['SystemID']) !== false) {
                         // Make sure account has network WoL enabled
                         if ($phoromatic_account_settings[$row['AccountID']]['NetworkPowerUpWhenNeeded'] == 1) {
                             self::send_wol_wakeup($row['NetworkMAC'], $row['LastIP']);
                         }
                     }
                 }
             }
         }
         if ($minute % 8 == 0 && $hour > 1) {
             // See if system appears down
             $stmt = phoromatic_server::$db->prepare('SELECT LastCommunication, CurrentTask, SystemID, AccountID, LastIP FROM phoromatic_systems WHERE State > 0 ORDER BY LastCommunication DESC');
             $result = $stmt ? $stmt->execute() : false;
             while ($result && ($row = $result->fetchArray())) {
                 $sys_hash = sha1($row['AccountID'] . $row['SystemID']);
                 // Avoid sending duplicate messages over time
                 if (isset($systems_already_reported[$sys_hash]) && $systems_already_reported[$sys_hash] > time() - 3600 * 24) {
                     continue;
                 }
                 if (phoromatic_server::system_check_if_down($row['AccountID'], $row['SystemID'], $row['LastCommunication'], $row['CurrentTask'])) {
                     if (strtotime($row['LastCommunication']) < time() - 86400 * 7) {
                         // If system hasn't been online in a week, likely has bigger worries...
                         continue;
                     }
                     $stmt_email = phoromatic_server::$db->prepare('SELECT UserName, Email FROM phoromatic_users WHERE UserID IN (SELECT UserID FROM phoromatic_user_settings WHERE AccountID = :account_id AND NotifyOnHungSystems = 1) AND AccountID = :account_id');
                     $stmt_email->bindValue(':account_id', $row['AccountID']);
                     $result_email = $stmt_email->execute();
                     while ($row_email = $result_email->fetchArray()) {
                         if (empty($row_email['Email'])) {
                             continue;
                         }
                         phoromatic_server::send_email($row_email['Email'], 'Phoromatic System Potential Problem: ' . phoromatic_server::system_id_to_name($row['SystemID'], $row['AccountID']), phoromatic_server::account_id_to_group_admin_email($row['AccountID']), '<p><strong>' . $row_email['UserName'] . ':</strong></p><p>One of the systems associated with your Phoromatic account has not been communicating with the Phoromatic Server and is part of a current active test schedule. Below is the system information details:</p><p><strong>System:</strong> ' . phoromatic_server::system_id_to_name($row['SystemID'], $row['AccountID']) . '<br /><strong>Last Communication:</strong> ' . phoromatic_server::user_friendly_timedate($row['LastCommunication']) . '<br /><strong>Last Task:</strong> ' . $row['CurrentTask'] . '<br /><strong>Local IP:</strong> ' . $row['LastIP'] . '</p>');
                     }
                     $systems_already_reported[$sys_hash] = time();
                 }
             }
         }
         phoromatic_server::close_database();
         sleep(60 - date('s') + 1);
         $is_first_run = false;
     }
 }
コード例 #5
0
    $stmt->bindValue(':account_id', ACCOUNT_ID);
    $stmt->bindValue(':upload_id', $upload_id);
    $stmt->bindValue(':abstract_id', $relative_id);
    $stmt->bindValue(':test_profile', $result_object->test_profile->get_identifier());
    $stmt->bindValue(':comparison_hash', $result_object->get_comparison_hash(true, false));
    $result = $stmt->execute();
}
if ($relative_id > 0) {
    foreach ($result_file->get_systems() as $s) {
        $stmt = phoromatic_server::$db->prepare('INSERT INTO phoromatic_results_systems (AccountID, UploadID, SystemIdentifier, Hardware, Software) VALUES (:account_id, :upload_id, :system_identifier, :hardware, :software)');
        $stmt->bindValue(':account_id', ACCOUNT_ID);
        $stmt->bindValue(':upload_id', $upload_id);
        $stmt->bindValue(':system_identifier', sqlite_escape_string($s->get_identifier()));
        $stmt->bindValue(':hardware', sqlite_escape_string($s->get_hardware()));
        $stmt->bindValue(':software', sqlite_escape_string($s->get_software()));
        $result = $stmt->execute();
    }
    $json['phoromatic']['response'] = 'Result Upload: ' . $upload_id;
    echo json_encode($json);
    // Email notifications
    $stmt = phoromatic_server::$db->prepare('SELECT UserName, Email FROM phoromatic_users WHERE UserID IN (SELECT UserID FROM phoromatic_user_settings WHERE AccountID = :account_id AND NotifyOnResultUploads = 1) AND AccountID = :account_id');
    $stmt->bindValue(':account_id', ACCOUNT_ID);
    $result = $stmt->execute();
    while ($row = $result->fetchArray()) {
        phoromatic_server::send_email($row['Email'], 'Phoromatic Result Upload', phoromatic_server::account_id_to_group_admin_email(ACCOUNT_ID), '<p><strong>' . $row['UserName'] . ':</strong></p><p>A new result file has been uploaded to Phoromatic.</p><p>Upload ID: ' . $upload_id . '<br />Upload Time: ' . phoromatic_server::current_time() . '<br />Title: ' . sqlite_escape_string($result_file->get_title()) . '<br />System: ' . SYSTEM_NAME . '</p>');
    }
    return true;
}
$json['phoromatic']['error'] = 'End Termination Error';
echo json_encode($json);
return false;