2023-09-21 05:25:18 +00:00
|
|
|
<?php
|
|
|
|
|
2024-11-26 01:23:07 +00:00
|
|
|
namespace App\Classes\FTN\Process\Netmail\Robot;
|
2023-09-21 05:25:18 +00:00
|
|
|
|
|
|
|
use Illuminate\Support\Facades\Notification;
|
|
|
|
use Illuminate\Support\Facades\Log;
|
|
|
|
|
2024-11-26 01:23:07 +00:00
|
|
|
use App\Classes\FTN\Process\Netmail\Robot;
|
2024-05-19 13:28:45 +00:00
|
|
|
use App\Models\{Echomail,Netmail};
|
2024-11-26 11:24:19 +00:00
|
|
|
use App\Notifications\Netmails\Filefix\CommandsProcessed;
|
2023-09-21 05:25:18 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Process messages to Ping
|
|
|
|
*
|
|
|
|
* @package App\Classes\FTN\Process
|
|
|
|
*/
|
2024-11-26 01:23:07 +00:00
|
|
|
final class Filefix extends Robot
|
2023-09-21 05:25:18 +00:00
|
|
|
{
|
2024-11-26 01:23:07 +00:00
|
|
|
private const LOGKEY = 'RPF';
|
2023-09-21 05:25:18 +00:00
|
|
|
|
2024-11-26 01:23:07 +00:00
|
|
|
public const commands = 'App\\Classes\\FTN\\Process\\Netmail\\Robot\\Filefix\\';
|
2024-10-31 11:40:58 +00:00
|
|
|
|
2024-05-19 13:28:45 +00:00
|
|
|
public static function handle(Echomail|Netmail $mo): bool
|
2023-09-21 05:25:18 +00:00
|
|
|
{
|
2024-11-26 01:23:07 +00:00
|
|
|
if ((strtolower($mo->to) !== 'filefix') || (! ($mo instanceof Netmail)))
|
2023-09-21 05:25:18 +00:00
|
|
|
return FALSE;
|
|
|
|
|
2024-11-28 11:07:39 +00:00
|
|
|
Log::info(sprintf('%s:- Processing FILEFIX [%s] message from (%s) [%s]',self::LOGKEY,$mo->to,$mo->from,$mo->fftn->ftn));
|
2023-09-21 05:25:18 +00:00
|
|
|
|
2024-11-26 01:23:07 +00:00
|
|
|
return parent::handle($mo);
|
2024-11-01 01:35:36 +00:00
|
|
|
}
|
|
|
|
|
2024-11-26 01:23:07 +00:00
|
|
|
public static function filefix(Netmail $mo): bool
|
2024-11-01 01:35:36 +00:00
|
|
|
{
|
2024-10-31 11:40:58 +00:00
|
|
|
$result = collect();
|
|
|
|
$result->push('--> BEGIN <--');
|
|
|
|
|
|
|
|
foreach ($mo->body_lines as $command) {
|
2024-11-28 11:07:39 +00:00
|
|
|
Log::debug(sprintf('%s:* Processing command [%s]',self::LOGKEY,$command));
|
|
|
|
|
2024-10-31 11:40:58 +00:00
|
|
|
// Skip empty lines
|
2024-11-28 11:07:39 +00:00
|
|
|
if (! $command || preg_match('/^\s+$/',$command))
|
2024-10-31 11:40:58 +00:00
|
|
|
continue;
|
|
|
|
|
2024-11-28 11:07:39 +00:00
|
|
|
$command = explode(' ',strtoupper(rtrim($command)));
|
|
|
|
Log::debug(sprintf('%s:* Processing command',self::LOGKEY),['command'=>$command]);
|
2024-10-31 11:40:58 +00:00
|
|
|
|
|
|
|
// 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],'---')) {
|
2024-11-28 11:07:39 +00:00
|
|
|
Log::info(sprintf('%s:= We got a tearline/tagline, end of processing',self::LOGKEY));
|
|
|
|
|
|
|
|
$result->push('--> END OF PROCESSING - TEARLINE/TAGLINE <--');
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
// Lines starting with a space, we'll abort
|
|
|
|
} elseif (! $command[0]) {
|
|
|
|
Log::info(sprintf('%s:= Got a new line with a space, end of processing',self::LOGKEY));
|
2024-10-31 11:40:58 +00:00
|
|
|
|
2024-11-28 11:07:39 +00:00
|
|
|
$result->push('--> END OF PROCESSING - SPACE DETECTED <--');
|
2024-10-31 11:40:58 +00:00
|
|
|
|
|
|
|
break;
|
|
|
|
|
2024-11-26 01:44:21 +00:00
|
|
|
// If command doesnt start with %, its an area
|
2024-10-31 11:40:58 +00:00
|
|
|
} elseif (! str_starts_with($command[0],'%')) {
|
2024-11-07 01:31:35 +00:00
|
|
|
Log::info(sprintf('%s:= Assuming command [%s] is an AREA command',self::LOGKEY,$command[0]));
|
2024-10-31 11:40:58 +00:00
|
|
|
|
|
|
|
array_unshift($command,'%AREA');
|
|
|
|
}
|
|
|
|
|
2024-11-01 13:10:38 +00:00
|
|
|
// Some commands are reserved words
|
|
|
|
switch ($x=strtolower(substr($command[0],1))) {
|
|
|
|
case 'list':
|
2024-11-26 01:44:21 +00:00
|
|
|
$class = self::commands.'AreaList';
|
2024-11-01 13:10:38 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
// Parse the message body and pluck out the commands on each line
|
2024-11-26 01:23:07 +00:00
|
|
|
$class = self::commands.ucfirst($x);
|
2024-11-01 13:10:38 +00:00
|
|
|
}
|
2024-10-31 11:40:58 +00:00
|
|
|
|
|
|
|
if (! class_exists($class)) {
|
|
|
|
$result->push(sprintf('%-25s <-- **COMMAND UNKNOWN**',join(' ',$command)));
|
2024-11-07 01:31:35 +00:00
|
|
|
Log::info(sprintf('%s:! Command UNKNOWN [%s] ',self::LOGKEY,join('|',$command)),['class'=>$class]);
|
2024-10-31 11:40:58 +00:00
|
|
|
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Drop the command from the array, the rest are arguments
|
|
|
|
array_shift($command);
|
|
|
|
|
|
|
|
// Refresh our echoareas
|
2024-11-26 01:23:07 +00:00
|
|
|
$mo->fftn->load('fileareas');
|
2024-10-31 11:40:58 +00:00
|
|
|
|
2024-10-31 12:53:43 +00:00
|
|
|
$o = new $class($mo,$command);
|
2024-10-31 11:40:58 +00:00
|
|
|
$result->push($o->process());
|
|
|
|
}
|
|
|
|
|
|
|
|
// Reply with a confirmation of what commands were processed
|
2024-11-01 01:35:36 +00:00
|
|
|
Notification::route('netmail',$mo->fftn)->notify(new CommandsProcessed($mo,$result));
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
2023-09-21 05:25:18 +00:00
|
|
|
}
|