Create TO ftn (for netmails), identify REPLYID, add file:list

This commit is contained in:
Deon George 2022-11-11 22:57:40 +11:00
parent 6284016400
commit eab36c1603
7 changed files with 88 additions and 17 deletions

View File

@ -5,7 +5,7 @@ APP_DEBUG=true
#APP_URL=http://localhost
LOG_CHANNEL=stderr
LOG_LEVEL=info
LOG_LEVEL=debug
DB_CONNECTION=pgsql
DB_HOST=postgres-test

View File

@ -45,7 +45,6 @@ class Message extends FTNBase
'codepage' => 'CODEPAGE: ',
'dbid' => 'DBID: ',
'pid' => 'PID: ',
'replyid' => 'REPLY: ',
'tid' => 'TID: ',
];
@ -176,7 +175,6 @@ class Message extends FTNBase
$this->zone = $zone;
$this->header = [];
$this->kludge = collect();
$this->user_from = '';
$this->user_to = '';
@ -234,6 +232,19 @@ class Message extends FTNBase
return NULL;
case 'tdomain':
// We'll use the zone's domain if this method class was called with a zone
if ($this->zone && ($this->zone->domain->name == Arr::get($this->dst,'d')))
return $this->zone->domain;
// If we get the domain from the packet, we'll find it
if ($x=Arr::get($this->dst,'d')) {
return Domain::where('name',$x)->single();
}
// Otherwise we'll assume the same as the source domain
return $this->fdomain ?: NULL;
case 'fzone':
// Use the zone if this class was called with it.
if ($this->zone && ($this->fz == $this->zone->zone_id))
@ -250,12 +261,28 @@ class Message extends FTNBase
->where('default',TRUE)
->single();
case 'tzone':
// Use the zone if this class was called with it.
if ($this->zone && ($this->tz == $this->zone->zone_id))
return $this->zone;
// If we have a domain, we'll use the zone from the domain
if ($x=$this->tdomain) {
if (($x=$this->tdomain->zones->search(function($item) { return $item->zone_id == $this->tz; })) !== FALSE)
return $this->tdomain->zones->get($x);
}
// No domain, so we'll use the default zone
return Zone::where('zone_id',$this->tz)
->where('default',TRUE)
->single();
// To Addresses
// Echomail doesnt have a zone, so we'll use the source zone
case 'tz': return Arr::get($this->echoarea ? $this->src : $this->dst,'z');
case 'tn': return Arr::get($this->header,'dnet');
case 'tf': return Arr::get($this->header,'dnode');
case 'tp': return Arr::get($this->dst,'p'); // @todo this wont work for netmails, since dst is not set for in transit messages
case 'tp': ;return Arr::get($this->dst,'p',0); // @todo this wont work for netmails, since dst is not set for in transit messages
case 'fftn':
case 'fftn_o':
@ -818,6 +845,9 @@ class Message extends FTNBase
elseif ($t = $this->kludge('MSGID: ',$kl))
$this->msgid = $t;
elseif ($t = $this->kludge('REPLY: ',$kl))
$this->replyid = $t;
elseif ($t = $this->kludge('GATE: ',$kl))
$this->gateid = $t;

View File

@ -450,12 +450,12 @@ class Packet extends FTNBase implements \Iterator, \Countable
Address::reguard();
} catch (\Exception $e) {
Log::error(sprintf('%s:! Error finding/creating address [%s] for message',self::LOGKEY,$msg->tboss));
Log::error(sprintf('%s:! Error finding/creating TO address [%s] for message',self::LOGKEY,$msg->tboss),['error'=>$e->getMessage()]);
}
// This shouldnt happen
if ($e || $ao->exists) {
Log::error(sprintf('%s:! Unexpected error attempting to create address [%s]',self::LOGKEY,$msg->tboss));
Log::error(sprintf('%s:! Unexpected error attempting to create TO address [%s]',self::LOGKEY,$msg->tboss));
$this->errors->push($msg);
return;
}
@ -492,12 +492,12 @@ class Packet extends FTNBase implements \Iterator, \Countable
Address::reguard();
} catch (\Exception $e) {
Log::error(sprintf('%s:! Error finding/creating address [%s] for message',self::LOGKEY,$msg->fboss));
Log::error(sprintf('%s:! Error finding/creating FROM address [%s] for message',self::LOGKEY,$msg->fboss),['error'=>$e->getMessage()]);
}
// This shouldnt happen
if ($e || $ao->exists) {
Log::error(sprintf('%s:! Unexpected error attempting to create address [%s]',self::LOGKEY,$msg->fboss));
Log::error(sprintf('%s:! Unexpected error attempting to create FROM address [%s]',self::LOGKEY,$msg->fboss));
$this->errors->push($msg);
return;
}

View File

@ -0,0 +1,42 @@
<?php
namespace App\Console\Commands;
use App\Models\File;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;
class FilesList extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'files:list';
/**
* The console command description.
*
* @var string
*/
protected $description = 'List files';
/**
* Execute the console command.
*
* @return int
*/
public function handle()
{
$this->table([
'files.id' => 'ID',
'file' => 'Filename',
'area' => 'Filearea'
],File::select(['files.id','file',DB::raw('fileareas.name AS filearea')])
->join('fileareas',['fileareas.id'=>'files.filearea_id'])
->cursor());
return Command::SUCCESS;
}
}

View File

@ -7,7 +7,7 @@ use Symfony\Component\HttpFoundation\File\File;
use App\Classes\FTN\Packet;
use App\Jobs\MessageProcess as Job;
use App\Models\Zone;
use App\Models\Address;
class PacketProcess extends Command
{
@ -19,7 +19,7 @@ class PacketProcess extends Command
protected $signature = 'packet:process'
.' {pkt : Packet to process}'
.' {--N|nobot : Dont process bots}'
.' {system? : Zone the packet is from}';
.' {ftn? : System the packet is from}';
/**
* The console command description.
@ -37,7 +37,7 @@ class PacketProcess extends Command
public function handle()
{
$f = new File($this->argument('pkt'));
$s = $this->argument('system') ? Zone::where('name',$this->argument('system'))->singleOrFail() : NULL;
$s = $this->argument('ftn') ? Address::findFTN($this->argument('ftn'))->system : NULL;
foreach (Packet::open($f,$s) as $msg) {
// @todo Quick check that the packet should be processed by us.

View File

@ -36,9 +36,9 @@ class NodeHierarchy extends Seeder
]);
foreach (['domain-a','domain-b'] as $domain) {
$domain = Domain::where('name',$domain)->singleOrFail();
$this->hierarchy($domain,100);
$this->hierarchy($domain,101);
$do = Domain::where('name',$domain)->singleOrFail();
$this->hierarchy($do,100);
$this->hierarchy($do,101);
}
}

View File

@ -106,9 +106,8 @@ class PacketTest extends TestCase
$this->assertNotTrue($msg->isNetmail());
$this->assertCount(0,$msg->rogue_path);
$this->assertCount(2,$msg->rogue_seenby);
$this->assertCount(1,$msg->rogue_seenby);
$this->assertNotFalse($msg->rogue_seenby->search('10:1/1'));
$this->assertNotFalse($msg->rogue_seenby->search('10:999/999'));
$this->assertNotFalse($msg->seenaddress->search($src->id));
}
@ -181,7 +180,7 @@ class PacketTest extends TestCase
$this->assertSame('61078e680cda04c8b5eba0f712582e70',md5($msg->message));
$this->assertSame('b9d65d4f7319ded282f3f1986276ae79',md5($msg->message_src));
$this->assertCount(1,$msg->pathaddress);
$this->assertCount(2,$msg->rogue_seenby);
$this->assertCount(1,$msg->rogue_seenby);
$this->assertContains('1/1 999/1 999',$msg->seenby);
$this->assertContains('999/1',$msg->path);
$this->assertCount(1,$msg->seenby);