diff --git a/app/Classes/FTN/Message.php b/app/Classes/FTN/Message.php index da9e09f..8eda39f 100644 --- a/app/Classes/FTN/Message.php +++ b/app/Classes/FTN/Message.php @@ -357,6 +357,9 @@ class Message extends FTNBase case 'errors': return $this->{$key}; + case 'dbid': + return $this->kludge->get($key); + default: throw new \Exception('Unknown key: '.$key); } diff --git a/app/Classes/File/Item.php b/app/Classes/File/Item.php index 0e631bd..ccbc3a9 100644 --- a/app/Classes/File/Item.php +++ b/app/Classes/File/Item.php @@ -36,9 +36,9 @@ class Item protected const I_RECV = (1<<0); protected const I_SEND = (1<<1); - protected string $file_name = ''; - protected int $file_size = 0; - protected int $file_mtime = 0; + protected string $file_name; + protected int $file_size; + protected int $file_mtime; /** Current read/write pointer */ protected int $file_pos = 0; /** File descriptor */ @@ -113,8 +113,27 @@ class Item { switch($key) { case 'mtime': + if ($this instanceof Mail) + $this->youngest()->timestamp; + + if ($this->action & self::I_RECV|self::I_SEND) + return $this->{'file_'.$key}; + + throw new \Exception('Invalid request for key: '.$key); + case 'name': + if ($this instanceof Mail) + return sprintf('%08x',timew($this->youngest())); + + if ($this->action & self::I_RECV|self::I_SEND) + return $this->{'file_'.$key}; + + throw new \Exception('Invalid request for key: '.$key); + case 'size': + if ($this instanceof Mail) + return strlen($this->file); + if ($this->action & self::I_RECV|self::I_SEND) return $this->{'file_'.$key}; @@ -124,6 +143,9 @@ class Item return $this->file_name; case 'sendas': + if ($this instanceof Mail) + return sprintf('%s.pkt',$this->name); + return $this->file_name ? basename($this->file_name) : $this->filemodel->name; default: diff --git a/app/Classes/File/Mail.php b/app/Classes/File/Mail.php index 7826446..dd3aec5 100644 --- a/app/Classes/File/Mail.php +++ b/app/Classes/File/Mail.php @@ -31,6 +31,7 @@ class Mail extends Item public function __get($key) { switch ($key) { case 'file': return $this->file; + case 'messages': return $this->file->messages; default: return parent::__get($key); } diff --git a/app/Classes/File/Send.php b/app/Classes/File/Send.php index 0662928..e290793 100644 --- a/app/Classes/File/Send.php +++ b/app/Classes/File/Send.php @@ -41,6 +41,9 @@ final class Send extends Item public function __get($key) { switch ($key) { + case 'dbids': + return $this->sending->messages->pluck('echoarea','dbid'); + case 'fd': return is_resource($this->f) ?: $this->f; @@ -242,13 +245,15 @@ final class Send extends Item */ public function open(string $compress=''): bool { - Log::debug(sprintf('%s:+ open',self::LOGKEY)); + Log::debug(sprintf('%s:+ Opening file to send',self::LOGKEY)); // If we have mail, we'll send that first if ($this->sending = $this->packets ->filter(function($item) { return ($item->action & self::I_SEND) && $item->sent === FALSE; }) ->first()) { + Log::debug(sprintf('%s:- Sending [%s]',self::LOGKEY,$this->sending->name)); + $this->file_pos = 0; $this->start = time(); $this->f = TRUE; diff --git a/app/Classes/Protocol/Binkp.php b/app/Classes/Protocol/Binkp.php index fa48227..dd828f5 100644 --- a/app/Classes/Protocol/Binkp.php +++ b/app/Classes/Protocol/Binkp.php @@ -5,11 +5,13 @@ namespace App\Classes\Protocol; use Carbon\Carbon; use Illuminate\Support\Arr; use Illuminate\Support\Collection; +use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Log; use League\Flysystem\UnreadableFileEncountered; use App\Classes\Crypt; use App\Classes\Protocol as BaseProtocol; +use App\Classes\FTN\Message; use App\Classes\Sock\SocketClient; use App\Classes\Sock\SocketException; use App\Exceptions\FileGrewException; @@ -991,8 +993,30 @@ final class Binkp extends BaseProtocol Log::error(sprintf('%s:! M_got[skip] for unknown file [%s]',self::LOGKEY,$buf)); } else { - Log::info(sprintf('%s:= Packet/File [%s] sent.',self::LOGKEY,$this->send->name)); + Log::info(sprintf('%s:= Packet/File [%s] sent with [%s].',self::LOGKEY,$this->send->name,$this->send->dbids->join(','))); $this->sessionClear(self::SE_WAITGOT|self::SE_SENDFILE); + + // Update netmail table + if ($x=$this->send->dbids->filter(function($item) { return (! $item); })->keys()->filter()) + DB::table('netmails') + ->whereIn('id',$x) + ->update([ + 'sent_at'=>Carbon::now(), + 'sent_pkt'=>$this->send->name, + 'sent_id'=>$this->node->address->id, + 'flags'=>DB::raw('flags | '.Message::FLAG_SENT), + ]); + + // Update echomails table + if ($x=$this->send->dbids->filter(function($item) { return $item; })->keys()->filter()) + DB::table('echomail_seenby') + ->whereIn('echomail_id',$x) + ->where('address_id',$this->node->address->id) + ->update([ + 'sent_at'=>Carbon::now(), + 'sent_pkt'=>$this->send->name, + ]); + $this->send->close(TRUE); } } diff --git a/app/Jobs/MessageProcess.php b/app/Jobs/MessageProcess.php index d1eb99e..d842c04 100644 --- a/app/Jobs/MessageProcess.php +++ b/app/Jobs/MessageProcess.php @@ -103,6 +103,13 @@ class MessageProcess implements ShouldQueue $o->flags |= Message::FLAG_RECD; $o->save(); + Log::info(sprintf('%s:! Netmail [%s] from (%s:%s) - was processed by us [%d]', + self::LOGKEY, + $this->msg->msgid, + $this->msg->user_from, + $this->msg->fftn, + $o->id, + )); break; } } @@ -112,7 +119,7 @@ class MessageProcess implements ShouldQueue $o->flags |= Message::FLAG_RECD; $o->save(); - Log::alert(sprintf('%s:! Ignoring Netmail [%s] to the Hub from (%s:%s) - its from a bot [%d].', + Log::alert(sprintf('%s:! Ignoring Netmail [%s] to the Hub from (%s:%s) - its from a bot [%d]', self::LOGKEY, $this->msg->msgid, $this->msg->user_from, @@ -289,6 +296,7 @@ class MessageProcess implements ShouldQueue $o->set_path = $this->msg->pathaddress; $o->set_seenby = $this->msg->seenaddress; // Record receiving packet and sender + $o->set_pkt = $this->packet; $o->save(); diff --git a/app/Models/Address.php b/app/Models/Address.php index 0a105e6..ac26f11 100644 --- a/app/Models/Address.php +++ b/app/Models/Address.php @@ -6,7 +6,6 @@ use Carbon\Carbon; use Illuminate\Database\Eloquent\Collection; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\SoftDeletes; -use Illuminate\Support\Facades\Crypt; use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Log; @@ -598,9 +597,9 @@ class Address extends Model ->whereIn('echomail_id',$x->pluck('id')) ->where('address_id',$this->id) ->whereNull('sent_at') - ->whereNull('packet') + ->whereNull('sent_pkt') ->whereNotNull('echomail_seenby.export_at') - ->update(['sent_at'=>Carbon::now(),'packet'=>$pkt->name]); + ->update(['sent_pkt'=>$pkt->name]); } return $pkt; @@ -638,21 +637,28 @@ class Address extends Model * @param bool $update * @return Packet|null */ - public function getNetmail(bool $update=TRUE): ?Packet + public function getNetmail(bool $update=FALSE): ?Packet { $pkt = NULL; + $s = Setup::findOrFail(config('app.id')); + if (($x=$this->netmailWaiting()) ->count()) { Log::debug(sprintf('%s:= Got [%d] netmails for [%s] for sending',self::LOGKEY,$x->count(),$this->ftn)); + if ($x->count() > $s->msgs_pkt) { + $x = $x->take($s->msgs_pkt); + Log::alert(sprintf('%s:= Only sending [%d] netmails for [%s]',self::LOGKEY,$x->count(),$this->ftn)); + } + $pkt = $this->getPacket($x); if ($pkt && $pkt->count() && $update) DB::table('netmails') ->whereIn('id',$x->pluck('id')) - ->update(['sent_at'=>Carbon::now(),'sent_pkt'=>$pkt->name]); + ->update(['sent_pkt'=>$pkt->name]); } return $pkt; diff --git a/app/Models/Echomail.php b/app/Models/Echomail.php index 77b9330..6200b0c 100644 --- a/app/Models/Echomail.php +++ b/app/Models/Echomail.php @@ -22,7 +22,7 @@ final class Echomail extends Model implements Packet private const LOGKEY = 'ME-'; private Collection $set_seenby; private Collection $set_path; - private ?string $set_packet = NULL; + private string $set_pkt; private bool $no_export = FALSE; protected $casts = [ @@ -50,7 +50,7 @@ final class Echomail extends Model implements Packet switch ($key) { case 'no_export': case 'set_path': - case 'set_packet': + case 'set_pkt': case 'set_seenby': $this->{$key} = $value; break; @@ -71,17 +71,8 @@ final class Echomail extends Model implements Packet return; } - // Our address - $ftns = Setup::findOrFail(config('app.id')) - ->system - ->match($model->fftn->zone); - - // Add our address to the seenby; - $model->set_seenby = $model->set_seenby->merge($ftns->pluck('id'))->unique(); - $model->set_path = $model->set_path->merge($ftns->pluck('id')); - // Save the seenby - $model->seenby()->syncWithPivotValues($model->set_seenby,['packet'=>$model->set_packet]); + $model->seenby()->sync($model->set_seenby); // Save the Path $ppoid = NULL; @@ -95,6 +86,15 @@ final class Echomail extends Model implements Packet $ppoid = $po[0]->id; } + // Our last node in the path is our sender + if (isset($model->set_pkt)) { + DB::update('UPDATE echomail_path set recv_pkt=? where address_id=? and echomail_id=?',[ + $model->set_pkt, + $model->set_path->last(), + $model->id, + ]); + } + // See if we need to export this message. $exportto = $model->echoarea->addresses->pluck('id')->diff($model->set_seenby); @@ -143,7 +143,6 @@ final class Echomail extends Model implements Packet { $this->set_path = collect(); $this->set_seenby = collect(); - $this->set_packet = NULL; } public function jsonSerialize(): array @@ -156,7 +155,7 @@ final class Echomail extends Model implements Packet */ public function packet(Address $ao): Message { - Log::debug(sprintf('%s:Bundling [%s]',self::LOGKEY,$this->id)); + Log::debug(sprintf('%s:+ Bundling [%s]',self::LOGKEY,$this->id)); // @todo Dont bundle mail to nodes that have been disabled, or addresses that have been deleted $o = new Message; @@ -166,7 +165,7 @@ final class Echomail extends Model implements Packet 'dnode' => $ao->node_id, 'onet' => $this->fftn->host_id, 'dnet' => $ao->host_id, - 'flags' => 0, // @todo? + 'flags' => 0, 'cost' => 0, 'date'=>$this->datetime->format('d M y H:i:s'), ]; @@ -198,8 +197,11 @@ final class Echomail extends Model implements Packet if ($this->origin) $o->origin = $this->origin; - $o->seenby = $this->seenby->pluck('ftn2d'); - $o->path = $this->pathorder(); + $sysaddress = Setup::findOrFail(config('app.id'))->system->match($this->fftn->zone)->first(); + $o->seenby = $this->seenby->push($sysaddress)->unique()->pluck('ftn2d'); + + // Add our address to the path and seenby + $o->path = $this->pathorder()->merge($sysaddress->ftn2d); $o->packed = TRUE; diff --git a/app/Models/File.php b/app/Models/File.php index a4ee08a..b6dea5c 100644 --- a/app/Models/File.php +++ b/app/Models/File.php @@ -42,7 +42,6 @@ class File extends Model case 'replaces': case 'no_export': case 'set_path': - case 'set_packet': case 'set_seenby': $this->{$key} = $value; break; diff --git a/app/Models/Netmail.php b/app/Models/Netmail.php index c013bb4..081b12b 100644 --- a/app/Models/Netmail.php +++ b/app/Models/Netmail.php @@ -85,11 +85,13 @@ final class Netmail extends Model implements Packet $ppoid = $po[0]->id; } + // Our last node in the path is our sender if (isset($model->set_pkt) && isset($model->set_sender)) { - DB::update('UPDATE netmail_path set recv_pkt=?,recv_id=? where address_id=?',[ + DB::update('UPDATE netmail_path set recv_pkt=?,recv_id=? where address_id=? and netmail_id=?',[ $model->set_pkt, $model->set_sender->id, Arr::get($model->set_path->last(),'node')->id, + $model->id, ]); } } @@ -130,7 +132,7 @@ final class Netmail extends Model implements Packet */ public function packet(Address $ao): Message { - Log::debug(sprintf('%s:Bundling [%s]',self::LOGKEY,$this->id)); + Log::debug(sprintf('%s:+ Bundling [%s]',self::LOGKEY,$this->id)); // @todo Dont bundle mail to nodes that have been disabled, or addresses that have been deleted $o = new Message; @@ -169,6 +171,7 @@ final class Netmail extends Model implements Packet // VIA kludge $sysaddress = Setup::findOrFail(config('app.id'))->system->match($this->fftn->zone)->first(); $via = $this->via ?: collect(); + // Add our address to the VIA line $via->push( sprintf('%s @%s.UTC %s %d.%d/%s %s', $sysaddress->ftn3d, @@ -185,7 +188,7 @@ final class Netmail extends Model implements Packet $o->packed = TRUE; } catch (\Exception $e) { - Log::error(sprintf('%s:Error converting netmail [%s] to a message (%d:%s)',self::LOGKEY,$this->id,$e->getLine(),$e->getMessage())); + Log::error(sprintf('%s:! Error converting netmail [%s] to a message (%d:%s)',self::LOGKEY,$this->id,$e->getLine(),$e->getMessage())); dump($this); } diff --git a/app/Models/System.php b/app/Models/System.php index af3c9d4..4c0439f 100644 --- a/app/Models/System.php +++ b/app/Models/System.php @@ -192,7 +192,7 @@ class System extends Model */ public function match(Zone $o,int $type=(Address::NODE_NC|Address::NODE_HC|Address::NODE_ACTIVE|Address::NODE_PVT|Address::NODE_POINT)): Collection { - return $this->addresses + return $this->akas ->where('zone_id',$o->id) ->filter(function($item) use ($type) { return $item->role & $type; diff --git a/database/migrations/2023_07_11_222130_packet_logging.php b/database/migrations/2023_07_11_222130_packet_logging.php index e3b78a6..4703576 100644 --- a/database/migrations/2023_07_11_222130_packet_logging.php +++ b/database/migrations/2023_07_11_222130_packet_logging.php @@ -11,53 +11,25 @@ return new class extends Migration */ public function up(): void { - /* - Schema::create('system_transfers',function (Blueprint $table) { - $table->id(); - $table->timestamps(); - - $table->string('packet')->nullable(); - $table->bigInteger('file_id')->nullable(); - $table->foreign('file_id')->references('id')->on('files'); - - $table->bigInteger('address_id'); - $table->foreign('address_id')->references('id')->on('addresses'); - - $table->unique(['address_id','packet']); - $table->unique(['address_id','file_id']); - }); - */ - Schema::table('netmails',function (Blueprint $table) { - $table->bigInteger('send_id')->nullable()->after('send_pkt'); - $table->foreign('send_id')->references('id')->on('addresses'); + $table->bigInteger('sent_id')->nullable()->after('sent_pkt'); + $table->foreign('sent_id')->references('id')->on('addresses'); }); Schema::table('netmail_path',function (Blueprint $table) { $table->string('recv_pkt')->nullable(); - - $table->bigInteger('recv_id')->nullable(); + $table->bigInteger('recv_id')->nullable()->after('recv_pkt'); $table->foreign('recv_id')->references('id')->on('addresses'); - - $table->unique(['recv_id','netmail_id']); }); DB::statement('ALTER TABLE echomail_seenby RENAME COLUMN packet TO sent_pkt'); Schema::table('echomail_seenby',function (Blueprint $table) { - $table->bigInteger('sent_id')->nullable(); - $table->foreign('sent_id')->references('id')->on('addresses'); - - $table->unique(['sent_id','echomail_id']); + $table->dropColumn('mid'); }); Schema::table('echomail_path',function (Blueprint $table) { $table->string('recv_pkt')->nullable(); - - $table->bigInteger('recv_id')->nullable(); - $table->foreign('recv_id')->references('id')->on('addresses'); - - $table->unique(['recv_id','echomail_id']); }); } @@ -66,6 +38,6 @@ return new class extends Migration */ public function down(): void { - //Schema::dropIfExists('system_transfers'); + abort(500,'Cant go back'); } }; diff --git a/resources/views/system/addedit.blade.php b/resources/views/system/addedit.blade.php index 9468a54..5777cba 100644 --- a/resources/views/system/addedit.blade.php +++ b/resources/views/system/addedit.blade.php @@ -415,57 +415,141 @@
- The last Netmails sent: - - - - - - - - + The last Netmails sent (to you): - - @dump($o->addresses->sortBy('zone.zone_id')->pluck('ftn')) - @foreach (\App\Models\Netmail::where('tftn_id',$o->addresses->pluck('id'))->whereNotNull('sent_at')->orderBy('sent_at')->limit(10) as $no) + @if(($x=\App\Models\Netmail::whereIn('sent_id',$o->addresses->pluck('id')) + ->whereNotNull('sent_at') + ->orderBy('sent_at','DESC') + ->limit(10) + ->get())->count()) + +
FTNPacketSent
+ - - - + + + - @endforeach - -
{{ $no->tftn->ftn }}PacketCountSent
+ + + + @foreach ($x->groupBy('sent_pkt') as $oo) + + {{ $oo->first()->sent_pkt }} + {{ $oo->count() }} + {{ $oo->first()->sent_at }} + + @endforeach + + + @else + None + @endif
- The last Echomails sent: - - - - - - - - + The last Echomails sent (to you): - - @foreach (\App\Models\Echomail::join('echomail_seenby',['echomail_seenby.echomail_id'=>'echomails.id']) - ->whereNotNull('echomail_seenby.sent_at') - ->whereIn('address_id',$o->addresses->pluck('id')) - ->orderBy('sent_at','DESC') - ->orderBy('packet') - ->limit(10) - ->get() - ->groupBy('packet') as $oo) + @if(($x=\App\Models\Echomail::select(['echomails.id','echomail_seenby.sent_pkt','echomail_seenby.sent_at']) + ->join('echomail_seenby',['echomail_seenby.echomail_id'=>'echomails.id']) + ->whereNotNull('echomail_seenby.sent_at') + ->whereIn('address_id',$o->addresses->pluck('id')) + ->orderBy('sent_at','DESC') + ->orderBy('sent_pkt') + ->limit(10) + ->get())->count()) +
FTNPacketSent
+ - - - + + + - @endforeach - -
{{ \App\Models\Address::where('id',$oo->first()->address_id)->single()->ftn }}{{ $oo->first()->packet }}{{ $oo->first()->sent_at }}PacketCountSent
+ + + + @foreach ($x->groupBy('sent_pkt') as $oo) + + {{ $oo->first()->sent_pkt }} + {{ $oo->count() }} + {{ $oo->first()->sent_at }} + + @endforeach + + + @else + None + @endif +
+
+ +
+
+ The last Netmails received (you sent): + + @if(($x=\App\Models\Netmail::select(['netmails.*','netmail_path.recv_pkt']) + ->join('netmail_path',['netmail_path.netmail_id'=>'netmails.id']) + ->whereIn('address_id',$o->addresses->pluck('id')) + ->orderBy('created_at','DESC') + ->limit(10) + ->get())->count()) + + + + + + + + + + + @foreach ($x->groupBy('recv_pkt') as $oo) + + + + + + @endforeach + +
PacketCountReceived
{{ $oo->first()->recv_pkt }}{{ $oo->count() }}{{ $oo->first()->created_at }}
+ @else + None + @endif +
+ +
+ The last Echomails received (you sent): + + @if(($x=\App\Models\Echomail::select(['echomails.created_at','echomail_path.recv_pkt']) + ->join('echomail_path',['echomail_path.echomail_id'=>'echomails.id']) + ->whereNotNull('echomail_path.recv_pkt') + ->whereIn('address_id',$o->addresses->pluck('id')) + ->orderBy('created_at','DESC') + ->orderBy('recv_pkt') + ->limit(10) + ->get())->count()) + + + + + + + + + + + @foreach ($x->groupBy('recv_pkt') as $oo) + + + + + + @endforeach + +
PacketCountReceived
{{ $oo->first()->recv_pkt }}{{ $oo->count() }}{{ $oo->first()->created_at }}
+ @else + None + @endif
diff --git a/resources/views/widgets/message.blade.php b/resources/views/widgets/message.blade.php index 13ecde2..96c81e1 100644 --- a/resources/views/widgets/message.blade.php +++ b/resources/views/widgets/message.blade.php @@ -1,6 +1,10 @@ +@php +use App\Classes\FTN\Message; +@endphp +
- TO: {!! \App\Classes\FTN\Message::tr($msg->to) !!} @if ($msg instanceof \App\Models\Netmail)({{ $msg->tftn->ftn }})@endif + TO: {!! Message::tr($msg->to) !!} @if ($msg instanceof \App\Models\Netmail)({{ $msg->tftn->ftn }})@endif
DATE: {{ $msg->datetime->format('Y-m-d H:i:s') }} @@ -9,7 +13,7 @@
- FROM: {!! \App\Classes\FTN\Message::tr($msg->from) !!} ({{ $msg->fftn->ftn }}) + FROM: {!! Message::tr($msg->from) !!} ({{ $msg->fftn->ftn }})
MSGID: {{ $msg->msgid }}@if($x=\App\Models\Echomail::where('replyid',$msg->msgid)->count()) ({{$x}} replies)@endif @if($msg->replyid)
REPLY: {{ $msg->replyid }}@endif @@ -18,7 +22,7 @@
- SUBJECT: {!! \App\Classes\FTN\Message::tr($msg->subject) !!} + SUBJECT: {!! Message::tr($msg->subject) !!}
@if ($msg instanceof \App\Models\Echomail)
@@ -30,7 +34,7 @@
-
{!! \App\Classes\FTN\Message::tr($msg->msg).($msg->origin ? sprintf("\r * Origin: %s",$msg->origin) : '') !!}
+
{!! Message::tr($msg->msg).($msg->origin ? sprintf("\r * Origin: %s",$msg->origin) : '') !!}
@@ -43,26 +47,29 @@
@endif -@if ($msg->flags & \App\Classes\FTN\Message::FLAG_LOCAL) +@if ($msg->flags & Message::FLAG_LOCAL)
Local message
-@elseif ($msg->flags & (\App\Classes\FTN\Message::FLAG_INTRANSIT|\App\Classes\FTN\Message::FLAG_RECD)) +@elseif ((! $msg->flags) || ($msg->flags & (Message::FLAG_INTRANSIT|Message::FLAG_RECD))) +
PATH:
{!! optimize_path($msg->pathorder())->join(' -> ') !!}
-
-
- RECEIVED: - @foreach ($msg->received as $path) - {{ $path->pivot->recv_pkt }} by {{ $path->ftn }} {{ $msg->created_at }} - @endforeach + @if ($msg->flags) +
+
+ RECEIVED: + @foreach ($msg->received as $path) + {{ $path->pivot->recv_pkt }} by {{ $path->ftn }} {{ $msg->created_at }} + @endforeach +
-
+ @endif @endif \ No newline at end of file