Improvements to working out region for new addresses, Bounce netmails to a invalid address (that we would host)
This commit is contained in:
parent
058b4ac4b9
commit
2c1ab88bbd
@ -189,7 +189,7 @@ abstract class Packet extends FTNBase implements \Iterator, \Countable
|
||||
$msgbuf = substr($msgbuf,$end+3);
|
||||
continue;
|
||||
|
||||
// If we have more to read
|
||||
// If we have more to read
|
||||
} elseif ($read_ptr < $size) {
|
||||
continue;
|
||||
}
|
||||
@ -430,10 +430,27 @@ abstract class Packet extends FTNBase implements \Iterator, \Countable
|
||||
|
||||
// If the $msg->tftn doesnt exist, we'll need to create it
|
||||
if ($msg->errors->has('to') && $this->tftn && $this->tftn->zone_id) {
|
||||
Log::debug(sprintf('%s:^ To address [%s] doesnt exist, it needs to be created',self::LOGKEY,$msg->set->get('set_tftn')));
|
||||
|
||||
$ao = Address::findFTN($msg->set->get('set_tftn'),TRUE,TRUE);
|
||||
|
||||
// If this is a netmail message, to a non existant address, we need to bounce it
|
||||
if (($msg instanceof Netmail)) {
|
||||
if ((! $ao) && our_address()->contains(Address::newFTN($msg->set_tftn)?->parent())) {
|
||||
Log::alert(sprintf('%s:^ To address [%s] doesnt exist, netmail will be bounced',self::LOGKEY,$msg->set->get('set_tftn')));
|
||||
|
||||
$this->messages->push($msg);
|
||||
return;
|
||||
|
||||
// If this is a netmail message, to a non existant address, we need to bounce it
|
||||
} elseif ($ao && (! $ao->active) && our_address()->contains($ao->parent())) {
|
||||
Log::alert(sprintf('%s:^ To address [%s] isnt active, netmail will be bounced',self::LOGKEY,$msg->set->get('set_tftn')));
|
||||
|
||||
$this->messages->push($msg);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
Log::debug(sprintf('%s:^ To address [%s] doesnt exist, it needs to be created',self::LOGKEY,$msg->set->get('set_tftn')));
|
||||
|
||||
if ($ao?->exists && ($ao->zone?->domain_id !== $this->tftn->zone->domain_id)) {
|
||||
Log::alert(sprintf('%s:! To address [%s] domain [%d] doesnt match packet domain [%d]?',self::LOGKEY,$msg->set->get('set_tftn'),$ao->zone?->domain_id,$this->fftn->zone->domain_id));
|
||||
|
||||
@ -442,7 +459,7 @@ abstract class Packet extends FTNBase implements \Iterator, \Countable
|
||||
|
||||
if (! $ao) {
|
||||
$so = System::createUnknownSystem();
|
||||
$ao = Address::createFTN($msg->set->get('set_fftn'),$so);
|
||||
$ao = Address::createFTN($msg->set->get('set_tftn'),$so);
|
||||
|
||||
Log::alert(sprintf('%s:- To FTN [%s] is not defined, created new entry for (%d)',self::LOGKEY,$msg->set->get('set_tftn'),$ao->id));
|
||||
}
|
||||
|
@ -77,7 +77,7 @@ class PacketInfo extends Command
|
||||
if ($msg instanceof Echomail)
|
||||
$this->warn(sprintf(' - To : %s',$msg->to));
|
||||
else
|
||||
$this->warn(sprintf(' - To : %s (%s)',$msg->to,$msg->tftn->ftn));
|
||||
$this->warn(sprintf(' - To : %s (%s)',$msg->to,$msg->tftn?->ftn ?: $msg->set_tftn));
|
||||
$this->warn(sprintf(' - Subject: %s',$msg->subject));
|
||||
if ($msg instanceof Echomail)
|
||||
$this->warn(sprintf(' - Area : %s',$msg->echoarea->name));
|
||||
|
@ -17,8 +17,8 @@ use League\Flysystem\UnableToMoveFile;
|
||||
use App\Classes\File;
|
||||
use App\Classes\FTN\Packet;
|
||||
use App\Exceptions\InvalidPacketException;
|
||||
use App\Models\{Echomail,Netmail,System};
|
||||
use App\Notifications\Netmails\{PacketPasswordInvalid,UnexpectedPacketFromYou};
|
||||
use App\Models\{Address,Echomail,Netmail,System};
|
||||
use App\Notifications\Netmails\{NetmailNoDestination,PacketPasswordInvalid,UnexpectedPacketFromYou};
|
||||
|
||||
class PacketProcess implements ShouldQueue
|
||||
{
|
||||
@ -119,10 +119,20 @@ class PacketProcess implements ShouldQueue
|
||||
|
||||
$count = 0;
|
||||
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));
|
||||
if ($msg instanceof Netmail) {
|
||||
Log::info(sprintf('%s:- Netmail from [%s] to [%s]',self::LOGKEY,$msg->fftn->ftn,$msg->tftn?->ftn ?: $msg->set_tftn));
|
||||
|
||||
elseif ($msg instanceof Echomail) {
|
||||
// If we dont have a destination, we need to bounce it, if we would be the parent of the address
|
||||
if ((! $msg->tftn) && our_address()->contains(Address::newFTN($msg->set_tftn)?->parent())) {
|
||||
Log::alert(sprintf('%s:! Netmail destination [%s] doesnt exist, bouncing back to [%s]',self::LOGKEY,$msg->set_tftn,$pkt->fftn->ftn));
|
||||
|
||||
Notification::route('netmail',$msg->fftn)->notify(new NetmailNoDestination($msg));
|
||||
$count++;
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
} elseif ($msg instanceof Echomail) {
|
||||
Log::info(sprintf('%s:- Echomail from [%s]',self::LOGKEY,$msg->fftn->ftn));
|
||||
|
||||
if ($netmail_only) {
|
||||
|
@ -355,7 +355,6 @@ class Address extends Model
|
||||
// Work out region
|
||||
$region_id = NULL;
|
||||
$zone_id = NULL;
|
||||
|
||||
// We can only work out region/zone if we have a domain - this is for 2D parsing
|
||||
if ($matches[5] ?? NULL) {
|
||||
$o = new self;
|
||||
@ -1357,7 +1356,7 @@ class Address extends Model
|
||||
case self::NODE_HC: // NC
|
||||
return self::active()
|
||||
->where('zone_id',$this->zone_id)
|
||||
->where('region_id',$this->region_id)
|
||||
->when($this->region_id,fn($q)=>$q->where('region_id',$this->region_id))
|
||||
->where('host_id',$this->host_id)
|
||||
->where('node_id',0)
|
||||
->where('point_id',0)
|
||||
@ -1393,7 +1392,7 @@ class Address extends Model
|
||||
*/
|
||||
private function session(string $type): ?string
|
||||
{
|
||||
return ($this->exists && ($x=$this->system->sessions->where('id',$this->zone_id)->first())) ? ($x->pivot->{$type} ?: '') : NULL;
|
||||
return ($x=$this->system?->sessions->where('id',$this->zone_id)->first()) ? ($x->pivot->{$type} ?: '') : NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -72,7 +72,7 @@ abstract class Netmails extends Notification //implements ShouldQueue
|
||||
|
||||
protected function sourceSummary(Echomail|Netmail $o,string $item=NULL): string
|
||||
{
|
||||
return sprintf("The %s was received here on [%s] and it looks like your system sent it on [%s].",
|
||||
return sprintf("The %s was processed here on [%s] and it looks like your system sent it on [%s].",
|
||||
$item ?: sprintf('%s with ID [%s] to [%s]',$o instanceof Netmail ? 'Netmail' : 'Echomail',$o->msgid,$o->to),
|
||||
Carbon::now()->utc()->toDateTimeString(),
|
||||
$o->date->utc()->toDateTimeString(),
|
||||
|
@ -5,7 +5,7 @@ namespace App\Notifications\Netmails;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
use App\Notifications\Netmails;
|
||||
use App\Models\{Echomail,Netmail};
|
||||
use App\Models\Netmail;
|
||||
use App\Traits\{MessagePath,PageTemplate};
|
||||
|
||||
class NetmailBadAddress extends Netmails
|
||||
|
65
app/Notifications/Netmails/NetmailNoDestination.php
Normal file
65
app/Notifications/Netmails/NetmailNoDestination.php
Normal file
@ -0,0 +1,65 @@
|
||||
<?php
|
||||
|
||||
namespace App\Notifications\Netmails;
|
||||
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
use App\Notifications\Netmails;
|
||||
use App\Models\Netmail;
|
||||
use App\Traits\{MessagePath,PageTemplate};
|
||||
|
||||
class NetmailNoDestination extends Netmails
|
||||
{
|
||||
use MessagePath,PageTemplate;
|
||||
|
||||
private const LOGKEY = 'NND';
|
||||
|
||||
private Netmail $mo;
|
||||
|
||||
/**
|
||||
* Send a sysop a message if they give us a message with a bad address in it.
|
||||
*
|
||||
* @param Netmail $mo
|
||||
*/
|
||||
public function __construct(Netmail $mo)
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
$this->mo = $mo;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 NO DESTINATION netmail to [%s]',self::LOGKEY,$ao->ftn));
|
||||
|
||||
$o->subject = sprintf('Bad destination for netmail [%s]',$this->mo->msgid);
|
||||
|
||||
// Message
|
||||
$msg = $this->page(FALSE,'nodest');
|
||||
|
||||
$msg->addText($this->sourceSummary($this->mo)."\r\r");
|
||||
|
||||
$msg->addText(sprintf("The TO address [%s] in this netmail doesnt exist for the domain [%s].\r\r",$this->mo->get_tftn,$ao->zone->domain->name));
|
||||
|
||||
$msg->addText("This netmail has been rejected and not stored here - so no downstream node will receive it. If you think this is a mistake, please let me know.\r\r");
|
||||
|
||||
$msg->addText($this->message_path($this->mo));
|
||||
|
||||
$o->msg = $msg->render();
|
||||
$o->set_tagline = 'I enjoyed reading your message, even though nobody else will get it :)';
|
||||
|
||||
$o->save();
|
||||
|
||||
return $o;
|
||||
}
|
||||
}
|
@ -115,7 +115,7 @@
|
||||
FROM: <strong class="highlight">{!! Message::tr($msg->from) !!}</strong> (<strong class="highlight">{{ $msg->fftn ? $msg->fftn->ftn : $msg->fftn_t}}</strong>)
|
||||
</div>
|
||||
<div class="col-4">
|
||||
TO: <strong class="highlight">{!! Message::tr($msg->to) !!}</strong>@if($msg instanceof Netmail) (<strong class="highlight">{{ $msg->tftn ? $msg->tftn->ftn : $msg->tftn_t }}</strong>) @endif
|
||||
TO: <strong class="highlight">{!! Message::tr($msg->to) !!}</strong>@if($msg instanceof Netmail) (<strong class="highlight">{{ $msg->tftn ? $msg->tftn->ftn : ($msg->tftn_t ?: $msg->set_tftn)}}</strong>) @endif
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user