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:
@@ -28,6 +28,17 @@ class Address extends Model
|
||||
|
||||
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 */
|
||||
|
||||
public function scopeFTNOrder($query)
|
||||
@@ -52,20 +63,20 @@ class Address extends Model
|
||||
|
||||
if (! $this->session('default')) {
|
||||
switch ($this->role) {
|
||||
case DomainController::NODE_ZC:
|
||||
case self::NODE_ZC:
|
||||
$children = self::select('addresses.*')
|
||||
->where('zone_id',$this->zone_id);
|
||||
|
||||
break;
|
||||
|
||||
case DomainController::NODE_RC:
|
||||
case self::NODE_RC:
|
||||
$children = self::select('addresses.*')
|
||||
->where('zone_id',$this->zone_id)
|
||||
->where('region_id',$this->region_id);
|
||||
|
||||
break;
|
||||
|
||||
case DomainController::NODE_NC:
|
||||
case self::NODE_NC:
|
||||
$children = self::select('addresses.*')
|
||||
->where('zone_id',$this->zone_id)
|
||||
->where('region_id',$this->region_id)
|
||||
@@ -73,16 +84,16 @@ class Address extends Model
|
||||
|
||||
break;
|
||||
|
||||
case DomainController::NODE_HC:
|
||||
case self::NODE_HC:
|
||||
// Identify our children.
|
||||
$children = self::select('addresses.*')
|
||||
->where('hub_id',$this->id);
|
||||
|
||||
break;
|
||||
|
||||
case DomainController::NODE_UNKNOWN:
|
||||
case DomainController::NODE_ACTIVE:
|
||||
case DomainController::NODE_POINT:
|
||||
case self::NODE_UNKNOWN:
|
||||
case self::NODE_ACTIVE:
|
||||
case self::NODE_POINT:
|
||||
// Nodes dont have children, but must return a relationship instance
|
||||
return $this->hasOne(self::class,NULL,'void');
|
||||
|
||||
@@ -158,14 +169,14 @@ class Address extends Model
|
||||
|
||||
switch ($this->role) {
|
||||
// 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())
|
||||
return $x->first()->match($this->zone)->first();
|
||||
return $x->first()->match($this->zone,255)->first();
|
||||
else
|
||||
return NULL;
|
||||
|
||||
// RC
|
||||
case DomainController::NODE_RC:
|
||||
case self::NODE_RC:
|
||||
$parent = self::where('zone_id',$this->zone_id)
|
||||
->where('region_id',0)
|
||||
->where('host_id',0)
|
||||
@@ -175,7 +186,7 @@ class Address extends Model
|
||||
break;
|
||||
|
||||
// Hosts
|
||||
case DomainController::NODE_NC:
|
||||
case self::NODE_NC:
|
||||
// See if we have a RC
|
||||
$parent = self::where('zone_id',$this->zone_id)
|
||||
->where('region_id',$this->region_id)
|
||||
@@ -195,9 +206,9 @@ class Address extends Model
|
||||
break;
|
||||
|
||||
// Hubs
|
||||
case DomainController::NODE_HC:
|
||||
case self::NODE_HC:
|
||||
// Normal Nodes
|
||||
case DomainController::NODE_ACTIVE:
|
||||
case self::NODE_ACTIVE:
|
||||
// If we are a child of a hub, then check our hub
|
||||
$parent = (($this->hub_id)
|
||||
? self::where('id',$this->hub_id)
|
||||
@@ -209,9 +220,9 @@ class Address extends Model
|
||||
|
||||
break;
|
||||
|
||||
case DomainController::NODE_UNKNOWN:
|
||||
case DomainController::NODE_POINT:
|
||||
case DomainController::NODE_DOWN:
|
||||
case self::NODE_UNKNOWN:
|
||||
case self::NODE_POINT:
|
||||
case self::NODE_DOWN:
|
||||
// @todo Points - if the boss is defined, we should return it.
|
||||
return NULL;
|
||||
|
||||
@@ -262,17 +273,17 @@ class Address extends Model
|
||||
public function getRoleNameAttribute(): string
|
||||
{
|
||||
switch ($this->role) {
|
||||
case DomainController::NODE_ACTIVE:
|
||||
return 'NODE';
|
||||
case DomainController::NODE_ZC:
|
||||
case self::NODE_ZC:
|
||||
return 'ZC';
|
||||
case DomainController::NODE_RC:
|
||||
case self::NODE_RC:
|
||||
return 'RC';
|
||||
case DomainController::NODE_NC:
|
||||
case self::NODE_NC:
|
||||
return 'NC';
|
||||
case DomainController::NODE_HC:
|
||||
case self::NODE_HC:
|
||||
return 'HUB';
|
||||
case DomainController::NODE_POINT:
|
||||
case self::NODE_ACTIVE:
|
||||
return 'NODE';
|
||||
case self::NODE_POINT:
|
||||
return 'POINT';
|
||||
default:
|
||||
return '?';
|
||||
@@ -374,9 +385,11 @@ class Address extends Model
|
||||
* @param bool $update
|
||||
* @return Packet|null
|
||||
*/
|
||||
public function getEchomail(bool $update=TRUE): ?Packet
|
||||
public function getEchomail(bool $update=TRUE,Collection $echomail=NULL): ?Packet
|
||||
{
|
||||
$pkt = NULL;
|
||||
if ($echomail)
|
||||
return $this->getPacket($echomail);
|
||||
|
||||
if (($x=$this->echomailWaiting())
|
||||
->count())
|
||||
|
@@ -69,7 +69,7 @@ final class Echomail extends Model implements Packet
|
||||
}
|
||||
|
||||
// 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;
|
||||
$model->set_seenby = array_merge($model->set_seenby,$ftns->pluck('id')->toArray());
|
||||
|
@@ -7,8 +7,6 @@ use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
use App\Http\Controllers\DomainController;
|
||||
|
||||
class System extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
@@ -103,17 +101,17 @@ class System extends Model
|
||||
public function full_name(Address $o): string
|
||||
{
|
||||
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);
|
||||
|
||||
case DomainController::NODE_RC;
|
||||
case Address::NODE_RC;
|
||||
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);
|
||||
|
||||
case DomainController::NODE_HC;
|
||||
case NULL:
|
||||
case Address::NODE_HC;
|
||||
case Address::NODE_ACTIVE;
|
||||
default:
|
||||
return $this->name;
|
||||
}
|
||||
@@ -121,12 +119,18 @@ class System extends Model
|
||||
|
||||
/**
|
||||
* Return the system's address in the same zone
|
||||
* This function can filter based on the address type needed.
|
||||
*
|
||||
* @param Zone $o
|
||||
* @param int $type
|
||||
* @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;
|
||||
});
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user