From 2ae24b995545b64ecd7d5356539aba86331fffe7 Mon Sep 17 00:00:00 2001 From: Deon George Date: Fri, 22 Sep 2023 14:45:44 +1000 Subject: [PATCH] Move fido configuation items into fido namespace. If keeping packets move them into a date aligned subdir --- app/Classes/FTN/Message.php | 2 ++ app/Classes/File/Item.php | 2 +- app/Classes/File/Receive.php | 2 +- app/Http/Requests/AreafixRequest.php | 2 +- app/Jobs/MessageProcess.php | 4 +-- app/Jobs/PacketProcess.php | 36 ++++++++++++++++--- app/Models/Address.php | 9 ++--- app/Models/File.php | 22 ++++++++++++ config/app.php | 10 ------ config/fido.php | 28 +++++++++++++++ config/filesystems.php | 2 +- resources/views/system/areafix.blade.php | 2 +- .../views/system/widget/form-system.blade.php | 2 +- 13 files changed, 97 insertions(+), 26 deletions(-) create mode 100644 config/fido.php diff --git a/app/Classes/FTN/Message.php b/app/Classes/FTN/Message.php index bdea307..19a9015 100644 --- a/app/Classes/FTN/Message.php +++ b/app/Classes/FTN/Message.php @@ -860,6 +860,8 @@ class Message extends FTNBase $this->point['dst'] = $t; // Via @YYYYMMDD.HHMMSS[.Precise][.Time Zone] [Serial Number] + // @todo The via line is still showing in the main message? https://clrghouz.bbs.dege.au/netmail/view/707 + // @todo Need to make sure that the CRC doesnt include this elseif ($t = $this->kludge('Via ',$kl)) $this->via->push($t); diff --git a/app/Classes/File/Item.php b/app/Classes/File/Item.php index cf8f5dc..64ae20b 100644 --- a/app/Classes/File/Item.php +++ b/app/Classes/File/Item.php @@ -39,7 +39,7 @@ final class Item extends Receive case 'stor_name': return sprintf('%04X-%s',$this->ao->id,$this->recvas); case 'rel_name': - return sprintf('%s/%s',config('app.fido'),$this->stor_name); + return sprintf('%s/%s',config('fido.dir'),$this->stor_name); case 'full_name': return Storage::disk(self::LOCATION)->path($this->rel_name); diff --git a/app/Classes/File/Receive.php b/app/Classes/File/Receive.php index 5f12a9b..d51f9b4 100644 --- a/app/Classes/File/Receive.php +++ b/app/Classes/File/Receive.php @@ -125,7 +125,7 @@ class Receive extends Base case self::IS_PKT: try { // If packet is greater than a size, lets queue it - if ($this->receiving->size > config('app.queue_size',0)) { + if ($this->receiving->size > config('fido.queue_size',0)) { Log::info(sprintf('%s:- Packet [%s] will be sent to the queue for processing because its [%d] size',self::LOGKEY,$this->receiving->full_name,$this->receiving->size)); PacketProcess::dispatch($this->receiving,$this->ao,$rcvd_time); diff --git a/app/Http/Requests/AreafixRequest.php b/app/Http/Requests/AreafixRequest.php index 92b0082..bea18fd 100644 --- a/app/Http/Requests/AreafixRequest.php +++ b/app/Http/Requests/AreafixRequest.php @@ -23,7 +23,7 @@ class AreafixRequest extends FormRequest return [ 'to' => [ 'required', - Rule::in(config('app.areafilefix')), + Rule::in(config('fido.areafilefix')), ], 'fftn_id' => [ 'required', diff --git a/app/Jobs/MessageProcess.php b/app/Jobs/MessageProcess.php index a22ea0e..773edc4 100644 --- a/app/Jobs/MessageProcess.php +++ b/app/Jobs/MessageProcess.php @@ -179,11 +179,11 @@ class MessageProcess implements ShouldQueue $processed = TRUE; // Dont send an advisement to an areabot - if (! in_array(strtolower($this->msg->user_from),config('app.areabots'))) + if (! in_array(strtolower($this->msg->user_from),config('fido.areabots'))) Notification::route('netmail',$this->msg->fftn_o)->notify(new NetmailForward($this->msg,$ao)); // We'll ignore messages from *fix users - } elseif (in_array(strtolower($this->msg->user_from),config('app.areabots'))) { + } elseif (in_array(strtolower($this->msg->user_from),config('fido.areabots'))) { $o->flags |= Message::FLAG_RECD; $o->save(); diff --git a/app/Jobs/PacketProcess.php b/app/Jobs/PacketProcess.php index 69c8151..f5f8286 100644 --- a/app/Jobs/PacketProcess.php +++ b/app/Jobs/PacketProcess.php @@ -11,6 +11,8 @@ use Illuminate\Queue\SerializesModels; use Illuminate\Support\Arr; use Illuminate\Support\Facades\Log; use Illuminate\Support\Facades\Notification; +use Illuminate\Support\Facades\Storage; +use League\Flysystem\UnableToMoveFile; use App\Classes\File; use App\Classes\File\Item; @@ -54,6 +56,8 @@ class PacketProcess implements ShouldQueue { Log::info(sprintf('%s:- Processing mail %s [%s]',self::LOGKEY,$this->file->whatType() === Item::IS_PKT ? 'PACKET' : 'ARCHIVE',$this->file->nameas)); + $fs = Storage::disk(config('fido.local_disk')); + try { $f = new File($this->file->full_name); $processed = FALSE; @@ -79,7 +83,7 @@ class PacketProcess implements ShouldQueue Log::info(sprintf('%s:- Packet has [%d] messages',self::LOGKEY,$pkt->count())); // Queue messages if there are too many in the packet. - if ($queue = ($pkt->count() > config('app.queue_msgs'))) + if ($queue = ($pkt->count() > config('fido.queue_msgs'))) Log::info(sprintf('%s:- Messages will be sent to the queue for processing',self::LOGKEY)); $count = 0; @@ -124,10 +128,34 @@ class PacketProcess implements ShouldQueue if (! $processed) { Log::alert(sprintf('%s:- Not deleting packet [%s], it doesnt seem to be processed?',self::LOGKEY,$this->file->nameas)); + } else { // If we want to keep the packet, we could do that logic here - } elseif (! config('app.packet_keep')) { - Log::debug(sprintf('%s:- Deleting processed packet [%s]',self::LOGKEY,$this->file->full_name)); - unlink($this->file->full_name); + if (config('fido.packet_keep')) { + $now = Carbon::now()->format('Ymd'); + $dir = sprintf('%s/%s',config('fido.dir'),$now); + Log::debug(sprintf('%s:- Moving processed packet [%s] to [%s]',self::LOGKEY,$this->file->rel_name,$dir)); + + try { + if ($fs->makeDirectory($dir)) { + $fs->move($this->file->rel_name,$x=sprintf('%s/%s',$dir,$this->file->stor_name)); + Log::info(sprintf('%s:- Moved processed packet [%s] to [%s]',self::LOGKEY,$this->file->rel_name,$x)); + + } else + Log::error(sprintf('%s:! Unable to create dir [%s]',self::LOGKEY,$dir)); + + } catch (UnableToMoveFile $e) { + Log::error(sprintf('%s:! Unable to move packet [%s] to [%s] (%s)',self::LOGKEY,$this->file->full_name,$dir,$e->getMessage())); + + } catch (\Exception $e) { + Log::error(sprintf('%s:! Failed moving packet [%s] to [%s] (%s)',self::LOGKEY,$this->file->full_name,$dir,$e->getMessage())); + } + + } else { + Log::debug(sprintf('%s:- Deleting processed packet [%s]',self::LOGKEY,$this->file->full_name)); + + // @todo Change this to use Storage::disk() + unlink($this->file->full_name); + } } } catch (InvalidPacketException $e) { diff --git a/app/Models/Address.php b/app/Models/Address.php index 981560b..d103833 100644 --- a/app/Models/Address.php +++ b/app/Models/Address.php @@ -92,6 +92,7 @@ class Address extends Model /** * Find children dependent on this record + * @todo If bosses are defined here, and points, then mail to a point goes to it's boss */ public function children() { @@ -232,6 +233,7 @@ class Address extends Model * * @return Address|null * @throws \Exception + * @todo Dont include points in this */ public function parent(): ?Address { @@ -386,7 +388,7 @@ class Address extends Model * * @param string $address * @param System $so - * @return self + * @return Address|null * @throws \Exception */ public static function createFTN(string $address,System $so): ?self @@ -478,8 +480,6 @@ class Address extends Model * Find a record in the DB for a node string, eg: 10:1/1.0 * * @param string $address - * @param bool $create - * @param System|null $so * @param bool $trashed * @return Address|null * @throws \Exception @@ -554,6 +554,7 @@ class Address extends Model * @param Domain $do * @param int $host * @param int $node + * @param int $point * @param bool $trashed * @return self|null * @throws \Exception @@ -770,7 +771,7 @@ class Address extends Model return NULL; // Get packet type - $type = collect(Packet::PACKET_TYPES)->get($this->system->pkt_type ?: config('app.default_pkt')); + $type = collect(Packet::PACKET_TYPES)->get($this->system->pkt_type ?: config('fido.packet_default')); $o = new $type; $o->addressHeader($ao,$this,$passwd); diff --git a/app/Models/File.php b/app/Models/File.php index 8d78b0f..5371f82 100644 --- a/app/Models/File.php +++ b/app/Models/File.php @@ -19,6 +19,8 @@ class File extends Model private const LOGKEY = 'MF-'; private bool $no_export = FALSE; + public string $prefix = ''; + public string $replaces = ''; protected $casts = [ 'kludges' => CollectionOrNull::class, @@ -162,11 +164,31 @@ class File extends Model /* ATTRIBUTES */ + /** + * Return the relative path to Storage::disk() in the store + * + * @return string + */ public function getFullStoragePathAttribute(): string { return sprintf('%04X/%s',$this->filearea_id,$this->name); } + /** + * Return the relative path to Storage::disk() in the inbound; + * + * @return string + */ + public function getRelNameAttribute(): string + { + return sprintf('%s/%s',config('fido.dir'),$this->prefix_name); + } + + public function getPrefixNameAttribute(): string + { + return sprintf('%s%s',$this->prefix ? $this->prefix.'-' : '',$this->name); + } + /* METHODS */ public function jsonSerialize(): array diff --git a/config/app.php b/config/app.php index a9354eb..bb6fe5a 100644 --- a/config/app.php +++ b/config/app.php @@ -15,16 +15,6 @@ return [ 'name' => env('APP_NAME', 'Laravel'), 'id' => env('APP_SETUP_ID', 1), - 'fido' => env('FIDO_DIR', 'fido'), - 'packet_keep' => env('FIDO_PACKET_KEEP', FALSE), - - // Size of packet before we decide to queue it for processing - 'queue_size' => env('FIDO_QUEUE_SIZE', 1000000), - // Number of messages in a packet that will result in them being queued for processing - 'queue_msgs' => env('FIDO_QUEUE_MSGS', 50), - 'default_pkt' => env('FIDO_DEFAULT_PACKET', '2+'), - 'areafilefix' => ['areafix','filefix'], - 'areabots' => array_merge(['sbbsecho'],['areafix','filefix']), /* |-------------------------------------------------------------------------- diff --git a/config/fido.php b/config/fido.php new file mode 100644 index 0000000..557d490 --- /dev/null +++ b/config/fido.php @@ -0,0 +1,28 @@ + ['areafix','filefix','rexfix','areamgr'], + + // Determine if incoming messages are from bots + 'areabots' => array_merge(['sbbsecho'],['areafix','filefix','rexfix','areamgr']), + + // Directory to use for any data we want to store locally + 'dir' => env('FIDO_DIR', 'fido'), + + // Our Storage::disk() for locally stored data + 'local_disk' => env('FIDO_LOCAL_DIR','local'), + + // Default packet to use if a user hasnt defined a packet format for their BBS + 'packet_default' => env('FIDO_DEFAULT_PACKET', '2+'), + + // Do we keep packets after processing, if so we'll store them in a data formatted dir yyyymmdd + 'packet_keep' => env('FIDO_PACKET_KEEP', FALSE), + + // Size of packet before we decide to queue it for processing + 'queue_size' => env('FIDO_QUEUE_SIZE', 1000000), + + // Number of messages in a packet that will result in them being queued for processing + 'queue_msgs' => env('FIDO_QUEUE_MSGS', 50), + +]; \ No newline at end of file diff --git a/config/filesystems.php b/config/filesystems.php index 90f00b5..85f21a8 100644 --- a/config/filesystems.php +++ b/config/filesystems.php @@ -33,7 +33,7 @@ return [ 'local' => [ 'driver' => 'local', 'root' => storage_path('app'), - 'throw' => false, + 'throw' => true, ], 'public' => [ diff --git a/resources/views/system/areafix.blade.php b/resources/views/system/areafix.blade.php index 7e1dd0b..5de247d 100644 --- a/resources/views/system/areafix.blade.php +++ b/resources/views/system/areafix.blade.php @@ -22,7 +22,7 @@
diff --git a/resources/views/system/widget/form-system.blade.php b/resources/views/system/widget/form-system.blade.php index 7863114..a9dd72f 100644 --- a/resources/views/system/widget/form-system.blade.php +++ b/resources/views/system/widget/form-system.blade.php @@ -194,7 +194,7 @@