Now correctly showing packet receive time, and sending Notifications based on the packet address, not the node address

This commit is contained in:
Deon George 2023-08-05 21:32:45 +10:00
parent c8a2affbfa
commit 74a56d1e17
9 changed files with 74 additions and 24 deletions

View File

@ -2,6 +2,7 @@
namespace App\Classes\File; namespace App\Classes\File;
use Carbon\Carbon;
use Illuminate\Support\Arr; use Illuminate\Support\Arr;
use Illuminate\Support\Facades\Log; use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Notification; use Illuminate\Support\Facades\Notification;
@ -100,6 +101,8 @@ class Receive extends Base
throw new \Exception('No file to close'); throw new \Exception('No file to close');
if ($this->f) { if ($this->f) {
$rcvd_time = Carbon::now();
if ($this->pos !== $this->receiving->recvsize) if ($this->pos !== $this->receiving->recvsize)
Log::warning(sprintf('%s:- Closing [%s], but missing [%d] bytes',self::LOGKEY,$this->receiving->nameas,$this->receiving->recvsize-$this->pos)); Log::warning(sprintf('%s:- Closing [%s], but missing [%d] bytes',self::LOGKEY,$this->receiving->nameas,$this->receiving->recvsize-$this->pos));
else else
@ -175,9 +178,9 @@ class Receive extends Base
try { try {
// Dispatch job. // Dispatch job.
if ($queue) if ($queue)
MessageProcess::dispatch($msg,$f->pktName(),$this->ao); MessageProcess::dispatch($msg,$f->pktName(),$this->ao,$po->fftn_o,$rcvd_time);
else else
MessageProcess::dispatchSync($msg,$f->pktName(),$this->ao); MessageProcess::dispatchSync($msg,$f->pktName(),$this->ao,$po->fftn_o,$rcvd_time);
} catch (\Exception $e) { } catch (\Exception $e) {
Log::error(sprintf('%s:! Got error dispatching message [%s] (%d:%s-%s).',self::LOGKEY,$msg->msgid,$e->getLine(),$e->getFile(),$e->getMessage())); Log::error(sprintf('%s:! Got error dispatching message [%s] (%d:%s-%s).',self::LOGKEY,$msg->msgid,$e->getLine(),$e->getFile(),$e->getMessage()));

View File

@ -2,6 +2,7 @@
namespace App\Console\Commands; namespace App\Console\Commands;
use Carbon\Carbon;
use Illuminate\Console\Command; use Illuminate\Console\Command;
use App\Classes\File; use App\Classes\File;
@ -47,7 +48,7 @@ class PacketProcess extends Command
$this->info(sprintf('Processing message from [%s] with msgid [%s] in (%s)',$msg->fboss,$msg->msgid,$f->pktName())); $this->info(sprintf('Processing message from [%s] with msgid [%s] in (%s)',$msg->fboss,$msg->msgid,$f->pktName()));
// Dispatch job. // Dispatch job.
Job::dispatchSync($msg,$f->pktName(),$a,$this->option('nobot')); Job::dispatchSync($msg,$f->pktName(),$a,$packet->fftn_o,Carbon::now(),$this->option('nobot'));
} }
} }
} }

View File

@ -23,14 +23,18 @@ class MessageProcess implements ShouldQueue
private Address $sender; private Address $sender;
private Message $msg; private Message $msg;
private Address $pktsrc;
private Carbon $recvtime;
private bool $skipbot; private bool $skipbot;
private string $packet; private string $packet;
public function __construct(Message $msg,string $packet,Address $sender,bool $skipbot=FALSE) public function __construct(Message $msg,string $packet,Address $sender,Address $pktsrc,Carbon $recvtime,bool $skipbot=FALSE)
{ {
$this->msg = $msg; $this->msg = $msg;
$this->packet = $packet; $this->packet = $packet;
$this->sender = $sender; $this->sender = $sender;
$this->pktsrc = $pktsrc;
$this->recvtime = $recvtime;
$this->skipbot = $skipbot; $this->skipbot = $skipbot;
} }
@ -111,6 +115,7 @@ class MessageProcess implements ShouldQueue
$o->set_pkt = $this->packet; $o->set_pkt = $this->packet;
$o->set_sender = $this->sender; $o->set_sender = $this->sender;
$o->set_path = $this->msg->pathaddress; $o->set_path = $this->msg->pathaddress;
$o->set_recvtime = $this->recvtime;
// Strip any local/transit flags // Strip any local/transit flags
$o->flags &= ~(Message::FLAG_LOCAL|Message::FLAG_INTRANSIT); $o->flags &= ~(Message::FLAG_LOCAL|Message::FLAG_INTRANSIT);
@ -222,7 +227,7 @@ class MessageProcess implements ShouldQueue
if (! $ea) { if (! $ea) {
Log::alert(sprintf('%s:! Echoarea [%s] doesnt exist for zone [%d]',self::LOGKEY,$this->msg->echoarea,$this->msg->fboss_o->zone->zone_id)); Log::alert(sprintf('%s:! Echoarea [%s] doesnt exist for zone [%d]',self::LOGKEY,$this->msg->echoarea,$this->msg->fboss_o->zone->zone_id));
Notification::route('netmail',$this->sender)->notify(new EchoareaNotExist($this->msg)); Notification::route('netmail',$this->pktsrc)->notify(new EchoareaNotExist($this->msg));
return; return;
} }
@ -281,14 +286,14 @@ class MessageProcess implements ShouldQueue
// @todo Can the sender create it if it doesnt exist? // @todo Can the sender create it if it doesnt exist?
// Can the system send messages to this area? // Can the system send messages to this area?
if (! $ea->sec_write || ($this->sender->security < $ea->sec_write)) { if (! $ea->sec_write || ($this->pktsrc->security < $ea->sec_write)) {
Notification::route('netmail',$this->sender)->notify(new EchoareaNoWrite($this->msg)); Notification::route('netmail',$this->pktsrc)->notify(new EchoareaNoWrite($this->msg));
return; return;
} }
// If the node is not subsccribed // If the node is not subscribed
if ($this->sender->echoareas->search(function($item) use ($ea) { return $item->id === $ea->id; }) === FALSE) if ($this->pktsrc->echoareas->search(function($item) use ($ea) { return $item->id === $ea->id; }) === FALSE)
Notification::route('netmail',$this->sender)->notify(new EchoareaNotSubscribed($this->msg)); Notification::route('netmail',$this->pktsrc)->notify(new EchoareaNotSubscribed($this->msg));
// We know about this area, store it // We know about this area, store it
$o = new Echomail; $o = new Echomail;
@ -312,6 +317,7 @@ class MessageProcess implements ShouldQueue
$o->rogue_path = $this->msg->rogue_path; $o->rogue_path = $this->msg->rogue_path;
$o->set_path = $this->msg->pathaddress; $o->set_path = $this->msg->pathaddress;
$o->set_seenby = $this->msg->seenaddress; $o->set_seenby = $this->msg->seenaddress;
$o->set_recvtime = $this->recvtime;
// Record receiving packet and sender // Record receiving packet and sender
$o->set_pkt = $this->packet; $o->set_pkt = $this->packet;

View File

@ -22,6 +22,7 @@ final class Echomail extends Model implements Packet
private const LOGKEY = 'ME-'; private const LOGKEY = 'ME-';
private Collection $set_seenby; private Collection $set_seenby;
private Collection $set_path; private Collection $set_path;
private Carbon $set_recvtime;
private string $set_pkt; private string $set_pkt;
private bool $no_export = FALSE; private bool $no_export = FALSE;
@ -51,6 +52,7 @@ final class Echomail extends Model implements Packet
case 'no_export': case 'no_export':
case 'set_path': case 'set_path':
case 'set_pkt': case 'set_pkt':
case 'set_recvtime':
case 'set_seenby': case 'set_seenby':
$this->{$key} = $value; $this->{$key} = $value;
break; break;
@ -87,9 +89,10 @@ final class Echomail extends Model implements Packet
} }
// Our last node in the path is our sender // Our last node in the path is our sender
if (isset($model->set_pkt)) { if (isset($model->set_pkt) && isset($model->set_recvtime)) {
DB::update('UPDATE echomail_path set recv_pkt=? where address_id=? and echomail_id=?',[ DB::update('UPDATE echomail_path set recv_pkt=?,recv_at=? where address_id=? and echomail_id=?',[
$model->set_pkt, $model->set_pkt,
$model->set_recvtime,
$model->set_path->last(), $model->set_path->last(),
$model->id, $model->id,
]); ]);

View File

@ -25,6 +25,7 @@ final class Netmail extends Model implements Packet
private Collection $set_path; private Collection $set_path;
private Address $set_sender; private Address $set_sender;
private Carbon $set_recvtime;
private string $set_pkt; private string $set_pkt;
private const cast_utf8 = [ private const cast_utf8 = [
@ -50,6 +51,7 @@ final class Netmail extends Model implements Packet
switch ($key) { switch ($key) {
case 'set_path': case 'set_path':
case 'set_pkt': case 'set_pkt':
case 'set_recvtime':
case 'set_sender': case 'set_sender':
$this->{$key} = $value; $this->{$key} = $value;
break; break;
@ -86,9 +88,10 @@ final class Netmail extends Model implements Packet
} }
// Our last node in the path is our sender // Our last node in the path is our sender
if (isset($model->set_pkt) && isset($model->set_sender)) { if (isset($model->set_pkt) && isset($model->set_sender) && isset($model->set_recvtime)) {
DB::update('UPDATE netmail_path set recv_pkt=?,recv_id=? where address_id=? and netmail_id=?',[ DB::update('UPDATE netmail_path set recv_pkt=?,recv_at=?,recv_id=? where address_id=? and netmail_id=?',[
$model->set_pkt, $model->set_pkt,
$model->set_recvtime,
$model->set_sender->id, $model->set_sender->id,
Arr::get($model->set_path->last(),'node')->id, Arr::get($model->set_path->last(),'node')->id,
$model->id, $model->id,

View File

@ -59,7 +59,7 @@ class EchoareaNoWrite extends Netmails
) )
); );
$msg->addText("It appears that you do not have permission to post in this echoarea, so the message from your system was rejected.\r\r"); $msg->addText(sprintf("It appears that you do not have permission to post in this echoarea using the address [%s], so the message from your system was rejected.\r\r",$ao->ftn));
$msg->addText("Please contact the ZC if you think this is a mistake.\r\r"); $msg->addText("Please contact the ZC if you think this is a mistake.\r\r");
$msg->addText($this->message_path($this->mo)); $msg->addText($this->message_path($this->mo));

View File

@ -59,7 +59,7 @@ class EchoareaNotSubscribed extends Netmails
) )
); );
$msg->addText("It appears that you havent been previously subscribed to this echoarea.\r\r"); $msg->addText(sprintf("It appears that you havent been previously subscribed to this echoarea using the address [%s].\r\r",$ao->ftn));
$msg->addText("Even though your post was accepted, I'm not configured to export any posts to you when others respond, you might like to log in to the web interface and do that.\r\r"); $msg->addText("Even though your post was accepted, I'm not configured to export any posts to you when others respond, you might like to log in to the web interface and do that.\r\r");

View File

@ -0,0 +1,34 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::table('netmail_path',function (Blueprint $table) {
$table->datetime('recv_at')->nullable();
});
DB::statement('UPDATE netmail_path SET recv_at=created_at FROM netmails WHERE netmails.id=netmail_path.netmail_id');
Schema::table('echomail_path',function (Blueprint $table) {
$table->datetime('recv_at')->nullable();
});
DB::statement('UPDATE echomail_path SET recv_at=created_at FROM echomails WHERE echomails.id=echomail_path.echomail_id');
}
/**
* Reverse the migrations.
*/
public function down(): void
{
//
}
};

View File

@ -521,11 +521,11 @@
<div class="col-4"> <div class="col-4">
The last Netmails received (you sent): The last Netmails received (you sent):
@if(($x=\App\Models\Netmail::select(['recv_pkt','created_at',DB::raw('count(*) AS count')]) @if(($x=\App\Models\Netmail::select(['recv_pkt','recv_at',DB::raw('count(*) AS count')])
->join('netmail_path',['netmail_path.netmail_id'=>'netmails.id']) ->join('netmail_path',['netmail_path.netmail_id'=>'netmails.id'])
->whereIn('address_id',$o->addresses->pluck('id')) ->whereIn('address_id',$o->addresses->pluck('id'))
->groupBy(['recv_pkt','created_at']) ->groupBy(['recv_pkt','recv_at'])
->orderBy('created_at','DESC') ->orderBy('recv_at','DESC')
->limit(10) ->limit(10)
->get())->count()) ->get())->count())
<table class="table monotable"> <table class="table monotable">
@ -541,7 +541,7 @@
@foreach ($x as $oo) @foreach ($x as $oo)
<tr> <tr>
<td class="packet">{{ $oo->recv_pkt }}</td> <td class="packet">{{ $oo->recv_pkt }}</td>
<td>{{ $oo->created_at }}</td> <td>{{ $oo->recv_at }}</td>
<td class="text-end">{{ $oo->count }}</td> <td class="text-end">{{ $oo->count }}</td>
</tr> </tr>
@endforeach @endforeach
@ -555,12 +555,12 @@
<div class="col-4"> <div class="col-4">
The last Echomails received (you sent): The last Echomails received (you sent):
@if(($x=\App\Models\Echomail::select(['recv_pkt','created_at',DB::raw('count(*) AS count')]) @if(($x=\App\Models\Echomail::select(['recv_pkt','recv_at',DB::raw('count(*) AS count')])
->join('echomail_path',['echomail_path.echomail_id'=>'echomails.id']) ->join('echomail_path',['echomail_path.echomail_id'=>'echomails.id'])
->whereNotNull('recv_pkt') ->whereNotNull('recv_pkt')
->whereIn('address_id',$o->addresses->pluck('id')) ->whereIn('address_id',$o->addresses->pluck('id'))
->groupBy(['recv_pkt','created_at']) ->groupBy(['recv_pkt','recv_at'])
->orderBy('created_at','DESC') ->orderBy('recv_at','DESC')
->limit(10) ->limit(10)
->get())->count()) ->get())->count())
<table class="table monotable"> <table class="table monotable">
@ -576,7 +576,7 @@
@foreach ($x as $oo) @foreach ($x as $oo)
<tr> <tr>
<td class="packet">{{ $oo->recv_pkt }}</td> <td class="packet">{{ $oo->recv_pkt }}</td>
<td>{{ $oo->created_at }}</td> <td>{{ $oo->recv_at }}</td>
<td class="text-end">{{ $oo->count }}</td> <td class="text-end">{{ $oo->count }}</td>
</tr> </tr>
@endforeach @endforeach