コード例 #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
//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>');
}
コード例 #3
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;
     }
 }
コード例 #4
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;