Skip to content

Commit

Permalink
review network/subnetork/vlan
Browse files Browse the repository at this point in the history
  • Loading branch information
dbarzin committed Aug 18, 2021
1 parent 17e7654 commit a6fa3bd
Show file tree
Hide file tree
Showing 22 changed files with 357 additions and 316 deletions.
31 changes: 30 additions & 1 deletion app/Http/Controllers/Admin/CartographyController.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
use App\PhysicalRouter;
use App\WifiTerminal;
use App\PhysicalSecurityDevice;
use App\Vlan;

use App\Http\Controllers\Controller;

Expand Down Expand Up @@ -1270,7 +1271,12 @@ public function cartography(Request $request) {
$section->addBookmark("SUBNET".$subnetwork->id);
$table=$this->addTable($section, $subnetwork->name);
$this->addHTMLRow($table,"Description",$subnetwork->description);
$this->addTextRow($table,"Adresse/Masque",$subnetwork->address . "( " . $subnetwork->ipRange() . " )");
$this->addTextRow($table,"Adresse/Masque",$subnetwork->address . " ( " . $subnetwork->ipRange() . " )");
// VLAN
$textRun=$this->addTextRunRow($table,"Vlan");
if ($subnetwork->gateway!=null)
$textRun->addLink("VLAN".$subnetwork->vlan->id, $subnetwork->vlan->name, CartographyController::FancyLinkStyle, null, true);
$this->addTextRow($table,"Zone",$subnetwork->zone);
$this->addTextRow($table,"Méthode d’attribution des IP",$subnetwork->ip_allocation_type);
$this->addTextRow($table,"DMZ ou non",$subnetwork->dmz);
$this->addTextRow($table,"Possibilité d’accès sans fil",$subnetwork->wifi);
Expand Down Expand Up @@ -1429,6 +1435,7 @@ public function cartography(Request $request) {
$physicalRouters = PhysicalRouter::orderBy("name")->get();
$wifiTerminals = WifiTerminal::orderBy("name")->get();
$physicalSecurityDevices = PhysicalSecurityDevice::orderBy("name")->get();
$vlans = Vlan::orderBy("name")->get();

// Generate Graph
$graph = "digraph {";
Expand Down Expand Up @@ -1922,6 +1929,28 @@ public function cartography(Request $request) {
}
}

// =====================================
if ($vlans->count()>0) {
$section->addTitle('VLANs', 2);
$section->addText("Réseau local (LAN) virtuel permettant de regrouper logiquement des équipements en s’affranchissant des contraintes physiques.");
$section->addTextBreak(1);

foreach($vlans as $vlan) {
$section->addBookmark("VLAN".$vlan->id);
$table=$this->addTable($section, $vlan->name);
$this->addHTMLRow($table,"Description",$vlan->description);

// Sous-réseaux
$textRun=$this->addTextRunRow($table,"Sous-réseaux ratachés");
foreach($vlan->subnetworks as $subnetwork) {
$textRun->addLink("SUBNET".$subnetwork->id, $subnetwork->name, CartographyController::FancyLinkStyle, null, true);
if ($vlan->subnetworks->last()!=$subnetwork)
$textRun->addText(", ");
}

$section->addTextBreak(1);
}
}

}

Expand Down
6 changes: 4 additions & 2 deletions app/Http/Controllers/Admin/NetworkController.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public function create()
public function store(StoreNetworkRequest $request)
{
$network = Network::create($request->all());
$network->subnetworks()->sync($request->input('subnetworks', []));
// $network->subnetworks()->sync($request->input('subnetworks', []));

return redirect()->route('admin.networks.index');
}
Expand All @@ -56,7 +56,9 @@ public function edit(Network $network)
public function update(UpdateNetworkRequest $request, Network $network)
{
$network->update($request->all());
$network->subnetworks()->sync($request->input('subnetworks', []));

// Subnetwork::where('network_id', $network->id)->update(['network_id' => null]);
// Subnetwork::whereIn('id', $request->input('subnetworks', []))->update(['network_id' => $network->id]);

return redirect()->route('admin.networks.index');
}
Expand Down
6 changes: 6 additions & 0 deletions app/Http/Controllers/Admin/ReportController.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
use App\PhysicalRouter;
use App\WifiTerminal;
use App\PhysicalSecurityDevice;
use App\Vlan;


use App\Http\Controllers\Controller;
Expand Down Expand Up @@ -480,6 +481,7 @@ public function logicalInfrastructure(Request $request) {
$dnsservers = Dnsserver::All()->sortBy("name");
$logicalServers = LogicalServer::All()->sortBy("name");
$certificates = Certificate::All()->sortBy("name");
$vlans = Vlan::All()->sortBy("name");

return view('admin/reports/logical_infrastructure')
->with("networks",$networks)
Expand Down Expand Up @@ -688,6 +690,8 @@ public function physicalInfrastructure(Request $request) {
return false;
});

// filtering ???
$vlans = Vlan::All()->sortBy("name");
}
else
{
Expand All @@ -704,6 +708,7 @@ public function physicalInfrastructure(Request $request) {
$physicalRouters = PhysicalRouter::All()->sortBy("name");
$wifiTerminals = WifiTerminal::All()->sortBy("name");
$physicalSecurityDevices = PhysicalSecurityDevice::All()->sortBy("name");
$vlans = Vlan::All()->sortBy("name");
}

return view('admin/reports/physical_infrastructure')
Expand All @@ -721,6 +726,7 @@ public function physicalInfrastructure(Request $request) {
->with("physicalRouters", $physicalRouters)
->with("wifiTerminals", $wifiTerminals)
->with("physicalSecurityDevices", $physicalSecurityDevices)
->with("vlans", $vlans)
;

}
Expand Down
22 changes: 15 additions & 7 deletions app/Http/Controllers/Admin/SubnetworkController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
namespace App\Http\Controllers\Admin;

use Gate;
use App\Network;
use App\Subnetwork;
use App\Gateway;
use App\Vlan;

use App\Http\Controllers\Controller;
use App\Http\Requests\MassDestroySubnetworkRequest;
Expand All @@ -30,18 +32,21 @@ public function create()
{
abort_if(Gate::denies('subnetwork_create'), Response::HTTP_FORBIDDEN, '403 Forbidden');

$connected_subnets = Subnetwork::all()->sortBy('name')->pluck('name', 'id')->prepend(trans('global.pleaseSelect'), '');
// $connected_subnets = Subnetwork::all()->sortBy('name')->pluck('name', 'id')->prepend(trans('global.pleaseSelect'), '');
$gateways = Gateway::all()->sortBy('name')->pluck('name', 'id')->prepend(trans('global.pleaseSelect'), '');
$vlans = Vlan::all()->sortBy('name')->pluck('name', 'id')->prepend(trans('global.pleaseSelect'), '');
$networks = Network::all()->sortBy('name')->pluck('name', 'id')->prepend(trans('global.pleaseSelect'), '');

// lists
$ip_allocation_type_list = Subnetwork::select('ip_allocation_type')->where("ip_allocation_type","<>",null)->distinct()->orderBy('ip_allocation_type')->pluck('ip_allocation_type');
$responsible_exp_list = Subnetwork::select('responsible_exp')->where("responsible_exp","<>",null)->distinct()->orderBy('responsible_exp')->pluck('responsible_exp');
$dmz_list = Subnetwork::select('dmz')->where("dmz","<>",null)->distinct()->orderBy('dmz')->pluck('dmz');
$wifi_list = Subnetwork::select('wifi')->where("wifi","<>",null)->distinct()->orderBy('wifi')->pluck('wifi');
$zone_list = Subnetwork::select('zone')->where("zone","<>",null)->distinct()->orderBy('zone')->pluck('zone');

return view('admin.subnetworks.create',
compact('connected_subnets', 'gateways',
'ip_allocation_type_list', 'responsible_exp_list','dmz_list','wifi_list'));
compact('gateways', 'vlans', 'networks',
'ip_allocation_type_list', 'responsible_exp_list','dmz_list','wifi_list','zone_list'));
}

public function store(StoreSubnetworkRequest $request)
Expand All @@ -55,20 +60,23 @@ public function edit(Subnetwork $subnetwork)
{
abort_if(Gate::denies('subnetwork_edit'), Response::HTTP_FORBIDDEN, '403 Forbidden');

$connected_subnets = Subnetwork::all()->sortBy('name')->pluck('name', 'id')->prepend(trans('global.pleaseSelect'), '');
// $connected_subnets = Subnetwork::all()->sortBy('name')->pluck('name', 'id')->prepend(trans('global.pleaseSelect'), '');
$gateways = Gateway::all()->sortBy('name')->pluck('name', 'id')->prepend(trans('global.pleaseSelect'), '');
$vlans = Vlan::all()->sortBy('name')->pluck('name', 'id')->prepend(trans('global.pleaseSelect'), '');
$networks = Network::all()->sortBy('name')->pluck('name', 'id')->prepend(trans('global.pleaseSelect'), '');

// lists
$ip_allocation_type_list = Subnetwork::select('ip_allocation_type')->where("ip_allocation_type","<>",null)->distinct()->orderBy('ip_allocation_type')->pluck('ip_allocation_type');
$responsible_exp_list = Subnetwork::select('responsible_exp')->where("responsible_exp","<>",null)->distinct()->orderBy('responsible_exp')->pluck('responsible_exp');
$dmz_list = Subnetwork::select('dmz')->where("dmz","<>",null)->distinct()->orderBy('dmz')->pluck('dmz');
$wifi_list = Subnetwork::select('wifi')->where("wifi","<>",null)->distinct()->orderBy('wifi')->pluck('wifi');
$zone_list = Subnetwork::select('zone')->where("zone","<>",null)->distinct()->orderBy('zone')->pluck('zone');

$subnetwork->load('connected_subnets', 'gateway');

return view('admin.subnetworks.edit',
compact('connected_subnets', 'gateways', 'subnetwork',
'ip_allocation_type_list', 'responsible_exp_list','dmz_list','wifi_list'));
compact('subnetwork', 'gateways', 'vlans', 'networks',
'ip_allocation_type_list', 'responsible_exp_list','dmz_list','wifi_list', 'zone_list'));
}

public function update(UpdateSubnetworkRequest $request, Subnetwork $subnetwork)
Expand All @@ -82,7 +90,7 @@ public function show(Subnetwork $subnetwork)
{
abort_if(Gate::denies('subnetwork_show'), Response::HTTP_FORBIDDEN, '403 Forbidden');

$subnetwork->load('connected_subnets', 'gateway', 'connectedSubnetsSubnetworks', 'subnetworksNetworks');
$subnetwork->load('connected_subnets', 'gateway');

return view('admin.subnetworks.show', compact('subnetwork'));
}
Expand Down
4 changes: 3 additions & 1 deletion app/Network.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ public function connectedNetworksExternalConnectedEntities()

public function subnetworks()
{
return $this->belongsToMany(Subnetwork::class)->orderBy("name");;
// return $this->belongsToMany(Subnetwork::class)->orderBy("name");
return $this->hasMany(Subnetwork::class, 'network_id', 'id')->orderBy("name");
}

}
17 changes: 12 additions & 5 deletions app/Subnetwork.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,13 @@ class Subnetwork extends Model
'description',
'address',
'ip_allocation_type',
'responsible_exp',
'vlan_id',
'zone',
'dmz',
'wifi',
'connected_subnets_id',
'wifi',
'responsible_exp',
'gateway_id',
'network_id',
'created_at',
'updated_at',
'deleted_at',
Expand All @@ -95,9 +97,9 @@ public function connectedSubnetsSubnetworks()
return $this->hasMany(Subnetwork::class, 'connected_subnets_id', 'id')->orderBy("name");
}

public function subnetworksNetworks()
public function network()
{
return $this->belongsToMany(Network::class)->orderBy("name");
return $this->belongsTo(Network::class, 'network_id');
}

public function connected_subnets()
Expand All @@ -110,6 +112,11 @@ public function gateway()
return $this->belongsTo(Gateway::class, 'gateway_id');
}

public function vlan()
{
return $this->belongsTo(Vlan::class, 'vlan_id');
}

public function ipRange() {
if ($this->address==null)
return null;
Expand Down
10 changes: 6 additions & 4 deletions app/Vlan.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,6 @@ class Vlan extends Model
protected $fillable = [
'name',
'description',
'address',
'mask',
'gateway',
'zone',
'created_at',
'updated_at',
'deleted_at',
Expand All @@ -78,4 +74,10 @@ public function vlanPhysicalRouters()
{
return $this->belongsToMany(PhysicalRouter::class)->orderBy("name");
}

public function subnetworks()
{
return $this->hasMany(Subnetwork::class, 'vlan_id', 'id')->orderBy("name");
}

}
64 changes: 64 additions & 0 deletions database/migrations/2021_08_18_171048_network_redesign.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class NetworkRedesign extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('subnetworks', function(Blueprint $table) {
// add column zone in subnetworks
$table->string('zone')->nullable();
// add link to vlan in subnetwork
$table->unsignedInteger('vlan_id')->nullable()->index('vlan_fk_6844934');
$table->foreign('vlan_id', 'vlan_fk_6844934')->references('id')->on('vlans')->onUpdate('NO ACTION')->onDelete('NO ACTION');
// add link to network in subnetwork
$table->unsignedInteger('network_id')->nullable()->index('network_fk_5476544');
$table->foreign('network_id', 'network_fk_5476544')->references('id')->on('vlans')->onUpdate('NO ACTION')->onDelete('NO ACTION');
});

/* to process later...
// remove link to physical_switch_id in wifi_terminals
Schema::table('wifi_terminals', function(Blueprint $table) {
$table->dropColumn('physical_switch_id');
}
// cleanup VLAN table
Schema::table('vlans', function(Blueprint $table) {
$table->dropColumn('address');
$table->dropColumn('mask');
$table->dropColumn('gateway');
$table->dropColumn('zone');
}
// remove table between networks and subnetworks
Schema::dropTable('network_subnetword');
*/
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('subnetworks', function(Blueprint $table) {
// remove column zone in subnetworks
$table->dropColumn('zone');
// remove link to vlan in subnetwork
$table->dropForeign('vlan_fk_6844934');
$table->dropColumn('vlan_id');
// remove link to vlan in network
$table->dropForeign('network_fk_5476544');
$table->dropColumn('network_id');
});
}
}
Loading

0 comments on commit a6fa3bd

Please sign in to comment.