Change how our src is determined in packets, add hexdump to packet debug

This commit is contained in:
Deon George 2021-08-21 00:33:41 +10:00
parent 5243fabd63
commit 68a10af776
4 changed files with 64 additions and 48 deletions

View File

@ -101,8 +101,9 @@ class Message extends FTNBase
private int $tzutc;
private array $zone; // Zone the message belongs to. (src/dst - for netmail)
private array $point; // Point the message belongs to (Netmail)
private array $src; // Address the message is from
private array $dst; // Address the message is to
private Collection $path; // FTS-0004.001 The message PATH lines
private Collection $pathaddress; // Collection of Addresses after parsing seenby
@ -180,7 +181,8 @@ class Message extends FTNBase
$this->tzutc = 0;
$this->zone = [];
$this->src = [];
$this->dst = [];
$this->point = [];
$this->path = collect();
@ -259,17 +261,17 @@ class Message extends FTNBase
{
switch ($key) {
// From Addresses
case 'fz': return Arr::get($this->zone,'src',0);
case 'fn': return Arr::get($this->header,'onet');
case 'ff': return Arr::get($this->header,'onode');
case 'fp': return Arr::get($this->point,'src');
case 'fz': return Arr::get($this->src,'z');
case 'fn': return $this->src ? Arr::get($this->src,'n') : Arr::get($this->header,'onet');;
case 'ff': return $this->src ? Arr::get($this->src,'f') : Arr::get($this->header,'onode');;
case 'fp': return Arr::get($this->src,'p');
// To Addresses
// Echomail doesnt have a zone, so we'll use the source zone
case 'tz': return Arr::get($this->zone,$this->echoarea ? 'src' : 'dst',0);
case 'tn': return Arr::get($this->header,'dnet');
case 'tf': return Arr::get($this->header,'dnode');
case 'tp': return Arr::get($this->point,'dst');
case 'tz': return Arr::get($this->echoarea ? $this->src : $this->dst,'z');
case 'tn': return $this->echoarea ? Arr::get($this->header,'dnet') : Arr::get($this->dst,'n');
case 'tf': return $this->echoarea ? Arr::get($this->header,'dnode') : Arr::get($this->dst,'f');
case 'tp': return Arr::get($this->dst,'p');
case 'fftn':
case 'fftn_o':
@ -277,6 +279,15 @@ class Message extends FTNBase
case 'tftn_o':
return parent::__get($key);
case 'fboss':
return sprintf('%d:%d/%d',$this->fz,$this->fn,$this->ff);
case 'tboss':
return sprintf('%d:%d/%d',$this->tz,$this->tn,$this->tf);
case 'fboss_o':
return Address::findFTN($this->fboss);
case 'tboss_o':
return Address::findFTN($this->tboss);
case 'date':
return Carbon::createFromFormat('d M y H:i:s O',
sprintf('%s %s%04d',chop(Arr::get($this->header,$key)),($this->tzutc < 0) ? '-' : '+',abs($this->tzutc)));
@ -649,18 +660,13 @@ class Message extends FTNBase
throw new InvalidPacketException('No address in Origin?');
// Double check, our src and origin match
$ftn = Address::parseFTN($matches[1]);
$this->src = Address::parseFTN($matches[1]);
// We'll double check our FTN
if ($this->isNetmail() && (($ftn['n'] !== $this->fn) || ($ftn['f'] !== $this->ff))) {
Log::error(sprintf('FTN [%s] doesnt match message header',$matches[1]),['ftn'=>$ftn,'fn'=>$this->fn,'ff'=>$this->ff]);
if ($this->isNetmail() && (($this->src['n'] !== $this->fn) || ($this->src['f'] !== $this->ff))) {
Log::error(sprintf('FTN [%s] doesnt match message header',$matches[1]),['ftn'=>$this->src,'fn'=>$this->fn,'ff'=>$this->ff]);
}
// http://ftsc.org/docs/fsc-0068.001
// MSGID should be the basis of the source
$this->zone['src'] = $ftn['z'];
$this->point['src'] = $ftn['p'];
// The message is the rest?
} elseif (strlen($v) > $x+1) {
$this->message .= substr($v,$x+1);
@ -698,22 +704,14 @@ class Message extends FTNBase
// INTL kludge is in Netmail, so we'll do some validation:
list($dst,$src) = explode(' ',$t);
$ftn = Address::parseFTN($src);
if (($ftn['n'] !== $this->fn) || ($ftn['f'] !== $this->ff)) {
$this->src = Address::parseFTN($src);
if (($this->src['n'] !== $this->fn) || ($this->src['f'] !== $this->ff)) {
Log::error(sprintf('INTL src address [%s] doesnt match packet',$src));
} else {
// We'll set our source zone
$this->zone['src'] = $ftn['z'];
}
$ftn = Address::parseFTN($dst);
if (($ftn['n'] !== $this->tn) || ($ftn['f'] !== $this->tf)) {
$this->dst = Address::parseFTN($dst);
if (($this->dst['n'] !== $this->tn) || ($this->dst['f'] !== $this->tf)) {
Log::error(sprintf('INTL dst address [%s] doesnt match packet',$dst));
} else {
// We'll set our source zone
$this->zone['dst'] = $ftn['z'];
}
}
@ -739,6 +737,12 @@ class Message extends FTNBase
$this->unknown->push(chop($v,"\r"));
}
// Work out our zone/point
// http://ftsc.org/docs/fsc-0068.001
// MSGID should be the basis of the source, we'll overrite our src from origin if we have it
if ($this->msgid)
$this->src = Address::parseFTN(strstr($this->msgid,' ',TRUE));
// Parse SEEN-BY
if ($this->seenby->count())
$this->seenaddress = $this->parseAddresses('seenby',$this->seenby,$this->rogue_seen);
@ -786,10 +790,10 @@ class Message extends FTNBase
if ($domain) {
$validator->after(function($validator) {
if (! Address::findFTN($this->fftn))
$validator->errors()->add('from',sprintf('Undefined Node [%s] sent message.',$this->fftn));
if (! Address::findFTN($this->tftn))
$validator->errors()->add('to',sprintf('Undefined Node [%s] for destination.',$this->fftn));
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));
});
}

View File

@ -68,7 +68,8 @@ class HomeController extends Controller
return view('pkt')
->with('file',$file)
->with('result',$pkt);
->with('result',$pkt)
->with('hexdump',$file ? hex_dump(file_get_contents($file)) : '');
}
/**

View File

@ -142,6 +142,17 @@
</div>
</div>
@endforeach
<h4 class="accordion-header" id="packetdebug" data-bs-toggle="collapse" data-bs-target="#collapse_hex" aria-expanded="false" aria-controls="collapse_hex">
Packet Dump
</h4>
<div id="collapse_hex" class="accordion-collapse collapse" aria-labelledby="packetdebug" data-bs-parent="#accordion_packetdebug">
<div class="accordion-body">
<pre>
{{ $hexdump }}
</pre>
</div>
</div>
</div>
@endif
@endsection