web/app/Rules/IsSiprNameOrIpAddress.php

40 lines
867 B
PHP

<?php
namespace App\Rules;
use Illuminate\Support\Facades\Hash;
use Illuminate\Contracts\Validation\Rule;
class IsSiprNameOrIpAddress implements Rule
{
/**
* Determine if the validation rule passes.
*
* @param string $attribute
* @param mixed $value
* @return bool
*/
public function passes($attribute, $value): bool
{
if (str_contains($value, 'sipr.tadah.rocks'))
{
if (count(explode('.', $value)) == 4)
{
return true;
}
}
return filter_var($value, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4 | FILTER_FLAG_NO_PRIV_RANGE) !== false;
}
/**
* Get the validation error message.
*
* @return string
*/
public function message(): string
{
return __('Not a valid SIPR name or IPv4 address.');
}
}