clrghouz/app/Console/Commands/PacketInfo.php

91 lines
2.8 KiB
PHP

<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use App\Classes\File;
use App\Classes\FTN\Packet;
use App\Models\System;
class PacketInfo extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'packet:info'
.' {file : Packet to process}'
.' {system? : System the packet is from}';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Packet Information';
/**
* Execute the console command.
*
* @return mixed
* @throws \App\Classes\FTN\InvalidPacketException
*/
public function handle()
{
$f = new File($this->argument('file'));
$s = $this->argument('system') ? System::where('name',$this->argument('system'))->singleOrFail() : NULL;
foreach ($f as $packet) {
$pkt = Packet::process($packet,$x=$f->itemName(),$f->itemSize(),$s);
$this->alert(sprintf('File Name: %s',$x));
$this->info(sprintf('Packet Type : %s (%s)',$pkt->type,get_class($pkt)));
$this->info(sprintf('From : %s to %s',$pkt->fftn,$pkt->tftn));
$this->info(sprintf('Dated : %s',$pkt->date));
$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));
$this->info(sprintf('Capabilities: %x',$pkt->capability));
$this->info(sprintf('Has Errors : %s',$pkt->errors->count() ? 'YES' : 'No'));
$this->info(sprintf('Messages : %d',$pkt->count()));
foreach ($pkt as $msg) {
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));
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);
}
}
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));
foreach ($msg->errors->errors()->all() as $error)
$this->line(' - '.$error);
}
$this->line("\n");
}
}
}