diff --git a/src/lang/de_DE.lang.php b/src/lang/de_DE.lang.php index fd8aee95..885d6199 100644 --- a/src/lang/de_DE.lang.php +++ b/src/lang/de_DE.lang.php @@ -125,6 +125,7 @@ $sm_lang = array( 'type' => 'Typ', 'type_website' => 'Webseite', 'type_service' => 'Service', + 'type_ping' => 'Ping', 'pattern' => 'Suchstring/-muster', 'pattern_description' => 'Wenn das gesuchte Muster nicht in der Webseite ist, wird die Seite als offline markiert. Reguläre Ausdrücke sind erlaubt.', 'last_check' => 'Letzter Check', diff --git a/src/psm/Module/Server/Controller/ServerController.php b/src/psm/Module/Server/Controller/ServerController.php index c2c61db2..748f5434 100644 --- a/src/psm/Module/Server/Controller/ServerController.php +++ b/src/psm/Module/Server/Controller/ServerController.php @@ -286,6 +286,8 @@ class ServerController extends AbstractServerController { $clean["port"] = 443; } elseif ($tmp["scheme"] === "http") { $clean["port"] = 80; + } elseif ($tmp["scheme"] === "rdp") { + $clean["port"] = 3389; } } @@ -458,6 +460,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_pattern' => psm_get_lang('servers', 'pattern'), 'label_pattern_description' => psm_get_lang('servers', 'pattern_description'), 'label_last_check' => psm_get_lang('servers', 'last_check'), diff --git a/src/psm/Util/Server/ServerValidator.php b/src/psm/Util/Server/ServerValidator.php index 8b23d14f..4c97333f 100644 --- a/src/psm/Util/Server/ServerValidator.php +++ b/src/psm/Util/Server/ServerValidator.php @@ -101,6 +101,11 @@ class ServerValidator { throw new \InvalidArgumentException('server_ip_bad_service'); } break; + case 'ping': + if(!filter_var($value, FILTER_VALIDATE_IP)) { + throw new \InvalidArgumentException('server_ip_bad_service'); + } + break; } return true; @@ -113,7 +118,7 @@ class ServerValidator { * @throws \InvalidArgumentException */ public function type($type) { - if(!in_array($type, array('service', 'website'))) { + if(!in_array($type, array('ping', 'service', 'website'))) { throw new \InvalidArgumentException('server_type_invalid'); } return true; diff --git a/src/psm/Util/Server/Updater/StatusUpdater.php b/src/psm/Util/Server/Updater/StatusUpdater.php index 84b147e1..ad787b2f 100644 --- a/src/psm/Util/Server/Updater/StatusUpdater.php +++ b/src/psm/Util/Server/Updater/StatusUpdater.php @@ -90,6 +90,9 @@ class StatusUpdater { } switch($this->server['type']) { + case 'ping': + $this->status_new = $this->updatePing($max_runs); + break; case 'service': $this->status_new = $this->updateService($max_runs); break; @@ -134,6 +137,41 @@ class StatusUpdater { } + /** + * Check the current servers ping status - Code from http://stackoverflow.com/a/20467492 + * @param int $max_runs + * @param int $run + * @return boolean + */ + protected function updatePing($max_runs, $run = 1) { + $errno = 0; + // save response time + $starttime = microtime(true); + // set ping payload + $package = "\x08\x00\x7d\x4b\x00\x00\x00\x00PingHost"; + + $fp = @fsockopen ($this->server['ip'], $this->server['port'], $errno, $this->error, 10); + $socket = socket_create(AF_INET, SOCK_RAW, 1); + socket_set_option($socket, SOL_SOCKET, SO_RCVTIMEO, array('sec' => 10, 'usec' => 0)); + socket_connect($socket, $this->server['ip'], null); + + socket_send($socket, $package, strLen($package), 0); + if (socket_read($socket, 255)) { + $this->rtime = microtime(true) - $starttime; + $status = true; + } else { + $status = false; + } + 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; + } + /** * Check the current server as a service * @param int $max_runs diff --git a/src/templates/default/module/server/server/update.tpl.html b/src/templates/default/module/server/server/update.tpl.html index 2378d21e..4f26e357 100644 --- a/src/templates/default/module/server/server/update.tpl.html +++ b/src/templates/default/module/server/server/update.tpl.html @@ -20,6 +20,7 @@