Updates to service updating - broadband
This commit is contained in:
43
app/Rules/IPv4_CIDR.php
Normal file
43
app/Rules/IPv4_CIDR.php
Normal file
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
namespace App\Rules;
|
||||
|
||||
use Illuminate\Contracts\Validation\Rule;
|
||||
|
||||
class IPv4_CIDR implements Rule
|
||||
{
|
||||
private const MAX=32;
|
||||
|
||||
/**
|
||||
* Determine if the validation rule passes.
|
||||
*
|
||||
* @param string $attribute
|
||||
* @param mixed $value
|
||||
* @return bool
|
||||
*/
|
||||
public function passes($attribute, $value)
|
||||
{
|
||||
if (str_contains($value,'/')) {
|
||||
list($value,$mask) = explode('/',$value);
|
||||
|
||||
$m = filter_var($mask,\FILTER_VALIDATE_INT,[
|
||||
'options' => [
|
||||
'min_range' => 0,
|
||||
"max_range" => self::MAX,
|
||||
]]
|
||||
);
|
||||
|
||||
return $m && filter_var($value,\FILTER_VALIDATE_IP,\FILTER_FLAG_IPV4);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation error message.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function message()
|
||||
{
|
||||
return 'The :attribute must be a valid IPv4 CIDR range.';
|
||||
}
|
||||
}
|
43
app/Rules/IPv6_CIDR.php
Normal file
43
app/Rules/IPv6_CIDR.php
Normal file
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
namespace App\Rules;
|
||||
|
||||
use Illuminate\Contracts\Validation\Rule;
|
||||
|
||||
class IPv6_CIDR implements Rule
|
||||
{
|
||||
private const MAX=128;
|
||||
|
||||
/**
|
||||
* Determine if the validation rule passes.
|
||||
*
|
||||
* @param string $attribute
|
||||
* @param mixed $value
|
||||
* @return bool
|
||||
*/
|
||||
public function passes($attribute, $value)
|
||||
{
|
||||
if (str_contains($value,':') && str_contains($value,'/')) {
|
||||
list($value,$mask) = explode('/',$value);
|
||||
|
||||
$m = filter_var($mask,\FILTER_VALIDATE_INT,[
|
||||
'options' => [
|
||||
'min_range' => 0,
|
||||
"max_range" => self::MAX,
|
||||
]
|
||||
]);
|
||||
|
||||
return $m && filter_var($value,\FILTER_VALIDATE_IP,\FILTER_FLAG_IPV6);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation error message.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function message()
|
||||
{
|
||||
return 'The :attribute must be a valid IPv6 CIDR range.';
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user