Updated shared for IP address CRUD

Updated shared for IP address CRUD
This commit is contained in:
cp6 2022-02-22 16:06:23 +11:00
parent cb2ff263fb
commit 077c048dda
5 changed files with 50 additions and 28 deletions

View File

@ -2,6 +2,7 @@
namespace App\Http\Controllers; namespace App\Http\Controllers;
use App\Models\IPs;
use App\Models\Labels; use App\Models\Labels;
use App\Models\Locations; use App\Models\Locations;
use App\Models\Pricing; use App\Models\Pricing;
@ -37,8 +38,6 @@ class SharedController extends Controller
$request->validate([ $request->validate([
'domain' => 'required|min:4', 'domain' => 'required|min:4',
'shared_type' => 'required', 'shared_type' => 'required',
'dedicated_ip' => 'present',
'has_dedicated_ip' => 'numeric',
'server_type' => 'numeric', 'server_type' => 'numeric',
'ram' => 'numeric', 'ram' => 'numeric',
'disk' => 'numeric', 'disk' => 'numeric',
@ -64,8 +63,6 @@ class SharedController extends Controller
'id' => $shared_id, 'id' => $shared_id,
'main_domain' => $request->domain, 'main_domain' => $request->domain,
'shared_type' => $request->shared_type, 'shared_type' => $request->shared_type,
'has_dedicated_ip' => $request->has_dedicated_ip,
'ip' => $request->dedicated_ip,
'provider_id' => $request->provider_id, 'provider_id' => $request->provider_id,
'location_id' => $request->location_id, 'location_id' => $request->location_id,
'disk' => $request->disk, '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') return redirect()->route('shared.index')
->with('success', 'Shared hosting created Successfully.'); ->with('success', 'Shared hosting created Successfully.');
} }
@ -122,7 +131,11 @@ class SharedController extends Controller
->where('l.service_id', '=', $shared->id) ->where('l.service_id', '=', $shared->id)
->get(['labels.label']); ->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) public function edit(Shared $shared)
@ -134,12 +147,16 @@ class SharedController extends Controller
->where('l.service_id', '=', $shared->id) ->where('l.service_id', '=', $shared->id)
->get(['labels.id', 'labels.label']); ->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') $shared = DB::table('shared_hosting as s')
->join('pricings as p', 's.id', '=', 'p.service_id') ->join('pricings as p', 's.id', '=', 'p.service_id')
->where('s.id', '=', $shared->id) ->where('s.id', '=', $shared->id)
->get(['s.*', 'p.*']); ->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) public function update(Request $request, Shared $shared)
@ -149,7 +166,6 @@ class SharedController extends Controller
'domain' => 'required|min:4', 'domain' => 'required|min:4',
'shared_type' => 'required', 'shared_type' => 'required',
'dedicated_ip' => 'present', 'dedicated_ip' => 'present',
'has_dedicated_ip' => 'numeric',
'server_type' => 'numeric', 'server_type' => 'numeric',
'disk' => 'numeric', 'disk' => 'numeric',
'os_id' => 'numeric', 'os_id' => 'numeric',
@ -172,8 +188,6 @@ class SharedController extends Controller
->update([ ->update([
'main_domain' => $request->domain, 'main_domain' => $request->domain,
'shared_type' => $request->shared_type, 'shared_type' => $request->shared_type,
'has_dedicated_ip' => $request->has_dedicated_ip,
'ip' => $request->dedicated_ip,
'provider_id' => $request->provider_id, 'provider_id' => $request->provider_id,
'location_id' => $request->location_id, 'location_id' => $request->location_id,
'disk' => $request->disk, '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') return redirect()->route('shared.index')
->with('success', 'Shared hosting updated Successfully.'); ->with('success', 'Shared hosting updated Successfully.');
} }
@ -230,6 +255,8 @@ class SharedController extends Controller
Labels::deleteLabelsAssignedTo($shared->id); Labels::deleteLabelsAssignedTo($shared->id);
IPs::deleteIPsAssignedTo($shared->id);
return redirect()->route('shared.index') return redirect()->route('shared.index')
->with('success', 'Shared hosting was deleted Successfully.'); ->with('success', 'Shared hosting was deleted Successfully.');
} }

View File

@ -17,8 +17,6 @@ class CreateSharedsTable extends Migration
$table->char('id', 8)->unique(); $table->char('id', 8)->unique();
$table->tinyInteger('active')->default(1); $table->tinyInteger('active')->default(1);
$table->string('main_domain'); $table->string('main_domain');
$table->tinyInteger('has_dedicated_ip')->default(0);
$table->string('ip')->nullable()->default(null);
$table->string('shared_type')->nullable(); $table->string('shared_type')->nullable();
$table->integer('provider_id')->default(9999); $table->integer('provider_id')->default(9999);
$table->integer('location_id')->default(9999); $table->integer('location_id')->default(9999);

View File

@ -20,8 +20,6 @@ class SharedSeeder extends Seeder
"active" => 1, "active" => 1,
"main_domain" => "node.ai", "main_domain" => "node.ai",
"shared_type" => "Direct Admin", "shared_type" => "Direct Admin",
"has_dedicated_ip" => 0,
"ip" => null,
"bandwidth" => 3000, "bandwidth" => 3000,
"disk" => 45, "disk" => 45,
"disk_type" => 'GB', "disk_type" => 'GB',

View File

@ -75,22 +75,12 @@
</select> </select>
</div> </div>
</div> </div>
<div class="col-12 col-md-3 mb-3"> <div class="col-12 col-md-6 mb-3">
<div class="input-group">
<div class="input-group-prepend"><span class="input-group-text">Has dedicated IP</span>
</div>
<select class="form-control" name="has_dedicated_ip">
<option value="0" {{ ($shared[0]->has_dedicated_ip === 0) ? 'selected' : '' }}>No
</option>
<option value="1" {{ ($shared[0]->has_dedicated_ip === 1) ? 'selected' : '' }}>Yes
</option>
</select></div>
</div>
<div class="col-12 col-md-3 mb-3">
<div class="input-group"> <div class="input-group">
<div class="input-group-prepend"><span class="input-group-text">Dedicated IP</span> <div class="input-group-prepend"><span class="input-group-text">Dedicated IP</span>
</div> </div>
<input type="text" name="dedicated_ip" class="form-control" value="{{$shared[0]->ip}}"> <input type="text" name="dedicated_ip" class="form-control"
value="@if(isset($ip_address[0]['address'])){{$ip_address[0]['address']}}@endif">
</div> </div>
</div> </div>
</div> </div>

View File

@ -52,11 +52,20 @@
</tr> </tr>
<tr> <tr>
<td class="px-2 py-2 font-bold text-muted">Has dedicated IP?</td> <td class="px-2 py-2 font-bold text-muted">Has dedicated IP?</td>
<td>{{ ($shared->has_dedicated_ip)? 'Yes': 'No' }}</td> <td>
@if(isset($ip_address[0]->address))
Yes
@else
No
@endif
</td>
</tr> </tr>
<tr> <tr>
<td class="px-2 py-2 font-bold text-muted">IP</td> <td class="px-2 py-2 font-bold text-muted">IP</td>
<td>{{ $shared->ip }}</td> <td><code>@if(isset($ip_address[0]->address))
{{$ip_address[0]->address}}
@endif
</code></td>
</tr> </tr>
<tr> <tr>
<td class="px-2 py-2 font-bold text-muted">Owned since</td> <td class="px-2 py-2 font-bold text-muted">Owned since</td>