Multiple enhancements to interactive messages, moved messages to Notifications, send netmail back when invalid packet password

This commit is contained in:
2023-07-23 17:27:52 +10:00
parent 9f0fa0a8ec
commit 17fe7e910d
28 changed files with 837 additions and 475 deletions

View File

@@ -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

View File

@@ -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
];
}

View File

@@ -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 [
'ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ'
];
}
}

View File

@@ -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;
}

View File

@@ -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;
}