#feature: add ip operation log & sql generator

This commit is contained in:
2025-12-25 14:25:57 +08:00
parent 79889e1040
commit 3bcbd0661f
21 changed files with 1751 additions and 21 deletions

50
app/Support/IpAccess.php Normal file
View File

@@ -0,0 +1,50 @@
<?php
namespace App\Support;
class IpAccess
{
/**
* @return array<int, string>
*/
public static function adminIps(): array
{
return config('toolbox.admin_ips', []);
}
public static function isAdmin(?string $ip): bool
{
if (!is_string($ip) || $ip === '') {
return false;
}
$adminIps = self::adminIps();
if (empty($adminIps)) {
return false;
}
foreach ($adminIps as $pattern) {
if ($pattern === $ip) {
return true;
}
if (str_contains($pattern, '*') && self::matchWildcard($pattern, $ip)) {
return true;
}
}
return false;
}
private static function matchWildcard(string $pattern, string $ip): bool
{
if (filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4) === false) {
return false;
}
$escaped = preg_quote($pattern, '#');
$regex = str_replace('\*', '[0-9.]*', $escaped);
return (bool) preg_match('#^' . $regex . '$#', $ip);
}
}