Attempt to work out a packets domain from a nodes addresses for looking at a default
This commit is contained in:
parent
0c51b17e6c
commit
3b86f76f51
@ -3,6 +3,7 @@
|
|||||||
namespace App\Classes\FTN;
|
namespace App\Classes\FTN;
|
||||||
|
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
|
use Illuminate\Database\Eloquent\ModelNotFoundException;
|
||||||
use Illuminate\Support\Arr;
|
use Illuminate\Support\Arr;
|
||||||
use Illuminate\Support\Collection;
|
use Illuminate\Support\Collection;
|
||||||
use Illuminate\Support\Facades\Log;
|
use Illuminate\Support\Facades\Log;
|
||||||
@ -11,7 +12,7 @@ use Symfony\Component\HttpFoundation\File\File;
|
|||||||
|
|
||||||
use App\Classes\FTN as FTNBase;
|
use App\Classes\FTN as FTNBase;
|
||||||
use App\Exceptions\InvalidPacketException;
|
use App\Exceptions\InvalidPacketException;
|
||||||
use App\Models\{Address,Domain,Echomail,Netmail,Software,System,Zone};
|
use App\Models\{Address,Echomail,Netmail,Software,System,Zone};
|
||||||
use App\Notifications\Netmails\{EchomailBadAddress,NetmailBadAddress};
|
use App\Notifications\Netmails\{EchomailBadAddress,NetmailBadAddress};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -87,11 +88,11 @@ abstract class Packet extends FTNBase implements \Iterator, \Countable
|
|||||||
* @param mixed $f File handler returning packet data
|
* @param mixed $f File handler returning packet data
|
||||||
* @param string $name
|
* @param string $name
|
||||||
* @param int $size
|
* @param int $size
|
||||||
* @param Domain|null $domain
|
* @param System|null $so - The system that sent us the packet, used to figure out domains if the packet is for a different zone
|
||||||
* @return Packet
|
* @return Packet
|
||||||
* @throws InvalidPacketException
|
* @throws InvalidPacketException
|
||||||
*/
|
*/
|
||||||
public static function process(mixed $f,string $name,int $size,Domain $domain=NULL): self
|
public static function process(mixed $f,string $name,int $size,System $so=NULL): self
|
||||||
{
|
{
|
||||||
Log::debug(sprintf('%s:+ Opening Packet [%s] with size [%d]',self::LOGKEY,$name,$size));
|
Log::debug(sprintf('%s:+ Opening Packet [%s] with size [%d]',self::LOGKEY,$name,$size));
|
||||||
|
|
||||||
@ -140,22 +141,29 @@ abstract class Packet extends FTNBase implements \Iterator, \Countable
|
|||||||
|
|
||||||
Log::info(sprintf('%s:- Packet [%s] is a [%s] packet',self::LOGKEY,$o->name,get_class($o)));
|
Log::info(sprintf('%s:- Packet [%s] is a [%s] packet',self::LOGKEY,$o->name,get_class($o)));
|
||||||
|
|
||||||
// Work out the packet zone
|
if ($o->fz && ($o->fd || $so)) {
|
||||||
if ($o->fz && ($o->fd || $domain)) {
|
Log::alert(sprintf('%s:! No domain in the packet, work it out from the system [%d] for zone [%d]',self::LOGKEY,$so->name,$o->fz));
|
||||||
$o->zone = Zone::select('zones.*')
|
|
||||||
->join('domains',['domains.id'=>'zones.domain_id'])
|
if (($x=$so->zones->where('zone_id',$o->fz)->unique('domain_id'))->count() === 1) {
|
||||||
->where('zone_id',$o->fz)
|
$o->zone = $x->pop();
|
||||||
->where('name',$o->fd ?: $domain->name)
|
|
||||||
->single();
|
} else {
|
||||||
|
Log::alert(sprintf('%s:! Node [%s] has two zones with [%d]',self::LOGKEY,$so->name,$o->fz));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// If zone is not set, then we need to use a default zone - the messages may not be from this zone.
|
// If zone is not set, then we need to use a default zone - the messages may not be from this zone.
|
||||||
if (empty($o->zone)) {
|
if (empty($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));
|
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));
|
||||||
|
|
||||||
|
try {
|
||||||
$o->zone = Zone::where('zone_id',$o->fz)
|
$o->zone = Zone::where('zone_id',$o->fz)
|
||||||
->where('default',TRUE)
|
->where('default',TRUE)
|
||||||
->singleOrFail();
|
->singleOrFail();
|
||||||
|
|
||||||
|
} catch (ModelNotFoundException $e) {
|
||||||
|
throw new InvalidPacketException(sprintf('%s:! We couldnt work out the packet zone, and there isnt a default for[%d]',self::LOGKEY,$o->fz));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Log::info(sprintf('%s:- Packet Dated [%s] from [%s] to [%s]',self::LOGKEY,$o->date,$o->fftn_t,$o->tftn_t));
|
Log::info(sprintf('%s:- Packet Dated [%s] from [%s] to [%s]',self::LOGKEY,$o->date,$o->fftn_t,$o->tftn_t));
|
||||||
@ -186,7 +194,7 @@ abstract class Packet extends FTNBase implements \Iterator, \Countable
|
|||||||
}
|
}
|
||||||
|
|
||||||
// If we get here
|
// If we get here
|
||||||
throw new InvalidPacketException(sprintf('Cannot determine END of message/packet: %s|%s',get_class($o),hex_dump($message)));;
|
throw new InvalidPacketException(sprintf('Cannot determine END of message/packet: %s|%s',get_class($o),hex_dump($message)));
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($msgbuf)
|
if ($msgbuf)
|
||||||
|
@ -50,7 +50,7 @@ class PacketInfo extends Command
|
|||||||
}
|
}
|
||||||
|
|
||||||
foreach ($f as $packet) {
|
foreach ($f as $packet) {
|
||||||
$pkt = Packet::process($packet,$x=$f->itemName(),$f->itemSize(),$a?->zone->domain);
|
$pkt = Packet::process($packet,$x=$f->itemName(),$f->itemSize(),$a?->system);
|
||||||
|
|
||||||
$this->alert(sprintf('File Name: %s',$x));
|
$this->alert(sprintf('File Name: %s',$x));
|
||||||
|
|
||||||
|
@ -17,7 +17,7 @@ use League\Flysystem\UnableToMoveFile;
|
|||||||
use App\Classes\File;
|
use App\Classes\File;
|
||||||
use App\Classes\FTN\Packet;
|
use App\Classes\FTN\Packet;
|
||||||
use App\Exceptions\InvalidPacketException;
|
use App\Exceptions\InvalidPacketException;
|
||||||
use App\Models\{Domain,Echomail,Netmail};
|
use App\Models\{Echomail,Netmail,System};
|
||||||
use App\Notifications\Netmails\PacketPasswordInvalid;
|
use App\Notifications\Netmails\PacketPasswordInvalid;
|
||||||
|
|
||||||
class PacketProcess implements ShouldQueue
|
class PacketProcess implements ShouldQueue
|
||||||
@ -27,15 +27,15 @@ class PacketProcess implements ShouldQueue
|
|||||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
||||||
|
|
||||||
private string $filename;
|
private string $filename;
|
||||||
private Domain $do;
|
private System $so;
|
||||||
private Carbon $rcvd_time;
|
private Carbon $rcvd_time;
|
||||||
private bool $interactive;
|
private bool $interactive;
|
||||||
private bool $nobot;
|
private bool $nobot;
|
||||||
|
|
||||||
public function __construct(string $filename,Domain $do,bool $interactive=TRUE,Carbon $rcvd_time=NULL,bool $nobot=FALSE)
|
public function __construct(string $filename,System $so,bool $interactive=TRUE,Carbon $rcvd_time=NULL,bool $nobot=FALSE)
|
||||||
{
|
{
|
||||||
$this->filename = $filename;
|
$this->filename = $filename;
|
||||||
$this->do = $do;
|
$this->so = $so;
|
||||||
$this->interactive = $interactive;
|
$this->interactive = $interactive;
|
||||||
$this->rcvd_time = $rcvd_time ?: Carbon::now();
|
$this->rcvd_time = $rcvd_time ?: Carbon::now();
|
||||||
$this->nobot = $nobot;
|
$this->nobot = $nobot;
|
||||||
@ -71,7 +71,7 @@ class PacketProcess implements ShouldQueue
|
|||||||
|
|
||||||
foreach ($f as $packet) {
|
foreach ($f as $packet) {
|
||||||
try {
|
try {
|
||||||
$pkt = Packet::process($packet,Arr::get(stream_get_meta_data($packet),'uri'),$f->itemSize(),$this->do);
|
$pkt = Packet::process($packet,Arr::get(stream_get_meta_data($packet),'uri'),$f->itemSize(),$this->so);
|
||||||
|
|
||||||
// Check that the packet is from a system that is defined in the DB
|
// Check that the packet is from a system that is defined in the DB
|
||||||
if (! $pkt->fftn) {
|
if (! $pkt->fftn) {
|
||||||
@ -81,7 +81,7 @@ class PacketProcess implements ShouldQueue
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (! our_nodes($pkt->fftn->zone->domain)->contains($pkt->fftn)) {
|
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] for [%s]',self::LOGKEY,$this->filename,$pkt->fftn_t,$this->do->name));
|
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 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
|
// @todo Parse the packet for netmails and process them. We'll only accept netmails to us, and ignore all others
|
||||||
|
Loading…
Reference in New Issue
Block a user