Changed to using new Address Model, Implemented Setup, Some minor CSS changes

This commit is contained in:
Deon George
2021-06-24 20:16:37 +10:00
parent ec6594b701
commit d1ca78d372
33 changed files with 766 additions and 172 deletions

View File

@@ -3,12 +3,11 @@
namespace App\Classes;
use Carbon\Carbon;
use Exception;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Log;
use App\Models\Node as NodeModel;
use App\Models\Address;
/**
* Object representing the node we are communicating with
@@ -64,7 +63,7 @@ class Node
// The nodes password
case 'password':
return ($this->ftns_authed->count() && $x=$this->ftns_authed->first()->sespass) ? $x : '-';
return ($this->ftns_authed->count() && ($x=$this->ftns_authed->first()->session('sespass'))) ? $x : '-';
// Return how long our session has been connected
case 'session_time':
@@ -102,8 +101,8 @@ class Node
{
switch ($key) {
case 'ftn':
if (! is_object($value) OR ! $value instanceof NodeModel)
throw new Exception('Not a node object: '.(is_object($value) ? get_class($value) : serialize($value)));
if (! is_object($value) OR ! $value instanceof Address)
throw new Exception('Not an Address object: '.(is_object($value) ? get_class($value) : serialize($value)));
// Ignore any duplicate FTNs that we get
if ($this->ftns->search(function($item) use ($value) { return $item->id === $value->id; }) !== FALSE) {
@@ -154,11 +153,11 @@ class Node
throw new Exception('Already authed');
foreach ($this->ftns as $o) {
if (! $o->sespass)
if (! $o->session('sespass'))
continue;
// If we have challenge, then we are doing MD5
$exp_pwd = $challenge ? $this->md5_challenge($o->sespass,$challenge) : $o->sespass;
$exp_pwd = $challenge ? $this->md5_challenge($o->session('sespass'),$challenge) : $o->session('sespass');
if ($exp_pwd === $password)
$this->ftns_authed->push($o);
@@ -208,11 +207,10 @@ class Node
* When we originate a call to a node, we need to store the node we are connecting with in the ftns_authed, so
* authentication proceeds when we send our M_pwd
*
* @param NodeModel $o
* @param Address $o
*/
public function originate(NodeModel $o): void
public function originate(Address $o): void
{
$this->ftns->push($o);
$this->ftns_authed->push($o);
}

View File

@@ -8,8 +8,7 @@ use Illuminate\Support\Facades\Log;
use App\Classes\File\{Receive,Send};
use App\Classes\Sock\SocketClient;
use App\Classes\Sock\SocketException;
use App\Models\Node as NodeModel;
use App\Models\Setup;
use App\Models\{Address,Setup};
abstract class Protocol
{
@@ -79,7 +78,7 @@ abstract class Protocol
protected const MO_CHAT = 4;
protected SocketClient $client; /* Our socket details */
protected Setup $setup; /* Our setup */
protected ?Setup $setup; /* Our setup */
protected Node $node; /* The node we are communicating with */
protected Send $send; /* The list of files we are sending */
protected Receive $recv; /* The list of files we are receiving */
@@ -92,6 +91,14 @@ abstract class Protocol
abstract protected function protocol_init(): int;
abstract protected function protocol_session(): int;
public function __construct(Setup $o=NULL)
{
if ($o && ! $o->system->addresses->count())
throw new Exception('We dont have any FTN addresses assigned');
$this->setup = $o;
}
/**
* @throws Exception
*/
@@ -181,11 +188,11 @@ abstract class Protocol
*
* @param int $type
* @param SocketClient $client
* @param NodeModel|null $o
* @param Address|null $o
* @return int
* @throws Exception
*/
public function session(int $type,SocketClient $client,NodeModel $o=NULL): int
public function session(int $type,SocketClient $client,Address $o=NULL): int
{
Log::debug(sprintf('%s: + Start [%d]',__METHOD__,$type));
@@ -198,9 +205,6 @@ abstract class Protocol
$this->recv = new Receive;
if ($o) {
// Our configuration and initialise values
$this->setup = Setup::findOrFail(self::setup);
// The node we are communicating with
$this->node = new Node;

View File

@@ -12,7 +12,7 @@ use League\Flysystem\UnreadableFileException;
use App\Classes\Protocol as BaseProtocol;
use App\Classes\Sock\SocketClient;
use App\Classes\Sock\SocketException;
use App\Models\Node;
use App\Models\Address;
final class Binkd extends BaseProtocol
{
@@ -100,7 +100,7 @@ final class Binkd extends BaseProtocol
{
// If our parent returns a PID, we've forked
if (! parent::onConnect($client)) {
$this->session(self::SESSION_BINKP,$client,(new Node));
$this->session(self::SESSION_BINKP,$client,(new Address));
$this->client->close();
Log::info(sprintf('%s: = End - Connection closed [%s]',__METHOD__,$client->getAddress()));
}
@@ -143,7 +143,7 @@ final class Binkd extends BaseProtocol
// If we are originating, we'll show the remote our address in the same network
// @todo Implement hiding our AKAs not in this network.
if ($this->originate)
$this->msgs(self::BPM_ADR,join(' ',$this->setup->nodes->pluck('ftn')->toArray()));
$this->msgs(self::BPM_ADR,join(' ',$this->setup->system->addresses->pluck('ftn')->toArray()));
}
/**
@@ -291,6 +291,7 @@ final class Binkd extends BaseProtocol
// @todo We maybe should count these and abort if there are too many?
if ($this->DEBUG)
Log::debug(sprintf('%s: - Socket EAGAIN',__METHOD__));
return 1;
}
@@ -304,6 +305,7 @@ final class Binkd extends BaseProtocol
// @todo Check that this is correct.
Log::debug(sprintf('%s: - Was the socket closed by the remote?',__METHOD__));
$this->error = -2;
return 0;
}
@@ -592,7 +594,7 @@ final class Binkd extends BaseProtocol
Log::debug(sprintf('%s: - Parsing AKA [%s]',__METHOD__,$rem_aka));
try {
if (! ($o = Node::findFTN($rem_aka))) {
if (! ($o = Address::findFTN($rem_aka))) {
Log::debug(sprintf('%s: ? AKA is UNKNOWN [%s]',__METHOD__,$rem_aka));
continue;
@@ -608,10 +610,10 @@ final class Binkd extends BaseProtocol
}
// Check if the remote has our AKA
if ($this->setup->nodes->pluck('ftn')->search($o->ftn) !== FALSE) {
Log::error(sprintf('%s: ! AKA is OURS [%s]',__METHOD__,$o->ftn));
if ($this->setup->system->addresses->pluck('ftn')->search($rem_aka) !== FALSE) {
Log::error(sprintf('%s: ! AKA is OURS [%s]',__METHOD__,$rem_aka));
$this->msgs(self::BPM_ERR,sprintf('Sorry that is my AKA [%s]',$o->ftn));
$this->msgs(self::BPM_ERR,sprintf('Sorry that is my AKA [%s]',$rem_aka));
$this->rc = self::S_FAILURE;
return 0;
@@ -671,7 +673,7 @@ final class Binkd extends BaseProtocol
// If we are not the originator, we'll show our addresses in common.
// @todo make this an option to hideAKAs or not
if (! $this->originate)
$this->msgs(self::BPM_ADR,join(' ',$this->setup->nodes->pluck('ftn')->toArray()));
$this->msgs(self::BPM_ADR,join(' ',$this->setup->system->addresses->pluck('ftn')->toArray()));
return 1;
}

View File

@@ -9,7 +9,7 @@ use Illuminate\Support\Facades\Log;
use App\Classes\Protocol as BaseProtocol;
use App\Classes\Sock\SocketClient;
use App\Classes\Sock\SocketException;
use App\Models\Node;
use App\Models\Address;
use App\Interfaces\CRC as CRCInterface;
use App\Interfaces\Zmodem as ZmodemInterface;
use App\Traits\CRC as CRCTrait;
@@ -80,7 +80,7 @@ final class EMSI extends BaseProtocol implements CRCInterface,ZmodemInterface
{
// If our parent returns a PID, we've forked
if (! parent::onConnect($client)) {
$this->session(self::SESSION_AUTO,$client,(new Node));
$this->session(self::SESSION_AUTO,$client,(new Address));
$this->client->close();
Log::info(sprintf('%s: = End - Connection closed [%s]',__METHOD__,$client->getAddress()));
}
@@ -183,7 +183,7 @@ final class EMSI extends BaseProtocol implements CRCInterface,ZmodemInterface
// Site address, password and compatibility
// @todo Only show the AKAs that is relevant to the node we are connecting to
$makedata .= sprintf('{EMSI}{%s}{%s}{%s}{%s}',
join(' ',$this->setup->nodes->pluck('ftn')->toArray()),
join(' ',$this->setup->system->addresses->pluck('ftn')->toArray()),
$this->node->password == '-' ? '' : $this->node->password,
join(',',$link_codes),
join(',',$compat_codes),
@@ -295,7 +295,7 @@ final class EMSI extends BaseProtocol implements CRCInterface,ZmodemInterface
Log::debug(sprintf('%s: - Parsing AKA [%s]',__METHOD__,$rem_aka));
try {
if (! ($o = Node::findFTN($rem_aka))) {
if (! ($o = Address::findFTN($rem_aka))) {
Log::debug(sprintf('%s: ? AKA is UNKNOWN [%s]',__METHOD__,$rem_aka));
continue;
}
@@ -307,7 +307,7 @@ final class EMSI extends BaseProtocol implements CRCInterface,ZmodemInterface
}
// Check if the remote has our AKA
if ($this->setup->nodes->pluck('ftn')->search($o->ftn) !== FALSE) {
if ($this->setup->system->addresses->pluck('ftn')->search($o->ftn) !== FALSE) {
Log::error(sprintf('%s: ! AKA is OURS [%s]',__METHOD__,$o->ftn));
continue;
@@ -338,9 +338,9 @@ final class EMSI extends BaseProtocol implements CRCInterface,ZmodemInterface
}
if (! $c) {
Log::info(sprintf('%s: - Remote has password [%s] on us',__METHOD__,$p));
Log::info(sprintf('%s: - Remote has password [%s] on us, and we expect [%s]',__METHOD__,$p,$this->node->password));
if ($p)
if ($p || $this->node->password)
$this->node->optionSet(self::O_BAD);
} else {
@@ -861,7 +861,7 @@ final class EMSI extends BaseProtocol implements CRCInterface,ZmodemInterface
if ($gotreq++)
return self::OK;
$this->client->buffer_add(self::EMSI_INQ);
$this->client->buffer_add(self::EMSI_INQ.self::CR);
$this->client->buffer_flush(5);
} elseif ($p && strstr($p,self::EMSI_BEG) && strstr($p,self::EMSI_ARGUS1)) {