2021-07-15 14:54:23 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Console\Commands;
|
|
|
|
|
2023-08-05 11:32:45 +00:00
|
|
|
use Carbon\Carbon;
|
2021-07-15 14:54:23 +00:00
|
|
|
use Illuminate\Console\Command;
|
2023-10-26 00:02:36 +00:00
|
|
|
use Illuminate\Support\Facades\Storage;
|
2021-07-15 14:54:23 +00:00
|
|
|
|
2022-11-13 13:29:55 +00:00
|
|
|
use App\Classes\File;
|
2021-07-15 14:54:23 +00:00
|
|
|
use App\Classes\FTN\Packet;
|
2021-09-06 13:39:32 +00:00
|
|
|
use App\Jobs\MessageProcess as Job;
|
2022-11-11 11:57:40 +00:00
|
|
|
use App\Models\Address;
|
2021-07-15 14:54:23 +00:00
|
|
|
|
2021-08-29 14:24:40 +00:00
|
|
|
class PacketProcess extends Command
|
2021-07-15 14:54:23 +00:00
|
|
|
{
|
|
|
|
/**
|
|
|
|
* The name and signature of the console command.
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
2021-09-10 14:38:11 +00:00
|
|
|
protected $signature = 'packet:process'
|
2022-11-13 13:29:55 +00:00
|
|
|
.' {file : Packet to process}'
|
2021-09-10 14:38:11 +00:00
|
|
|
.' {--N|nobot : Dont process bots}'
|
2023-11-22 01:15:48 +00:00
|
|
|
.' {ftn? : System the packet is from}'
|
|
|
|
.' {--Q|dontqueue : Dont queue the message}';
|
2021-07-15 14:54:23 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The console command description.
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
protected $description = 'Process Packet';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Execute the console command.
|
|
|
|
*
|
2023-11-22 01:15:48 +00:00
|
|
|
* @return void
|
2021-07-15 14:54:23 +00:00
|
|
|
* @throws \App\Classes\FTN\InvalidPacketException
|
|
|
|
*/
|
|
|
|
public function handle()
|
|
|
|
{
|
2023-10-26 00:02:36 +00:00
|
|
|
$fs = Storage::disk(config('fido.local_disk'));
|
|
|
|
$rel_name = sprintf('%s/%s',config('fido.dir'),$this->argument('file'));
|
|
|
|
|
|
|
|
$f = new File($fs->path($rel_name));
|
|
|
|
|
2023-11-22 01:15:48 +00:00
|
|
|
$m = [];
|
2023-10-26 00:02:36 +00:00
|
|
|
if ($this->argument('ftn')) {
|
|
|
|
$a = Address::findFTN($this->argument('ftn'));
|
|
|
|
|
2023-11-23 12:17:13 +00:00
|
|
|
} elseif (preg_match(sprintf('/^%s\.pkt$/',Packet::regex),$this->argument('file'),$m)) {
|
|
|
|
$a = Address::findOrFail(hexdec($m[1]));
|
2023-10-26 00:02:36 +00:00
|
|
|
|
|
|
|
} else {
|
|
|
|
$this->error('Unable to determine sender FTN address');
|
|
|
|
exit(1);
|
|
|
|
}
|
2021-07-15 14:54:23 +00:00
|
|
|
|
2022-11-13 13:29:55 +00:00
|
|
|
foreach ($f as $packet) {
|
2023-10-26 00:02:36 +00:00
|
|
|
foreach ($pkt = Packet::process($packet,$f->itemName(),$f->itemSize(),$a?->zone->domain) as $msg) {
|
2022-11-13 13:29:55 +00:00
|
|
|
// @todo Quick check that the packet should be processed by us.
|
2023-01-25 05:26:10 +00:00
|
|
|
$this->info(sprintf('Processing message from [%s] with msgid [%s] in (%s)',$msg->fboss,$msg->msgid,$f->pktName()));
|
2021-09-12 13:06:17 +00:00
|
|
|
|
2022-11-13 13:29:55 +00:00
|
|
|
// Dispatch job.
|
2023-11-22 01:15:48 +00:00
|
|
|
if ($this->option('dontqueue'))
|
|
|
|
Job::dispatchSync($msg,$f->pktName(),$a,$pkt->fftn_o,Carbon::now(),$this->option('nobot'));
|
|
|
|
else
|
|
|
|
Job::dispatch($msg,$f->pktName(),$a,$pkt->fftn_o,Carbon::now(),$this->option('nobot'));
|
2022-11-13 13:29:55 +00:00
|
|
|
}
|
2021-07-15 14:54:23 +00:00
|
|
|
}
|
|
|
|
}
|
2023-07-15 00:46:19 +00:00
|
|
|
}
|