diff --git a/app/Classes/FTN/Message.php b/app/Classes/FTN/Message.php index 6ecdee0..0f4c0d3 100644 --- a/app/Classes/FTN/Message.php +++ b/app/Classes/FTN/Message.php @@ -702,19 +702,31 @@ class Message extends FTNBase $node = (int)$item; } - $ftn = sprintf('%d:%d/%d',$this->fz,$net&DomainController::NUMBER_MAX,$node&DomainController::NUMBER_MAX); - // @todo This should be enhanced to include the address at the time of the message. - if ($aos->has($ftn)) - $ao = $aos->get($ftn); - else - $aos->put($ftn,($ao=(Address::findFTN($ftn))?->id)); + // If domain should be flattened, look for node regardless of zone (within the list of zones for the domain) + if ($this->fdomain && $this->fdomain->flatten) { + $ao = Address::findZone($this->fdomain,$net&DomainController::NUMBER_MAX,$node&DomainController::NUMBER_MAX); - if (! $ao) { + $aoid = $ao?->id; + + if (! $ao) + $ftn = sprintf('%d:%d/%d',0,$net&DomainController::NUMBER_MAX,$node&DomainController::NUMBER_MAX); + + } else { + $ftn = sprintf('%d:%d/%d',$this->fz,$net&DomainController::NUMBER_MAX,$node&DomainController::NUMBER_MAX); + + // @todo This should be enhanced to include the address at the time of the message. + if ($aos->has($ftn)) + $aoid = $aos->get($ftn); + else + $aos->put($ftn,($aoid=(Address::findFTN($ftn))?->id)); + } + + if (! $aoid) { Log::alert(sprintf('%s:! Undefined Node [%s] in %s.',self::LOGKEY,$ftn,$type)); $rogue->push($ftn); } else { - $nodes->push($ao); + $nodes->push($aoid); } } } diff --git a/app/Console/Commands/PacketProcess.php b/app/Console/Commands/PacketProcess.php index 33abc89..353e8ab 100644 --- a/app/Console/Commands/PacketProcess.php +++ b/app/Console/Commands/PacketProcess.php @@ -48,7 +48,7 @@ class PacketProcess extends Command $this->info(sprintf('Processing message from [%s] with msgid [%s] in (%s)',$msg->fboss,$msg->msgid,$f->pktName())); // Dispatch job. - Job::dispatchSync($msg,$f->pktName(),$a,$packet->fftn_o,Carbon::now(),$this->option('nobot')); + Job::dispatchSync($msg,$f->pktName(),$a,$a,Carbon::now(),$this->option('nobot')); } } } diff --git a/app/Http/Controllers/DomainController.php b/app/Http/Controllers/DomainController.php index 34d8928..64a9a4f 100644 --- a/app/Http/Controllers/DomainController.php +++ b/app/Http/Controllers/DomainController.php @@ -5,6 +5,7 @@ namespace App\Http\Controllers; use Illuminate\Support\Collection; use Illuminate\Http\Request; +use App\Http\Requests\DomainRequest; use App\Models\{Address,Domain,Zone}; class DomainController extends Controller @@ -15,20 +16,10 @@ class DomainController extends Controller /** * Add or edit a domain */ - public function add_edit(Request $request,Domain $o) + public function add_edit(DomainRequest $request,Domain $o) { if ($request->post()) { - $this->authorize('admin',$o); - - $request->validate([ - // http://ftsc.org/docs/old/fsp-1028.002 - 'name' => 'required|max:8|regex:/^[a-z-_~]{1,8}$/|unique:domains,name,'.($o->exists ? $o->id : 0), - 'dnsdomain' => 'nullable|regex:/^(?!:\/\/)(?=.{1,255}$)((.{1,63}\.){1,127}(?![0-9]*$)[a-z0-9-]+\.?)$/i|unique:domains,dnsdomain,'.($o->exists ? $o->id : NULL), - 'active' => 'required|boolean', - 'public' => 'required|boolean', - ]); - - foreach (['name','dnsdomain','active','public','homepage','notes'] as $key) + foreach (['name','dnsdomain','active','public','homepage','notes','flatten'] as $key) $o->{$key} = $request->post($key); $o->save(); diff --git a/app/Http/Controllers/EchoareaController.php b/app/Http/Controllers/EchoareaController.php index 5b9f395..6a7125b 100644 --- a/app/Http/Controllers/EchoareaController.php +++ b/app/Http/Controllers/EchoareaController.php @@ -18,7 +18,7 @@ class EchoareaController extends Controller $request->validate([ 'domain_id' => 'required|exists:domains,id', - 'name' => 'required|min:4|max:35|regex:/^[a-zA-Z-_~]{4,}$/|unique:echoareas,name,'.($o->exists ? $o->id : 0), + 'name' => 'required|min:4|max:35|regex:/^[a-zA-Z0-9\-_~]{4,}$/|unique:echoareas,name,'.($o->exists ? $o->id : 0), 'description' => 'required', 'active' => 'required|boolean', 'show' => 'required|boolean', diff --git a/app/Http/Requests/DomainRequest.php b/app/Http/Requests/DomainRequest.php new file mode 100644 index 0000000..37abf28 --- /dev/null +++ b/app/Http/Requests/DomainRequest.php @@ -0,0 +1,33 @@ +isMethod('post')) + return []; + + $o = $this->route('o'); + + return [ + 'name' => 'required|max:8|regex:/^[a-z-_~]{1,8}$/|unique:domains,name,'.($o->exists ? $o->id : 0), + 'dnsdomain' => 'nullable|regex:/^(?!:\/\/)(?=.{1,255}$)((.{1,63}\.){1,127}(?![0-9]*$)[a-z0-9-]+\.?)$/i|unique:domains,dnsdomain,'.($o->exists ? $o->id : NULL), + 'active' => 'required|boolean', + 'public' => 'required|boolean', + 'flatten' => 'nullable|boolean', + ]; + } +} \ No newline at end of file diff --git a/app/Models/Address.php b/app/Models/Address.php index 0bc26a6..44974f7 100644 --- a/app/Models/Address.php +++ b/app/Models/Address.php @@ -402,7 +402,7 @@ class Address extends Model return $q ->where(function($q) use ($ftn) { return $q->where('region_id',$ftn['n']) - ->where('host_id',0); + ->where('host_id',$ftn['n']); }); }) ->where('node_id',$ftn['f']) @@ -433,7 +433,7 @@ class Address extends Model return $q->where(function($qq) use ($ftn) { return $qq ->where('region_id',$ftn['n']) - ->where('host_id',0); + ->where('host_id',$ftn['n']); }) ->orWhere(function($qq) use ($ftn) { return $qq @@ -513,6 +513,50 @@ class Address extends Model return ($o && $o->system->active) ? $o : NULL; } + /** + * This is to find an address for a domain (like fidonet), which is technically 2D even though it uses multiple zones. + * + * This was implemented to identify seenby and path kludges + * + * @param Domain $do + * @param int $host + * @param int $node + * @param bool $trashed + * @return self|null + * @throws \Exception + */ + public static function findZone(Domain $do,int $host,int $node,bool $trashed=FALSE): ?self + { + if (! $do->flatten) + throw new \Exception(sprintf('Domain is not set with flatten: %d',$do->id)); + + $zones = $do->zones->pluck('zone_id'); + + $o = (new self) + ->select('addresses.*') + ->join('zones',['zones.id'=>'addresses.zone_id']) + //->join('domains',['domains.id'=>'zones.domain_id']) + ->when($trashed,function($query) { + $query->trashed(); + },function($query) { + $query->active(); + }) + ->whereIN('zones.zone_id',$zones) + ->where(function($q) use ($host) { + return $q + ->where(function($q) use ($host) { + return $q->where('region_id',$host) + ->where('host_id',$host); + }) + ->orWhere('host_id',$host); + }) + ->where('node_id',$node) + ->where('zones.domain_id',$do->id) + ->single(); + + return $o; + } + /** * Create an activation code for this address * diff --git a/database/migrations/2023_09_09_221103_domain_2d.php b/database/migrations/2023_09_09_221103_domain_2d.php new file mode 100644 index 0000000..c0bd1aa --- /dev/null +++ b/database/migrations/2023_09_09_221103_domain_2d.php @@ -0,0 +1,28 @@ +boolean('flatten')->nullable(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::table('domains',function (Blueprint $table) { + $table->dropColumn('flatten'); + }); + } +}; diff --git a/resources/views/domain/addedit.blade.php b/resources/views/domain/addedit.blade.php index 37992ef..ad18071 100644 --- a/resources/views/domain/addedit.blade.php +++ b/resources/views/domain/addedit.blade.php @@ -29,7 +29,7 @@ -