diff --git a/app/Classes/FTN/Process/Netmail/Areafix.php b/app/Classes/FTN/Process/Netmail/Areafix.php index 1da7110..14210f1 100644 --- a/app/Classes/FTN/Process/Netmail/Areafix.php +++ b/app/Classes/FTN/Process/Netmail/Areafix.php @@ -79,8 +79,16 @@ final class Areafix extends Process array_unshift($command,'%AREA'); } - // Parse the message body and pluck out the commands on each line - $class = self::areafix_commands.ucfirst(strtolower(substr($command[0],1))); + // Some commands are reserved words + switch ($x=strtolower(substr($command[0],1))) { + case 'list': + $class = self::areafix_commands.'Arealist'; + break; + + default: + // Parse the message body and pluck out the commands on each line + $class = self::areafix_commands.ucfirst($x); + } if (! class_exists($class)) { $result->push(sprintf('%-25s <-- **COMMAND UNKNOWN**',join(' ',$command))); diff --git a/app/Classes/FTN/Process/Netmail/Robot/Areafix/AreaList.php b/app/Classes/FTN/Process/Netmail/Robot/Areafix/AreaList.php new file mode 100644 index 0000000..e15baa2 --- /dev/null +++ b/app/Classes/FTN/Process/Netmail/Robot/Areafix/AreaList.php @@ -0,0 +1,38 @@ +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/Classes/FTN/Process/Netmail/Robot/Areafix/Rescan.php b/app/Classes/FTN/Process/Netmail/Robot/Areafix/Rescan.php new file mode 100644 index 0000000..ff6b9f4 --- /dev/null +++ b/app/Classes/FTN/Process/Netmail/Robot/Areafix/Rescan.php @@ -0,0 +1,61 @@ + []', + ' Use the rescan command to resend mail from an echoarea.', + ' This is will resend mail again, even if you have received it in the past.', + ' Arguments:', + ' - ECHOAREA (required) name of area to subscribe or unsubscribe', + ' - DAYS (optional) number of days to resend mail from this area that you', + ' If DAYS is omitted, the default is 30', + ]; + } + + public function process(): string + { + Log::debug(sprintf('%s:- Areafix [%s] for [%s] for [%s]',self::LOGKEY,self::command,$this->mo->fftn->ftn,join('|',$this->arguments))); + + $command = self::command.' '.join(' ',$this->arguments); + + if (! is_numeric($this->arguments[1])) + return sprintf('%-25s <-- INVALID, DAYS [%s] NOT NUMERIC',$command,$this->arguments[1]); + + // Area exists + if ($ea=$this->mo->fftn->domain->echoareas->where('name',$this->arguments[0])->pop()) { + // If already subscribed + if ($this->mo->fftn->echoareas->pluck('name')->contains($this->arguments[0])) { + AreafixRescan::dispatch($this->mo->fftn,$ea,$this->arguments[1],TRUE) + ->onQueue('mail'); + + Log::debug(sprintf('%s:- FTN [%s] RESCAN [%s] DAYS [%d]',self::LOGKEY,$this->mo->fftn->ftn,$this->arguments[0],$this->arguments[1])); + + return sprintf('%-25s <-- RESCAN [%d] DAYS queued',$command,$this->arguments[1]); + + // If not subscribed + } else { + Log::debug(sprintf('%s:- FTN [%s] is NOT subscribed to [%s], NO ACTION taken',self::LOGKEY,$this->mo->fftn->ftn,$this->arguments[0])); + + return sprintf('%-25s <-- NOT subscribed, NO ACTION taken',$command); + } + + } else { + Log::debug(sprintf('%s:- FTN [%s] area UNKNOWN [%s], NO ACTION taken',self::LOGKEY,$this->mo->fftn->ftn,$this->arguments[0])); + + return sprintf('%-25s <-- AREA UNKNOWN, NO ACTION TAKEN',$command); + } + } +} \ No newline at end of file diff --git a/app/Classes/FTN/Process/Netmail/Robot/Areafix/Scan.php b/app/Classes/FTN/Process/Netmail/Robot/Areafix/Scan.php index 8d188e0..266fdbb 100644 --- a/app/Classes/FTN/Process/Netmail/Robot/Areafix/Scan.php +++ b/app/Classes/FTN/Process/Netmail/Robot/Areafix/Scan.php @@ -28,7 +28,7 @@ class Scan extends Base public function process(): string { - Log::debug(sprintf('%s:- Areafix [%s] for [%s] for [%s]',self::LOGKEY,self::command,$this->mo->fftn->ftn,join('|',$this->arguments))); + Log::debug(sprintf('%s:- Areafix [%s] for [%s] for [%s]',self::LOGKEY,self::command,$this->mo->fftn->ftn,join('|',$this->arguments))); $command = self::command.' '.join(' ',$this->arguments); @@ -42,6 +42,8 @@ class Scan extends Base AreafixRescan::dispatch($this->mo->fftn,$ea,$this->arguments[1]) ->onQueue('mail'); + Log::debug(sprintf('%s:- FTN [%s] SCAN [%s] DAYS [%d]',self::LOGKEY,$this->mo->fftn->ftn,$this->arguments[0],$this->arguments[1])); + return sprintf('%-25s <-- SCAN [%d] DAYS queued',$command,$this->arguments[1]); // If not subscribed diff --git a/app/Models/Domain.php b/app/Models/Domain.php index 190f4eb..e4c211a 100644 --- a/app/Models/Domain.php +++ b/app/Models/Domain.php @@ -42,12 +42,14 @@ class Domain extends Model public function echoareas() { - return $this->hasMany(Echoarea::class); + return $this->hasMany(Echoarea::class) + ->orderBY('name'); } public function fileareas() { - return $this->hasMany(Filearea::class); + return $this->hasMany(Filearea::class) + ->orderBY('name'); } public function nodelist_filearea() diff --git a/app/Notifications/Netmails/Areafix/AreaList.php b/app/Notifications/Netmails/Areafix/AreaList.php new file mode 100644 index 0000000..5317db5 --- /dev/null +++ b/app/Notifications/Netmails/Areafix/AreaList.php @@ -0,0 +1,104 @@ +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 areafix for a node [%s] LIST processed',self::LOGKEY,$ao->ftn)); + + $o->to = $this->mo->from; + $o->replyid = $this->mo->msgid; + $o->subject = 'Areafix - List'; + + // Message + $msg = $this->page(FALSE,'Areafix'); + + $msg->addText("Here are the list of available echoareas:\r\r\r\r"); + + $areas = $ao->domain + ->echoareas + ->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('-',4), + )); + $msg->addText(sprintf(": : %-10s : %-48s : %-4s :\r",'AREA','DESCRIPTION','MSGS')); + $msg->addText(sprintf(":---:-%s-:-%s-:-%s-:\r", + str_repeat('-',10), + str_repeat('-',48), + str_repeat('-',4), + )); + + foreach ($areas as $eao) { + $msg->addText(sprintf(":%s%s%s: %-10s : %-48s : %4d :\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->messages_count(30), + )); + } + + $msg->addText(sprintf(":---:-%s-:-%s-:-%s-:\r", + str_repeat('-',10), + str_repeat('-',48), + str_repeat('-',4), + )); + + $msg->addText("\r'*' = Subscribed, '+' = available, 'R' = read only, 'W' = write only\r"); + $msg->addText('(MSGS = Messages in the last month)'); + + } 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 robot cross the road? The chicken programmed it.'; + + $o->save(); + + return $o; + } +} \ No newline at end of file