Process packet seenby/path/via lines when saving echomail/netmail
This commit is contained in:
@@ -5,12 +5,13 @@ namespace App\Classes\FTN;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Support\Arr;
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Support\Facades\Notification;
|
||||
use Symfony\Component\HttpFoundation\File\File;
|
||||
|
||||
use App\Classes\FTN as FTNBase;
|
||||
use App\Models\{Address,Software,System,Zone};
|
||||
use App\Models\{Address,Domain,Software,System,Zone};
|
||||
use App\Notifications\Netmails\EchomailBadAddress;
|
||||
|
||||
/**
|
||||
* Represents a Fidonet Packet, that contains an array of messages.
|
||||
@@ -172,11 +173,11 @@ class Packet extends FTNBase implements \Iterator, \Countable
|
||||
* @param mixed $f
|
||||
* @param string $name
|
||||
* @param int $size
|
||||
* @param System|null $system
|
||||
* @param Domain|null $domain
|
||||
* @return Packet
|
||||
* @throws InvalidPacketException
|
||||
*/
|
||||
public static function process(mixed $f,string $name,int $size,System $system=NULL): self
|
||||
public static function process(mixed $f,string $name,int $size,Domain $domain=NULL): self
|
||||
{
|
||||
Log::debug(sprintf('%s:+ Opening Packet [%s] with size [%d]',self::LOGKEY,$name,$size));
|
||||
|
||||
@@ -223,11 +224,29 @@ class Packet extends FTNBase implements \Iterator, \Countable
|
||||
else if (! strlen($x))
|
||||
throw new InvalidPacketException('No message in packet: '.bin2hex($x));
|
||||
|
||||
$o->zone = $system?->zones->firstWhere('zone_id',$o->fz);
|
||||
// Work out the packet zone
|
||||
if ($o->fz && ($o->fd || $domain)) {
|
||||
$o->zone = Zone::select('zones.*')
|
||||
->join('domains',['domains.id'=>'zones.domain_id'])
|
||||
->where('zone_id',$o->fz)
|
||||
->where('name',$o->fd ?: $domain->name)
|
||||
->single();
|
||||
|
||||
// If zone is null, we'll take the zone from the packet
|
||||
if (! $o->zone)
|
||||
$o->zone = Zone::where('zone_id',$o->fz)->where('default',TRUE)->single();
|
||||
// We need not knowing the domain, we use the default zone
|
||||
} else {
|
||||
$o->zone = Zone::where('zone_id',$o->fz)
|
||||
->where('default',TRUE)
|
||||
->single();
|
||||
}
|
||||
|
||||
// If zone is not set, then we need to use a default zone - the messages may not be from this zone.
|
||||
if (! $o->zone) {
|
||||
Log::alert(sprintf('%s:! We couldnt work out the packet zone, so we have fallen back to the default for [%d]',self::LOGKEY,$o->fz));
|
||||
|
||||
$o->zone = Zone::where('zone_id',$o->fz)
|
||||
->where('default',TRUE)
|
||||
->singleOrFail();
|
||||
}
|
||||
|
||||
$buf_ptr = 0;
|
||||
$message = '';
|
||||
@@ -415,15 +434,27 @@ class Packet extends FTNBase implements \Iterator, \Countable
|
||||
*/
|
||||
private function parseMessage(string $message): void
|
||||
{
|
||||
Log::info(sprintf('%s:+ Processing message [%d] bytes',self::LOGKEY,strlen($message)));
|
||||
Log::info(sprintf('%s:+ Processing packet message [%d] bytes',self::LOGKEY,strlen($message)));
|
||||
|
||||
$msg = Message::parseMessage($message,$this->zone);
|
||||
|
||||
// If the message from domain is different to the packet address domain, we'll skip this message
|
||||
|
||||
// If the message is invalid, we'll ignore it
|
||||
if ($msg->errors) {
|
||||
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 the messages is not for the right zone, we'll ignore it
|
||||
if ($msg->errors->messages()->has('invalid-zone')) {
|
||||
Log::alert(sprintf('%s:! Message is from an invalid zone [%s], packet is from [%s] - ignoring it',self::LOGKEY,$msg->fftn,$msg->zone->domain->name));
|
||||
|
||||
if (! $msg->rescanned->count())
|
||||
Notification::route('netmail',$this->fftn_o)->notify(new EchomailBadAddress($msg));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// If the to address doenst exist, we'll create a new entry
|
||||
if ($msg->errors->messages()->has('to') && $msg->tzone) {
|
||||
try {
|
||||
// @todo Need to work out the correct region for the host_id
|
||||
@@ -450,15 +481,13 @@ class Packet extends FTNBase implements \Iterator, \Countable
|
||||
$ao->role = Address::NODE_UNKNOWN;
|
||||
|
||||
$so = System::createUnknownSystem();
|
||||
// @todo Remove this debugging line
|
||||
if ($so->id !== 443)
|
||||
Log::alert(sprintf('%s:? Just created Discovered System for MSGID [%s] A',self::LOGKEY,$msg->msgid));
|
||||
|
||||
$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 the from address doenst exist, we'll create a new entry
|
||||
if ($msg->errors->messages()->has('from') && $msg->tzone) {
|
||||
try {
|
||||
// @todo Need to work out the correct region for the host_id
|
||||
@@ -485,9 +514,6 @@ class Packet extends FTNBase implements \Iterator, \Countable
|
||||
$ao->role = Address::NODE_UNKNOWN;
|
||||
|
||||
$so = System::createUnknownSystem();
|
||||
// @todo Remvoe this debugging line
|
||||
if ($so->id !== 443)
|
||||
Log::alert(sprintf('%s:? Just created Discovered System for MSGID [%s] B',self::LOGKEY,$msg->msgid));
|
||||
|
||||
$so->addresses()->save($ao);
|
||||
|
||||
|
Reference in New Issue
Block a user