2021-04-01 10:59:15 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Models;
|
|
|
|
|
|
|
|
use Illuminate\Database\Eloquent\Collection;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
2023-07-02 13:40:08 +00:00
|
|
|
use Illuminate\Support\Arr;
|
2021-04-01 10:59:15 +00:00
|
|
|
use Illuminate\Support\Facades\File;
|
|
|
|
|
2023-07-02 13:40:08 +00:00
|
|
|
use App\Classes\Protocol\{Binkp,DNS,EMSI};
|
|
|
|
|
2021-04-01 10:59:15 +00:00
|
|
|
/**
|
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
|
|
|
|
*/
|
|
|
|
class Setup extends Model
|
|
|
|
{
|
2023-07-02 13:40:08 +00:00
|
|
|
public const PRODUCT_NAME = 'Clearing Houz';
|
2024-05-22 05:25:39 +00:00
|
|
|
public const PRODUCT_NAME_SHORT = 'clrghouz';
|
2023-07-02 13:40:08 +00:00
|
|
|
public const PRODUCT_ID = 0xAB8D;
|
|
|
|
public const PRODUCT_VERSION_MAJ = 0;
|
|
|
|
public const PRODUCT_VERSION_MIN = 0;
|
|
|
|
|
|
|
|
public const 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
|
|
|
|
2024-11-26 11:07:07 +00:00
|
|
|
public const MAX_BATCH_FILES = 5;
|
2022-12-02 13:22:56 +00:00
|
|
|
public const MAX_MSGS_PKT = 50;
|
|
|
|
|
2023-07-02 13:40:08 +00:00
|
|
|
protected $casts = [
|
2023-07-05 12:42:59 +00:00
|
|
|
'options' => 'array',
|
2023-07-02 13:40:08 +00:00
|
|
|
'servers' => 'array',
|
|
|
|
];
|
|
|
|
|
2021-04-01 10:59:15 +00:00
|
|
|
/**
|
2023-07-02 13:40:08 +00:00
|
|
|
* @throws \Exception
|
2021-04-01 10:59:15 +00:00
|
|
|
*/
|
|
|
|
public function __get($key)
|
|
|
|
{
|
|
|
|
switch ($key) {
|
2023-07-02 13:40:08 +00:00
|
|
|
case 'binkp_bind':
|
|
|
|
case 'dns_bind':
|
|
|
|
case 'emsi_bind':
|
|
|
|
return Arr::get($this->servers,str_replace('_','.',$key),self::BIND);
|
|
|
|
|
|
|
|
case 'binkp_port':
|
|
|
|
return Arr::get($this->servers,str_replace('_','.',$key),Binkp::PORT);
|
|
|
|
case 'dns_port':
|
|
|
|
return Arr::get($this->servers,str_replace('_','.',$key),DNS::PORT);
|
2023-08-04 07:01:48 +00:00
|
|
|
case 'emsi_port':
|
|
|
|
return Arr::get($this->servers,str_replace('_','.',$key),EMSI::PORT);
|
2023-07-02 13:40:08 +00:00
|
|
|
|
2023-07-05 12:42:59 +00:00
|
|
|
case 'options_options':
|
|
|
|
return Arr::get($this->options,'options');
|
|
|
|
|
|
|
|
case 'binkp_active':
|
|
|
|
case 'dns_active':
|
|
|
|
case 'emsi_active':
|
2021-04-01 10:59:15 +00:00
|
|
|
case 'binkp_options':
|
2023-07-02 13:40:08 +00:00
|
|
|
case 'dns_options':
|
|
|
|
case 'emsi_options':
|
2023-07-05 12:42:59 +00:00
|
|
|
return Arr::get($this->servers,str_replace('_','.',$key));
|
2023-07-02 13:40:08 +00:00
|
|
|
|
2024-11-26 11:07:07 +00:00
|
|
|
case 'batch_files':
|
|
|
|
return Arr::get($this->options,$key,self::MAX_BATCH_FILES);
|
|
|
|
|
2023-07-05 12:42:59 +00:00
|
|
|
case 'msgs_pkt':
|
|
|
|
return Arr::get($this->options,$key,self::MAX_MSGS_PKT);
|
2022-12-02 13:22:56 +00:00
|
|
|
|
2021-04-01 10:59:15 +00:00
|
|
|
default:
|
|
|
|
return parent::__get($key);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2023-07-02 13:40:08 +00:00
|
|
|
* @throws \Exception
|
2021-04-01 10:59:15 +00:00
|
|
|
*/
|
|
|
|
public function __set($key,$value)
|
|
|
|
{
|
|
|
|
switch ($key) {
|
2023-07-02 13:40:08 +00:00
|
|
|
case 'binkp_bind':
|
|
|
|
case 'binkp_port':
|
2021-04-01 10:59:15 +00:00
|
|
|
case 'binkp_options':
|
2023-07-02 13:40:08 +00:00
|
|
|
case 'dns_bind':
|
|
|
|
case 'dns_port':
|
|
|
|
case 'dns_options':
|
|
|
|
case 'emsi_bind':
|
|
|
|
case 'emsi_port':
|
|
|
|
case 'emsi_options':
|
|
|
|
return Arr::set($this->servers,str_replace('_','.',$key),$value);
|
|
|
|
|
2021-04-01 10:59:15 +00:00
|
|
|
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
|
2023-07-02 13:40:08 +00:00
|
|
|
* @throws \Exception
|
2022-03-14 11:28:54 +00:00
|
|
|
*/
|
|
|
|
public static function product_id(int $c=self::PRODUCT_ID): string
|
|
|
|
{
|
|
|
|
return hexstr($c);
|
|
|
|
}
|
|
|
|
|
2024-11-02 12:30:42 +00:00
|
|
|
/**
|
|
|
|
* Application version
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public static function version(): string
|
|
|
|
{
|
|
|
|
return File::exists('VERSION') ? chop(File::get('VERSION')) : 'dev';
|
|
|
|
}
|
|
|
|
|
2022-03-14 11:28:54 +00:00
|
|
|
/* RELATIONS */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The defined system that this setup is valid for
|
|
|
|
*
|
|
|
|
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
|
|
|
*/
|
|
|
|
public function system()
|
|
|
|
{
|
|
|
|
return $this->belongsTo(System::class);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* METHODS */
|
|
|
|
|
2023-07-06 01:34:42 +00:00
|
|
|
public function optionClear(int $key,$index='option_options'): void
|
2021-06-24 10:16:37 +00:00
|
|
|
{
|
2023-07-02 13:40:08 +00:00
|
|
|
$this->{$index} &= ~$key;
|
2021-06-24 10:16:37 +00:00
|
|
|
}
|
|
|
|
|
2023-07-06 01:34:42 +00:00
|
|
|
public function optionGet(int $key,$index='option_options'): int
|
2021-06-24 10:16:37 +00:00
|
|
|
{
|
2023-07-02 13:40:08 +00:00
|
|
|
return ($this->{$index} & $key);
|
2021-06-24 10:16:37 +00:00
|
|
|
}
|
|
|
|
|
2023-07-06 01:34:42 +00:00
|
|
|
public function optionSet(int $key,$index='option_options'): void
|
2021-06-24 10:16:37 +00:00
|
|
|
{
|
2023-07-02 13:40:08 +00:00
|
|
|
$this->{$index} |= $key;
|
2021-06-24 10:16:37 +00:00
|
|
|
}
|
2021-04-01 10:59:15 +00:00
|
|
|
}
|