Added New Nodes Report
All checks were successful
Create Docker Image / Build Docker Image (x86_64) (push) Successful in 29s
Create Docker Image / Build Docker Image (arm64) (push) Successful in 1m32s
Create Docker Image / Final Docker Image Manifest (push) Successful in 8s

This commit is contained in:
Deon George 2024-11-04 12:44:46 +11:00
parent 231977932c
commit db6c569345
3 changed files with 219 additions and 0 deletions

View File

@ -0,0 +1,50 @@
<?php
namespace App\Console\Commands;
use App\Models\Address;
use Carbon\Carbon;
use Illuminate\Console\Command;
use App\Jobs\NodesNew as Job;
use App\Models\Domain;
class NodesNew extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'nodes:new'
.' {domain : Domain}'
.' {--date= : From a specific date (default 1 since last Saturday)}'
.' {--netmail= : Send a Netmail to FTN}';
/**
* The console command description.
*
* @var string
*/
protected $description = 'List new nodes since last Saturday (or a specific date)';
/**
* Execute the console command.
*/
public function handle(): int
{
$do = Domain::where('name',$this->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);
}
}

65
app/Jobs/NodesNew.php Normal file
View File

@ -0,0 +1,65 @@
<?php
namespace App\Jobs;
use Carbon\Carbon;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Notification;
use App\Models\{Address, Domain, System};
use App\Notifications\Netmails\NodesNew as NotificationNodesNew;
class NodesNew implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
private const LOGKEY = 'JNN';
private ?Carbon $since; // New nodes since this date
private Address $ao; // Domain we are processing
private Domain $do; // Domain we are processing
/**
* Create a new job instance.
*/
public function __construct(Domain $do,Carbon $since=NULL,Address $ao=NULL)
{
$this->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));
}
}

View File

@ -0,0 +1,104 @@
<?php
namespace App\Notifications\Netmails;
use Carbon\Carbon;
use Illuminate\Bus\Queueable;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Support\Facades\Log;
use App\Classes\FTN\Message;
use App\Notifications\Netmails;
use App\Models\{Address,Netmail};
use App\Traits\PageTemplate;
class NodesNew extends Netmails //implements ShouldQueue
{
use Queueable,PageTemplate;
private const LOGKEY = 'NNN';
private Carbon $since;
private Collection $list;
/**
* Create a new notification instance.
*/
public function __construct(Carbon $since,Collection $list)
{
parent::__construct();
$this->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;
}
}