From 8cc561ea2b8431599ae0baa4f22032213db1d4e5 Mon Sep 17 00:00:00 2001 From: Deon George Date: Wed, 29 Jan 2025 08:45:46 +1100 Subject: [PATCH] Fix for EMSI aborting with $rc undefined, Fix for idle nodes updates failing on updated_at column and change text used when nodes have never polled --- app/Classes/Protocol/EMSI.php | 2 ++ app/Classes/Protocol/Zmodem.php | 10 ++++---- app/Jobs/AddressIdle.php | 4 +-- app/Notifications/Echomails/AbsentNodes.php | 28 +++++++++++++++------ 4 files changed, 28 insertions(+), 16 deletions(-) diff --git a/app/Classes/Protocol/EMSI.php b/app/Classes/Protocol/EMSI.php index bbc7743..b8ea5bf 100644 --- a/app/Classes/Protocol/EMSI.php +++ b/app/Classes/Protocol/EMSI.php @@ -929,6 +929,8 @@ final class EMSI extends BaseProtocol implements CRCInterface,ZmodemInterface } catch (SocketException $e) { if ($c++ > 2) return self::TIMEOUT; + else + $ch = -2; } if (static::DEBUG) diff --git a/app/Classes/Protocol/Zmodem.php b/app/Classes/Protocol/Zmodem.php index 13774e1..a642064 100644 --- a/app/Classes/Protocol/Zmodem.php +++ b/app/Classes/Protocol/Zmodem.php @@ -489,7 +489,7 @@ final class Zmodem extends Protocol implements CRCInterface,ZmodemInterface * @param Send $send * @return int */ - public function zmodem_sendfile(Send $send,Node $node): int + public function zmodem_sendfile(Send $send,Node $node): void { Log::debug(sprintf('%s:+ zmodem_sendfile',self::LOGKEY)); @@ -513,16 +513,16 @@ final class Zmodem extends Protocol implements CRCInterface,ZmodemInterface break; } - return $rc; + return; } catch (\Exception $e) { - Log::error(sprintf('%s:! Error [%s]',self::LOGKEY,$e->getMessage()),['rc'=>$rc]); + Log::error(sprintf('%s:! Error [%s]',self::LOGKEY,$e->getMessage()),['rc'=>$rc ?? '-UNDEFINED-']); - return $rc; + return; } } - return self::OK; + return; } /** diff --git a/app/Jobs/AddressIdle.php b/app/Jobs/AddressIdle.php index 4bde45a..d65742c 100644 --- a/app/Jobs/AddressIdle.php +++ b/app/Jobs/AddressIdle.php @@ -9,11 +9,9 @@ use Illuminate\Database\Eloquent\Collection; use Illuminate\Foundation\Bus\Dispatchable; use Illuminate\Queue\InteractsWithQueue; use Illuminate\Queue\SerializesModels; -use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Log; use Illuminate\Support\Facades\Notification; -use App\Classes\FTN\Message; use App\Models\{Address,Domain,System}; use App\Notifications\Echomails\AbsentNodes; use App\Notifications\Emails\NodeMarkedDown as NodeMarkedDownEmail; @@ -205,7 +203,7 @@ class AddressIdle implements ShouldQueue ->whereIn('addresses.id',our_nodes($do)->pluck('id')) ->when($ao,fn($query)=>$query->where('addresses.id',$ao->id)) ->where(fn($q)=>$q->where('last_session','<',$age) - ->orWhere(fn($q)=>$q->whereNull('last_session')->where('updated_at','<',Carbon::now()->subDays(14)->startOfDay()))) + ->orWhere(fn($q)=>$q->whereNull('last_session')->where('addresses.updated_at','<',Carbon::now()->subDays(14)->startOfDay()))) ->whereRaw(sprintf('((role IS NULL) OR (role=0) OR ((role & %d) > 0))',$flags)) ->whereRaw(sprintf('((role IS NULL) OR ((role & %d) = 0))',Address::NODE_KEEP)) ->join('systems',['systems.id'=>'addresses.system_id']) diff --git a/app/Notifications/Echomails/AbsentNodes.php b/app/Notifications/Echomails/AbsentNodes.php index 0dd3104..4e52f8f 100644 --- a/app/Notifications/Echomails/AbsentNodes.php +++ b/app/Notifications/Echomails/AbsentNodes.php @@ -57,22 +57,30 @@ class AbsentNodes extends Echomails $msg->addText("The following nodes have had their status changed, because they are absent from the network.\r\r"); - // Nodes marked HOLD - will be marked down ... + // Nodes marked HOLD if (($x=$this->aos->filter(fn($item)=>$item->active && ($item->role & Address::NODE_HOLD)))->count()) { $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_seen?->diffInDays($now)).($ao->contacted ? '': ' ^')."\r"); + foreach ($x as $ao) { + if (! $ao->system->last_seen) + $msg->addText(sprintf('* %s (%s), not seen since registered %d days ago',$ao->ftn4d,$ao->system->name,$ao->system->updated_at->diffInDays($now)).($ao->contacted ? '': ' ^')."\r"); + else + $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"); } - // Nodes marked DOWN - will be delisted on... + // Nodes marked DOWN if (($x=$this->aos->filter(fn($item)=>$item->active && ($item->role & Address::NODE_DOWN)))->count()) { $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_seen?->diffInDays($now)).($ao->contacted ? '': ' ^')."\r"); + foreach ($x as $ao) { + if (! $ao->system->last_seen) + $msg->addText(sprintf('* %s (%s), not seen since registered %d days ago',$ao->ftn4d,$ao->system->name,$ao->system->updated_at->diffInDays($now)).($ao->contacted ? '': ' ^')."\r"); + else + $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"); } @@ -81,8 +89,12 @@ class AbsentNodes extends Echomails if (($x=$this->aos->filter(fn($item)=>! $item->active))->count()) { $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_seen?->diffInDays($now)).($ao->contacted ? '': ' ^')."\r"); + foreach ($x as $ao) { + if (! $ao->system->last_seen) + $msg->addText(sprintf('* %s (%s), not seen since registered %d days ago',$ao->ftn4d,$ao->system->name,$ao->system->updated_at->diffInDays($now)).($ao->contacted ? '': ' ^')."\r"); + else + $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"); }