-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c433099
commit eb338d3
Showing
10 changed files
with
314 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers; | ||
|
||
use Illuminate\Http\Request; | ||
use App\Models\NethsecurityPCI; | ||
use App\Models\NethserverPCI; | ||
|
||
class PciController extends Controller | ||
{ | ||
public function index(Request $request, string $installation){ | ||
$pciSearch = $request->input('pci_search'); | ||
$pciHardwareMatch = []; | ||
$count = 0; | ||
|
||
if($pciSearch === null || $pciSearch === ''){ | ||
return view('hardwarePci', ['pciHardwareMatch' => collect(), | ||
'installation' => $installation, | ||
'pciSearch' => $pciSearch]); | ||
} | ||
|
||
if($installation === 'NethSecurity'){ | ||
if(! empty($pciSearch)){ | ||
if (preg_match('/^[0-9a-fA-F]{4}:[0-9a-fA-F]{4}$/', $pciSearch)){ | ||
$ids = explode(':', $pciSearch); | ||
$vendorId = $ids[0]; | ||
$deviceId = $ids[1]; | ||
|
||
$pciHardwareMatch = NethsecurityPCI::where('vendor_id', $vendorId) | ||
->where('device_id', $deviceId) | ||
->get(); | ||
}else{ | ||
return view('hardwarePci', ['installation' => $installation, 'pciSearch' => $pciSearch]) | ||
-> with('error','The format of the PCI ID is incorrect. Make sure to enter a value in the correct | ||
format (xxxx:xxxx), where xxxx represents a sequence of 4 hexadecimal characters.'); | ||
} | ||
} | ||
}else if($installation === 'NethServer'){ | ||
if(! empty($pciSearch)){ | ||
if (preg_match('/^[0-9a-fA-F]{4}:[0-9a-fA-F]{4}$/', $pciSearch)) { | ||
$ids = explode(':', $pciSearch); | ||
$vendorId = $ids[0]; | ||
$deviceId = $ids[1]; | ||
|
||
$pciHardwareMatch = NethserverPCI::where('vendor_id', $vendorId) | ||
->where('device_id', $deviceId) | ||
->get(); | ||
}else { | ||
return view('hardwarePci', ['installation' => $installation, 'pciSearch' => $pciSearch]) | ||
-> with('error','The format of the PCI ID is incorrect. Make sure to enter a value in the correct | ||
format (xxxx:xxxx), where xxxx represents a sequence of 4 hexadecimal characters.'); | ||
} | ||
} | ||
} | ||
|
||
$count = $pciHardwareMatch->count(); | ||
|
||
$pciHardware = []; | ||
$hardwareCounts = []; | ||
|
||
foreach ($pciHardwareMatch as $hardware){ | ||
$key = $hardware->class_id . '_' | ||
. $hardware->vendor_id . '_' | ||
. $hardware->device_id . '_' | ||
. $hardware->class_name . '_' | ||
. $hardware->vendor_name . '_' | ||
. $hardware->device_name . '_' | ||
. $hardware->driver; | ||
|
||
if(array_key_exists($key, $pciHardware)){ | ||
$hardwareCounts[$key]++; | ||
}else{ | ||
$pciHardware[$key] = $hardware; | ||
$hardwareCounts[$key] = 1; | ||
} | ||
} | ||
|
||
return view('hardwarePci', ['pciHardware' => $pciHardware, | ||
'count' => $count, | ||
'installation' => $installation, | ||
'hardwareCounts' => $hardwareCounts, | ||
'pciSearch' => $pciSearch]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?php | ||
|
||
namespace App\Models; | ||
|
||
use Illuminate\Database\Eloquent\Model; | ||
|
||
class NethsecurityPCI extends Model | ||
{ | ||
protected $table= 'nethsecurity_pci'; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?php | ||
|
||
namespace App\Models; | ||
|
||
use Illuminate\Database\Eloquent\Model; | ||
|
||
class NethserverPCI extends Model | ||
{ | ||
protected $table= 'nethserver_pci'; | ||
} |
38 changes: 38 additions & 0 deletions
38
database/migrations/2024_04_23_102211_nethserver_pci_view.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?php | ||
|
||
use Illuminate\Database\Migrations\Migration; | ||
use Illuminate\Support\Facades\DB; | ||
|
||
return new class extends Migration | ||
{ | ||
/** | ||
* Run the migrations. | ||
*/ | ||
public function up(): void | ||
{ | ||
DB::statement(" | ||
CREATE OR REPLACE VIEW nethserver_pci AS | ||
SELECT | ||
pci_obj->>'class_id' as class_id, | ||
pci_obj->>'vendor_id' as vendor_id, | ||
pci_obj->>'device_id' as device_id, | ||
pci_obj->>'class_name' as class_name, | ||
pci_obj->>'vendor_name' as vendor_name, | ||
pci_obj->>'device_name' as device_name, | ||
pci_obj->>'driver' as driver | ||
FROM installations, | ||
json_array_elements(data->'facts'->'nodes'->'1'->'pci') as pci_obj | ||
WHERE data->>'installation' LIKE 'nethserver' | ||
AND (data->'facts'->'nodes'->'1'->'product'->>'name') IS NOT NULL | ||
AND updated_at >= CURRENT_TIMESTAMP - INTERVAL '72 hours'; | ||
"); | ||
} | ||
|
||
/** | ||
* Reverse the migrations. | ||
*/ | ||
public function down(): void | ||
{ | ||
DB::statement("DROP VIEW IF EXISTS nethserver_pci"); | ||
} | ||
}; |
37 changes: 37 additions & 0 deletions
37
database/migrations/2024_04_23_102939_nethsecurity_pci_view.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?php | ||
|
||
use Illuminate\Database\Migrations\Migration; | ||
use Illuminate\Support\Facades\DB; | ||
|
||
return new class extends Migration | ||
{ | ||
/** | ||
* Run the migrations. | ||
*/ | ||
public function up(): void | ||
{ | ||
DB::statement(" | ||
CREATE OR REPLACE VIEW nethsecurity_pci AS | ||
SELECT | ||
pci_obj->>'class_id' as class_id, | ||
pci_obj->>'vendor_id' as vendor_id, | ||
pci_obj->>'device_id' as device_id, | ||
pci_obj->>'class_name' as class_name, | ||
pci_obj->>'vendor_name' as vendor_name, | ||
pci_obj->>'device_name' as device_name, | ||
pci_obj->>'driver' as driver | ||
FROM installations, | ||
json_array_elements(data->'facts'->'pci') as pci_obj | ||
WHERE data->>'installation' LIKE 'nethsecurity' | ||
AND updated_at >= CURRENT_TIMESTAMP - INTERVAL '72 hours'; | ||
"); | ||
} | ||
|
||
/** | ||
* Reverse the migrations. | ||
*/ | ||
public function down(): void | ||
{ | ||
DB::statement("DROP VIEW IF EXISTS nethsecurity_pci"); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ | |
<head> | ||
<meta charset="UTF-8"> | ||
<title>Hardware</title> | ||
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script> | ||
<link rel="stylesheet" href="{{ asset('css/hardware.css') }}"> | ||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons/font/bootstrap-icons.css"> | ||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css"> | ||
|
@@ -28,14 +29,23 @@ | |
<div class="container"> | ||
<h1>Find {{$installation}} Hardware</h1> | ||
<p>Enter a search term in the input box below to find {{$installation}} hardware matching your requirements.</p> | ||
|
||
<form action="{{ route('hardware', ['installation' => $installation]) }}" method="GET"> | ||
<div class="btn-group"> | ||
<button class="btn btn-secondary dropdown-toggle" type="button" id="dropdownMenuButton" data-bs-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Search by name</button> | ||
<div class="dropdown-menu" style="width: 10px;" aria-labelledby="dropdownMenuButton"> | ||
<a class="dropdown-item search-by-name" href="{{ route('hardware', ['installation' => $installation]) }}">Search by name </a> | ||
<a class="dropdown-item" href="{{ route('hardware-pci', ['installation' => $installation]) }}">Search by PCI id</a> | ||
</div> | ||
</div> | ||
@csrf | ||
<input type="text" name="search_term" id="search_term" placeholder="Search hardware..."> | ||
<button type="submit">Search</button> | ||
|
||
</form> | ||
|
||
@if (empty($groupedInputMatch)) | ||
@if ($searchTerm === null || $searchTerm = '') | ||
<p></p> | ||
@elseif (empty($groupedInputMatch)) | ||
<p>No hardware found</p> | ||
@else | ||
<ul> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<title>Hardware PCI</title> | ||
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script> | ||
<link rel="stylesheet" href="{{ asset('css/hardware.css') }}"> | ||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons/font/bootstrap-icons.css"> | ||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css"> | ||
<link rel="icon" href="{{ asset('images/logoNethesis.png')}}"> | ||
</head> | ||
<body> | ||
<nav class="navbar navbar-expand-lg navbar-light bg-light"> | ||
<div class="container-fluid"> | ||
<a class="navbar-brand"><img src="{{ asset('images/logoNethesis.png') }}" alt="Logo Nethesis"></a> | ||
<div class="collapse navbar-collapse" id="navbarNav"> | ||
<ul class="navbar-nav"> | ||
<li class="nav-item"> | ||
<a class="nav-link active" href="{{route('map')}}">Map</a> | ||
</li> | ||
<li class="nav-item"> | ||
<a class="nav-link active" href="{{route('select-hardware')}}">Select Hardware</a> | ||
</li> | ||
</ul> | ||
</div> | ||
</div> | ||
</nav> | ||
<div class="scrollable-content"> | ||
<div class="container"> | ||
<h1>Find {{$installation}} Hardware PCI</h1> | ||
<p>Enter the Vendor ID and Device ID in the input fields below to find {{$installation}} PCI hardware matching your requirements.</p> | ||
|
||
<form action="{{ route('hardware-pci', ['installation' => $installation]) }}" method="GET"> | ||
<div class="btn-group"> | ||
<button class="btn btn-secondary dropdown-toggle" type="button" id="dropdownMenuButton" data-bs-toggle="dropdown" aria-haspopup="true" aria-expanded="false"> | ||
Search by PCI id | ||
</button> | ||
<div class="dropdown-menu" aria-labelledby="dropdownMenuButton"> | ||
<a class="dropdown-item" href="{{ route('hardware', ['installation' => $installation]) }}">Search by name</a> | ||
<a class="dropdown-item search-by-id" href="{{ route('hardware-pci', ['installation' => $installation]) }}">Search by PCI id</a> | ||
</div> | ||
</div> | ||
@csrf | ||
<input type="text" name="pci_search" id="pci_search" placeholder="Search hardware PCI (xxxx:xxxx) ..."> | ||
<button type="submit">Search</button> | ||
</form> | ||
|
||
@if($pciSearch === null || $pciSearch = '') | ||
<p></p> | ||
@elseif (isset($error)) | ||
<div class="alert alert-danger" role="alert"> | ||
{{ $error }} | ||
</div> | ||
@elseif (empty($pciHardware)) | ||
<p>No hardware found</p> | ||
@else | ||
<p>{{$count}} hardware found </p> | ||
@foreach ($pciHardware as $key => $hardware) | ||
<div class="card"> | ||
<ul class="list-group list-group-flush"> | ||
<li calss="list-group-item"> | ||
<div class="card-header"> | ||
<strong> Hardware occurences ({{ $hardwareCounts[$key] }})</strong><br> | ||
</div> | ||
<br> | ||
<li class="list-group-item"><strong><label>Class ID:</label></strong> {{ $hardware->class_id }}</li><br> | ||
<li class="list-group-item"><strong>Vendor ID:</strong> {{ $hardware->vendor_id }}</li><br> | ||
<li class="list-group-item"><strong>Device ID:</strong> {{ $hardware->device_id }}</li><br> | ||
<li class="list-group-item"><strong>Class Name:</strong> {{ $hardware->class_name }}</li><br> | ||
<li class="list-group-item"><strong>Vendor Name:</strong> {{ $hardware->vendor_name }}</li><br> | ||
<li class="list-group-item"><strong>Device Name:</strong> {{ $hardware->device_name }}</li><br> | ||
<li class="list-group-item"><strong>Driver:</strong> {{ $hardware->driver ?? 'N/A' }}</li><br> | ||
<br> | ||
</li> | ||
</ul> | ||
</div> | ||
<br> | ||
@endforeach | ||
@endif | ||
</div> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters