Process packet seenby/path/via lines when saving echomail/netmail
This commit is contained in:
@@ -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,
|
||||
]);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
Reference in New Issue
Block a user