Split out areafix command processing, implemented start of filefix
This commit is contained in:
parent
521a9b0679
commit
b67ae28b98
50
app/Classes/FTN/Process/Netmail/Robot.php
Normal file
50
app/Classes/FTN/Process/Netmail/Robot.php
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Classes\FTN\Process\Netmail;
|
||||||
|
|
||||||
|
use Illuminate\Support\Facades\Notification;
|
||||||
|
use Illuminate\Support\Facades\Log;
|
||||||
|
|
||||||
|
use App\Classes\FTN\Process;
|
||||||
|
use App\Models\{Echomail,Netmail};
|
||||||
|
use App\Notifications\Netmails\Areafix\{InvalidPassword,NotConfiguredHere};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Process messages to Ping
|
||||||
|
*
|
||||||
|
* @package App\Classes\FTN\Process
|
||||||
|
*/
|
||||||
|
abstract class Robot extends Process
|
||||||
|
{
|
||||||
|
private const LOGKEY = 'RPR';
|
||||||
|
|
||||||
|
public static function handle(Echomail|Netmail $mo): bool
|
||||||
|
{
|
||||||
|
if (((strtolower($mo->to) !== 'areafix') && (strtolower($mo->to) !== 'filefix')) || (! ($mo instanceof Netmail)))
|
||||||
|
return FALSE;
|
||||||
|
|
||||||
|
Log::info(sprintf('%s:- Processing *FIX [%s] message from (%s) [%s]',self::LOGKEY,$mo->to,$mo->from,$mo->fftn->ftn));
|
||||||
|
|
||||||
|
// If this is not a node we manage, then respond with a sorry can help you
|
||||||
|
if (! $mo->fftn->system->sessions->count()) {
|
||||||
|
Notification::route('netmail',$mo->fftn)->notify(new NotConfiguredHere($mo));
|
||||||
|
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
// If this nodes password is not correct
|
||||||
|
if ($mo->fftn->pass_fix !== strtoupper($mo->subject)) {
|
||||||
|
Notification::route('netmail',$mo->fftn)->notify(new InvalidPassword($mo));
|
||||||
|
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((strtolower($mo->to) === 'areafix'))
|
||||||
|
return static::areafix($mo);
|
||||||
|
|
||||||
|
if ((strtolower($mo->to) === 'filefix'))
|
||||||
|
return static::filefix($mo);
|
||||||
|
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
}
|
@ -1,55 +1,33 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace App\Classes\FTN\Process\Netmail;
|
namespace App\Classes\FTN\Process\Netmail\Robot;
|
||||||
|
|
||||||
use Illuminate\Support\Facades\Notification;
|
use Illuminate\Support\Facades\Notification;
|
||||||
use Illuminate\Support\Facades\Log;
|
use Illuminate\Support\Facades\Log;
|
||||||
|
|
||||||
use App\Classes\FTN\Process;
|
use App\Classes\FTN\Process\Netmail\Robot;
|
||||||
use App\Classes\FTN\Process\Netmail\Robot\Unknown;
|
|
||||||
use App\Models\{Echomail,Netmail};
|
use App\Models\{Echomail,Netmail};
|
||||||
use App\Notifications\Netmails\FixCantHandle;
|
use App\Notifications\Netmails\Areafix\CommandsProcessed;
|
||||||
use App\Notifications\Netmails\Areafix\{CommandsProcessed,InvalidPassword,NotConfiguredHere};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Process messages to Ping
|
* Process messages to Ping
|
||||||
*
|
*
|
||||||
* @package App\Classes\FTN\Process
|
* @package App\Classes\FTN\Process
|
||||||
*/
|
*/
|
||||||
final class Areafix extends Process
|
final class Areafix extends Robot
|
||||||
{
|
{
|
||||||
private const LOGKEY = 'RP-';
|
private const LOGKEY = 'RPA';
|
||||||
|
|
||||||
public const areafix_commands = 'App\\Classes\\FTN\\Process\\Netmail\\Robot\\Areafix\\';
|
public const commands = 'App\\Classes\\FTN\\Process\\Netmail\\Robot\\Areafix\\';
|
||||||
|
|
||||||
public static function handle(Echomail|Netmail $mo): bool
|
public static function handle(Echomail|Netmail $mo): bool
|
||||||
{
|
{
|
||||||
if (((strtolower($mo->to) !== 'areafix') && (strtolower($mo->to) !== 'filefix')) || (! ($mo instanceof Netmail)))
|
if ((strtolower($mo->to) !== 'areafix') || (! ($mo instanceof Netmail)))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
Log::info(sprintf('%s:- Processing *FIX [%s] message from (%s) [%s]',self::LOGKEY,$mo->to,$mo->from,$mo->fftn->ftn));
|
Log::info(sprintf('%s:- Processing AREAFIX [%s] message from (%s) [%s]', self::LOGKEY, $mo->to, $mo->from, $mo->fftn->ftn));
|
||||||
|
|
||||||
// If this is not a node we manage, then respond with a sorry can help you
|
return parent::handle($mo);
|
||||||
if (! $mo->fftn->system->sessions->count()) {
|
|
||||||
Notification::route('netmail',$mo->fftn)->notify(new NotConfiguredHere($mo));
|
|
||||||
|
|
||||||
return TRUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
// If this nodes password is not correct
|
|
||||||
if ($mo->fftn->pass_fix !== strtoupper($mo->subject)) {
|
|
||||||
Notification::route('netmail',$mo->fftn)->notify(new InvalidPassword($mo));
|
|
||||||
|
|
||||||
return TRUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((strtolower($mo->to) === 'areafix'))
|
|
||||||
return self::areafix($mo);
|
|
||||||
|
|
||||||
if ((strtolower($mo->to) === 'filefix'))
|
|
||||||
return self::filefix($mo);
|
|
||||||
|
|
||||||
return FALSE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function areafix(Netmail $mo): bool
|
public static function areafix(Netmail $mo): bool
|
||||||
@ -72,7 +50,7 @@ final class Areafix extends Process
|
|||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// If command doesnt start with %, its an area
|
// If command doesnt start with %, its an area
|
||||||
} elseif (! str_starts_with($command[0],'%')) {
|
} elseif (! str_starts_with($command[0],'%')) {
|
||||||
Log::info(sprintf('%s:= Assuming command [%s] is an AREA command',self::LOGKEY,$command[0]));
|
Log::info(sprintf('%s:= Assuming command [%s] is an AREA command',self::LOGKEY,$command[0]));
|
||||||
|
|
||||||
@ -82,12 +60,12 @@ final class Areafix extends Process
|
|||||||
// Some commands are reserved words
|
// Some commands are reserved words
|
||||||
switch ($x=strtolower(substr($command[0],1))) {
|
switch ($x=strtolower(substr($command[0],1))) {
|
||||||
case 'list':
|
case 'list':
|
||||||
$class = self::areafix_commands.'AreaList';
|
$class = self::commands.'AreaList';
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
// Parse the message body and pluck out the commands on each line
|
// Parse the message body and pluck out the commands on each line
|
||||||
$class = self::areafix_commands.ucfirst($x);
|
$class = self::commands.ucfirst($x);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (! class_exists($class)) {
|
if (! class_exists($class)) {
|
||||||
@ -112,11 +90,4 @@ final class Areafix extends Process
|
|||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function filefix(Netmail $mo): bool
|
|
||||||
{
|
|
||||||
Notification::route('netmail',$mo->fftn)->notify(new FixCantHandle($mo));
|
|
||||||
|
|
||||||
return TRUE;
|
|
||||||
}
|
|
||||||
}
|
}
|
@ -5,7 +5,7 @@ namespace App\Classes\FTN\Process\Netmail\Robot\Areafix;
|
|||||||
use Illuminate\Support\Facades\Log;
|
use Illuminate\Support\Facades\Log;
|
||||||
use Illuminate\Support\Facades\Notification;
|
use Illuminate\Support\Facades\Notification;
|
||||||
|
|
||||||
use App\Classes\FTN\Process\Netmail\Areafix;
|
use App\Classes\FTN\Process\Netmail\Robot\Areafix;
|
||||||
use App\Notifications\Netmails\Areafix\Help as HelpNotification;
|
use App\Notifications\Netmails\Areafix\Help as HelpNotification;
|
||||||
|
|
||||||
// A Help Index Command
|
// A Help Index Command
|
||||||
@ -33,7 +33,7 @@ class Help extends Base
|
|||||||
if (($file === 'Base.php') || (! str_ends_with(strtolower($file),'.php')))
|
if (($file === 'Base.php') || (! str_ends_with(strtolower($file),'.php')))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
$class = Areafix::areafix_commands.preg_replace('/\.php$/','',$file);
|
$class = Areafix::commands.preg_replace('/\.php$/','',$file);
|
||||||
if ($result->count())
|
if ($result->count())
|
||||||
$result->push('');
|
$result->push('');
|
||||||
|
|
||||||
|
93
app/Classes/FTN/Process/Netmail/Robot/Filefix.php
Normal file
93
app/Classes/FTN/Process/Netmail/Robot/Filefix.php
Normal file
@ -0,0 +1,93 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Classes\FTN\Process\Netmail\Robot;
|
||||||
|
|
||||||
|
use Illuminate\Support\Facades\Notification;
|
||||||
|
use Illuminate\Support\Facades\Log;
|
||||||
|
|
||||||
|
use App\Classes\FTN\Process\Netmail\Robot;
|
||||||
|
use App\Models\{Echomail,Netmail};
|
||||||
|
use App\Notifications\Netmails\Areafix\CommandsProcessed;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Process messages to Ping
|
||||||
|
*
|
||||||
|
* @package App\Classes\FTN\Process
|
||||||
|
*/
|
||||||
|
final class Filefix extends Robot
|
||||||
|
{
|
||||||
|
private const LOGKEY = 'RPF';
|
||||||
|
|
||||||
|
public const commands = 'App\\Classes\\FTN\\Process\\Netmail\\Robot\\Filefix\\';
|
||||||
|
|
||||||
|
public static function handle(Echomail|Netmail $mo): bool
|
||||||
|
{
|
||||||
|
if ((strtolower($mo->to) !== 'filefix') || (! ($mo instanceof Netmail)))
|
||||||
|
return FALSE;
|
||||||
|
|
||||||
|
Log::info(sprintf('%s:- Processing FILEFIX [%s] message from (%s) [%s]', self::LOGKEY, $mo->to, $mo->from, $mo->fftn->ftn));
|
||||||
|
|
||||||
|
return parent::handle($mo);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function filefix(Netmail $mo): bool
|
||||||
|
{
|
||||||
|
$result = collect();
|
||||||
|
$result->push('--> BEGIN <--');
|
||||||
|
|
||||||
|
foreach ($mo->body_lines as $command) {
|
||||||
|
// Skip empty lines
|
||||||
|
if (! $command)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
$command = explode(' ',strtoupper(trim($command)));
|
||||||
|
|
||||||
|
// If command starts with '...' or '---', its a tear/tag line, and we have reached the end
|
||||||
|
if (str_starts_with($command[0],'...') || str_starts_with($command[0],'---')) {
|
||||||
|
Log::debug(sprintf('%s:= We got a tearline/tagline, end of processing',self::LOGKEY));
|
||||||
|
|
||||||
|
$result->push('--> END OF PROCESSING <--');
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
// 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]));
|
||||||
|
|
||||||
|
array_unshift($command,'%AREA');
|
||||||
|
}
|
||||||
|
|
||||||
|
// Some commands are reserved words
|
||||||
|
switch ($x=strtolower(substr($command[0],1))) {
|
||||||
|
case 'list':
|
||||||
|
$class = self::commands.'FileList';
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
// Parse the message body and pluck out the commands on each line
|
||||||
|
$class = self::commands.ucfirst($x);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (! class_exists($class)) {
|
||||||
|
$result->push(sprintf('%-25s <-- **COMMAND UNKNOWN**',join(' ',$command)));
|
||||||
|
Log::info(sprintf('%s:! Command UNKNOWN [%s] ',self::LOGKEY,join('|',$command)),['class'=>$class]);
|
||||||
|
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Drop the command from the array, the rest are arguments
|
||||||
|
array_shift($command);
|
||||||
|
|
||||||
|
// Refresh our echoareas
|
||||||
|
$mo->fftn->load('fileareas');
|
||||||
|
|
||||||
|
$o = new $class($mo,$command);
|
||||||
|
$result->push($o->process());
|
||||||
|
}
|
||||||
|
|
||||||
|
// Reply with a confirmation of what commands were processed
|
||||||
|
Notification::route('netmail',$mo->fftn)->notify(new CommandsProcessed($mo,$result));
|
||||||
|
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
}
|
50
app/Classes/FTN/Process/Netmail/Robot/Filefix/Help.php
Normal file
50
app/Classes/FTN/Process/Netmail/Robot/Filefix/Help.php
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Classes\FTN\Process\Netmail\Robot\Filefix;
|
||||||
|
|
||||||
|
use App\Classes\FTN\Process\Netmail\Robot\Areafix\Base;
|
||||||
|
use Illuminate\Support\Facades\Log;
|
||||||
|
use Illuminate\Support\Facades\Notification;
|
||||||
|
|
||||||
|
use App\Classes\FTN\Process\Netmail\Robot\Filefix;
|
||||||
|
use App\Notifications\Netmails\Filefix\Help as HelpNotification;
|
||||||
|
|
||||||
|
// A Help Index Command
|
||||||
|
class Help extends Base
|
||||||
|
{
|
||||||
|
private const LOGKEY = 'FFH';
|
||||||
|
|
||||||
|
private const filefix_classes = 'app/Classes/FTN/Process/Netmail/Robot/Filefix';
|
||||||
|
private const command = '%HELP';
|
||||||
|
|
||||||
|
public static function help(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
self::command,
|
||||||
|
' This message!',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function process(): string
|
||||||
|
{
|
||||||
|
Log::debug(sprintf('%s:- Processing [%s] for [%s]',self::LOGKEY,self::command,$this->mo->fftn->ftn));
|
||||||
|
|
||||||
|
$result = collect();
|
||||||
|
|
||||||
|
foreach (preg_grep('/^([^.])/',scandir(self::filefix_classes)) as $file) {
|
||||||
|
if (($file === 'Base.php') || (! str_ends_with(strtolower($file),'.php')))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
$class = Filefix::commands.preg_replace('/\.php$/','',$file);
|
||||||
|
if ($result->count())
|
||||||
|
$result->push('');
|
||||||
|
|
||||||
|
$result = $result
|
||||||
|
->merge($class::help());
|
||||||
|
}
|
||||||
|
|
||||||
|
Notification::route('netmail',$this->mo->fftn)->notify(new HelpNotification($this->mo,$result));
|
||||||
|
|
||||||
|
return sprintf('%-25s <-- COMMAND PROCESSED',self::command);
|
||||||
|
}
|
||||||
|
}
|
@ -16,7 +16,7 @@ class Help extends Netmails
|
|||||||
private const LOGKEY = 'ACH';
|
private const LOGKEY = 'ACH';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reply to a areafix, commands unknown.
|
* Reply to an areafix HELP commands.
|
||||||
*
|
*
|
||||||
* @param Netmail $mo
|
* @param Netmail $mo
|
||||||
* @param Collection $commands
|
* @param Collection $commands
|
||||||
|
63
app/Notifications/Netmails/Filefix/Help.php
Normal file
63
app/Notifications/Netmails/Filefix/Help.php
Normal file
@ -0,0 +1,63 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Notifications\Netmails\Filefix;
|
||||||
|
|
||||||
|
use Illuminate\Support\Collection;
|
||||||
|
use Illuminate\Support\Facades\Log;
|
||||||
|
|
||||||
|
use App\Notifications\Netmails;
|
||||||
|
use App\Models\Netmail;
|
||||||
|
use App\Traits\{MessagePath,PageTemplate};
|
||||||
|
|
||||||
|
class Help extends Netmails
|
||||||
|
{
|
||||||
|
use MessagePath,PageTemplate;
|
||||||
|
|
||||||
|
private const LOGKEY = 'FCH';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reply to a filefix HELP commands.
|
||||||
|
*
|
||||||
|
* @param Netmail $mo
|
||||||
|
* @param Collection $commands
|
||||||
|
*/
|
||||||
|
public function __construct(private Netmail $mo,private Collection $commands)
|
||||||
|
{
|
||||||
|
parent::__construct();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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] HELP processed',self::LOGKEY,$ao->ftn));
|
||||||
|
|
||||||
|
$o->to = $this->mo->from;
|
||||||
|
$o->replyid = $this->mo->msgid;
|
||||||
|
$o->subject = 'Filefix - Help';
|
||||||
|
|
||||||
|
// Message
|
||||||
|
$msg = $this->page(FALSE,'Filefix');
|
||||||
|
|
||||||
|
$msg->addText("Here are the list of commands available to you:\r\r\r\r");
|
||||||
|
|
||||||
|
foreach ($this->commands as $command) {
|
||||||
|
$msg->addText("$command\r");
|
||||||
|
}
|
||||||
|
|
||||||
|
$o->msg = $msg->render();
|
||||||
|
$o->set_tagline = 'Why did the chicken cross the road? The robot programmed it.';
|
||||||
|
|
||||||
|
$o->save();
|
||||||
|
|
||||||
|
return $o;
|
||||||
|
}
|
||||||
|
}
|
@ -9,6 +9,7 @@ return [
|
|||||||
// Netmail
|
// Netmail
|
||||||
'robots' => [
|
'robots' => [
|
||||||
\App\Classes\FTN\Process\Netmail\Ping::class,
|
\App\Classes\FTN\Process\Netmail\Ping::class,
|
||||||
\App\Classes\FTN\Process\Netmail\Areafix::class,
|
\App\Classes\FTN\Process\Netmail\Robot\Areafix::class,
|
||||||
|
\App\Classes\FTN\Process\Netmail\Robot\Filefix::class,
|
||||||
],
|
],
|
||||||
];
|
];
|
Loading…
Reference in New Issue
Block a user