Add Zmodem/BINKP/EMSI

This commit is contained in:
Deon George
2021-04-01 21:59:15 +11:00
parent 619cabb751
commit b94e39c7af
33 changed files with 8216 additions and 42 deletions

View File

@@ -2,23 +2,30 @@
namespace App\Models;
use Exception;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use App\Traits\ScopeActive;
class Node extends Model
{
use ScopeActive;
protected $casts = [
'is_zc'=>'boolean',
'is_rc'=>'boolean',
'is_hub'=>'boolean',
'is_host'=>'boolean',
];
protected $fillable = ['zone_id','host_id','node_id','point_id'];
/* SCOPES */
public function scopeHost()
{
// @todo
}
/* RELATIONS */
@@ -26,7 +33,7 @@ class Node extends Model
/**
* Node nodelist flags
*
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
* @return BelongsToMany
*/
public function flags()
{
@@ -48,7 +55,7 @@ class Node extends Model
public function getFTNAttribute()
{
return $this->zone_id
? sprintf('%s:%s/%s.%s',$this->zone->zone_id,$this->host_id,$this->node_id,$this->point_id)
? sprintf('%d:%d/%d.%d@%s',$this->zone->zone_id,$this->host_id,$this->node_id,$this->point_id,$this->zone->domain->name)
: '-';
}
@@ -63,7 +70,51 @@ class Node extends Model
/* METHODS */
public function hasFlag($relation,$model)
/**
* 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 = [];
// @todo domain can have more chars.
if (! preg_match('#^([0-9]+):([0-9]+)/([0-9]+)(.([0-9]+))?(@([a-z]{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] > 0xffff))
throw new Exception('Invalid FTN: '.$ftn);
}
if (isset($matches[5]) AND $matches[5] > 0xffff)
throw new Exception('Invalid FTN: '.$ftn);
return (new self)->active()
->select('nodes.*')
->where('zones.zone_id',$matches[1])
->where(function($query) use ($matches) {
$query->where('hub_id',$matches[2])
->orWhere('host_id',$matches[2]);
})
->join('zones',['zones.id'=>'nodes.zone_id'])
->join('domains',['domains.id'=>'zones.domain_id'])
->where('zones.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();
}
public function hasFlag($relation,$model): bool
{
return (bool) $this->{$relation}()
->wherePivot($model->getForeignKey(),$model->{$model->getKeyName()})

125
app/Models/Setup.php Normal file
View File

@@ -0,0 +1,125 @@
<?php
namespace App\Models;
use Exception;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\File;
/**
* Class Setup
*
* @package App\Models
* @property Collection nodes
* @property array binkp_options
*/
class Setup extends Model
{
// Our non model attributes and values
private array $internal = [];
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 */
$this->do_prevent = 1; /* EMSI - send an immediate EMSI_INQ on connect */
$this->ignore_nrq = 0;
$this->options = 0; /* EMSI - our capabilities */
/* EMSI - the order of protocols we are able to accept */
$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
*/
public function __get($key)
{
switch ($key) {
case 'binkp_options':
case 'ignore_nrq':
case 'inbound':
case 'opt_nr':
case 'opt_nd':
case 'opt_nda':
case 'opt_md':
case 'opt_cr':
case 'opt_mb':
case 'opt_cht':
case 'do_prevent':
case 'options':
return $this->internal[$key] ?? FALSE;
case 'version':
return File::exists('VERSION') ? chop(File::get('VERSION')) : 'dev';
default:
return parent::__get($key);
}
}
/**
* @throws Exception
*/
public function __set($key,$value)
{
switch ($key) {
case 'binkp_options':
case 'ignore_nrq':
case 'inbound':
case 'opt_nr':
case 'opt_nd':
case 'opt_nda':
case 'opt_md':
case 'opt_cr':
case 'opt_mb':
case 'opt_cht':
case 'do_prevent':
case 'options':
$this->internal[$key] = $value;
break;
default:
parent::__get($key);
}
}
}