2024-05-28 00:44:33 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Console\Commands\Debug;
|
|
|
|
|
|
|
|
use Illuminate\Console\Command;
|
|
|
|
|
|
|
|
use App\Models\Address;
|
|
|
|
|
|
|
|
class PacketDump extends Command
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* The name and signature of the console command.
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
protected $signature = 'debug:packet:dump'.
|
|
|
|
' {type : Type of packet, netmail|echomail }'.
|
|
|
|
' {ftn : FTN}'.
|
2024-06-17 09:03:48 +00:00
|
|
|
' {file? : filename}';
|
2024-05-28 00:44:33 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The console command description.
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
protected $description = 'Create an outgoing FTN packet';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Execute the console command.
|
|
|
|
*
|
|
|
|
* @return int
|
|
|
|
* @throws \Exception
|
|
|
|
*/
|
|
|
|
public function handle(): int
|
|
|
|
{
|
|
|
|
$ao = Address::findFTN($this->argument('ftn'));
|
|
|
|
|
|
|
|
switch (strtolower($this->argument('type'))) {
|
|
|
|
case 'netmail':
|
|
|
|
$pkt = $ao->getNetmail();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'echomail':
|
|
|
|
$pkt = $ao->getEchomail();
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
$this->error('Unknown type: '.$this->argument('type'));
|
|
|
|
throw new \Exception('Unknown type: '.$this->argument('type'));
|
|
|
|
}
|
|
|
|
|
2024-06-17 09:03:48 +00:00
|
|
|
if (! $this->argument('file')) {
|
2024-05-28 00:44:33 +00:00
|
|
|
$this->info('Item Name:'.$pkt->name);
|
|
|
|
$this->info('Item Type:'.get_class($pkt));
|
|
|
|
$this->info('Dump:');
|
2024-06-17 09:03:48 +00:00
|
|
|
echo hex_dump((string)$pkt);
|
2024-05-28 00:44:33 +00:00
|
|
|
|
|
|
|
} else {
|
|
|
|
$f = fopen($this->argument('file'),'w+');
|
|
|
|
fputs($f,(string)$pkt);
|
|
|
|
fclose($f);
|
|
|
|
}
|
|
|
|
|
|
|
|
return self::SUCCESS;
|
|
|
|
}
|
|
|
|
}
|