Change the way we figure out zones in packets, some packet testing, fix Echomail import

This commit is contained in:
Deon George
2021-08-29 23:58:12 +10:00
parent 271f066667
commit 9fb6d191d0
11 changed files with 218 additions and 48 deletions

View File

@@ -10,7 +10,7 @@ use Illuminate\Support\Facades\Validator;
use Illuminate\Validation\Validator as ValidatorResult;
use App\Classes\FTN as FTNBase;
use App\Models\{Address,Domain};
use App\Models\{Address,Zone};
use App\Rules\TwoByteInteger;
use App\Traits\EncodeUTF8;
@@ -163,9 +163,9 @@ class Message extends FTNBase
0xfc => 0x207f, 0xfd => 0x00b2, 0xfe => 0x25a0, 0xff => 0x00a0,
];
public function __construct(Domain $domain=NULL)
public function __construct(Zone $zone=NULL)
{
$this->domain = $domain;
$this->zone = $zone;
$this->header = [];
$this->kludge = collect();
@@ -204,9 +204,9 @@ class Message extends FTNBase
* @return Message
* @throws InvalidPacketException
*/
public static function parseMessage(string $msg,Domain $domain=NULL): self
public static function parseMessage(string $msg,Zone $zone=NULL): self
{
$o = new self($domain);
$o = new self($zone);
try {
$o->header = unpack(self::unpackheader(self::header),substr($msg,0,self::HEADER_LEN));
@@ -246,7 +246,7 @@ class Message extends FTNBase
$o->unpackMessage(substr($msg,self::HEADER_LEN+$ptr));
if (($x=$o->validate($domain))->fails()) {
if (($x=$o->validate())->fails()) {
Log::debug('Message fails validation',['result'=>$x->errors()]);
//throw new \Exception('Message validation fails:'.join(' ',$x->errors()->all()));
}
@@ -651,7 +651,7 @@ class Message extends FTNBase
* Extract information out of the message text.
*
* @param string $message
* @throws InvalidPacketException
* @throws \Exception
*/
public function unpackMessage(string $message): void
{
@@ -690,11 +690,13 @@ class Message extends FTNBase
preg_match('/^.*\((.*)\)$/',$this->origin,$matches);
// Double check we have an address in the origin line
if (! Arr::get($matches,1))
throw new InvalidPacketException('No address in Origin?');
if (! Arr::get($matches,1)) {
Log::error(sprintf('%s:! Origin line doesnt have an address',self::LOGKEY));
// Double check, our src and origin match
$this->src = Address::parseFTN($matches[1]);
} else {
// Double check, our src and origin match
$this->src = Address::parseFTN($matches[1]);
}
// We'll double check our FTN
if ($this->isNetmail() && (($this->src['n'] !== $this->fn) || ($this->src['f'] !== $this->ff))) {
@@ -758,6 +760,9 @@ class Message extends FTNBase
elseif ($t = $this->kludge('PATH: ',$v))
$this->path->push($t);
elseif ($t = $this->kludge('SEEN-BY: ',$v))
$this->seenby->push($t);
// To Point: <SOH>TOPT <point number><CR>
elseif ($t = $this->kludge('TOPT ',$v))
$this->point['dst'] = $t;
@@ -777,6 +782,14 @@ class Message extends FTNBase
$m = [];
if ($this->msgid && preg_match('#([0-9]+:[0-9]+/[0-9]+)?\.?([0-9]+)?@?([A-Za-z-_~]+)?\ +#',$this->msgid,$m)) {
$this->src = Address::parseFTN($m[1].((isset($m[2]) && $m[2] != '') ? '.'.$m[2] : '').(isset($m[3]) ? '@'.$m[3] : ''));
// Without a MSGID, get our domain from the origin
} elseif ($this->origin && preg_match('#\(([0-9]+:[0-9]+/[0-9]+)?\.?([0-9]+)?@?([A-Za-z-_~]+)?\)$#',$this->origin,$m)) {
$this->src = Address::parseFTN($m[1].((isset($m[2]) && $m[2] != '') ? '.'.$m[2] : '').(isset($m[3]) ? '@'.$m[3] : ''));
// Otherwise get it from our zone object and packet header
} elseif ($this->zone) {
$this->src = Address::parseFTN(sprintf('%d:%d/%d.%d',$this->zone->zone_id,$this->fn,$this->ff,$this->fp));
}
// Parse SEEN-BY
@@ -793,7 +806,7 @@ class Message extends FTNBase
*
* @return \Illuminate\Contracts\Validation\Validator
*/
public function validate(Domain $domain=NULL): ValidatorResult
public function validate(): ValidatorResult
{
// Check lengths
$validator = Validator::make([
@@ -820,18 +833,16 @@ class Message extends FTNBase
'flags' => 'required|numeric',
'cost' => 'required|numeric',
'echoarea' => 'nullable|max:'.self::AREATAG_LEN,
'ozone' => ['required',$this->domain ? 'in:'.$x=$this->domain->zones->pluck('zone_id')->join(','): ''],
'dzone' => ['required',$this->domain ? 'in:'.$x : '']
'ozone' => ['required'],
'dzone' => ['required']
]);
if ($domain) {
$validator->after(function($validator) {
if (! $this->fboss_o)
$validator->errors()->add('from',sprintf('Undefined Node [%s] sent message.',$this->fboss));
if (! $this->tboss_o)
$validator->errors()->add('to',sprintf('Undefined Node [%s] for destination.',$this->tboss));
});
}
$validator->after(function($validator) {
if (! $this->fboss_o)
$validator->errors()->add('from',sprintf('Undefined Node [%s] sent message.',$this->fboss));
if (! $this->tboss_o)
$validator->errors()->add('to',sprintf('Undefined Node [%s] for destination.',$this->tboss));
});
if ($validator->fails())
$this->errors = $validator;