mirror of
https://github.com/cp6/my-idlers.git
synced 2025-06-05 00:28:09 +00:00
Added IP who is data fetch and update
This commit is contained in:
parent
146bd64803
commit
97585e0f5b
4 changed files with 64 additions and 3 deletions
|
@ -8,6 +8,7 @@ use App\Models\SeedBoxes;
|
||||||
use App\Models\Server;
|
use App\Models\Server;
|
||||||
use App\Models\Shared;
|
use App\Models\Shared;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
|
use Illuminate\Support\Facades\Http;
|
||||||
use Illuminate\Support\Str;
|
use Illuminate\Support\Str;
|
||||||
|
|
||||||
class IPsController extends Controller
|
class IPsController extends Controller
|
||||||
|
@ -37,7 +38,7 @@ class IPsController extends Controller
|
||||||
|
|
||||||
$ip_id = Str::random(8);
|
$ip_id = Str::random(8);
|
||||||
|
|
||||||
IPs::create([
|
$ip = IPs::create([
|
||||||
'id' => $ip_id,
|
'id' => $ip_id,
|
||||||
'address' => $request->address,
|
'address' => $request->address,
|
||||||
'is_ipv4' => ($request->ip_type === 'ipv4') ? 1 : 0,
|
'is_ipv4' => ($request->ip_type === 'ipv4') ? 1 : 0,
|
||||||
|
@ -45,6 +46,8 @@ class IPsController extends Controller
|
||||||
'active' => 1
|
'active' => 1
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
$fetch = IPs::getUpdateIpInfo($ip);
|
||||||
|
|
||||||
return redirect()->route('IPs.index')
|
return redirect()->route('IPs.index')
|
||||||
->with('success', 'IP address created Successfully.');
|
->with('success', 'IP address created Successfully.');
|
||||||
}
|
}
|
||||||
|
@ -58,4 +61,17 @@ class IPsController extends Controller
|
||||||
return redirect()->route('IPs.index')
|
return redirect()->route('IPs.index')
|
||||||
->with('error', 'IP was not deleted.');
|
->with('error', 'IP was not deleted.');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getUpdateWhoIs(IPs $IP): \Illuminate\Http\RedirectResponse
|
||||||
|
{
|
||||||
|
$result = IPs::getUpdateIpInfo($IP);
|
||||||
|
|
||||||
|
if ($result) {
|
||||||
|
return redirect()->route('IPs.index')
|
||||||
|
->with('success', 'IP address updated Successfully.');
|
||||||
|
}
|
||||||
|
return redirect()->route('IPs.index')
|
||||||
|
->with('error', 'IP was not updated.');
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,6 +6,7 @@ use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
use Illuminate\Support\Facades\Cache;
|
use Illuminate\Support\Facades\Cache;
|
||||||
use Illuminate\Support\Facades\DB;
|
use Illuminate\Support\Facades\DB;
|
||||||
|
use Illuminate\Support\Facades\Http;
|
||||||
use Illuminate\Support\Str;
|
use Illuminate\Support\Str;
|
||||||
|
|
||||||
class IPs extends Model
|
class IPs extends Model
|
||||||
|
@ -16,7 +17,7 @@ class IPs extends Model
|
||||||
|
|
||||||
protected $keyType = 'string';
|
protected $keyType = 'string';
|
||||||
|
|
||||||
protected $fillable = ['id', 'active', 'service_id', 'address', 'is_ipv4'];
|
protected $fillable = ['id', 'service_id', 'address', 'is_ipv4', 'active', 'continent', 'country', 'region', 'city', 'org', 'isp', 'asn', 'timezone_gmt', 'fetched_at'];
|
||||||
|
|
||||||
public $incrementing = false;
|
public $incrementing = false;
|
||||||
|
|
||||||
|
@ -52,4 +53,33 @@ class IPs extends Model
|
||||||
return $this->hasOne(Note::class, 'service_id', 'id');
|
return $this->hasOne(Note::class, 'service_id', 'id');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function getUpdateIpInfo(IPs $IP): bool
|
||||||
|
{
|
||||||
|
\Log::debug($IP->address);
|
||||||
|
|
||||||
|
$response = Http::get("https://ipwhois.app/json/{{$IP->address}}");
|
||||||
|
|
||||||
|
if ($response->ok()) {
|
||||||
|
|
||||||
|
$data = $response->json();
|
||||||
|
|
||||||
|
\Log::debug($data);
|
||||||
|
|
||||||
|
$IP->update([
|
||||||
|
'continent' => $data['continent'],
|
||||||
|
'country' => $data['country'],
|
||||||
|
'region' => $data['region'],
|
||||||
|
'city' => $data['city'],
|
||||||
|
'org' => $data['org'],
|
||||||
|
'isp' => $data['isp'],
|
||||||
|
'asn' => $data['asn'],
|
||||||
|
'timezone_gmt' => $data['timezone_gmt'],
|
||||||
|
'fetched_at' => now()
|
||||||
|
]);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return $response->ok();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,13 +7,17 @@
|
||||||
<x-response-alerts></x-response-alerts>
|
<x-response-alerts></x-response-alerts>
|
||||||
<x-card class="shadow mt-3">
|
<x-card class="shadow mt-3">
|
||||||
<a href="{{ route('IPs.create') }}" class="btn btn-primary mb-3">Add IP</a>
|
<a href="{{ route('IPs.create') }}" class="btn btn-primary mb-3">Add IP</a>
|
||||||
<x-response-alerts></x-response-alerts>
|
|
||||||
<div class="table-responsive">
|
<div class="table-responsive">
|
||||||
<table class="table table-bordered" id="ips-table">
|
<table class="table table-bordered" id="ips-table">
|
||||||
<thead class="table-light">
|
<thead class="table-light">
|
||||||
<tr>
|
<tr>
|
||||||
<th class="text-nowrap">Type</th>
|
<th class="text-nowrap">Type</th>
|
||||||
<th class="text-nowrap">Address</th>
|
<th class="text-nowrap">Address</th>
|
||||||
|
<th class="text-nowrap">Country</th>
|
||||||
|
<th class="text-nowrap">City</th>
|
||||||
|
<th class="text-nowrap">ORG</th>
|
||||||
|
<th class="text-nowrap">ASN</th>
|
||||||
|
<th class="text-nowrap">ISP</th>
|
||||||
<th class="text-nowrap">Actions</th>
|
<th class="text-nowrap">Actions</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
|
@ -27,8 +31,17 @@
|
||||||
IPv6
|
IPv6
|
||||||
@endif</td>
|
@endif</td>
|
||||||
<td class="text-nowrap">{{ $ip->address}}</td>
|
<td class="text-nowrap">{{ $ip->address}}</td>
|
||||||
|
<td class="text-nowrap">{{ $ip->country}}</td>
|
||||||
|
<td class="text-nowrap">{{ $ip->city}}</td>
|
||||||
|
<td class="text-nowrap">{{ $ip->org}}</td>
|
||||||
|
<td class="text-nowrap">{{ $ip->asn}}</td>
|
||||||
|
<td class="text-nowrap">{{ $ip->isp}}</td>
|
||||||
<td class="text-nowrap">
|
<td class="text-nowrap">
|
||||||
<form action="{{ route('IPs.destroy', $ip->id) }}" method="POST">
|
<form action="{{ route('IPs.destroy', $ip->id) }}" method="POST">
|
||||||
|
<a href="{{ route('ip.pull.info', $ip->id) }}"
|
||||||
|
class="text-body mx-1">
|
||||||
|
<i class="fa-solid fa-arrows-rotate" title="Pull IP info"></i>
|
||||||
|
</a>
|
||||||
@csrf
|
@csrf
|
||||||
@method('DELETE')
|
@method('DELETE')
|
||||||
<i class="fas fa-trash text-danger ms-3" @click="confirmDeleteModal"
|
<i class="fas fa-trash text-danger ms-3" @click="confirmDeleteModal"
|
||||||
|
|
|
@ -65,4 +65,6 @@ Route::middleware(['auth'])->group(function () {
|
||||||
|
|
||||||
Route::get('servers-compare-choose', [ServerController::class, 'chooseCompare'])->name('servers-compare-choose');
|
Route::get('servers-compare-choose', [ServerController::class, 'chooseCompare'])->name('servers-compare-choose');
|
||||||
Route::get('servers-compare/{server1}/{server2}', [ServerController::class, 'compareServers'])->name('servers.compare');
|
Route::get('servers-compare/{server1}/{server2}', [ServerController::class, 'compareServers'])->name('servers.compare');
|
||||||
|
|
||||||
|
Route::get('ip/{IP}/pull-ip-info', [IPsController::class, 'getUpdateWhoIs'])->middleware(['throttle:10,1'])->name('ip.pull.info');
|
||||||
});
|
});
|
||||||
|
|
Loading…
Add table
Reference in a new issue