From 077c048dda7e997f0a5228497066c5837e21a26e Mon Sep 17 00:00:00 2001 From: cp6 Date: Tue, 22 Feb 2022 16:06:23 +1100 Subject: [PATCH] Updated shared for IP address CRUD Updated shared for IP address CRUD --- app/Http/Controllers/SharedController.php | 45 +++++++++++++++---- ...2022_02_03_040140_create_shareds_table.php | 2 - database/seeders/SharedSeeder.php | 2 - resources/views/shared/edit.blade.php | 16 ++----- resources/views/shared/show.blade.php | 13 +++++- 5 files changed, 50 insertions(+), 28 deletions(-) diff --git a/app/Http/Controllers/SharedController.php b/app/Http/Controllers/SharedController.php index 42fbe7f..8f8d5ce 100644 --- a/app/Http/Controllers/SharedController.php +++ b/app/Http/Controllers/SharedController.php @@ -2,6 +2,7 @@ namespace App\Http\Controllers; +use App\Models\IPs; use App\Models\Labels; use App\Models\Locations; use App\Models\Pricing; @@ -37,8 +38,6 @@ class SharedController extends Controller $request->validate([ 'domain' => 'required|min:4', 'shared_type' => 'required', - 'dedicated_ip' => 'present', - 'has_dedicated_ip' => 'numeric', 'server_type' => 'numeric', 'ram' => 'numeric', 'disk' => 'numeric', @@ -64,8 +63,6 @@ class SharedController extends Controller 'id' => $shared_id, 'main_domain' => $request->domain, 'shared_type' => $request->shared_type, - 'has_dedicated_ip' => $request->has_dedicated_ip, - 'ip' => $request->dedicated_ip, 'provider_id' => $request->provider_id, 'location_id' => $request->location_id, 'disk' => $request->disk, @@ -104,6 +101,18 @@ class SharedController extends Controller } } + if (!is_null($request->dedicated_ip)) { + IPs::create( + [ + 'id' => Str::random(8), + 'service_id' => $shared_id, + 'address' => $request->dedicated_ip, + 'is_ipv4' => (filter_var($request->dedicated_ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6)) ? 0 : 1, + 'active' => 1 + ] + ); + } + return redirect()->route('shared.index') ->with('success', 'Shared hosting created Successfully.'); } @@ -122,7 +131,11 @@ class SharedController extends Controller ->where('l.service_id', '=', $shared->id) ->get(['labels.label']); - return view('shared.show', compact(['shared', 'shared_extras', 'labels'])); + $ip_address = DB::table('ips as i') + ->where('i.service_id', '=', $shared->id) + ->get(); + + return view('shared.show', compact(['shared', 'shared_extras', 'labels', 'ip_address'])); } public function edit(Shared $shared) @@ -134,12 +147,16 @@ class SharedController extends Controller ->where('l.service_id', '=', $shared->id) ->get(['labels.id', 'labels.label']); + $ip_address = json_decode(DB::table('ips as i') + ->where('i.service_id', '=', $shared->id) + ->get(), true); + $shared = DB::table('shared_hosting as s') ->join('pricings as p', 's.id', '=', 'p.service_id') ->where('s.id', '=', $shared->id) ->get(['s.*', 'p.*']); - return view('shared.edit', compact(['shared', 'locations', 'providers', 'labels'])); + return view('shared.edit', compact(['shared', 'locations', 'providers', 'labels', 'ip_address'])); } public function update(Request $request, Shared $shared) @@ -149,7 +166,6 @@ class SharedController extends Controller 'domain' => 'required|min:4', 'shared_type' => 'required', 'dedicated_ip' => 'present', - 'has_dedicated_ip' => 'numeric', 'server_type' => 'numeric', 'disk' => 'numeric', 'os_id' => 'numeric', @@ -172,8 +188,6 @@ class SharedController extends Controller ->update([ 'main_domain' => $request->domain, 'shared_type' => $request->shared_type, - 'has_dedicated_ip' => $request->has_dedicated_ip, - 'ip' => $request->dedicated_ip, 'provider_id' => $request->provider_id, 'location_id' => $request->location_id, 'disk' => $request->disk, @@ -214,6 +228,17 @@ class SharedController extends Controller } } + $delete_ip = DB::table('ips')->where('service_id', '=', $request->id)->delete(); + + if (isset($request->dedicated_ip)) { + DB::insert('INSERT IGNORE INTO ips (id, address, service_id, is_ipv4) values (?, ?, ?, ?)', [ + Str::random(8), + $request->dedicated_ip, + $request->id, + (filter_var($request->dedicated_ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6)) ? 0 : 1 + ]); + } + return redirect()->route('shared.index') ->with('success', 'Shared hosting updated Successfully.'); } @@ -230,6 +255,8 @@ class SharedController extends Controller Labels::deleteLabelsAssignedTo($shared->id); + IPs::deleteIPsAssignedTo($shared->id); + return redirect()->route('shared.index') ->with('success', 'Shared hosting was deleted Successfully.'); } diff --git a/database/migrations/2022_02_03_040140_create_shareds_table.php b/database/migrations/2022_02_03_040140_create_shareds_table.php index ca70310..c30457b 100644 --- a/database/migrations/2022_02_03_040140_create_shareds_table.php +++ b/database/migrations/2022_02_03_040140_create_shareds_table.php @@ -17,8 +17,6 @@ class CreateSharedsTable extends Migration $table->char('id', 8)->unique(); $table->tinyInteger('active')->default(1); $table->string('main_domain'); - $table->tinyInteger('has_dedicated_ip')->default(0); - $table->string('ip')->nullable()->default(null); $table->string('shared_type')->nullable(); $table->integer('provider_id')->default(9999); $table->integer('location_id')->default(9999); diff --git a/database/seeders/SharedSeeder.php b/database/seeders/SharedSeeder.php index 1aae5cc..a27c58d 100644 --- a/database/seeders/SharedSeeder.php +++ b/database/seeders/SharedSeeder.php @@ -20,8 +20,6 @@ class SharedSeeder extends Seeder "active" => 1, "main_domain" => "node.ai", "shared_type" => "Direct Admin", - "has_dedicated_ip" => 0, - "ip" => null, "bandwidth" => 3000, "disk" => 45, "disk_type" => 'GB', diff --git a/resources/views/shared/edit.blade.php b/resources/views/shared/edit.blade.php index 38cc04f..5737415 100644 --- a/resources/views/shared/edit.blade.php +++ b/resources/views/shared/edit.blade.php @@ -75,22 +75,12 @@ -
-
-
Has dedicated IP -
-
-
-
+
Dedicated IP
- +
diff --git a/resources/views/shared/show.blade.php b/resources/views/shared/show.blade.php index cebd9ce..34143c6 100644 --- a/resources/views/shared/show.blade.php +++ b/resources/views/shared/show.blade.php @@ -52,11 +52,20 @@ Has dedicated IP? - {{ ($shared->has_dedicated_ip)? 'Yes': 'No' }} + + @if(isset($ip_address[0]->address)) + Yes + @else + No + @endif + IP - {{ $shared->ip }} + @if(isset($ip_address[0]->address)) + {{$ip_address[0]->address}} + @endif + Owned since