clrghouz/app/Console/Commands/PacketInfo.php

103 lines
3.2 KiB
PHP
Raw Normal View History

2021-08-12 13:15:45 +00:00
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
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;
use App\Models\Address;
2021-08-12 13:15:45 +00:00
class PacketInfo extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'packet:info'
2022-11-13 13:29:55 +00:00
.' {file : Packet to process}'
.' {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.
*
* @return mixed
* @throws \App\Classes\FTN\InvalidPacketException
*/
public function handle()
{
$fs = Storage::disk(config('fido.local_disk'));
$rel_name = sprintf('%s/%s',config('fido.dir'),$this->argument('file'));
$a = NULL;
$f = new File($fs->path($rel_name));
$m = NULL;
if ($this->argument('ftn')) {
$a = Address::findFTN($this->argument('ftn'));
} elseif (preg_match(sprintf('/^%s\.(.{3})$/',Packet::regex),$this->argument('file'),$m)) {
$a = Address::findOrFail(hexdec($m[1]));
}
2021-08-12 13:15:45 +00:00
2022-11-13 13:29:55 +00:00
foreach ($f as $packet) {
$pkt = Packet::process($packet,$x=$f->itemName(),$f->itemSize(),$a?->zone->domain);
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
$this->info(sprintf('Packet Type : %s (%s)',$pkt->type,get_class($pkt)));
2023-01-11 02:08:59 +00:00
$this->info(sprintf('From : %s to %s',$pkt->fftn,$pkt->tftn));
$this->info(sprintf('Dated : %s (%s)',$pkt->date,$pkt->date->timestamp));
2023-01-11 02:08:59 +00:00
$this->info(sprintf('Password : %s (%s)',$pkt->password,$pkt->password ? 'SET' : 'NOT set'));
$this->info(sprintf('Messages : %d',$pkt->messages->count()));
$this->info(sprintf('Tosser : %d (%s) version %s',$pkt->software->code,$pkt->software->name,$pkt->software_ver));
2022-11-13 13:29:55 +00:00
$this->info(sprintf('Capabilities: %x',$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) {
2023-01-11 02:08:59 +00:00
try {
$this->warn(sprintf('- Date : %s',$msg->date));
$this->warn(sprintf(' - Flags : %s',$msg->flags()->filter()->keys()->join(', ')));
$this->warn(sprintf(' - From : %s (%s)',$msg->user_from,$msg->fftn));
$this->warn(sprintf(' - To : %s (%s)',$msg->user_to,$msg->tftn));
$this->warn(sprintf(' - Subject: %s',$msg->subject));
$this->warn(sprintf(' - Area : %s',$msg->echoarea));
2022-11-13 13:29:55 +00:00
2023-01-11 02:08:59 +00:00
if ($msg->errors)
foreach ($msg->errors->errors()->all() as $error)
$this->line(' - '.$error);
} 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) {
$this->error(sprintf('- Date: %s',$msg->date));
$this->error(sprintf(' - FLAGS: %s',$msg->flags()->filter()->keys()->join(', ')));
$this->error(sprintf(' - From: %s (%s)',$msg->user_from,$msg->fftn));
$this->error(sprintf(' - To: %s (%s)',$msg->user_to,$msg->tftn));
$this->error(sprintf(' - Subject: %s',$msg->subject));
2021-08-13 13:46:48 +00:00
foreach ($msg->errors->errors()->all() as $error)
$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
}
}
}