protected function _auth_https_post($host, $path, $data) { $url = $host . $path . $data; return psm_curl_get($url); }
/** * Check if an update is available for PHP Server Monitor. * * Will only check for new version if user turned updates on in config. * @return boolean */ function psm_update_available() { if (!psm_get_conf('show_update')) { // user does not want updates, fair enough. return false; } $last_update = psm_get_conf('last_update_check'); if (time() - PSM_UPDATE_INTERVAL > $last_update) { // been more than a week since update, lets go // update last check date psm_update_conf('last_update_check', time()); $latest = psm_curl_get(PSM_UPDATE_URL); // add latest version to database if ($latest !== false && strlen($latest) < 15) { psm_update_conf('version_update_check', $latest); } } else { $latest = psm_get_conf('version_update_check'); } if ($latest != false) { $current = psm_get_conf('version'); return version_compare($latest, $current, '>'); } else { return false; } }
/** * Check the current server as a website * @param int $max_runs * @param int $run * @return boolean */ protected function updateWebsite($max_runs, $run = 1) { $starttime = microtime(true); // We're only interested in the header, because that should tell us plenty! // unless we have a pattern to search for! $curl_result = psm_curl_get($this->server['ip'], true, $this->server['pattern'] == '' ? false : true, $this->server['timeout'], true, $this->server['website_username'], psm_password_decrypt($this->server['server_id'] . psm_get_conf('password_encrypt_key'), $this->server['website_password'])); $this->rtime = microtime(true) - $starttime; // the first line would be the status code.. $status_code = strtok($curl_result, "\r\n"); // keep it general // $code[1][0] = status code // $code[2][0] = name of status code $code_matches = array(); preg_match_all("/[A-Z]{2,5}\\/\\d\\.\\d\\s(\\d{3})\\s(.*)/", $status_code, $code_matches); if (empty($code_matches[0])) { // somehow we dont have a proper response. $this->error = 'TIMEOUT ERROR: no response from server'; $result = false; } else { $code = $code_matches[1][0]; $msg = $code_matches[2][0]; // All status codes starting with a 4 or higher mean trouble! if (substr($code, 0, 1) >= '4') { $this->error = "HTTP STATUS ERROR: " . $code . ' ' . $msg; $result = false; } else { $result = true; //Okay, the HTTP status is good : 2xx or 3xx. Now we have to test the pattern if it's set up if ($this->server['pattern'] != '') { // Check to see if the pattern was found. if (!preg_match("/{$this->server['pattern']}/i", $curl_result)) { $this->error = 'TEXT ERROR : Pattern not found.'; $result = false; } } } } // check if server is available and rerun if asked. if (!$result && $run < $max_runs) { return $this->updateWebsite($max_runs, $run + 1); } return $result; }