From 9897c928d9a467a5ecda52260b612cd22bc3de05 Mon Sep 17 00:00:00 2001 From: Deon George Date: Sun, 27 Jun 2021 01:15:19 +1000 Subject: [PATCH] Added ZT to System, more ZT validation on zone --- app/Http/Controllers/SystemController.php | 3 ++- app/Http/Controllers/ZoneController.php | 22 +++++++++++++++++++--- resources/views/system/addedit.blade.php | 13 +++++++++++-- resources/views/zone/addedit.blade.php | 6 +++--- 4 files changed, 35 insertions(+), 9 deletions(-) diff --git a/app/Http/Controllers/SystemController.php b/app/Http/Controllers/SystemController.php index da4b812..20eb0da 100644 --- a/app/Http/Controllers/SystemController.php +++ b/app/Http/Controllers/SystemController.php @@ -200,9 +200,10 @@ class SystemController extends Controller 'mailer_address' => 'nullable|regex:/^(?!:\/\/)(?=.{1,255}$)((.{1,63}\.){1,127}(?![0-9]*$)[a-z0-9-]+\.?)$/i', 'mailer_port' => 'nullable|digits_between:2,5', 'active' => 'required|boolean', + 'zt_id' => 'nullable|size:10|regex:/^([A-Fa-f0-9]){10}$/|unique:systems,zt_id,'.($o->exists ? $o->id : 0), ]); - foreach (['name','location','sysop','address','port','active','method','notes','mailer_type','mailer_address','mailer_port'] as $key) + foreach (['name','location','sysop','address','port','active','method','notes','mailer_type','mailer_address','mailer_port','zt_id'] as $key) $o->{$key} = $request->post($key); $o->save(); diff --git a/app/Http/Controllers/ZoneController.php b/app/Http/Controllers/ZoneController.php index 68f83d6..667b348 100644 --- a/app/Http/Controllers/ZoneController.php +++ b/app/Http/Controllers/ZoneController.php @@ -35,11 +35,27 @@ class ZoneController extends Controller }) ], 'system_id' => 'required|exists:systems,id', - 'zt_id' => 'nullable|size:10|regex:/^([A-Fa-f0-9]){10}$/', + 'zt_id' => 'nullable|size:16|regex:/^([A-Fa-f0-9]){16}$/|unique:zones,zt_id,'.($o->exists ? $o->id : 0), 'zt_ipv4' => 'nullable|ipv4', - 'zt_ipv4_mask' => 'nullable|numeric|lte:31', + 'zt_ipv4_mask' => [ + 'nullable','numeric','lte:31','required_with:zt_ipv4', + Rule::unique('zones')->where(function ($query) use ($request,$o) { + return $query->where('zt_ipv4',$request->post('zt_ipv4')) + ->where('zt_ipv4_mask',$request->post('zt_ipv4_mask')) + ->when($o->exists,function($query) use ($o) { + return $query->where('id','<>',$o->id); + }); + })], 'zt_ipv6' => 'nullable|ipv6', - 'zt_ipv6_mask' => 'nullable|numeric|lte:112', + 'zt_ipv6_mask' => [ + 'nullable','numeric','lte:112','required_with:zt_ipv6', + Rule::unique('zones')->where(function ($query) use ($request,$o) { + return $query->where('zt_ipv6',$request->post('zt_ipv6')) + ->where('zt_ipv6_mask',$request->post('zt_ipv6_mask')) + ->when($o->exists,function($query) use ($o) { + return $query->where('id','<>',$o->id); + }); + })], 'active' => 'required|boolean', ]); diff --git a/resources/views/system/addedit.blade.php b/resources/views/system/addedit.blade.php index abfcaa4..1f77bfa 100644 --- a/resources/views/system/addedit.blade.php +++ b/resources/views/system/addedit.blade.php @@ -60,8 +60,17 @@ -
- ZeroTier ID +
+ +
+ + + + @error('zt_id') + {{ $message }} + @enderror + +
diff --git a/resources/views/zone/addedit.blade.php b/resources/views/zone/addedit.blade.php index b2291a4..8f4833b 100644 --- a/resources/views/zone/addedit.blade.php +++ b/resources/views/zone/addedit.blade.php @@ -86,7 +86,7 @@
-
+
@@ -117,11 +117,11 @@
-
+
- + /