Added filefix %LIST
This commit is contained in:
parent
b67ae28b98
commit
a161b8fc5e
@ -50,7 +50,7 @@ final class Filefix extends Robot
|
||||
|
||||
break;
|
||||
|
||||
// If command doesnt start with %, its an area
|
||||
// If command doesnt start with %, its an area
|
||||
} elseif (! str_starts_with($command[0],'%')) {
|
||||
Log::info(sprintf('%s:= Assuming command [%s] is an AREA command',self::LOGKEY,$command[0]));
|
||||
|
||||
@ -60,7 +60,7 @@ final class Filefix extends Robot
|
||||
// Some commands are reserved words
|
||||
switch ($x=strtolower(substr($command[0],1))) {
|
||||
case 'list':
|
||||
$class = self::commands.'FileList';
|
||||
$class = self::commands.'AreaList';
|
||||
break;
|
||||
|
||||
default:
|
||||
|
39
app/Classes/FTN/Process/Netmail/Robot/Filefix/AreaList.php
Normal file
39
app/Classes/FTN/Process/Netmail/Robot/Filefix/AreaList.php
Normal file
@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\FTN\Process\Netmail\Robot\Filefix;
|
||||
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Support\Facades\Notification;
|
||||
|
||||
use App\Classes\FTN\Process\Netmail\Robot\Areafix\Base;
|
||||
use App\Notifications\Netmails\Filefix\AreaList as AreaListNotification;
|
||||
|
||||
// LIST - List echoareas in a domain
|
||||
class AreaList extends Base
|
||||
{
|
||||
private const LOGKEY = 'AFS';
|
||||
private const command = '%LIST';
|
||||
|
||||
public static function help(): array
|
||||
{
|
||||
return [
|
||||
self::command,
|
||||
' List the available fileareas in this network',
|
||||
];
|
||||
}
|
||||
|
||||
public function process(): string
|
||||
{
|
||||
Log::debug(sprintf('%s:- Filefix [%s] for [%s] for [%s]',self::LOGKEY,self::command,$this->mo->fftn->ftn,join('|',$this->arguments)));
|
||||
|
||||
if (count($this->arguments) > 1)
|
||||
return sprintf('%-25s <-- INVALID COMMAND',self::command);
|
||||
|
||||
else {
|
||||
Notification::route('netmail',$this->mo->fftn)
|
||||
->notify(new AreaListNotification($this->mo));
|
||||
|
||||
return sprintf('%-25s <-- COMMAND PROCESSED',self::command);
|
||||
}
|
||||
}
|
||||
}
|
@ -12,12 +12,12 @@ class AreaList extends Netmails
|
||||
{
|
||||
use MessagePath,PageTemplate;
|
||||
|
||||
private const LOGKEY = 'ACH';
|
||||
private const LOGKEY = 'ACL';
|
||||
|
||||
private Netmail $mo;
|
||||
|
||||
/**
|
||||
* Reply to a areafix, commands unknown.
|
||||
* Reply to a areafix AREALIST commands.
|
||||
*
|
||||
* @param Netmail $mo
|
||||
*/
|
||||
|
103
app/Notifications/Netmails/Filefix/AreaList.php
Normal file
103
app/Notifications/Netmails/Filefix/AreaList.php
Normal file
@ -0,0 +1,103 @@
|
||||
<?php
|
||||
|
||||
namespace App\Notifications\Netmails\Filefix;
|
||||
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
use App\Notifications\Netmails;
|
||||
use App\Models\Netmail;
|
||||
use App\Traits\{MessagePath,PageTemplate};
|
||||
|
||||
class AreaList extends Netmails
|
||||
{
|
||||
use MessagePath,PageTemplate;
|
||||
|
||||
private const LOGKEY = 'FCL';
|
||||
|
||||
private Netmail $mo;
|
||||
|
||||
/**
|
||||
* Reply to a filefix AREALIST commands.
|
||||
*
|
||||
* @param Netmail $mo
|
||||
*/
|
||||
public function __construct(Netmail $mo)
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
$this->mo = $mo->withoutRelations();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the mail representation of the notification.
|
||||
*
|
||||
* @param mixed $notifiable
|
||||
* @return Netmail
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function toNetmail(object $notifiable): Netmail
|
||||
{
|
||||
$o = $this->setupNetmail($notifiable);
|
||||
$ao = $notifiable->routeNotificationFor(static::via);
|
||||
|
||||
Log::info(sprintf('%s:+ Responding to filefix for a node [%s] LIST processed',self::LOGKEY,$ao->ftn));
|
||||
|
||||
$o->to = $this->mo->from;
|
||||
$o->replyid = $this->mo->msgid;
|
||||
$o->subject = 'Filefix - List';
|
||||
|
||||
// Message
|
||||
$msg = $this->page(FALSE,'Filefix');
|
||||
|
||||
$msg->addText("Here are the list of available filereas:\r\r\r\r");
|
||||
|
||||
$areas = $ao->domain
|
||||
->fileareas
|
||||
->filter(fn($item)=>$item->active && ($item->can_read($ao->security) || $item->can_write($ao->security)));
|
||||
|
||||
if ($areas->count()) {
|
||||
$msg->addText(sprintf(":---:-%s-:-%s-:-%s-:\r",
|
||||
str_repeat('-',10),
|
||||
str_repeat('-',48),
|
||||
str_repeat('-',5),
|
||||
));
|
||||
$msg->addText(sprintf(": : %-10s : %-48s : %-5s :\r",'AREA','DESCRIPTION','FILES'));
|
||||
$msg->addText(sprintf(":---:-%s-:-%s-:-%s-:\r",
|
||||
str_repeat('-',10),
|
||||
str_repeat('-',48),
|
||||
str_repeat('-',5),
|
||||
));
|
||||
|
||||
foreach ($areas as $eao) {
|
||||
$msg->addText(sprintf(":%s%s%s: %-10s : %-48s : %5d :\r",
|
||||
($x=$ao->fileareas->contains($eao)) ? '*' : ' ',
|
||||
(! $x ? '+' : ' '),
|
||||
($eao->can_read($ao->security) && (! $eao->can_write($ao->security)))
|
||||
? 'R'
|
||||
: (((! $eao->can_read($ao->security)) && $eao->can_write($ao->security)) ? 'W' : ' '),
|
||||
$eao->name,
|
||||
$eao->description,
|
||||
$eao->files()->count(),
|
||||
));
|
||||
}
|
||||
|
||||
$msg->addText(sprintf(":---:-%s-:-%s-:-%s-:\r",
|
||||
str_repeat('-',10),
|
||||
str_repeat('-',48),
|
||||
str_repeat('-',5),
|
||||
));
|
||||
|
||||
$msg->addText("\r'*' = Subscribed, '+' = available, 'R' = read only, 'W' = write only\r");
|
||||
|
||||
} else {
|
||||
$msg->addText(sprintf('No areas available to you from domain [%s]',$ao->domain->name));
|
||||
}
|
||||
|
||||
$o->msg = $msg->render();
|
||||
$o->set_tagline = 'Why did the chicken cross the road? The robot programmed it.';
|
||||
|
||||
$o->save();
|
||||
|
||||
return $o;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user