From aa06296963f87d20da9e85316ec3a23fd0daa318 Mon Sep 17 00:00:00 2001 From: Deon George Date: Sat, 26 Jun 2021 10:34:49 +1000 Subject: [PATCH] Fixes for nodelist importing --- app/Http/Controllers/DomainController.php | 14 ++-- app/Http/Controllers/SystemController.php | 2 +- app/Jobs/ImportNodelist.php | 81 +++++++++++++++++------ app/Models/Nodelist.php | 2 +- resources/views/domain/home.blade.php | 2 +- resources/views/domain/view.blade.php | 51 +++++++++++--- resources/views/zone/addedit.blade.php | 2 +- resources/views/zone/home.blade.php | 4 +- 8 files changed, 115 insertions(+), 43 deletions(-) diff --git a/app/Http/Controllers/DomainController.php b/app/Http/Controllers/DomainController.php index a51d46e..eeda084 100644 --- a/app/Http/Controllers/DomainController.php +++ b/app/Http/Controllers/DomainController.php @@ -9,12 +9,14 @@ use App\Models\{Address,Domain,Zone}; class DomainController extends Controller { - public const NODE_ZC = 1<<1; // Zone - public const NODE_RC = 1<<2; // Region - public const NODE_NC = 1<<3; // Host - public const NODE_HC = 1<<4; // Hub - public const NODE_PVT = 1<<5; // Pvt - public const NODE_DOWN = 1<<6; // Down + public const NODE_ACTIVE = 0; // Active + public const NODE_ZC = 1<<0; // Zone + public const NODE_RC = 1<<1; // Region + public const NODE_NC = 1<<2; // Host + public const NODE_HC = 1<<3; // Hub + public const NODE_PVT = 1<<4; // Pvt + public const NODE_HOLD = 1<<5; // Hold + public const NODE_DOWN = 1<<6; // Down // http://ftsc.org/docs/frl-1002.001 public const NUMBER_MAX = 0x7fff; diff --git a/app/Http/Controllers/SystemController.php b/app/Http/Controllers/SystemController.php index a641690..da4b812 100644 --- a/app/Http/Controllers/SystemController.php +++ b/app/Http/Controllers/SystemController.php @@ -190,7 +190,7 @@ class SystemController extends Controller $this->authorize('admin',$o); $request->validate([ - 'name' => 'required|min:3|unique:systems,name,'.($o->exists ? $o->id : 0), + 'name' => 'required|min:3', 'location' => 'required|min:3', 'sysop' => 'required|min:3', 'address' => 'nullable|regex:/^(?!:\/\/)(?=.{1,255}$)((.{1,63}\.){1,127}(?![0-9]*$)[a-z0-9-]+\.?)$/i', diff --git a/app/Jobs/ImportNodelist.php b/app/Jobs/ImportNodelist.php index 3a61015..daf1a79 100644 --- a/app/Jobs/ImportNodelist.php +++ b/app/Jobs/ImportNodelist.php @@ -58,11 +58,12 @@ class ImportNodelist implements ShouldQueue Log::debug(sprintf('%s:Processing [%d] lines.',static::LOGKEY,$lines)); $fh = fopen($file,'r'); - $c =0; + $p = $c =0; $region = NULL; $host = NULL; $hub_id = NULL; + $zo = NULL; while (! feof($fh)) { $line = stream_get_line($fh, 0, "\r\n"); @@ -89,17 +90,20 @@ class ImportNodelist implements ShouldQueue switch ($fields[0]) { case 'Zone': $zone = $fields[1]; // We ignore the Zone entries, since they are dynamically created. - $zo = Zone::firstOrCreate([ - 'zone_id'=>$zone, - 'domain_id'=>$this->do->id, - ]); + Zone::unguard(); + $zo = Zone::firstOrNew([ + 'zone_id'=>$zone, + 'domain_id'=>$this->do->id, + 'active'=>TRUE, + ]); + Zone::reguard(); $region = 0; - $host = 0; + $host = $fields[1]; $hub_id = NULL; $role = DomainController::NODE_ZC; - continue 2; + break; case 'Region': $region = $fields[1]; @@ -118,6 +122,7 @@ class ImportNodelist implements ShouldQueue continue 2; case 'Hub': + $node = $fields[1]; $role = DomainController::NODE_HC; break; @@ -128,6 +133,12 @@ class ImportNodelist implements ShouldQueue break; + case 'Hold': + $node = $fields[1]; + $role = DomainController::NODE_HOLD; + + break; + case 'Down': $node = $fields[1]; $role = DomainController::NODE_DOWN; @@ -150,7 +161,6 @@ class ImportNodelist implements ShouldQueue Address::unguard(); $ao = Address::firstOrNew([ - 'zone_id' => $zo->id, 'region_id' => $region, 'host_id' => $host, 'node_id' => $node, @@ -164,36 +174,52 @@ class ImportNodelist implements ShouldQueue $role = NULL; + if ($ao->exists) + Log::debug(sprintf('%s:Processing existing address [%s]',self::LOGKEY,$ao->ftn)); + + $sysop = trim(str_replace('_',' ',$fields[4])); + $system = trim(str_replace('_',' ',$fields[2])); + $location = trim(str_replace('_',' ',$fields[3])); + // Get the System - if ($ao->system_id && (($ao->system->sysop === str_replace('_',' ',$fields[4])) || ($ao->system->name !== str_replace('_',' ',$fields[2])))) { + if ($ao->system_id && (($ao->system->sysop === $sysop) || ($ao->system->name === $system))) { $so = $ao->system; // If the sysop name is different - if ($so->sysop !== str_replace('_',' ',$fields[4])) { - $so->sysop = str_replace('_',' ',$fields[4]); - $so->location = str_replace('_',' ',$fields[3]); + if ($so->sysop !== $sysop) { + Log::debug(sprintf('%s:Sysop Name changed for BBS [%s:%s] from [%s] to [%s]', + self::LOGKEY,$so->id,$so->name,$so->sysop,$sysop)); + + $so->sysop = $sysop; // We have the same name has changed. - } else { - $so->name = str_replace('_',' ',$fields[2]); - $so->location = str_replace('_',' ',$fields[3]); + } elseif ($so->name !== $system) { + Log::debug(sprintf('%s:System Name changed for BBS [%s:%s] to [%s]', + self::LOGKEY,$so->id,$so->name,$system)); + + $so->name = $system; } // We'll search and see if we already have that system } else { - $so = System::where('name',str_replace('_',' ',$fields[2])) - ->where('sysop',str_replace('_',' ',$fields[4])) + $so = System::where('name',$system) + ->where('sysop',$sysop) ->firstOrNew(); - $so->name = str_replace('_',' ',$fields[2]); - $so->sysop = str_replace('_',' ',$fields[4]); - $so->location = str_replace('_',' ',$fields[3]); + if ($so->exists) + Log::debug(sprintf('%s:Linking address [%d:%d/%d] to [%s:%s]',self::LOGKEY,$zo->zone_id,$ao->host_id,$ao->node_id,$so->id,$so->name)); + else + Log::debug(sprintf('%s:New System [%s] with address [%d:%d/%d]',self::LOGKEY,$system,$zo->zone_id,$ao->host_id,$ao->node_id)); + + $so->name = $system; + $so->sysop = $sysop; $so->active = TRUE; if (! $so->exists) $so->notes = sprintf('Created by Nodelist Import: %d',$this->no->id); } + $so->location = $location; /* if (! in_array($fields[5],['-Unpublished-'])) $so->phone = $fields[5]; @@ -204,6 +230,19 @@ class ImportNodelist implements ShouldQueue // Save the system record $so->save(); + // If our zone didnt exist, we'll create it with this system + if (! $zo->exists) { + $zo->system_id = $so->id; + $zo->save(); + } + + $ao->zone_id = $zo->id; + + if ($ao->getDirty()) { + dd($ao); + $p++; + } + try { $so->addresses()->save($ao); if ($role == DomainController::NODE_HC) @@ -226,6 +265,6 @@ class ImportNodelist implements ShouldQueue if ($this->deletefile and $c) unlink($file); - Log::info(sprintf('%s:Records Updated: %d',self::LOGKEY,$c)); + Log::info(sprintf('%s:Updated %d records from %d systems',self::LOGKEY,$p,$c)); } } diff --git a/app/Models/Nodelist.php b/app/Models/Nodelist.php index f4a98d9..063f01a 100644 --- a/app/Models/Nodelist.php +++ b/app/Models/Nodelist.php @@ -9,7 +9,7 @@ class Nodelist extends Model protected $dates = ['date']; protected $fillable = ['date','domain_id']; - public const definitions = ['Zone','Region','Host','Hub','Pvt','Down']; + public const definitions = ['Zone','Region','Host','Hub','Pvt','Hold','Down']; /* RELATIONS */ diff --git a/resources/views/domain/home.blade.php b/resources/views/domain/home.blade.php index 9b3d641..a43a49f 100644 --- a/resources/views/domain/home.blade.php +++ b/resources/views/domain/home.blade.php @@ -47,7 +47,7 @@ {{ $oo->name }} {{ $oo->active ? 'YES' : 'NO' }} {{ $oo->dnsdomain }} - {{ join(', ',$oo->zones->pluck('zone_id')->toArray()) }} + {{ join(', ',$oo->zones->pluck('zone_id')->sort()->toArray()) }} @endforeach diff --git a/resources/views/domain/view.blade.php b/resources/views/domain/view.blade.php index f57602b..f81502b 100644 --- a/resources/views/domain/view.blade.php +++ b/resources/views/domain/view.blade.php @@ -55,13 +55,12 @@

The following systems are members of this network.

- +
- @@ -74,7 +73,6 @@ - @@ -82,20 +80,18 @@ @foreach ($oz->addresses()->active()->FTNorder()->whereNull('hub_id')->with(['system','zone.domain'])->get() as $ao) @if ($ao->role == 'Host') - + - @endif - + - @@ -104,9 +100,9 @@ @if ($ao->role == 'Hub') @foreach ($oz->addresses()->active()->FTNorder()->where('hub_id',$ao->id)->with(['system','zone.domain'])->get() as $aoo) - + - + @@ -139,4 +135,39 @@ -@endsection \ No newline at end of file +@endsection + +@section('page-scripts') + + + + + + + + +@append \ No newline at end of file diff --git a/resources/views/zone/addedit.blade.php b/resources/views/zone/addedit.blade.php index dbdb132..b2291a4 100644 --- a/resources/views/zone/addedit.blade.php +++ b/resources/views/zone/addedit.blade.php @@ -56,7 +56,7 @@ diff --git a/resources/views/zone/home.blade.php b/resources/views/zone/home.blade.php index deba573..4c034bc 100644 --- a/resources/views/zone/home.blade.php +++ b/resources/views/zone/home.blade.php @@ -38,12 +38,12 @@ - @foreach (\App\Models\Zone::with(['domain'])->get() as $oo) + @foreach (\App\Models\Zone::orderBy('zone_id')->with(['domain','addresses'])->get() as $oo) - + @endforeach
System Sysop LocationRole Address Last Seen
{{ sprintf('ZC-%s-%05d',$oz->domain->name,$oz->zone_id) }} {{ $oz->system->sysop }} {{ $oz->system->location }}Zone {{ $oz->zone_id }}:0/0.0@{{ $oz->domain->name }} -
{{ sprintf('NC-%s-%05d',$oz->domain->name,$ao->host_id) }}{{ sprintf('NC-%s-%05d',$oz->domain->name,$ao->host_id) }} [{{ $ao->id }}] {{ $ao->system->sysop }} {{ $ao->system->location }}{{ $ao->role }} {{ $oz->zone_id }}:{{ $ao->host_id }}/0.0@{{ $oz->domain->name }} -
{{ $ao->system->full_name($ao) }}{{ $ao->system->full_name($ao) }} [{{ $ao->id }}] {{ $ao->system->sysop }} {{ $ao->system->location }}{{ $ao->role }} {{ $ao->ftn }} -
{{ $aoo->system->full_name($aoo) }}{{ $aoo->system->full_name($aoo) }} [{{ $aoo->id }}] {{ $aoo->system->sysop }}{{ $ao->system->location }}{{ $aoo->system->location }} {{ $aoo->role }} {{ $aoo->ftn }} -
{{ $oo->domain->name }} {{ $oo->zone_id }} {{ $oo->active ? 'YES' : 'NO' }}-{{ $oo->addresses->count() }}