From a65e4b8bc3a3dd71889bd950a8480be3306f1995 Mon Sep 17 00:00:00 2001 From: Deon George Date: Wed, 4 Dec 2024 20:28:32 +1100 Subject: [PATCH] Additional syntax validation for areafix/filefix commands --- .../FTN/Process/Netmail/Robot/Areafix/Area.php | 18 +++++++++++------- .../Process/Netmail/Robot/Areafix/Rescan.php | 13 ++++++++----- .../FTN/Process/Netmail/Robot/Areafix/Scan.php | 13 ++++++++----- .../FTN/Process/Netmail/Robot/Filefix/Area.php | 18 +++++++++++------- .../Process/Netmail/Robot/Filefix/Rescan.php | 13 ++++++++----- .../FTN/Process/Netmail/Robot/Filefix/Scan.php | 13 ++++++++----- 6 files changed, 54 insertions(+), 34 deletions(-) diff --git a/app/Classes/FTN/Process/Netmail/Robot/Areafix/Area.php b/app/Classes/FTN/Process/Netmail/Robot/Areafix/Area.php index 19848c0..8ab196e 100644 --- a/app/Classes/FTN/Process/Netmail/Robot/Areafix/Area.php +++ b/app/Classes/FTN/Process/Netmail/Robot/Areafix/Area.php @@ -3,6 +3,7 @@ namespace App\Classes\FTN\Process\Netmail\Robot\Areafix; use Carbon\Carbon; +use Illuminate\Support\Arr; use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Log; @@ -37,18 +38,21 @@ class Area extends Base { $command = self::command.' '.join(' ',$this->arguments); - // If command starts with '-', its to unsubscribe - if (str_starts_with($this->arguments[0],'-')) { - $sub = FALSE; - $area = substr($this->arguments[0],1); + if (! ($area=Arr::get($this->arguments,0,NULL))) + return sprintf('%-25s <-- INVALID, AN AREA IS REQUIRED',$command); - } elseif (str_starts_with($this->arguments[0],'+')) { + // If command starts with '-', its to unsubscribe + if (str_starts_with($area,'-')) { + $sub = FALSE; + $area = substr($area,1); + + } elseif (str_starts_with($area,'+')) { $sub = TRUE; - $area = substr($this->arguments[0],1); + $area = substr($area,1); } else { $sub = TRUE; - $area = $this->arguments[0]; + $area = $area; } Log::debug(sprintf('%s:- Processing [%s] for [%s]',self::LOGKEY,$sub ? 'ADD' : 'REMOVE',$area)); diff --git a/app/Classes/FTN/Process/Netmail/Robot/Areafix/Rescan.php b/app/Classes/FTN/Process/Netmail/Robot/Areafix/Rescan.php index 250201c..5eb1505 100644 --- a/app/Classes/FTN/Process/Netmail/Robot/Areafix/Rescan.php +++ b/app/Classes/FTN/Process/Netmail/Robot/Areafix/Rescan.php @@ -32,29 +32,32 @@ class Rescan extends Base $command = self::command.' '.join(' ',$this->arguments); + if (! ($area=Arr::get($this->arguments,0))) + return sprintf('%-25s <-- INVALID, AN AREA IS REQUIRED',$command); + if (! is_numeric($days=Arr::get($this->arguments,1,30))) 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 ($ea=$this->mo->fftn->domain->echoareas->where('name',$area)->pop()) { // If already subscribed - if ($this->mo->fftn->echoareas->pluck('name')->contains($this->arguments[0])) { + if ($this->mo->fftn->echoareas->pluck('name')->contains($area)) { AreafixRescan::dispatch($this->mo->fftn,$ea,$days,TRUE) ->onQueue('mail'); - Log::debug(sprintf('%s:- FTN [%s] RESCAN [%s] DAYS [%d]',self::LOGKEY,$this->mo->fftn->ftn,$this->arguments[0],$days)); + Log::debug(sprintf('%s:- FTN [%s] RESCAN [%s] DAYS [%d]',self::LOGKEY,$this->mo->fftn->ftn,$area,$days)); return sprintf('%-25s <-- RESCAN [%d] DAYS queued',$command,$days); // 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])); + Log::debug(sprintf('%s:- FTN [%s] is NOT subscribed to [%s], NO ACTION taken',self::LOGKEY,$this->mo->fftn->ftn,$area)); 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])); + Log::debug(sprintf('%s:- FTN [%s] area UNKNOWN [%s], NO ACTION taken',self::LOGKEY,$this->mo->fftn->ftn,$area)); return sprintf('%-25s <-- AREA UNKNOWN, NO ACTION TAKEN',$command); } diff --git a/app/Classes/FTN/Process/Netmail/Robot/Areafix/Scan.php b/app/Classes/FTN/Process/Netmail/Robot/Areafix/Scan.php index f7e4442..a3bbe99 100644 --- a/app/Classes/FTN/Process/Netmail/Robot/Areafix/Scan.php +++ b/app/Classes/FTN/Process/Netmail/Robot/Areafix/Scan.php @@ -33,29 +33,32 @@ class Scan extends Base $command = self::command.' '.join(' ',$this->arguments); + if (! ($area=Arr::get($this->arguments,0))) + return sprintf('%-25s <-- INVALID, AN AREA IS REQUIRED',$command); + if (! is_numeric($days=Arr::get($this->arguments,1,30))) 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 ($ea=$this->mo->fftn->domain->echoareas->where('name',$area)->pop()) { // If already subscribed - if ($this->mo->fftn->echoareas->pluck('name')->contains($this->arguments[0])) { + if ($this->mo->fftn->echoareas->pluck('name')->contains($area)) { AreafixRescan::dispatch($this->mo->fftn,$ea,$days) ->onQueue('mail'); - Log::debug(sprintf('%s:- FTN [%s] SCAN [%s] DAYS [%d]',self::LOGKEY,$this->mo->fftn->ftn,$this->arguments[0],$days)); + Log::debug(sprintf('%s:- FTN [%s] SCAN [%s] DAYS [%d]',self::LOGKEY,$this->mo->fftn->ftn,$area,$days)); return sprintf('%-25s <-- SCAN [%d] DAYS queued',$command,$days); // 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])); + Log::debug(sprintf('%s:- FTN [%s] is NOT subscribed to [%s], NO ACTION taken',self::LOGKEY,$this->mo->fftn->ftn,$area)); 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])); + Log::debug(sprintf('%s:- FTN [%s] area UNKNOWN [%s], NO ACTION taken',self::LOGKEY,$this->mo->fftn->ftn,$area)); return sprintf('%-25s <-- AREA UNKNOWN, NO ACTION TAKEN',$command); } diff --git a/app/Classes/FTN/Process/Netmail/Robot/Filefix/Area.php b/app/Classes/FTN/Process/Netmail/Robot/Filefix/Area.php index 59b9618..afc6b9c 100644 --- a/app/Classes/FTN/Process/Netmail/Robot/Filefix/Area.php +++ b/app/Classes/FTN/Process/Netmail/Robot/Filefix/Area.php @@ -3,6 +3,7 @@ namespace App\Classes\FTN\Process\Netmail\Robot\Filefix; use Carbon\Carbon; +use Illuminate\Support\Arr; use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Log; @@ -38,18 +39,21 @@ class Area extends Base { $command = self::command.' '.join(' ',$this->arguments); - // If command starts with '-', its to unsubscribe - if (str_starts_with($this->arguments[0],'-')) { - $sub = FALSE; - $area = substr($this->arguments[0],1); + if (! ($area=Arr::get($this->arguments,0,NULL))) + return sprintf('%-25s <-- INVALID, AN AREA IS REQUIRED',$command); - } elseif (str_starts_with($this->arguments[0],'+')) { + // If command starts with '-', its to unsubscribe + if (str_starts_with($area,'-')) { + $sub = FALSE; + $area = substr($area,1); + + } elseif (str_starts_with($area,'+')) { $sub = TRUE; - $area = substr($this->arguments[0],1); + $area = substr($area,1); } else { $sub = TRUE; - $area = $this->arguments[0]; + $area = $area; } Log::debug(sprintf('%s:- Processing [%s] for [%s]',self::LOGKEY,$sub ? 'ADD' : 'REMOVE',$area)); diff --git a/app/Classes/FTN/Process/Netmail/Robot/Filefix/Rescan.php b/app/Classes/FTN/Process/Netmail/Robot/Filefix/Rescan.php index 955c02d..a2361da 100644 --- a/app/Classes/FTN/Process/Netmail/Robot/Filefix/Rescan.php +++ b/app/Classes/FTN/Process/Netmail/Robot/Filefix/Rescan.php @@ -34,6 +34,9 @@ class Rescan extends Base $command = self::command.' '.join(' ',$this->arguments); + if (! ($area=Arr::get($this->arguments,0))) + return sprintf('%-25s <-- INVALID, AN AREA IS REQUIRED',$command); + if (! is_numeric($days=Arr::get($this->arguments,1,30))) return sprintf('%-25s <-- INVALID, DAYS [%s] NOT NUMERIC',$command,$this->arguments[1]); @@ -41,25 +44,25 @@ class Rescan extends Base $days = 365; // Area exists - if ($fa=$this->mo->fftn->domain->fileareas->where('name',$this->arguments[0])->pop()) { + if ($fa=$this->mo->fftn->domain->fileareas->where('name',$area)->pop()) { // If already subscribed - if ($this->mo->fftn->fileareas->pluck('name')->contains($this->arguments[0])) { + if ($this->mo->fftn->fileareas->pluck('name')->contains($area)) { FilefixRescan::dispatch($this->mo->fftn,$fa,$days,TRUE) ->onQueue('mail'); - Log::debug(sprintf('%s:- FTN [%s] RESCAN [%s] DAYS [%d]',self::LOGKEY,$this->mo->fftn->ftn,$this->arguments[0],$days)); + Log::debug(sprintf('%s:- FTN [%s] RESCAN [%s] DAYS [%d]',self::LOGKEY,$this->mo->fftn->ftn,$area,$days)); return sprintf('%-25s <-- RESCAN [%d] DAYS queued',$command,$days); // 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])); + Log::debug(sprintf('%s:- FTN [%s] is NOT subscribed to [%s], NO ACTION taken',self::LOGKEY,$this->mo->fftn->ftn,$area)); return sprintf('%-25s <-- NOT subscribed, NO ACTION taken',$command); } } else { - Log::debug(sprintf('%s:- FILE [%s] area UNKNOWN [%s], NO ACTION taken',self::LOGKEY,$this->mo->fftn->ftn,$this->arguments[0])); + Log::debug(sprintf('%s:- FILE [%s] area UNKNOWN [%s], NO ACTION taken',self::LOGKEY,$this->mo->fftn->ftn,$area)); return sprintf('%-25s <-- AREA UNKNOWN, NO ACTION TAKEN',$command); } diff --git a/app/Classes/FTN/Process/Netmail/Robot/Filefix/Scan.php b/app/Classes/FTN/Process/Netmail/Robot/Filefix/Scan.php index 120b04c..8991ef8 100644 --- a/app/Classes/FTN/Process/Netmail/Robot/Filefix/Scan.php +++ b/app/Classes/FTN/Process/Netmail/Robot/Filefix/Scan.php @@ -34,6 +34,9 @@ class Scan extends Base $command = self::command.' '.join(' ',$this->arguments); + if (! ($area=Arr::get($this->arguments,0))) + return sprintf('%-25s <-- INVALID, AN AREA IS REQUIRED',$command); + if (! is_numeric($days=Arr::get($this->arguments,1,30))) return sprintf('%-25s <-- INVALID, DAYS [%s] NOT NUMERIC',$command,$this->arguments[1]); @@ -41,25 +44,25 @@ class Scan extends Base $days = 365; // Area exists - if ($fa=$this->mo->fftn->domain->fileareas->where('name',$this->arguments[0])->pop()) { + if ($fa=$this->mo->fftn->domain->fileareas->where('name',$area)->pop()) { // If already subscribed - if ($this->mo->fftn->fileareas->pluck('name')->contains($this->arguments[0])) { + if ($this->mo->fftn->fileareas->pluck('name')->contains($area)) { FilefixRescan::dispatch($this->mo->fftn,$fa,$days) ->onQueue('mail'); - Log::debug(sprintf('%s:- FTN [%s] SCAN [%s] DAYS [%d]',self::LOGKEY,$this->mo->fftn->ftn,$this->arguments[0],$days)); + Log::debug(sprintf('%s:- FTN [%s] SCAN [%s] DAYS [%d]',self::LOGKEY,$this->mo->fftn->ftn,$area,$days)); return sprintf('%-25s <-- SCAN [%d] DAYS queued',$command,$days); // 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])); + Log::debug(sprintf('%s:- FTN [%s] is NOT subscribed to [%s], NO ACTION taken',self::LOGKEY,$this->mo->fftn->ftn,$area)); return sprintf('%-25s <-- NOT subscribed, NO ACTION taken',$command); } } else { - Log::debug(sprintf('%s:- FILE [%s] area UNKNOWN [%s], NO ACTION taken',self::LOGKEY,$this->mo->fftn->ftn,$this->arguments[0])); + Log::debug(sprintf('%s:- FILE [%s] area UNKNOWN [%s], NO ACTION taken',self::LOGKEY,$this->mo->fftn->ftn,$area)); return sprintf('%-25s <-- AREA UNKNOWN, NO ACTION TAKEN',$command); }