2021-05-13 12:40:21 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
|
|
|
|
use Illuminate\Http\Request;
|
2021-06-18 13:01:41 +00:00
|
|
|
use Illuminate\Validation\Rule;
|
2021-05-13 12:40:21 +00:00
|
|
|
|
|
|
|
use App\Models\Zone;
|
|
|
|
|
|
|
|
class ZoneController extends Controller
|
|
|
|
{
|
|
|
|
public function __construct()
|
|
|
|
{
|
|
|
|
$this->middleware('auth');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Add or edit a node
|
|
|
|
*/
|
|
|
|
public function add_edit(Request $request,Zone $o)
|
|
|
|
{
|
|
|
|
if ($request->post()) {
|
2021-06-18 13:01:41 +00:00
|
|
|
$this->authorize('admin',$o);
|
|
|
|
|
|
|
|
$request->validate([
|
|
|
|
'domain_id' => 'required|exists:domains,id',
|
|
|
|
'zone_id' => [
|
|
|
|
'required',
|
|
|
|
'digits_between:1,5',
|
|
|
|
Rule::unique('zones')->where(function ($query) use ($request,$o) {
|
|
|
|
return $query->where('domain_id',$request->post('domain_id'))
|
|
|
|
->when($o->exists,function($query) use ($o) {
|
|
|
|
return $query->where('id','<>',$o->id);
|
|
|
|
});
|
|
|
|
})
|
|
|
|
],
|
|
|
|
'system_id' => 'required|exists:systems,id',
|
2021-06-24 12:28:06 +00:00
|
|
|
'zt_id' => 'nullable|size:10|regex:/^([A-Fa-f0-9]){10}$/',
|
|
|
|
'zt_ipv4' => 'nullable|ipv4',
|
|
|
|
'zt_ipv4_mask' => 'nullable|numeric|lte:31',
|
|
|
|
'zt_ipv6' => 'nullable|ipv6',
|
|
|
|
'zt_ipv6_mask' => 'nullable|numeric|lte:112',
|
2021-06-18 13:01:41 +00:00
|
|
|
'active' => 'required|boolean',
|
|
|
|
]);
|
|
|
|
|
2021-06-24 12:28:06 +00:00
|
|
|
foreach (['zone_id','domain_id','system_id','active','notes','zt_id','zt_ipv4','zt_ipv4_mask','zt_ipv6','zt_ipv6_mask'] as $key)
|
2021-05-13 12:40:21 +00:00
|
|
|
$o->{$key} = $request->post($key);
|
|
|
|
|
|
|
|
$o->save();
|
|
|
|
|
|
|
|
return redirect()->action([self::class,'home']);
|
|
|
|
}
|
|
|
|
|
|
|
|
return view('zone.addedit')
|
|
|
|
->with('o',$o);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function home()
|
|
|
|
{
|
|
|
|
return view('zone.home');
|
|
|
|
}
|
|
|
|
}
|