2021-04-01 10:59:15 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Classes;
|
|
|
|
|
2021-08-15 14:41:43 +00:00
|
|
|
use Illuminate\Support\Collection;
|
2021-04-01 10:59:15 +00:00
|
|
|
use Illuminate\Support\Facades\Log;
|
|
|
|
|
|
|
|
use App\Classes\File\{Receive,Send};
|
2024-11-08 12:13:04 +00:00
|
|
|
use App\Classes\Protocol\{Binkp,DNS,EMSI,Zmodem};
|
2024-06-01 02:55:27 +00:00
|
|
|
use App\Classes\Sock\Exception\SocketException;
|
2021-04-01 10:59:15 +00:00
|
|
|
use App\Classes\Sock\SocketClient;
|
2023-12-10 08:07:53 +00:00
|
|
|
use App\Models\{Address,Mailer,Setup,System,SystemLog};
|
2021-04-01 10:59:15 +00:00
|
|
|
|
2024-05-17 12:10:54 +00:00
|
|
|
// @todo after receiving a mail packet/file, dont acknowledge it until we can validate that we can read it properly.
|
|
|
|
|
2021-04-01 10:59:15 +00:00
|
|
|
abstract class Protocol
|
|
|
|
{
|
|
|
|
// Enable extra debugging
|
2023-07-19 00:27:47 +00:00
|
|
|
protected const DEBUG = FALSE;
|
2021-04-01 10:59:15 +00:00
|
|
|
|
2021-08-15 14:41:43 +00:00
|
|
|
private const LOGKEY = 'P--';
|
|
|
|
|
2023-07-02 13:40:08 +00:00
|
|
|
/* CONSTS */
|
|
|
|
|
2021-04-01 10:59:15 +00:00
|
|
|
// Return constants
|
|
|
|
protected const OK = 0;
|
|
|
|
protected const TIMEOUT = -2;
|
|
|
|
protected const RCDO = -3;
|
|
|
|
protected const ERROR = -5;
|
|
|
|
|
|
|
|
protected const MAX_PATH = 1024;
|
|
|
|
|
2023-07-02 13:40:08 +00:00
|
|
|
/* O_ options - [First 9 bits are protocol P_* (Interfaces/ZModem)] */
|
|
|
|
|
|
|
|
/** 0000 0000 0000 0000 0010 0000 0000 BOTH - No file requests accepted by this system */
|
|
|
|
protected const O_NRQ = 1<<9;
|
|
|
|
/** 0000 0000 0000 0000 0100 0000 0000 BOTH - Hold file requests (not processed at this time). */
|
|
|
|
protected const O_HRQ = 1<<10;
|
|
|
|
/** 0000 0000 0000 0000 1000 0000 0000 - Filename conversion, transmitted files must be 8.3 */
|
|
|
|
protected const O_FNC = 1<<11;
|
|
|
|
/** 0000 0000 0000 0001 0000 0000 0000 - Supports other forms of compressed mail */
|
|
|
|
protected const O_XMA = 1<<12;
|
|
|
|
/** 0000 0000 0000 0010 0000 0000 0000 BOTH - Hold ALL files (Answering System) */
|
|
|
|
protected const O_HAT = 1<<13;
|
|
|
|
/** 0000 0000 0000 0100 0000 0000 0000 BOTH - Hold Mail traffic */
|
|
|
|
protected const O_HXT = 1<<14;
|
|
|
|
/** 0000 0000 0000 1000 0000 0000 0000 - No files pickup desired (Calling System) */
|
|
|
|
protected const O_NPU = 1<<15;
|
|
|
|
/** 0000 0000 0001 0000 0000 0000 0000 - Pickup files for primary address only */
|
|
|
|
protected const O_PUP = 1<<16;
|
|
|
|
/** 0000 0000 0010 0000 0000 0000 0000 EMSI - Pickup files for all presented addresses */
|
|
|
|
protected const O_PUA = 1<<17;
|
|
|
|
/** 0000 0000 0100 0000 0000 0000 0000 BINK - Node needs to be password validated */
|
|
|
|
protected const O_PWD = 1<<18;
|
|
|
|
/** 0000 0000 1000 0000 0000 0000 0000 BOTH - Node invalid password presented */
|
|
|
|
protected const O_BAD = 1<<19;
|
|
|
|
/** 0000 0001 0000 0000 0000 0000 0000 EMSI - Use RH1 for Hydra (files-after-freqs) */
|
|
|
|
protected const O_RH1 = 1<<20;
|
|
|
|
/** 0000 0010 0000 0000 0000 0000 0000 BOTH - Node is nodelisted */
|
|
|
|
protected const O_LST = 1<<21;
|
|
|
|
/** 0000 0100 0000 0000 0000 0000 0000 BOTH - Inbound session */
|
|
|
|
protected const O_INB = 1<<22;
|
|
|
|
/** 0000 1000 0000 0000 0000 0000 0000 BOTH - TCP session */
|
|
|
|
protected const O_TCP = 1<<23;
|
|
|
|
/** 0001 0000 0000 0000 0000 0000 0000 EMSI - Remote understands EMSI-II */
|
|
|
|
protected const O_EII = 1<<24;
|
|
|
|
|
|
|
|
/* Negotiation Options */
|
|
|
|
|
|
|
|
/** 00 0000 I/They dont want a capability? */
|
|
|
|
protected const O_NO = 0;
|
|
|
|
/** 00 0001 - I want a capability, but can be persuaded */
|
|
|
|
protected const O_WANT = 1<<0;
|
|
|
|
/** 00 0010 - They want a capability and we want it too */
|
|
|
|
protected const O_WE = 1<<1;
|
|
|
|
/** 00 0100 - They want a capability */
|
|
|
|
protected const O_THEY = 1<<2;
|
|
|
|
/** 00 1000 - I want a capability, and wont compromise */
|
|
|
|
protected const O_NEED = 1<<3;
|
|
|
|
/** 01 0000 - Extra options set */
|
|
|
|
protected const O_EXT = 1<<4;
|
|
|
|
/** 10 0000 - We agree on a capability and we are set to use it */
|
|
|
|
protected const O_YES = 1<<5;
|
2021-04-01 10:59:15 +00:00
|
|
|
|
|
|
|
// Session Status
|
2023-07-07 13:59:04 +00:00
|
|
|
public const S_OK = 0;
|
2021-04-01 10:59:15 +00:00
|
|
|
protected const S_NODIAL = 1;
|
|
|
|
protected const S_REDIAL = 2;
|
|
|
|
protected const S_BUSY = 3;
|
|
|
|
protected const S_FAILURE = 4;
|
2023-07-07 13:59:04 +00:00
|
|
|
public const S_MASK = 7;
|
2021-04-01 10:59:15 +00:00
|
|
|
protected const S_HOLDR = 8;
|
|
|
|
protected const S_HOLDX = 16;
|
|
|
|
protected const S_HOLDA = 32;
|
|
|
|
protected const S_ADDTRY = 64;
|
|
|
|
protected const S_ANYHOLD = (self::S_HOLDR|self::S_HOLDX|self::S_HOLDA);
|
|
|
|
|
|
|
|
// File transfer status
|
|
|
|
|
2024-11-08 12:13:04 +00:00
|
|
|
public const FOP_OK = 0;
|
|
|
|
public const FOP_CONT = 1;
|
|
|
|
public const FOP_SKIP = 2;
|
|
|
|
public const FOP_ERROR = 3;
|
2023-07-02 13:40:08 +00:00
|
|
|
public const FOP_SUSPEND = 4;
|
|
|
|
public const FOP_GOT = 5;
|
|
|
|
|
|
|
|
public const TCP_SPEED = 115200;
|
2021-04-01 10:59:15 +00:00
|
|
|
|
|
|
|
protected SocketClient $client; /* Our socket details */
|
2024-11-02 12:30:42 +00:00
|
|
|
protected Setup $setup; /* Our setup */
|
2021-04-01 10:59:15 +00:00
|
|
|
protected Node $node; /* The node we are communicating with */
|
2023-07-02 13:40:08 +00:00
|
|
|
/** The list of files we are sending */
|
|
|
|
protected Send $send;
|
|
|
|
/** The list of files we are receiving */
|
|
|
|
protected Receive $recv;
|
|
|
|
|
|
|
|
/** @var int The active options for a session */
|
|
|
|
private int $options;
|
|
|
|
/** @var int Tracks the session state */
|
|
|
|
private int $session;
|
|
|
|
/** @var array Our negotiated capability for a protocol session */
|
|
|
|
protected array $capability; // @todo make private
|
|
|
|
/** @var bool Are we originating a connection */
|
|
|
|
protected bool $originate;
|
|
|
|
|
2024-11-08 12:13:04 +00:00
|
|
|
/** @var bool Is the application down for maintenance */
|
2024-06-07 08:07:34 +00:00
|
|
|
protected bool $down = FALSE;
|
|
|
|
|
2024-11-08 12:13:04 +00:00
|
|
|
/** @var int Our mailer ID for logging purposes */
|
|
|
|
private int $mailer_id;
|
|
|
|
|
2023-07-02 13:40:08 +00:00
|
|
|
private array $comms;
|
2021-04-01 10:59:15 +00:00
|
|
|
|
2023-11-22 10:04:58 +00:00
|
|
|
protected bool $force_queue = FALSE;
|
|
|
|
|
2021-04-01 10:59:15 +00:00
|
|
|
abstract protected function protocol_init(): int;
|
2021-08-15 14:41:43 +00:00
|
|
|
|
2023-11-22 10:04:58 +00:00
|
|
|
abstract protected function protocol_session(bool $force_queue=FALSE): int;
|
2021-04-01 10:59:15 +00:00
|
|
|
|
2024-11-08 21:58:09 +00:00
|
|
|
/**
|
|
|
|
* @param Setup $setup
|
|
|
|
* @throws \Exception
|
|
|
|
*/
|
|
|
|
public function __construct(Setup $setup)
|
2021-06-24 10:16:37 +00:00
|
|
|
{
|
2024-11-08 21:58:09 +00:00
|
|
|
$this->setup = $setup;
|
2024-11-08 12:13:04 +00:00
|
|
|
|
|
|
|
// Some initialisation details
|
|
|
|
switch (get_class($this)) {
|
|
|
|
case Binkp::class:
|
|
|
|
$this->mailer_id = Mailer::where('name','BINKP')->sole()->id;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DNS::class:
|
|
|
|
case Zmodem::class:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case EMSI::class:
|
|
|
|
$this->mailer_id = Mailer::where('name','EMSI')->sole()->id;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
throw new \Exception('not handled'.get_class($this));
|
|
|
|
}
|
2021-06-24 10:16:37 +00:00
|
|
|
}
|
|
|
|
|
2021-04-01 10:59:15 +00:00
|
|
|
/**
|
2023-06-27 07:39:11 +00:00
|
|
|
* @throws \Exception
|
2021-04-01 10:59:15 +00:00
|
|
|
*/
|
|
|
|
public function __get($key)
|
|
|
|
{
|
|
|
|
switch ($key) {
|
|
|
|
case 'ls_SkipGuard': /* double-skip protection on/off */
|
|
|
|
case 'rxOptions': /* Options from ZRINIT header */
|
|
|
|
return $this->comms[$key] ?? 0;
|
|
|
|
|
|
|
|
case 'ls_rxAttnStr':
|
|
|
|
return $this->comms[$key] ?? '';
|
|
|
|
|
|
|
|
default:
|
2023-06-27 07:39:11 +00:00
|
|
|
throw new \Exception('Unknown key: '.$key);
|
2021-04-01 10:59:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2023-06-27 07:39:11 +00:00
|
|
|
* @throws \Exception
|
2021-04-01 10:59:15 +00:00
|
|
|
*/
|
|
|
|
public function __set($key,$value)
|
|
|
|
{
|
|
|
|
switch ($key) {
|
|
|
|
case 'ls_rxAttnStr':
|
|
|
|
case 'ls_SkipGuard':
|
|
|
|
case 'rxOptions':
|
|
|
|
$this->comms[$key] = $value;
|
|
|
|
break;
|
|
|
|
|
2023-12-10 09:44:15 +00:00
|
|
|
case 'client':
|
|
|
|
$this->{$key} = $value;
|
|
|
|
break;
|
|
|
|
|
2021-04-01 10:59:15 +00:00
|
|
|
default:
|
2023-06-27 07:39:11 +00:00
|
|
|
throw new \Exception('Unknown key: '.$key);
|
2021-04-01 10:59:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-07-02 13:40:08 +00:00
|
|
|
/* Capabilities are what we negotitate with the remote and are valid for the session */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Clear a capability bit
|
|
|
|
*
|
|
|
|
* @param int $cap (F_*)
|
|
|
|
* @param int $val (O_*)
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function capClear(int $cap,int $val): void
|
|
|
|
{
|
|
|
|
if (! array_key_exists($cap,$this->capability))
|
|
|
|
$this->capability[$cap] = 0;
|
|
|
|
|
|
|
|
$this->capability[$cap] &= ~$val;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get a session bit (SE_*)
|
|
|
|
*
|
|
|
|
* @param int $cap (F_*)
|
|
|
|
* @param int $val (O_*)
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
protected function capGet(int $cap,int $val): bool
|
|
|
|
{
|
|
|
|
if (! array_key_exists($cap,$this->capability))
|
|
|
|
$this->capability[$cap] = 0;
|
|
|
|
|
|
|
|
if ($val === self::O_WE)
|
|
|
|
return $this->capGet($cap,self::O_WANT) && $this->capGet($cap,self::O_THEY);
|
|
|
|
|
|
|
|
return $this->capability[$cap] & $val;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set a session bit (SE_*)
|
|
|
|
*
|
|
|
|
* @param int $cap (F_*)
|
|
|
|
* @param int $val (O_*)
|
|
|
|
*/
|
|
|
|
protected function capSet(int $cap,int $val): void
|
|
|
|
{
|
|
|
|
if (! array_key_exists($cap,$this->capability) || $val === 0)
|
|
|
|
$this->capability[$cap] = 0;
|
|
|
|
|
|
|
|
$this->capability[$cap] |= $val;
|
|
|
|
}
|
|
|
|
|
2021-04-01 10:59:15 +00:00
|
|
|
/**
|
|
|
|
* We got an error, close anything we are have open
|
|
|
|
*
|
2023-06-27 07:39:11 +00:00
|
|
|
* @throws \Exception
|
2021-04-01 10:59:15 +00:00
|
|
|
*/
|
2021-08-15 14:41:43 +00:00
|
|
|
protected function error_close(): void
|
|
|
|
{
|
|
|
|
if ($this->send->fd)
|
2023-09-05 10:07:27 +00:00
|
|
|
$this->send->close(FALSE,$this->node);
|
2021-04-01 10:59:15 +00:00
|
|
|
|
2021-08-15 14:41:43 +00:00
|
|
|
if ($this->recv->fd)
|
|
|
|
$this->recv->close();
|
|
|
|
}
|
2021-04-01 10:59:15 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Incoming Protocol session
|
|
|
|
*
|
|
|
|
* @param SocketClient $client
|
2024-11-08 21:58:09 +00:00
|
|
|
* @return int
|
2021-04-01 10:59:15 +00:00
|
|
|
* @throws SocketException
|
|
|
|
*/
|
2024-11-08 21:58:09 +00:00
|
|
|
public function onConnect(SocketClient $client): int
|
2021-04-01 10:59:15 +00:00
|
|
|
{
|
|
|
|
$pid = pcntl_fork();
|
|
|
|
|
2023-06-27 07:39:11 +00:00
|
|
|
if ($pid === -1)
|
2021-04-01 10:59:15 +00:00
|
|
|
throw new SocketException(SocketException::CANT_ACCEPT,'Could not fork process');
|
|
|
|
|
2024-11-08 21:58:09 +00:00
|
|
|
// If our parent returns a PID, we've forked
|
2023-07-08 08:00:23 +00:00
|
|
|
if ($pid)
|
2024-09-09 13:34:42 +00:00
|
|
|
Log::info(sprintf('%s:+ New connection from [%s], thread [%d] created',self::LOGKEY,$client->address_remote,$pid));
|
2023-07-08 08:00:23 +00:00
|
|
|
|
2024-11-08 21:58:09 +00:00
|
|
|
// This is the new thread
|
|
|
|
else {
|
|
|
|
Log::withContext(['pid'=>getmypid()]);
|
|
|
|
|
|
|
|
$this->session($client,(new Address));
|
|
|
|
}
|
|
|
|
|
2021-04-01 10:59:15 +00:00
|
|
|
return $pid;
|
|
|
|
}
|
|
|
|
|
2023-07-02 13:40:08 +00:00
|
|
|
/* O_* determine what features processing is availabile */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Clear an option bit (O_*)
|
|
|
|
*
|
|
|
|
* @param int $key
|
|
|
|
* @return void
|
|
|
|
*/
|
2021-04-01 10:59:15 +00:00
|
|
|
protected function optionClear(int $key): void
|
|
|
|
{
|
|
|
|
$this->options &= ~$key;
|
|
|
|
}
|
|
|
|
|
2023-07-02 13:40:08 +00:00
|
|
|
/**
|
|
|
|
* Get an option bit (O_*)
|
|
|
|
*
|
|
|
|
* @param int $key
|
|
|
|
* @return int
|
|
|
|
*/
|
2021-04-01 10:59:15 +00:00
|
|
|
protected function optionGet(int $key): int
|
|
|
|
{
|
|
|
|
return ($this->options & $key);
|
|
|
|
}
|
|
|
|
|
2023-07-02 13:40:08 +00:00
|
|
|
/**
|
|
|
|
* Set an option bit (O_*)
|
|
|
|
*
|
|
|
|
* @param int $key
|
|
|
|
* @return void
|
|
|
|
*/
|
2021-04-01 10:59:15 +00:00
|
|
|
protected function optionSet(int $key): void
|
|
|
|
{
|
|
|
|
$this->options |= $key;
|
|
|
|
}
|
|
|
|
|
2021-08-15 14:41:43 +00:00
|
|
|
/**
|
|
|
|
* Our addresses to send to the remote
|
2023-07-08 08:00:23 +00:00
|
|
|
*
|
2021-08-15 14:41:43 +00:00
|
|
|
* @return Collection
|
2024-11-08 12:13:04 +00:00
|
|
|
* @throws \Exception
|
2021-08-15 14:41:43 +00:00
|
|
|
*/
|
|
|
|
protected function our_addresses(): Collection
|
|
|
|
{
|
2023-07-08 08:00:23 +00:00
|
|
|
if ($this->setup->optionGet(Setup::O_HIDEAKA,'options_options')) {
|
2021-08-15 14:41:43 +00:00
|
|
|
$addresses = collect();
|
|
|
|
|
2021-10-18 12:08:08 +00:00
|
|
|
foreach (($this->originate ? $this->node->aka_remote_authed : $this->node->aka_remote) as $ao)
|
2023-12-18 04:13:16 +00:00
|
|
|
$addresses = $addresses->merge(our_address($ao->zone->domain));
|
2021-08-15 14:41:43 +00:00
|
|
|
|
|
|
|
$addresses = $addresses->unique();
|
|
|
|
|
2023-07-02 13:40:08 +00:00
|
|
|
Log::debug(sprintf('%s:- Presenting limited AKAs [%s]',self::LOGKEY,$addresses->pluck('ftn')->join(',')));
|
2021-08-15 14:41:43 +00:00
|
|
|
|
|
|
|
} else {
|
2024-11-02 12:30:42 +00:00
|
|
|
$addresses = our_address();
|
2021-08-15 14:41:43 +00:00
|
|
|
|
2023-07-02 13:40:08 +00:00
|
|
|
Log::debug(sprintf('%s:- Presenting ALL our AKAs [%s]',self::LOGKEY,$addresses->pluck('ftn')->join(',')));
|
2021-08-15 14:41:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return $addresses;
|
|
|
|
}
|
|
|
|
|
2021-04-01 10:59:15 +00:00
|
|
|
/**
|
2024-11-08 21:58:09 +00:00
|
|
|
* Setup a session with a remote client
|
2021-04-01 10:59:15 +00:00
|
|
|
*
|
2024-11-08 21:58:09 +00:00
|
|
|
* @param SocketClient $client Socket details of session
|
|
|
|
* @param Address|null $o If we have an address, we originated a session to this Address
|
2023-07-07 13:59:04 +00:00
|
|
|
* @return int
|
2023-06-27 07:39:11 +00:00
|
|
|
* @throws \Exception
|
2021-04-01 10:59:15 +00:00
|
|
|
*/
|
2024-11-08 12:13:04 +00:00
|
|
|
public function session(SocketClient $client,Address $o=NULL): int
|
2021-04-01 10:59:15 +00:00
|
|
|
{
|
2021-07-23 14:54:39 +00:00
|
|
|
if ($o->exists)
|
2021-10-18 12:08:08 +00:00
|
|
|
Log::withContext(['ftn'=>$o->ftn]);
|
2021-07-23 14:54:39 +00:00
|
|
|
|
2021-04-01 10:59:15 +00:00
|
|
|
// This sessions options
|
|
|
|
$this->options = 0;
|
|
|
|
$this->session = 0;
|
2023-07-02 13:40:08 +00:00
|
|
|
$this->capability = [];
|
2021-04-01 10:59:15 +00:00
|
|
|
|
|
|
|
// Our files that we are sending/receive
|
|
|
|
$this->send = new Send;
|
|
|
|
$this->recv = new Receive;
|
|
|
|
|
|
|
|
if ($o) {
|
|
|
|
// The node we are communicating with
|
|
|
|
$this->node = new Node;
|
|
|
|
|
|
|
|
$this->originate = $o->exists;
|
|
|
|
|
|
|
|
// If we are connecting to a node
|
|
|
|
if ($o->exists) {
|
2023-07-02 13:40:08 +00:00
|
|
|
Log::debug(sprintf('%s:+ Originating a connection to [%s]',self::LOGKEY,$o->ftn));
|
2021-04-01 10:59:15 +00:00
|
|
|
$this->node->originate($o);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
$this->optionSet(self::O_INB);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// We are an IP node
|
|
|
|
$this->optionSet(self::O_TCP);
|
2023-12-10 09:44:15 +00:00
|
|
|
$this->client = $client;
|
2024-06-07 08:07:34 +00:00
|
|
|
// @todo This appears to be a bug in laravel? Need to call app()->isDownForMaintenance() twice?
|
|
|
|
app()->isDownForMaintenance();
|
|
|
|
$this->down = app()->isDownForMaintenance();
|
2021-04-01 10:59:15 +00:00
|
|
|
|
2024-11-08 12:13:04 +00:00
|
|
|
switch (get_class($this)) {
|
|
|
|
case EMSI::class:
|
2023-12-10 08:07:53 +00:00
|
|
|
Log::debug(sprintf('%s:- Starting EMSI',self::LOGKEY));
|
2021-04-01 10:59:15 +00:00
|
|
|
|
|
|
|
$rc = $this->protocol_init();
|
|
|
|
if ($rc < 0) {
|
2023-02-11 12:06:13 +00:00
|
|
|
Log::error(sprintf('%s:! Unable to start EMSI [%d]',self::LOGKEY,$rc));
|
2021-04-01 10:59:15 +00:00
|
|
|
|
2023-07-07 13:59:04 +00:00
|
|
|
return self::S_FAILURE;
|
2021-04-01 10:59:15 +00:00
|
|
|
}
|
|
|
|
|
2023-11-22 10:04:58 +00:00
|
|
|
$rc = $this->protocol_session($this->originate);
|
2021-04-01 10:59:15 +00:00
|
|
|
|
|
|
|
break;
|
|
|
|
|
2024-11-08 12:13:04 +00:00
|
|
|
case Binkp::class:
|
2023-07-02 13:40:08 +00:00
|
|
|
Log::debug(sprintf('%s:- Starting BINKP',self::LOGKEY));
|
2023-12-10 08:07:53 +00:00
|
|
|
|
2023-11-22 10:04:58 +00:00
|
|
|
$rc = $this->protocol_session($this->originate);
|
2021-04-01 10:59:15 +00:00
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2024-11-08 12:13:04 +00:00
|
|
|
Log::error(sprintf('%s:! Unsupported session type [%s]',self::LOGKEY,get_class($this)));
|
2021-04-01 10:59:15 +00:00
|
|
|
|
2023-07-07 13:59:04 +00:00
|
|
|
return self::S_FAILURE;
|
2021-04-01 10:59:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// @todo These flags determine when we connect to the remote.
|
|
|
|
// If the remote indicated that they dont support file requests (NRQ) or temporarily hold them (HRQ)
|
2023-07-05 23:20:33 +00:00
|
|
|
if (($this->node->optionGet(self::O_NRQ) && (! $this->setup->optionGet(EMSI::F_IGNORE_NRQ,'emsi_options'))) || $this->node->optionGet(self::O_HRQ))
|
2021-04-01 10:59:15 +00:00
|
|
|
$rc |= self::S_HOLDR;
|
|
|
|
|
|
|
|
if ($this->optionGet(self::O_HXT))
|
|
|
|
$rc |= self::S_HOLDX;
|
|
|
|
|
|
|
|
if ($this->optionGet(self::O_HAT))
|
|
|
|
$rc |= self::S_HOLDA;
|
|
|
|
|
2023-07-02 13:40:08 +00:00
|
|
|
Log::info(sprintf('%s:= Total: %s - %d:%02d:%02d online, (%d) %lu%s sent, (%d) %lu%s received - %s',
|
2021-08-15 14:41:43 +00:00
|
|
|
self::LOGKEY,
|
2021-09-11 01:47:26 +00:00
|
|
|
$this->node->address ? $this->node->address->ftn : 'Unknown',
|
2021-04-01 10:59:15 +00:00
|
|
|
$this->node->session_time/3600,
|
|
|
|
$this->node->session_time%3600/60,
|
|
|
|
$this->node->session_time%60,
|
|
|
|
$this->send->total_sent,$this->send->total_sent_bytes,'b',
|
|
|
|
$this->recv->total_recv,$this->recv->total_recv_bytes,'b',
|
2023-06-27 07:39:11 +00:00
|
|
|
(($rc & self::S_MASK) === self::S_OK) ? 'Successful' : 'Failed',
|
2021-04-01 10:59:15 +00:00
|
|
|
));
|
|
|
|
|
2022-12-01 12:51:43 +00:00
|
|
|
// Add unknown FTNs to the DB
|
2023-09-15 12:57:32 +00:00
|
|
|
$so = ($this->node->aka_remote_authed->count())
|
|
|
|
? $this->node->aka_remote_authed->first()->system
|
|
|
|
: System::createUnknownSystem();
|
2022-12-01 12:51:43 +00:00
|
|
|
|
|
|
|
if ($so && $so->exists) {
|
2023-09-15 12:57:32 +00:00
|
|
|
foreach ($this->node->aka_other as $aka)
|
2024-06-26 23:51:38 +00:00
|
|
|
// @todo For disabled zones, we shouldnt refuse to record the address
|
2024-11-08 12:13:04 +00:00
|
|
|
// @todo If the system hasnt presented an address for a configured period (eg: 30 days) assume it no longer carries it
|
2024-06-26 23:51:38 +00:00
|
|
|
if ((! Address::findFTN($aka)) && ($oo=Address::createFTN($aka,$so))) {
|
2024-05-27 08:04:04 +00:00
|
|
|
$oo->validated = TRUE;
|
|
|
|
$oo->save();
|
2024-05-25 12:25:57 +00:00
|
|
|
}
|
2022-12-01 12:51:43 +00:00
|
|
|
|
2022-12-02 11:54:02 +00:00
|
|
|
// Log session in DB
|
|
|
|
$slo = new SystemLog;
|
|
|
|
$slo->items_sent = $this->send->total_sent;
|
|
|
|
$slo->items_sent_size = $this->send->total_sent_bytes;
|
|
|
|
$slo->items_recv = $this->recv->total_recv;
|
|
|
|
$slo->items_recv_size = $this->recv->total_recv_bytes;
|
2024-11-08 12:13:04 +00:00
|
|
|
$slo->mailer_id = $this->mailer_id;
|
2022-12-02 11:54:02 +00:00
|
|
|
$slo->sessiontime = $this->node->session_time;
|
|
|
|
$slo->result = ($rc & self::S_MASK);
|
2023-07-26 09:44:07 +00:00
|
|
|
$slo->originate = $this->originate;
|
2022-12-02 11:54:02 +00:00
|
|
|
|
|
|
|
$so->logs()->save($slo);
|
2023-11-22 07:15:06 +00:00
|
|
|
|
|
|
|
// If we are autohold, then remove that
|
|
|
|
if ($so->autohold) {
|
|
|
|
$so->autohold = FALSE;
|
|
|
|
$so->save();
|
|
|
|
}
|
2022-12-02 11:54:02 +00:00
|
|
|
}
|
2021-04-01 10:59:15 +00:00
|
|
|
|
2023-07-07 13:59:04 +00:00
|
|
|
return $rc;
|
2021-04-01 10:59:15 +00:00
|
|
|
}
|
|
|
|
|
2023-07-02 13:40:08 +00:00
|
|
|
/* SE_* flags determine our session processing status, at any point in time */
|
|
|
|
|
2021-04-01 10:59:15 +00:00
|
|
|
/**
|
2023-07-02 13:40:08 +00:00
|
|
|
* Clear a session bit (SE_*)
|
2021-04-01 10:59:15 +00:00
|
|
|
*
|
|
|
|
* @param int $key
|
|
|
|
*/
|
|
|
|
protected function sessionClear(int $key): void
|
|
|
|
{
|
|
|
|
$this->session &= ~$key;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2023-07-02 13:40:08 +00:00
|
|
|
* Get a session bit (SE_*)
|
|
|
|
*
|
2021-04-01 10:59:15 +00:00
|
|
|
* @param int $key
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
protected function sessionGet(int $key): bool
|
|
|
|
{
|
|
|
|
return ($this->session & $key);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2023-07-02 13:40:08 +00:00
|
|
|
* Set a session bit (SE_*)
|
2021-04-01 10:59:15 +00:00
|
|
|
*
|
|
|
|
* @param int $key
|
|
|
|
*/
|
|
|
|
protected function sessionSet(int $key): void
|
|
|
|
{
|
|
|
|
$this->session |= $key;
|
|
|
|
}
|
|
|
|
}
|