mirror of
https://github.com/vitodeploy/vito.git
synced 2025-07-07 00:42:34 +00:00
init
This commit is contained in:
19
app/ValidationRules/CronRule.php
Executable file
19
app/ValidationRules/CronRule.php
Executable file
@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\ValidationRules;
|
||||
|
||||
use Cron\CronExpression;
|
||||
use Illuminate\Contracts\Validation\Rule;
|
||||
|
||||
class CronRule implements Rule
|
||||
{
|
||||
public function passes($attribute, $value): bool
|
||||
{
|
||||
return CronExpression::isValidExpression($value);
|
||||
}
|
||||
|
||||
public function message(): string
|
||||
{
|
||||
return __('Invalid frequency');
|
||||
}
|
||||
}
|
22
app/ValidationRules/DomainRule.php
Executable file
22
app/ValidationRules/DomainRule.php
Executable file
@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace App\ValidationRules;
|
||||
|
||||
use Illuminate\Contracts\Validation\Rule;
|
||||
|
||||
class DomainRule implements Rule
|
||||
{
|
||||
public function passes($attribute, $value): bool
|
||||
{
|
||||
if ($value) {
|
||||
return preg_match("/^(?!\-)(?:[a-zA-Z\d\-]{0,62}[a-zA-Z\d]\.){1,126}(?!\d+)[a-zA-Z\d]{1,63}$/", $value);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function message(): string
|
||||
{
|
||||
return __('Domain is not valid');
|
||||
}
|
||||
}
|
28
app/ValidationRules/RestrictedIPAddressesRule.php
Executable file
28
app/ValidationRules/RestrictedIPAddressesRule.php
Executable file
@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace App\ValidationRules;
|
||||
|
||||
use Illuminate\Contracts\Validation\Rule;
|
||||
|
||||
class RestrictedIPAddressesRule implements Rule
|
||||
{
|
||||
/**
|
||||
* Determine if the validation rule passes.
|
||||
*
|
||||
* @param string $attribute
|
||||
* @param mixed $value
|
||||
* @return bool
|
||||
*/
|
||||
public function passes($attribute, $value)
|
||||
{
|
||||
return ! in_array($value, config('core.restricted_ip_addresses'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array|\Illuminate\Contracts\Translation\Translator|string|null
|
||||
*/
|
||||
public function message()
|
||||
{
|
||||
return __('IP address is restricted.');
|
||||
}
|
||||
}
|
50
app/ValidationRules/SshKeyRule.php
Executable file
50
app/ValidationRules/SshKeyRule.php
Executable file
@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
namespace App\ValidationRules;
|
||||
|
||||
use Illuminate\Contracts\Validation\Rule;
|
||||
|
||||
class SshKeyRule implements Rule
|
||||
{
|
||||
/**
|
||||
* Determine if the validation rule passes.
|
||||
*
|
||||
* @param string $attribute
|
||||
* @param mixed $value
|
||||
* @return bool
|
||||
*/
|
||||
public function passes($attribute, $value)
|
||||
{
|
||||
$key_parts = explode(' ', $value, 3);
|
||||
if (count($key_parts) < 2) {
|
||||
return false;
|
||||
}
|
||||
if (count($key_parts) > 3) {
|
||||
return false;
|
||||
}
|
||||
$algorithm = $key_parts[0];
|
||||
$key = $key_parts[1];
|
||||
if (! in_array($algorithm, ['ssh-rsa', 'ssh-dss'])) {
|
||||
return false;
|
||||
}
|
||||
$key_base64_decoded = base64_decode($key, true);
|
||||
if ($key_base64_decoded == false) {
|
||||
return false;
|
||||
}
|
||||
$check = base64_decode(substr($key, 0, 16));
|
||||
$check = preg_replace("/[^\w\-]/", '', $check);
|
||||
if ((string) $check !== (string) $algorithm) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array|\Illuminate\Contracts\Translation\Translator|string|null
|
||||
*/
|
||||
public function message()
|
||||
{
|
||||
return __('Invalid key');
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user