From 46cf488337fc0ea49066918270c37c70b45c34dc Mon Sep 17 00:00:00 2001 From: Deon George Date: Sun, 8 Dec 2024 21:38:10 +1100 Subject: [PATCH] NodesNew also now sends an Echomail --- app/Jobs/AddressIdleDomain.php | 5 +- app/Jobs/NodesNew.php | 20 ++-- app/Notifications/Echomails/NodesNew.php | 114 +++++++++++++++++++++++ app/Notifications/Netmails/NodesNew.php | 27 +++--- 4 files changed, 145 insertions(+), 21 deletions(-) create mode 100644 app/Notifications/Echomails/NodesNew.php diff --git a/app/Jobs/AddressIdleDomain.php b/app/Jobs/AddressIdleDomain.php index 7ef9972..770b99f 100644 --- a/app/Jobs/AddressIdleDomain.php +++ b/app/Jobs/AddressIdleDomain.php @@ -2,6 +2,7 @@ namespace App\Jobs; +use Carbon\Carbon; use Illuminate\Bus\Queueable; use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Foundation\Bus\Dispatchable; @@ -19,7 +20,9 @@ class AddressIdleDomain implements ShouldQueue */ public function handle(): void { - foreach (Domain::whereNotNull('nodestatus_id')->cursor() as $do) + foreach (Domain::whereNotNull('nodestatus_id')->cursor() as $do) { AddressIdle::dispatch($do); + NodesNew::dispatch($do,Carbon::now()->subWeek()->startOfDay()); + } } } \ No newline at end of file diff --git a/app/Jobs/NodesNew.php b/app/Jobs/NodesNew.php index 488b00e..5c2f3bd 100644 --- a/app/Jobs/NodesNew.php +++ b/app/Jobs/NodesNew.php @@ -12,7 +12,8 @@ use Illuminate\Support\Facades\Log; use Illuminate\Support\Facades\Notification; use App\Models\{Address,Domain}; -use App\Notifications\Netmails\NodesNew as NotificationNodesNew; +use App\Notifications\Echomails\NodesNew as NodesNewEchomail; +use App\Notifications\Netmails\NodesNew as NodesNewNetmail; class NodesNew implements ShouldQueue { @@ -21,7 +22,7 @@ class NodesNew implements ShouldQueue private const LOGKEY = 'JNN'; private ?Carbon $since; // New nodes since this date - private Address $ao; // Domain we are processing + private ?Address $ao; // Domain we are processing private Domain $do; // Domain we are processing /** @@ -39,7 +40,7 @@ class NodesNew implements ShouldQueue */ public function handle(): void { - $since = ($this->since ?: Carbon::parse('last saturday'))->startOfDay(); + $since = ($this->since ?: Carbon::parse('last monday'))->startOfDay(); $result = Address::FTN() ->ActiveFTN() @@ -48,18 +49,19 @@ class NodesNew implements ShouldQueue ->join('system_zone',['system_zone.system_id'=>'systems.id','system_zone.zone_id'=>'zones.id']) ->whereIn('zones.id',$this->do->zones->pluck('id')) ->where('systems.active',TRUE) - ->where('systems.created_at','>=',$since) + ->where('addresses.created_at','>=',$since) ->orderBy('addresses.created_at') ->get(); if ($result->count()) { Log::notice(sprintf('%s:- Sending new nodes since [%s] (%d)',self::LOGKEY,$since,$result->count())); - Notification::route('netmail',$this->ao->withoutRelations()) - ->notify(new NotificationNodesNew( - $since, - $result, - )); + if ($this->ao) + Notification::route('netmail',$this->ao->withoutRelations()) + ->notify(new NodesNewNetmail($since,$result)); + else + Notification::route('echomail',$this->do->nodestatus_echoarea) + ->notify(new NodesNewEchomail($since,$result)); } else Log::notice(sprintf('%s:- No nodes since [%s]',self::LOGKEY,$since)); diff --git a/app/Notifications/Echomails/NodesNew.php b/app/Notifications/Echomails/NodesNew.php new file mode 100644 index 0000000..b49b94b --- /dev/null +++ b/app/Notifications/Echomails/NodesNew.php @@ -0,0 +1,114 @@ +list = $list; + $this->since = $since; + } + + public function toEchomail(object $notifiable): Echomail + { + $echoarea = $notifiable->routeNotificationFor(static::via); + $o = $this->setupEchomail($echoarea); + + Log::info(sprintf('%s:+ Sending a NEW NODE LIST to echoarea [%s]',self::LOGKEY,$echoarea->name)); + + $o->subject = sprintf('Here is a list of new nodes on clrghouz since %s',$this->since->format('Y-m-d')); + + $our = our_address($echoarea->domain)->last(); + $o->to = 'All'; + $o->subject = 'New nodes to '.$echoarea->domain->name; + $o->fftn_id = $our->id; + $o->kludges->put('CHRS:','CP437 2'); + + $o->msg = $this->report(); + $o->set_tagline = 'All aboard!'; + + $o->save(); + + return $o; + } + + /** + * Return the rendered new nodes report. + */ + public function report(): string + { + // Message + $msg = $this->page(FALSE,'new nodes'); + + $msg->addText("Hi Everyone,\r\r") + ->addText(sprintf("The following new system have been defined on clrghouz since %s.\r\r",$this->since->format('Y-m-d'))); + + $this->list->loadMissing(['system']); + + $space = str_repeat(' ',$this->list->pluck('ftn4d')->max(fn($item)=>strlen($item))+2); + + $c = 0; + foreach ($this->list as $oo) { + if ($c++) + $msg->addText("\r"); + + $msg->addText(sprintf("* %s - %s (%s) from %s.\r",$oo->ftn4D,$oo->system->sysop,$oo->system->name,$oo->system->location)); + $msg->addText(sprintf("%s Address registered: %s\r\r",$space,$oo->created_at->format('Y-m-d'))); + + if ($oo->system->method) { + switch ($oo->system->method) { + case 23: + $msg->addText(sprintf("%s - BBS is available TELNET [%s:%d]\r",$space,$oo->system->address,$oo->system->port)); + break; + + case 22: + $msg->addText(sprintf("%s - BBS is available SSH [%s:%d]\r",$space,$oo->system->address,$oo->system->port)); + break; + + case 519: + $msg->addText(sprintf("%s - BBS is available RLOGIN [%s:%d]\r",$space,$oo->system->address,$oo->system->port)); + break; + + default: + $msg->addText(sprintf("%s - No Details available for connecting to BBS\r",$space)); + } + } + + if ($oo->system->mailers->count()) { + $msg->addText("\r"); + $msg->addText(sprintf("%s - Mail can be sent using:\r",$space)); + + foreach ($oo->system->mailers as $mo) { + $msg->addText(sprintf("%s * %s [%s:%d]\r",$space,$mo->name,$oo->system->address,$mo->pivot->port)); + } + + } else { + $msg->addText(sprintf("%s - No mailer information provided, so will be PRIVATE\r",$space)); + } + } + + return $msg->render(); + } +} \ No newline at end of file diff --git a/app/Notifications/Netmails/NodesNew.php b/app/Notifications/Netmails/NodesNew.php index 69f2c1e..433fe49 100644 --- a/app/Notifications/Netmails/NodesNew.php +++ b/app/Notifications/Netmails/NodesNew.php @@ -32,9 +32,6 @@ class NodesNew extends Netmails //implements ShouldQueue $this->since = $since; } - /** - * Get the mail representation of the notification. - */ public function toNetmail(object $notifiable): Netmail { $o = $this->setupNetmail($notifiable); @@ -42,14 +39,27 @@ class NodesNew extends Netmails //implements ShouldQueue Log::info(sprintf('%s:+ Sending a NEW NODE LIST to [%s] at address [%s]',self::LOGKEY,$ao->system->sysop,$ao->ftn)); - $o->subject = sprintf('Here is a list of new nodes on clrghouz since %s',$x=$this->since->format('Y-m-d')); + $o->subject = sprintf('Here is a list of new nodes on clrghouz since %s',$this->since->format('Y-m-d')); $o->flags = (Message::FLAG_LOCAL|Message::FLAG_PRIVATE|Message::FLAG_CRASH); + $o->msg = $this->report($ao); + $o->set_tagline = 'All aboard!'; + + $o->save(); + + return $o; + } + + /** + * Return the rendered new nodes report. + */ + public function report(Address $ao): string + { // Message $msg = $this->page(FALSE,'new nodes'); $msg->addText(sprintf("Hi %s,\r\r",$ao->system->sysop)) - ->addText(sprintf("The following new system have been defined on clrghouz since %s.\r\r",$x)); + ->addText(sprintf("The following new system have been defined on clrghouz since %s.\r\r",$this->since->format('Y-m-d'))); $this->list->loadMissing(['system']); @@ -95,11 +105,6 @@ class NodesNew extends Netmails //implements ShouldQueue } } - $o->msg = $msg->render(); - $o->set_tagline = 'All aboard!'; - - $o->save(); - - return $o; + return $msg->render(); } } \ No newline at end of file