From 9f762a642c9df2ab99beadc659783de4bcf8044a Mon Sep 17 00:00:00 2001 From: Deon George Date: Thu, 19 Aug 2021 23:35:48 +1000 Subject: [PATCH] Added SEEN-BY/PATH processing, dont show networks that are not public, minor other formatting --- app/Classes/FTN/Message.php | 61 ++++++++++++++++++++++++- app/Classes/FTN/Packet.php | 4 +- app/Classes/FTN/Process/Ping.php | 5 +- app/Http/Controllers/HomeController.php | 8 +++- app/Jobs/ProcessPacket.php | 25 ++++++---- resources/views/zone/addedit.blade.php | 26 +++++------ 6 files changed, 98 insertions(+), 31 deletions(-) diff --git a/app/Classes/FTN/Message.php b/app/Classes/FTN/Message.php index 3cd5f25..4a6f79f 100644 --- a/app/Classes/FTN/Message.php +++ b/app/Classes/FTN/Message.php @@ -22,6 +22,8 @@ use App\Traits\EncodeUTF8; */ class Message extends FTNBase { + private const LOGKEY = 'FM-'; + use EncodeUTF8; private const cast_utf8 = [ @@ -103,7 +105,11 @@ class Message extends FTNBase private array $point; // Point the message belongs to (Netmail) private Collection $path; // FTS-0004.001 The message PATH lines + private Collection $pathaddress; // Collection of Addresses after parsing seenby + private Collection $rogue_path; // Collection of FTNs in the Seen-by that are not defined private Collection $seenby; // FTS-0004.001 The message SEEN-BY lines + private Collection $seenaddress; // Collection of Addresses after parsing seenby + private Collection $rogue_seen; // Collection of FTNs in the Seen-by that are not defined private Collection $via; // The path the message has gone using Via lines (Netmail) private Collection $unknown; // Temporarily hold attributes we have no logic for. @@ -179,6 +185,8 @@ class Message extends FTNBase $this->path = collect(); $this->seenby = collect(); + $this->rogue_seen = collect(); + $this->rogue_path = collect(); $this->via = collect(); $this->unknown = collect(); } @@ -297,6 +305,10 @@ class Message extends FTNBase case 'kludge': case 'path': case 'seenby': + case 'pathaddress': + case 'seenaddress': + case 'rogue_path': + case 'rogue_seen': case 'via': case 'errors': @@ -436,7 +448,6 @@ class Message extends FTNBase $return .= sprintf(" * Origin: %s\r",$this->origin); } else { - dump([__METHOD__=>'NOT LOCAL']); $return .= $this->message."\r"; } @@ -518,6 +529,46 @@ class Message extends FTNBase return ($this->flags & $flag); } + /** + * Parse the Seenby/path lines and return a collection of addresses + * + * @param string $type + * @param Collection $addresses + * @param Collection $rogue + * @return Collection + * @throws \Exception + */ + private function parseAddresses(string $type,Collection $addresses,Collection &$rogue): Collection + { + $nodes = collect(); + + $net = NULL; + foreach ($addresses as $line) { + foreach (explode(' ',$line) as $item) { + if (($x=strpos($item,'/')) !== FALSE) { + $net = (int)substr($item,0,$x); + $node = (int)substr($item,$x+1); + + } else { + $node = (int)$item; + }; + + $ftn = sprintf('%d:%d/%d',$this->fz,$net&0x7fff,$node&0x7fff); + $ao = Address::findFTN($ftn); + + if (! $ao) { + Log::alert(sprintf('%s:! Undefined Node [%s] in %s.',self::LOGKEY,$ftn,$type)); + $rogue->push($ftn); + + } else { + $nodes->push($ao); + } + } + } + + return $nodes; + } + /** * Process the data after the ORIGIN * There may be kludge lines after the origin - notably SEEN-BY @@ -687,6 +738,14 @@ class Message extends FTNBase else $this->unknown->push(chop($v,"\r")); } + + // Parse SEEN-BY + if ($this->seenby->count()) + $this->seenaddress = $this->parseAddresses('seenby',$this->seenby,$this->rogue_seen); + + // Parse PATH + if ($this->path->count()) + $this->pathaddress = $this->parseAddresses('path',$this->path,$this->rogue_path); } /** diff --git a/app/Classes/FTN/Packet.php b/app/Classes/FTN/Packet.php index 1f03829..ab1f408 100644 --- a/app/Classes/FTN/Packet.php +++ b/app/Classes/FTN/Packet.php @@ -80,7 +80,7 @@ class Packet extends FTNBase */ public static function open(File $file,Domain $domain=NULL): self { - Log::debug(sprintf('%s:Opening Packet [%s]',self::LOGKEY,$file)); + Log::debug(sprintf('%s:+ Opening Packet [%s]',self::LOGKEY,$file)); $f = fopen($file,'r'); $fstat = fstat($f); @@ -366,7 +366,7 @@ class Packet extends FTNBase // If the message is invalid, we'll ignore it if ($msg->errors && $msg->errors->messages()->has('from')) { $this->errors->push($msg); - Log::error(sprintf('%s:%s Skipping...',self::LOGKEY,join('|',$msg->errors->messages()->get('from')))); + Log::error(sprintf('%s:! %s Skipping...',self::LOGKEY,join('|',$msg->errors->messages()->get('from')))); } else { $this->messages->push($msg); diff --git a/app/Classes/FTN/Process/Ping.php b/app/Classes/FTN/Process/Ping.php index 54cbf61..0a09e0d 100644 --- a/app/Classes/FTN/Process/Ping.php +++ b/app/Classes/FTN/Process/Ping.php @@ -33,12 +33,11 @@ final class Ping extends Process $ftns = Setup::findOrFail(config('app.id'))->system->match($msg->fftn_o->zone)->first(); $reply = sprintf("Your ping was received here on %s and it looks like you sent it on %s. If that is correct, then it took %s to get here.\r", - $msg->date->toDateTimeString(), - Carbon::now()->toDateTimeString(), + $msg->date->utc()->toDateTimeString(), + Carbon::now()->utc()->toDateTimeString(), $msg->date->diffForHumans(['parts'=>3,'syntax'=>CarbonInterface::DIFF_ABSOLUTE]) ); - $reply .= "\r"; $reply .= "\r"; $reply .= "Your message travelled along this path on the way here:\r"; foreach ($msg->via as $path) diff --git a/app/Http/Controllers/HomeController.php b/app/Http/Controllers/HomeController.php index 02399f4..c5ea6b5 100644 --- a/app/Http/Controllers/HomeController.php +++ b/app/Http/Controllers/HomeController.php @@ -5,15 +5,19 @@ namespace App\Http\Controllers; use Illuminate\Http\Request; use Illuminate\Support\Collection; use Illuminate\Support\Facades\Auth; +use Illuminate\Support\Facades\DB; +use Illuminate\Support\Facades\Gate; use App\Classes\FTN\Packet; -use App\Models\{Address, Domain, Setup, System}; -use Illuminate\Support\Facades\DB; +use App\Models\{Address,Domain,Setup}; class HomeController extends Controller { public function network(Domain $o) { + if (! $o->public && ! Gate::check('admin',$o)) + abort(404); + $o->load(['zones.system','zones.domain']); return view('domain.view') diff --git a/app/Jobs/ProcessPacket.php b/app/Jobs/ProcessPacket.php index 0f152c3..d205e68 100644 --- a/app/Jobs/ProcessPacket.php +++ b/app/Jobs/ProcessPacket.php @@ -161,14 +161,6 @@ class ProcessPacket implements ShouldQueue // Else we are echomail } else { - Log::info(sprintf('%s: - Echomail [%s] in [%s] from (%s) [%s] to (%s).', - self::LOGKEY, - $this->msg->msgid, - $this->msg->echoarea, - $this->msg->user_to,$this->msg->tftn, - $this->msg->user_from, - )); - $ea = Echoarea::where('name',$this->msg->echoarea) ->where('domain_id',$this->msg->fftn_o->zone->domain_id) ->single(); @@ -191,6 +183,7 @@ class ProcessPacket implements ShouldQueue } // @todo Can the sender create it if it doesnt exist? + // @todo Can the sender send messages to this area? // - Create it, or // - Else record in bad area @@ -207,11 +200,23 @@ class ProcessPacket implements ShouldQueue $o->msgid = $this->msg->msgid; $o->msg = $this->msg->message_src; - // @todo Record Path - // @todo Record SeenBy + $o->path = $this->msg->pathaddress->pluck('id')->jsonSerialize(); + $o->rogue_path = $this->msg->rogue_path->jsonSerialize(); + $o->seenby = $this->msg->seenaddress->pluck('id')->jsonSerialize(); + $o->rogue_seen = $this->msg->rogue_path->jsonSerialize(); + $o->toexport = TRUE; $o->save(); + Log::info(sprintf('%s: - Echomail [%s] in [%s] from (%s) [%s] to (%s) - [%s].', + self::LOGKEY, + $this->msg->msgid, + $this->msg->echoarea, + $this->msg->user_to,$this->msg->tftn, + $this->msg->user_from, + $o->id, + )); + // If the message is to a bot, we'll process it foreach (config('process.echomail') as $class) { if ($class::handle($this->msg)) { diff --git a/resources/views/zone/addedit.blade.php b/resources/views/zone/addedit.blade.php index 367f5a9..3ea2b59 100644 --- a/resources/views/zone/addedit.blade.php +++ b/resources/views/zone/addedit.blade.php @@ -51,6 +51,19 @@
+ +
+
+ active))checked @endif> + + + active))checked @endif> + +
+
+
+ +
@@ -67,19 +80,6 @@
- -
- -
-
- active))checked @endif> - - - active))checked @endif> - -
-
-