Correctly storing netmail flags (intransit, local, recv) with senders ID and packet name

This commit is contained in:
2023-07-15 10:46:19 +10:00
parent 7bf957df3a
commit 61ab0614b6
7 changed files with 187 additions and 36 deletions

View File

@@ -11,7 +11,7 @@ use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Facades\Log;
use App\Classes\FTN\{Message,Process};
use App\Models\{Echoarea,Echomail,Netmail,Setup};
use App\Models\{Address,Echoarea,Echomail,Netmail,Setup};
class MessageProcess implements ShouldQueue
{
@@ -19,16 +19,17 @@ class MessageProcess implements ShouldQueue
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
private Address $sender;
private Message $msg;
private bool $skipbot;
private string $packet;
public function __construct(Message $msg,string $packet,bool $skipbot=FALSE)
public function __construct(Message $msg,string $packet,Address $sender,bool $skipbot=FALSE)
{
// Some checks
$this->msg = $msg;
$this->skipbot = $skipbot;
$this->packet = $packet;
$this->sender = $sender;
$this->skipbot = $skipbot;
}
/**
@@ -41,7 +42,7 @@ class MessageProcess implements ShouldQueue
// If we are a netmail
if ($this->msg->isNetmail()) {
Log::info(sprintf('%s:Processing Netmail [%s] to (%s) [%s] from (%s) [%s].',
Log::info(sprintf('%s:- Processing Netmail [%s] to (%s) [%s] from (%s) [%s].',
self::LOGKEY,
$this->msg->msgid,
$this->msg->user_to,$this->msg->tftn,
@@ -49,12 +50,44 @@ class MessageProcess implements ShouldQueue
));
// @todo Enable checks to reject old messages
// @todo Enable checks to reject duplicate
// Check for duplicate messages
// FTS-0009.001
if ($this->msg->msgid) {
$o = Netmail::where('msgid',$this->msg->msgid)
->where('fftn_id',($x=$this->msg->fboss_o) ? $x->id : NULL)
->where('datetime','>',Carbon::now()->subYears(3))
->single();
Log::debug(sprintf('%s:- Checking for duplicate from host id [%d].',self::LOGKEY,($x=$this->msg->fboss_o) ? $x->id : NULL));
if ($o) {
Log::alert(sprintf('%s:! Duplicate netmail [%s] in [%s] from (%s) [%s] to (%s) - ignorning.',
self::LOGKEY,
$this->msg->msgid,
$this->msg->echoarea,
$this->msg->user_from,$this->msg->fftn,
$this->msg->user_to,
));
if (! $o->msg_crc)
$o->msg_crc = md5($this->msg->message);
$o->save();
return;
}
}
// @todo Enable checks to see if this is a file request or file send
$o = $this->create_netmail($this->msg);
$o->recv_pkt = $this->packet;
$o->set_pkt = $this->packet;
$o->set_sender = $this->sender;
$o->set_path = $this->msg->pathaddress;
// Strip any local flag
$o->flags &= ~Message::FLAG_LOCAL;
// Determine if the message is to this system, or in transit
if ($ftns->search(function($item) { return $this->msg->tftn === $item->ftn; }) !== FALSE) {
@@ -67,7 +100,7 @@ class MessageProcess implements ShouldQueue
if (! $this->skipbot)
foreach (config('process.robots') as $class) {
if ($processed = $class::handle($this->msg)) {
$o->local = TRUE;
$o->flags |= Message::FLAG_RECD;
$o->save();
break;
@@ -76,16 +109,16 @@ class MessageProcess implements ShouldQueue
// We'll ignore messages from *fix users
if (in_array(strtolower($this->msg->user_from),['filefix','areafix'])) {
$o->local = TRUE;
$o->flags |= Message::FLAG_RECD;
$o->save();
Log::info(sprintf('%s:Ignoring Netmail [%d-%s] to the Hub from (%s) [%s] - its from a bot.',
Log::alert(sprintf('%s:! Ignoring Netmail [%s] to the Hub from (%s:%s) - its from a bot [%d].',
self::LOGKEY,
$o->id,
$this->msg->msgid,
$this->msg->user_from,
$this->msg->fftn)
);
$this->msg->fftn,
$o->id,
));
$processed = TRUE;
}
@@ -98,7 +131,7 @@ class MessageProcess implements ShouldQueue
'Á ÀÄÙÀÄÙÀÄÙÀÄÙ Á '
];
Log::info(sprintf('Netmail to the Hub from (%s) [%s] but no users here.',$this->msg->user_from,$this->msg->fftn));
Log::alert(sprintf('%s:! Netmail to the Hub from (%s) [%s] but no users here.',self::LOGKEY,$this->msg->user_from,$this->msg->fftn));
$reply = "Your Netmail was not processed by the hub and cannot be delivered to anybody (as there are no users here).\r";
@@ -146,20 +179,21 @@ class MessageProcess implements ShouldQueue
// @todo In transit loop checking
// @todo In transit TRACE response
$o->flags |= Message::FLAG_INTRANSIT;
$o->save();
Log::info(sprintf('%s:Netmail [%d-%s] in transit to (%s) [%s] from (%s) [%s].',
Log::info(sprintf('%s:= Netmail [%s] in transit to (%s:%s) from (%s:%s) [%d].',
self::LOGKEY,
$o->id,
$this->msg->msgid,
$this->msg->user_to,$this->msg->tftn,
$this->msg->user_from,$this->msg->fftn,
$o->id,
));
}
// Else we are echomail
} else {
Log::debug(sprintf('%s: - Looking for echomail area [%s] for mail from [%s]',self::LOGKEY,$this->msg->echoarea,$this->msg->fboss));
Log::debug(sprintf('%s:- Looking for echomail area [%s] for mail from [%s]',self::LOGKEY,$this->msg->echoarea,$this->msg->fboss));
if (! $this->msg->fboss_o) {
Log::error(sprintf('%s:! Cannot process message for echomail area [%s] for mail from [%s] with msgid [%s] - no boss object?',self::LOGKEY,$this->msg->echoarea,$this->msg->fboss,$this->msg->msgid));
@@ -175,7 +209,7 @@ class MessageProcess implements ShouldQueue
return;
}
Log::debug(sprintf('%s: - Processing echomail [%s] in [%s].',self::LOGKEY,$this->msg->msgid,$this->msg->echoarea));
Log::debug(sprintf('%s:- Processing echomail [%s] in [%s].',self::LOGKEY,$this->msg->msgid,$this->msg->echoarea));
// Check for duplicate messages
// FTS-0009.001
@@ -185,7 +219,7 @@ class MessageProcess implements ShouldQueue
->where('datetime','>',Carbon::now()->subYears(3))
->single();
Log::debug(sprintf('%s: - Checking for duplicate from host id [%d].',self::LOGKEY,($x=$this->msg->fboss_o) ? $x->id : NULL));
Log::debug(sprintf('%s:- Checking for duplicate from host id [%d].',self::LOGKEY,($x=$this->msg->fboss_o) ? $x->id : NULL));
if ($o) {
Log::alert(sprintf('%s:! Duplicate echomail [%s] in [%s] from (%s) [%s] to (%s) - updating seenby.',
@@ -254,10 +288,11 @@ class MessageProcess implements ShouldQueue
$o->rogue_path = $this->msg->rogue_path;
$o->set_path = $this->msg->pathaddress;
$o->set_seenby = $this->msg->seenaddress;
// Record receiving packet and sender
$o->save();
Log::info(sprintf('%s: - Echomail [%s] in [%s] from (%s) [%s] to (%s) - [%s].',
Log::info(sprintf('%s:= Echomail [%s] in [%s] from (%s) [%s] to (%s) - [%s].',
self::LOGKEY,
$this->msg->msgid,
$this->msg->echoarea,