2021-07-15 14:54:23 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Jobs;
|
|
|
|
|
|
|
|
use Illuminate\Bus\Queueable;
|
|
|
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
|
|
|
use Illuminate\Foundation\Bus\Dispatchable;
|
|
|
|
use Illuminate\Queue\InteractsWithQueue;
|
|
|
|
use Illuminate\Queue\SerializesModels;
|
2021-07-23 14:53:35 +00:00
|
|
|
use Illuminate\Support\Facades\Log;
|
2021-07-15 14:54:23 +00:00
|
|
|
|
2021-07-23 14:53:35 +00:00
|
|
|
use App\Classes\FTN\{Message,Process};
|
2021-08-24 13:42:03 +00:00
|
|
|
use App\Models\{Echoarea,Echomail,Netmail,Setup};
|
2021-07-15 14:54:23 +00:00
|
|
|
|
2021-08-29 14:24:40 +00:00
|
|
|
class PacketProcess implements ShouldQueue
|
2021-07-15 14:54:23 +00:00
|
|
|
{
|
2021-08-18 14:20:34 +00:00
|
|
|
private const LOGKEY = 'PP-';
|
|
|
|
|
2021-07-15 14:54:23 +00:00
|
|
|
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
|
|
|
|
|
|
|
private Message $msg;
|
|
|
|
|
|
|
|
public function __construct(Message $msg)
|
|
|
|
{
|
|
|
|
// Some checks
|
|
|
|
$this->msg = $msg;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-08-29 14:24:40 +00:00
|
|
|
* When calling PacketProcess - we assume that the packet is from a valid source
|
2021-07-15 14:54:23 +00:00
|
|
|
*/
|
|
|
|
public function handle()
|
|
|
|
{
|
|
|
|
// Load our details
|
|
|
|
$ftns = Setup::findOrFail(config('app.id'))->system->addresses;
|
|
|
|
|
|
|
|
// If we are a netmail
|
|
|
|
if ($this->msg->isNetmail()) {
|
|
|
|
// @todo Enable checks to reject old messages
|
2021-07-23 14:53:35 +00:00
|
|
|
// @todo Enable checks to reject duplicate
|
|
|
|
// @todo Enable checks to see if this is a file request or file send
|
2021-07-15 14:54:23 +00:00
|
|
|
|
|
|
|
// Determine if the message is to this system, or in transit
|
2021-07-18 12:10:21 +00:00
|
|
|
if ($ftns->search(function($item) { return $this->msg->tftn == $item->ftn; }) !== FALSE) {
|
2021-07-15 14:54:23 +00:00
|
|
|
// @todo Check if it is a duplicate message
|
|
|
|
// @todo Check if the message is from a system we know about
|
|
|
|
|
|
|
|
$processed = FALSE;
|
|
|
|
|
|
|
|
// If the message is to a bot, we'll process it
|
|
|
|
foreach (config('process.robots') as $class) {
|
|
|
|
if ($processed = $class::handle($this->msg)) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-08-14 14:21:04 +00:00
|
|
|
// We'll ignore messages from *fix users
|
|
|
|
if (in_array(strtolower($this->msg->user_from),['filefix','areafix'])) {
|
|
|
|
Log::info(sprintf('Ignoring Netmail to the Hub from (%s) [%s] - its from a bot.',$this->msg->user_from,$this->msg->fftn));
|
|
|
|
|
|
|
|
$o = new Netmail;
|
|
|
|
$o->to = $this->msg->user_to;
|
|
|
|
$o->from = $this->msg->user_from;
|
|
|
|
$o->subject = $this->msg->subject;
|
|
|
|
$o->datetime = $this->msg->date;
|
|
|
|
$o->tzoffset = $this->msg->date->utcOffset();
|
|
|
|
|
|
|
|
$o->flags = $this->msg->flags;
|
|
|
|
$o->cost = $this->msg->cost;
|
|
|
|
$o->msgid = $this->msg->msgid;
|
|
|
|
|
|
|
|
$o->fftn_id = ($x=$this->msg->fftn_o) ? $x->id : NULL;
|
|
|
|
$o->tftn_id = ($x=$this->msg->tftn_o) ? $x->id : NULL;
|
|
|
|
$o->msg = $this->msg->message_src;
|
|
|
|
$o->local = TRUE;
|
|
|
|
|
|
|
|
$o->save();
|
|
|
|
|
|
|
|
$processed = TRUE;
|
|
|
|
}
|
|
|
|
|
2021-07-15 14:54:23 +00:00
|
|
|
// If not processed, no users here!
|
|
|
|
if (! $processed) {
|
2021-07-23 14:53:35 +00:00
|
|
|
$reject = [
|
|
|
|
'ÚÄ¿ÚÄ¿ ÂÚÄ¿ÚÄ¿Ú¿',
|
|
|
|
'³ ³ÄÙ ³³ÄÙ³ ³ ',
|
|
|
|
'Á ÀÄÙÀÄÙÀÄÙÀÄÙ Á '
|
|
|
|
];
|
|
|
|
|
|
|
|
Log::info(sprintf('Netmail to the Hub from (%s) [%s] but no users here.',$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";
|
|
|
|
|
|
|
|
$reply .= "\r";
|
|
|
|
$reply .= "\r";
|
|
|
|
$reply .= "This is your original message:\r";
|
|
|
|
$reply .= "------------------------------ BEING MESSAGE ------------------------------\r";
|
|
|
|
$reply .= sprintf("TO: %s\r",$this->msg->user_to);
|
|
|
|
$reply .= sprintf("SUBJECT: %s\r",$this->msg->subject);
|
|
|
|
$reply .= $this->msg->message;
|
|
|
|
$reply .= "------------------------------ CONTROL LINES ------------------------------\r";
|
|
|
|
$reply .= sprintf("DATE: %s\r",$this->msg->date->format('Y-m-d H:i:s'));
|
|
|
|
$reply .= sprintf("MSGID: %s\r",$this->msg->msgid);
|
|
|
|
|
|
|
|
foreach ($this->msg->kludge as $k=>$v)
|
|
|
|
$reply .= sprintf("@%s: %s\n",strtoupper($k),$v);
|
|
|
|
foreach ($this->msg->via as $via)
|
|
|
|
$reply .= sprintf("VIA: %s\n",$via);
|
|
|
|
|
|
|
|
$reply .= "------------------------------ END MESSAGE ------------------------------\r";
|
|
|
|
|
|
|
|
$o = new Netmail();
|
|
|
|
$o->to = $this->msg->user_from;
|
|
|
|
$o->from = Setup::PRODUCT_NAME;
|
|
|
|
$o->subject = 'Message Undeliverable - '.$this->msg->msgid;
|
2021-07-30 14:35:52 +00:00
|
|
|
$o->datetime = $this->msg->date;
|
|
|
|
$o->tzoffset = $this->msg->date->utcOffset();
|
|
|
|
|
|
|
|
$o->cost = 0;
|
|
|
|
$o->flags = Message::FLAG_LOCAL;
|
|
|
|
|
2021-07-23 14:53:35 +00:00
|
|
|
$o->fftn_id = ($x=$this->msg->tftn_o) ? $x->id : NULL;
|
|
|
|
$o->tftn_id = ($x=$this->msg->fftn_o) ? $x->id : NULL;
|
|
|
|
$o->reply = $this->msg->msgid;
|
2021-07-30 14:35:52 +00:00
|
|
|
$o->msg = Process::format_msg($reply,$reject);
|
2021-07-23 14:53:35 +00:00
|
|
|
|
|
|
|
$o->tagline = 'Do you think it was fate which brought us together? Nah, bad luck :(';
|
2021-07-30 14:35:52 +00:00
|
|
|
$o->tearline = sprintf('%s (%04X)',Setup::PRODUCT_NAME,Setup::PRODUCT_ID);
|
2021-07-23 14:53:35 +00:00
|
|
|
$o->save();
|
2021-07-15 14:54:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// If in transit, store for collection
|
|
|
|
} else {
|
2021-07-23 14:53:35 +00:00
|
|
|
Log::info(sprintf('Netmail [%s] in transit to (%s) [%s] from (%s) [%s].',
|
|
|
|
$this->msg->msgid,
|
|
|
|
$this->msg->user_to,$this->msg->tftn,
|
|
|
|
$this->msg->user_from,$this->msg->fftn,
|
|
|
|
));
|
|
|
|
|
2021-07-15 14:54:23 +00:00
|
|
|
// @todo Check if the message is to a system we know about
|
|
|
|
// @todo In transit loop checking
|
|
|
|
// @todo In transit TRACE response
|
|
|
|
|
2021-07-30 14:35:52 +00:00
|
|
|
$o = new Netmail;
|
2021-07-23 14:53:35 +00:00
|
|
|
$o->to = $this->msg->user_to;
|
|
|
|
$o->from = $this->msg->user_from;
|
|
|
|
$o->subject = $this->msg->subject;
|
2021-07-30 14:35:52 +00:00
|
|
|
$o->datetime = $this->msg->date;
|
|
|
|
$o->tzoffset = $this->msg->date->utcOffset();
|
|
|
|
|
2021-07-23 14:53:35 +00:00
|
|
|
$o->flags = $this->msg->flags;
|
|
|
|
$o->cost = $this->msg->cost;
|
2021-07-30 14:35:52 +00:00
|
|
|
$o->msgid = $this->msg->msgid;
|
|
|
|
|
|
|
|
$o->fftn_id = ($x=$this->msg->fftn_o) ? $x->id : NULL;
|
|
|
|
$o->tftn_id = ($x=$this->msg->tftn_o) ? $x->id : NULL;
|
|
|
|
$o->msg = $this->msg->message_src;
|
2021-07-23 14:53:35 +00:00
|
|
|
|
|
|
|
$o->save();
|
2021-07-15 14:54:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Else we are echomail
|
|
|
|
} else {
|
2021-08-11 13:45:30 +00:00
|
|
|
$ea = Echoarea::where('name',$this->msg->echoarea)
|
2021-08-22 06:25:43 +00:00
|
|
|
->where('domain_id',$this->msg->fboss_o->zone->domain_id)
|
2021-08-11 13:45:30 +00:00
|
|
|
->single();
|
|
|
|
|
2021-08-18 14:20:34 +00:00
|
|
|
// Check for duplicate messages
|
|
|
|
if ($this->msg->msgid) {
|
|
|
|
$o = Echomail::where('msgid',$this->msg->msgid)->single();
|
|
|
|
|
|
|
|
if ($o) {
|
|
|
|
Log::alert(sprintf('%s:! Ignoring duplicate echomail [%s] in [%s] from (%s) [%s] to (%s).',
|
|
|
|
self::LOGKEY,
|
|
|
|
$this->msg->msgid,
|
|
|
|
$this->msg->echoarea,
|
|
|
|
$this->msg->user_to,$this->msg->tftn,
|
|
|
|
$this->msg->user_from,
|
|
|
|
));
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-07-30 14:35:52 +00:00
|
|
|
// @todo Can the sender create it if it doesnt exist?
|
2021-08-19 13:35:48 +00:00
|
|
|
// @todo Can the sender send messages to this area?
|
2021-07-30 14:35:52 +00:00
|
|
|
// - Create it, or
|
|
|
|
// - Else record in bad area
|
2021-07-15 14:54:23 +00:00
|
|
|
|
|
|
|
// We know about this area, store it
|
2021-07-30 14:35:52 +00:00
|
|
|
$o = new Echomail;
|
|
|
|
$o->to = $this->msg->user_to;
|
|
|
|
$o->from = $this->msg->user_from;
|
|
|
|
$o->subject = $this->msg->subject;
|
|
|
|
$o->datetime = $this->msg->date;
|
|
|
|
$o->tzoffset = $this->msg->date->utcOffset();
|
|
|
|
|
2021-08-22 06:25:43 +00:00
|
|
|
$o->fftn_id = ($x=$this->msg->fboss_o) ? $x->id : NULL;
|
2021-08-11 13:45:30 +00:00
|
|
|
$o->echoarea_id = $ea?->id;
|
2021-07-30 14:35:52 +00:00
|
|
|
$o->msgid = $this->msg->msgid;
|
|
|
|
|
|
|
|
$o->msg = $this->msg->message_src;
|
2021-08-29 13:58:12 +00:00
|
|
|
$o->path = $this->msg->pathaddress->jsonSerialize();
|
2021-08-19 13:35:48 +00:00
|
|
|
$o->rogue_path = $this->msg->rogue_path->jsonSerialize();
|
2021-08-29 13:58:12 +00:00
|
|
|
$o->seenby = $this->msg->seenaddress->jsonSerialize();
|
|
|
|
$o->rogue_seen = $this->msg->rogue_seen->jsonSerialize();
|
2021-08-19 13:35:48 +00:00
|
|
|
$o->toexport = TRUE;
|
2021-07-30 14:35:52 +00:00
|
|
|
|
|
|
|
$o->save();
|
|
|
|
|
2021-08-19 13:35:48 +00:00
|
|
|
Log::info(sprintf('%s: - Echomail [%s] in [%s] from (%s) [%s] to (%s) - [%s].',
|
|
|
|
self::LOGKEY,
|
|
|
|
$this->msg->msgid,
|
|
|
|
$this->msg->echoarea,
|
|
|
|
$this->msg->user_to,$this->msg->tftn,
|
|
|
|
$this->msg->user_from,
|
|
|
|
$o->id,
|
|
|
|
));
|
|
|
|
|
2021-07-30 14:35:52 +00:00
|
|
|
// If the message is to a bot, we'll process it
|
|
|
|
foreach (config('process.echomail') as $class) {
|
|
|
|
if ($class::handle($this->msg)) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2021-07-15 14:54:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|