Multiple enhancements to interactive messages, moved messages to Notifications, send netmail back when invalid packet password
This commit is contained in:
@@ -84,8 +84,10 @@ class Message extends FTNBase
|
||||
public const FLAG_AUDITREQ = 1<<14; // (ARQ)
|
||||
/** @var int Requesting a file update (filename in subject) */
|
||||
public const FLAG_FILEUPDATEREQ = 1<<15; // (URQ)
|
||||
/** Echomail has been scanned out */
|
||||
/** @var int Echomail has been scanned out */
|
||||
public const FLAG_ECHOMAIL = 1<<16;
|
||||
/** @var int Use packet password on the subject line for this message */
|
||||
public const FLAG_PKTPASSWD = 1<<17;
|
||||
|
||||
// FTS-0001.016 Message header 32 bytes node, net, flags, cost, date
|
||||
public const HEADER_LEN = 0x20; // Length of message header
|
||||
|
@@ -368,8 +368,9 @@ class Packet extends FTNBase implements \Iterator, \Countable
|
||||
*
|
||||
* @param Address $oo
|
||||
* @param Address $o
|
||||
* @param string|null $passwd Override the password used in the packet
|
||||
*/
|
||||
public function addressHeader(Address $oo,Address $o): void
|
||||
public function addressHeader(Address $oo,Address $o,string $passwd=NULL): void
|
||||
{
|
||||
Log::debug(sprintf('%s:+ Creating packet for [%s]',self::LOGKEY,$o->ftn));
|
||||
|
||||
@@ -393,7 +394,7 @@ class Packet extends FTNBase implements \Iterator, \Countable
|
||||
'H' => $date->format('H'), // Hour
|
||||
'M' => $date->format('i'), // Minute
|
||||
'S' => $date->format('s'), // Second
|
||||
'password' => $o->session('pktpass'), // Packet Password
|
||||
'password' => (! is_null($passwd)) ? $passwd : $o->session('pktpass'), // Packet Password
|
||||
];
|
||||
}
|
||||
|
||||
|
@@ -2,17 +2,11 @@
|
||||
|
||||
namespace App\Classes\FTN;
|
||||
|
||||
use Illuminate\Support\Arr;
|
||||
|
||||
/**
|
||||
* Abstract class to hold the common functions for automatic responding to echomail/netmail messages
|
||||
*/
|
||||
abstract class Process
|
||||
{
|
||||
private const LOGKEY = 'R--';
|
||||
|
||||
protected const MSG_WIDTH = 79;
|
||||
|
||||
/**
|
||||
* Return TRUE if the process class handled the message.
|
||||
*
|
||||
@@ -20,79 +14,4 @@ abstract class Process
|
||||
* @return bool
|
||||
*/
|
||||
abstract public static function handle(Message $msg): bool;
|
||||
|
||||
/**
|
||||
* This function will format text to static::MSG_WIDTH, as well as adding the logo.
|
||||
*/
|
||||
public static function format_msg(string $text,array $logo = []): string
|
||||
{
|
||||
$msg = utf8_decode(join("\r",static::msg_header()))."\r";
|
||||
$c = 0;
|
||||
$offset = 0;
|
||||
|
||||
while ($offset < strlen($text)) {
|
||||
$ll = '';
|
||||
|
||||
// Add our logo
|
||||
if ($c<count($logo)) {
|
||||
$line = utf8_decode(Arr::get($logo,$c++));
|
||||
$ll = $line.' ';
|
||||
}
|
||||
|
||||
// Look for a return
|
||||
$return = strpos($text,"\r",$offset);
|
||||
|
||||
if ($return !== FALSE)
|
||||
$return -= $offset;
|
||||
|
||||
if (($return !== FALSE && $return < static::MSG_WIDTH-strlen($ll))) {
|
||||
$subtext = substr($text,$offset,$return);
|
||||
|
||||
} else {
|
||||
$subtext = substr($text,$offset,static::MSG_WIDTH-strlen($ll));
|
||||
|
||||
// Look for a space
|
||||
$space = strrpos($subtext,' ');
|
||||
|
||||
if ($space === FALSE)
|
||||
$space = strlen($subtext);
|
||||
else
|
||||
$subtext = substr($text,$offset,$space);
|
||||
}
|
||||
|
||||
$msg .= $ll.$subtext."\r";
|
||||
$offset += strlen($subtext)+1;
|
||||
}
|
||||
|
||||
// In case our text is shorter than the loo
|
||||
for ($c; $c<count($logo);$c++)
|
||||
$msg .= utf8_decode(Arr::get($logo,$c))."\r";
|
||||
|
||||
$msg .= utf8_decode(join("\r",static::msg_footer()))."\r";
|
||||
|
||||
return $msg;
|
||||
}
|
||||
|
||||
/**
|
||||
* Header added to messages
|
||||
*
|
||||
* @return string[]
|
||||
*/
|
||||
protected static function msg_header(): array
|
||||
{
|
||||
return [
|
||||
' ÜÜÜ Ü ÜÜÜ ÜÜÜ ÜÜÜ Ü ÜÜÜ ÜÜÜ Ü ÜÜÜ Ü Ü ÜÜÜ',
|
||||
' Û ß Û ÛÜÛ ÜÜÛ Û ß Ü Û Û ÛÜÛ ÛßÛ Û Û Û Û Üß',
|
||||
' ÛÜÛ ÛÜÛ ÛÜÜ ÛÜÛ Û Û Û Û ÜÜÛ Û Û ÛÜÛ ÛÜÛ ÛÜÜ',
|
||||
' FTN Mailer and Tosser',
|
||||
'ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ'
|
||||
];
|
||||
}
|
||||
|
||||
protected static function msg_footer(): array
|
||||
{
|
||||
return [
|
||||
'ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ'
|
||||
];
|
||||
}
|
||||
}
|
@@ -2,12 +2,11 @@
|
||||
|
||||
namespace App\Classes\FTN\Process\Echomail;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Carbon\CarbonInterface;
|
||||
use Illuminate\Support\Facades\Notification;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
use App\Classes\FTN\{Message,Process};
|
||||
use App\Models\{Echoarea,Echomail,Setup};
|
||||
use App\Notifications\Echomails\Test as TestNotification;
|
||||
|
||||
/**
|
||||
* Process messages to Test
|
||||
@@ -18,12 +17,6 @@ final class Test extends Process
|
||||
{
|
||||
private const LOGKEY = 'RT-';
|
||||
|
||||
private static array $logo = [
|
||||
'Ú¿ÚÄ¿ÚĿڿ',
|
||||
' ³ ³ÄÙÀÄ¿ ³ ',
|
||||
' Á ÀÄÙÀÄÙ Á '
|
||||
];
|
||||
|
||||
private const testing = ['test','testing'];
|
||||
|
||||
public static function handle(Message $msg): bool
|
||||
@@ -32,51 +25,8 @@ final class Test extends Process
|
||||
return FALSE;
|
||||
|
||||
Log::info(sprintf('%s:- Processing TEST message from (%s) [%s]',self::LOGKEY,$msg->user_from,$msg->fftn));
|
||||
$ftns = Setup::findOrFail(config('app.id'))->system->match($msg->fboss_o->zone)->first();
|
||||
|
||||
$reply = sprintf("Your test was received here on %s and it looks like you sent it on %s. If that is correct, then it took %s to get here.\r",
|
||||
Carbon::now()->utc()->toDateTimeString(),
|
||||
$msg->date->utc()->toDateTimeString(),
|
||||
$msg->date->diffForHumans(['parts'=>3,'syntax'=>CarbonInterface::DIFF_ABSOLUTE])
|
||||
);
|
||||
|
||||
$reply .= "\r";
|
||||
$reply .= "\r";
|
||||
$reply .= "------------------------------ BEGIN MESSAGE ------------------------------\r";
|
||||
$reply .= sprintf("TO: %s\r",$msg->user_to);
|
||||
$reply .= sprintf("SUBJECT: %s\r",$msg->subject);
|
||||
$reply .= str_replace("\r---","\r#--",$msg->message)."\r";
|
||||
$reply .= "------------------------------ CONTROL LINES ------------------------------\r";
|
||||
$reply .= sprintf("DATE: %s\r",$msg->date->utc()->format('Y-m-d H:i:s'));
|
||||
$reply .= sprintf("MSGID: %s\r",$msg->msgid);
|
||||
|
||||
foreach ($msg->kludge as $k=>$v)
|
||||
$reply .= sprintf("@%s: %s\r",strtoupper($k),$v);
|
||||
foreach ($msg->via as $via)
|
||||
$reply .= sprintf("VIA: %s\r",$via);
|
||||
|
||||
$reply .= "------------------------------ END MESSAGE ------------------------------\r";
|
||||
|
||||
$eo = Echoarea::where('name',$msg->echoarea)->single();
|
||||
|
||||
$o = new Echomail;
|
||||
$o->init();
|
||||
$o->to = $msg->user_from;
|
||||
$o->from = Setup::PRODUCT_NAME;
|
||||
$o->subject = 'Test Reply';
|
||||
$o->datetime = Carbon::now();
|
||||
$o->tzoffset = $o->datetime->utcOffset();
|
||||
$o->echoarea_id = $eo?->id;
|
||||
$o->replyid = $msg->msgid;
|
||||
$o->fftn_id = $ftns->id;
|
||||
|
||||
$o->flags = Message::FLAG_LOCAL;
|
||||
$o->msg = static::format_msg($reply,self::$logo);
|
||||
$o->tagline = 'I ate a clock yesterday, it was very time-consuming.';
|
||||
$o->tearline = sprintf('%s (%04X)',Setup::PRODUCT_NAME,Setup::PRODUCT_ID);
|
||||
$o->origin = sprintf('%s (%s)',Setup::PRODUCT_NAME,$ftns->ftn4d);
|
||||
$o->kludges = collect(['chrs'=>$msg->kludge->get('chrs') ?: 'CP437 2']);
|
||||
$o->save();
|
||||
Notification::route('echomail',$msg->echoarea)->notify(new TestNotification($msg));
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
@@ -2,12 +2,11 @@
|
||||
|
||||
namespace App\Classes\FTN\Process\Netmail;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Carbon\CarbonInterface;
|
||||
use Illuminate\Support\Facades\Notification;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
use App\Classes\FTN\{Message,Process};
|
||||
use App\Models\{Netmail,Setup};
|
||||
use App\Notifications\Netmails\Ping as PingNotification;
|
||||
|
||||
/**
|
||||
* Process messages to Ping
|
||||
@@ -18,48 +17,14 @@ final class Ping extends Process
|
||||
{
|
||||
private const LOGKEY = 'RP-';
|
||||
|
||||
private static array $logo = [
|
||||
'ÚÄ¿þÚÄ¿ÚÄ¿',
|
||||
'³ ³Â³ ³Àij',
|
||||
'ÃÄÙÁÁ ÁÄÄÙ'
|
||||
];
|
||||
|
||||
public static function handle(Message $msg): bool
|
||||
{
|
||||
if (strtolower($msg->user_to) !== 'ping')
|
||||
return FALSE;
|
||||
|
||||
Log::info(sprintf('%s:- Processing PING message from (%s) [%s]',self::LOGKEY,$msg->user_from,$msg->fftn));
|
||||
$ftns = Setup::findOrFail(config('app.id'))->system->match($msg->fftn_o->zone)->first();
|
||||
|
||||
$reply = sprintf("Your ping was received here on %s and it looks like you sent it on %s. If that is correct, then it took %s to get here.\r",
|
||||
Carbon::now()->utc()->toDateTimeString(),
|
||||
$msg->date->utc()->toDateTimeString(),
|
||||
$msg->date->diffForHumans(['parts'=>3,'syntax'=>CarbonInterface::DIFF_ABSOLUTE])
|
||||
);
|
||||
|
||||
$reply .= "\r";
|
||||
$reply .= "Your message travelled along this path on the way here:\r";
|
||||
foreach ($msg->via as $path)
|
||||
$reply .= sprintf(" * %s\r",$path);
|
||||
|
||||
$o = new Netmail;
|
||||
$o->to = $msg->user_from;
|
||||
$o->from = Setup::PRODUCT_NAME;
|
||||
$o->subject = 'Ping Reply';
|
||||
$o->datetime = Carbon::now();
|
||||
$o->tzoffset = $o->datetime->utcOffset();
|
||||
|
||||
$o->replyid = $msg->msgid;
|
||||
$o->fftn_id = $ftns->id;
|
||||
$o->tftn_id = ($x=$msg->fftn_o) ? $x->id : NULL;
|
||||
$o->flags = Message::FLAG_LOCAL|Message::FLAG_PRIVATE;
|
||||
$o->cost = 0;
|
||||
|
||||
$o->msg = static::format_msg($reply,self::$logo);
|
||||
$o->tagline = 'My ping pong opponent was not happy with my serve. He kept returning it.';
|
||||
$o->tearline = sprintf('%s (%04X)',Setup::PRODUCT_NAME,Setup::PRODUCT_ID);
|
||||
$o->save();
|
||||
Notification::route('netmail',$msg->fftn_o)->notify(new PingNotification($msg));
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
@@ -3,9 +3,8 @@
|
||||
namespace App\Classes\File;
|
||||
|
||||
use Illuminate\Support\Arr;
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Illuminate\Support\Facades\Notification;
|
||||
use Symfony\Component\HttpFoundation\File\Exception\FileException;
|
||||
|
||||
use App\Classes\{File,Protocol};
|
||||
@@ -13,6 +12,7 @@ use App\Classes\FTN\{InvalidPacketException,Packet};
|
||||
use App\Exceptions\FileGrewException;
|
||||
use App\Jobs\{MessageProcess,TicProcess};
|
||||
use App\Models\Address;
|
||||
use App\Notifications\Netmails\PacketPasswordInvalid;
|
||||
|
||||
/**
|
||||
* Object representing the files we are receiving
|
||||
@@ -138,10 +138,10 @@ class Receive extends Base
|
||||
}
|
||||
|
||||
// Check the packet password
|
||||
if ($this->ao->session('pktpass') != $po->password) {
|
||||
if ($this->ao->session('pktpass') !== $po->password) {
|
||||
Log::error(sprintf('%s:! Packet from [%s] with password [%s] is invalid.',self::LOGKEY,$this->ao->ftn,$po->password));
|
||||
|
||||
// @todo Generate message to system advising invalid password - that message should be sent without a packet password!
|
||||
Notification::route('netmail',$this->ao)->notify(new PacketPasswordInvalid($po->password,$this->receiving->nameas));
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -158,6 +158,20 @@ class Receive extends Base
|
||||
// @todo Quick check that the packet should be processed by us.
|
||||
// @todo validate that the packet's zone is in the domain.
|
||||
|
||||
/*
|
||||
* // @todo generate exception when echomail for an area that doesnt exist
|
||||
* // @todo generate exception when echomail for an area sender cannot post to
|
||||
* // @todo generate exception when echomail for an area sender not subscribed to
|
||||
* // @todo generate exception when echomail comes from a system not defined here
|
||||
* // @todo generate exception when echomail comes from a system doesnt exist
|
||||
*
|
||||
* // @todo generate exception when netmail to system that doesnt exist (node/point)
|
||||
* // @todo generate exception when netmail from system that doesnt exist (node/point)
|
||||
* // @todo generate warning when netmail comes from a system not defined here
|
||||
*
|
||||
* // @todo generate exception when packet has wrong password
|
||||
*/
|
||||
|
||||
try {
|
||||
// Dispatch job.
|
||||
if ($queue)
|
||||
|
Reference in New Issue
Block a user