Updated reseller for IP address CRUD

Updated reseller for IP address CRUD
This commit is contained in:
cp6 2022-02-22 15:59:30 +11:00
parent 9eafe5fa55
commit cb2ff263fb
5 changed files with 76 additions and 47 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,9 +38,8 @@ class ResellerController extends Controller
$request->validate([ $request->validate([
'domain' => 'required|min:4', 'domain' => 'required|min:4',
'reseller_type' => 'required', 'reseller_type' => 'required',
'dedicated_ip' => 'present', 'dedicated_ip' => 'present|ip',
'accounts' => 'numeric', 'accounts' => 'numeric',
'has_dedicated_ip' => 'numeric',
'server_type' => 'numeric', 'server_type' => 'numeric',
'ram' => 'numeric', 'ram' => 'numeric',
'disk' => 'numeric', 'disk' => 'numeric',
@ -66,8 +66,6 @@ class ResellerController extends Controller
'main_domain' => $request->domain, 'main_domain' => $request->domain,
'accounts' => $request->accounts, 'accounts' => $request->accounts,
'reseller_type' => $request->reseller_type, 'reseller_type' => $request->reseller_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,
@ -98,6 +96,18 @@ class ResellerController extends Controller
'next_due_date' => $request->next_due_date, 'next_due_date' => $request->next_due_date,
]); ]);
if (!is_null($request->dedicated_ip)) {
IPs::create(
[
'id' => Str::random(8),
'service_id' => $reseller_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('reseller.index') return redirect()->route('reseller.index')
->with('success', 'Reseller hosting created Successfully.'); ->with('success', 'Reseller hosting created Successfully.');
} }
@ -117,7 +127,11 @@ class ResellerController extends Controller
->where('l.service_id', '=', $reseller->id) ->where('l.service_id', '=', $reseller->id)
->get(['labels.label']); ->get(['labels.label']);
return view('reseller.show', compact(['reseller', 'reseller_extras', 'labels'])); $ip_address = DB::table('ips as i')
->where('i.service_id', '=', $reseller->id)
->get();
return view('reseller.show', compact(['reseller', 'reseller_extras', 'labels', 'ip_address']));
} }
public function edit(Reseller $reseller) public function edit(Reseller $reseller)
@ -125,12 +139,16 @@ class ResellerController extends Controller
$locations = DB::table('locations')->get(['*']); $locations = DB::table('locations')->get(['*']);
$providers = json_decode(DB::table('providers')->get(['*']), true); $providers = json_decode(DB::table('providers')->get(['*']), true);
$ip_address = json_decode(DB::table('ips as i')
->where('i.service_id', '=', $reseller->id)
->get(), true);
$reseller = DB::table('reseller_hosting as s') $reseller = DB::table('reseller_hosting as s')
->join('pricings as p', 's.id', '=', 'p.service_id') ->join('pricings as p', 's.id', '=', 'p.service_id')
->where('s.id', '=', $reseller->id) ->where('s.id', '=', $reseller->id)
->get(['s.*', 'p.*']); ->get(['s.*', 'p.*']);
return view('reseller.edit', compact(['reseller', 'locations', 'providers'])); return view('reseller.edit', compact(['reseller', 'locations', 'providers', 'ip_address']));
} }
public function update(Request $request, Reseller $reseller) public function update(Request $request, Reseller $reseller)
@ -140,7 +158,6 @@ class ResellerController extends Controller
'domain' => 'required|min:4', 'domain' => 'required|min:4',
'reseller_type' => 'required', 'reseller_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',
@ -163,8 +180,6 @@ class ResellerController extends Controller
->update([ ->update([
'main_domain' => $request->domain, 'main_domain' => $request->domain,
'reseller_type' => $request->reseller_type, 'reseller_type' => $request->reseller_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,
@ -195,6 +210,17 @@ class ResellerController extends Controller
'next_due_date' => $request->next_due_date, 'next_due_date' => $request->next_due_date,
]); ]);
$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('reseller.index') return redirect()->route('reseller.index')
->with('success', 'Reseller hosting updated Successfully.'); ->with('success', 'Reseller hosting updated Successfully.');
} }
@ -207,10 +233,12 @@ class ResellerController extends Controller
$items->delete(); $items->delete();
$p = new Pricing(); $p = new Pricing();
$p->deletePricing($reseller->id); $p->deletePricing($id);
Labels::deleteLabelsAssignedTo($id); Labels::deleteLabelsAssignedTo($id);
IPs::deleteIPsAssignedTo($id);
return redirect()->route('reseller.index') return redirect()->route('reseller.index')
->with('success', 'Reseller hosting was deleted Successfully.'); ->with('success', 'Reseller hosting was deleted Successfully.');
} }

View File

@ -17,8 +17,6 @@ class CreateResellersTable 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->integer('accounts')->default(1); $table->integer('accounts')->default(1);
$table->string('reseller_type')->nullable(); $table->string('reseller_type')->nullable();
$table->integer('provider_id')->default(9999); $table->integer('provider_id')->default(9999);

View File

@ -43,15 +43,7 @@
</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">No</option>
<option value="1">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> <div class="input-group-prepend"><span class="input-group-text">Dedicated IP</span></div>
<input type="text" name="dedicated_ip" class="form-control"></div> <input type="text" name="dedicated_ip" class="form-control"></div>

View File

@ -51,13 +51,16 @@
value="Webmin" {{ ($reseller[0]->reseller_type === 'Webmin') ? 'selected' : '' }}> value="Webmin" {{ ($reseller[0]->reseller_type === 'Webmin') ? 'selected' : '' }}>
Webmin Webmin
</option> </option>
<option value="Moss" {{ ($reseller[0]->reseller_type === 'Moss') ? 'selected' : '' }}> <option
value="Moss" {{ ($reseller[0]->reseller_type === 'Moss') ? 'selected' : '' }}>
Moss Moss
</option> </option>
<option value="Other" {{ ($reseller[0]->reseller_type === 'Other') ? 'selected' : '' }}> <option
value="Other" {{ ($reseller[0]->reseller_type === 'Other') ? 'selected' : '' }}>
Other Other
</option> </option>
<option value="Plesk" {{ ($reseller[0]->reseller_type === 'Plesk') ? 'selected' : '' }}> <option
value="Plesk" {{ ($reseller[0]->reseller_type === 'Plesk') ? 'selected' : '' }}>
Plesk Plesk
</option> </option>
<option <option
@ -75,22 +78,13 @@
</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" {{ ($reseller[0]->has_dedicated_ip === 0) ? 'selected' : '' }}>No
</option>
<option value="1" {{ ($reseller[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="{{$reseller[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>
@ -116,10 +110,12 @@
<div class="input-group"> <div class="input-group">
<div class="input-group-prepend"><span class="input-group-text">Term</span></div> <div class="input-group-prepend"><span class="input-group-text">Term</span></div>
<select class="form-control" id="payment_term" name="payment_term"> <select class="form-control" id="payment_term" name="payment_term">
<option value="1" {{ ($reseller[0]->term === 1) ? 'selected' : '' }}>Monthly</option> <option value="1" {{ ($reseller[0]->term === 1) ? 'selected' : '' }}>Monthly
</option>
<option value="2" {{ ($reseller[0]->term === 2) ? 'selected' : '' }}>Quarterly <option value="2" {{ ($reseller[0]->term === 2) ? 'selected' : '' }}>Quarterly
</option> </option>
<option value="3" {{ ($reseller[0]->term === 3) ? 'selected' : '' }}>Half annual (half <option value="3" {{ ($reseller[0]->term === 3) ? 'selected' : '' }}>Half annual
(half
year) year)
</option> </option>
<option value="4" {{ ($reseller[0]->term === 4) ? 'selected' : '' }}>Annual (yearly) <option value="4" {{ ($reseller[0]->term === 4) ? 'selected' : '' }}>Annual (yearly)
@ -200,7 +196,8 @@
<div class="col-12 col-lg-3 mb-4"> <div class="col-12 col-lg-3 mb-4">
<div class="input-group"> <div class="input-group">
<div class="input-group-prepend"><span class="input-group-text">Domains</span></div> <div class="input-group-prepend"><span class="input-group-text">Domains</span></div>
<input type="number" name="domains" class="form-control" value="{{$reseller[0]->domains_limit}}" <input type="number" name="domains" class="form-control"
value="{{$reseller[0]->domains_limit}}"
min="1" max="9999"> min="1" max="9999">
</div> </div>
</div> </div>
@ -214,7 +211,8 @@
<div class="col-12 col-lg-3 mb-4"> <div class="col-12 col-lg-3 mb-4">
<div class="input-group"> <div class="input-group">
<div class="input-group-prepend"><span class="input-group-text">Disk</span></div> <div class="input-group-prepend"><span class="input-group-text">Disk</span></div>
<input type="number" name="disk" class="form-control" value="{{$reseller[0]->disk_as_gb}}" <input type="number" name="disk" class="form-control"
value="{{$reseller[0]->disk_as_gb}}"
min="1" max="99999"> min="1" max="99999">
<div class="input-group-append"><span class="input-group-text">GB</span></div> <div class="input-group-append"><span class="input-group-text">GB</span></div>
</div> </div>
@ -222,7 +220,8 @@
<div class="col-12 col-lg-3 mb-4"> <div class="col-12 col-lg-3 mb-4">
<div class="input-group"> <div class="input-group">
<div class="input-group-prepend"><span class="input-group-text">Email</span></div> <div class="input-group-prepend"><span class="input-group-text">Email</span></div>
<input type="number" name="email" class="form-control" value="{{$reseller[0]->email_limit}}" <input type="number" name="email" class="form-control"
value="{{$reseller[0]->email_limit}}"
min="1" max="99999"> min="1" max="99999">
</div> </div>
</div> </div>
@ -241,7 +240,8 @@
<div class="col-12 col-lg-3 mb-4"> <div class="col-12 col-lg-3 mb-4">
<div class="input-group"> <div class="input-group">
<div class="input-group-prepend"><span class="input-group-text">FTP</span></div> <div class="input-group-prepend"><span class="input-group-text">FTP</span></div>
<input type="number" name="ftp" class="form-control" value="{{$reseller[0]->ftp_limit}}" min="1" <input type="number" name="ftp" class="form-control" value="{{$reseller[0]->ftp_limit}}"
min="1"
max="99999"> max="99999">
</div> </div>
</div> </div>
@ -254,7 +254,8 @@
</div> </div>
</div> </div>
<div class="form-check mt-2"> <div class="form-check mt-2">
<input class="form-check-input" name="is_active" type="checkbox" value="1" {{ ($reseller[0]->active === 1) ? 'checked' : '' }}> <input class="form-check-input" name="is_active" type="checkbox"
value="1" {{ ($reseller[0]->active === 1) ? 'checked' : '' }}>
<label class="form-check-label"> <label class="form-check-label">
I still have this server I still have this server
</label> </label>

View File

@ -34,7 +34,8 @@
</tr> </tr>
<tr> <tr>
<td class="px-2 py-2 font-bold text-muted">Main domain</td> <td class="px-2 py-2 font-bold text-muted">Main domain</td>
<td><a href="https://{{ $reseller->main_domain }}" class="text-decoration-none">{{ $reseller->main_domain }}</a></td> <td><a href="https://{{ $reseller->main_domain }}"
class="text-decoration-none">{{ $reseller->main_domain }}</a></td>
</tr> </tr>
<tr> <tr>
<td class="px-2 py-2 font-bold text-muted">Location</td> <td class="px-2 py-2 font-bold text-muted">Location</td>
@ -52,11 +53,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>{{ ($reseller->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>{{ $reseller->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>