diff --git a/app/Classes/Protocol/DNS.php b/app/Classes/Protocol/DNS.php index cd18ea9..d45bf4f 100644 --- a/app/Classes/Protocol/DNS.php +++ b/app/Classes/Protocol/DNS.php @@ -7,7 +7,6 @@ use Illuminate\Support\Str; use App\Classes\Protocol as BaseProtocol; use App\Classes\Sock\SocketClient; -use App\Http\Controllers\DomainController; use App\Models\{Address,Domain,Mailer}; /** @@ -328,7 +327,7 @@ final class DNS extends BaseProtocol { $m = []; - return (preg_match('/^'.$prefix.'([0-9]+)+/',$label,$m) && ($m[1] <= DomainController::NUMBER_MAX)) + return (preg_match('/^'.$prefix.'([0-9]+)+/',$label,$m) && ($m[1] <= Address::ADDRESS_FIELD_MAX)) ? $m[1] : NULL; } diff --git a/app/Http/Controllers/DomainController.php b/app/Http/Controllers/DomainController.php index cafc714..083ae1e 100644 --- a/app/Http/Controllers/DomainController.php +++ b/app/Http/Controllers/DomainController.php @@ -10,9 +10,6 @@ use App\Models\{Address,Domain,Zone}; class DomainController extends Controller { - // http://ftsc.org/docs/frl-1002.001 - public const NUMBER_MAX = 0x7fff; - /** * Add or edit a domain */ diff --git a/app/Http/Controllers/SystemController.php b/app/Http/Controllers/SystemController.php index 7947d4b..10822a2 100644 --- a/app/Http/Controllers/SystemController.php +++ b/app/Http/Controllers/SystemController.php @@ -242,8 +242,8 @@ class SystemController extends Controller 'point_id' => [ 'required', function($attribute,$value,$fail) use ($request) { - if (! is_numeric($value) || $value > DomainController::NUMBER_MAX) - $fail(sprintf('Point numbers must be between 0 and %d',DomainController::NUMBER_MAX)); + if (! is_numeric($value) || $value > Address::ADDRESS_FIELD_MAX) + $fail(sprintf('Point numbers must be between 0 and %d',Address::ADDRESS_FIELD_MAX)); // Check that the host doesnt already exist $o = Address::where(function($query) use ($request,$value) { diff --git a/app/Models/Address.php b/app/Models/Address.php index 6fa59d7..92fd925 100644 --- a/app/Models/Address.php +++ b/app/Models/Address.php @@ -12,7 +12,6 @@ use Illuminate\Support\Facades\Log; use App\Classes\FTN\{Message,Packet}; use App\Exceptions\InvalidFTNException; -use App\Http\Controllers\DomainController; use App\Traits\ScopeActive; class Address extends Model @@ -38,6 +37,9 @@ class Address extends Model public const NODE_UNKNOWN = 1<<15; // Unknown public const NODE_ALL = 0xFFF; // Mask to catch all nodes + // http://ftsc.org/docs/frl-1002.001 + public const ADDRESS_FIELD_MAX = 0x7fff; // Maximum value for a field in the address + public static function boot() { parent::boot(); @@ -968,10 +970,10 @@ class Address extends Model // Check our numbers are correct. foreach ([1,2,3] as $i) - if ((! is_numeric($matches[$i])) || ($matches[$i] > DomainController::NUMBER_MAX)) + if ((! is_numeric($matches[$i])) || ($matches[$i] > self::ADDRESS_FIELD_MAX)) throw new InvalidFTNException(sprintf('Invalid FTN: [%s] - zone, host, or node address invalid [%d]',$ftn,$matches[$i])); - if ((! empty($matches[4])) AND ((! is_numeric($matches[$i])) || ($matches[4] > DomainController::NUMBER_MAX))) + if ((! empty($matches[4])) AND ((! is_numeric($matches[$i])) || ($matches[4] > self::ADDRESS_FIELD_MAX))) throw new InvalidFTNException(sprintf('Invalid FTN: [%s] - point address invalid [%d]',$ftn,$matches[4])); return [ diff --git a/app/Rules/FidoInteger.php b/app/Rules/FidoInteger.php index f05dc02..05cb61e 100644 --- a/app/Rules/FidoInteger.php +++ b/app/Rules/FidoInteger.php @@ -4,13 +4,13 @@ namespace App\Rules; use Illuminate\Contracts\Validation\Rule; -use App\Http\Controllers\DomainController; +use App\Models\Address; class FidoInteger implements Rule { /** * Determine if the validation rule passes. - * This will check that a number used for zone, net, host is between 1 and DomainController::NUMBER_MAX. + * This will check that a number used for zone, net, host is between 1 and Address::ADDRESS_FIELD_MAX. * * @param string $attribute * @param mixed $value @@ -18,7 +18,7 @@ class FidoInteger implements Rule */ public function passes($attribute,$value) { - return (is_numeric($value) && ($value >= 0) && ($value < DomainController::NUMBER_MAX)); + return (is_numeric($value) && ($value >= 0) && ($value < Address::ADDRESS_FIELD_MAX)); } /** @@ -28,6 +28,6 @@ class FidoInteger implements Rule */ public function message() { - return sprintf('The number must be between 0 and %d.',DomainController::NUMBER_MAX); + return sprintf('The number must be between 0 and %d.',Address::ADDRESS_FIELD_MAX); } } \ No newline at end of file diff --git a/app/Rules/TwoByteInteger.php b/app/Rules/TwoByteInteger.php index 1f36e7a..17a5490 100644 --- a/app/Rules/TwoByteInteger.php +++ b/app/Rules/TwoByteInteger.php @@ -4,13 +4,13 @@ namespace App\Rules; use Illuminate\Contracts\Validation\Rule; -use App\Http\Controllers\DomainController; +use App\Models\Address; class TwoByteInteger implements Rule { /** * Determine if the validation rule passes. - * This will check that a number used for zone, net, host is between 1 and DomainController::NUMBER_MAX. + * This will check that a number used for zone, net, host is between 1 and Address::ADDRESS_FIELD_MAX. * * @param string $attribute * @param mixed $value @@ -18,7 +18,7 @@ class TwoByteInteger implements Rule */ public function passes($attribute,$value) { - return (is_numeric($value) && ($value > 0) && ($value < DomainController::NUMBER_MAX)); + return (is_numeric($value) && ($value > 0) && ($value < Address::ADDRESS_FIELD_MAX)); } /** @@ -28,6 +28,6 @@ class TwoByteInteger implements Rule */ public function message() { - return sprintf('The number must be between 1 and %d.',DomainController::NUMBER_MAX); + return sprintf('The number must be between 1 and %d.',Address::ADDRESS_FIELD_MAX); } } \ No newline at end of file diff --git a/app/Rules/TwoByteIntegerWithZero.php b/app/Rules/TwoByteIntegerWithZero.php index 8f9f2d6..44311dc 100644 --- a/app/Rules/TwoByteIntegerWithZero.php +++ b/app/Rules/TwoByteIntegerWithZero.php @@ -4,13 +4,13 @@ namespace App\Rules; use Illuminate\Contracts\Validation\Rule; -use App\Http\Controllers\DomainController; +use App\Models\Address; class TwoByteIntegerWithZero implements Rule { /** * Determine if the validation rule passes. - * This will check that a number used for zone, net, host is between 1 and DomainController::NUMBER_MAX. + * This will check that a number used for zone, net, host is between 1 and Address::ADDRESS_FIELD_MAX. * * @param string $attribute * @param mixed $value @@ -18,7 +18,7 @@ class TwoByteIntegerWithZero implements Rule */ public function passes($attribute,$value) { - return (is_numeric($value) && ($value >= 0) && ($value < DomainController::NUMBER_MAX)); + return (is_numeric($value) && ($value >= 0) && ($value < Address::ADDRESS_FIELD_MAX)); } /** @@ -28,6 +28,6 @@ class TwoByteIntegerWithZero implements Rule */ public function message() { - return sprintf('The number must be between 1 and %d.',DomainController::NUMBER_MAX); + return sprintf('The number must be between 1 and %d.',Address::ADDRESS_FIELD_MAX); } } \ No newline at end of file diff --git a/app/Traits/ParseAddresses.php b/app/Traits/ParseAddresses.php index 5faec80..429d724 100644 --- a/app/Traits/ParseAddresses.php +++ b/app/Traits/ParseAddresses.php @@ -5,7 +5,6 @@ namespace App\Traits; use Illuminate\Support\Collection; use Illuminate\Support\Facades\Log; -use App\Http\Controllers\DomainController; use App\Models\{Address,System,Zone}; trait ParseAddresses @@ -37,13 +36,13 @@ trait ParseAddresses // If domain should be flattened, look for node regardless of zone (within the list of zones for the domain) $ao = ($zone->domain->flatten) - ? Address::findZone($zone->domain,$net&DomainController::NUMBER_MAX,$node&DomainController::NUMBER_MAX,0) - : Address::findFTN(sprintf('%d:%d/%d@%s',$zone->zone_id,$net&DomainController::NUMBER_MAX,$node&DomainController::NUMBER_MAX,$zone->domain->name)); + ? Address::findZone($zone->domain,$net&Address::ADDRESS_FIELD_MAX,$node&Address::ADDRESS_FIELD_MAX,0) + : Address::findFTN(sprintf('%d:%d/%d@%s',$zone->zone_id,$net&Address::ADDRESS_FIELD_MAX,$node&Address::ADDRESS_FIELD_MAX,$zone->domain->name)); switch ($type) { case 'seenby': if (! $ao) - $rogue->push(sprintf('%d:%d/%d',$zone->domain->flatten ? 0 : $zone->zone_id,$net&DomainController::NUMBER_MAX,$node&DomainController::NUMBER_MAX)); + $rogue->push(sprintf('%d:%d/%d',$zone->domain->flatten ? 0 : $zone->zone_id,$net&Address::ADDRESS_FIELD_MAX,$node&Address::ADDRESS_FIELD_MAX)); else $nodes->push($ao->id); @@ -51,7 +50,7 @@ trait ParseAddresses case 'path': if (! $ao) { - $ftn = sprintf('%d:%d/%d@%s',$zone->zone_id,$net&DomainController::NUMBER_MAX,$node&DomainController::NUMBER_MAX,$zone->domain->name); + $ftn = sprintf('%d:%d/%d@%s',$zone->zone_id,$net&Address::ADDRESS_FIELD_MAX,$node&Address::ADDRESS_FIELD_MAX,$zone->domain->name); Log::info(sprintf('%s:- Creating address [%s] for path',self::LOGKEY,$ftn)); $ao = Address::createFTN($ftn,System::createUnknownSystem());