diff --git a/app/Jobs/PacketProcess.php b/app/Jobs/PacketProcess.php index 59ca43b..b9e3e50 100644 --- a/app/Jobs/PacketProcess.php +++ b/app/Jobs/PacketProcess.php @@ -18,7 +18,7 @@ use App\Classes\File; use App\Classes\FTN\Packet; use App\Exceptions\InvalidPacketException; use App\Models\{Echomail,Netmail,System}; -use App\Notifications\Netmails\PacketPasswordInvalid; +use App\Notifications\Netmails\{PacketPasswordInvalid,UnexpectedPacketFromYou}; class PacketProcess implements ShouldQueue { @@ -80,17 +80,9 @@ class PacketProcess implements ShouldQueue break; } - if (! our_nodes($pkt->fftn->zone->domain)->contains($pkt->fftn)) { - Log::error(sprintf('%s:! Packet [%s] is from a system that is not configured with us? [%s]',self::LOGKEY,$this->filename,$pkt->fftn_t)); - - // @todo Notification::route('netmail',$pkt->fftn)->notify(new UnexpectedPacketFromYou($this->filename)); - // @todo Parse the packet for netmails and process them. We'll only accept netmails to us, and ignore all others - break; - } - // If we dont have the tftn in the DB, then packet cannot be to us if (! $pkt->tftn) { - Log::error(sprintf('%s:! Packet [%s] is from a system [%s] we dont know about?',self::LOGKEY,$this->filename,$pkt->tftn_t)); + Log::error(sprintf('%s:! Packet [%s] is for a system [%s] we dont know about?',self::LOGKEY,$this->filename,$pkt->tftn_t)); // @todo Notification::route('netmail',$pkt->fftn)->notify(new UnexpectedPacketToUs($this->filename)); break; @@ -104,8 +96,15 @@ class PacketProcess implements ShouldQueue break; } + $netmail_only = FALSE; + + if (! our_nodes($pkt->fftn->zone->domain)->contains($pkt->fftn)) { + Log::alert(sprintf('%s:! Packet [%s] is from a system that is not configured with us, only NETMAIL processed [%s]',self::LOGKEY,$this->filename,$pkt->fftn_t)); + + $netmail_only = TRUE; + // Check the packet password - if ($pkt->fftn->pass_packet !== strtoupper($pkt->password)) { + } elseif ($pkt->fftn->pass_packet !== strtoupper($pkt->password)) { Log::error(sprintf('%s:! Packet from [%s] with password [%s] is invalid.',self::LOGKEY,$pkt->fftn->ftn,$pkt->password)); Notification::route('netmail',$pkt->fftn)->notify(new PacketPasswordInvalid($pkt->password,$f->pktName())); @@ -122,9 +121,17 @@ class PacketProcess implements ShouldQueue foreach ($pkt as $msg) { if ($msg instanceof Netmail) Log::info(sprintf('%s:- Netmail from [%s] to [%s]',self::LOGKEY,$msg->fftn->ftn,$msg->tftn->ftn)); - elseif ($msg instanceof Echomail) + + elseif ($msg instanceof Echomail) { Log::info(sprintf('%s:- Echomail from [%s]',self::LOGKEY,$msg->fftn->ftn)); + if ($netmail_only) { + Log::alert(sprintf('%s:! Echomail IGNORED as packet is from an unknown system [%s]',self::LOGKEY,$pkt->fftn->ftn)); + + continue; + } + } + if ($msg->errors->count()) { Log::error(sprintf('%s:! Message [%s] has [%d] errors, unable to process',self::LOGKEY,$msg->msgid,$msg->errors->count())); @@ -155,6 +162,8 @@ class PacketProcess implements ShouldQueue if ($count === $pkt->count()) $processed = TRUE; + elseif ($netmail_only) + Notification::route('netmail',$pkt->fftn)->notify(new UnexpectedPacketFromYou($f->pktName())); } catch (\Exception $e) { Log::error(sprintf('%s:! Got an exception [%s] processing packet',self::LOGKEY,$e->getMessage())); diff --git a/app/Notifications/Netmails/NetmailBadAddress.php b/app/Notifications/Netmails/NetmailBadAddress.php index 556b3ef..ea781b3 100644 --- a/app/Notifications/Netmails/NetmailBadAddress.php +++ b/app/Notifications/Netmails/NetmailBadAddress.php @@ -19,7 +19,7 @@ class NetmailBadAddress extends Netmails /** * Send a sysop a message if they give us a message with a bad address in it. * - * @param Echomail $mo + * @param Netmail $mo */ public function __construct(Netmail $mo) { diff --git a/app/Notifications/Netmails/UnexpectedPacketFromYou.php b/app/Notifications/Netmails/UnexpectedPacketFromYou.php new file mode 100644 index 0000000..6205f15 --- /dev/null +++ b/app/Notifications/Netmails/UnexpectedPacketFromYou.php @@ -0,0 +1,59 @@ +filename = $filename; + } + + /** + * Get the mail representation of the notification. + * + * @param mixed $notifiable + * @return Netmail + * @throws \Exception + */ + public function toNetmail(object $notifiable): Netmail + { + $o = $this->setupNetmail($notifiable); + $ao = $notifiable->routeNotificationFor(static::via); + + Log::info(sprintf('%s:+ Creating NETMAIL UNEXPECTED PACKET netmail to [%s]',self::LOGKEY,$ao->ftn)); + + $o->subject = sprintf('Unexpected packet from you [%s]',$this->filename); + + // Message + $msg = $this->page(FALSE,'unexpected'); + + $msg->addText("We received a packet from you with echomail, but your node is not defined here. Those echomail messages were ignored. If you think this is a mistake, please let me know.\r\r"); + + $o->msg = $msg->render(); + $o->set_tagline = 'The unexpected moment is always sweeter'; + + $o->save(); + + return $o; + } +} \ No newline at end of file