Moved ipv6 validation in to function.class.php and made the validate code a lot prettier
parent
f525f31d6a
commit
ce5e1d8bc6
|
@ -529,6 +529,21 @@ function psm_is_cli() {
|
||||||
return (!isset($_SERVER['SERVER_SOFTWARE']) && (php_sapi_name() == 'cli' || (is_numeric($_SERVER['argc']) && $_SERVER['argc'] > 0)));
|
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) {
|
||||||
|
// if $ip is a valid ipv6 address it returns true
|
||||||
|
if(filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6)){
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
###############################################
|
###############################################
|
||||||
#
|
#
|
||||||
# Debug functions
|
# Debug functions
|
||||||
|
|
|
@ -243,7 +243,7 @@ class StatusUpdater {
|
||||||
//if(psm_is_cli()) {
|
//if(psm_is_cli()) {
|
||||||
|
|
||||||
// IPv6 ready
|
// IPv6 ready
|
||||||
if ($this->is_ipv6($this->server['ip'])) {
|
if (psm_validate_ipv6($this->server['ip'])) {
|
||||||
$socket = socket_create(AF_INET6, SOCK_RAW, 1);
|
$socket = socket_create(AF_INET6, SOCK_RAW, 1);
|
||||||
} else {
|
} else {
|
||||||
$socket = socket_create(AF_INET, SOCK_RAW, 1);
|
$socket = socket_create(AF_INET, SOCK_RAW, 1);
|
||||||
|
@ -286,23 +286,4 @@ class StatusUpdater {
|
||||||
public function getRtime() {
|
public function getRtime() {
|
||||||
return $this->rtime;
|
return $this->rtime;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Test if ip is IPv6
|
|
||||||
* @param string $ip
|
|
||||||
* @return boolean
|
|
||||||
*/
|
|
||||||
private function is_ipv6($ip) {
|
|
||||||
// If it contains anything other than hex characters, periods, colons or a / it's not IPV6
|
|
||||||
if (!preg_match("/^([0-9a-f\.\/:]+)$/",strtolower($ip))) { return false; }
|
|
||||||
|
|
||||||
// An IPV6 address needs at minimum two colons in it
|
|
||||||
if (substr_count($ip,":") < 2) { return false; }
|
|
||||||
|
|
||||||
// If any of the "octets" are longer than 4 characters it's not valid
|
|
||||||
$part = preg_split("/[:\/]/",$ip);
|
|
||||||
foreach ($part as $i) { if (strlen($i) > 4) { return false; } }
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue