Process packet seenby/path/via lines when saving echomail/netmail

This commit is contained in:
2023-09-20 20:29:23 +10:00
parent 7fedf88d8c
commit 612efda945
11 changed files with 337 additions and 230 deletions

View File

@@ -13,11 +13,11 @@ use Rennokki\QueryCache\Traits\QueryCacheable;
use App\Casts\{CollectionOrNull,CompressedString};
use App\Classes\FTN\Message;
use App\Interfaces\Packet;
use App\Traits\{EncodeUTF8,MsgID};
use App\Traits\{EncodeUTF8,MsgID,ParseAddresses};
final class Echomail extends Model implements Packet
{
use SoftDeletes,EncodeUTF8,MsgID,QueryCacheable;
use SoftDeletes,EncodeUTF8,MsgID,QueryCacheable,ParseAddresses;
private const LOGKEY = 'ME-';
private Collection $set_seenby;
@@ -68,17 +68,17 @@ final class Echomail extends Model implements Packet
// @todo if the message is updated with new SEEN-BY's from another route, we'll delete the pending export for systems (if there is one)
static::created(function($model) {
if (! $model->echoarea_id) {
Log::alert(sprintf('%s:- Message has no echoarea, not exporting',self::LOGKEY,$model->id));
return;
}
$rogue = collect();
$seenby = NULL;
$path = [];
// Save the seenby
$model->seenby()->sync($model->set_seenby);
// Parse PATH
if ($model->set_path->count())
$path = self::parseAddresses('path',$model->set_path,$model->fftn->zone,$rogue);
// Save the Path
$ppoid = NULL;
foreach ($model->set_path as $aoid) {
foreach ($path as $aoid) {
$po = DB::select('INSERT INTO echomail_path (echomail_id,address_id,parent_id) VALUES (?,?,?) RETURNING id',[
$model->id,
$aoid,
@@ -88,12 +88,26 @@ final class Echomail extends Model implements Packet
$ppoid = $po[0]->id;
}
$rogue = collect();
// Parse SEEN-BY
if ($model->set_seenby->count())
$seenby = self::parseAddresses('seenby',$model->set_seenby,$model->fftn->zone,$rogue);
if (count($rogue)) {
$model->rogue_seenby = $rogue;
$model->save();
}
if ($seenby)
$model->seenby()->sync($seenby);
// Our last node in the path is our sender
if (isset($model->set_pkt) && isset($model->set_recvtime)) {
DB::update('UPDATE echomail_path set recv_pkt=?,recv_at=? where address_id=? and echomail_id=?',[
$model->set_pkt,
$model->set_recvtime,
$model->set_path->last(),
$path->last(),
$model->id,
]);
}
@@ -105,7 +119,7 @@ final class Echomail extends Model implements Packet
->addresses
->filter(function($item) use ($model) { return $item->security >= $model->echoarea->sec_read; }))
->pluck('id')
->diff($model->set_seenby);
->diff($seenby);
if ($exportto->count()) {
if ($model->no_export) {

View File

@@ -15,8 +15,6 @@ use App\Classes\FTN\Message;
use App\Interfaces\Packet;
use App\Traits\{EncodeUTF8,MsgID};
// @deprecated recv_pkt now in netmail_path
// @deprecated local - use flags
final class Netmail extends Model implements Packet
{
private const LOGKEY = 'MN-';
@@ -66,37 +64,68 @@ final class Netmail extends Model implements Packet
parent::boot();
static::created(function($model) {
$nodes = collect();
// Parse PATH
// <FTN Address> @YYYYMMDD.HHMMSS[.Precise][.Time Zone] <Program Name> <Version> [Serial Number]
if (isset($model->set_path)) {
if ($model->set_path->count()) {
foreach ($model->set_path as $line) {
$m = [];
if (preg_match('/^([0-9]+:[0-9]+\/[0-9]+(\..*)?)\s+@([0-9.a-zA-Z]+)\s+(.*)$/',$line,$m)) {
// Address
$ao = Address::findFTN($m[1]);
// Time
$t = [];
$datetime = '';
if (! preg_match('/^([0-9]+\.[0-9]+)(\.?(.*))?$/',$m[3],$t))
Log::alert(sprintf('%s:! Unable to determine time from [%s]',self::LOGKEY,$m[3]));
else
$datetime = Carbon::createFromFormat('Ymd.His',$t[1],$t[3] ?? '');
if (! $ao) {
Log::alert(sprintf('%s:! Undefined Node [%s] for Netmail.',self::LOGKEY,$m[1]));
//$rogue->push(['node'=>$m[1],'datetime'=>$datetime,'program'=>$m[4]]);
} else {
$nodes->push(['node'=>$ao,'datetime'=>$datetime,'program'=>$m[4]]);
}
}
}
// If there are no details (Mystic), we'll create a blank
} else {
$nodes->push(['node'=>$model->set_sender,'datetime'=>Carbon::now(),'program'=>'Unknown']);
}
}
// Save the Path
$ppoid = NULL;
if (isset($model->set_path)) {
// If there are no details (Mystic), we'll create a blank
if (! $model->set_path->count()) {
$model->set_path->push(['node'=>$model->set_sender,'datetime'=>Carbon::now(),'program'=>'Unknown']);
}
foreach ($nodes as $path) {
$po = DB::select('INSERT INTO netmail_path (netmail_id,address_id,parent_id,datetime,program) VALUES (?,?,?,?,?) RETURNING id',[
$model->id,
$path['node']->id,
$ppoid,
(string)$path['datetime'],
$path['program'],
]);
foreach ($model->set_path as $path) {
$po = DB::select('INSERT INTO netmail_path (netmail_id,address_id,parent_id,datetime,program) VALUES (?,?,?,?,?) RETURNING id',[
$model->id,
$path['node']->id,
$ppoid,
(string)$path['datetime'],
$path['program'],
]);
$ppoid = $po[0]->id;
}
$ppoid = $po[0]->id;
}
// Our last node in the path is our sender
if (isset($model->set_pkt) && isset($model->set_sender) && isset($model->set_recvtime)) {
DB::update('UPDATE netmail_path set recv_pkt=?,recv_at=?,recv_id=? where address_id=? and netmail_id=?',[
$model->set_pkt,
$model->set_recvtime,
$model->set_sender->id,
Arr::get($model->set_path->last(),'node')->id,
$model->id,
]);
}
// Our last node in the path is our sender
if ($nodes->count() && isset($model->set_pkt) && isset($model->set_sender) && isset($model->set_recvtime)) {
DB::update('UPDATE netmail_path set recv_pkt=?,recv_at=?,recv_id=? where address_id=? and netmail_id=?',[
$model->set_pkt,
$model->set_recvtime,
$model->set_sender->id,
Arr::get($nodes->last(),'node')->id,
$model->id,
]);
}
});
}