Integrate Mailer::class into System_Log::class, removed Zmodem Server/Client
This commit is contained in:
parent
8fc0336314
commit
0526500ff0
@ -9,7 +9,7 @@ use App\Classes\File\{Receive,Send};
|
||||
use App\Classes\Protocol\EMSI;
|
||||
use App\Classes\Sock\SocketClient;
|
||||
use App\Classes\Sock\SocketException;
|
||||
use App\Models\{Address,Setup,System,SystemLog};
|
||||
use App\Models\{Address,Mailer,Setup,System,SystemLog};
|
||||
|
||||
abstract class Protocol
|
||||
{
|
||||
@ -26,16 +26,6 @@ abstract class Protocol
|
||||
protected const RCDO = -3;
|
||||
protected const ERROR = -5;
|
||||
|
||||
// Our sessions Types
|
||||
/** @deprecated use Mailer::class */
|
||||
public const SESSION_AUTO = 0;
|
||||
/** @deprecated Use mailers:class */
|
||||
public const SESSION_EMSI = 1;
|
||||
/** @deprecated Use mailers:class */
|
||||
public const SESSION_BINKP = 2;
|
||||
/** @deprecated Use mailers:class */
|
||||
public const SESSION_ZMODEM = 3;
|
||||
|
||||
protected const MAX_PATH = 1024;
|
||||
|
||||
/* O_ options - [First 9 bits are protocol P_* (Interfaces/ZModem)] */
|
||||
@ -331,13 +321,13 @@ abstract class Protocol
|
||||
/**
|
||||
* Initialise our Session
|
||||
*
|
||||
* @param int $type
|
||||
* @param Mailer $mo
|
||||
* @param SocketClient $client
|
||||
* @param Address|null $o
|
||||
* @return int
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function session(int $type,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]);
|
||||
@ -371,10 +361,9 @@ abstract class Protocol
|
||||
$this->optionSet(self::O_TCP);
|
||||
$this->setClient($client);
|
||||
|
||||
switch ($type) {
|
||||
/** @noinspection PhpMissingBreakStatementInspection */
|
||||
case self::SESSION_AUTO:
|
||||
Log::debug(sprintf('%s:- Trying EMSI',self::LOGKEY));
|
||||
switch ($mo->name) {
|
||||
case 'EMSI':
|
||||
Log::debug(sprintf('%s:- Starting EMSI',self::LOGKEY));
|
||||
|
||||
$rc = $this->protocol_init();
|
||||
if ($rc < 0) {
|
||||
@ -383,27 +372,19 @@ abstract class Protocol
|
||||
return self::S_FAILURE;
|
||||
}
|
||||
|
||||
case self::SESSION_EMSI:
|
||||
Log::debug(sprintf('%s:- Starting EMSI',self::LOGKEY));
|
||||
$rc = $this->protocol_session($this->originate);
|
||||
|
||||
break;
|
||||
|
||||
case self::SESSION_BINKP:
|
||||
case 'BINKP':
|
||||
Log::debug(sprintf('%s:- Starting BINKP',self::LOGKEY));
|
||||
|
||||
$rc = $this->protocol_session($this->originate);
|
||||
|
||||
break;
|
||||
|
||||
case self::SESSION_ZMODEM:
|
||||
Log::debug(sprintf('%s:- Starting ZMODEM',self::LOGKEY));
|
||||
$this->client->speed = self::TCP_SPEED;
|
||||
$this->originate = FALSE;
|
||||
|
||||
return $this->protocol_session($this->originate);
|
||||
|
||||
default:
|
||||
Log::error(sprintf('%s:! Unsupported session type [%d]',self::LOGKEY,$type));
|
||||
Log::error(sprintf('%s:! Unsupported session type [%d]',self::LOGKEY,$mo->id));
|
||||
|
||||
return self::S_FAILURE;
|
||||
}
|
||||
@ -448,7 +429,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->sessiontype = $type;
|
||||
$slo->mailer_id = $mo->id;
|
||||
$slo->sessiontime = $this->node->session_time;
|
||||
$slo->result = ($rc & self::S_MASK);
|
||||
$slo->originate = $this->originate;
|
||||
|
@ -14,7 +14,7 @@ use App\Classes\Protocol as BaseProtocol;
|
||||
use App\Classes\Sock\SocketClient;
|
||||
use App\Classes\Sock\SocketException;
|
||||
use App\Exceptions\{FileGrewException,InvalidFTNException};
|
||||
use App\Models\Address;
|
||||
use App\Models\{Address,Mailer};
|
||||
|
||||
final class Binkp extends BaseProtocol
|
||||
{
|
||||
@ -148,7 +148,6 @@ final class Binkp extends BaseProtocol
|
||||
* @param SocketClient $client
|
||||
* @return int|null
|
||||
* @throws SocketException
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function onConnect(SocketClient $client): ?int
|
||||
{
|
||||
@ -156,8 +155,7 @@ final class Binkp extends BaseProtocol
|
||||
if (! parent::onConnect($client)) {
|
||||
Log::withContext(['pid'=>getmypid()]);
|
||||
|
||||
// @todo If we can use SESSION_EMSI set an object class value that in BINKP of SESSION_BINKP, and move this method to the parent class
|
||||
$this->session(self::SESSION_BINKP,$client,(new Address));
|
||||
$this->session(Mailer::where('name','BINKP')->singleOrFail(),$client,(new Address));
|
||||
$this->client->close();
|
||||
exit(0);
|
||||
}
|
||||
|
@ -9,7 +9,7 @@ use App\Classes\Protocol as BaseProtocol;
|
||||
use App\Classes\Sock\SocketClient;
|
||||
use App\Classes\Sock\SocketException;
|
||||
use App\Exceptions\InvalidFTNException;
|
||||
use App\Models\{Address,Setup};
|
||||
use App\Models\{Address,Mailer,Setup};
|
||||
use App\Interfaces\CRC as CRCInterface;
|
||||
use App\Interfaces\Zmodem as ZmodemInterface;
|
||||
use App\Traits\CRC as CRCTrait;
|
||||
@ -88,7 +88,6 @@ final class EMSI extends BaseProtocol implements CRCInterface,ZmodemInterface
|
||||
* @param SocketClient $client
|
||||
* @return int|null
|
||||
* @throws SocketException
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function onConnect(SocketClient $client): ?int
|
||||
{
|
||||
@ -96,8 +95,7 @@ final class EMSI extends BaseProtocol implements CRCInterface,ZmodemInterface
|
||||
if (! parent::onConnect($client)) {
|
||||
Log::withContext(['pid'=>getmypid()]);
|
||||
|
||||
// @todo Can this be SESSION_EMSI? if so, set an object class value that in EMSI of SESSION_EMSI, and move this method to the parent class
|
||||
$this->session(self::SESSION_AUTO,$client,(new Address));
|
||||
$this->session(Mailer::where('name','EMSI')->singleOrFail(),$client,(new Address));
|
||||
$this->client->close();
|
||||
exit(0);
|
||||
}
|
||||
|
@ -10,7 +10,7 @@ use App\Classes\File\{Receive,Send};
|
||||
use App\Classes\Sock\{SocketClient,SocketException};
|
||||
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;
|
||||
|
||||
/**
|
||||
@ -213,7 +213,7 @@ final class Zmodem extends Protocol implements CRCInterface,ZmodemInterface
|
||||
if (! parent::onConnect($client)) {
|
||||
Log::withContext(['pid'=>getmypid()]);
|
||||
|
||||
$this->session(self::SESSION_ZMODEM,$client);
|
||||
$this->session(Mailer::where('name','ZMODEM')->singleOrFail(),$client);
|
||||
$this->client->close();
|
||||
|
||||
Log::info(sprintf('%s:= onConnect - Connection closed [%s]',self::LOGKEY,$client->address_remote));
|
||||
|
@ -1,51 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
use App\Classes\Sock\SocketException;
|
||||
use App\Classes\Sock\SocketServer;
|
||||
use App\Classes\Protocol\Zmodem as ZmodemClass;
|
||||
|
||||
class CommZmodemReceive extends Command
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'comm:zmodem:receive';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'ZMODEM receive';
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return mixed
|
||||
* @throws SocketException
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
Log::info('Listening for ZMODEM connections...');
|
||||
|
||||
$server = new SocketServer(60177,'0.0.0.0');
|
||||
$server->handler = [new ZmodemClass,'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,45 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
use App\Classes\Protocol;
|
||||
use App\Classes\Protocol\Zmodem as ZmodemClass;
|
||||
use App\Classes\Sock\SocketClient;
|
||||
|
||||
class CommZmodemSend extends Command
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'comm:zmodem:send {ip}';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'ZMODEM send';
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
Log::info('Call ZMODEM send');
|
||||
|
||||
[$address,$service_port] = explode(':',$this->argument('ip'),2);
|
||||
$client = SocketClient::create($address,$service_port);
|
||||
|
||||
$o = new ZmodemClass;
|
||||
$o->session(Protocol::SESSION_ZMODEM,$client);
|
||||
|
||||
Log::info(sprintf('Connection ended: %s',$client->address_remote),['m'=>__METHOD__]);
|
||||
}
|
||||
}
|
@ -94,13 +94,13 @@ class AddressPoll implements ShouldQueue, ShouldBeUnique
|
||||
switch ($o->name) {
|
||||
case 'BINKP':
|
||||
$s = new Binkp(Setup::findOrFail(config('app.id')));
|
||||
$session = Binkp::SESSION_BINKP;
|
||||
$mo = Mailer::where('name','BINKP')->singleOrFail();
|
||||
|
||||
break;
|
||||
|
||||
case 'EMSI':
|
||||
$s = new EMSI(Setup::findOrFail(config('app.id')));
|
||||
$session = EMSI::SESSION_AUTO;
|
||||
$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($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;
|
||||
|
||||
|
@ -8,6 +8,11 @@ class SystemLog extends Model
|
||||
{
|
||||
/* RELATIONS */
|
||||
|
||||
public function mailer()
|
||||
{
|
||||
return $this->belongsTo(Mailer::class);
|
||||
}
|
||||
|
||||
public function system()
|
||||
{
|
||||
return $this->belongsTo(System::class);
|
||||
|
46
database/migrations/2023_12_10_143252_fix_mailer_id.php
Normal file
46
database/migrations/2023_12_10_143252_fix_mailer_id.php
Normal file
@ -0,0 +1,46 @@
|
||||
<?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->bigInteger('mailer_id')->nullable()->after('system_id');
|
||||
$table->foreign('mailer_id')->references('id')->on('mailers');
|
||||
});
|
||||
|
||||
DB::update('UPDATE system_logs SET mailer_id=? WHERE sessiontype=?',[1,2]);
|
||||
DB::update('UPDATE system_logs SET mailer_id=? WHERE sessiontype=?',[2,0]);
|
||||
DB::update('ALTER TABLE system_logs ALTER COLUMN mailer_id SET NOT NULL');
|
||||
|
||||
Schema::table('system_logs',function (Blueprint $table) {
|
||||
$table->dropColumn(['sessiontype']);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('system_logs',function (Blueprint $table) {
|
||||
$table->integer('sessiontype')->nullable();
|
||||
});
|
||||
|
||||
DB::update('UPDATE system_logs SET sessiontype=? WHERE mailer_id=?',[0,2]);
|
||||
DB::update('UPDATE system_logs SET sessiontype=? WHERE mailer_id=?',[2,1]);
|
||||
DB::update('ALTER TABLE system_logs ALTER COLUMN sessiontype SET NOT NULL');
|
||||
|
||||
Schema::table('system_logs',function (Blueprint $table) {
|
||||
$table->dropForeign(['mailer_id']);
|
||||
$table->dropColumn(['mailer_id']);
|
||||
});
|
||||
}
|
||||
};
|
@ -267,7 +267,7 @@
|
||||
Method:
|
||||
</div>
|
||||
<div class="col-8">
|
||||
<strong class="highlight">{{ $x?->sessiontype ? \App\Models\Mailer::findOrFail($x->sessiontype)->name : '-' }}</strong>
|
||||
<strong class="highlight">{{ $x ? $x->mailer->name : '-' }}</strong>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user