Skip to main content

Black Friday 2025! Only until December 1st: coupon FRIDAY25 for 40% off Yearly/Lifetime membership!

Read more here

protonemedia/eddy-server-management

507 stars
2 code files
View protonemedia/eddy-server-management on GitHub

app/Rules/FirewallPort.php

Open in GitHub
use Closure;
use Illuminate\Contracts\Validation\ValidationRule;
use Illuminate\Support\Str;
 
class FirewallPort implements ValidationRule
{
public function validate(string $attribute, mixed $value, Closure $fail): void
{
if (is_numeric($value)) {
if ($value < 1 || $value > 65535) {
$fail(__('The :attribute field must be between :min and :max.', ['min' => 1, 'max' => 65535]));
}
 
return;
}
 
if (Str::substrCount($value, ':') !== 1) {
$fail(__('The :attribute field is invalid.'));
 
return;
}
 
[$fromPort, $toPort] = explode(':', $value);
 
if ($toPort < $fromPort) {
$fail(__('The range is invalid.'));
}
 
if ($toPort < 1 || $toPort > 65535) {
$fail(__('The :attribute field must be between :min and :max.', ['min' => 1, 'max' => 65535]));
}
 
if ($fromPort < 1 || $fromPort > 65535) {
$fail(__('The :attribute field must be between :min and :max.', ['min' => 1, 'max' => 65535]));
}
}
}

app/Http/Controllers/FirewallRuleController.php

Open in GitHub
use App\Enum;
use App\Models\Server;
use App\Rules\FirewallPort;
use App\Server\Firewall\RuleAction;
use Illuminate\Http\Request;
 
class FirewallRuleController extends Controller
{
// ...
 
public function store(Server $server, Request $request)
{
$data = $request->validate([
'name' => ['required', 'string', 'max:255'],
'action' => ['required', 'string', Enum::rule(RuleAction::class)],
'port' => ['required', new FirewallPort],
'from_ipv4' => ['nullable', 'string', 'ipv4'],
]);
 
// ...
}
 
// ...
}

We'd Love Your Feedback

Tell us what you like or what we can improve

Feel free to share anything you like or dislike about this page or the platform in general.