2021-08-12 13:15:45 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Console\Commands;
|
|
|
|
|
|
|
|
use Illuminate\Console\Command;
|
2023-10-06 04:14:15 +00:00
|
|
|
use Illuminate\Support\Facades\Storage;
|
2021-08-12 13:15:45 +00:00
|
|
|
|
2022-11-13 13:29:55 +00:00
|
|
|
use App\Classes\File;
|
2021-08-12 13:15:45 +00:00
|
|
|
use App\Classes\FTN\Packet;
|
2024-05-17 12:10:54 +00:00
|
|
|
use App\Models\{Address,Echomail};
|
2021-08-12 13:15:45 +00:00
|
|
|
|
|
|
|
class PacketInfo extends Command
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* The name and signature of the console command.
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
2021-10-19 11:38:52 +00:00
|
|
|
protected $signature = 'packet:info'
|
2022-11-13 13:29:55 +00:00
|
|
|
.' {file : Packet to process}'
|
2023-09-20 10:29:23 +00:00
|
|
|
.' {ftn? : FTN the packet is from}';
|
2021-08-12 13:15:45 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The console command description.
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
protected $description = 'Packet Information';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Execute the console command.
|
|
|
|
*
|
2024-05-27 05:08:39 +00:00
|
|
|
* @return int
|
2024-05-17 12:10:54 +00:00
|
|
|
* @throws \App\Exceptions\InvalidPacketException
|
2021-08-12 13:15:45 +00:00
|
|
|
*/
|
2024-05-27 05:08:39 +00:00
|
|
|
public function handle():int
|
2021-08-12 13:15:45 +00:00
|
|
|
{
|
2023-10-06 04:14:15 +00:00
|
|
|
$fs = Storage::disk(config('fido.local_disk'));
|
|
|
|
$rel_name = sprintf('%s/%s',config('fido.dir'),$this->argument('file'));
|
2023-10-26 00:02:36 +00:00
|
|
|
$a = NULL;
|
2023-10-06 04:14:15 +00:00
|
|
|
|
|
|
|
$f = new File($fs->path($rel_name));
|
2023-10-26 00:02:36 +00:00
|
|
|
|
|
|
|
$m = NULL;
|
|
|
|
if ($this->argument('ftn')) {
|
|
|
|
$a = Address::findFTN($this->argument('ftn'));
|
|
|
|
|
2023-11-24 22:48:37 +00:00
|
|
|
} elseif (preg_match(sprintf('/^%s\.(.{3})$/',Packet::regex),$this->argument('file'),$m)) {
|
2023-11-23 12:17:13 +00:00
|
|
|
$a = Address::findOrFail(hexdec($m[1]));
|
2023-10-26 00:02:36 +00:00
|
|
|
}
|
2021-08-12 13:15:45 +00:00
|
|
|
|
2022-11-13 13:29:55 +00:00
|
|
|
foreach ($f as $packet) {
|
2024-11-02 05:35:22 +00:00
|
|
|
$pkt = Packet::process($packet,$x=$f->itemName(),$f->itemSize(),$a?->system);
|
2021-08-12 13:15:45 +00:00
|
|
|
|
2022-11-13 13:29:55 +00:00
|
|
|
$this->alert(sprintf('File Name: %s',$x));
|
2021-08-12 13:15:45 +00:00
|
|
|
|
2023-06-25 10:45:02 +00:00
|
|
|
$this->info(sprintf('Packet Type : %s (%s)',$pkt->type,get_class($pkt)));
|
2024-05-27 23:35:22 +00:00
|
|
|
$this->info(sprintf('From : %s to %s',$pkt->fftn->ftn,$pkt->tftn ? $pkt->tftn->ftn : $pkt->tftn_t));
|
2024-05-17 12:10:54 +00:00
|
|
|
$this->info(sprintf('Dated : %s (%s) [%s]',$pkt->date,$pkt->date->timestamp,$pkt->date->tz->toOffsetName()));
|
|
|
|
$this->info(sprintf('Password : %s (%s)',$pkt->password ?: '-',$pkt->password ? 'SET' : 'NOT set'));
|
|
|
|
$this->info(sprintf('Messages : %d',$pkt->count()));
|
2024-05-28 02:23:59 +00:00
|
|
|
$this->info(sprintf('Tosser : %d (%s) version %s (%x)',$pkt->software->code,$pkt->software->name,$pkt->software_ver,$pkt->product));
|
|
|
|
$this->info(sprintf('Capabilities: %s',$pkt->capability));
|
2023-01-11 02:08:59 +00:00
|
|
|
$this->info(sprintf('Has Errors : %s',$pkt->errors->count() ? 'YES' : 'No'));
|
|
|
|
$this->info(sprintf('Messages : %d',$pkt->count()));
|
2022-11-13 13:29:55 +00:00
|
|
|
|
|
|
|
foreach ($pkt as $msg) {
|
2024-05-17 12:10:54 +00:00
|
|
|
echo "\n";
|
|
|
|
|
2023-01-11 02:08:59 +00:00
|
|
|
try {
|
2024-11-19 12:26:35 +00:00
|
|
|
$this->warn(sprintf('- TYPE : %s',get_class($msg)));
|
|
|
|
$this->warn(sprintf(' - Date : %s (%s)',$msg->date,$msg->date->tz->toOffsetName()));
|
2024-05-20 11:31:21 +00:00
|
|
|
$this->warn(sprintf(' - Errors : %s',$msg->errors->count() ? 'YES' : 'No'));
|
2024-05-17 12:10:54 +00:00
|
|
|
$this->warn(sprintf(' - Flags : %s',$msg->flags()->keys()->join(', ')));
|
|
|
|
$this->warn(sprintf(' - Cost : %d',$msg->cost));
|
|
|
|
$this->warn(sprintf(' - From : %s (%s)',$msg->from,$msg->fftn->ftn));
|
|
|
|
if ($msg instanceof Echomail)
|
|
|
|
$this->warn(sprintf(' - To : %s',$msg->to));
|
|
|
|
else
|
|
|
|
$this->warn(sprintf(' - To : %s (%s)',$msg->to,$msg->tftn->ftn));
|
2023-01-11 02:08:59 +00:00
|
|
|
$this->warn(sprintf(' - Subject: %s',$msg->subject));
|
2024-05-17 12:10:54 +00:00
|
|
|
if ($msg instanceof Echomail)
|
|
|
|
$this->warn(sprintf(' - Area : %s',$msg->echoarea->name));
|
2022-11-13 13:29:55 +00:00
|
|
|
|
2024-05-20 11:31:21 +00:00
|
|
|
if ($msg->errors->count()) {
|
2024-05-17 12:10:54 +00:00
|
|
|
echo "\n";
|
|
|
|
$this->error("Errors:");
|
2024-05-20 11:31:21 +00:00
|
|
|
foreach ($msg->errors->all() as $error)
|
2024-05-17 12:10:54 +00:00
|
|
|
$this->error(' - '.$error);
|
|
|
|
}
|
2023-01-11 02:08:59 +00:00
|
|
|
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
$this->error('! ERROR: '.$e->getMessage());
|
|
|
|
$this->info('Message dump:');
|
|
|
|
echo hex_dump($msg->dump);
|
|
|
|
exit(1);
|
|
|
|
}
|
2022-11-13 13:29:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
foreach ($pkt->errors as $msg) {
|
2024-06-28 13:27:06 +00:00
|
|
|
$this->error(sprintf('- Date: %s',$msg->datetime));
|
2022-11-13 13:29:55 +00:00
|
|
|
$this->error(sprintf(' - FLAGS: %s',$msg->flags()->filter()->keys()->join(', ')));
|
2024-05-19 13:28:45 +00:00
|
|
|
$this->error(sprintf(' - From: %s (%s)',$msg->from,$msg->fftn));
|
|
|
|
$this->error(sprintf(' - To: %s (%s)',$msg->to,$msg->tftn));
|
2022-11-13 13:29:55 +00:00
|
|
|
$this->error(sprintf(' - Subject: %s',$msg->subject));
|
2021-08-13 13:46:48 +00:00
|
|
|
|
2024-05-20 11:31:21 +00:00
|
|
|
foreach ($msg->errors->all() as $error)
|
2021-08-24 14:15:09 +00:00
|
|
|
$this->line(' - '.$error);
|
2022-11-13 13:29:55 +00:00
|
|
|
}
|
2021-08-13 13:46:48 +00:00
|
|
|
|
2022-11-13 13:29:55 +00:00
|
|
|
$this->line("\n");
|
2021-08-12 13:15:45 +00:00
|
|
|
}
|
2024-05-27 05:08:39 +00:00
|
|
|
|
|
|
|
return self::SUCCESS;
|
2021-08-12 13:15:45 +00:00
|
|
|
}
|
2024-06-28 08:28:12 +00:00
|
|
|
}
|