From db6c569345365086529ed0ef7abcd77c4006e13d Mon Sep 17 00:00:00 2001 From: Deon George Date: Mon, 4 Nov 2024 12:44:46 +1100 Subject: [PATCH] Added New Nodes Report --- app/Console/Commands/NodesNew.php | 50 ++++++++++++ app/Jobs/NodesNew.php | 65 +++++++++++++++ app/Notifications/Netmails/NodesNew.php | 104 ++++++++++++++++++++++++ 3 files changed, 219 insertions(+) create mode 100644 app/Console/Commands/NodesNew.php create mode 100644 app/Jobs/NodesNew.php create mode 100644 app/Notifications/Netmails/NodesNew.php diff --git a/app/Console/Commands/NodesNew.php b/app/Console/Commands/NodesNew.php new file mode 100644 index 0000000..8e84db1 --- /dev/null +++ b/app/Console/Commands/NodesNew.php @@ -0,0 +1,50 @@ +argument('domain'))->singleOrFail(); + $ao = NULL; + + if ($this->option('netmail')) { + $ao = Address::findFTN($this->option('netmail')); + + if (! $ao) { + $this->error('Address not found: '.$this->option('netmail')); + return self::FAILURE; + } + } + + return Job::dispatchSync($do,$this->option('date') ? Carbon::parse($this->option('date')) : Carbon::parse('last saturday'),$ao); + } +} \ No newline at end of file diff --git a/app/Jobs/NodesNew.php b/app/Jobs/NodesNew.php new file mode 100644 index 0000000..122714f --- /dev/null +++ b/app/Jobs/NodesNew.php @@ -0,0 +1,65 @@ +do = $do->withoutRelations(); + $this->ao = $ao?->withoutRelations(); + $this->since = $since; + } + + /** + * Execute the job. + */ + public function handle(): void + { + $since = ($this->since ?: Carbon::parse('last saturday'))->startOfDay(); + + $result = Address::FTN() + ->ActiveFTN() + ->join('systems',['systems.id'=>'addresses.system_id']) + ->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) + ->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, + )); + + } else + Log::notice(sprintf('%s:- No nodes since [%s]',self::LOGKEY,$since)); + } +} \ No newline at end of file diff --git a/app/Notifications/Netmails/NodesNew.php b/app/Notifications/Netmails/NodesNew.php new file mode 100644 index 0000000..26c68b7 --- /dev/null +++ b/app/Notifications/Netmails/NodesNew.php @@ -0,0 +1,104 @@ +list = $list; + $this->since = $since; + } + + /** + * Get the mail representation of the notification. + */ + public function toNetmail(object $notifiable): Netmail + { + $o = $this->setupNetmail($notifiable); + $ao = $notifiable->routeNotificationFor(static::via); + + 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->flags = (Message::FLAG_LOCAL|Message::FLAG_PRIVATE|Message::FLAG_CRASH); + + // 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)); + + $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 from %s.\r",$oo->ftn4D,$oo->system->sysop,$oo->system->location)); + + 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)); + } + } + + $o->msg = $msg->render(); + $o->set_tagline = 'All aboard!'; + + $o->save(); + + return $o; + } +} \ No newline at end of file