Enabled akas() method to only show current active akas. Should fix the link register netmail from polling an invalid FTN id.

This commit is contained in:
Deon George 2023-06-23 21:28:29 +10:00
parent b8534d8598
commit fdbc58856b
8 changed files with 52 additions and 26 deletions

View File

@ -596,7 +596,7 @@ class SystemController extends Controller
$ca = NULL; $ca = NULL;
$la = NULL; $la = NULL;
foreach ($s->addresses as $ao) { foreach ($s->akas as $ao) {
if (($ca=$so->match($ao->zone))->count()) if (($ca=$so->match($ao->zone))->count())
break; break;
} }

View File

@ -61,6 +61,18 @@ class Address extends Model
/* SCOPES */ /* SCOPES */
public function scopeActive($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')
->FTNorder();
}
public function scopeFTNOrder($query) public function scopeFTNOrder($query)
{ {
return $query return $query
@ -293,6 +305,17 @@ class Address extends Model
/* ATTRIBUTES */ /* ATTRIBUTES */
/**
* Return if this address is active
*
* @param bool $value
* @return bool
*/
public function getActiveAttribute(bool $value): bool
{
return $value && $this->zone->active && $this->zone->domain->active;
}
/** /**
* Render the node name in full 5D * Render the node name in full 5D
* *
@ -356,7 +379,6 @@ class Address extends Model
// Are we looking for a region address // Are we looking for a region address
if (($ftn['f'] === 0) && $ftn['p'] === 0) { if (($ftn['f'] === 0) && $ftn['p'] === 0) {
$o = (new self)->active() $o = (new self)->active()
->select('addresses.*')
->where('zones.zone_id',$ftn['z']) ->where('zones.zone_id',$ftn['z'])
->where(function($q) use ($ftn) { ->where(function($q) use ($ftn) {
return $q return $q
@ -367,11 +389,6 @@ class Address extends Model
}) })
->where('node_id',$ftn['f']) ->where('node_id',$ftn['f'])
->where('point_id',$ftn['p']) ->where('point_id',$ftn['p'])
->join('zones',['zones.id'=>'addresses.zone_id'])
->join('domains',['domains.id'=>'zones.domain_id'])
->where('zones.active',TRUE)
->where('domains.active',TRUE)
->where('addresses.active',TRUE)
->when($ftn['d'],function($query,$domain) { ->when($ftn['d'],function($query,$domain) {
$query->where('domains.name',$domain); $query->where('domains.name',$domain);
}) })
@ -385,7 +402,6 @@ class Address extends Model
} }
$o = (new self)->active() $o = (new self)->active()
->select('addresses.*')
->where('zones.zone_id',$ftn['z']) ->where('zones.zone_id',$ftn['z'])
->where(function($q) use ($ftn) { ->where(function($q) use ($ftn) {
return $q->where(function($qq) use ($ftn) { return $q->where(function($qq) use ($ftn) {
@ -400,11 +416,6 @@ class Address extends Model
}) })
->where('node_id',$ftn['f']) ->where('node_id',$ftn['f'])
->where('point_id',$ftn['p']) ->where('point_id',$ftn['p'])
->join('zones',['zones.id'=>'addresses.zone_id'])
->join('domains',['domains.id'=>'zones.domain_id'])
->where('zones.active',TRUE)
->where('domains.active',TRUE)
->where('addresses.active',TRUE)
->when($ftn['d'],function($query,$domain) { ->when($ftn['d'],function($query,$domain) {
$query->where('domains.name',$domain); $query->where('domains.name',$domain);
}) })

View File

@ -59,6 +59,8 @@ final class Netmail extends Model implements Packet
static::created(function($model) { static::created(function($model) {
// Save the Path // Save the Path
$ppoid = NULL; $ppoid = NULL;
if (isset($model->set_path))
foreach ($model->set_path as $path) { foreach ($model->set_path as $path) {
$po = DB::select('INSERT INTO netmail_path (netmail_id,address_id,parent_id,datetime,program) VALUES (?,?,?,?,?) RETURNING id',[ $po = DB::select('INSERT INTO netmail_path (netmail_id,address_id,parent_id,datetime,program) VALUES (?,?,?,?,?) RETURNING id',[
$model->id, $model->id,

View File

@ -40,6 +40,12 @@ class System extends Model
->FTNorder(); ->FTNorder();
} }
public function akas()
{
return $this->hasMany(Address::class)
->active();
}
public function logs() public function logs()
{ {
return $this->hasMany(SystemLog::class); return $this->hasMany(SystemLog::class);

View File

@ -819,6 +819,10 @@ a.link:focus:after {
color: #0c0c0c; color: #0c0c0c;
} }
.inactive {
color: #3f6982;
}
.trashed { .trashed {
text-decoration: line-through; text-decoration: line-through;
color: #3f6982; color: #3f6982;

View File

@ -24,7 +24,7 @@
@foreach ($user->systems as $o) @foreach ($user->systems as $o)
<tr> <tr>
<th><a href="{{ url('ftn/system/addedit',[$o->id]) }}">{{ $o->name }}</a></th> <th><a href="{{ url('ftn/system/addedit',[$o->id]) }}">{{ $o->name }}</a></th>
<th class="text-end">{!! $o->addresses->pluck('ftn')->join('<br>') !!}</th> <th class="text-end">{!! $o->akas->pluck('ftn')->join('<br>') !!}</th>
</tr> </tr>
@endforeach @endforeach
</tbody> </tbody>

View File

@ -107,7 +107,7 @@
<tbody> <tbody>
@foreach ($o->addresses->sortBy(function($item) { return sprintf('%04x%04x%04x%04x%04x',$item->zone->zone_id,$item->region_id,$item->host_id,$item->node_id,$item->point_id); }) as $oo) @foreach ($o->addresses->sortBy(function($item) { return sprintf('%04x%04x%04x%04x%04x',$item->zone->zone_id,$item->region_id,$item->host_id,$item->node_id,$item->point_id); }) as $oo)
<tr> <tr>
<td @if($oo->trashed()) class="trashed" @endif>{{ $oo->ftn }}</td> <td @if($oo->trashed()) class="trashed" @elseif (! $oo->active) class="inactive" @endif>{{ $oo->ftn }}</td>
<td>{{ $oo->active ? 'YES' : 'NO' }}</td> <td>{{ $oo->active ? 'YES' : 'NO' }}</td>
<td>{{ $oo->role_name }}</td> <td>{{ $oo->role_name }}</td>
<td class="nowrap actions"> <td class="nowrap actions">
@ -120,6 +120,9 @@
@if($oo->trashed()) @if($oo->trashed())
<a href="{{ url('ftn/system/recaddress',[$oo->id]) }}" title="Restore Address"><i class="bi bi-bandaid-fill"></i></a> <a href="{{ url('ftn/system/recaddress',[$oo->id]) }}" title="Restore Address"><i class="bi bi-bandaid-fill"></i></a>
<a href="{{ url('ftn/system/puraddress',[$oo->id]) }}" title="Purge Address" class="purge"><i class="bi bi-scissors"></i></a> <a href="{{ url('ftn/system/puraddress',[$oo->id]) }}" title="Purge Address" class="purge"><i class="bi bi-scissors"></i></a>
@elseif(! $oo->active)
<!-- No options -->
<a href="javascript:;" title="Net Disabled"><i class="bi bi-slash-square"></i></a>
@else @else
<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>
<a href="{{ url('ftn/system/movaddress',[$o->id,$oo->id]) }}" title="Move Address to another System"><i class="bi bi-arrow-right-square-fill"></i></a> <a href="{{ url('ftn/system/movaddress',[$o->id,$oo->id]) }}" title="Move Address to another System"><i class="bi bi-arrow-right-square-fill"></i></a>

View File

@ -15,7 +15,7 @@
</tr> </tr>
<tr> <tr>
<th>Networks</th> <th>Networks</th>
<th>{{ $o->addresses->pluck('ftn')->join(', ') }}</th> <th>{{ $o->akas->pluck('ftn')->join(', ') }}</th>
</tr> </tr>
<tr> <tr>
<th>Address</th> <th>Address</th>