clrghouz/app/Classes/FTN/Process/Netmail/Areafix.php

94 lines
2.8 KiB
PHP

<?php
namespace App\Classes\FTN\Process\Netmail;
use Illuminate\Support\Facades\Notification;
use Illuminate\Support\Facades\Log;
use App\Classes\FTN\Process;
use App\Classes\FTN\Process\Netmail\Robot\Unknown;
use App\Models\{Echomail,Netmail};
use App\Notifications\Netmails\Areafix as AreafixNotification;
/**
* Process messages to Ping
*
* @package App\Classes\FTN\Process
*/
final class Areafix extends Process
{
private const LOGKEY = 'RP-';
private const areafix_commands = 'App\\Classes\\FTN\\Process\\Netmail\\Robot\\Areafix\\';
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 AREAFIX message from (%s) [%s]',self::LOGKEY,$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 AreafixNotification\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 AreafixNotification\InvalidPassword($mo));
return TRUE;
}
$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::debug(sprintf('%s:= Assuming command [%s] is an AREA command',self::LOGKEY,$command[0]));
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)));
if (! class_exists($class)) {
$result->push(sprintf('%-25s <-- **COMMAND UNKNOWN**',join(' ',$command)));
continue;
}
// Drop the command from the array, the rest are arguments
array_shift($command);
// Refresh our echoareas
$mo->fftn->load('echoareas');
$o = new $class($mo->fftn,$command);
$result->push($o->process());
}
// Reply with a confirmation of what commands were processed
Notification::route('netmail',$mo->fftn)->notify(new AreafixNotification\CommandsProcessed($mo,$result));
return TRUE;
}
}