diff --git a/src/psm/Util/Server/Updater/types/Service.Updater.php b/src/psm/Util/Server/Updater/types/Service.Updater.php new file mode 100644 index 00000000..53148298 --- /dev/null +++ b/src/psm/Util/Server/Updater/types/Service.Updater.php @@ -0,0 +1,102 @@ +. + * + * @package phpservermon + * @author Samuel Denis-D'Ortun + * @copyright Copyright (c) 2014 Samuel Denis-D'Ortun + * @license http://www.gnu.org/licenses/gpl.txt GNU GPL v3 + * @version Release: @package_version@ + * @link http://www.phpservermonitor.org/ + **/ +namespace psm\Util\Updater\Types; + + +require_once 'AbstractUpdater.php'; + +use psm\Service\Database; +use psm\Util\Updater; + + +class ServiceUpdater extends AbstractUpdater +{ + + const SOCK_OPEN_TIMEOUT = 3; + + public function GetIcon() + { + return 'icon-globe'; + } + + public function PrepareIP($ip) + { + // make sure websites start with http:// + if (substr($ip, 0, 4) != 'http') + { + $ip = 'http://' . $ip; + } + + return $ip; + } + + public function ValidateIP($ip) + { + if ( + !filter_var($ip, FILTER_VALIDATE_IP) + // domain regex as per http://stackoverflow.com/questions/106179/regular-expression-to-match-hostname-or-ip-address : + && !preg_match("/^(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]*[a-zA-Z0-9])\.)*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9\-]*[A-Za-z0-9])/", $ip) + ) + { + throw new \InvalidArgumentException('server_ip_bad_service'); + } + } + + + /** + * Check the current server as a website + * + * @param array $server + * + * @return boolean + */ + public function Update($server) + { + $this->StartRun(); + $errorStr = ''; + $errno = 0; + $fp = @fsockopen($server['ip'], $server['port'], $errno, $errorStr, self::SOCK_OPEN_TIMEOUT); + + if ( !empty( $errorStr )) + { + $this->SetError($errorStr); + } + + $result = ( $fp === false ) ? false : true; + + if (is_resource($fp)) + { + fclose($fp); + } + $this->StopRun(); + + + return $result; + } + + +}