Remove CommProtocolReceive commands, Remove protocol onConnect() functions, pass Setup::class to protocols
This commit is contained in:
parent
72ad1307c5
commit
bf3fce252d
@ -3,7 +3,6 @@
|
|||||||
namespace App\Classes;
|
namespace App\Classes;
|
||||||
|
|
||||||
use Illuminate\Support\Collection;
|
use Illuminate\Support\Collection;
|
||||||
use Illuminate\Support\Facades\Config;
|
|
||||||
use Illuminate\Support\Facades\Log;
|
use Illuminate\Support\Facades\Log;
|
||||||
|
|
||||||
use App\Classes\File\{Receive,Send};
|
use App\Classes\File\{Receive,Send};
|
||||||
@ -138,9 +137,13 @@ abstract class Protocol
|
|||||||
|
|
||||||
abstract protected function protocol_session(bool $force_queue=FALSE): int;
|
abstract protected function protocol_session(bool $force_queue=FALSE): int;
|
||||||
|
|
||||||
public function __construct()
|
/**
|
||||||
|
* @param Setup $setup
|
||||||
|
* @throws \Exception
|
||||||
|
*/
|
||||||
|
public function __construct(Setup $setup)
|
||||||
{
|
{
|
||||||
$this->setup = Config::get('setup',Setup::findOrFail(config('app.id')));
|
$this->setup = $setup;
|
||||||
|
|
||||||
// Some initialisation details
|
// Some initialisation details
|
||||||
switch (get_class($this)) {
|
switch (get_class($this)) {
|
||||||
@ -267,20 +270,27 @@ abstract class Protocol
|
|||||||
* Incoming Protocol session
|
* Incoming Protocol session
|
||||||
*
|
*
|
||||||
* @param SocketClient $client
|
* @param SocketClient $client
|
||||||
* @return int|null
|
* @return int
|
||||||
* @throws SocketException
|
* @throws SocketException
|
||||||
*/
|
*/
|
||||||
public function onConnect(SocketClient $client): ?int
|
public function onConnect(SocketClient $client): int
|
||||||
{
|
{
|
||||||
$pid = pcntl_fork();
|
$pid = pcntl_fork();
|
||||||
|
|
||||||
if ($pid === -1)
|
if ($pid === -1)
|
||||||
throw new SocketException(SocketException::CANT_ACCEPT,'Could not fork process');
|
throw new SocketException(SocketException::CANT_ACCEPT,'Could not fork process');
|
||||||
|
|
||||||
|
// If our parent returns a PID, we've forked
|
||||||
if ($pid)
|
if ($pid)
|
||||||
Log::info(sprintf('%s:+ New connection from [%s], thread [%d] created',self::LOGKEY,$client->address_remote,$pid));
|
Log::info(sprintf('%s:+ New connection from [%s], thread [%d] created',self::LOGKEY,$client->address_remote,$pid));
|
||||||
|
|
||||||
// Parent return ready for next connection
|
// This is the new thread
|
||||||
|
else {
|
||||||
|
Log::withContext(['pid'=>getmypid()]);
|
||||||
|
|
||||||
|
$this->session($client,(new Address));
|
||||||
|
}
|
||||||
|
|
||||||
return $pid;
|
return $pid;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -347,10 +357,10 @@ abstract class Protocol
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initialise our Session
|
* Setup a session with a remote client
|
||||||
*
|
*
|
||||||
* @param SocketClient $client
|
* @param SocketClient $client Socket details of session
|
||||||
* @param Address|null $o
|
* @param Address|null $o If we have an address, we originated a session to this Address
|
||||||
* @return int
|
* @return int
|
||||||
* @throws \Exception
|
* @throws \Exception
|
||||||
*/
|
*/
|
||||||
|
@ -12,7 +12,6 @@ use App\Classes\Crypt;
|
|||||||
use App\Classes\Node;
|
use App\Classes\Node;
|
||||||
use App\Classes\Protocol as BaseProtocol;
|
use App\Classes\Protocol as BaseProtocol;
|
||||||
use App\Classes\Sock\Exception\SocketException;
|
use App\Classes\Sock\Exception\SocketException;
|
||||||
use App\Classes\Sock\SocketClient;
|
|
||||||
use App\Exceptions\{FileGrewException,InvalidFTNException};
|
use App\Exceptions\{FileGrewException,InvalidFTNException};
|
||||||
use App\Models\{Address,Setup};
|
use App\Models\{Address,Setup};
|
||||||
|
|
||||||
@ -142,27 +141,6 @@ final class Binkp extends BaseProtocol
|
|||||||
*/
|
*/
|
||||||
private Crypt $crypt_out;
|
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($client,(new Address));
|
|
||||||
$this->client->close();
|
|
||||||
exit(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* BINKD handshake
|
* BINKD handshake
|
||||||
*
|
*
|
||||||
|
@ -6,7 +6,6 @@ use Illuminate\Support\Facades\Log;
|
|||||||
use Illuminate\Support\Str;
|
use Illuminate\Support\Str;
|
||||||
|
|
||||||
use App\Classes\Protocol as BaseProtocol;
|
use App\Classes\Protocol as BaseProtocol;
|
||||||
use App\Classes\Sock\SocketClient;
|
|
||||||
use App\Models\{Address,Domain,Mailer};
|
use App\Models\{Address,Domain,Mailer};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -64,22 +63,6 @@ final class DNS extends BaseProtocol
|
|||||||
public const DNS_TYPE_OPT = 41; // OPT Records
|
public const DNS_TYPE_OPT = 41; // OPT Records
|
||||||
public const DNS_TYPE_DS = 43; // DS Records (Delegation signer RFC 4034)
|
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
|
protected function protocol_init(): int
|
||||||
{
|
{
|
||||||
// N/A
|
// N/A
|
||||||
|
@ -7,7 +7,6 @@ use Illuminate\Support\Facades\Log;
|
|||||||
|
|
||||||
use App\Classes\Protocol as BaseProtocol;
|
use App\Classes\Protocol as BaseProtocol;
|
||||||
use App\Classes\Sock\Exception\SocketException;
|
use App\Classes\Sock\Exception\SocketException;
|
||||||
use App\Classes\Sock\SocketClient;
|
|
||||||
use App\Exceptions\InvalidFTNException;
|
use App\Exceptions\InvalidFTNException;
|
||||||
use App\Interfaces\CRC as CRCInterface;
|
use App\Interfaces\CRC as CRCInterface;
|
||||||
use App\Interfaces\Zmodem as ZmodemInterface;
|
use App\Interfaces\Zmodem as ZmodemInterface;
|
||||||
@ -82,27 +81,6 @@ final class EMSI extends BaseProtocol implements CRCInterface,ZmodemInterface
|
|||||||
'1'=>self::P_ZMODEM,
|
'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($client,(new Address));
|
|
||||||
$this->client->close();
|
|
||||||
exit(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Send our welcome banner
|
* Send our welcome banner
|
||||||
*
|
*
|
||||||
|
@ -202,27 +202,6 @@ final class Zmodem extends Protocol implements CRCInterface,ZmodemInterface
|
|||||||
private string $rxbuf = '';
|
private string $rxbuf = '';
|
||||||
private string $txbuf = '';
|
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($client);
|
|
||||||
$this->client->close();
|
|
||||||
|
|
||||||
Log::info(sprintf('%s:= onConnect - Connection closed [%s]',self::LOGKEY,$client->address_remote));
|
|
||||||
exit(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initialise our session
|
* Initialise our session
|
||||||
*/
|
*/
|
||||||
|
@ -141,7 +141,11 @@ final class SocketServer {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->handler[0]->{$this->handler[1]}($r);
|
// If the handler returns a value, then that is the main thread
|
||||||
|
if (! $this->handler[0]->{$this->handler[1]}($r)) {
|
||||||
|
$r->close();
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,53 +0,0 @@
|
|||||||
<?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());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,53 +0,0 @@
|
|||||||
<?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());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -50,7 +50,7 @@ class ServerStart extends Command
|
|||||||
'address'=>$o->binkp_bind,
|
'address'=>$o->binkp_bind,
|
||||||
'port'=>$o->binkp_port,
|
'port'=>$o->binkp_port,
|
||||||
'proto'=>SOCK_STREAM,
|
'proto'=>SOCK_STREAM,
|
||||||
'class'=>new Binkp,
|
'class'=>new Binkp($o),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
if ($o->emsi_active)
|
if ($o->emsi_active)
|
||||||
@ -58,7 +58,7 @@ class ServerStart extends Command
|
|||||||
'address'=>$o->emsi_bind,
|
'address'=>$o->emsi_bind,
|
||||||
'port'=>$o->emsi_port,
|
'port'=>$o->emsi_port,
|
||||||
'proto'=>SOCK_STREAM,
|
'proto'=>SOCK_STREAM,
|
||||||
'class'=>new EMSI,
|
'class'=>new EMSI($o),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
if ($o->dns_active)
|
if ($o->dns_active)
|
||||||
@ -66,7 +66,7 @@ class ServerStart extends Command
|
|||||||
'address'=>$o->dns_bind,
|
'address'=>$o->dns_bind,
|
||||||
'port'=>$o->dns_port,
|
'port'=>$o->dns_port,
|
||||||
'proto'=>SOCK_DGRAM,
|
'proto'=>SOCK_DGRAM,
|
||||||
'class'=>new DNS,
|
'class'=>new DNS($o),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$children = collect();
|
$children = collect();
|
||||||
|
@ -10,6 +10,7 @@ use Illuminate\Queue\InteractsWithQueue;
|
|||||||
use Illuminate\Queue\ManuallyFailedException;
|
use Illuminate\Queue\ManuallyFailedException;
|
||||||
use Illuminate\Queue\MaxAttemptsExceededException;
|
use Illuminate\Queue\MaxAttemptsExceededException;
|
||||||
use Illuminate\Queue\SerializesModels;
|
use Illuminate\Queue\SerializesModels;
|
||||||
|
use Illuminate\Support\Facades\Config;
|
||||||
use Illuminate\Support\Facades\Log;
|
use Illuminate\Support\Facades\Log;
|
||||||
use Illuminate\Support\Facades\Notification;
|
use Illuminate\Support\Facades\Notification;
|
||||||
|
|
||||||
@ -85,6 +86,7 @@ class AddressPoll implements ShouldQueue, ShouldBeUnique
|
|||||||
}
|
}
|
||||||
|
|
||||||
Log::info(sprintf('%s:- Polling [%s] - attempt [%d]',self::LOGKEY,$this->ao->ftn,$this->attempts()));
|
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) {
|
foreach ($this->ao->system->mailer_preferred as $o) {
|
||||||
// If we chose a protocol, skip to find the mailer details for it
|
// If we chose a protocol, skip to find the mailer details for it
|
||||||
@ -93,12 +95,12 @@ class AddressPoll implements ShouldQueue, ShouldBeUnique
|
|||||||
|
|
||||||
switch ($o->name) {
|
switch ($o->name) {
|
||||||
case 'BINKP':
|
case 'BINKP':
|
||||||
$s = new Binkp;
|
$s = new Binkp($setup);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'EMSI':
|
case 'EMSI':
|
||||||
$s = new EMSI;
|
$s = new EMSI($setup);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user