diff --git a/app/Classes/Dynamic/HubStats.php b/app/Classes/Dynamic/HubStats.php index e829fa1..1a22961 100644 --- a/app/Classes/Dynamic/HubStats.php +++ b/app/Classes/Dynamic/HubStats.php @@ -100,7 +100,7 @@ class HubStats extends Dynamic $o->uncollected_echomail ?? 0, $o->uncollected_netmail ?? 0, $o->uncollected_files ?? 0, - $o->system->last_session?->format('Y-m-d H:i'), + $o->system->last_seen?->format('Y-m-d H:i') ?: '-', is_null($o->system->pollmode) ? 'HOLD' : ($o->system->pollmode ? 'CRASH' : 'DAILY'), $o->system->autohold ? 'YES' : 'NO'); } diff --git a/app/Classes/Protocol/Binkp.php b/app/Classes/Protocol/Binkp.php index c6fffec..f4dbbf0 100644 --- a/app/Classes/Protocol/Binkp.php +++ b/app/Classes/Protocol/Binkp.php @@ -1278,9 +1278,13 @@ final class Binkp extends BaseProtocol } } - if ($this->optionGet(self::O_PWD)) + if ($this->optionGet(self::O_PWD)) { Log::info(sprintf('%s:- SECURE',self::LOGKEY)); + // @todo Since we have connected, if the node was marked down/hold reset that + // Notification::route('netmail',$ao->system->uncommon()->first()->withoutRelations())->notify(new NodeMarkedDownNetmail($ao->withoutRelations())); + } + return $this->binkp_hsdone(); } @@ -1376,6 +1380,9 @@ final class Binkp extends BaseProtocol if ($this->node->aka_authed) { $this->msgs(self::BPM_OK,sprintf('%ssecure',$have_pwd ? '' : 'non-')); + // @todo Since we have connected, if the node was marked down/hold reset that + // Notification::route('netmail',$ao->system->uncommon()->first()->withoutRelations())->notify(new NodeMarkedDownNetmail($ao->withoutRelations())); + } else { $this->msgs(self::OK,'non-secure'); } diff --git a/app/Classes/Protocol/EMSI.php b/app/Classes/Protocol/EMSI.php index 7d551ad..afcc42c 100644 --- a/app/Classes/Protocol/EMSI.php +++ b/app/Classes/Protocol/EMSI.php @@ -1061,6 +1061,9 @@ final class EMSI extends BaseProtocol implements CRCInterface,ZmodemInterface return (self::S_REDIAL|self::S_ADDTRY); } + // @todo Since we have connected, if the node was marked down/hold reset that + // Notification::route('netmail',$ao->system->uncommon()->first()->withoutRelations())->notify(new NodeMarkedDownNetmail($ao->withoutRelations())); + // @todo Lock Node AKAs Log::info(sprintf('%s:- We have [%lu%s] mail, [%lu%s] files',self::LOGKEY,$this->send->mail_size,'b',$this->send->files_size,'b')); diff --git a/app/Jobs/AddressIdle.php b/app/Jobs/AddressIdle.php index 9f8b80f..c57f54e 100644 --- a/app/Jobs/AddressIdle.php +++ b/app/Jobs/AddressIdle.php @@ -51,7 +51,7 @@ class AddressIdle implements ShouldQueue // Delist DOWN nodes foreach ($this->old($this->do,config('fido.idle.delist'),Address::NODE_DOWN,$this->ao) as $ao) { // Only delist system that has been marked down - // Only mark delist them if its been 14 days since they were marked DOWN + // Only delist them if its been 14 days since they were marked DOWN if ((! $ao->is_down) || ($ao->updated_at->greaterThan(Carbon::now()->subWeeks(2)))) continue; @@ -106,6 +106,11 @@ class AddressIdle implements ShouldQueue // Mark nodes DOWN foreach ($this->old($this->do,config('fido.idle.down'),Address::NODE_HOLD,$this->ao) as $ao) { + // Only mark down system that has been marked down + // Only mark down them if its been 14 days since they were marked HOLD + if ((! $ao->is_hold) || ($ao->updated_at->greaterThan(Carbon::now()->subWeeks(2)))) + continue; + Log::info(sprintf('%s:- Marking [%s] as DOWN, not seen for [%d] days',self::LOGKEY,$ao->ftn,config('fido.idle.down'))); $contact = FALSE; diff --git a/app/Jobs/SystemHeartbeat.php b/app/Jobs/SystemHeartbeat.php index fe1f422..ce5955e 100644 --- a/app/Jobs/SystemHeartbeat.php +++ b/app/Jobs/SystemHeartbeat.php @@ -60,15 +60,15 @@ class SystemHeartbeat #implements ShouldQueue // If we havent polled in heatbeat hours, poll system foreach ($l as $oo) { 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_id < Address::NODE_NN) && ($oo->system->last_session->addHours(6) < Carbon::now()))) + if ((! $oo->system->last_seen) + || ($oo->system->hearbeat && ($oo->system->last_seen->addHours($oo->system->heartbeat) < Carbon::now())) + || ((! $oo->system->hearbeat) && ($oo->role_id < Address::NODE_NN) && ($oo->system->last_seen->addHours(6) < Carbon::now()))) { Log::info(sprintf('%s:- Polling [%s] (%s) - we havent seen them since [%s], heartbeat [%d]', self::LOGKEY, $oo->ftn, $oo->system->name, - $oo->system->last_session ?: 'Never', + $oo->system->last_seen ?: 'Never', $oo->system->heartbeat, )); @@ -78,7 +78,7 @@ class SystemHeartbeat #implements ShouldQueue Log::debug(sprintf('%s:= Not scheduling poll to [%s], we saw them [%s], heartbeat [%d]', self::LOGKEY, $oo->ftn, - $oo->system->last_session, + $oo->system->last_seen, $oo->system->heartbeat )); } diff --git a/app/Models/System.php b/app/Models/System.php index 13ed10a..12f80a0 100644 --- a/app/Models/System.php +++ b/app/Models/System.php @@ -2,6 +2,7 @@ namespace App\Models; +use Carbon\Carbon; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; use Illuminate\Support\Collection; @@ -181,6 +182,11 @@ class System extends Model return $val ?: Setup::findOrFail(config('app.id'))->msgs_pkt; } + public function getLastSeenAttribute(): ?Carbon + { + return $this->logs_recent->first()?->created_at; + } + /* METHODS */ public function echoareas() @@ -289,7 +295,7 @@ class System extends Model } /** - * Return other addresses that are no collected here, but are on the same network as us. + * Return other addresses that are not collected here, but are on the same network as us. * * @return \Illuminate\Database\Eloquent\Collection * @throws \Exception @@ -298,6 +304,7 @@ class System extends Model { $our = our_address(); - return $this->akas->filter(fn($item)=>($item->parent() && (! $our->contains($item->parent())))); + return $this->akas + ->filter(fn($item)=>(($x=$item->parent()) && (! $our->contains($x)) && ($our->pluck('zone.domain_id')->contains($item->zone->domain_id)))); } } \ No newline at end of file diff --git a/app/Notifications/Echomails/AbsentNodes.php b/app/Notifications/Echomails/AbsentNodes.php index d7a0fdb..0dd3104 100644 --- a/app/Notifications/Echomails/AbsentNodes.php +++ b/app/Notifications/Echomails/AbsentNodes.php @@ -62,7 +62,7 @@ class AbsentNodes extends Echomails $msg->addText("The following nodes have been marked HOLD:\r"); foreach ($x as $ao) - $msg->addText(sprintf('* %s (%s), last seen %d days ago',$ao->ftn4d,$ao->system->name,$ao->system->last_session->diffInDays($now)).($ao->contacted ? '': ' ^')."\r"); + $msg->addText(sprintf('* %s (%s), last seen %d days ago',$ao->ftn4d,$ao->system->name,$ao->system->last_seen?->diffInDays($now)).($ao->contacted ? '': ' ^')."\r"); $msg->addText("\r"); } @@ -72,7 +72,7 @@ class AbsentNodes extends Echomails $msg->addText("The following nodes have been marked DOWN:\r"); foreach ($x as $ao) - $msg->addText(sprintf('* %s (%s), last seen %d days ago',$ao->ftn4d,$ao->system->name,$ao->system->last_session->diffInDays($now)).($ao->contacted ? '': ' ^')."\r"); + $msg->addText(sprintf('* %s (%s), last seen %d days ago',$ao->ftn4d,$ao->system->name,$ao->system->last_seen?->diffInDays($now)).($ao->contacted ? '': ' ^')."\r"); $msg->addText("\r"); } @@ -82,7 +82,7 @@ class AbsentNodes extends Echomails $msg->addText("The following nodes have been DE-LISTED:\r"); foreach ($x as $ao) - $msg->addText(sprintf('* %s (%s), last seen %d days ago',$ao->ftn4d,$ao->system->name,$ao->system->last_session->diffInDays($now)).($ao->contacted ? '': ' ^')."\r"); + $msg->addText(sprintf('* %s (%s), last seen %d days ago',$ao->ftn4d,$ao->system->name,$ao->system->last_seen?->diffInDays($now)).($ao->contacted ? '': ' ^')."\r"); $msg->addText("\r"); } diff --git a/app/Notifications/Emails/NodeDelisted.php b/app/Notifications/Emails/NodeDelisted.php index ae5a1fa..9b362ef 100644 --- a/app/Notifications/Emails/NodeDelisted.php +++ b/app/Notifications/Emails/NodeDelisted.php @@ -49,8 +49,8 @@ class NodeDelisted extends Notification //implements ShouldQueue ->line(sprintf('Your system has been DE-LISTED, because it hasnt polled **%s** with address %s since **%s** (%d days).', $x, $this->ao->ftn4d, - $this->ao->system->last_session->format('Y-m-d'), - $this->ao->system->last_session->diffInDays($now))) + $this->ao->system->last_seen?->format('Y-m-d') ?: 'Not seen', + $this->ao->system->last_seen?->diffInDays($now))) ->line('') ->line('If you think this was a mistake, please let me know.') ->line(sprintf('If you think about returning to %s, then reach out and we can get you back online pretty quickly.',$x)); diff --git a/app/Notifications/Emails/NodeMarkedDown.php b/app/Notifications/Emails/NodeMarkedDown.php index 50cddae..b066a5a 100644 --- a/app/Notifications/Emails/NodeMarkedDown.php +++ b/app/Notifications/Emails/NodeMarkedDown.php @@ -49,13 +49,13 @@ class NodeMarkedDown extends Notification //implements ShouldQueue ->line(sprintf('Your system has been marked **DOWN**, because it hasnt polled **%s** with address %s since **%s** (%d days).', $this->ao->zone->domain->name, $this->ao->ftn4d, - $this->ao->system->last_session->format('Y-m-d'), - $this->ao->system->last_session->diffInDays($now))) + $this->ao->system->last_seen?->format('Y-m-d') ?: 'Not seen', + $this->ao->system->last_seen?->diffInDays($now))) ->line('') ->line('You have (waiting for collection):') - ->lineIf($this->ao->uncollected_netmail,sprintf('* %s Netmails',number_format($this->ao->uncollected_netmail))) - ->lineIf($this->ao->uncollected_echomail,sprintf('* %s Echomails',number_format($this->ao->uncollected_echomail))) - ->lineIf($this->ao->uncollected_files,sprintf('* %s Files',number_format($this->ao->uncollected_files))) + ->line(sprintf('* %s Netmails',number_format($this->ao->uncollected_netmail))) + ->line(sprintf('* %s Echomails',number_format($this->ao->uncollected_echomail))) + ->line(sprintf('* %s Files',number_format($this->ao->uncollected_files))) ->line('') ->line(sprintf('Your system will automatically be **DE-LISTED** if your system hasnt polled to collected your mail/file(s) by **%s**',$now->addDays(7)->format('Y-m-d'))) ->line('If you think you\'ve received this email by mistake or need help, please let me know.'); diff --git a/app/Notifications/Emails/NodeMarkedHold.php b/app/Notifications/Emails/NodeMarkedHold.php index be8ebf2..9c47dfd 100644 --- a/app/Notifications/Emails/NodeMarkedHold.php +++ b/app/Notifications/Emails/NodeMarkedHold.php @@ -49,15 +49,15 @@ class NodeMarkedHold extends Notification //implements ShouldQueue ->line(sprintf('Your system has been marked **HOLD**, because it hasnt polled **%s** with address %s since **%s** (%d days).', $this->ao->zone->domain->name, $this->ao->ftn4d, - $this->ao->system->last_session->format('Y-m-d'), - $this->ao->system->last_session->diffInDays($now))) + $this->ao->system->last_seen?->format('Y-m-d') ?: 'Not seen', + $this->ao->system->last_seen?->diffInDays($now))) ->line('') ->line('You have (waiting for collection):') - ->lineIf($this->ao->uncollected_netmail,sprintf('* %s Netmails',number_format($this->ao->uncollected_netmail))) - ->lineIf($this->ao->uncollected_echomail,sprintf('* %s Echomails',number_format($this->ao->uncollected_echomail))) - ->lineIf($this->ao->uncollected_files,sprintf('* %s Files',number_format($this->ao->uncollected_files))) + ->line(sprintf('* %s Netmails',number_format($this->ao->uncollected_netmail))) + ->line(sprintf('* %s Echomails',number_format($this->ao->uncollected_echomail))) + ->line(sprintf('* %s Files',number_format($this->ao->uncollected_files))) ->line('') - ->line(sprintf('To clear this status, all you need to do make sure your system polls and collects mail by **%s**',$this->ao->system->last_session->addDays(config('fido.idle.down'))->format('Y-m-d'))) + ->line(sprintf('To clear this status, all you need to do make sure your system polls and collects mail by **%s**',($this->ao->system->last_seen ?: Carbon::now())->addDays(config('fido.idle.down'))->format('Y-m-d'))) ->line('If you think you\'ve received this email by mistake or need help, please let me know.'); } } \ No newline at end of file diff --git a/app/Notifications/Netmails/NodeDelisted.php b/app/Notifications/Netmails/NodeDelisted.php index d4b51ed..a011f04 100644 --- a/app/Notifications/Netmails/NodeDelisted.php +++ b/app/Notifications/Netmails/NodeDelisted.php @@ -44,7 +44,7 @@ class NodeDelisted extends Netmails //implements ShouldQueue $msg = $this->page(TRUE,'delist'); $msg->addText(sprintf("Hi %s,\r\r",$this->ao->system->sysop)) - ->addText(sprintf("Your system has been marked **DE-LISTED**, because it hasnt polled **%s** with address %s since **%s** (%d days).\r",$this->ao->zone->domain->name,$this->ao->ftn4d,$this->ao->system->last_session->format('Y-m-d'),$this->ao->system->last_session->diffInDays($now))) + ->addText(sprintf("Your system has been marked **DE-LISTED**, because it hasnt polled **%s** with address %s since **%s** (%d days).\r",$this->ao->zone->domain->name,$this->ao->ftn4d,$this->ao->system->last_seen?->format('Y-m-d') ?: 'Not seen',$this->ao->system->last_seen?->diffInDays($now))) ->addText("\r") ->addText("If you think this was a mistake, please let me know.\r\r") ->addText(sprintf('If you think about returning to %s, then reach out and we can get you back online pretty quickly.',$x)); diff --git a/app/Notifications/Netmails/NodeMarkedDown.php b/app/Notifications/Netmails/NodeMarkedDown.php index 3066bed..7161b84 100644 --- a/app/Notifications/Netmails/NodeMarkedDown.php +++ b/app/Notifications/Netmails/NodeMarkedDown.php @@ -31,12 +31,11 @@ class NodeMarkedDown extends Netmails //implements ShouldQueue public function toNetmail(object $notifiable): Netmail { $now = Carbon::now(); - - $o = $this->setupNetmail($notifiable); $ao = $notifiable->routeNotificationFor(static::via); Log::info(sprintf('%s:+ Sending a NODE MARKED DOWN NETMAIL for address [%s]',self::LOGKEY,$ao->ftn)); + $o = $this->setupNetmail($notifiable); $o->subject = sprintf('ACTION REQUIRED: Your system will be delisted on %s',$now->format('Y-m-d')); $o->flags = (Message::FLAG_LOCAL|Message::FLAG_PRIVATE|Message::FLAG_CRASH); @@ -44,7 +43,7 @@ class NodeMarkedDown extends Netmails //implements ShouldQueue $msg = $this->page(TRUE,'down'); $msg->addText(sprintf("Hi %s,\r\r",$this->ao->system->sysop)) - ->addText(sprintf("Your system has been marked **DOWN**, because it hasnt polled **%s** with address %s since **%s** (%d days).\r",$this->ao->zone->domain->name,$this->ao->ftn4d,$this->ao->system->last_session->format('Y-m-d'),$this->ao->system->last_session->diffInDays($now))) + ->addText(sprintf("Your system has been marked **DOWN**, because it hasnt polled **%s** with address %s since **%s** (%d days).\r",$this->ao->zone->domain->name,$this->ao->ftn4d,$this->ao->system->last_seen?->format('Y-m-d') ?: 'Not seen',$this->ao->system->last_seen?->diffInDays($now))) ->addText("\r") ->addText("You have (waiting for collection):\r") ->addText(sprintf("* %s Netmails\r",number_format($this->ao->uncollected_netmail))) diff --git a/app/Notifications/Netmails/NodeMarkedHold.php b/app/Notifications/Netmails/NodeMarkedHold.php index d1816cf..0cb6885 100644 --- a/app/Notifications/Netmails/NodeMarkedHold.php +++ b/app/Notifications/Netmails/NodeMarkedHold.php @@ -44,14 +44,14 @@ class NodeMarkedHold extends Netmails //implements ShouldQueue $msg = $this->page(TRUE,'hold'); $msg->addText(sprintf("Hi %s,\r\r",$this->ao->system->sysop)) - ->addText(sprintf("Your system has been marked **HOLD**, because it hasnt polled **%s** with address %s since **%s** (%d days).\r",$this->ao->zone->domain->name,$this->ao->ftn4d,$this->ao->system->last_session->format('Y-m-d'),$this->ao->system->last_session->diffInDays($now))) + ->addText(sprintf("Your system has been marked **HOLD**, because it hasnt polled **%s** with address %s since **%s** (%d days).\r",$this->ao->zone->domain->name,$this->ao->ftn4d,$this->ao->system->last_seen?->format('Y-m-d') ?: 'Not seen',$this->ao->system->last_seen?->diffInDays($now))) ->addText("\r") ->addText("You have (waiting for collection):\r") ->addText(sprintf("* %s Netmails\r",number_format($this->ao->uncollected_netmail))) ->addText(sprintf("* %s Echomails\r",number_format($this->ao->uncollected_echomail))) ->addText(sprintf("* %s Files\r",number_format($this->ao->uncollected_files))) ->addText("\r") - ->addText(sprintf("To clear this status, all you need to do make sure your system polls and collects mail by **%s**\r\r",$this->ao->system->last_session->addDays(config('fido.idle.down'))->format('Y-m-d'))) + ->addText(sprintf("To clear this status, all you need to do make sure your system polls and collects mail by **%s**\r\r",($this->ao->system->last_seen ?: Carbon::now())->addDays(config('fido.idle.down'))->format('Y-m-d'))) ->addText("If you think you've received this netmail by mistake or need help, please let me know.\r"); $o->msg = $msg->render(); diff --git a/resources/views/echoarea/addedit.blade.php b/resources/views/echoarea/addedit.blade.php index 0f00066..2832846 100644 --- a/resources/views/echoarea/addedit.blade.php +++ b/resources/views/echoarea/addedit.blade.php @@ -1,3 +1,5 @@ +@use(App\Models\Domain) + @extends('layouts.app') @section('htmlheader_title') @@ -20,7 +22,7 @@ @@ -180,7 +182,7 @@ {{ $ao->system->full_name($ao) }} @auth@if($ao->is_hosted){{ $ao->is_default ? '**' : '*' }}@elseif($ao->system->setup)+@endif[{{ $ao->system_id }}]@endauth {{ $ao->ftn_3d }} - {{ $ao->system->last_session ? $ao->system->last_session->format('Y-m-d H:i') : '-' }} + {{ $ao->system->last_seen?->format('Y-m-d H:i') ?: '-' }} {{ ($x=$o->waiting($ao))->count() ? $x->first()->datetime->format('Y-m-d H:i') : '-' }} {{ number_format($x->count()) }} diff --git a/resources/views/status.blade.php b/resources/views/status.blade.php index 1a1b41f..1299ac7 100644 --- a/resources/views/status.blade.php +++ b/resources/views/status.blade.php @@ -1,3 +1,6 @@ +@use(App\Models\SystemLog) +@use(Carbon\Carbon) + @extends('layouts.app') @section('htmlheader_title') Stats @@ -119,7 +122,7 @@
Systems
@@ -188,7 +191,7 @@ {{ number_format($o->uncollected_echomail ?? 0) }} {{ number_format($o->uncollected_netmail ?? 0) }} {{ number_format($o->uncollected_files ?? 0) }} - {{ $o->system->last_session?->format('Y-m-d H:i') }} + {{ $o->system->last_seen?->format('Y-m-d H:i') }} {{ is_null($o->system->pollmode) ? 'HOLD' : ($o->system->pollmode ? 'CRASH' : 'DAILY') }} {{ $o->system->autohold ? 'YES' : 'NO' }} diff --git a/resources/views/system/ours.blade.php b/resources/views/system/ours.blade.php index e7aec9c..187d13c 100644 --- a/resources/views/system/ours.blade.php +++ b/resources/views/system/ours.blade.php @@ -1,3 +1,5 @@ +@use(App\Models\SystemZone) + @extends('layouts.app') @section('htmlheader_title') Systems @@ -28,7 +30,7 @@ - @foreach (\App\Models\SystemZone::select('*')->with(['system.addresses.zone.domain','zone.domain'])->get() as $oo) + @foreach (SystemZone::select('*')->with(['system.addresses.zone.domain','zone.domain','system.logs_recent'])->get() as $oo) {{ $oo->zone->domain->name }} @@ -40,7 +42,7 @@ {{ $oo->system->name }} {{ $oo->system->sysop }} {{ $oo->system->location }} - {{ $oo->system->last_session ? $oo->system->last_session->format('Y-m-d H:i') : '-' }} + {{ $oo->system->last_seen?->format('Y-m-d H:i') ?: '-' }} {{ $oo->system->akas->where('zone_id',$oo->zone_id)->pluck('ftn4d')->join(', ') }} {{ $oo->system->zt_id }}