clrghouz/app/Console/Commands/BinkpSend.php
2021-07-02 23:44:20 +10:00

58 lines
1.5 KiB
PHP

<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use Illuminate\Database\Eloquent\ModelNotFoundException;
use Illuminate\Support\Facades\Log;
use App\Classes\Protocol\Binkp;
use App\Classes\Sock\SocketClient;
use App\Models\{Address,Setup};
class BinkpSend extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'binkp:send {ftn : FTN to Send to}';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Binkp send';
/**
* Execute the console command.
*
* @return mixed
* @throws \App\Classes\Sock\SocketException
* @throws \Exception
*/
public function handle()
{
Log::info('Call BINKP send');
$no = Address::findFTN($this->argument('ftn'));
if (! $no)
throw new ModelNotFoundException('Unknown node: '.$this->argument('ftn'));
if ($no->system->mailer_type != Setup::O_BINKP)
throw new \Exception(sprintf('Node [%s] doesnt support BINKD',$this->argument('ftn')));
if ((! $no->system->mailer_address) || (! $no->system->mailer_port))
throw new \Exception(sprintf('Unable to poll [%s] missing mailer details',$this->argument('ftn')));
$client = SocketClient::create($no->system->mailer_address,$no->system->mailer_port);
$o = new Binkp(Setup::findOrFail(config('app.id')));
$o->session(Binkp::SESSION_BINKP,$client,$no);
Log::info(sprintf('Connection ended: %s',$client->getAddress()),['m'=>__METHOD__]);
}
}