Merge 8543581972
into 7414c6e99e
commit
c7cf49f758
|
@ -277,6 +277,7 @@ function psm_curl_get($href, $header = false, $body = true, $timeout = 10, $add_
|
|||
curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
|
||||
curl_setopt($ch, CURLOPT_ENCODING, '');
|
||||
curl_setopt($ch, CURLOPT_URL, $href);
|
||||
|
||||
if($add_agent) {
|
||||
curl_setopt ($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (compatible; phpservermon/'.PSM_VERSION.'; +http://www.phpservermonitor.org)');
|
||||
}
|
||||
|
@ -529,6 +530,23 @@ function psm_is_cli() {
|
|||
return (!isset($_SERVER['SERVER_SOFTWARE']) && (php_sapi_name() == 'cli' || (is_numeric($_SERVER['argc']) && $_SERVER['argc'] > 0)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if ip is IPv6 or not
|
||||
*
|
||||
* @param string $ip
|
||||
* @return boolean
|
||||
*/
|
||||
function psm_validate_ipv6($ip) {
|
||||
// Need to remove [] on ipv6 address before we can test
|
||||
$ip = trim($ip, '[]');
|
||||
|
||||
if(filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6)){
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
###############################################
|
||||
#
|
||||
# Debug functions
|
||||
|
|
|
@ -115,6 +115,7 @@ $sm_lang = array(
|
|||
'type' => 'Тип',
|
||||
'type_website' => 'Сайт',
|
||||
'type_service' => 'Услуга',
|
||||
'type_ping' => 'Ping',
|
||||
'pattern' => 'Търсене на стринг/образец',
|
||||
'pattern_description' => 'Ако този текст не е намерен в интернет страницата (когато имате добавен сайт), той ще бъде маркиран като Офлайн. Регулярните изрази са разрешени.',
|
||||
'last_check' => 'Последна проверка',
|
||||
|
|
|
@ -115,6 +115,7 @@ $sm_lang = array(
|
|||
'type' => 'Type',
|
||||
'type_website' => 'Hjemmeside',
|
||||
'type_service' => 'Tjeneste',
|
||||
'type_ping' => 'Ping',
|
||||
'pattern' => 'Søge streng/mønster',
|
||||
'pattern_description' => 'Hvis dette mønster ikke findes på hjemmesiden, vil serveren blive markeret offline. Regulære udtryk er tilladt.',
|
||||
'last_check' => 'Sidst kontrolleret',
|
||||
|
|
|
@ -115,6 +115,7 @@ $sm_lang = array(
|
|||
'type' => 'Type',
|
||||
'type_website' => 'Website',
|
||||
'type_service' => 'Service',
|
||||
'type_ping' => 'Ping',
|
||||
'pattern' => 'Search string/pattern',
|
||||
'pattern_description' => 'If this pattern is not found on the website, the server will be marked offline. Regular expressions are allowed.',
|
||||
'last_check' => 'Letzter Check',
|
||||
|
|
|
@ -115,6 +115,7 @@ $sm_lang = array(
|
|||
'type' => 'Type',
|
||||
'type_website' => 'Website',
|
||||
'type_service' => 'Service',
|
||||
'type_ping' => 'Ping',
|
||||
'pattern' => 'Search string/pattern',
|
||||
'pattern_description' => 'If this pattern is not found on the website, the server will be marked offline. Regular expressions are allowed.',
|
||||
'last_check' => 'Last check',
|
||||
|
|
|
@ -115,6 +115,7 @@ $sm_lang = array(
|
|||
'type' => 'Tipo',
|
||||
'type_website' => 'Website',
|
||||
'type_service' => 'Service',
|
||||
'type_ping' => 'Ping',
|
||||
'pattern' => 'Search string/pattern',
|
||||
'pattern_description' => 'If this pattern is not found on the website, the server will be marked offline. Regular expressions are allowed.',
|
||||
'last_check' => 'Ultima verificación',
|
||||
|
|
|
@ -115,6 +115,7 @@ $sm_lang = array(
|
|||
'type' => 'Type',
|
||||
'type_website' => 'Site Web',
|
||||
'type_service' => 'Service',
|
||||
'type_ping' => 'Ping',
|
||||
'pattern' => 'Rechercher un texte/motif',
|
||||
'pattern_description' => 'Si ce texte n\'est par retrouvé sur le site web, le serveur est marqué hors-service. Les expressions réguliaires sont autorisées.',
|
||||
'last_check' => 'Dernière vérification',
|
||||
|
|
|
@ -115,6 +115,7 @@ $sm_lang = array(
|
|||
'type' => 'Tipo',
|
||||
'type_website' => 'Website',
|
||||
'type_service' => 'Service',
|
||||
'type_ping' => 'Ping',
|
||||
'pattern' => 'Search string/pattern',
|
||||
'pattern_description' => 'If this pattern is not found on the website, the server will be marked offline. Regular expressions are allowed.',
|
||||
'last_check' => 'Ultimo Controllo',
|
||||
|
|
|
@ -115,6 +115,7 @@ $sm_lang = array(
|
|||
'type' => 'Type',
|
||||
'type_website' => 'Website',
|
||||
'type_service' => 'Service',
|
||||
'type_ping' => 'Ping',
|
||||
'pattern' => 'Search string/regex',
|
||||
'pattern_description' => 'If this pattern is not found on the website, the server will be marked offline. Regular expressions are allowed.',
|
||||
'last_check' => '최근체크',
|
||||
|
|
|
@ -115,6 +115,7 @@ $sm_lang = array(
|
|||
'type' => 'Type',
|
||||
'type_website' => 'Website',
|
||||
'type_service' => 'Service',
|
||||
'type_ping' => 'Ping',
|
||||
'pattern' => 'Zoek voor tekst/regex',
|
||||
'pattern_description' => 'Als dit patroon niet gevonden wordt op de website, zal de server als offline gemarkeerd worden. Regular expressions zijn toegestaan.',
|
||||
'last_check' => 'Laatst gecontroleerd',
|
||||
|
|
|
@ -115,6 +115,7 @@ $sm_lang = array(
|
|||
'type' => 'Tipo',
|
||||
'type_website' => 'Website',
|
||||
'type_service' => 'Service',
|
||||
'type_ping' => 'Ping',
|
||||
'pattern' => 'Pesquisa palavra/padrão',
|
||||
'pattern_description' => 'Se esse padrão não for encontrado no site, o servidor será marcado offline. As expressões regulares são permitidas.',
|
||||
'last_check' => 'Última verificação',
|
||||
|
|
|
@ -115,6 +115,7 @@ $sm_lang = array(
|
|||
'type' => '类型',
|
||||
'type_website' => '网站',
|
||||
'type_service' => '服务',
|
||||
'type_ping' => 'Ping',
|
||||
'pattern' => '字符串/正则匹配',
|
||||
'pattern_description' => '如果在网站上未找到对应匹配内容, 则标记该网站为离线. 支持正则表达式.',
|
||||
'last_check' => '最后检查',
|
||||
|
|
|
@ -108,7 +108,7 @@ class ServerController extends AbstractServerController {
|
|||
$servers[$x]['type_icon'] = 'icon-globe';
|
||||
// add link to label
|
||||
$ip = $servers[$x]['ip'];
|
||||
if(!empty($servers[$x]['port']) && ($servers[$x]['port'] != 80)) {
|
||||
if(!empty($servers[$x]['port']) && ($servers[$x]['port'] != 80) && ($servers[$x]['port'] != 443)) {
|
||||
$ip .= ' : ' . $servers[$x]['port'];
|
||||
}
|
||||
$servers[$x]['ip'] = '<a href="'.$servers[$x]['ip'].'" target="_blank">'.$ip.'</a>';
|
||||
|
@ -208,18 +208,20 @@ class ServerController extends AbstractServerController {
|
|||
'label' => strip_tags($_POST['label']),
|
||||
'ip' => strip_tags($_POST['ip']),
|
||||
'port' => intval($_POST['port']),
|
||||
'type' => in_array($_POST['type'], array('website', 'service')) ? $_POST['type'] : 'website',
|
||||
'type' => in_array($_POST['type'], array('website', 'service', 'ping')) ? $_POST['type'] : 'website',
|
||||
'pattern' => $_POST['pattern'],
|
||||
'warning_threshold' => intval($_POST['warning_threshold']),
|
||||
'active' => in_array($_POST['active'], array('yes', 'no')) ? $_POST['active'] : 'no',
|
||||
'email' => in_array($_POST['email'], array('yes', 'no')) ? $_POST['email'] : 'no',
|
||||
'sms' => in_array($_POST['sms'], array('yes', 'no')) ? $_POST['sms'] : 'no',
|
||||
);
|
||||
// make sure websites start with http://
|
||||
if($clean['type'] == 'website' && substr($clean['ip'], 0, 4) != 'http') {
|
||||
$clean['ip'] = 'http://' . $clean['ip'];
|
||||
|
||||
// Make sure websites start with http:// or https:// if port is 443
|
||||
if($clean['type'] == 'website' && !preg_match('#^http(s)?://#', $clean['ip'])) {
|
||||
$clean['ip'] = ($clean['port'] == 443 ? 'https' : 'http') . '://' . $clean['ip'];
|
||||
}
|
||||
|
||||
|
||||
// check for edit or add
|
||||
if($this->server_id > 0) {
|
||||
// edit
|
||||
|
@ -342,6 +344,7 @@ class ServerController extends AbstractServerController {
|
|||
'label_type' => psm_get_lang('servers', 'type'),
|
||||
'label_website' => psm_get_lang('servers', 'type_website'),
|
||||
'label_service' => psm_get_lang('servers', 'type_service'),
|
||||
'label_ping' => psm_get_lang('servers', 'type_ping'),
|
||||
'label_type' => psm_get_lang('servers', 'type'),
|
||||
'label_pattern' => psm_get_lang('servers', 'pattern'),
|
||||
'label_pattern_description' => psm_get_lang('servers', 'pattern_description'),
|
||||
|
|
|
@ -206,7 +206,7 @@ class Installer {
|
|||
`ip` varchar(100) NOT NULL,
|
||||
`port` int(5) unsigned NOT NULL,
|
||||
`label` varchar(255) NOT NULL,
|
||||
`type` enum('service','website') NOT NULL default 'service',
|
||||
`type` enum('service','website','ping') NOT NULL default 'service',
|
||||
`pattern` varchar(255) NOT NULL,
|
||||
`status` enum('on','off') NOT NULL default 'on',
|
||||
`error` varchar(255) NULL,
|
||||
|
|
|
@ -82,7 +82,7 @@ class StatusUpdater {
|
|||
$this->server = $this->db->selectRow(PSM_DB_PREFIX . 'servers', array(
|
||||
'server_id' => $server_id,
|
||||
), array(
|
||||
'server_id', 'ip', 'port', 'label', 'type', 'pattern', 'status', 'active', 'warning_threshold', 'warning_threshold_counter',
|
||||
'server_id', 'ip', 'port', 'label', 'type', 'pattern', 'status', 'rtime', 'active', 'warning_threshold', 'warning_threshold_counter',
|
||||
));
|
||||
if(empty($this->server)) {
|
||||
return false;
|
||||
|
@ -95,6 +95,9 @@ class StatusUpdater {
|
|||
case 'website':
|
||||
$this->status_new = $this->updateWebsite($max_runs);
|
||||
break;
|
||||
case 'ping':
|
||||
$this->status_new = $this->updatePing($max_runs);
|
||||
break;
|
||||
}
|
||||
|
||||
// update server status
|
||||
|
@ -166,8 +169,26 @@ class StatusUpdater {
|
|||
* @return boolean
|
||||
*/
|
||||
protected function updateWebsite($max_runs, $run = 1) {
|
||||
|
||||
$starttime = microtime(true);
|
||||
|
||||
// Parse a URL and return its components
|
||||
$url = parse_url($this->server['ip']);
|
||||
|
||||
// Build url
|
||||
$this->server['ip'] = $url['scheme'] . '://' . (psm_validate_ipv6($url['host']) ? '['. $url['host'] .']' : $url['host']) . ':'.$this->server['port'] . (isset($url['path']) ? $url['path'] : '') . (isset($url['query']) ? '?'.$url['query'] : '');
|
||||
|
||||
/**
|
||||
*
|
||||
* Need php_http.dll extensions but might be a better tool for the job
|
||||
* http://stackoverflow.com/questions/14056977/function-http-build-url
|
||||
// Sets port number
|
||||
$url['port'] = (isset($url['port']) ? $url['port'] : $this->server['port'])
|
||||
// Update Server[ip]
|
||||
$this->server['ip'] = http_build_url('', $url);
|
||||
|
||||
*/
|
||||
|
||||
// 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(
|
||||
|
@ -188,7 +209,7 @@ class StatusUpdater {
|
|||
|
||||
if(empty($code_matches[0])) {
|
||||
// somehow we dont have a proper response.
|
||||
$this->error = 'no response from server';
|
||||
$this->error = 'No response from server.';
|
||||
$result = false;
|
||||
} else {
|
||||
$code = $code_matches[1][0];
|
||||
|
@ -218,6 +239,64 @@ class StatusUpdater {
|
|||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check the current server with a ping and hope to get a pong
|
||||
* @param int $max_runs
|
||||
* @param int $run
|
||||
* @return boolean
|
||||
*/
|
||||
protected function updatePing($max_runs, $run = 1) {
|
||||
$errno = 0;
|
||||
$timeout = 1;
|
||||
$package = "\x08\x00\x7d\x4b\x00\x00\x00\x00PingHost"; /* ICMP ping packet with a pre-calculated checksum */
|
||||
|
||||
// save response time
|
||||
$starttime = microtime(true);
|
||||
|
||||
/**
|
||||
* Only run if is cron
|
||||
* socket_create() need to run as root :(
|
||||
* ugly cli hack i know
|
||||
* might be a better way still have not found a solution when updating true website
|
||||
*/
|
||||
if(psm_is_cli()) {
|
||||
|
||||
// if ipv6 we have to use AF_INET6
|
||||
if (psm_validate_ipv6($this->server['ip'])) {
|
||||
// Need to remove [] on ipv6 address
|
||||
$this->server['ip'] = trim($this->server['ip'], '[]');
|
||||
$socket = socket_create(AF_INET6, SOCK_RAW, 1);
|
||||
} else {
|
||||
$socket = socket_create(AF_INET, SOCK_RAW, 1);
|
||||
}
|
||||
|
||||
socket_set_option($socket, SOL_SOCKET, SO_RCVTIMEO, array('sec' => $timeout, 'usec' => 0));
|
||||
socket_connect($socket, $this->server['ip'], null);
|
||||
socket_send($socket, $package, strLen($package), 0);
|
||||
|
||||
// if ping fails it returns false
|
||||
$status = (socket_read($socket, 255)) ? true : false;
|
||||
$this->rtime = (microtime(true) - $starttime);
|
||||
|
||||
socket_close($socket);
|
||||
|
||||
// check if server is available and rerun if asked.
|
||||
if(!$status && $run < $max_runs) {
|
||||
return $this->updatePing($max_runs, $run + 1);
|
||||
}
|
||||
|
||||
return $status;
|
||||
// If state on last update was 'on' and the update request is comming from the website
|
||||
} elseif ($this->server['status'] == 'on') {
|
||||
// need to set rtime to the value from last update, if not the latency will be 0
|
||||
$this->rtime = $this->server['rtime'];
|
||||
$this->error = 'Update skipped, status will be updated on next cron script run.';
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the error returned by the update function
|
||||
*
|
||||
|
|
|
@ -98,6 +98,7 @@
|
|||
<select id="type" name="type">
|
||||
<option value="service" {edit_type_selected_service}>{label_service}</option>
|
||||
<option value="website" {edit_type_selected_website}>{label_website}</option>
|
||||
<option value="ping" {edit_type_selected_ping}>{label_ping}</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
|
Loading…
Reference in New Issue