Compare commits

..

4 Commits

Author SHA1 Message Date
fdede4fca9 Enable per system configuration of messages per packet
All checks were successful
Create Docker Image / Build Docker Image (x86_64) (push) Successful in 43s
Create Docker Image / Build Docker Image (arm64) (push) Successful in 1m49s
Create Docker Image / Final Docker Image Manifest (push) Successful in 10s
2024-06-02 09:37:08 +10:00
b5f22bea86 Downgrade DNS query errors, since they are handled
All checks were successful
Create Docker Image / Build Docker Image (x86_64) (push) Successful in 38s
Create Docker Image / Build Docker Image (arm64) (push) Successful in 1m48s
Create Docker Image / Final Docker Image Manifest (push) Successful in 10s
2024-06-01 12:55:44 +10:00
aa50580c13 Move HAproxy exceptions into their own class, and downgrade HAproxy errors since they are handled 2024-06-01 12:55:27 +10:00
81f59dcbb8 Remove EncodeUTF8 infavour of using attribute casting only. The implementation of EncodeUTF8 was not correct, essentially removing any previous casting causing issues when saving a record.
All checks were successful
Create Docker Image / Build Docker Image (x86_64) (push) Successful in 42s
Create Docker Image / Build Docker Image (arm64) (push) Successful in 1m50s
Create Docker Image / Final Docker Image Manifest (push) Successful in 11s
2024-06-01 10:46:02 +10:00
30 changed files with 92 additions and 313 deletions

View File

@ -673,7 +673,7 @@ class Message extends FTNBase
* @return Echomail|Netmail
* @throws InvalidPacketException
*/
public function unpackMessage(string $message,Echomail|Netmail $o): Echomail|Netmail
private function unpackMessage(string $message,Echomail|Netmail $o): Echomail|Netmail
{
// Remove DOS \n\r
$message = preg_replace("/\n\r/","\r",$message);
@ -796,9 +796,6 @@ class Message extends FTNBase
$ptr_content_start = $ptr_end-$ptr_start;
}
// Trim any right \r from the message
$o->msg = rtrim($o->msg,"\r");
// Quick validation that we are done
if ($ptr_content_start !== strlen($content))
throw new InvalidPacketException('There is more data in the message content?');
@ -850,6 +847,9 @@ class Message extends FTNBase
'replyid' => 'sometimes|min:1',
'msg' => 'required|min:1', // @todo max message length?
'msg_crc' => 'required|size:32',
'tagline' => 'sometimes|min:1|max:255',
'tearline' => 'sometimes|min:1|max:255',
'origin' => 'sometimes|min:1|max:255',
'local' => 'sometimes|boolean',
'fftn_id' => 'required|exists:App\Models\Address,id',
'tftn_id' => $this->isNetmail() ? 'required|exists:App\Models\Address,id' : 'prohibited',

View File

@ -507,7 +507,7 @@ class SystemController extends Controller
$no->flags = (Message::FLAG_LOCAL|Message::FLAG_PRIVATE|Message::FLAG_CRASH);
$no->cost = 0;
$no->set_tearline = sprintf('%s (%04X)',Setup::PRODUCT_NAME,Setup::PRODUCT_ID);
$no->tearline = sprintf('%s (%04X)',Setup::PRODUCT_NAME,Setup::PRODUCT_ID);
$no->save();
Log::info(sprintf('%s:= Areafix to [%s], scheduling a poll',self::LOGKEY,$no->tftn->ftn));

View File

@ -129,6 +129,8 @@ class PacketProcess implements ShouldQueue
if ($queue || (! $this->interactive))
Log::info(sprintf('%s:! Message [%s] will be sent to the queue to process',self::LOGKEY,$msg->msgid));
//dump(['msg'=>$msg]);
Log::debug('***',['a']);
try {
// Dispatch job.
if ($queue || (! $this->interactive))
@ -136,9 +138,11 @@ class PacketProcess implements ShouldQueue
else
MessageProcess::dispatchSync($msg->withoutRelations(),$this->nobot);
Log::debug('***',['b']);
$count++;
} catch (\Exception $e) {
Log::debug('***',['c']);
Log::error(sprintf('%s:! Got error [%s] dispatching message [%s] (%d:%s-%s).',self::LOGKEY,get_class($e),$msg->msgid,$e->getLine(),$e->getFile(),$e->getMessage()));
}
}

View File

@ -46,27 +46,6 @@ final class Echomail extends Model implements Packet
'rogue_path' => CollectionOrNull::class, // @deprecated?
];
public function __get($key)
{
switch ($key) {
case 'set_echoarea':
case 'set_fftn':
case 'set_path':
case 'set_pkt':
case 'set_recvtime':
case 'set_seenby':
case 'set_sender':
case 'set_tagline':
case 'set_tearline':
case 'set_origin':
return $this->set->get($key);
default:
return parent::__get($key);
}
}
public function __set($key,$value)
{
switch ($key) {
@ -92,7 +71,7 @@ final class Echomail extends Model implements Packet
case 'set_pkt':
case 'set_recvtime':
case 'set_sender':
// @todo We'll normalise these values when saving the netmail
case 'set_tagline':
case 'set_tearline':
case 'set_origin':
@ -122,26 +101,6 @@ final class Echomail extends Model implements Packet
static::creating(function($model) {
if (isset($model->errors) && $model->errors->count())
throw new \Exception('Cannot save, validation errors exist');
if ($model->set->has('set_tagline'))
$model->tagline_id = Tagline::firstOrCreate(['value'=>$model->set_tagline])->id;
if ($model->set->has('set_tearline'))
$model->tearline_id = Tearline::firstOrCreate(['value'=>$model->set_tearline])->id;
if ($model->set->has('set_origin')) {
// Make sure our origin contains our FTN
$m = [];
if ((preg_match('#^(.*)\s+\(([0-9]+:[0-9]+/[0-9]+.*)\)+\s*$#',$model->set_origin,$m))
&& (Address::findFTN($m[2])->id === $model->fftn_id))
$model->origin_id = Origin::firstOrCreate(['value'=>$m[1]])->id;
}
// If we can rebuild the message content, then we can do away with msg_src
if (md5($model->rebuildMessage()) === $model->msg_crc) {
Log::debug(sprintf('%s:- Pruning message source, since we can rebuild the message [%s]',self::LOGKEY,$model->msgid));
$model->msg_src = NULL;
}
});
// @todo if the message is updated with new SEEN-BY's from another route, we'll delete the pending export for systems (if there is one)
@ -254,6 +213,12 @@ final class Echomail extends Model implements Packet
return $this->belongsTo(Echoarea::class);
}
public function fftn()
{
return $this->belongsTo(Address::class)
->withTrashed();
}
public function seenby()
{
return $this->belongsToMany(Address::class,'echomail_seenby')

View File

@ -45,27 +45,6 @@ final class Netmail extends Model implements Packet
'sent_at' => 'datetime:Y-m-d H:i:s',
];
public function __get($key)
{
switch ($key) {
case 'set_fftn':
case 'set_tftn':
case 'set_path':
case 'set_pkt':
case 'set_recvtime':
case 'set_seenby':
case 'set_sender':
case 'set_tagline':
case 'set_tearline':
case 'set_origin':
return $this->set->get($key);
default:
return parent::__get($key);
}
}
public function __set($key,$value)
{
switch ($key) {
@ -88,7 +67,7 @@ final class Netmail extends Model implements Packet
case 'set_pkt':
case 'set_recvtime':
case 'set_sender':
// @todo We'll normalise these values when saving the netmail
case 'set_tagline':
case 'set_tearline':
case 'set_origin':
@ -115,26 +94,6 @@ final class Netmail extends Model implements Packet
static::creating(function($model) {
if (isset($model->errors) && $model->errors->count())
throw new \Exception('Cannot save, validation errors exist');
if ($model->set->has('set_tagline'))
$model->tagline_id = Tagline::firstOrCreate(['value'=>$model->set_tagline])->id;
if ($model->set->has('set_tearline'))
$model->tearline_id = Tearline::firstOrCreate(['value'=>$model->set_tearline])->id;
if ($model->set->has('set_origin')) {
// Make sure our origin contains our FTN
$m = [];
if ((preg_match('#^(.*)\s+\(([0-9]+:[0-9]+/[0-9]+.*)\)+\s*$#',$model->set_origin,$m))
&& (Address::findFTN($m[2])->id === $model->fftn_id))
$model->origin_id = Origin::firstOrCreate(['value'=>$m[1]])->id;
}
// If we can rebuild the message content, then we can do away with msg_src
if (md5($model->rebuildMessage()) === $model->msg_crc) {
Log::debug(sprintf('%s:- Pruning message source, since we can rebuild the message [%s]',self::LOGKEY,$model->msgid));
$model->msg_src = NULL;
}
});
static::created(function($model) {
@ -201,12 +160,27 @@ final class Netmail extends Model implements Packet
]);
}
// Save our origin, tearline & tagline
if ($model->set->has('set_tagline'))
$model->tagline = $model->set->get('set_tagline');
if ($model->set->has('set_tearline'))
$model->tearline = $model->set->get('set_tearline');
if ($model->set->has('set_origin'))
$model->origin = $model->set->get('set_origin');
$model->save();
});
}
/* RELATIONS */
public function fftn()
{
return $this
->belongsTo(Address::class)
->withTrashed();
}
public function path()
{
return $this->belongsToMany(Address::class,'netmail_path')

View File

@ -1,20 +0,0 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class Origin extends Model
{
//use HasFactory;
public const UPDATED_AT = NULL;
protected $fillable = ['value'];
public function complete(Address $o): string
{
return sprintf(' * Origin: %s (%s)',$this->value,$o->point_id ? $o->ftn4d : $o->ftn3d);
}
}

View File

@ -1,20 +0,0 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class Tagline extends Model
{
//use HasFactory;
public const UPDATED_AT = NULL;
protected $fillable = ['value'];
public function complete(): string
{
return sprintf('... %s',$this->value);
}
}

View File

@ -1,20 +0,0 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class Tearline extends Model
{
//use HasFactory;
public const UPDATED_AT = NULL;
protected $fillable = ['value'];
public function complete(): string
{
return sprintf('--- %s',$this->value);
}
}

View File

@ -58,7 +58,7 @@ abstract class Echomails extends Notification //implements ShouldQueue
$o->flags = (Message::FLAG_LOCAL);
$o->set_tearline = sprintf('%s (%04X)',Setup::PRODUCT_NAME,Setup::PRODUCT_ID);
$o->tearline = sprintf('%s (%04X)',Setup::PRODUCT_NAME,Setup::PRODUCT_ID);
return $o;
}

View File

@ -48,6 +48,7 @@ class AbsentNodes extends Echomails
$o->subject = 'Status changes for nodes';
$o->fftn_id = ($x=our_address($echoarea->domain)->last())->id;
$o->kludges->put('CHRS:','CP437 2');
$o->origin = sprintf('%s (%s)',Setup::PRODUCT_NAME,$x->ftn4d);
// Message
$msg = new Page;
@ -94,8 +95,7 @@ class AbsentNodes extends Echomails
$msg->addText("\rEmails and/or Netmails have been sent to these nodes. If you can help let them know that they have outstanding mail on the Hub, that would be helpful :)");
$o->msg = $msg->render();
$o->set_tagline = 'When life gives you lemons, freeze them and throw them back.';
$o->set_origin = sprintf('%s (%s)',Setup::PRODUCT_NAME,$x->ftn4d);
$o->tagline = 'When life gives you lemons, freeze them and throw them back.';
$o->save();

View File

@ -50,6 +50,7 @@ class Test extends Echomails
$o->replyid = $this->mo->msgid;
$o->subject = 'Test Reply';
$o->kludges->put('CHRS:',$this->mo->kludges->get('chrs') ?: 'CP437 2');
$o->origin = sprintf('%s (%s)',Setup::PRODUCT_NAME,$x->ftn4d);
// Message
$msg = new Page;
@ -73,8 +74,7 @@ class Test extends Echomails
$msg->addText($this->message_path($this->mo));
$o->msg = $msg->render();
$o->set_tagline = 'I ate a clock yesterday, it was very time-consuming.';
$o->set_origin = sprintf('%s (%s)',Setup::PRODUCT_NAME,$x->ftn4d);
$o->tagline = 'I ate a clock yesterday, it was very time-consuming.';
$o->save();

View File

@ -64,7 +64,7 @@ abstract class Netmails extends Notification //implements ShouldQueue
$o->flags = (Message::FLAG_LOCAL|Message::FLAG_PRIVATE);
$o->cost = 0;
$o->set_tearline = sprintf('%s (%04X)',Setup::PRODUCT_NAME,Setup::PRODUCT_ID);
$o->tearline = sprintf('%s (%04X)',Setup::PRODUCT_NAME,Setup::PRODUCT_ID);
return $o;
}

View File

@ -59,7 +59,7 @@ class AddressLink extends Netmails
));
$o->msg = $msg->render();
$o->set_tagline = 'Address Linking...';
$o->tagline = 'Address Linking...';
$o->save();

View File

@ -55,7 +55,7 @@ class Areafix extends Netmails
$msg->addText($this->message_path($this->mo));
$o->msg = $msg->render();
$o->set_tagline = 'Why did the robot cross the road? The chicken programmed it.';
$o->tagline = 'Why did the robot cross the road? The chicken programmed it.';
$o->save();

View File

@ -55,7 +55,7 @@ class NotConfiguredHere extends Netmails
$msg->addText($this->message_path($this->mo));
$o->msg = $msg->render();
$o->set_tagline = 'Why did the robot cross the road? The chicken programmed it.';
$o->tagline = 'Why did the robot cross the road? The chicken programmed it.';
$o->save();

View File

@ -63,7 +63,7 @@ class EchoareaNoWrite extends Netmails
$msg->addText($this->message_path($this->mo));
$o->msg = $msg->render();
$o->set_tagline = 'See something wrong? Do something right.';
$o->tagline = 'See something wrong? Do something right.';
$o->save();

View File

@ -65,7 +65,7 @@ class EchoareaNotExist extends Netmails
$msg->addText($this->message_path($this->mo));
$o->msg = $msg->render();
$o->set_tagline = 'Don\'t let your trash become someone else\'s treasure. Feed your shredder often.';
$o->tagline = 'Don\'t let your trash become someone else\'s treasure. Feed your shredder often.';
$o->save();

View File

@ -64,7 +64,7 @@ class EchoareaNotSubscribed extends Netmails
$msg->addText($this->message_path($this->mo));
$o->msg = $msg->render();
$o->set_tagline = 'Don\'t let your trash become someone else\'s treasure. Feed your shredder.';
$o->tagline = 'Don\'t let your trash become someone else\'s treasure. Feed your shredder.';
$o->save();

View File

@ -64,7 +64,7 @@ class EchomailBadAddress extends Netmails
$msg->addText($this->message_path($this->mo));
$o->msg = $msg->render();
$o->set_tagline = 'I enjoyed reading your message, even though nobody else will get it :)';
$o->tagline = 'I enjoyed reading your message, even though nobody else will get it :)';
$o->save();

View File

@ -61,7 +61,7 @@ class NetmailForward extends Netmails
$msg->addText(sprintf("To avoid receiving this netmail, send messages to [%s] to [%s].\r\r",$this->mo->to,$this->ao->ftn3d));
$o->msg = $msg->render();
$o->set_tagline = 'Thank you so much for your mail. I love it already.';
$o->tagline = 'Thank you so much for your mail. I love it already.';
$o->save();

View File

@ -64,7 +64,7 @@ class NetmailHubNoUser extends Netmails
$msg->addText($this->message_path($this->mo));
$o->msg = $msg->render();
$o->set_tagline = 'Do you think it was fate which brought us together? Nah, bad luck :(';
$o->tagline = 'Do you think it was fate which brought us together? Nah, bad luck :(';
$o->save();

View File

@ -50,7 +50,7 @@ class NodeDelisted extends Netmails //implements ShouldQueue
->addText(sprintf('If you think about returning to %s, then reach out and we can get you back online pretty quickly.',$x));
$o->msg = $msg->render();
$o->set_tagline = 'You\'ve been DE-LISTED';
$o->tagline = 'You\'ve been DE-LISTED';
$o->save();

View File

@ -55,7 +55,7 @@ class NodeMarkedDown extends Netmails //implements ShouldQueue
->addText("If you think you've received this netmail by mistake or need help, please let me know.\r");
$o->msg = $msg->render();
$o->set_tagline = 'Pending de-list';
$o->tagline = 'Pending de-list';
$o->save();

View File

@ -55,7 +55,7 @@ class NodeMarkedHold extends Netmails //implements ShouldQueue
->addText("If you think you've received this netmail by mistake or need help, please let me know.\r");
$o->msg = $msg->render();
$o->set_tagline = 'You\'ve been marked HOLD';
$o->tagline = 'You\'ve been marked HOLD';
$o->save();

View File

@ -62,7 +62,7 @@ class PacketPasswordInvalid extends Netmails
$msg->addText("Head over to the website if you dont know what your packet password should be :)\r");
$o->msg = $msg->render();
$o->set_tagline = 'Safety first, password second.';
$o->tagline = 'Safety first, password second.';
$o->save();

View File

@ -63,7 +63,7 @@ class Ping extends Netmails
$msg->addText($this->message_path($this->mo));
$o->msg = $msg->render();
$o->set_tagline = 'My ping pong opponent was not happy with my serve. He kept returning it.';
$o->tagline = 'My ping pong opponent was not happy with my serve. He kept returning it.';
$o->save();

View File

@ -47,7 +47,7 @@ class PollingFailed extends Netmails
$msg->addText("To fix this, update your details that I use in the web interface, or change your system to HOLD while you are there.\r\r");
$o->msg = $msg->render();
$o->set_tagline = 'Painful? We can make that painless :)';
$o->tagline = 'Painful? We can make that painless :)';
$o->save();

View File

@ -40,7 +40,7 @@ class Test extends Netmails
);
$o->msg = $msg->render();
$o->set_tagline = 'Testing, testing, 1 2 3.';
$o->tagline = 'Testing, testing, 1 2 3.';
$o->save();

View File

@ -11,7 +11,7 @@ use Illuminate\Support\Facades\Log;
use Illuminate\Support\MessageBag;
use App\Classes\FTN\Message;
use App\Models\{Address,Echomail,Origin,Tagline,Tearline};
use App\Models\{Address,Echomail};
trait MessageAttributes
{
@ -28,35 +28,26 @@ trait MessageAttributes
$this->set = collect();
}
/* RELATIONS */
public function fftn()
{
return $this
->belongsTo(Address::class)
->withTrashed();
}
public function origin()
{
return $this->belongsTo(Origin::class);
}
public function tagline()
{
return $this->belongsTo(Tagline::class);
}
public function tearline()
{
return $this->belongsTo(Tearline::class);
}
/* ATTRIBUTES */
public function getContentAttribute(): string
{
return ($this->msg_src) ? $this->msg_src : $this->rebuildMessage();
if ($this->msg_src)
return $this->msg_src;
// If we have a msg_src attribute, we'll use that
$result = $this->msg."\r\r";
if ($this->tagline)
$result .= sprintf("%s\r",$this->tagline);
if ($this->tearline)
$result .= sprintf("%s\r",$this->tearline);
if ($this->origin)
$result .= sprintf("%s",$this->origin);
return rtrim($result,"\r");
}
public function getDateAttribute(): Carbon
@ -66,35 +57,38 @@ trait MessageAttributes
public function getOriginAttribute(string $val=NULL): ?string
{
if (($x=$this->getRelationValue('origin')) && $x->value)
return $x->complete($this->fftn);
if ($this->exists && (! $val))
return $val;
if (($this->set->has('set_origin')) || ($val))
return sprintf(' * Origin: %s',$this->set->get('set_origin',$val));
return NULL;
// If $val is not set, then it may be an unsaved object
return sprintf(' * Origin: %s',
((! $this->exists) && $this->set->has('set_origin'))
? $this->set->get('set_origin')
: $val);
}
public function getTaglineAttribute(string $val=NULL): ?string
{
if (($x=$this->getRelationValue('tagline')) && $x->value)
return $x->complete();
if ($this->exists && (! $val))
return $val;
if (($this->set->has('set_tagline')) || ($val))
return sprintf('... %s',$this->set->get('set_tagline',$val));
return NULL;
// If $val is not set, then it may be an unsaved object
return sprintf('... %s',
((! $this->exists) && $this->set->has('set_tagline'))
? $this->set->get('set_tagline')
: $val);
}
public function getTearlineAttribute(string $val=NULL): ?string
{
if (($x=$this->getRelationValue('tearline')) && $x->value)
return $x->complete();
if ($this->exists && (! $val))
return $val;
if (($this->set->has('set_tearline')) || ($val))
return sprintf('--- %s',$this->set->get('set_tearline',$val));
return NULL;
// If $val is not set, then it may be an unsaved object
return sprintf('--- %s',
((! $this->exists) && $this->set->has('set_tearline'))
? $this->set->get('set_tearline')
: $val);
}
/* METHODS */
@ -170,23 +164,6 @@ trait MessageAttributes
return Message::packMessage($this);
}
public function rebuildMessage(): string
{
// If we have a msg_src attribute, we'll use that
$result = $this->msg."\r";
if ($x=$this->tagline)
$result .= sprintf("%s\r",$x);
if ($x=$this->tearline)
$result .= sprintf("%s\r",$x);
if ($x=$this->origin)
$result .= sprintf("%s",$x);
return rtrim($result,"\r");
}
/**
* Return our path in order
*

View File

@ -1,81 +0,0 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('taglines', function (Blueprint $table) {
$table->id();
$table->timestamp('created_at');
$table->softDeletes();
$table->string('value')->unique();
});
Schema::create('tearlines', function (Blueprint $table) {
$table->id();
$table->timestamp('created_at');
$table->softDeletes();
$table->string('value')->unique();
});
Schema::create('origins', function (Blueprint $table) {
$table->id();
$table->timestamp('created_at');
$table->softDeletes();
$table->string('value')->unique();
});
Schema::table('echomails', function (Blueprint $table) {
$table->bigInteger('tagline_id')->nullable();
$table->foreign('tagline_id')->references('id')->on('taglines');
$table->bigInteger('tearline_id')->nullable();
$table->foreign('tearline_id')->references('id')->on('tearlines');
$table->bigInteger('origin_id')->nullable();
$table->foreign('origin_id')->references('id')->on('origins');
});
Schema::table('netmails', function (Blueprint $table) {
$table->bigInteger('tagline_id')->nullable();
$table->foreign('tagline_id')->references('id')->on('taglines');
$table->bigInteger('tearline_id')->nullable();
$table->foreign('tearline_id')->references('id')->on('tearlines');
$table->bigInteger('origin_id')->nullable();
$table->foreign('origin_id')->references('id')->on('origins');
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::table('netmails', function (Blueprint $table) {
$table->dropForeign(['tagline_id']);
$table->dropForeign(['tearline_id']);
$table->dropForeign(['origin_id']);
$table->dropColumn(['tagline_id','tearline_id','origin_id']);
});
Schema::table('echomails', function (Blueprint $table) {
$table->dropForeign(['tagline_id']);
$table->dropForeign(['tearline_id']);
$table->dropForeign(['origin_id']);
$table->dropColumn(['tagline_id','tearline_id','origin_id']);
});
Schema::dropIfExists('origins');
Schema::dropIfExists('tearlines');
Schema::dropIfExists('taglines');
}
};