Changed to using new Address Model, Implemented Setup, Some minor CSS changes
This commit is contained in:
@@ -2,12 +2,16 @@
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Exception;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
use App\Http\Controllers\DomainController;
|
||||
use App\Traits\ScopeActive;
|
||||
|
||||
class Address extends Model
|
||||
{
|
||||
use ScopeActive;
|
||||
|
||||
/* RELATIONS */
|
||||
|
||||
public function system()
|
||||
@@ -49,4 +53,65 @@ class Address extends Model
|
||||
return '?';
|
||||
}
|
||||
}
|
||||
|
||||
/* GENERAL METHODS */
|
||||
|
||||
/**
|
||||
* Find a record in the DB for a node string, eg: 10:1/1.0
|
||||
*
|
||||
* @param string $ftn
|
||||
* @return Node|null
|
||||
* @throws Exception
|
||||
*/
|
||||
public static function findFTN(string $ftn): ?self
|
||||
{
|
||||
$matches = [];
|
||||
|
||||
// http://ftsc.org/docs/frl-1028.002
|
||||
if (! preg_match('#^([0-9]+):([0-9]+)/([0-9]+)(.([0-9]+))?(@([a-z0-9\-_~]{0,8}))?$#',strtolower($ftn),$matches))
|
||||
throw new Exception('Invalid FTN: '.$ftn);
|
||||
|
||||
// Check our numbers are correct.
|
||||
foreach ([1,2,3] as $i) {
|
||||
if (! $matches[$i] || ($matches[$i] > DomainController::NUMBER_MAX))
|
||||
throw new Exception('Invalid FTN: '.$ftn);
|
||||
}
|
||||
if (isset($matches[5]) AND $matches[5] > DomainController::NUMBER_MAX)
|
||||
throw new Exception('Invalid FTN: '.$ftn);
|
||||
|
||||
$o = (new self)->active()
|
||||
->select('addresses.*')
|
||||
->where('zones.zone_id',$matches[1])
|
||||
->where('host_id',$matches[2])
|
||||
->join('zones',['zones.id'=>'addresses.zone_id'])
|
||||
->join('domains',['domains.id'=>'zones.domain_id'])
|
||||
->where('zones.active',TRUE)
|
||||
->where('domains.active',TRUE)
|
||||
->where('addresses.active',TRUE)
|
||||
->where('node_id',$matches[3])
|
||||
->where('point_id',(isset($matches[5]) AND $matches[5]) ? $matches[5] : 0)
|
||||
->when(isset($matches[7]),function($query) use ($matches) {
|
||||
$query->where('domains.name',$matches[7]);
|
||||
})
|
||||
->when((! isset($matches[7]) OR ! $matches[7]),function($query) {
|
||||
$query->where('domains.default',TRUE);
|
||||
})
|
||||
->single();
|
||||
|
||||
return ($o && $o->system->active) ? $o : NULL;
|
||||
}
|
||||
|
||||
public function session(string $type): ?string
|
||||
{
|
||||
static $session = NULL;
|
||||
|
||||
if (is_null($session)) {
|
||||
$session = (new AddressZone)
|
||||
->where('zone_id',$this->zone_id)
|
||||
->where('system_id',$this->system_id)
|
||||
->single();
|
||||
}
|
||||
|
||||
return $session ? $session->{$type} : NULL;
|
||||
}
|
||||
}
|
||||
|
10
app/Models/AddressZone.php
Normal file
10
app/Models/AddressZone.php
Normal file
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class AddressZone extends Model
|
||||
{
|
||||
protected $table = 'address_zone';
|
||||
}
|
@@ -16,22 +16,60 @@ use Illuminate\Support\Facades\File;
|
||||
*/
|
||||
class Setup extends Model
|
||||
{
|
||||
public const S_DOMAIN = 1<<1; // Users can create Domains
|
||||
public const S_SYSTEM = 1<<2; // Users can create Systems
|
||||
|
||||
public const BINKP_OPT_CHT = 1<<1; /* CHAT mode - not implemented */
|
||||
public const BINKP_OPT_CR = 1<<2; /* Crypt mode - not implemented */
|
||||
public const BINKP_OPT_MB = 1<<3; /* Multi-Batch mode */
|
||||
public const BINKP_OPT_MD = 1<<4; /* CRAM-MD5 mode */
|
||||
public const BINKP_OPT_ND = 1<<5; /* http://ftsc.org/docs/fsp-1027.001: No-dupes mode */
|
||||
public const BINKP_OPT_NDA = 1<<6; /* http://ftsc.org/docs/fsp-1027.001: Asymmetric ND mode */
|
||||
public const BINKP_OPT_NR = 1<<7; /* http://ftsc.org/docs/fsp-1027.001: Non-Reliable mode */
|
||||
public const BINKP_OPT_MPWD = 1<<8; /* Multi-Password mode - not implemented */
|
||||
|
||||
public const BINKP_PORT = 24554;
|
||||
public const BINKP_BIND = '0.0.0.0';
|
||||
public const EMSI_PORT = 60179;
|
||||
public const EMSI_BIND = self::BINKP_BIND;
|
||||
|
||||
public const O_BINKP = 1<<1; /* Listen for BINKD connections */
|
||||
public const O_EMSI = 1<<2; /* Listen for EMSI connections */
|
||||
public const O_HIDEAKA = 1<<3; /* Hide AKAs to different Zones */
|
||||
|
||||
// Our non model attributes and values
|
||||
private array $internal = [];
|
||||
|
||||
/* RELATIONS */
|
||||
|
||||
public function system()
|
||||
{
|
||||
return $this->belongsTo(System::class);
|
||||
}
|
||||
|
||||
/* ATTRIBUTES */
|
||||
|
||||
public function getLocationAttribute()
|
||||
{
|
||||
return $this->system->location;
|
||||
}
|
||||
|
||||
public function getSysopAttribute()
|
||||
{
|
||||
return $this->system->sysop;
|
||||
}
|
||||
|
||||
public function getSystemNameAttribute()
|
||||
{
|
||||
return $this->system->name;
|
||||
}
|
||||
|
||||
/* METHODS */
|
||||
|
||||
public function __construct(array $attributes = [])
|
||||
{
|
||||
parent::__construct($attributes);
|
||||
|
||||
// @todo This should go in a config file in the config dir
|
||||
$this->opt_cht = 0; /* CHAT mode - not implemented*/
|
||||
$this->opt_cr = 0; /* Crypt mode - not implemented*/
|
||||
$this->opt_mb = 1; /* Multi-Batch mode */
|
||||
$this->opt_md = 0; /* CRAM-MD5 mode */
|
||||
$this->opt_nd = 0; /* http://ftsc.org/docs/fsp-1027.001: No-dupes mode */
|
||||
$this->opt_nda = 1; /* http://ftsc.org/docs/fsp-1027.001: Asymmetric ND mode */
|
||||
$this->opt_mpwd = 0; /* Multi-Password mode - not implemented */
|
||||
$this->opt_nr = 1; /* http://ftsc.org/docs/fsp-1027.001: Non-Reliable mode */
|
||||
$this->binkp_options = ['m','d','r','b'];
|
||||
|
||||
/* EMSI SETTINGS */
|
||||
@@ -43,32 +81,6 @@ class Setup extends Model
|
||||
$this->inbound = '/tmp';
|
||||
}
|
||||
|
||||
/* RELATIONS */
|
||||
|
||||
public function nodes()
|
||||
{
|
||||
return $this->belongsToMany(Node::class);
|
||||
}
|
||||
|
||||
/* ATTRIBUTES */
|
||||
|
||||
public function getLocationAttribute()
|
||||
{
|
||||
return $this->nodes->first()->location;
|
||||
}
|
||||
|
||||
public function getSysopAttribute()
|
||||
{
|
||||
return $this->nodes->first()->sysop;
|
||||
}
|
||||
|
||||
public function getSystemNameAttribute()
|
||||
{
|
||||
return $this->nodes->first()->system;
|
||||
}
|
||||
|
||||
/* METHODS */
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
@@ -78,15 +90,15 @@ class Setup extends Model
|
||||
case 'binkp_options':
|
||||
case 'ignore_nrq':
|
||||
case 'inbound':
|
||||
case 'opt_nr':
|
||||
case 'opt_nr': // @todo - this keys are now in #binkp as bits
|
||||
case 'opt_nd':
|
||||
case 'opt_nda':
|
||||
case 'opt_md':
|
||||
case 'opt_cr':
|
||||
case 'opt_mb':
|
||||
case 'opt_cht':
|
||||
case 'opt_mpwd':
|
||||
case 'do_prevent':
|
||||
case 'options':
|
||||
return $this->internal[$key] ?? FALSE;
|
||||
|
||||
case 'version':
|
||||
@@ -113,13 +125,43 @@ class Setup extends Model
|
||||
case 'opt_cr':
|
||||
case 'opt_mb':
|
||||
case 'opt_cht':
|
||||
case 'opt_mpwd':
|
||||
case 'do_prevent':
|
||||
case 'options':
|
||||
$this->internal[$key] = $value;
|
||||
break;
|
||||
|
||||
default:
|
||||
parent::__get($key);
|
||||
parent::__set($key,$value);
|
||||
}
|
||||
}
|
||||
|
||||
public function binkpOptionClear(int $key): void
|
||||
{
|
||||
$this->binkp &= ~$key;
|
||||
}
|
||||
|
||||
public function binkpOptionGet(int $key): int
|
||||
{
|
||||
return ($this->binkp & $key);
|
||||
}
|
||||
|
||||
public function binkpOptionSet(int $key): void
|
||||
{
|
||||
$this->binkp |= $key;
|
||||
}
|
||||
|
||||
public function optionClear(int $key): void
|
||||
{
|
||||
$this->options &= ~$key;
|
||||
}
|
||||
|
||||
public function optionGet(int $key): int
|
||||
{
|
||||
return ($this->options & $key);
|
||||
}
|
||||
|
||||
public function optionSet(int $key): void
|
||||
{
|
||||
$this->options |= $key;
|
||||
}
|
||||
}
|
@@ -11,8 +11,6 @@ class System extends Model
|
||||
{
|
||||
use HasFactory,ScopeActive;
|
||||
|
||||
/* SCOPES */
|
||||
|
||||
/* RELATIONS */
|
||||
|
||||
public function addresses()
|
||||
@@ -23,6 +21,4 @@ class System extends Model
|
||||
->orderBy('node_id')
|
||||
->orderBy('point_id');
|
||||
}
|
||||
|
||||
/* CASTS */
|
||||
}
|
Reference in New Issue
Block a user