2021-04-01 10:59:15 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Models;
|
|
|
|
|
|
|
|
use Exception;
|
|
|
|
use Illuminate\Database\Eloquent\Collection;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
use Illuminate\Support\Facades\File;
|
|
|
|
|
|
|
|
/**
|
2022-03-14 11:28:54 +00:00
|
|
|
* This class represents our configuration.
|
|
|
|
*
|
|
|
|
* Our 'System' is defined by system_id, and from it we can find out our BBS name and addresses.
|
2021-04-01 10:59:15 +00:00
|
|
|
*
|
|
|
|
* @package App\Models
|
|
|
|
* @property Collection nodes
|
|
|
|
* @property array binkp_options
|
|
|
|
*/
|
|
|
|
class Setup extends Model
|
|
|
|
{
|
2021-06-24 10:16:37 +00:00
|
|
|
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;
|
2022-01-28 13:45:25 +00:00
|
|
|
public const BINKP_BIND = '::';
|
2021-06-24 10:16:37 +00:00
|
|
|
public const EMSI_PORT = 60179;
|
|
|
|
public const EMSI_BIND = self::BINKP_BIND;
|
2023-04-22 11:30:30 +00:00
|
|
|
public const DNS_PORT = 53;
|
|
|
|
public const DNS_BIND = '::';
|
2021-06-24 10:16:37 +00:00
|
|
|
|
|
|
|
public const O_BINKP = 1<<1; /* Listen for BINKD connections */
|
|
|
|
public const O_EMSI = 1<<2; /* Listen for EMSI connections */
|
2023-04-22 11:30:30 +00:00
|
|
|
public const O_DNS = 1<<3; /* List for DNS */
|
|
|
|
public const O_HIDEAKA = 1<<4; /* Hide AKAs to different Zones */
|
2021-06-24 10:16:37 +00:00
|
|
|
|
2021-07-15 14:54:23 +00:00
|
|
|
public const PRODUCT_NAME = 'Clearing Houz';
|
|
|
|
public const PRODUCT_ID = 0xAB8D;
|
|
|
|
public const PRODUCT_VERSION_MAJ = 0;
|
|
|
|
public const PRODUCT_VERSION_MIN = 0;
|
|
|
|
|
2022-12-02 13:22:56 +00:00
|
|
|
public const MAX_MSGS_PKT = 50;
|
|
|
|
|
2021-07-17 05:48:07 +00:00
|
|
|
public const hexdigitslower = '0123456789abcdef';
|
|
|
|
|
2021-04-01 10:59:15 +00:00
|
|
|
// Our non model attributes and values
|
|
|
|
private array $internal = [];
|
|
|
|
|
2021-06-24 10:16:37 +00:00
|
|
|
public function __construct(array $attributes = [])
|
|
|
|
{
|
|
|
|
parent::__construct($attributes);
|
|
|
|
|
2021-08-14 06:14:22 +00:00
|
|
|
// @todo These option should be in setup?
|
2021-06-24 10:16:37 +00:00
|
|
|
$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 */
|
|
|
|
}
|
|
|
|
|
2021-04-01 10:59:15 +00:00
|
|
|
/**
|
|
|
|
* @throws Exception
|
|
|
|
*/
|
|
|
|
public function __get($key)
|
|
|
|
{
|
|
|
|
switch ($key) {
|
|
|
|
case 'binkp_options':
|
|
|
|
case 'ignore_nrq':
|
2021-06-24 10:16:37 +00:00
|
|
|
case 'opt_nr': // @todo - this keys are now in #binkp as bits
|
2021-04-01 10:59:15 +00:00
|
|
|
case 'opt_nd':
|
|
|
|
case 'opt_nda':
|
|
|
|
case 'opt_md':
|
|
|
|
case 'opt_cr':
|
|
|
|
case 'opt_mb':
|
|
|
|
case 'opt_cht':
|
2021-06-24 10:16:37 +00:00
|
|
|
case 'opt_mpwd':
|
2021-04-01 10:59:15 +00:00
|
|
|
case 'do_prevent':
|
|
|
|
return $this->internal[$key] ?? FALSE;
|
|
|
|
|
2022-12-02 13:22:56 +00:00
|
|
|
case 'max_msgs_pkt':
|
|
|
|
return self::MAX_MSGS_PKT;
|
|
|
|
|
2021-04-01 10:59:15 +00:00
|
|
|
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 'opt_nr':
|
|
|
|
case 'opt_nd':
|
|
|
|
case 'opt_nda':
|
|
|
|
case 'opt_md':
|
|
|
|
case 'opt_cr':
|
|
|
|
case 'opt_mb':
|
|
|
|
case 'opt_cht':
|
2021-06-24 10:16:37 +00:00
|
|
|
case 'opt_mpwd':
|
2021-04-01 10:59:15 +00:00
|
|
|
case 'do_prevent':
|
|
|
|
$this->internal[$key] = $value;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2021-06-24 10:16:37 +00:00
|
|
|
parent::__set($key,$value);
|
2021-04-01 10:59:15 +00:00
|
|
|
}
|
|
|
|
}
|
2021-06-24 10:16:37 +00:00
|
|
|
|
2022-03-14 11:28:54 +00:00
|
|
|
/**
|
|
|
|
* The Mailer Product ID in hex.
|
|
|
|
*
|
|
|
|
* @param int $c
|
|
|
|
* @return string
|
|
|
|
* @throws Exception
|
|
|
|
*/
|
|
|
|
public static function product_id(int $c=self::PRODUCT_ID): string
|
|
|
|
{
|
|
|
|
return hexstr($c);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* RELATIONS */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The defined system that this setup is valid for
|
|
|
|
*
|
|
|
|
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
|
|
|
*/
|
|
|
|
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 */
|
|
|
|
|
2021-08-14 06:14:22 +00:00
|
|
|
/* BINKP OPTIONS: BINKP_OPT_* */
|
|
|
|
|
2021-06-24 10:16:37 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2021-08-14 06:14:22 +00:00
|
|
|
/* GENERAL OPTIONS: O_* */
|
|
|
|
|
2021-06-24 10:16:37 +00:00
|
|
|
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;
|
|
|
|
}
|
2021-04-01 10:59:15 +00:00
|
|
|
}
|