From 23159d19d57298fff4cd1ce7e2d22963981e2008 Mon Sep 17 00:00:00 2001 From: Deon George Date: Thu, 9 May 2024 21:22:30 +1000 Subject: [PATCH] Rework address roles, making Address::role optional, rework determining uplink/downlinks/parent/children --- app/Classes/FTN/Packet.php | 8 +- app/Console/Commands/Debug/AddressCheck.php | 7 +- .../Commands/Debug/AddressCheckRole.php | 48 ++ app/Console/Commands/Debug/ZoneCheck.php | 70 +- app/Console/Commands/UserCodeSend.php | 2 +- app/Http/Controllers/DomainController.php | 2 +- app/Http/Controllers/SystemController.php | 21 +- app/Jobs/MailSend.php | 2 +- app/Jobs/NodelistImport.php | 10 +- app/Jobs/SystemHeartbeat.php | 4 +- app/Models/Address.php | 619 ++++++++++++------ app/Models/Echoarea.php | 3 +- app/Models/System.php | 13 +- app/Models/User.php | 7 +- app/helpers.php | 2 +- ...07_211343_address_remove_role_not_null.php | 24 + database/seeders/TestNodeHierarchy.php | 8 +- .../views/layouts/partials/sidebar.blade.php | 4 +- resources/views/status.blade.php | 2 +- resources/views/system/addedit.blade.php | 73 +-- .../views/system/widget/routing.blade.php | 68 ++ .../views/system/widget/system.blade.php | 9 +- tests/Feature/RoutingTest.php | 82 +-- 23 files changed, 667 insertions(+), 421 deletions(-) create mode 100644 app/Console/Commands/Debug/AddressCheckRole.php create mode 100644 database/migrations/2024_05_07_211343_address_remove_role_not_null.php create mode 100644 resources/views/system/widget/routing.blade.php diff --git a/app/Classes/FTN/Packet.php b/app/Classes/FTN/Packet.php index ffda3d5..a5a6531 100644 --- a/app/Classes/FTN/Packet.php +++ b/app/Classes/FTN/Packet.php @@ -420,7 +420,7 @@ class Packet extends FTNBase implements \Iterator, \Countable 'host_id' => $msg->tn, 'node_id' => $msg->tf, 'point_id' => $msg->tp, - 'active' => TRUE, + 'active' => TRUE, // @todo This should be false, as it hasnt been assigned to the node ]); Address::reguard(); @@ -433,8 +433,6 @@ class Packet extends FTNBase implements \Iterator, \Countable return; } - $ao->role = Address::NODE_UNKNOWN; - $so = System::createUnknownSystem(); $so->addresses()->save($ao); @@ -453,7 +451,7 @@ class Packet extends FTNBase implements \Iterator, \Countable 'host_id' => $msg->fn, 'node_id' => $msg->ff, 'point_id' => $msg->fp, - 'active'=> TRUE, + 'active'=> TRUE, // @todo This should be FALSE as it hasnt been assigned to the node ]); Address::reguard(); @@ -466,8 +464,6 @@ class Packet extends FTNBase implements \Iterator, \Countable return; } - $ao->role = Address::NODE_UNKNOWN; - $so = System::createUnknownSystem(); $so->addresses()->save($ao); diff --git a/app/Console/Commands/Debug/AddressCheck.php b/app/Console/Commands/Debug/AddressCheck.php index 3ea2269..1893efc 100644 --- a/app/Console/Commands/Debug/AddressCheck.php +++ b/app/Console/Commands/Debug/AddressCheck.php @@ -22,10 +22,11 @@ class AddressCheck extends Command return Command::FAILURE; } - $this->info(sprintf('Address: %s',$o->ftn)); - $this->info(sprintf('Uplink: %s',$o->parent()?->ftn)); + $this->info(sprintf('Address: %s (%s)',$o->ftn,$o->role_name)); + $this->info(sprintf("Children: \n- %s",$o->children()->pluck('ftn4d')->join("\n- "))); + $this->info(sprintf('Uplink: %s (Parent: %s)',$o->uplink()?->ftn,$o->parent()?->ftn)); $this->info(sprintf('Our Address: %s',our_address($o)?->ftn)); - $this->info(sprintf('Domain Addresses: %s',our_address($o->zone->domain)->pluck('ftn4d')->join(','))); + $this->info(sprintf('- Domain Addresses: %s',our_address($o->zone->domain)->pluck('ftn4d')->join(','))); return Command::SUCCESS; } diff --git a/app/Console/Commands/Debug/AddressCheckRole.php b/app/Console/Commands/Debug/AddressCheckRole.php new file mode 100644 index 0000000..ad2533a --- /dev/null +++ b/app/Console/Commands/Debug/AddressCheckRole.php @@ -0,0 +1,48 @@ +with(['zone.domain'])->cursor() as $o) { + // Trim the role bit from role, since we now work out a role automatically. + // @todo This doesnt work, because role_id returns back the overridden role, and thus would remove it + if (($o->role & Address::NODE_ALL) === $o->role_id) { + $o->role &= ~$o->role_id; + + if ((! $o->role) || ($o->role === Address::NODE_UNKNOWN)) + $o->role = NULL; + + if ($o->getDirty()) + if ($this->option('fix')) { + $o->save(); + + } else { + $this->warn(sprintf('Not changing [%s](%s) from [%d] to [%d]',$o->ftn,$o->role_name,$o->getOriginal('role'),$o->role)); + } + } + } + } +} \ No newline at end of file diff --git a/app/Console/Commands/Debug/ZoneCheck.php b/app/Console/Commands/Debug/ZoneCheck.php index 43687b1..0d6e5aa 100644 --- a/app/Console/Commands/Debug/ZoneCheck.php +++ b/app/Console/Commands/Debug/ZoneCheck.php @@ -4,7 +4,7 @@ namespace App\Console\Commands\Debug; use Illuminate\Console\Command; -use App\Models\{Address,Domain}; +use App\Models\Domain; class ZoneCheck extends Command { @@ -25,77 +25,23 @@ class ZoneCheck extends Command $this->warn('Zone: '.$zo->zone_id); $this->info(sprintf('- Our address(es): %s',our_address($do)->pluck('ftn4d')->join(','))); - $this->table(['id','ftn','role','parent','our_address','region_id','host_id','hub_id','system','notes'],$zo->addresses()->FTNorder()->active()->with(['system'])->get()->transform(function($item) { + $this->table(['id','ftn','role','parent','children','downlinks','uplink','send from','region_id','system','notes'],$zo->addresses()->FTNorder()->active()->with(['system'])->get()->transform(function($item) { return [ 'id'=>$item->id, 'ftn'=>$item->ftn4d, 'role'=>$item->role_name, - 'parent'=>($x=$item->parent())?->ftn4d, - 'our_address'=>$x ? our_address($item->parent())->ftn4d : '', + 'parent'=>$item->parent()?->ftn4d, + 'children'=>$item->children()->count(), + 'downlinks'=>$item->downlinks()->count(), + 'uplink'=>($x=$item->uplink())?->ftn4d, + 'send from'=>$x ? our_address($item->uplink())?->ftn4d : '', 'region_id'=>$item->region_id, - 'host_id'=>$item->host_id, - 'hub_id'=>$item->hub_id, 'system'=>$item->system->name, - 'notes'=>$this->check($item), + 'notes'=>$item->isRoleOverride() ? 'Role Override' : '', ]; })); } return Command::SUCCESS; } - - /** - * Check that an address is defined correctly - * - * @param Address $ao - * @return string - */ - private function check(Address $ao): string - { - // ZC address - if ($ao->role === Address::NODE_ZC) { - if (($ao->region_id === 0) && ($ao->host_id === 0) && ($ao->node_id === 0) && is_null($ao->hub_id) && ($ao->point_id === 0)) - return 'OK'; - - else - return 'INVALID ZC address'; - } - - // RC address - if ($ao->role === Address::NODE_RC) { - if ($ao->region_id && ($ao->region_id === $ao->host_id) && ($ao->node_id === 0) && is_null($ao->hub_id) && ($ao->point_id === 0)) - return 'OK'; - else - return 'INVALID RC address'; - } - - // NC address - if ($ao->role === Address::NODE_NC) { - if (($ao->node_id === 0) && is_null($ao->hub_id) && ($ao->point_id === 0)) - return 'OK'; - else - return 'INVALID NC address'; - } - - // HUB address - if ($ao->role === Address::NODE_HC) { - if (($ao->node_id !== 0) && is_null($ao->hub_id) && ($ao->point_id === 0)) - return 'OK'; - else - return 'INVALID HUB address'; - } - - // POINT address - if ($ao->role === Address::NODE_POINT) { - if ($ao->point_id !== 0) - return 'OK'; - else - return 'INVALID POINT address'; - } - - if ($ao->region_id && ($ao->host_id === 0)) - return 'INVALID REGION NODE'; - - return ''; - } } \ No newline at end of file diff --git a/app/Console/Commands/UserCodeSend.php b/app/Console/Commands/UserCodeSend.php index 5988e76..00fb83f 100644 --- a/app/Console/Commands/UserCodeSend.php +++ b/app/Console/Commands/UserCodeSend.php @@ -27,6 +27,6 @@ class UserCodeSend extends Command $ao = Address::findFTN($this->argument('ftn')); $uo = User::where('email',$this->argument('email'))->singleOrFail(); - Notification::route('netmail',$ao->parent())->notify(new AddressLink($uo)); + Notification::route('netmail',$ao->uplink())->notify(new AddressLink($uo)); } } \ No newline at end of file diff --git a/app/Http/Controllers/DomainController.php b/app/Http/Controllers/DomainController.php index dbefebd..697df8d 100644 --- a/app/Http/Controllers/DomainController.php +++ b/app/Http/Controllers/DomainController.php @@ -118,7 +118,7 @@ class DomainController extends Controller if (! $o->public && ! Gate::check('admin',$o)) abort(404); - $o->load(['zones.system','zones.domain']); + $o->load(['zones.system','zones.domain','zones.addresses.nodes_hub']); return view('domain.view') ->with('o',$o); diff --git a/app/Http/Controllers/SystemController.php b/app/Http/Controllers/SystemController.php index f7ed779..f2c0fab 100644 --- a/app/Http/Controllers/SystemController.php +++ b/app/Http/Controllers/SystemController.php @@ -76,7 +76,6 @@ class SystemController extends Controller */ public function address_add(Request $request,System $o) { - // @todo a point address is failing validation // @todo This should be admin of the zone $this->authorize('admin',$o); session()->flash('accordion','address'); @@ -124,7 +123,6 @@ class SystemController extends Controller $oo->host_id = $request->region_id_new; $oo->node_id = 0; $oo->point_id = 0; - $oo->role = Address::NODE_RC; $oo->active = TRUE; $o->addresses()->save($oo); @@ -152,6 +150,7 @@ class SystemController extends Controller }); }) ->where('zone_id',$request->zone_id) + ->where('node_id',$request->node_id_new) ->where('point_id',0); if ($o->count()) { @@ -212,7 +211,6 @@ class SystemController extends Controller $oo->host_id = $request->host_id_new; $oo->node_id = $request->node_id_new; $oo->point_id = 0; - $oo->role = Address::NODE_ACTIVE; $oo->active = TRUE; $o->addresses()->save($oo); @@ -276,9 +274,8 @@ class SystemController extends Controller $oo->host_id = $request->host_id; $oo->node_id = $request->node_id; $oo->point_id = $request->point_id; + // @todo Validation should check that the hub is in the right region and net $oo->hub_id = $request->hub_id > 0 ? $request->hub_id : NULL; - if (is_null($oo->role)) - $oo->role = ((! $oo->point_id) && $request->hub) ? Address::NODE_HC : ($request->point_id ? Address::NODE_POINT : Address::NODE_ACTIVE); $oo->security = $request->security; $oo->active = TRUE; @@ -327,10 +324,13 @@ class SystemController extends Controller session()->flash('accordion','address'); // Make sure that no other system has this address active. - if ($o->role === Address::NODE_ACTIVE) + if ($o->role_id === Address::NODE_NN) return redirect()->back()->withErrors(['address'=>sprintf('%s cannot be demoted any more',$o->ftn3D)]); - $o->role = ($o->role << 1); + $off = $o->role_id; + $o->role &= ~$off; + $o->role |= ($off << 1); + $o->save(); return redirect()->to(sprintf('system/addedit/%d',$o->system_id)); @@ -502,10 +502,13 @@ class SystemController extends Controller session()->flash('accordion','address'); // Make sure that no other system has this address active. - if ($o->role === Address::NODE_NC) + if ($o->role_id === Address::NODE_NC) return redirect()->back()->withErrors(['address'=>sprintf('%s cannot be promoted any more',$o->ftn3D)]); - $o->role = ($o->role >> 1); + $off = $o->role_id; + $o->role &= ~$off; + $o->role |= ($off >> 1); + $o->save(); return redirect()->to(sprintf('system/addedit/%d',$o->system_id)); diff --git a/app/Jobs/MailSend.php b/app/Jobs/MailSend.php index e8d2c6c..257d382 100644 --- a/app/Jobs/MailSend.php +++ b/app/Jobs/MailSend.php @@ -69,7 +69,7 @@ class MailSend #implements ShouldQueue // Return the system we poll $u = $u->transform(function($item) { - if ($x=$item->parent()) { + if ($x=$item->uplink()) { $x->uncollected_echomail = $item->uncollected_echomail; $x->uncollected_netmail = $item->uncollected_netmail; $x->uncollected_files = $item->uncollected_files; diff --git a/app/Jobs/NodelistImport.php b/app/Jobs/NodelistImport.php index e2bd058..0831bec 100644 --- a/app/Jobs/NodelistImport.php +++ b/app/Jobs/NodelistImport.php @@ -178,6 +178,7 @@ class NodelistImport implements ShouldQueue } $node = 0; + $role = NULL; switch ($fields[0]) { case 'Zone': @@ -193,7 +194,6 @@ class NodelistImport implements ShouldQueue $region = 0; $host = 0; $hub_id = NULL; - $role = Address::NODE_ZC; break; @@ -201,14 +201,12 @@ class NodelistImport implements ShouldQueue $region = (int)$fields[1]; $host = (int)$fields[1]; $hub_id = NULL; - $role = Address::NODE_RC; break; case 'Host': $host = (int)$fields[1]; $hub_id = NULL; - $role = Address::NODE_NC; break; @@ -238,7 +236,6 @@ class NodelistImport implements ShouldQueue case '': $node = $fields[1]; - $role = Address::NODE_ACTIVE; break; default: @@ -431,7 +428,7 @@ class NodelistImport implements ShouldQueue $so->sysop = $sysop; // We have the same name has changed (except for ZC/RC addresses) - } elseif (($so->name !== $system) && (! ((Address::NODE_ZC|Address::NODE_RC|Address::NODE_NC) & $ao->role))) { + } elseif (($so->name !== $system) && (! ((Address::NODE_ZC|Address::NODE_RC|Address::NODE_NC) & $ao->role_id))) { Log::alert(sprintf('%s:! System Name changed for BBS [%s:%s] to [%s]', self::LOGKEY,$so->id,$so->name,$system)); @@ -499,6 +496,7 @@ class NodelistImport implements ShouldQueue throw new \Exception($e->getMessage()); } + // @todo This should be a bit test ($ao->rule & Address::NODE_PVT)? if ($methods->count() && ($ao->role != Address::NODE_PVT)) { $methods->transform(function($item) { $item['active'] = Arr::get($item,'active',TRUE); return $item; }); $so->mailers()->sync($methods); @@ -519,7 +517,7 @@ class NodelistImport implements ShouldQueue try { $so->addresses()->save($ao); - if ($ao->role === Address::NODE_HC) + if ($ao->role_id === Address::NODE_HC) $hub_id = $ao->id; $no->addresses()->attach($ao,['role'=>$ao->role]); diff --git a/app/Jobs/SystemHeartbeat.php b/app/Jobs/SystemHeartbeat.php index a970d65..fe1f422 100644 --- a/app/Jobs/SystemHeartbeat.php +++ b/app/Jobs/SystemHeartbeat.php @@ -44,7 +44,7 @@ class SystemHeartbeat #implements ShouldQueue ->whereNotNull('pollmode') ->where(function($query) { return $query - ->where('role','<',Address::NODE_ACTIVE) + ->where('role','<',Address::NODE_NN) ->orWhereNotNull('heartbeat'); }) ->when(! $this->force,function($query) { @@ -62,7 +62,7 @@ class SystemHeartbeat #implements ShouldQueue if (Job::where('queue','poll')->get()->pluck('command.address.id')->search($oo->id) === FALSE) { if ((! $oo->system->last_session) || ($oo->system->hearbeat && ($oo->system->last_session->addHours($oo->system->heartbeat) < Carbon::now())) - || ((! $oo->system->hearbeat) && ($oo->role < Address::NODE_ACTIVE) && ($oo->system->last_session->addHours(6) < Carbon::now()))) + || ((! $oo->system->hearbeat) && ($oo->role_id < Address::NODE_NN) && ($oo->system->last_session->addHours(6) < Carbon::now()))) { Log::info(sprintf('%s:- Polling [%s] (%s) - we havent seen them since [%s], heartbeat [%d]', self::LOGKEY, diff --git a/app/Models/Address.php b/app/Models/Address.php index b5962fc..4c8f24e 100644 --- a/app/Models/Address.php +++ b/app/Models/Address.php @@ -5,6 +5,7 @@ namespace App\Models; use Carbon\Carbon; use Illuminate\Database\Eloquent\Collection; use Illuminate\Database\Eloquent\Model; +use Illuminate\Database\Eloquent\Relations\HasMany; use Illuminate\Database\Eloquent\SoftDeletes; use Illuminate\Database\QueryException; use Illuminate\Support\Facades\DB; @@ -21,28 +22,20 @@ use App\Traits\ScopeActive; * If an address is not active, it belonged to the system at a point in time in the past. * * If an address is validated, we know that the system is using the address (we've confirmed that during a session). - * Any mail for that address will be delivered. + * validated is update/removed is during a mailer session, confirming if the node has the address * - * If an address is not validated, and the session password matches, validate the address. - * If the session password doesnt match, treat the address as foreign (dont deliver, unless we originate netmail) + * We'll only trigger a poll to a system that we have mail for if active && validated, unless "forced". * - * Session: - * + address not active - * ++ address validated (shouldnt be the case) - * ++ address not validated + * Any mail for that address will be delivered, if active && validated. * - * + address active - * ++ address validated (give mail/files) - * ++ address not validated - validate if the password is correct - * - * Mail in (from) - * ++ address not validated, do not process - * ++ address validated, process - * - * Mail out (to) - * ++ address validated, deliver - * ++ address not validated, only deliver netmail if we originate the call + * @see \App\Http\Requests\AddressAdd::class for rules about AKA and role */ + +// Need to add +// Calculated Region for an FTN, ie: find the parent and use their region id +// - if creating an RC, then the region is part of the creation, ZC region is 0 +// Then use this in createFTN + class Address extends Model { use ScopeActive,SoftDeletes; @@ -56,17 +49,21 @@ class Address extends Model public const NODE_RC = 1<<1; // Region public const NODE_NC = 1<<2; // Host public const NODE_HC = 1<<3; // Hub - public const NODE_ACTIVE = 1<<4; // Node + public const NODE_NN = 1<<4; // Node public const NODE_PVT = 1<<5; // Pvt (we dont have address information) @todo public const NODE_HOLD = 1<<6; // Hold (user has requested hold, we havent heard from the node for 7 days @todo public const NODE_DOWN = 1<<7; // Down we havent heard from the node for 30 days @todo public const NODE_POINT = 1<<8; // Point public const NODE_UNKNOWN = 1<<15; // Unknown - public const NODE_ALL = 0xFFF; // Mask to catch all nodes + public const NODE_ALL = 0x811f; // Mask to catch all nodes, excluding their status // http://ftsc.org/docs/frl-1002.001 public const ADDRESS_FIELD_MAX = 0x7fff; // Maximum value for a field in the address + protected $visible = ['zone_id','region_id','host_id','node_id','point_id','security']; + + /* STATIC */ + public static function boot() { parent::boot(); @@ -80,19 +77,22 @@ class Address extends Model }); } - protected $visible = ['zone_id','region_id','host_id','node_id','point_id','security']; - /* SCOPES */ + /** + * An FTN is active only if the address, zone, domain is also active + * + * @param $query + * @return mixed + */ public function scopeActiveFTN($query) { return $query->select($this->getTable().'.*') ->join('zones',['zones.id'=>'addresses.zone_id']) ->join('domains',['domains.id'=>'zones.domain_id']) - ->where('addresses.active',TRUE) ->where('zones.active',TRUE) ->where('domains.active',TRUE) - ->orderBy('domains.name') + ->active() ->FTNorder(); } @@ -113,13 +113,6 @@ class Address extends Model ->orderBy('point_id'); } - public function scopeTrashed($query) - { - return $query->select($this->getTable().'.*') - ->withTrashed() - ->FTNorder(); - } - /** * Return a list of addresses and the amount of uncollected echomail * @@ -140,7 +133,17 @@ class Address extends Model public function scopeUncollectedEchomailTotal($query) { return $query - ->select(['addresses.id','zone_id','host_id','node_id','point_id','system_id',DB::raw('count(*) as uncollected_echomail'),DB::raw('0 as uncollected_netmail'),DB::raw('0 as uncollected_files')]) + ->select([ + 'addresses.id', + 'zone_id', + 'host_id', + 'node_id', + 'point_id', + 'system_id', + DB::raw('count(*) as uncollected_echomail'), + DB::raw('0 as uncollected_netmail'), + DB::raw('0 as uncollected_files'), + ]) ->UncollectedEchomail(); } @@ -164,7 +167,17 @@ class Address extends Model public function scopeUncollectedFilesTotal($query) { return $query - ->select(['addresses.id','zone_id','host_id','node_id','point_id','system_id',DB::raw('0 as uncollected_echomail'),DB::raw('0 as uncollected_netmail'),DB::raw('count(*) as uncollected_files')]) + ->select([ + 'addresses.id', + 'zone_id', + 'host_id', + 'node_id', + 'point_id', + 'system_id', + DB::raw('0 as uncollected_echomail'), + DB::raw('0 as uncollected_netmail'), + DB::raw('count(*) as uncollected_files') + ]) ->UncollectedFiles(); } @@ -192,12 +205,27 @@ class Address extends Model public function scopeUncollectedNetmailTotal($query) { return $query - ->select(['addresses.id','zone_id','host_id','node_id','point_id','system_id',DB::raw('0 as uncollected_echomail'),DB::raw('count(*) as uncollected_netmail'),DB::raw('0 as uncollected_files')]) + ->select([ + 'addresses.id', + 'zone_id', + 'host_id', + 'node_id', + 'point_id', + 'system_id', + DB::raw('0 as uncollected_echomail'), + DB::raw('count(*) as uncollected_netmail'), + DB::raw('0 as uncollected_files') + ]) ->UncollectedNetmail(); } /* RELATIONS */ + public function domain() + { + return $this->hasOneThrough(Domain::class,Zone::class,'id','id','zone_id','domain_id'); + } + public function dynamics() { return $this->hasMany(Dynamic::class); @@ -211,31 +239,48 @@ class Address extends Model public function echoareas() { return $this->belongsToMany(Echoarea::class) + ->orderBy('name') ->withPivot(['subscribed']); } - /** - * Echomails that this address has seen - * - * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany - */ - public function echomails() - { - return $this->belongsToMany(Echomail::class,'echomail_seenby') - ->withPivot(['export_at','sent_at','sent_pkt']); - } - public function echomail_from() { return $this->hasMany(Echomail::class,'fftn_id','id'); } + /** + * Echomails that this address has seen + * + * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany + * @todo Rework echomail_seenby to not have a specific seenby recorded for the fftn_id, but automatically include it when generating seenbys. + */ + public function echomail_seen() + { + return $this->belongsToMany(Echomail::class,'echomail_seenby') + ->withPivot(['export_at','sent_at','sent_pkt']); + } + + /** + * @deprecated use echomail_seen() + */ + public function echomails() { + return $this->echomail_seen(); + } + + /** + * @deprecated use file_seen + */ + public function files() + { + return $this->file_seen(); + } + /** * Files that this address has seen * * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany */ - public function files() + public function file_seen(): \Illuminate\Database\Eloquent\Relations\BelongsToMany { return $this->belongsToMany(File::class,'file_seenby') ->withPivot(['sent_at','export_at']); @@ -246,17 +291,116 @@ class Address extends Model * * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany */ - public function fileareas() + public function fileareas(): \Illuminate\Database\Eloquent\Relations\BelongsToMany { return $this->belongsToMany(Filearea::class) + ->orderBy('name') ->withPivot(['subscribed']); } + /** + * If we are a hub, if role === NODE_HC and child entries have us as their hub_id + * + * @return HasMany + */ + public function nodes_hub(): HasMany + { + return $this->hasMany(Address::class,'hub_id','id') + ->active() + ->FTNorder() + ->with(['zone.domain']); + } + + /** + * Return the nodes that belong to this NC/RC/ZC + * + * @return HasMany + */ + public function nodes_net(): HasMany + { + return HasMany::noConstraints( + fn()=>$this->newHasMany( + (new self)->newQuery() + ->where('zone_id',$this->zone_id) + ->where('host_id',$this->host_id) + ->where('point_id',0) + ->whereNot('id',$this->id) + ->active() + ->FTNorder() + ->with(['zone.domain']), + $this, + NULL, + ($this->role_id === self::NODE_NC) ? 'id' : NULL) + ); + } + + /** + * If we are a boss node, return our children. + * + * @return HasMany + */ + public function nodes_point(): HasMany + { + return HasMany::noConstraints( + fn()=>$this->newHasMany( + (new self)->newQuery() + ->where('zone_id',$this->zone_id) + ->where('host_id',$this->host_id) + ->where('node_id',$this->node_id) + ->where('point_id','>',0) + ->whereNot('id',$this->id) + ->active() + ->FTNorder() + ->with(['zone.domain']), + $this, + NULL, + ($this->role_id !== self::NODE_POINT) ? 'id' : NULL) + ); + } + + public function nodes_region(): HasMany + { + return HasMany::noConstraints( + fn()=>$this->newHasMany( + (new self)->newQuery() + ->where('zone_id',$this->zone_id) + ->where('region_id',$this->region_id) + ->whereNot('id',$this->id) + ->active() + ->FTNorder() + ->with(['zone.domain']), + $this, + NULL, + ($this->role_id === self::NODE_RC) ? 'id' : NULL) + ); + } + + public function nodes_zone(): HasMany + { + return HasMany::noConstraints( + fn()=>$this->newHasMany( + (new self)->newQuery() + ->where('zone_id',$this->zone_id) + ->whereNot('id',$this->id) + ->active() + ->FTNorder() + ->with(['zone.domain']), + $this, + NULL, + ($this->role_id === self::NODE_ZC) ? 'id' : NULL) + ); + } + public function system() { return $this->belongsTo(System::class); } + public function uplink_hub() + { + return $this->belongsTo(Address::class,'hub_id','id'); + } + public function zone() { return $this->belongsTo(Zone::class); @@ -305,9 +449,54 @@ class Address extends Model return sprintf('%s.%d',$this->getFTN3DAttribute(),$this->point_id); } + public function getIsDownAttribute(): bool + { + return $this->role & self::NODE_DOWN; + } + + public function getIsHoldAttribute(): bool + { + return $this->role & self::NODE_HOLD; + } + + public function getIsPrivateAttribute(): bool + { + return $this->role & self::NODE_PVT; + } + + /** + * Determine this address' role (without status) + * + * @return int + * @see \App\Http\Requests\AddressAdd::class + */ + public function getRoleIdAttribute(): int + { + static $warn= FALSE; + + $val = ($this->role & self::NODE_ALL); + $role = $this->ftn_role(); + + if ($this->isRoleOverride()) { + if (! $warn) { + $warn = TRUE; + Log::alert(sprintf('%s:! Address ROLE [%d] is not consistent with what is expected [%d] for [%s]',self::LOGKEY,$val,$role,$this->ftn)); + } + + return $val; + + } else + return $role; + } + + /** + * Return a name for the role (without status) + * + * @return string + */ public function getRoleNameAttribute(): string { - switch ($this->role) { + switch ($this->role_id) { case self::NODE_ZC: return 'ZC'; case self::NODE_RC: @@ -316,23 +505,64 @@ class Address extends Model return 'NC'; case self::NODE_HC: return 'HUB'; - case self::NODE_ACTIVE: + case self::NODE_NN: return 'NODE'; case self::NODE_POINT: return 'POINT'; - case self::NODE_PVT: - return 'PRIVATE'; default: - return '?'; + return $this->role_id; } } /* METHODS */ /** - * Find children dependent on this record + * Find the immediate children dependent on this record + * + * @return Collection */ public function children(): Collection + { + // If we are a point, our parent is the boss + switch ($this->role_id) { + case self::NODE_NN: // Normal Nodes -> Points + return $this->nodes_point; + + case self::NODE_HC: // Hubs -> Normal Nodes + return $this->nodes_hub; + + case self::NODE_NC: // Nets -> Normal Nodes, excluding Hub's Nodes + return $this->nodes_net->diff($this + ->nodes_net + ->filter(function($item) { return $item->role_id === Address::NODE_HC; }) + ->transform(function($item) { return $item->children(); }) + ->flatten()); + + case self::NODE_RC: // Regions, excluding NC's Nodes + return $this->nodes_region->diff($this + ->nodes_region + ->filter(function($item) { return $item->role_id === Address::NODE_NC; }) + ->transform(function($item) { return $item->nodes_net; }) + ->flatten()); + + case self::NODE_ZC: // Zones, excluding RC's Nodes + return $this->nodes_zone->diff($this + ->nodes_zone + ->filter(function($item) { return $item->role_id === Address::NODE_RC; }) + ->transform(function($item) { return $item->nodes_region; }) + ->flatten()); + } + + return new Collection; + } + + /** + * Find who we should forward mail onto, taking into account session details that we have + * + * @return Collection + * @throws \Exception + */ + public function downlinks(): Collection { // We have no session data for this address, by definition it has no children if (! $this->session('sespass') && (! our_address()->pluck('id')->contains($this->id))) @@ -340,73 +570,19 @@ class Address extends Model // If this system is not marked to default route for this address if (! $this->session('default')) { - switch ($this->role) { - case self::NODE_ZC: - $children = self::select('addresses.*') - ->where('zone_id',$this->zone_id); + $children = $this->children(); - break; - - case self::NODE_RC: - $children = self::select('addresses.*') - ->where('zone_id',$this->zone_id) - ->where('region_id',$this->region_id); - - break; - - case self::NODE_NC: - $children = self::select('addresses.*') - ->where('zone_id',$this->zone_id) - ->where('region_id',$this->region_id) - ->where('host_id',$this->host_id); - - break; - - case self::NODE_HC: - // Identify our children. - $children = self::select('addresses.*') - ->where('zone_id',$this->zone_id) - ->where('region_id',$this->region_id) - ->where('hub_id',$this->id); - - break; - - case self::NODE_ACTIVE: - case self::NODE_PVT: - case self::NODE_HOLD: - case self::NODE_DOWN: - case self::NODE_UNKNOWN: - // Identify our children. - $children = self::select('addresses.*') - ->where('zone_id',$this->zone_id) - ->where('region_id',$this->region_id) - ->where('host_id',$this->host_id) - ->where('node_id',$this->node_id) - ->where('point_id','<>',0); - break; - - case self::NODE_POINT: - // Points dont have children, but must return a relationship instance - return new Collection; - - default: - throw new \Exception('Unknown role: '.serialize($this->role)); - } - - // We route everything for this domain + // We route everything for this domain } else { $children = self::select('addresses.*') ->join('zones',['zones.id'=>'addresses.zone_id']) - ->where('domain_id',$this->zone->domain_id); + ->where('addresses.id','<>',$this->id) + ->where('domain_id',$this->zone->domain_id) + ->active() + ->FTNorder() + ->get(); } - // I cant have myself as a child, and have a high role than me - $children = $children->where('addresses.id','<>',$this->id) - ->where('role','>',$this->role) - ->FTNorder() - ->active() - ->get(); - // If there are no children if (! $children->count()) return new Collection; @@ -431,6 +607,7 @@ class Address extends Model * @param System $so * @return Address|null * @throws \Exception + * @todo Move to Static */ public static function createFTN(string $address,System $so): ?self { @@ -500,11 +677,10 @@ class Address extends Model $o = new self; $o->active = TRUE; $o->zone_id = $zo->id; - $o->region_id = 0; + $o->region_id = 0; // @todo Automatically determine region $o->host_id = $ftn['n']; $o->node_id = $ftn['f']; $o->point_id = $ftn['p']; - $o->role = $ftn['p'] ? self::NODE_POINT : self::NODE_UNKNOWN; try { $so->addresses()->save($o); @@ -524,6 +700,7 @@ class Address extends Model * @param bool $trashed * @return Address|null * @throws \Exception + * @todo Move to Static */ public static function findFTN(string $address,bool $trashed=FALSE): ?self { @@ -535,7 +712,7 @@ class Address extends Model ->join('zones',['zones.id'=>'addresses.zone_id']) ->join('domains',['domains.id'=>'zones.domain_id']) ->when($trashed,function($query) { - $query->trashed(); + $query->withTrashed(); },function($query) { $query->active(); }) @@ -543,10 +720,11 @@ class Address extends Model ->where('node_id',$ftn['f']) ->where('point_id',$ftn['p']) ->when($ftn['d'],function($query,$domain) { - $query->where('domains.name',$domain); - },function($query) { - $query->where('zones.default',TRUE); - }); + $query->where('domains.name',$domain); + },function($query) { + $query->where('zones.default',TRUE); + }) + ->orderBy('created_at','DESC'); $q = $query->clone(); @@ -555,7 +733,7 @@ class Address extends Model $o = $query ->where('region_id',$ftn['n']) ->where('host_id',$ftn['n']) - ->single(); + ->first(); // Look for a normal address if (! $o) @@ -569,9 +747,10 @@ class Address extends Model }) ->orWhere('host_id',$ftn['n']); }) - ->single(); + ->first(); // Check and see if we are a flattened domain, our address might be available with a different zone. + // This occurs when we are parsing 2D addresses from SEEN-BY, but we have the zone if (! $o && ($ftn['p'] === 0)) { if ($ftn['d']) $do = Domain::where(['name'=>$ftn['d']])->single(); @@ -599,6 +778,7 @@ class Address extends Model * @param bool $trashed * @return self|null * @throws \Exception + * @todo Move to Static */ public static function findZone(Domain $do,int $host,int $node,int $point,bool $trashed=FALSE): ?self { @@ -611,7 +791,7 @@ class Address extends Model ->select('addresses.*') ->join('zones',['zones.id'=>'addresses.zone_id']) ->when($trashed,function($query) { - $query->trashed(); + $query->withTrashed(); },function($query) { $query->active(); }) @@ -683,6 +863,7 @@ class Address extends Model /** * Echomail waiting to be sent to this system * + * @param int|null $max * @return Collection */ public function echomailWaiting(int $max=NULL): Collection @@ -711,6 +892,45 @@ class Address extends Model ->get(); } + /** + * Work out what role this FTN should have + * + * @return int|null + */ + private function ftn_role(): ?int + { + $role = NULL; + + // If we have a point address, we're a point + if ($this->point_id) + $role = self::NODE_POINT; + + // If we have a node_id, we're either a Node or a Hub + elseif ($this->node_id) { + $role = ($this->nodes_hub->count()) + ? self::NODE_HC + : ((($this->role & Address::NODE_ALL) === self::NODE_HC) ? self::NODE_HC : self::NODE_NN); + + // point_id and node_id are zero + // If our region_id !== host_id, and are not zero, and node_id/point_id === 0, we are an NC + } elseif (($this->region_id !== $this->host_id) && $this->host_id) { + $role = self::NODE_NC; + + // point_id and node_id are zero + } elseif (($this->region_id === $this->host_id) && $this->host_id) { + $role = self::NODE_RC; + + // point_id and node_id are zero + } elseif (($this->region_id === $this->host_id) && (! $this->host_id)) { + $role = self::NODE_ZC; + } + + if (is_null($role)) + Log::alert(sprintf('%s:! Address ROLE [%d] could not be determined for [%s]',self::LOGKEY,($this->role & Address::NODE_ALL),$this->ftn)); + + return $role; + } + /** * Get echomail for this node * @@ -825,6 +1045,7 @@ class Address extends Model * @param Collection $msgs of message models (Echomail/Netmail) * @param string|null $passwd Override password used in packet * @return Packet|null + * @throws \Exception */ public function getPacket(Collection $msgs,string $passwd=NULL): ?Packet { @@ -854,6 +1075,14 @@ class Address extends Model return $o; } + public function isRoleOverride(): bool + { + $val = ($this->role & self::NODE_ALL); + $role = $this->ftn_role(); + + return ($val && ($role !== $val)) || (! $role); + } + /** * Netmail waiting to be sent to this system * @@ -894,102 +1123,66 @@ class Address extends Model } /** - * Who we send this systems mail to. + * Find the immediate parent for this node. * * @return Address|null * @throws \Exception */ public function parent(): ?Address { - // If we have session password, then we are the parent - if ($this->session('sespass')) - return $this; - - // If it is our address - if (our_address()->contains($this)) - return NULL; - - switch ($this->role) { - // ZCs dont have parents, but we may have a default - case self::NODE_ZC: - if (($x=$this->zone->systems->where('pivot.default',TRUE))->count()) - return $x->first()->match($this->zone,255)->first(); - else - return NULL; - - // RC - case self::NODE_RC: - $parent = self::where('zone_id',$this->zone_id) - ->where('region_id',0) - ->where('host_id',0) - ->where('node_id',0) - ->single(); - - break; - - // Hosts - case self::NODE_NC: - // See if we have an RC - $parent = self::where('zone_id',$this->zone_id) - ->where('region_id',$this->region_id) - ->where('host_id',$this->region_id) - ->where('node_id',0) - ->single(); - - if (! $parent) { - // See if we have an ZC - $parent = self::where('zone_id',$this->zone_id) - ->where('region_id',0) - ->where('host_id',0) - ->where('node_id',0) - ->single(); - } - - break; - - // Hubs - case self::NODE_HC: - // Normal Nodes - case self::NODE_ACTIVE: - case self::NODE_PVT: - case self::NODE_HOLD: - case self::NODE_DOWN: - case self::NODE_UNKNOWN: - // If we are a child of a hub, then check our hub - $parent = ($this->hub_id - ? self::where('id',$this->hub_id) - : self::where('zone_id',$this->zone_id) - ->where('region_id',$this->region_id) - ->where('host_id',$this->host_id) - ->where('role','<',self::NODE_HC)) - ->active() - ->single(); - break; - - case self::NODE_POINT: - $parent = self::where('zone_id',$this->zone_id) - ->where('region_id',$this->region_id) + // If we are a point, our parent is the boss + switch ($this->role_id) { + case self::NODE_POINT: // BOSS Node + return Address::active() + ->where('zone_id',$this->zone_id) ->where('host_id',$this->host_id) ->where('node_id',$this->node_id) ->where('point_id',0) - ->active() ->single(); - break; + + case self::NODE_NN: // HUB if it exists, otherwise NC + if ($this->uplink_hub) + return $this->uplink_hub; + + // Else fall through + + case self::NODE_HC: // RC + return Address::active() + ->where('zone_id',$this->zone_id) + ->where('host_id',$this->host_id) + ->where('node_id',0) + ->where('point_id',0) + ->single(); + + case self::NODE_NC: // RC + return Address::active() + ->where('zone_id',$this->zone_id) + ->where('region_id',$this->region_id) + ->where('host_id',$this->region_id) + ->where('node_id',0) + ->where('point_id',0) + ->single(); + + case self::NODE_RC: // ZC + return Address::active() + ->where('zone_id',$this->zone_id) + ->where('region_id',0) + ->where('node_id',0) + ->where('point_id',0) + ->single(); default: - throw new \Exception(sprintf('Unknown role: %s (%d)',serialize($this->role),$this->id)); + return NULL; } - - return $parent?->parent(); } /** - * * Parse a string and split it out as an FTN array * * @param string $ftn * @return array * @throws \Exception + * @todo Move to Static */ public static function parseFTN(string $ftn): array { @@ -1023,4 +1216,32 @@ class Address extends Model { return ($this->exists && ($x=$this->system->sessions->where('id',$this->zone_id)->first())) ? ($x->pivot->{$type} ?: '') : NULL; } + + /** + * Get the appropriate parent for this address, taking into account who we have session information with + * + * @return Address|$this|null + * @throws \Exception + */ + public function uplink(): ?Address + { + // If it is our address + if (our_address()->contains($this)) + return NULL; + + // If we have session password, then we are the parent + if ($x=$this->session('sespass')) + return $this; + + if ($x=$this->parent()?->uplink()) { + return $x; + + } else { + $sz = SystemZone::whereIn('zone_id',$this->domain->zones->pluck('id')) + ->where('default',TRUE) + ->single(); + + return $sz?->system->addresses->sortBy('security')->last(); + } + } } \ No newline at end of file diff --git a/app/Models/Echoarea.php b/app/Models/Echoarea.php index 5434ec8..daf2384 100644 --- a/app/Models/Echoarea.php +++ b/app/Models/Echoarea.php @@ -58,8 +58,7 @@ class Echoarea extends Model public function addresses_active() { - return $this->belongsToMany(Address::class) - ->activeFTN(); + return $this->belongsToMany(Address::class); } public function domain() diff --git a/app/Models/System.php b/app/Models/System.php index f02777e..305dbb2 100644 --- a/app/Models/System.php +++ b/app/Models/System.php @@ -194,7 +194,7 @@ class System extends Model */ public function full_name(Address $o): string { - switch ($o->attributes['role']) { + switch ($o->role_id) { case Address::NODE_ZC; return sprintf('ZC-%s-%05d',$o->zone->domain->name,$o->zone->zone_id); @@ -205,7 +205,7 @@ class System extends Model return sprintf('NC-%s-%05d',$o->zone->domain->name,$o->host_id); case Address::NODE_HC; - case Address::NODE_ACTIVE; + case Address::NODE_NN; default: return $this->name; } @@ -218,9 +218,8 @@ class System extends Model * @param Zone $o * @param int $type * @return Collection - * @todo This doesnt return sorted addresses, so it is possible that a node address is returned first, before a NC/HC, etc */ - public function match(Zone $o,int $type=(Address::NODE_NC|Address::NODE_HC|Address::NODE_ACTIVE|Address::NODE_PVT|Address::NODE_POINT)): Collection + public function match(Zone $o,int $type=(Address::NODE_NC|Address::NODE_HC|Address::NODE_NN|Address::NODE_POINT)): Collection { $akas = $this->akas ->where(function($item) use($o) { @@ -228,9 +227,7 @@ class System extends Model }); return ($akas->count() > 1) - ? $akas->filter(function($item) use ($type) { - return $item->role & $type; - }) + ? $akas->filter(function($item) use ($type) { return $item->role_id & $type;}) : $akas; } @@ -241,7 +238,7 @@ class System extends Model * @param int $type * @return Collection */ - public function inMyZones(Collection $addresses,int $type=(Address::NODE_HC|Address::NODE_ACTIVE|Address::NODE_PVT|Address::NODE_POINT)): Collection + public function inMyZones(Collection $addresses,int $type=(Address::NODE_HC|Address::NODE_NN|Address::NODE_POINT)): Collection { $myzones = $this->addresses->pluck('zone_id')->unique(); diff --git a/app/Models/User.php b/app/Models/User.php index 345b1e9..24a982b 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -101,9 +101,8 @@ class User extends Authenticatable implements MustVerifyEmail } /** - * Return the zones that this user is ZC for - * * @return Collection + * @deprecated not used - but if it is, probably could use Address::points()? */ public function points(): Collection { @@ -122,8 +121,8 @@ class User extends Authenticatable implements MustVerifyEmail */ public function zc(): Collection { - $this->load('systems.addresses'); + $this->load('systems.addresses.nodes_hub'); - return $this->systems->pluck('addresses')->flatten()->where('role',Address::NODE_ZC); + return $this->systems->pluck('addresses')->flatten()->where('role_id',Address::NODE_ZC); } } diff --git a/app/helpers.php b/app/helpers.php index 344a136..b22298b 100644 --- a/app/helpers.php +++ b/app/helpers.php @@ -117,7 +117,7 @@ function our_address(Domain|Address $o=NULL): Collection|Address|NULL $filter = $our->filter(function($item) use ($o) { return $item->zone->domain_id === $o->zone->domain_id; })->sortBy('role'); // If we are looking for a specific address, and there is only 1 result, return it, otherwise return what we have - if (config('fido.strict') && ($x=$filter->filter(function($item) use ($o) { return $item->role <= $o->role; })->sortBy('role'))->count()) + if (config('fido.strict') && ($x=$filter->filter(function($item) use ($o) { return $item->role_id <= $o->role_id; })->sortBy('role'))->count()) $filter = $x; return $filter->last(); diff --git a/database/migrations/2024_05_07_211343_address_remove_role_not_null.php b/database/migrations/2024_05_07_211343_address_remove_role_not_null.php new file mode 100644 index 0000000..5232d40 --- /dev/null +++ b/database/migrations/2024_05_07_211343_address_remove_role_not_null.php @@ -0,0 +1,24 @@ +$nid, 'point_id'=>0, 'system_id'=>$so->id, - 'role'=>Address::NODE_ACTIVE, + 'role'=>Address::NODE_NN, 'created_at'=>Carbon::now(), 'updated_at'=>Carbon::now(), ]); @@ -167,7 +167,7 @@ class TestNodeHierarchy extends Seeder 'node_id'=>$nid, 'point_id'=>0, 'system_id'=>$so->id, - 'role'=>Address::NODE_ACTIVE, + 'role'=>Address::NODE_NN, 'created_at'=>Carbon::now(), 'updated_at'=>Carbon::now(), ]); @@ -214,7 +214,7 @@ class TestNodeHierarchy extends Seeder 'node_id'=>$nid, 'point_id'=>0, 'system_id'=>$so->id, - 'role'=>Address::NODE_ACTIVE, + 'role'=>Address::NODE_NN, 'created_at'=>Carbon::now(), 'updated_at'=>Carbon::now(), ]); @@ -251,7 +251,7 @@ class TestNodeHierarchy extends Seeder 'point_id'=>0, 'system_id'=>$so->id, 'hub_id'=>$hub->id, - 'role'=>Address::NODE_ACTIVE, + 'role'=>Address::NODE_NN, 'created_at'=>Carbon::now(), 'updated_at'=>Carbon::now(), ]); diff --git a/resources/views/layouts/partials/sidebar.blade.php b/resources/views/layouts/partials/sidebar.blade.php index 4b7dfaf..c58933e 100644 --- a/resources/views/layouts/partials/sidebar.blade.php +++ b/resources/views/layouts/partials/sidebar.blade.php @@ -32,14 +32,14 @@
Echoareas
Fileareas
+ @endif + @can('admin')
System Admin
This Host Systems
- @endif - @can('admin')
Users
Create
diff --git a/resources/views/status.blade.php b/resources/views/status.blade.php index 0d3d475..8483e74 100644 --- a/resources/views/status.blade.php +++ b/resources/views/status.blade.php @@ -177,7 +177,7 @@ {{ $o->zone->domain->name }} {{ $o->system->name }} - @if (($x=$o->parent()) && ($x->id !== $o->id)) + @if (($x=$o->uplink()) && ($x->id !== $o->id))
[via {{ $x->ftn4d }}] @endif diff --git a/resources/views/system/addedit.blade.php b/resources/views/system/addedit.blade.php index 8fe565c..755134b 100644 --- a/resources/views/system/addedit.blade.php +++ b/resources/views/system/addedit.blade.php @@ -1,3 +1,7 @@ +@php + use App\Models\Address; +@endphp + @extends('layouts.app') @@ -135,10 +139,10 @@ - @if ((\App\Models\Address::NODE_HC|\App\Models\Address::NODE_ACTIVE) & $oo->role) + @if ((Address::NODE_HC|Address::NODE_NN) & $oo->role_id) @endif - @if ((\App\Models\Address::NODE_NC|\App\Models\Address::NODE_HC) & $oo->role) + @if ((Address::NODE_NC|Address::NODE_HC) & $oo->role_id) @endif @endif @@ -276,70 +280,7 @@
-
- -
- @if(! $o->setup && ($x=\App\Models\Zone::active() - ->whereIn('id',$o->zones->pluck('id')) - ->whereNotIn('id',$o->sessions->pluck('id')) - ->get())->count()) - -

This host's mail is sent to:

- - - - - - - - - - @foreach($x as $zo) - @foreach ($o->match($zo,\App\Models\Address::NODE_ALL) as $oo) - - - - - @endforeach - @endforeach - -
AKAUplink
{{ $oo->ftn }} - @if ($x=$oo->parent()) - {{ $x->ftn4d }} - @else - None - @endif -
- @endif -
- - -
- @if($o->sessions->count()) -

This host collects mail for the following systems:

- - - - - - - - - - - @foreach ($o->sessions->sortBy('zone_id') as $zo) - @foreach ($o->match($zo,\App\Models\Address::NODE_ALL) as $oo) - - - - - @endforeach - @endforeach - -
AKADownlink(s)
{{ $oo->ftn }}{!! (($x=$oo->children()) && $x->count()) ? $x->pluck('ftn4d')->join('
') : 'None' !!}
- @endif -
-
+ @include('system.widget.routing')
diff --git a/resources/views/system/widget/routing.blade.php b/resources/views/system/widget/routing.blade.php new file mode 100644 index 0000000..3c42fd4 --- /dev/null +++ b/resources/views/system/widget/routing.blade.php @@ -0,0 +1,68 @@ +@php + use App\Models\{Address,Zone}; +@endphp + +
+ +
+ @if(! $o->setup && ($x=Zone::active() + ->whereIn('id',$o->zones->pluck('id')) + ->whereNotIn('id',$o->sessions->pluck('id')) + ->get())->count()) + +

This host's mail is sent to:

+ + + + + + + + + + @foreach($x as $zo) + @foreach ($o->match($zo,Address::NODE_ALL) as $oo) + + + + + @endforeach + @endforeach + +
AKAUplink
{{ $oo->ftn }} + @if ($x=$oo->uplink()) + {{ $x->ftn4d }} + @else + None + @endif +
+ @endif +
+ + +
+ @if($o->sessions->count()) +

This host collects mail for the following systems:

+ + + + + + + + + + + @foreach ($o->sessions->sortBy('zone_id') as $zo) + @foreach ($o->match($zo,Address::NODE_ALL) as $oo) + + + + + @endforeach + @endforeach + +
AKAFor Systems(s)
{{ $oo->ftn }}{!! (($x=$oo->downlinks()) && $x->count()) ? $x->pluck('ftn')->join('
') : 'None' !!}
+ @endif +
+
\ No newline at end of file diff --git a/resources/views/system/widget/system.blade.php b/resources/views/system/widget/system.blade.php index c08dfc4..47da7c7 100644 --- a/resources/views/system/widget/system.blade.php +++ b/resources/views/system/widget/system.blade.php @@ -1,3 +1,7 @@ +@php + use App\Models\{Mailer,User}; +@endphp +
@@ -14,7 +18,7 @@ @@ -145,7 +149,7 @@
- @foreach (\App\Models\Mailer::all() as $mo) + @foreach (Mailer::all() as $mo) @php($x=$o->mailers->find($mo))
@@ -282,6 +286,7 @@
+
pollmode))d-none @endif" id="heartbeat_option"> @can('admin',$o)
diff --git a/tests/Feature/RoutingTest.php b/tests/Feature/RoutingTest.php index f8aa67e..19d202a 100644 --- a/tests/Feature/RoutingTest.php +++ b/tests/Feature/RoutingTest.php @@ -46,8 +46,8 @@ use App\Models\{Address,Domain,Setup,System}; * + See COMMON * + Everything else is sent to the HUB or Host or RC (our uplink) * - * @see Address::parent() - * @see Address::children() + * @see Address::uplink() + * @see Address::downlinks() */ class RoutingTest extends TestCase { @@ -106,9 +106,9 @@ class RoutingTest extends TestCase // Pick ZC without any session info - we have 0 children $ao = Address::findFTN('101:0/0@a'); - $this->assertEquals($ao->role,Address::NODE_ZC); - $this->assertCount(0,$ao->children()); - $this->assertNull($ao->parent()); + $this->assertEquals($ao->role_id,Address::NODE_ZC); + $this->assertCount(0,$ao->downlinks()); + $this->assertNull($ao->uplink()); } // If we have a ZC, make sure we are routing to all it's children @@ -117,7 +117,7 @@ class RoutingTest extends TestCase $this->session_zc(); $ao = Address::findFTN('101:0/0@a'); - $this->assertCount(935,$ao->children()); + $this->assertCount(935,$ao->downlinks()); } // An RC's parent should be the ZC, when we have session details with parent @@ -126,8 +126,8 @@ class RoutingTest extends TestCase $this->session_zc(); $ao = Address::findFTN('101:1/0@a'); - $this->assertEquals($ao->role,Address::NODE_RC); - $this->assertEquals('101:0/0.0@a',$ao->parent()->ftn); + $this->assertEquals($ao->role_id,Address::NODE_RC); + $this->assertEquals('101:0/0.0@a',$ao->uplink()->ftn); } // Get a list of active addresses in a Region @@ -136,7 +136,7 @@ class RoutingTest extends TestCase $this->session_rc(); $ao = Address::findFTN('100:1/0@a'); - $this->assertEquals(185,$ao->children()->count()); + $this->assertEquals(185,$ao->downlinks()->count()); } // An RCs node still collects mail from the RC @@ -146,8 +146,8 @@ class RoutingTest extends TestCase // An RCs node should still be the RC $ao = Address::findFTN('100:1/100@a'); - $this->assertEquals($ao->role,Address::NODE_ACTIVE); - $this->assertEquals('100:1/0.0@a',$ao->parent()->ftn); + $this->assertEquals($ao->role_id,Address::NODE_NN); + $this->assertEquals('100:1/0.0@a',$ao->uplink()->ftn); } // An NC collects mail for its children @@ -157,8 +157,8 @@ class RoutingTest extends TestCase // A NCs parent should still be the RC $ao = Address::findFTN('100:10/0@a'); - $this->assertEquals($ao->role,Address::NODE_NC); - $this->assertEquals('100:1/0.0@a',$ao->parent()->ftn); + $this->assertEquals($ao->role_id,Address::NODE_NC); + $this->assertEquals('100:1/0.0@a',$ao->uplink()->ftn); } // A Hub still collects mail from NC @@ -168,8 +168,8 @@ class RoutingTest extends TestCase // A Hubs parent should still be the NC $ao = Address::findFTN('100:10/20.0@a'); - $this->assertEquals($ao->role,Address::NODE_HC); - $this->assertEquals('100:1/0.0@a',$ao->parent()->ftn); + $this->assertEquals($ao->role_id,Address::NODE_HC); + $this->assertEquals('100:1/0.0@a',$ao->uplink()->ftn); } // A Hub's node still collects mail from Hub @@ -179,8 +179,8 @@ class RoutingTest extends TestCase // A Hubs node should still be the Hub $ao = Address::findFTN('100:10/22.0@a'); - $this->assertEquals($ao->role,Address::NODE_ACTIVE); - $this->assertEquals('100:1/0.0@a',$ao->parent()->ftn); + $this->assertEquals($ao->role_id,Address::NODE_NN); + $this->assertEquals('100:1/0.0@a',$ao->uplink()->ftn); } // An RCs parent is us even if we have session details for another RC @@ -189,7 +189,7 @@ class RoutingTest extends TestCase $this->session_rc(); $ao = Address::findFTN('100:2/0@a'); - $this->assertNull($ao->parent()?->ftn); + $this->assertNull($ao->uplink()?->ftn); } // If we also have session details for an NC, then there are less RC nodes @@ -199,7 +199,7 @@ class RoutingTest extends TestCase $this->session_nc(); $ao = Address::findFTN('100:1/0@a'); - $this->assertCount(185-36,$ao->children()); + $this->assertCount(185-36,$ao->downlinks()); } // If we also have session details for an Hub, then there are less RC nodes @@ -211,10 +211,10 @@ class RoutingTest extends TestCase $ao->system->sessions()->attach([$ao->zone_id=>['sespass'=>'ABCD']]); $ao = Address::findFTN('100:1/0@a'); - $this->assertCount(185-6,$ao->children()); + $this->assertCount(185-6,$ao->downlinks()); $ao = Address::findFTN('100:10/22@a'); - $this->assertEquals('100:10/20.0@a',$ao->parent()->ftn); + $this->assertEquals('100:10/20.0@a',$ao->uplink()->ftn); } // If we also have session details for an Hub, then there are less RC nodes @@ -223,7 +223,7 @@ class RoutingTest extends TestCase $this->session_hub(); $ao = Address::findFTN('100:10/22@a'); - $this->assertEquals('100:10/20.0@a',$ao->parent()->ftn); + $this->assertEquals('100:10/20.0@a',$ao->uplink()->ftn); } // When we have an RC with session details, we route to all its children @@ -232,7 +232,7 @@ class RoutingTest extends TestCase $this->session_nc(); $ao = Address::findFTN('100:10/0@a'); - $this->assertCount(35,$ao->children()); + $this->assertCount(35,$ao->downlinks()); } public function test_complex_rc_nc_hc() @@ -242,29 +242,29 @@ class RoutingTest extends TestCase $this->session_hub(); $ao = Address::findFTN('100:1/100.0@a'); - $this->assertCount(0,$ao->children()); - $this->assertEquals('100:1/0.0@a',$ao->parent()->ftn); + $this->assertCount(0,$ao->downlinks()); + $this->assertEquals('100:1/0.0@a',$ao->uplink()->ftn); // RC $ao = Address::findFTN('100:1/0.0@a'); - $this->assertCount(186-1-30-6,$ao->children()); + $this->assertCount(186-1-30-6,$ao->downlinks()); $ao = Address::findFTN('100:11/0.0@a'); - $this->assertEquals('100:1/0.0@a',$ao->parent()->ftn); + $this->assertEquals('100:1/0.0@a',$ao->uplink()->ftn); // NC $ao = Address::findFTN('100:10/0.0@a'); - $this->assertCount(36-1-6,$ao->children()); + $this->assertCount(36-1-6,$ao->downlinks()); $ao = Address::findFTN('100:10/10.0@a'); - $this->assertEquals('100:10/0.0@a',$ao->parent()->ftn); + $this->assertEquals('100:10/0.0@a',$ao->uplink()->ftn); // HC $ao = Address::findFTN('100:10/20.0@a'); - $this->assertCount(6-1,$ao->children()); + $this->assertCount(6-1,$ao->downlinks()); $ao = Address::findFTN('100:10/22.0@a'); - $this->assertEquals('100:10/20.0@a',$ao->parent()->ftn); + $this->assertEquals('100:10/20.0@a',$ao->uplink()->ftn); } public function test_complex_rc_nc_hc_us() @@ -283,29 +283,29 @@ class RoutingTest extends TestCase $ao->system->sessions()->attach([$ao->zone_id=>['sespass'=>'ABCD']]); $ao = Address::findFTN('100:1/100.0@a'); - $this->assertCount(0,$ao->children()); - $this->assertEquals('100:1/0.0@a',$ao->parent()?->ftn); + $this->assertCount(0,$ao->downlinks()); + $this->assertEquals('100:1/0.0@a',$ao->uplink()?->ftn); // RC $ao = Address::findFTN('100:1/0.0@a'); - $this->assertCount(186-36-36-1,$ao->children()); + $this->assertCount(186-36-36-1,$ao->downlinks()); $ao = Address::findFTN('100:11/0.0@a'); - $this->assertEquals('100:11/0.0@a',$ao->parent()->ftn); + $this->assertEquals('100:11/0.0@a',$ao->uplink()->ftn); // NC $ao = Address::findFTN('100:10/0.0@a'); - $this->assertCount(36-6-1,$ao->children()); + $this->assertCount(36-6-1,$ao->downlinks()); $ao = Address::findFTN('100:10/10.0@a'); - $this->assertNull($ao->parent()?->ftn); + $this->assertNull($ao->uplink()?->ftn); // HC $ao = Address::findFTN('100:10/20.0@a'); - $this->assertCount(6-1,$ao->children()); + $this->assertCount(6-1,$ao->downlinks()); $ao = Address::findFTN('100:10/22.0@a'); - $this->assertEquals('100:10/20.0@a',$ao->parent()->ftn); + $this->assertEquals('100:10/20.0@a',$ao->uplink()->ftn); Cache::forget('so'); } @@ -330,9 +330,9 @@ class RoutingTest extends TestCase $ao->system->sessions()->attach([$ao->zone_id=>['sespass'=>'ABCD']]); $ao = Address::findFTN('100:10/21.2@a'); - $this->assertEquals('100:10/21.0@a',$ao->parent()?->ftn); + $this->assertEquals('100:10/21.0@a',$ao->uplink()?->ftn); $ao = Address::findFTN('100:10/21@a'); - $this->assertCount(1,$ao->children()); + $this->assertCount(1,$ao->downlinks()); } } \ No newline at end of file