From b5e76c77f8b1c5b467074b2a2bc4407a6215bc67 Mon Sep 17 00:00:00 2001 From: Deon George Date: Tue, 26 Nov 2024 12:44:21 +1100 Subject: [PATCH] Added filefix %LIST --- .../FTN/Process/Netmail/Robot/Filefix.php | 4 +- .../Netmail/Robot/Filefix/AreaList.php | 39 +++++++ .../Netmails/Areafix/AreaList.php | 4 +- .../Netmails/Filefix/AreaList.php | 103 ++++++++++++++++++ 4 files changed, 146 insertions(+), 4 deletions(-) create mode 100644 app/Classes/FTN/Process/Netmail/Robot/Filefix/AreaList.php create mode 100644 app/Notifications/Netmails/Filefix/AreaList.php diff --git a/app/Classes/FTN/Process/Netmail/Robot/Filefix.php b/app/Classes/FTN/Process/Netmail/Robot/Filefix.php index 78b0b85..ead72de 100644 --- a/app/Classes/FTN/Process/Netmail/Robot/Filefix.php +++ b/app/Classes/FTN/Process/Netmail/Robot/Filefix.php @@ -50,7 +50,7 @@ final class Filefix extends Robot break; - // If command doesnt start with %, its an area + // If command doesnt start with %, its an area } elseif (! str_starts_with($command[0],'%')) { Log::info(sprintf('%s:= Assuming command [%s] is an AREA command',self::LOGKEY,$command[0])); @@ -60,7 +60,7 @@ final class Filefix extends Robot // Some commands are reserved words switch ($x=strtolower(substr($command[0],1))) { case 'list': - $class = self::commands.'FileList'; + $class = self::commands.'AreaList'; break; default: diff --git a/app/Classes/FTN/Process/Netmail/Robot/Filefix/AreaList.php b/app/Classes/FTN/Process/Netmail/Robot/Filefix/AreaList.php new file mode 100644 index 0000000..48b9eb4 --- /dev/null +++ b/app/Classes/FTN/Process/Netmail/Robot/Filefix/AreaList.php @@ -0,0 +1,39 @@ +mo->fftn->ftn,join('|',$this->arguments))); + + if (count($this->arguments) > 1) + return sprintf('%-25s <-- INVALID COMMAND',self::command); + + else { + Notification::route('netmail',$this->mo->fftn) + ->notify(new AreaListNotification($this->mo)); + + return sprintf('%-25s <-- COMMAND PROCESSED',self::command); + } + } +} \ No newline at end of file diff --git a/app/Notifications/Netmails/Areafix/AreaList.php b/app/Notifications/Netmails/Areafix/AreaList.php index 5317db5..176332e 100644 --- a/app/Notifications/Netmails/Areafix/AreaList.php +++ b/app/Notifications/Netmails/Areafix/AreaList.php @@ -12,12 +12,12 @@ class AreaList extends Netmails { use MessagePath,PageTemplate; - private const LOGKEY = 'ACH'; + private const LOGKEY = 'ACL'; private Netmail $mo; /** - * Reply to a areafix, commands unknown. + * Reply to a areafix AREALIST commands. * * @param Netmail $mo */ diff --git a/app/Notifications/Netmails/Filefix/AreaList.php b/app/Notifications/Netmails/Filefix/AreaList.php new file mode 100644 index 0000000..49d8996 --- /dev/null +++ b/app/Notifications/Netmails/Filefix/AreaList.php @@ -0,0 +1,103 @@ +mo = $mo->withoutRelations(); + } + + /** + * 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:+ Responding to filefix for a node [%s] LIST processed',self::LOGKEY,$ao->ftn)); + + $o->to = $this->mo->from; + $o->replyid = $this->mo->msgid; + $o->subject = 'Filefix - List'; + + // Message + $msg = $this->page(FALSE,'Filefix'); + + $msg->addText("Here are the list of available filereas:\r\r\r\r"); + + $areas = $ao->domain + ->fileareas + ->filter(fn($item)=>$item->active && ($item->can_read($ao->security) || $item->can_write($ao->security))); + + if ($areas->count()) { + $msg->addText(sprintf(":---:-%s-:-%s-:-%s-:\r", + str_repeat('-',10), + str_repeat('-',48), + str_repeat('-',5), + )); + $msg->addText(sprintf(": : %-10s : %-48s : %-5s :\r",'AREA','DESCRIPTION','FILES')); + $msg->addText(sprintf(":---:-%s-:-%s-:-%s-:\r", + str_repeat('-',10), + str_repeat('-',48), + str_repeat('-',5), + )); + + foreach ($areas as $eao) { + $msg->addText(sprintf(":%s%s%s: %-10s : %-48s : %5d :\r", + ($x=$ao->echoareas->contains($eao)) ? '*' : ' ', + (! $x ? '+' : ' '), + ($eao->can_read($ao->security) && (! $eao->can_write($ao->security))) + ? 'R' + : (((! $eao->can_read($ao->security)) && $eao->can_write($ao->security)) ? 'W' : ' '), + $eao->name, + $eao->description, + $eao->files()->count(), + )); + } + + $msg->addText(sprintf(":---:-%s-:-%s-:-%s-:\r", + str_repeat('-',10), + str_repeat('-',48), + str_repeat('-',5), + )); + + $msg->addText("\r'*' = Subscribed, '+' = available, 'R' = read only, 'W' = write only\r"); + + } else { + $msg->addText(sprintf('No areas available to you from domain [%s]',$ao->domain->name)); + } + + $o->msg = $msg->render(); + $o->set_tagline = 'Why did the chicken cross the road? The robot programmed it.'; + + $o->save(); + + return $o; + } +} \ No newline at end of file