Compare commits

..

No commits in common. "0bbff33fdd5f26cd065a8031cc5b8ba2b61cb89d" and "67dad76bd14fcbf2bc4d6b305078ea902cdff0ec" have entirely different histories.

45 changed files with 376 additions and 775 deletions

View File

@ -794,7 +794,7 @@ class Message extends FTNBase
// Quick validation that we are done
if ($ptr_content_start !== strlen($content)) {
Log::alert(sprintf('%s:! We failed parsing the message start [%d] content [%d]',self::LOGKEY,$ptr_content_start,strlen($content)));
Log::alert(sprintf('%s:! We failed parsing the message.',self::LOGKEY));
$o->msg = substr($message,0,$ptr_end);
}
}

View File

@ -160,7 +160,7 @@ abstract class Packet extends FTNBase implements \Iterator, \Countable
try {
$o->zone = Zone::where('zone_id',$o->fz)
->where('default',TRUE)
->sole();
->singleOrFail();
} catch (ModelNotFoundException $e) {
throw new InvalidPacketException(sprintf('%s:! We couldnt work out the packet zone, and there isnt a default for[%d]',self::LOGKEY,$o->fz));
@ -263,7 +263,7 @@ abstract class Packet extends FTNBase implements \Iterator, \Countable
case 'software':
Software::unguard();
$o = Software::firstOrNew(['code'=>$this->product,'type'=>Software::SOFTWARE_TOSSER]);
$o = Software::singleOrNew(['code'=>$this->product,'type'=>Software::SOFTWARE_TOSSER]);
Software::reguard();
return $o;

View File

@ -1,36 +1,58 @@
<?php
namespace App\Classes\FTN\Process\Netmail\Robot;
namespace App\Classes\FTN\Process\Netmail;
use Illuminate\Support\Facades\Notification;
use Illuminate\Support\Facades\Log;
use App\Classes\FTN\Process\Netmail\Robot;
use App\Classes\FTN\Process;
use App\Classes\FTN\Process\Netmail\Robot\Unknown;
use App\Models\{Echomail,Netmail};
use App\Notifications\Netmails\Areafix\CommandsProcessed;
use App\Notifications\Netmails\FixCantHandle;
use App\Notifications\Netmails\Areafix\{CommandsProcessed,InvalidPassword,NotConfiguredHere};
/**
* Process messages to Ping
*
* @package App\Classes\FTN\Process
*/
final class Filefix extends Robot
final class Areafix extends Process
{
private const LOGKEY = 'RPF';
private const LOGKEY = 'RP-';
public const commands = 'App\\Classes\\FTN\\Process\\Netmail\\Robot\\Filefix\\';
public const areafix_commands = 'App\\Classes\\FTN\\Process\\Netmail\\Robot\\Areafix\\';
public static function handle(Echomail|Netmail $mo): bool
{
if ((strtolower($mo->to) !== 'filefix') || (! ($mo instanceof Netmail)))
if (((strtolower($mo->to) !== 'areafix') && (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));
Log::info(sprintf('%s:- Processing *FIX [%s] message from (%s) [%s]',self::LOGKEY,$mo->to,$mo->from,$mo->fftn->ftn));
return parent::handle($mo);
// 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;
}
public static function filefix(Netmail $mo): bool
// 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
{
$result = collect();
$result->push('--> BEGIN <--');
@ -60,12 +82,12 @@ final class Filefix extends Robot
// Some commands are reserved words
switch ($x=strtolower(substr($command[0],1))) {
case 'list':
$class = self::commands.'AreaList';
$class = self::areafix_commands.'AreaList';
break;
default:
// Parse the message body and pluck out the commands on each line
$class = self::commands.ucfirst($x);
$class = self::areafix_commands.ucfirst($x);
}
if (! class_exists($class)) {
@ -79,7 +101,7 @@ final class Filefix extends Robot
array_shift($command);
// Refresh our echoareas
$mo->fftn->load('fileareas');
$mo->fftn->load('echoareas');
$o = new $class($mo,$command);
$result->push($o->process());
@ -90,4 +112,11 @@ final class Filefix extends Robot
return TRUE;
}
public static function filefix(Netmail $mo): bool
{
Notification::route('netmail',$mo->fftn)->notify(new FixCantHandle($mo));
return TRUE;
}
}

View File

@ -1,50 +0,0 @@
<?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;
}
}

View File

@ -1,93 +0,0 @@
<?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 Areafix extends Robot
{
private const LOGKEY = 'RPA';
public const commands = 'App\\Classes\\FTN\\Process\\Netmail\\Robot\\Areafix\\';
public static function handle(Echomail|Netmail $mo): bool
{
if ((strtolower($mo->to) !== 'areafix') || (! ($mo instanceof Netmail)))
return FALSE;
Log::info(sprintf('%s:- Processing AREAFIX [%s] message from (%s) [%s]', self::LOGKEY, $mo->to, $mo->from, $mo->fftn->ftn));
return parent::handle($mo);
}
public static function areafix(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.'AreaList';
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('echoareas');
$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;
}
}

View File

@ -5,7 +5,7 @@ namespace App\Classes\FTN\Process\Netmail\Robot\Areafix;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Notification;
use App\Classes\FTN\Process\Netmail\Robot\Areafix;
use App\Classes\FTN\Process\Netmail\Areafix;
use App\Notifications\Netmails\Areafix\Help as HelpNotification;
// A Help Index Command
@ -33,7 +33,7 @@ class Help extends Base
if (($file === 'Base.php') || (! str_ends_with(strtolower($file),'.php')))
continue;
$class = Areafix::commands.preg_replace('/\.php$/','',$file);
$class = Areafix::areafix_commands.preg_replace('/\.php$/','',$file);
if ($result->count())
$result->push('');

View File

@ -1,39 +0,0 @@
<?php
namespace App\Classes\FTN\Process\Netmail\Robot\Filefix;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Notification;
use App\Classes\FTN\Process\Netmail\Robot\Areafix\Base;
use App\Notifications\Netmails\Filefix\AreaList as AreaListNotification;
// LIST - List echoareas in a domain
class AreaList extends Base
{
private const LOGKEY = 'AFS';
private const command = '%LIST';
public static function help(): array
{
return [
self::command,
' List the available fileareas in this network',
];
}
public function process(): string
{
Log::debug(sprintf('%s:- Filefix [%s] for [%s] for [%s]',self::LOGKEY,self::command,$this->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);
}
}
}

View File

@ -1,50 +0,0 @@
<?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);
}
}

View File

@ -1,201 +0,0 @@
<?php
namespace App\Classes\Fonts;
use App\Classes\Font;
final class Ansitex extends Font
{
protected const FONT = [
'a' => [
[0xda,0xc4,0xdc],
[0xb3,0xdf,0xdb],
[0x20,0x20,0x20],
],
'b' => [
[0xb3,0xc4,0xdc],
[0xb3,0x5f,0xdb],
[0x20,0x20,0x20],
],
'c' => [
[0xda,0xc4,0xdc],
[0xb3,0x5f,0xdc],
[0x20,0x20,0x20],
],
'd' => [
[0xda,0xc4,0xdb],
[0xb3,0x5f,0xdb],
[0x20,0x20,0x20],
],
'e' => [
[0xda,0xc4,0xdc],
[0xc3,0x5f,0xdc],
[0x20,0x20,0x20],
],
'f' => [
[0xda,0xc4,0xdc],
[0xc3,0x20,0x20],
[0x20,0x20,0x20],
],
'g' => [
[0xda,0xc4,0xdc],
[0xb3,0x5f,0xdb],
[0x20,0xc4,0xdf],
],
'h' => [
[0xde,0xc4,0xdc],
[0xde,0x20,0xdb],
[0x20,0x20,0x20],
],
'i' => [
[0x20,0xdf],
[0xde,0xdb],
[0x20,0x20],
],
'j' => [
[0x20,0xdf],
[0xde,0xdb],
[0xc4,0xdf],
],
'k' => [
[0xb3,0x20,0xdc],
[0xb3,0x60,0xdc],
[0x20,0x20,0x20],
],
'l' => [
[0xb3,0x20],
[0xb3,0xdc],
[0x20,0x20],
],
'm' => [
[0xda,0xda,0xdc],
[0xb3,0xb3,0xdb],
[0x20,0x20,0x20],
],
'n' => [
[0xda,0xc4,0xdc],
[0xb3,0x20,0xdb],
[0x20,0x20,0x20],
],
'o' => [
[0xda,0xc4,0xdc],
[0xb3,0x5f,0xdb],
[0x20,0x20,0x20],
],
'p' => [
[0xda,0xc4,0xdc],
[0xb3,0x5f,0xdb],
[0xc0,0x20,0x20],
],
'q' => [
[0xda,0xc4,0xdc],
[0xb3,0x5f,0xdb],
[0x20,0x20,0xdf],
],
'r' => [
[0xda,0xc4,0xdc],
[0xb3,0xc1,0x5c],
[0x20,0x20,0x20],
],
's' => [
[0xda,0xc4,0xdc],
[0x2e,0x5c,0xdc],
[0x20,0x20,0x20],
],
't' => [
[0xda,0xc2,0xdc],
[0x20,0xb3,0x20],
[0x20,0x20,0x20],
],
'u' => [
[0xda,0x20,0xdc],
[0xb3,0x5f,0xdb],
[0x20,0x20,0x20],
],
'v' => [
[0xda,0x20,0xdc],
[0x60,0x5c,0xdb],
[0x20,0x20,0x20],
],
'w' => [
[0xda,0xda,0xdb],
[0x60,0x5c,0xdb],
[0x20,0x20,0x20],
],
'x' => [
[0xda,0x20,0xdc],
[0xda,0xdf,0xdc],
[0x20,0x20,0x20],
],
'y' => [
[0xda,0x20,0xdc],
[0xb3,0x5f,0xdb],
[0x20,0xc4,0xdf],
],
'z' => [
[0xda,0xc4,0xdc],
[0x2e,0x2f,0xdc],
[0x20,0x20,0x20],
],
'1' => [
[0xc4,0xdc],
[0x20,0xdb],
[0x20,0x20],
],
'2' => [
[0xfe,0xc4,0xdc],
[0xda,0x2f,0xdc],
[0x20,0x20,0x20],
],
'3' => [
[0xda,0xc4,0xdc],
[0xda,0xf0,0xdb],
[0x20,0x20,0x20],
],
'4' => [
[0xde,0x20,0xdc],
[0xc0,0xc4,0xdb],
[0x20,0x20,0x20],
],
'5' => [
[0xda,0xc4,0xdc],
[0x2e,0x2d,0xdc],
[0x20,0x20,0x20],
],
'6' => [
[0xde,0xc4,0xbf],
[0xb3,0x5f,0xdb],
[0x20,0x20,0x20],
],
'7' => [
[0xfe,0x2d,0xbf],
[0x20,0xde,0x20],
[0x20,0x20,0x20],
],
'8' => [
[0xda,0xc4,0xdc],
[0xc3,0xf0,0xdb],
[0x20,0x20,0x20],
],
'9' => [
[0xda,0xc4,0xdc],
[0xd4,0xc4,0xdb],
[0x20,0x20,0x20],
],
'0' => [
[0xda,0xc4,0xdc],
[0xb3,0x5f,0xdb],
[0x20,0x20,0x20],
],
'#' => [
[0xdc,0xba,0xdc],
[0xfe,0xba,0xfe],
[0x20,0x20,0x20],
],
'!' => [
[0xdb],
[0xfe],
[0x20],
],
];
}

View File

@ -3,10 +3,11 @@
namespace App\Classes;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Config;
use Illuminate\Support\Facades\Log;
use App\Classes\File\{Receive,Send};
use App\Classes\Protocol\{Binkp,DNS,EMSI,Zmodem};
use App\Classes\Protocol\EMSI;
use App\Classes\Sock\Exception\SocketException;
use App\Classes\Sock\SocketClient;
use App\Models\{Address,Mailer,Setup,System,SystemLog};
@ -122,13 +123,10 @@ abstract class Protocol
protected array $capability; // @todo make private
/** @var bool Are we originating a connection */
protected bool $originate;
/** Our comms details */
/** @var bool Is the application down for maintenance */
protected bool $down = FALSE;
/** @var int Our mailer ID for logging purposes */
private int $mailer_id;
private array $comms;
protected bool $force_queue = FALSE;
@ -137,31 +135,9 @@ abstract class Protocol
abstract protected function protocol_session(bool $force_queue=FALSE): int;
/**
* @param Setup $setup
* @throws \Exception
*/
public function __construct(Setup $setup)
public function __construct()
{
$this->setup = $setup;
// Some initialisation details
switch (get_class($this)) {
case Binkp::class:
$this->mailer_id = Mailer::where('name','BINKP')->sole()->id;
break;
case DNS::class:
case Zmodem::class:
break;
case EMSI::class:
$this->mailer_id = Mailer::where('name','EMSI')->sole()->id;
break;
default:
throw new \Exception('not handled'.get_class($this));
}
$this->setup = Config::get('setup',Setup::findOrFail(config('app.id')));
}
/**
@ -270,27 +246,20 @@ abstract class Protocol
* Incoming Protocol session
*
* @param SocketClient $client
* @return int
* @return int|null
* @throws SocketException
*/
public function onConnect(SocketClient $client): int
public function onConnect(SocketClient $client): ?int
{
$pid = pcntl_fork();
if ($pid === -1)
throw new SocketException(SocketException::CANT_ACCEPT,'Could not fork process');
// If our parent returns a PID, we've forked
if ($pid)
Log::info(sprintf('%s:+ New connection from [%s], thread [%d] created',self::LOGKEY,$client->address_remote,$pid));
// This is the new thread
else {
Log::withContext(['pid'=>getmypid()]);
$this->session($client,(new Address));
}
// Parent return ready for next connection
return $pid;
}
@ -333,7 +302,6 @@ abstract class Protocol
* Our addresses to send to the remote
*
* @return Collection
* @throws \Exception
*/
protected function our_addresses(): Collection
{
@ -357,14 +325,15 @@ abstract class Protocol
}
/**
* Setup a session with a remote client
* Initialise our Session
*
* @param SocketClient $client Socket details of session
* @param Address|null $o If we have an address, we originated a session to this Address
* @param Mailer $mo
* @param SocketClient $client
* @param Address|null $o
* @return int
* @throws \Exception
*/
public function session(SocketClient $client,Address $o=NULL): int
public function session(Mailer $mo,SocketClient $client,Address $o=NULL): int
{
if ($o->exists)
Log::withContext(['ftn'=>$o->ftn]);
@ -397,10 +366,12 @@ abstract class Protocol
// We are an IP node
$this->optionSet(self::O_TCP);
$this->client = $client;
// @todo This appears to be a bug in laravel? Need to call app()->isDownForMaintenance() twice?
app()->isDownForMaintenance();
$this->down = app()->isDownForMaintenance();
switch (get_class($this)) {
case EMSI::class:
switch ($mo->name) {
case 'EMSI':
Log::debug(sprintf('%s:- Starting EMSI',self::LOGKEY));
$rc = $this->protocol_init();
@ -414,7 +385,7 @@ abstract class Protocol
break;
case Binkp::class:
case 'BINKP':
Log::debug(sprintf('%s:- Starting BINKP',self::LOGKEY));
$rc = $this->protocol_session($this->originate);
@ -422,11 +393,13 @@ abstract class Protocol
break;
default:
Log::error(sprintf('%s:! Unsupported session type [%s]',self::LOGKEY,get_class($this)));
Log::error(sprintf('%s:! Unsupported session type [%d]',self::LOGKEY,$mo->id));
return self::S_FAILURE;
}
// @todo Unlock outbounds
// @todo These flags determine when we connect to the remote.
// If the remote indicated that they dont support file requests (NRQ) or temporarily hold them (HRQ)
if (($this->node->optionGet(self::O_NRQ) && (! $this->setup->optionGet(EMSI::F_IGNORE_NRQ,'emsi_options'))) || $this->node->optionGet(self::O_HRQ))
@ -457,7 +430,6 @@ abstract class Protocol
if ($so && $so->exists) {
foreach ($this->node->aka_other as $aka)
// @todo For disabled zones, we shouldnt refuse to record the address
// @todo If the system hasnt presented an address for a configured period (eg: 30 days) assume it no longer carries it
if ((! Address::findFTN($aka)) && ($oo=Address::createFTN($aka,$so))) {
$oo->validated = TRUE;
$oo->save();
@ -469,7 +441,7 @@ abstract class Protocol
$slo->items_sent_size = $this->send->total_sent_bytes;
$slo->items_recv = $this->recv->total_recv;
$slo->items_recv_size = $this->recv->total_recv_bytes;
$slo->mailer_id = $this->mailer_id;
$slo->mailer_id = $mo->id;
$slo->sessiontime = $this->node->session_time;
$slo->result = ($rc & self::S_MASK);
$slo->originate = $this->originate;
@ -483,6 +455,12 @@ abstract class Protocol
}
}
// @todo Optional after session execution event
// if ($this->node->start_time && $this->setup->cfg('CFG_AFTERSESSION')) {}
// @todo Optional after session includes mail event
// if ($this->node->start_time && $this->setup->cfg('CFG_AFTERMAIL')) {}
return $rc;
}

View File

@ -12,8 +12,9 @@ use App\Classes\Crypt;
use App\Classes\Node;
use App\Classes\Protocol as BaseProtocol;
use App\Classes\Sock\Exception\SocketException;
use App\Classes\Sock\SocketClient;
use App\Exceptions\{FileGrewException,InvalidFTNException};
use App\Models\{Address,Setup};
use App\Models\{Address,Mailer,Setup};
final class Binkp extends BaseProtocol
{
@ -141,6 +142,27 @@ final class Binkp extends BaseProtocol
*/
private Crypt $crypt_out;
/**
* Incoming BINKP session
*
* @param SocketClient $client
* @return int|null
* @throws SocketException
*/
public function onConnect(SocketClient $client): ?int
{
// If our parent returns a PID, we've forked
if (! parent::onConnect($client)) {
Log::withContext(['pid'=>getmypid()]);
$this->session(Mailer::where('name','BINKP')->singleOrFail(),$client,(new Address));
$this->client->close();
exit(0);
}
return NULL;
}
/**
* BINKD handshake
*

View File

@ -6,6 +6,7 @@ use Illuminate\Support\Facades\Log;
use Illuminate\Support\Str;
use App\Classes\Protocol as BaseProtocol;
use App\Classes\Sock\SocketClient;
use App\Models\{Address,Domain,Mailer};
/**
@ -63,6 +64,22 @@ final class DNS extends BaseProtocol
public const DNS_TYPE_OPT = 41; // OPT Records
public const DNS_TYPE_DS = 43; // DS Records (Delegation signer RFC 4034)
public function onConnect(SocketClient $client): ?int
{
// If our parent returns a PID, we've forked
if (! parent::onConnect($client)) {
Log::withContext(['pid'=>getmypid()]);
$this->client = $client;
$this->protocol_session();
Log::debug(sprintf('%s:= onConnect - Connection closed [%s]',self::LOGKEY,$client->address_remote));
exit(0);
}
return NULL;
}
protected function protocol_init(): int
{
// N/A
@ -162,11 +179,11 @@ final class DNS extends BaseProtocol
switch ($labels->first()) {
case '_binkp':
$mailer = Mailer::where('name','BINKP')->sole();
$mailer = Mailer::where('name','BINKP')->singleOrFail();
break;
case '_ifcico':
$mailer = Mailer::where('name','EMSI')->sole();
$mailer = Mailer::where('name','EMSI')->singleOrFail();
break;
default:

View File

@ -7,10 +7,11 @@ use Illuminate\Support\Facades\Log;
use App\Classes\Protocol as BaseProtocol;
use App\Classes\Sock\Exception\SocketException;
use App\Classes\Sock\SocketClient;
use App\Exceptions\InvalidFTNException;
use App\Interfaces\CRC as CRCInterface;
use App\Interfaces\Zmodem as ZmodemInterface;
use App\Models\{Address,Setup};
use App\Models\{Address,Mailer,Setup};
use App\Traits\CRC as CRCTrait;
// http://ftsc.org/docs/fsc-0056.001
@ -81,6 +82,27 @@ final class EMSI extends BaseProtocol implements CRCInterface,ZmodemInterface
'1'=>self::P_ZMODEM,
];
/**
* Incoming EMSI session
*
* @param SocketClient $client
* @return int|null
* @throws SocketException
*/
public function onConnect(SocketClient $client): ?int
{
// If our parent returns a PID, we've forked
if (! parent::onConnect($client)) {
Log::withContext(['pid'=>getmypid()]);
$this->session(Mailer::where('name','EMSI')->singleOrFail(),$client,(new Address));
$this->client->close();
exit(0);
}
return NULL;
}
/**
* Send our welcome banner
*

View File

@ -10,7 +10,7 @@ use App\Classes\Sock\Exception\SocketException;
use App\Classes\Sock\SocketClient;
use App\Interfaces\CRC as CRCInterface;
use App\Interfaces\Zmodem as ZmodemInterface;
use App\Models\Address;
use App\Models\{Address,Mailer};
use App\Traits\CRC as CRCTrait;
/**
@ -202,6 +202,27 @@ final class Zmodem extends Protocol implements CRCInterface,ZmodemInterface
private string $rxbuf = '';
private string $txbuf = '';
/**
* @param SocketClient $client
* @return null
* @throws SocketException
*/
public function onConnect(SocketClient $client): ?int
{
// If our parent returns a PID, we've forked
if (! parent::onConnect($client)) {
Log::withContext(['pid'=>getmypid()]);
$this->session(Mailer::where('name','ZMODEM')->singleOrFail(),$client);
$this->client->close();
Log::info(sprintf('%s:= onConnect - Connection closed [%s]',self::LOGKEY,$client->address_remote));
exit(0);
}
return NULL;
}
/**
* Initialise our session
*/

View File

@ -141,11 +141,7 @@ final class SocketServer {
continue;
}
// If the handler returns a value, then that is the main thread
if (! $this->handler[0]->{$this->handler[1]}($r)) {
$r->close();
exit(0);
}
$this->handler[0]->{$this->handler[1]}($r);
}
}

View File

@ -30,7 +30,7 @@ class AddressIdle extends Command
*/
public function handle(): int
{
$do = Domain::where('name',$this->argument('domain'))->sole();
$do = Domain::where('name',$this->argument('domain'))->singleOrFail();
return Job::dispatchSync($do,$this->option('ftn') ? Address::findFTN($this->option('ftn')) : NULL);
}

View File

@ -0,0 +1,53 @@
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Log;
use App\Classes\Protocol\Binkp;
use App\Classes\Sock\Exception\SocketException;
use App\Classes\Sock\SocketServer;
use App\Models\Setup;
class CommBinkpReceive extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'comm:binkp:receive';
/**
* The console command description.
*
* @var string
*/
protected $description = 'BINKP receive';
/**
* Execute the console command.
*
* @return mixed
* @throws SocketException
*/
public function handle()
{
Log::info('Listening for BINKP connections...');
$o = Setup::findOrFail(config('app.id'));
$server = new SocketServer($o->binkp_port,$o->binkp_bind);
$server->handler = [new Binkp,'onConnect'];
try {
$server->listen();
} catch (SocketException $e) {
if ($e->getMessage() === 'Can\'t accept connections: "Success"')
Log::debug('Server Terminated');
else
Log::emergency('Uncaught Message: '.$e->getMessage());
}
}
}

View File

@ -27,6 +27,8 @@ class CommBinkpSend extends Command
*/
protected $description = 'BINKP send';
private const ID = 'BINKP';
/**
* Execute the console command.
*
@ -40,7 +42,7 @@ class CommBinkpSend extends Command
Log::info(sprintf('CBS:- Call BINKP send for %s',$ao->ftn));
$mo = Mailer::where('name','BINKP')->sole();
$mo = Mailer::where('name',self::ID)->singleOrFail();
if ($this->option('now'))
Job::dispatchSync($ao,$mo);

View File

@ -0,0 +1,53 @@
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Log;
use App\Classes\Protocol\EMSI;
use App\Classes\Sock\Exception\SocketException;
use App\Classes\Sock\SocketServer;
use App\Models\Setup;
class CommEMSIReceive extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'comm:emsi:receive';
/**
* The console command description.
*
* @var string
*/
protected $description = 'EMSI receive';
/**
* Execute the console command.
*
* @return mixed
* @throws \Exception
*/
public function handle()
{
Log::info('Listening for EMSI connections...');
$o = Setup::findOrFail(config('app.id'));
$server = new SocketServer($o->emsi_port,$o->emsi_bind);
$server->handler = [new EMSI,'onConnect'];
try {
$server->listen();
} catch (SocketException $e) {
if ($e->getMessage() === 'Can\'t accept connections: "Success"')
Log::debug('Server Terminated');
else
Log::emergency('Uncaught Message: '.$e->getMessage());
}
}
}

View File

@ -27,6 +27,8 @@ class CommEMSISend extends Command
*/
protected $description = 'EMSI send';
private const ID = 'EMSI';
/**
* Execute the console command.
*
@ -40,7 +42,7 @@ class CommEMSISend extends Command
Log::info(sprintf('CES:- Call EMSI send for %s',$ao->ftn));
$mo = Mailer::where('name','EMSI')->sole();
$mo = Mailer::where('name',self::ID)->singleOrFail();
if ($this->option('now'))
Job::dispatchSync($ao,$mo);

View File

@ -16,7 +16,7 @@ class ZoneCheck extends Command
public function handle(): int
{
$do = Domain::where('name',$this->argument('domain'))->sole();
$do = Domain::where('name',$this->argument('domain'))->singleOrFail();
foreach ($do->zones->sortby('zone_id') as $zo) {
if ($this->option('zone') && ($this->option('zone') != $zo->zone_id))

View File

@ -34,8 +34,7 @@ class EchoareaImport extends Command
*/
public function handle(): int
{
$do = Domain::where('name',strtolower($this->argument('domain')))->single();
$do = Domain::where('name',strtolower($this->argument('domain')))->singleOrFail();
return Job::dispatchSync($this->argument('file'),$do,$this->option('prefix') ?: '',$this->option('unlink'));
}
}

View File

@ -34,8 +34,7 @@ class FileareaImport extends Command
*/
public function handle(): int
{
$do = Domain::where('name',strtolower($this->argument('domain')))->sole();
$do = Domain::where('name',strtolower($this->argument('domain')))->singleOrFail();
return Job::dispatchSync($this->argument('file'),$do,$this->option('prefix') ?: '',$this->option('unlink'));
}
}

View File

@ -40,7 +40,7 @@ class Rescan extends Command
if (! $this->argument('area'))
throw new \Exception('Areaname is required');
$fao = Filearea::where('name',$this->argument('area'))->sole();
$fao = Filearea::where('name',$this->argument('area'))->singleOrFail();
if ($fao->domain_id !== $ao->zone->domain_id)
throw new \Exception(sprintf('File area [%s] is not in domain [%s] for FTN [%s]',$fao->name,$ao->zone->domain->name,$ao->ftn));

View File

@ -33,7 +33,7 @@ class NodesNew extends Command
*/
public function handle(): int
{
$do = Domain::where('name',$this->argument('domain'))->sole();
$do = Domain::where('name',$this->argument('domain'))->singleOrFail();
$ao = NULL;
if ($this->option('netmail')) {

View File

@ -50,7 +50,7 @@ class ServerStart extends Command
'address'=>$o->binkp_bind,
'port'=>$o->binkp_port,
'proto'=>SOCK_STREAM,
'class'=>new Binkp($o),
'class'=>new Binkp,
]);
if ($o->emsi_active)
@ -58,7 +58,7 @@ class ServerStart extends Command
'address'=>$o->emsi_bind,
'port'=>$o->emsi_port,
'proto'=>SOCK_STREAM,
'class'=>new EMSI($o),
'class'=>new EMSI,
]);
if ($o->dns_active)
@ -66,7 +66,7 @@ class ServerStart extends Command
'address'=>$o->dns_bind,
'port'=>$o->dns_port,
'proto'=>SOCK_DGRAM,
'class'=>new DNS($o),
'class'=>new DNS,
]);
$children = collect();

View File

@ -25,7 +25,7 @@ class UserCodeSend extends Command
public function handle(): int
{
$ao = Address::findFTN($this->argument('ftn'));
$uo = User::where('email',$this->argument('email'))->sole();
$uo = User::where('email',$this->argument('email'))->singleOrFail();
Notification::route('netmail',$ao->uplink())->notify(new AddressLink($uo));

View File

@ -69,7 +69,7 @@ class ZoneController extends Controller
$o->save();
$zo = Zone::where('zone_id',$request->zone_id)
->where('domain_id',$request->domain_id)
->sole();
->singleOrFail();
// Find the zones 0/0 address, and assign it to this host.
$ao = Address::where('zone_id',$zo->id)

View File

@ -10,7 +10,6 @@ use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\ManuallyFailedException;
use Illuminate\Queue\MaxAttemptsExceededException;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Facades\Config;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Notification;
@ -86,7 +85,6 @@ class AddressPoll implements ShouldQueue, ShouldBeUnique
}
Log::info(sprintf('%s:- Polling [%s] - attempt [%d]',self::LOGKEY,$this->ao->ftn,$this->attempts()));
$setup = Config::get('setup',Setup::findOrFail(config('app.id')));
foreach ($this->ao->system->mailer_preferred as $o) {
// If we chose a protocol, skip to find the mailer details for it
@ -95,12 +93,14 @@ class AddressPoll implements ShouldQueue, ShouldBeUnique
switch ($o->name) {
case 'BINKP':
$s = new Binkp($setup);
$s = new Binkp;
$mo = Mailer::where('name','BINKP')->singleOrFail();
break;
case 'EMSI':
$s = new EMSI($setup);
$s = new EMSI;
$mo = Mailer::where('name','EMSI')->singleOrFail();
break;
@ -116,7 +116,7 @@ class AddressPoll implements ShouldQueue, ShouldBeUnique
try {
$client = SocketClient::create($this->ao->system->address,$o->pivot->port);
if (($s->session($client,$this->ao) & Protocol::S_MASK) === Protocol::S_OK) {
if (($s->session($mo,$client,$this->ao) & Protocol::S_MASK) === Protocol::S_OK) {
Log::info(sprintf('%s:= Connection ended successfully with [%s] (%s)',self::LOGKEY,$client->address_remote,$this->ao->ftn));
return;

View File

@ -62,9 +62,7 @@ class NodelistImport implements ShouldQueue
{
switch ($key) {
case 'jobname':
return ($this->domain)
? sprintf('%s-%s',$this->domain?->name,(is_object($this->file) ? $this->file->name : $this->file))
: (is_object($this->file) ? $this->file->name : $this->file);
return sprintf('%s-%s',$this->domain?->name,is_object($this->file) ? $this->file->name : $this->file);
default:
return NULL;
@ -146,8 +144,8 @@ class NodelistImport implements ShouldQueue
return;
}
$mailer_binkp = Mailer::where('name','BINKP')->sole();
$mailer_emsi = Mailer::where('name','EMSI')->sole();
$mailer_binkp = Mailer::where('name','BINKP')->singleOrFail();
$mailer_emsi = Mailer::where('name','EMSI')->singleOrFail();
$p = $c = 0;

View File

@ -34,7 +34,7 @@ class TicProcess implements ShouldQueue
*/
public function __construct(private string $file,private ?string $domain=NULL)
{
$this->do = $domain ? Domain::where('name',$domain)->sole() : NULL;
$this->do = $domain ? Domain::where('name',$domain)->singleOrFail() : NULL;
$this->onQueue(self::QUEUE);
}

View File

@ -120,7 +120,7 @@ class Address extends Model
// Check Domain exists
Domain::unguard();
$do = Domain::firstOrNew(['name'=>$ftn['d']]);
$do = Domain::singleOrNew(['name'=>$ftn['d']]);
Domain::reguard();
if (! $do->exists) {
@ -143,7 +143,7 @@ class Address extends Model
// Create zone
Zone::unguard();
$zo = Zone::firstOrNew(['domain_id'=>$do->id,'zone_id'=>$ftn['z']]);
$zo = Zone::singleOrNew(['domain_id'=>$do->id,'zone_id'=>$ftn['z']]);
Zone::reguard();
if (! $zo->exists) {

View File

@ -6,8 +6,6 @@ use Illuminate\Database\Eloquent\Model;
class SystemLog extends Model
{
const UPDATED_AT = null;
/* RELATIONS */
public function mailer()

View File

@ -12,12 +12,12 @@ class AreaList extends Netmails
{
use MessagePath,PageTemplate;
private const LOGKEY = 'ACL';
private const LOGKEY = 'ACH';
private Netmail $mo;
/**
* Reply to a areafix AREALIST commands.
* Reply to a areafix, commands unknown.
*
* @param Netmail $mo
*/

View File

@ -16,7 +16,7 @@ class Help extends Netmails
private const LOGKEY = 'ACH';
/**
* Reply to an areafix HELP commands.
* Reply to a areafix, commands unknown.
*
* @param Netmail $mo
* @param Collection $commands

View File

@ -1,103 +0,0 @@
<?php
namespace App\Notifications\Netmails\Filefix;
use Illuminate\Support\Facades\Log;
use App\Notifications\Netmails;
use App\Models\Netmail;
use App\Traits\{MessagePath,PageTemplate};
class AreaList extends Netmails
{
use MessagePath,PageTemplate;
private const LOGKEY = 'FCL';
private Netmail $mo;
/**
* Reply to a filefix AREALIST commands.
*
* @param Netmail $mo
*/
public function __construct(Netmail $mo)
{
parent::__construct();
$this->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 filefix for a node [%s] LIST processed',self::LOGKEY,$ao->ftn));
$o->to = $this->mo->from;
$o->replyid = $this->mo->msgid;
$o->subject = 'Filefix - List';
// Message
$msg = $this->page(FALSE,'Filefix');
$msg->addText("Here are the list of available filereas:\r\r\r\r");
$areas = $ao->domain
->fileareas
->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('-',5),
));
$msg->addText(sprintf(": : %-10s : %-48s : %-5s :\r",'AREA','DESCRIPTION','FILES'));
$msg->addText(sprintf(":---:-%s-:-%s-:-%s-:\r",
str_repeat('-',10),
str_repeat('-',48),
str_repeat('-',5),
));
foreach ($areas as $eao) {
$msg->addText(sprintf(":%s%s%s: %-10s : %-48s : %5d :\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->files()->count(),
));
}
$msg->addText(sprintf(":---:-%s-:-%s-:-%s-:\r",
str_repeat('-',10),
str_repeat('-',48),
str_repeat('-',5),
));
$msg->addText("\r'*' = Subscribed, '+' = available, 'R' = read only, 'W' = write only\r");
} 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 chicken cross the road? The robot programmed it.';
$o->save();
return $o;
}
}

View File

@ -1,63 +0,0 @@
<?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;
}
}

View File

@ -17,11 +17,11 @@ use App\Listeners\EchomailListener;
use App\Listeners\Matrix\MessageListener;
use App\Notifications\Channels\{EchomailChannel,MatrixChannel,NetmailChannel};
use App\Models\{Echomail,Netmail,User};
use App\Traits\Single;
use App\Traits\SingleOrFail;
class AppServiceProvider extends ServiceProvider
{
use Single;
use SingleOrFail;
/**
* Register any application services.
@ -52,7 +52,7 @@ class AppServiceProvider extends ServiceProvider
*/
public function boot()
{
static::bootSingle();
static::bootSingleOrFail();
// Add our page assets
Blade::directive('pa',function($expression) {

View File

@ -1,25 +0,0 @@
<?php
/**
* Add eloquent queries single(), singleOrNew()
*/
namespace App\Traits;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\ModelNotFoundException;
trait Single
{
private static function bootSingle(): void
{
// When a query should return 1 object, or NULL if it doesnt
Builder::macro('single',function () {
$result = $this->get();
if ($result->count() === 1)
return $result->first();
return NULL;
});
}
}

View File

@ -0,0 +1,49 @@
<?php
/**
* Add eloquent queries single(), singleOrFail(), singleOrNew()
*/
namespace App\Traits;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\ModelNotFoundException;
trait SingleOrFail
{
private static function bootSingleOrFail(): void
{
// When a query should return 1 object, or FAIL if it doesnt
// @deprecated use sole()
Builder::macro('singleOrFail',function () {
$result = $this->get();
if (($x=$result->count()) === 1)
return $result->first();
if ($x === 0)
throw new ModelNotFoundException('Query brings back 0 record(s) called for singleOrFail()');
else
throw new \Exception(sprintf('Query brings back %d record(s) called for singleOrFail()',$x));
});
// When a query should return 1 object, or NULL if it doesnt
Builder::macro('single',function () {
$result = $this->get();
if ($result->count() === 1)
return $result->first();
return NULL;
});
// When a query should return 1 object, or NULL if it doesnt
Builder::macro('singleOrNew',function ($args) {
$result = $this->where($args)->get();
if ($result->count() === 1)
return $result->first();
return $this->newModelInstance($args);
});
}
}

View File

@ -9,7 +9,6 @@ return [
// Netmail
'robots' => [
\App\Classes\FTN\Process\Netmail\Ping::class,
\App\Classes\FTN\Process\Netmail\Robot\Areafix::class,
\App\Classes\FTN\Process\Netmail\Robot\Filefix::class,
\App\Classes\FTN\Process\Netmail\Areafix::class,
],
];

View File

@ -1,28 +0,0 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::table('system_logs', function (Blueprint $table) {
$table->dropColumn(['updated_at']);
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::table('system_logs', function (Blueprint $table) {
$table->timestamp('updated_at');
});
}
};

View File

@ -38,7 +38,7 @@ class TestNodeHierarchy extends Seeder
]);
foreach (['a','b'] as $domain) {
$do = Domain::where('name',$domain)->sole();
$do = Domain::where('name',$domain)->singleOrFail();
$this->hierarchy($do,100);
$this->hierarchy($do,101);
}
@ -84,7 +84,7 @@ class TestNodeHierarchy extends Seeder
'updated_at'=>Carbon::now(),
]);
$zo = Zone::where('zone_id',$zoneid)->where('domain_id',$domain->id)->sole();
$zo = Zone::where('zone_id',$zoneid)->where('domain_id',$domain->id)->singleOrFail();
if (self::DEBUG)
dump(['zo'=>$zo->zone_id,'rid'=>0,'hid'=>0,'nid'=>0]);

16
routes/channels.php Normal file
View File

@ -0,0 +1,16 @@
<?php
/*
|--------------------------------------------------------------------------
| Broadcast Channels
|--------------------------------------------------------------------------
|
| Here you may register all of the event broadcasting channels that your
| application supports. The given channel authorization callbacks are
| used to check if an authenticated user can listen to the channel.
|
*/
Broadcast::channel('App.User.{id}', function ($user, $id) {
return (int) $user->id === (int) $id;
});

View File

@ -57,7 +57,7 @@ class RoutingTest extends TestCase
{
//$this->seed(TestNodeHierarchy::class);
$do = Domain::where('name','a')->sole();
$do = Domain::where('name','a')->singleOrFail();
$zo = $do->zones->where('zone_id',100)->pop();
return $zo->addresses;
}