Auto create Domains/Zones as systems present their AKAs to us

This commit is contained in:
Deon George
2022-12-01 23:51:43 +11:00
parent 55a2a67b8d
commit d5d4a0d781
6 changed files with 112 additions and 9 deletions

View File

@@ -35,6 +35,7 @@ class Node
private Collection $ftns; // The FTNs of the remote system
private Collection $ftns_authed; // The FTNs we have validated
private Collection $ftns_other; // Other FTN addresses presented
private bool $authed; // Have we authenticated the remote.
private int $options; // This nodes capabilities/options
@@ -46,6 +47,7 @@ class Node
$this->start_time = Carbon::now();
$this->ftns = collect();
$this->ftns_authed = collect();
$this->ftns_other = collect();
}
/**
@@ -72,6 +74,10 @@ class Node
case 'aka_authed':
return $this->authed;
// FTNs that we dont know about
case 'aka_other':
return $this->ftns_other;
// The nodes password
case 'password':
return ($this->ftns->count() && ($x=$this->ftns->first()->session('sespass'))) ? $x : '-';
@@ -125,6 +131,17 @@ class Node
break;
case 'ftn_other':
// Ignore any duplicate FTNs that we get
if ($this->ftns_other->search($value) !== FALSE) {
Log::debug(sprintf('%s: - Ignoring Duplicate FTN [%s]',__METHOD__,$value->ftn));
break;
}
$this->ftns_other->push($value);
break;
case 'system':
case 'sysop':
case 'location':
@@ -159,26 +176,40 @@ class Node
public function auth(string $password,string $challenge=''): int
{
Log::debug(sprintf('%s:+ auth [%s]',self::LOGKEY,$password));
$so = NULL;
// Make sure we havent been here already
if ($this->ftns_authed->count())
throw new Exception('Already authed');
foreach ($this->ftns as $o) {
if (! $o->session('sespass'))
if (! $sespass=$o->session('sespass'))
continue;
// If we have challenge, then we are doing MD5
$exp_pwd = $challenge ? $this->md5_challenge($o->session('sespass'),$challenge) : $o->session('sespass');
$exp_pwd = $challenge ? $this->md5_challenge($sespass,$challenge) : $sespass;
if ($exp_pwd === $password) {
$o->system->last_session = Carbon::now();
$o->system->save();
if (! $so)
$so = $o->system;
// Make sure we are the same system
if ($so->id !== $o->system->id) {
Log::alert(sprintf('%s:! AKA [%s] is from a different system?',self::LOGKEY,$o->ftn),['so'=>$so->name]);
continue;
}
$this->ftns_authed->push($o);
$this->authed = TRUE;
}
}
if ($this->authed) {
$o->system->last_session = Carbon::now();
$o->system->save();
}
Log::debug(sprintf('%s:= auth, we authed [%d] addresses',self::LOGKEY,$this->ftns_authed->count()));
return $this->ftns_authed->count();
}

View File

@@ -9,7 +9,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\{Address,Setup};
use App\Models\{Address,Setup,System};
abstract class Protocol
{
@@ -313,6 +313,19 @@ abstract class Protocol
(($rc & self::S_MASK) == self::S_OK) ? 'Successful' : 'Failed',
));
// Add unknown FTNs to the DB
if ($this->node->aka_remote_authed->count()) {
$so = $this->node->aka_remote_authed->first()->system;
} else {
$so = System::where('name','Discovered System')->single();
}
if ($so && $so->exists) {
foreach ($this->node->aka_other as $aka) {
Address::findFTN($aka,TRUE,$so);
}
}
// @todo Log to history log in the DB.
//if ($this->node->start_time && $this->setup->cfg('CFG_HISTORY')) {}

View File

@@ -632,6 +632,7 @@ final class Binkp extends BaseProtocol
if (! ($o = Address::findFTN($rem_aka))) {
Log::debug(sprintf('%s: ? AKA is UNKNOWN [%s]',self::LOGKEY,$rem_aka));
$this->node->ftn_other = $rem_aka;
continue;
}

View File

@@ -303,6 +303,8 @@ final class EMSI extends BaseProtocol implements CRCInterface,ZmodemInterface
try {
if (! ($o = Address::findFTN($rem_aka))) {
Log::debug(sprintf('%s: ? AKA is UNKNOWN [%s]',self::LOGKEY,$rem_aka));
$this->node->ftn_other = $rem_aka;
continue;
}