Rework address roles, making Address::role optional, rework determining uplink/downlinks/parent/children

This commit is contained in:
2024-05-09 21:22:30 +10:00
parent 2765a27db8
commit 23159d19d5
23 changed files with 667 additions and 421 deletions

View File

@@ -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;
}

View File

@@ -0,0 +1,48 @@
<?php
namespace App\Console\Commands\Debug;
use App\Models\Address;
use Illuminate\Console\Command;
class AddressCheckRole extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'debug:address:check:role {--f|fix : Fix the role}';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Check address roles and optionally fix';
/**
* Execute the console command.
*/
public function handle()
{
foreach (Address::withTrashed()->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));
}
}
}
}
}

View File

@@ -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 '';
}
}

View File

@@ -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));
}
}