Process netmails from unlisted systems
All checks were successful
Create Docker Image / Build Docker Image (x86_64) (push) Successful in 31s
Create Docker Image / Build Docker Image (arm64) (push) Successful in 1m30s
Create Docker Image / Final Docker Image Manifest (push) Successful in 9s

This commit is contained in:
Deon George 2024-11-20 16:01:11 +09:30
parent 016c1fb1b0
commit 67dad76bd1
3 changed files with 81 additions and 13 deletions

View File

@ -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()));

View File

@ -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)
{

View File

@ -0,0 +1,59 @@
<?php
namespace App\Notifications\Netmails;
use Illuminate\Support\Facades\Log;
use App\Notifications\Netmails;
use App\Models\{Echomail,Netmail};
use App\Traits\{MessagePath,PageTemplate};
class UnexpectedPacketFromYou extends Netmails
{
use MessagePath,PageTemplate;
private const LOGKEY = 'NUP';
private string $filename;
/**
* Send a sysop a message if they send us echomail and they are not defined with us.
*
* @param Echomail $mo
*/
public function __construct(string $filename)
{
parent::__construct();
$this->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;
}
}