Move DomainController::NODE* to Address::NODE*, make role mandatory in the database, change logic so that mail generated by the host comes from a node address.

This commit is contained in:
Deon George 2022-01-24 22:56:13 +11:00
parent efa7195633
commit d660d5a6df
15 changed files with 143 additions and 110 deletions

View File

@ -10,7 +10,6 @@ use Illuminate\Support\Facades\Log;
use Symfony\Component\HttpFoundation\File\File; use Symfony\Component\HttpFoundation\File\File;
use App\Classes\FTN as FTNBase; use App\Classes\FTN as FTNBase;
use App\Http\Controllers\DomainController;
use App\Models\{Address,Setup,Software,System,Zone}; use App\Models\{Address,Setup,Software,System,Zone};
class Packet extends FTNBase implements \Iterator, \Countable class Packet extends FTNBase implements \Iterator, \Countable
@ -462,7 +461,7 @@ class Packet extends FTNBase implements \Iterator, \Countable
} }
$ao->active = TRUE; $ao->active = TRUE;
$ao->role = DomainController::NODE_UNKNOWN; $ao->role = Address::NODE_UNKNOWN;
System::unguard(); System::unguard();
$so = System::firstOrCreate([ $so = System::firstOrCreate([

View File

@ -194,7 +194,7 @@ abstract class Protocol
$addresses = collect(); $addresses = collect();
foreach (($this->originate ? $this->node->aka_remote_authed : $this->node->aka_remote) as $ao) foreach (($this->originate ? $this->node->aka_remote_authed : $this->node->aka_remote) as $ao)
$addresses = $addresses->merge($this->setup->system->match($ao->zone)); $addresses = $addresses->merge($this->setup->system->match($ao->zone,Address::NODE_ZC|Address::NODE_RC|Address::NODE_NC|Address::NODE_HC|Address::NODE_ACTIVE|Address::NODE_PVT|Address::NODE_POINT));
$addresses = $addresses->unique(); $addresses = $addresses->unique();

View File

@ -154,7 +154,7 @@ final class Binkp extends BaseProtocol
$addresses = collect(); $addresses = collect();
foreach ($this->node->aka_remote_authed as $ao) foreach ($this->node->aka_remote_authed as $ao)
$addresses = $addresses->merge($this->setup->system->match($ao->zone)); $addresses = $addresses->merge($this->setup->system->match($ao->zone,Address::NODE_ZC|Address::NODE_RC|Address::NODE_NC|Address::NODE_HC|Address::NODE_ACTIVE|Address::NODE_PVT|Address::NODE_POINT));
$addresses = $addresses->unique(); $addresses = $addresses->unique();

View File

@ -9,17 +9,6 @@ use App\Models\{Address,Domain,Zone};
class DomainController extends Controller class DomainController extends Controller
{ {
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_POINT = 1<<4; // Point
public const NODE_PVT = 1<<5; // Pvt
public const NODE_HOLD = 1<<6; // Hold
public const NODE_DOWN = 1<<7; // Down
public const NODE_UNKNOWN = 1<<8; // Down
// http://ftsc.org/docs/frl-1002.001 // http://ftsc.org/docs/frl-1002.001
public const NUMBER_MAX = 0x7fff; public const NUMBER_MAX = 0x7fff;
@ -65,7 +54,7 @@ class DomainController extends Controller
*/ */
public function api_hosts(Zone $o,int $region): Collection public function api_hosts(Zone $o,int $region): Collection
{ {
$oo = Address::where('role',self::NODE_NC) $oo = Address::where('role',Address::NODE_NC)
->where('zone_id',$o->id) ->where('zone_id',$o->id)
->when($region,function($query,$region) { return $query->where('region_id',$region)->where('node_id',0); }) ->when($region,function($query,$region) { return $query->where('region_id',$region)->where('node_id',0); })
->when((! $region),function($query) use ($region) { return $query->where('region_id',0); }) ->when((! $region),function($query) use ($region) { return $query->where('region_id',0); })
@ -107,7 +96,7 @@ class DomainController extends Controller
*/ */
public function api_regions(Zone $o): Collection public function api_regions(Zone $o): Collection
{ {
$oo = Address::where('role',self::NODE_RC) $oo = Address::where('role',Address::NODE_RC)
->where('zone_id',$o->id) ->where('zone_id',$o->id)
->where('node_id',0) ->where('node_id',0)
->where('point_id',0) ->where('point_id',0)

View File

@ -53,13 +53,13 @@ class SystemController extends Controller
->where('host_id',0) ->where('host_id',0)
->where('node_id',0) ->where('node_id',0)
->where('point_id',0) ->where('point_id',0)
->where('role',DomainController::NODE_RC); ->where('role',Address::NODE_RC);
}) })
// Check that a host doesnt already exist // Check that a host doesnt already exist
->orWhere(function($query) use ($value) { ->orWhere(function($query) use ($value) {
return $query->where('host_id',$value) return $query->where('host_id',$value)
->where('point_id',0) ->where('point_id',0)
->where('role',DomainController::NODE_NC); ->where('role',Address::NODE_NC);
}); });
if ($o->count()) { if ($o->count()) {
@ -75,7 +75,7 @@ class SystemController extends Controller
$oo->host_id = 0; $oo->host_id = 0;
$oo->node_id = 0; $oo->node_id = 0;
$oo->point_id = 0; $oo->point_id = 0;
$oo->role = DomainController::NODE_RC; $oo->role = Address::NODE_RC;
$oo->active = TRUE; $oo->active = TRUE;
$o->addresses()->save($oo); $o->addresses()->save($oo);
@ -92,12 +92,12 @@ class SystemController extends Controller
$o = Address::where(function($query) use ($value) { $o = Address::where(function($query) use ($value) {
return $query->where(function($query) use ($value) { return $query->where(function($query) use ($value) {
return $query->where('region_id',$value) return $query->where('region_id',$value)
->where('role',DomainController::NODE_RC); ->where('role',Address::NODE_RC);
}) })
// Check that a host doesnt already exist // Check that a host doesnt already exist
->orWhere(function($query) use ($value) { ->orWhere(function($query) use ($value) {
return $query->where('host_id',$value) return $query->where('host_id',$value)
->where('role',DomainController::NODE_NC); ->where('role',Address::NODE_NC);
}); });
}) })
->where('zone_id',$request->post('zone_id')) ->where('zone_id',$request->post('zone_id'))
@ -119,7 +119,7 @@ class SystemController extends Controller
->where('host_id',$request->post('host_id_new')) ->where('host_id',$request->post('host_id_new'))
->where('node_id',$value) ->where('node_id',$value)
->where('point_id',0) ->where('point_id',0)
->where('role',DomainController::NODE_RC); ->where('role',Address::NODE_RC);
}); });
if ($o->count()) { if ($o->count()) {
@ -147,7 +147,7 @@ class SystemController extends Controller
'host_id'=>$request->host_id_new, 'host_id'=>$request->host_id_new,
'node_id'=>0, 'node_id'=>0,
'point_id'=>0, 'point_id'=>0,
'role'=>DomainController::NODE_NC, 'role'=>Address::NODE_NC,
]); ]);
} }
@ -161,7 +161,7 @@ class SystemController extends Controller
$oo->host_id = $request->post('host_id_new'); $oo->host_id = $request->post('host_id_new');
$oo->node_id = $request->post('node_id_new'); $oo->node_id = $request->post('node_id_new');
$oo->point_id = 0; $oo->point_id = 0;
$oo->role = DomainController::NODE_NC; $oo->role = Address::NODE_NC;
$oo->active = TRUE; $oo->active = TRUE;
$o->addresses()->save($oo); $o->addresses()->save($oo);
@ -204,7 +204,7 @@ class SystemController extends Controller
$oo->node_id = $request->post('node_id'); $oo->node_id = $request->post('node_id');
$oo->point_id = $request->post('point_id'); $oo->point_id = $request->post('point_id');
$oo->hub_id = $request->post('hub_id') > 0 ? $request->post('hub_id') : NULL; $oo->hub_id = $request->post('hub_id') > 0 ? $request->post('hub_id') : NULL;
$oo->role = (! $oo->point_id) && $request->post('hub') ? DomainController::NODE_HC : NULL; $oo->role = (! $oo->point_id) && $request->post('hub') ? Address::NODE_HC : Address::NODE_ACTIVE;
$oo->active = TRUE; $oo->active = TRUE;
$o->addresses()->save($oo); $o->addresses()->save($oo);
@ -242,7 +242,7 @@ class SystemController extends Controller
$zo = Zone::findOrFail($validate['zone_id']); $zo = Zone::findOrFail($validate['zone_id']);
// If this session is for the ZC, it now becomes the default. // If this session is for the ZC, it now becomes the default.
if (in_array(DomainController::NODE_ZC,$o->match($zo)->pluck('role')->toArray())) { if ($o->match($zo,Address::NODE_ZC)->count()) {
SystemZone::where('default',TRUE)->update(['default'=>FALSE]); SystemZone::where('default',TRUE)->update(['default'=>FALSE]);
$validate['default'] = TRUE; $validate['default'] = TRUE;
} }

View File

@ -93,7 +93,7 @@ class ZoneController extends Controller
'host_id'=>0, 'host_id'=>0,
'node_id'=>0, 'node_id'=>0,
'point_id'=>0, 'point_id'=>0,
'role'=>DomainController::NODE_ZC, 'role'=>Address::NODE_ZC,
]); ]);
} }
@ -121,7 +121,7 @@ class ZoneController extends Controller
$default = $o->systems->where('pivot.default',TRUE); $default = $o->systems->where('pivot.default',TRUE);
if ($default->count() && $default->first()->addresses->pluck('role')->search(DomainController::NODE_ZC) !== FALSE) if ($default->count() && $default->first()->addresses->pluck('role')->search(Address::NODE_ZC) !== FALSE)
abort(412); abort(412);
if ($default->count() && ($default->first()->id != $request->sid)) if ($default->count() && ($default->first()->id != $request->sid))

View File

@ -12,7 +12,6 @@ use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log; use Illuminate\Support\Facades\Log;
use Illuminate\Support\Str; use Illuminate\Support\Str;
use App\Http\Controllers\DomainController;
use App\Models\{Address,Domain,Nodelist,Setup,System,Zone}; use App\Models\{Address,Domain,Nodelist,Setup,System,Zone};
use App\Traits\Import as ImportTrait; use App\Traits\Import as ImportTrait;
@ -134,13 +133,13 @@ class NodelistImport implements ShouldQueue
$region = 0; $region = 0;
$host = 0; $host = 0;
$hub_id = NULL; $hub_id = NULL;
$role = DomainController::NODE_ZC; $role = Address::NODE_ZC;
break; break;
case 'Region': case 'Region':
$region = $fields[1]; $region = $fields[1];
$role = DomainController::NODE_RC; $role = Address::NODE_RC;
$host = 0; $host = 0;
$hub_id = NULL; $hub_id = NULL;
@ -149,36 +148,37 @@ class NodelistImport implements ShouldQueue
case 'Host': case 'Host':
$host = $fields[1]; $host = $fields[1];
$hub_id = NULL; $hub_id = NULL;
$role = DomainController::NODE_NC; $role = Address::NODE_NC;
break; break;
case 'Hub': case 'Hub':
$node = $fields[1]; $node = $fields[1];
$role = DomainController::NODE_HC; $role = Address::NODE_HC;
break; break;
case 'Pvt': case 'Pvt':
$node = $fields[1]; $node = $fields[1];
$role = DomainController::NODE_PVT; $role = Address::NODE_PVT;
break; break;
case 'Hold': case 'Hold':
$node = $fields[1]; $node = $fields[1];
$role = DomainController::NODE_HOLD; $role = Address::NODE_HOLD;
break; break;
case 'Down': case 'Down':
$node = $fields[1]; $node = $fields[1];
$role = DomainController::NODE_DOWN; $role = Address::NODE_DOWN;
break; break;
case '': case '':
$node = $fields[1]; $node = $fields[1];
$role = Address::NODE_ACTIVE;
break; break;
default: default:
@ -205,8 +205,6 @@ class NodelistImport implements ShouldQueue
$ao->role = $role; $ao->role = $role;
$ao->hub_id = $hub_id; $ao->hub_id = $hub_id;
$role = NULL;
if ($ao->exists) if ($ao->exists)
Log::debug(sprintf('%s:Processing existing address [%s]',self::LOGKEY,$ao->ftn)); Log::debug(sprintf('%s:Processing existing address [%s]',self::LOGKEY,$ao->ftn));
@ -330,7 +328,7 @@ class NodelistImport implements ShouldQueue
$so->baud = $fields[6]; $so->baud = $fields[6];
*/ */
if ($method && ($ao->role != DomainController::NODE_PVT)) { if ($method && ($ao->role != Address::NODE_PVT)) {
$so->mailer_type = $method; $so->mailer_type = $method;
$so->mailer_address = $address; $so->mailer_address = $address;
$so->mailer_port = $port; $so->mailer_port = $port;
@ -352,7 +350,7 @@ class NodelistImport implements ShouldQueue
try { try {
$so->addresses()->save($ao); $so->addresses()->save($ao);
if ($ao->role == DomainController::NODE_HC) if ($ao->role == Address::NODE_HC)
$hub_id = $ao->id; $hub_id = $ao->id;
$no->addresses()->attach($ao,['role'=>$ao->role]); $no->addresses()->attach($ao,['role'=>$ao->role]);
@ -382,4 +380,4 @@ class NodelistImport implements ShouldQueue
Log::info(sprintf('%s:Updated %d records from %d systems',self::LOGKEY,$p,$c)); Log::info(sprintf('%s:Updated %d records from %d systems',self::LOGKEY,$p,$c));
} }
} }

View File

@ -28,6 +28,17 @@ class Address extends Model
protected $with = ['zone']; protected $with = ['zone'];
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_ACTIVE = 1<<4; // Node
public const NODE_PVT = 1<<5; // Pvt
public const NODE_HOLD = 1<<6; // Hold
public const NODE_DOWN = 1<<7; // Down
public const NODE_POINT = 1<<8; // Point
public const NODE_UNKNOWN = 1<<15; // Unknown
/* SCOPES */ /* SCOPES */
public function scopeFTNOrder($query) public function scopeFTNOrder($query)
@ -52,20 +63,20 @@ class Address extends Model
if (! $this->session('default')) { if (! $this->session('default')) {
switch ($this->role) { switch ($this->role) {
case DomainController::NODE_ZC: case self::NODE_ZC:
$children = self::select('addresses.*') $children = self::select('addresses.*')
->where('zone_id',$this->zone_id); ->where('zone_id',$this->zone_id);
break; break;
case DomainController::NODE_RC: case self::NODE_RC:
$children = self::select('addresses.*') $children = self::select('addresses.*')
->where('zone_id',$this->zone_id) ->where('zone_id',$this->zone_id)
->where('region_id',$this->region_id); ->where('region_id',$this->region_id);
break; break;
case DomainController::NODE_NC: case self::NODE_NC:
$children = self::select('addresses.*') $children = self::select('addresses.*')
->where('zone_id',$this->zone_id) ->where('zone_id',$this->zone_id)
->where('region_id',$this->region_id) ->where('region_id',$this->region_id)
@ -73,16 +84,16 @@ class Address extends Model
break; break;
case DomainController::NODE_HC: case self::NODE_HC:
// Identify our children. // Identify our children.
$children = self::select('addresses.*') $children = self::select('addresses.*')
->where('hub_id',$this->id); ->where('hub_id',$this->id);
break; break;
case DomainController::NODE_UNKNOWN: case self::NODE_UNKNOWN:
case DomainController::NODE_ACTIVE: case self::NODE_ACTIVE:
case DomainController::NODE_POINT: case self::NODE_POINT:
// Nodes dont have children, but must return a relationship instance // Nodes dont have children, but must return a relationship instance
return $this->hasOne(self::class,NULL,'void'); return $this->hasOne(self::class,NULL,'void');
@ -158,14 +169,14 @@ class Address extends Model
switch ($this->role) { switch ($this->role) {
// ZCs dont have parents, but we may have a default // ZCs dont have parents, but we may have a default
case DomainController::NODE_ZC: case self::NODE_ZC:
if (($x=$this->zone->systems->where('pivot.default',TRUE))->count()) if (($x=$this->zone->systems->where('pivot.default',TRUE))->count())
return $x->first()->match($this->zone)->first(); return $x->first()->match($this->zone,255)->first();
else else
return NULL; return NULL;
// RC // RC
case DomainController::NODE_RC: case self::NODE_RC:
$parent = self::where('zone_id',$this->zone_id) $parent = self::where('zone_id',$this->zone_id)
->where('region_id',0) ->where('region_id',0)
->where('host_id',0) ->where('host_id',0)
@ -175,7 +186,7 @@ class Address extends Model
break; break;
// Hosts // Hosts
case DomainController::NODE_NC: case self::NODE_NC:
// See if we have a RC // See if we have a RC
$parent = self::where('zone_id',$this->zone_id) $parent = self::where('zone_id',$this->zone_id)
->where('region_id',$this->region_id) ->where('region_id',$this->region_id)
@ -195,9 +206,9 @@ class Address extends Model
break; break;
// Hubs // Hubs
case DomainController::NODE_HC: case self::NODE_HC:
// Normal Nodes // Normal Nodes
case DomainController::NODE_ACTIVE: case self::NODE_ACTIVE:
// If we are a child of a hub, then check our hub // If we are a child of a hub, then check our hub
$parent = (($this->hub_id) $parent = (($this->hub_id)
? self::where('id',$this->hub_id) ? self::where('id',$this->hub_id)
@ -209,9 +220,9 @@ class Address extends Model
break; break;
case DomainController::NODE_UNKNOWN: case self::NODE_UNKNOWN:
case DomainController::NODE_POINT: case self::NODE_POINT:
case DomainController::NODE_DOWN: case self::NODE_DOWN:
// @todo Points - if the boss is defined, we should return it. // @todo Points - if the boss is defined, we should return it.
return NULL; return NULL;
@ -262,17 +273,17 @@ class Address extends Model
public function getRoleNameAttribute(): string public function getRoleNameAttribute(): string
{ {
switch ($this->role) { switch ($this->role) {
case DomainController::NODE_ACTIVE: case self::NODE_ZC:
return 'NODE';
case DomainController::NODE_ZC:
return 'ZC'; return 'ZC';
case DomainController::NODE_RC: case self::NODE_RC:
return 'RC'; return 'RC';
case DomainController::NODE_NC: case self::NODE_NC:
return 'NC'; return 'NC';
case DomainController::NODE_HC: case self::NODE_HC:
return 'HUB'; return 'HUB';
case DomainController::NODE_POINT: case self::NODE_ACTIVE:
return 'NODE';
case self::NODE_POINT:
return 'POINT'; return 'POINT';
default: default:
return '?'; return '?';
@ -374,9 +385,11 @@ class Address extends Model
* @param bool $update * @param bool $update
* @return Packet|null * @return Packet|null
*/ */
public function getEchomail(bool $update=TRUE): ?Packet public function getEchomail(bool $update=TRUE,Collection $echomail=NULL): ?Packet
{ {
$pkt = NULL; $pkt = NULL;
if ($echomail)
return $this->getPacket($echomail);
if (($x=$this->echomailWaiting()) if (($x=$this->echomailWaiting())
->count()) ->count())

View File

@ -69,7 +69,7 @@ final class Echomail extends Model implements Packet
} }
// Our address // Our address
$ftns = Setup::findOrFail(config('app.id'))->system->match($model->fftn->zone); $ftns = Setup::findOrFail(config('app.id'))->system->match($model->fftn->zone,Address::NODE_ACTIVE|Address::NODE_PVT|Address::NODE_HOLD);
// Add our address to the seenby; // Add our address to the seenby;
$model->set_seenby = array_merge($model->set_seenby,$ftns->pluck('id')->toArray()); $model->set_seenby = array_merge($model->set_seenby,$ftns->pluck('id')->toArray());

View File

@ -7,8 +7,6 @@ use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Collection; use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\Auth;
use App\Http\Controllers\DomainController;
class System extends Model class System extends Model
{ {
use HasFactory; use HasFactory;
@ -103,17 +101,17 @@ class System extends Model
public function full_name(Address $o): string public function full_name(Address $o): string
{ {
switch ($o->attributes['role']) { switch ($o->attributes['role']) {
case DomainController::NODE_ZC; case Address::NODE_ZC;
return sprintf('ZC-%s-%05d',$o->zone->domain->name,$o->zone->zone_id); return sprintf('ZC-%s-%05d',$o->zone->domain->name,$o->zone->zone_id);
case DomainController::NODE_RC; case Address::NODE_RC;
return sprintf('RC-%s-%05d',$o->zone->domain->name,$o->region_id); return sprintf('RC-%s-%05d',$o->zone->domain->name,$o->region_id);
case DomainController::NODE_NC; case Address::NODE_NC;
return sprintf('NC-%s-%05d',$o->zone->domain->name,$o->host_id); return sprintf('NC-%s-%05d',$o->zone->domain->name,$o->host_id);
case DomainController::NODE_HC; case Address::NODE_HC;
case NULL: case Address::NODE_ACTIVE;
default: default:
return $this->name; return $this->name;
} }
@ -121,12 +119,18 @@ class System extends Model
/** /**
* Return the system's address in the same zone * Return the system's address in the same zone
* This function can filter based on the address type needed.
* *
* @param Zone $o * @param Zone $o
* @param int $type
* @return Collection * @return Collection
*/ */
public function match(Zone $o): Collection public function match(Zone $o,int $type=(Address::NODE_HC|Address::NODE_ACTIVE|Address::NODE_PVT|Address::NODE_POINT)): Collection
{ {
return $this->addresses->where('zone_id',$o->id); return $this->addresses
->where('zone_id',$o->id)
->filter(function($item) use ($type) {
return $item->role & $type;
});
} }
} }

View File

@ -0,0 +1,30 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class AddressRoleNotnull extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
\App\Models\Address::whereNull('role')->withTrashed()->update(['role'=>\App\Models\Address::NODE_ACTIVE]);
DB::commit();
DB::statement("ALTER TABLE addresses ALTER COLUMN role set NOT NULL");
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
DB::statement("ALTER TABLE addresses ALTER COLUMN role drop NOT NULL");
}
}

View File

@ -6,7 +6,6 @@ use Carbon\Carbon;
use Illuminate\Database\Seeder; use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\DB;
use App\Http\Controllers\DomainController;
use App\Models\{Address,Domain,System,Zone}; use App\Models\{Address,Domain,System,Zone};
class NodeHierarchy extends Seeder class NodeHierarchy extends Seeder
@ -73,7 +72,7 @@ class NodeHierarchy extends Seeder
'node_id'=>0, 'node_id'=>0,
'point_id'=>0, 'point_id'=>0,
'system_id'=>$so->id, 'system_id'=>$so->id,
'role'=>DomainController::NODE_ZC, 'role'=>Address::NODE_ZC,
'created_at'=>Carbon::now(), 'created_at'=>Carbon::now(),
'updated_at'=>Carbon::now(), 'updated_at'=>Carbon::now(),
]); ]);
@ -90,6 +89,7 @@ class NodeHierarchy extends Seeder
'node_id'=>$nid, 'node_id'=>$nid,
'point_id'=>0, 'point_id'=>0,
'system_id'=>$so->id, 'system_id'=>$so->id,
'role'=>Address::NODE_ACTIVE,
'created_at'=>Carbon::now(), 'created_at'=>Carbon::now(),
'updated_at'=>Carbon::now(), 'updated_at'=>Carbon::now(),
]); ]);
@ -107,7 +107,7 @@ class NodeHierarchy extends Seeder
'node_id'=>0, 'node_id'=>0,
'point_id'=>0, 'point_id'=>0,
'system_id'=>$so->id, 'system_id'=>$so->id,
'role'=>DomainController::NODE_RC, 'role'=>Address::NODE_RC,
'created_at'=>Carbon::now(), 'created_at'=>Carbon::now(),
'updated_at'=>Carbon::now(), 'updated_at'=>Carbon::now(),
]); ]);
@ -124,6 +124,7 @@ class NodeHierarchy extends Seeder
'node_id'=>$nid, 'node_id'=>$nid,
'point_id'=>0, 'point_id'=>0,
'system_id'=>$so->id, 'system_id'=>$so->id,
'role'=>Address::NODE_ACTIVE,
'created_at'=>Carbon::now(), 'created_at'=>Carbon::now(),
'updated_at'=>Carbon::now(), 'updated_at'=>Carbon::now(),
]); ]);
@ -142,7 +143,7 @@ class NodeHierarchy extends Seeder
'node_id'=>0, 'node_id'=>0,
'point_id'=>0, 'point_id'=>0,
'system_id'=>$so->id, 'system_id'=>$so->id,
'role'=>DomainController::NODE_NC, 'role'=>Address::NODE_NC,
'created_at'=>Carbon::now(), 'created_at'=>Carbon::now(),
'updated_at'=>Carbon::now(), 'updated_at'=>Carbon::now(),
]); ]);
@ -159,6 +160,7 @@ class NodeHierarchy extends Seeder
'node_id'=>$nid, 'node_id'=>$nid,
'point_id'=>0, 'point_id'=>0,
'system_id'=>$so->id, 'system_id'=>$so->id,
'role'=>Address::NODE_ACTIVE,
'created_at'=>Carbon::now(), 'created_at'=>Carbon::now(),
'updated_at'=>Carbon::now(), 'updated_at'=>Carbon::now(),
]); ]);
@ -175,7 +177,7 @@ class NodeHierarchy extends Seeder
$hub->node_id = $bid; $hub->node_id = $bid;
$hub->point_id = 0; $hub->point_id = 0;
$hub->system_id = $so->id; $hub->system_id = $so->id;
$hub->role = DomainController::NODE_HC; $hub->role = Address::NODE_HC;
$hub->created_at = Carbon::now(); $hub->created_at = Carbon::now();
$hub->updated_at = Carbon::now(); $hub->updated_at = Carbon::now();
$hub->save(); $hub->save();
@ -194,6 +196,7 @@ class NodeHierarchy extends Seeder
'point_id'=>0, 'point_id'=>0,
'system_id'=>$so->id, 'system_id'=>$so->id,
'hub_id'=>$hub->id, 'hub_id'=>$hub->id,
'role'=>Address::NODE_ACTIVE,
'created_at'=>Carbon::now(), 'created_at'=>Carbon::now(),
'updated_at'=>Carbon::now(), 'updated_at'=>Carbon::now(),
]); ]);

View File

@ -5,7 +5,7 @@
@endsection @endsection
@php @php
use App\Http\Controllers\DomainController as DC; use App\Models\Address as Address;
@endphp @endphp
@section('content') @section('content')
@ -117,7 +117,7 @@ use App\Http\Controllers\DomainController as DC;
@can('admin',$oo) @can('admin',$oo)
<a href="{{ url('ftn/system/susaddress',[$oo->id]) }}" title="@if($oo->active)Pause @else Activate @endif Address"><i class="bi @if($oo->active)bi-pause-circle-fill @else bi-play-circle-fill @endif"></i></a> <a href="{{ url('ftn/system/susaddress',[$oo->id]) }}" title="@if($oo->active)Pause @else Activate @endif Address"><i class="bi @if($oo->active)bi-pause-circle-fill @else bi-play-circle-fill @endif"></i></a>
{{-- {{--
@if (! $oo->role & (DC::NODE_ZC|DC::NODE_RC|DC::NODE_NC)) @if (! $oo->role & (Address::NODE_ZC|Address::NODE_RC|Address::NODE_NC))
<a href="{{ url('ftn/system/modaddress',[$oo->id]) }}" title="Modify Address" class="modify"><i class="bi bi-pen-fill"></i></a> <a href="{{ url('ftn/system/modaddress',[$oo->id]) }}" title="Modify Address" class="modify"><i class="bi bi-pen-fill"></i></a>
@endif @endif
--}} --}}

View File

@ -28,9 +28,9 @@ class PacketTest extends TestCase
Zone::unguard(); Zone::unguard();
Address::unguard(); Address::unguard();
$zo = Zone::firstOrCreate(['zone_id'=>21,'default'=>TRUE,'active'=>TRUE,'domain_id'=>$this->do->id,'system_id'=>$this->so->id]); $zo = Zone::firstOrCreate(['zone_id'=>21,'default'=>TRUE,'active'=>TRUE,'domain_id'=>$this->do->id,'system_id'=>$this->so->id]);
$src = Address::firstOrCreate(['zone_id'=>$zo->id,'region_id'=>0,'host_id'=>3,'node_id'=>151,'point_id'=>0,'active'=>TRUE,'system_id'=>$this->so->id]); $src = Address::firstOrCreate(['zone_id'=>$zo->id,'region_id'=>0,'host_id'=>3,'node_id'=>151,'point_id'=>0,'role'=>Address::NODE_ACTIVE,'active'=>TRUE,'system_id'=>$this->so->id]);
$hub = Address::firstOrCreate(['zone_id'=>$zo->id,'region_id'=>0,'host_id'=>1,'node_id'=>1,'point_id'=>0,'active'=>TRUE,'system_id'=>$this->so->id]); $hub = Address::firstOrCreate(['zone_id'=>$zo->id,'region_id'=>0,'host_id'=>1,'node_id'=>1,'point_id'=>0,'role'=>Address::NODE_ACTIVE,'active'=>TRUE,'system_id'=>$this->so->id]);
$ao = Address::firstOrCreate(['zone_id'=>$zo->id,'region_id'=>0,'host_id'=>1,'node_id'=>4,'point_id'=>0,'active'=>TRUE,'system_id'=>$this->so->id]); $ao = Address::firstOrCreate(['zone_id'=>$zo->id,'region_id'=>0,'host_id'=>1,'node_id'=>4,'point_id'=>0,'role'=>Address::NODE_ACTIVE,'active'=>TRUE,'system_id'=>$this->so->id]);
// This packet has an incorrect zone in the Origin // This packet has an incorrect zone in the Origin
$f = new File(__DIR__.'/data/test_nomsgid_origin.pkt'); $f = new File(__DIR__.'/data/test_nomsgid_origin.pkt');
@ -63,7 +63,7 @@ class PacketTest extends TestCase
Zone::unguard(); Zone::unguard();
Address::unguard(); Address::unguard();
$zo = Zone::firstOrCreate(['zone_id'=>10,'default'=>TRUE,'active'=>TRUE,'domain_id'=>$this->do->id,'system_id'=>$this->so->id]); $zo = Zone::firstOrCreate(['zone_id'=>10,'default'=>TRUE,'active'=>TRUE,'domain_id'=>$this->do->id,'system_id'=>$this->so->id]);
$src = Address::firstOrCreate(['zone_id'=>$zo->id,'region_id'=>0,'host_id'=>999,'node_id'=>1,'point_id'=>0,'active'=>TRUE,'system_id'=>$this->so->id]); $src = Address::firstOrCreate(['zone_id'=>$zo->id,'region_id'=>0,'host_id'=>999,'node_id'=>1,'point_id'=>0,'role'=>Address::NODE_ACTIVE,'active'=>TRUE,'system_id'=>$this->so->id]);
// This packet has an incorrect zone in the Origin // This packet has an incorrect zone in the Origin
$f = new File(__DIR__.'/data/test_nomsgid_noorigin.pkt'); $f = new File(__DIR__.'/data/test_nomsgid_noorigin.pkt');
@ -92,7 +92,7 @@ class PacketTest extends TestCase
Zone::unguard(); Zone::unguard();
Address::unguard(); Address::unguard();
$zo = Zone::firstOrCreate(['zone_id'=>10,'default'=>TRUE,'active'=>TRUE,'domain_id'=>$this->do->id,'system_id'=>$this->so->id]); $zo = Zone::firstOrCreate(['zone_id'=>10,'default'=>TRUE,'active'=>TRUE,'domain_id'=>$this->do->id,'system_id'=>$this->so->id]);
$src = Address::firstOrCreate(['zone_id'=>$zo->id,'region_id'=>0,'host_id'=>999,'node_id'=>1,'point_id'=>0,'active'=>TRUE,'system_id'=>$this->so->id]); $src = Address::firstOrCreate(['zone_id'=>$zo->id,'region_id'=>0,'host_id'=>999,'node_id'=>1,'point_id'=>0,'role'=>Address::NODE_ACTIVE,'active'=>TRUE,'system_id'=>$this->so->id]);
// This packet has an incorrect zone in the Origin // This packet has an incorrect zone in the Origin
$f = new File(__DIR__.'/data/test_msgid_origin.pkt'); $f = new File(__DIR__.'/data/test_msgid_origin.pkt');

View File

@ -2,14 +2,11 @@
namespace Tests\Feature; namespace Tests\Feature;
use App\Http\Controllers\DomainController;
use App\Models\Address;
use Database\Seeders\NodeHierarchy;
use Illuminate\Database\Eloquent\Collection; use Illuminate\Database\Eloquent\Collection;
use Illuminate\Foundation\Testing\DatabaseTransactions; use Illuminate\Foundation\Testing\DatabaseTransactions;
use Tests\TestCase; use Tests\TestCase;
use App\Models\Domain; use App\Models\{Address,Domain};
class RoutingTest extends TestCase class RoutingTest extends TestCase
{ {
@ -36,7 +33,7 @@ class RoutingTest extends TestCase
// Pick ZC without any session info - we have 0 children // Pick ZC without any session info - we have 0 children
$ao = Address::findFTN('100:0/0@domain-a'); $ao = Address::findFTN('100:0/0@domain-a');
$this->assertEquals($ao->role,DomainController::NODE_ZC); $this->assertEquals($ao->role,Address::NODE_ZC);
$this->assertCount(0,$ao->children); $this->assertCount(0,$ao->children);
$this->assertNull($ao->parent()); $this->assertNull($ao->parent());
@ -47,15 +44,15 @@ class RoutingTest extends TestCase
// A node's parent should be the ZC // A node's parent should be the ZC
$ao = Address::findFTN('100:10/0@domain-a'); $ao = Address::findFTN('100:10/0@domain-a');
$this->assertEquals($ao->role,DomainController::NODE_NC); $this->assertEquals($ao->role,Address::NODE_NC);
$this->assertEquals('100:0/0.0@domain-a',$ao->parent()->ftn); $this->assertEquals('100:0/0.0@domain-a',$ao->parent()->ftn);
$ao = Address::findFTN('100:21/2001.0@domain-a'); $ao = Address::findFTN('100:21/2001.0@domain-a');
$this->assertEquals($ao->role,DomainController::NODE_ACTIVE); $this->assertEquals($ao->role,Address::NODE_ACTIVE);
$this->assertEquals('100:0/0.0@domain-a',$ao->parent()->ftn); $this->assertEquals('100:0/0.0@domain-a',$ao->parent()->ftn);
// Pick a NC and we have 10 less children // Pick a NC and we have 10 less children
$ao = Address::findFTN('100:10/0@domain-a'); $ao = Address::findFTN('100:10/0@domain-a');
$this->assertEquals($ao->role,DomainController::NODE_NC); $this->assertEquals($ao->role,Address::NODE_NC);
$ao->system->sessions()->attach([$ao->zone_id=>['sespass'=>'ABCD']]); $ao->system->sessions()->attach([$ao->zone_id=>['sespass'=>'ABCD']]);
$ao = Address::findFTN('100:10/0@domain-a'); $ao = Address::findFTN('100:10/0@domain-a');
$this->assertCount(9,$ao->children); $this->assertCount(9,$ao->children);
@ -64,15 +61,15 @@ class RoutingTest extends TestCase
// A node's parent should be the ZC // A node's parent should be the ZC
$ao = Address::findFTN('100:20/0@domain-a'); $ao = Address::findFTN('100:20/0@domain-a');
$this->assertEquals($ao->role,DomainController::NODE_NC); $this->assertEquals($ao->role,Address::NODE_NC);
$this->assertEquals('100:0/0.0@domain-a',$ao->parent()->ftn); $this->assertEquals('100:0/0.0@domain-a',$ao->parent()->ftn);
$ao = Address::findFTN('100:10/2001.0@domain-a'); $ao = Address::findFTN('100:10/2001.0@domain-a');
$this->assertEquals($ao->role,DomainController::NODE_ACTIVE); $this->assertEquals($ao->role,Address::NODE_ACTIVE);
$this->assertEquals('100:10/0.0@domain-a',$ao->parent()->ftn); $this->assertEquals('100:10/0.0@domain-a',$ao->parent()->ftn);
// Pick a Node and we have 1 less child // Pick a Node and we have 1 less child
$ao = Address::findFTN('100:21/2001.0@domain-a'); $ao = Address::findFTN('100:21/2001.0@domain-a');
$this->assertEquals($ao->role,DomainController::NODE_ACTIVE); $this->assertEquals($ao->role,Address::NODE_ACTIVE);
$ao->system->sessions()->attach([$ao->zone_id=>['sespass'=>'ABCD']]); $ao->system->sessions()->attach([$ao->zone_id=>['sespass'=>'ABCD']]);
$ao = Address::findFTN('100:21/2001.0@domain-a'); $ao = Address::findFTN('100:21/2001.0@domain-a');
$this->assertNULL($ao->children); $this->assertNULL($ao->children);
@ -81,7 +78,7 @@ class RoutingTest extends TestCase
// Define address on a HC and we have 3 less children // Define address on a HC and we have 3 less children
$ao = Address::findFTN('100:21/1000.0@domain-a'); $ao = Address::findFTN('100:21/1000.0@domain-a');
$this->assertEquals($ao->role,DomainController::NODE_HC); $this->assertEquals($ao->role,Address::NODE_HC);
$ao->system->sessions()->attach([$ao->zone_id=>['sespass'=>'ABCD']]); $ao->system->sessions()->attach([$ao->zone_id=>['sespass'=>'ABCD']]);
$ao = Address::findFTN('100:21/1000.0@domain-a'); $ao = Address::findFTN('100:21/1000.0@domain-a');
$this->assertCount(2,$ao->children); $this->assertCount(2,$ao->children);
@ -90,7 +87,7 @@ class RoutingTest extends TestCase
// Define address on a NC and we have 10 less children // Define address on a NC and we have 10 less children
$ao = Address::findFTN('100:20/0@domain-a'); $ao = Address::findFTN('100:20/0@domain-a');
$this->assertEquals($ao->role,DomainController::NODE_NC); $this->assertEquals($ao->role,Address::NODE_NC);
$ao->system->sessions()->attach([$ao->zone_id=>['sespass'=>'ABCD']]); $ao->system->sessions()->attach([$ao->zone_id=>['sespass'=>'ABCD']]);
$ao = Address::findFTN('100:0/0@domain-a'); $ao = Address::findFTN('100:0/0@domain-a');
$this->assertCount(27,$ao->children); $this->assertCount(27,$ao->children);
@ -107,7 +104,7 @@ class RoutingTest extends TestCase
// Pick ZC without any session info - we have 0 children // Pick ZC without any session info - we have 0 children
$ao = Address::findFTN('100:1/0@domain-a'); $ao = Address::findFTN('100:1/0@domain-a');
$this->assertEquals($ao->role,DomainController::NODE_RC); $this->assertEquals($ao->role,Address::NODE_RC);
$this->assertCount(0,$ao->children); $this->assertCount(0,$ao->children);
// Add session info, and we have 51 children // Add session info, and we have 51 children
@ -117,7 +114,7 @@ class RoutingTest extends TestCase
// Pick a NC and we have 10 less children // Pick a NC and we have 10 less children
$ao = Address::findFTN('100:10/0@domain-a'); $ao = Address::findFTN('100:10/0@domain-a');
$this->assertEquals($ao->role,DomainController::NODE_NC); $this->assertEquals($ao->role,Address::NODE_NC);
$ao->system->sessions()->attach([$ao->zone_id=>['sespass'=>'ABCD']]); $ao->system->sessions()->attach([$ao->zone_id=>['sespass'=>'ABCD']]);
$ao = Address::findFTN('100:10/0@domain-a'); $ao = Address::findFTN('100:10/0@domain-a');
$this->assertCount(9,$ao->children); $this->assertCount(9,$ao->children);
@ -126,7 +123,7 @@ class RoutingTest extends TestCase
// Pick a Node and we have 1 less child // Pick a Node and we have 1 less child
$ao = Address::findFTN('100:11/2001.0@domain-a'); $ao = Address::findFTN('100:11/2001.0@domain-a');
$this->assertEquals($ao->role,DomainController::NODE_ACTIVE); $this->assertEquals($ao->role,Address::NODE_ACTIVE);
$ao->system->sessions()->attach([$ao->zone_id=>['sespass'=>'ABCD']]); $ao->system->sessions()->attach([$ao->zone_id=>['sespass'=>'ABCD']]);
$ao = Address::findFTN('100:11/2001.0@domain-a'); $ao = Address::findFTN('100:11/2001.0@domain-a');
$this->assertNULL($ao->children); $this->assertNULL($ao->children);
@ -135,7 +132,7 @@ class RoutingTest extends TestCase
// Define address on a HC and we have 3 less children // Define address on a HC and we have 3 less children
$ao = Address::findFTN('100:11/1000.0@domain-a'); $ao = Address::findFTN('100:11/1000.0@domain-a');
$this->assertEquals($ao->role,DomainController::NODE_HC); $this->assertEquals($ao->role,Address::NODE_HC);
$ao->system->sessions()->attach([$ao->zone_id=>['sespass'=>'ABCD']]); $ao->system->sessions()->attach([$ao->zone_id=>['sespass'=>'ABCD']]);
$ao = Address::findFTN('100:11/1000.0@domain-a'); $ao = Address::findFTN('100:11/1000.0@domain-a');
$this->assertCount(2,$ao->children); $this->assertCount(2,$ao->children);
@ -154,7 +151,7 @@ class RoutingTest extends TestCase
// Pick a HC without any session info - we have 0 children // Pick a HC without any session info - we have 0 children
$ao = Address::findFTN('100:20/0@domain-a'); $ao = Address::findFTN('100:20/0@domain-a');
$this->assertEquals($ao->role,DomainController::NODE_NC); $this->assertEquals($ao->role,Address::NODE_NC);
$this->assertCount(0,$ao->children); $this->assertCount(0,$ao->children);
// Add session info, we have 10 children // Add session info, we have 10 children
@ -164,14 +161,14 @@ class RoutingTest extends TestCase
// Add session info to a hub, we have 3 less children // Add session info to a hub, we have 3 less children
$ao = Address::findFTN('100:20/2000@domain-a'); $ao = Address::findFTN('100:20/2000@domain-a');
$this->assertEquals($ao->role,DomainController::NODE_HC); $this->assertEquals($ao->role,Address::NODE_HC);
$ao->system->sessions()->attach([$ao->zone_id=>['sespass'=>'ABCD']]); $ao->system->sessions()->attach([$ao->zone_id=>['sespass'=>'ABCD']]);
$ao = Address::findFTN('100:20/0@domain-a'); $ao = Address::findFTN('100:20/0@domain-a');
$this->assertCount(6,$ao->children); $this->assertCount(6,$ao->children);
// Add session info to a node, we have 1 less child // Add session info to a node, we have 1 less child
$ao = Address::findFTN('100:20/1@domain-a'); $ao = Address::findFTN('100:20/1@domain-a');
$this->assertEquals($ao->role,DomainController::NODE_ACTIVE); $this->assertEquals($ao->role,Address::NODE_ACTIVE);
$ao->system->sessions()->attach([$ao->zone_id=>['sespass'=>'ABCD']]); $ao->system->sessions()->attach([$ao->zone_id=>['sespass'=>'ABCD']]);
$ao = Address::findFTN('100:20/0@domain-a'); $ao = Address::findFTN('100:20/0@domain-a');
$this->assertCount(5,$ao->children); $this->assertCount(5,$ao->children);
@ -188,7 +185,7 @@ class RoutingTest extends TestCase
// Pick a HC without any session info - we have 0 children // Pick a HC without any session info - we have 0 children
$ao = Address::findFTN('100:20/2000@domain-a'); $ao = Address::findFTN('100:20/2000@domain-a');
$this->assertEquals($ao->role,DomainController::NODE_HC); $this->assertEquals($ao->role,Address::NODE_HC);
$this->assertCount(0,$ao->children); $this->assertCount(0,$ao->children);
// Add session info, we have 2 children // Add session info, we have 2 children
@ -209,7 +206,7 @@ class RoutingTest extends TestCase
// Node with session details still doesnt have any children // Node with session details still doesnt have any children
$ao = Address::findFTN('100:20/2001@domain-a'); $ao = Address::findFTN('100:20/2001@domain-a');
$this->assertEquals($ao->role,DomainController::NODE_ACTIVE); $this->assertEquals($ao->role,Address::NODE_ACTIVE);
$ao->system->sessions()->attach([$ao->zone_id=>['sespass'=>'ABCD']]); $ao->system->sessions()->attach([$ao->zone_id=>['sespass'=>'ABCD']]);
$ao = Address::findFTN('100:20/2001@domain-a'); $ao = Address::findFTN('100:20/2001@domain-a');
$this->assertNULL($ao->children); $this->assertNULL($ao->children);