mirror of
				https://github.com/billz/raspap-webgui.git
				synced 2025-03-01 10:31:47 +00:00 
			
		
		
		
	Add validateCidr()
This commit is contained in:
		| @@ -452,3 +452,30 @@ function getBridgedState() | ||||
|     return  $arrHostapdConf['BridgedEnable']; | ||||
| } | ||||
|  | ||||
| /** | ||||
|  * Validates the format of a CIDR notation string | ||||
|  * | ||||
|  * @param string $cidr | ||||
|  * @return bool | ||||
|  */ | ||||
| function validateCidr($cidr) | ||||
| { | ||||
|     $parts = explode('/', $cidr); | ||||
|     if(count($parts) != 2) { | ||||
|         return false; | ||||
|     } | ||||
|     $ip = $parts[0]; | ||||
|     $netmask = intval($parts[1]); | ||||
|  | ||||
|     if($netmask < 0) { | ||||
|         return false; | ||||
|     } | ||||
|     if(filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)) { | ||||
|         return $netmask <= 32; | ||||
|     } | ||||
|     if(filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6)) { | ||||
|         return $netmask <= 128; | ||||
|     } | ||||
|     return false; | ||||
| } | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user