From 6284016400304109c66de8b0db6c23a2b98d686f Mon Sep 17 00:00:00 2001 From: Deon George Date: Sun, 6 Nov 2022 14:40:03 +1100 Subject: [PATCH] Auto create FTN address for intransit netmail when the destination is not known. --- app/Classes/FTN/Packet.php | 45 ++++++++++++++++++++++- app/Classes/FTN/Process/Echomail/Test.php | 2 +- app/Jobs/MessageProcess.php | 3 +- app/Jobs/NodelistImport.php | 4 +- 4 files changed, 49 insertions(+), 5 deletions(-) diff --git a/app/Classes/FTN/Packet.php b/app/Classes/FTN/Packet.php index 37aa4a4..ce68a78 100644 --- a/app/Classes/FTN/Packet.php +++ b/app/Classes/FTN/Packet.php @@ -435,6 +435,48 @@ class Packet extends FTNBase implements \Iterator, \Countable Log::info(sprintf('%s:- Message [%s] has errors',self::LOGKEY,$msg->msgid)); // If the from address doenst exist, we'll create a new entry + if ($msg->errors->messages()->has('to')) { + $e = NULL; + + try { + Address::unguard(); + $ao = Address::firstOrNew([ + 'zone_id' => $msg->tzone->id, + 'region_id' => 0, + 'host_id' => $msg->tn, + 'node_id' => $msg->tf, + 'point_id' => $msg->tp, + ]); + Address::reguard(); + + } catch (\Exception $e) { + Log::error(sprintf('%s:! Error finding/creating address [%s] for message',self::LOGKEY,$msg->tboss)); + } + + // This shouldnt happen + if ($e || $ao->exists) { + Log::error(sprintf('%s:! Unexpected error attempting to create address [%s]',self::LOGKEY,$msg->tboss)); + $this->errors->push($msg); + return; + } + + $ao->active = TRUE; + $ao->role = Address::NODE_UNKNOWN; + + System::unguard(); + $so = System::firstOrCreate([ + 'name' => 'Discovered System', + 'sysop' => 'Unknown', + 'location' => '', + 'active' => TRUE, + ]); + System::reguard(); + + $so->addresses()->save($ao); + + Log::alert(sprintf('%s: - To FTN is not defined, creating new entry for [%s] (%d)',self::LOGKEY,$msg->tboss,$ao->id)); + } + if ($msg->errors->messages()->has('from')) { $e = NULL; @@ -475,8 +517,9 @@ class Packet extends FTNBase implements \Iterator, \Countable $so->addresses()->save($ao); Log::alert(sprintf('%s: - From FTN is not defined, creating new entry for [%s] (%d)',self::LOGKEY,$msg->fboss,$ao->id)); + } - } elseif($msg->errors->messages()->has('user_from') || $msg->errors->messages()->has('user_to')) { + if ($msg->errors->messages()->has('user_from') || $msg->errors->messages()->has('user_to')) { Log::error(sprintf('%s:! Skipping message [%s] due to errors (%s)...',self::LOGKEY,$msg->msgid,join(',',$msg->errors->messages()->keys()))); $this->errors->push($msg); return; diff --git a/app/Classes/FTN/Process/Echomail/Test.php b/app/Classes/FTN/Process/Echomail/Test.php index f7dcee7..1ae7f7e 100644 --- a/app/Classes/FTN/Process/Echomail/Test.php +++ b/app/Classes/FTN/Process/Echomail/Test.php @@ -42,7 +42,7 @@ final class Test extends Process $reply .= "\r"; $reply .= "\r"; - $reply .= "------------------------------ BEING MESSAGE ------------------------------\r"; + $reply .= "------------------------------ BEGIN MESSAGE ------------------------------\r"; $reply .= sprintf("TO: %s\r",$msg->user_to); $reply .= sprintf("SUBJECT: %s\r",$msg->subject); $reply .= $msg->message."\r"; diff --git a/app/Jobs/MessageProcess.php b/app/Jobs/MessageProcess.php index 2c08eee..5ffae95 100644 --- a/app/Jobs/MessageProcess.php +++ b/app/Jobs/MessageProcess.php @@ -122,7 +122,8 @@ class MessageProcess implements ShouldQueue // If in transit, store for collection } else { - Log::info(sprintf('Netmail [%s] in transit to (%s) [%s] from (%s) [%s].', + Log::info(sprintf('%s:Netmail [%s] in transit to (%s) [%s] from (%s) [%s].', + self::LOGKEY, $this->msg->msgid, $this->msg->user_to,$this->msg->tftn, $this->msg->user_from,$this->msg->fftn, diff --git a/app/Jobs/NodelistImport.php b/app/Jobs/NodelistImport.php index 03528c4..cc458c6 100644 --- a/app/Jobs/NodelistImport.php +++ b/app/Jobs/NodelistImport.php @@ -128,7 +128,8 @@ class NodelistImport implements ShouldQueue $node = 0; switch ($fields[0]) { - case 'Zone': $zone = $fields[1]; + case 'Zone': + $zone = $fields[1]; Zone::unguard(); $zo = Zone::firstOrNew([ 'zone_id'=>$zone, @@ -364,7 +365,6 @@ class NodelistImport implements ShouldQueue } catch (\Exception $e) { Log::error(sprintf('%s:Error with line [%s] (%s)',self::LOGKEY,$line,$e->getMessage()),['fields'=>$fields]); - throw new \Exception($e->getMessage()); } if (! ($c % 100)) {