Implement 2D domain processing - mainly for fidonet

This commit is contained in:
Deon George 2023-09-10 22:48:12 +10:00
parent ed7dc2ab8b
commit 673c444acd
8 changed files with 148 additions and 25 deletions

View File

@ -702,19 +702,31 @@ class Message extends FTNBase
$node = (int)$item;
}
// 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);
$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))
$ao = $aos->get($ftn);
$aoid = $aos->get($ftn);
else
$aos->put($ftn,($ao=(Address::findFTN($ftn))?->id));
$aos->put($ftn,($aoid=(Address::findFTN($ftn))?->id));
}
if (! $ao) {
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);
}
}
}

View File

@ -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'));
}
}
}

View File

@ -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();

View File

@ -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',

View File

@ -0,0 +1,33 @@
<?php
namespace App\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Gate;
use App\Models\Domain;
class DomainRequest extends FormRequest
{
public function authorize(Domain $o)
{
return Gate::allows( 'admin',$o);
}
public function rules(Request $request)
{
if (! $request->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',
];
}
}

View File

@ -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
*

View File

@ -0,0 +1,28 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::table('domains',function (Blueprint $table) {
$table->boolean('flatten')->nullable();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::table('domains',function (Blueprint $table) {
$table->dropColumn('flatten');
});
}
};

View File

@ -29,7 +29,7 @@
</div>
</div>
<div class="col-4">
<div class="col-2">
<label for="active" class="form-label">Active</label>
<div class="input-group">
<div class="btn-group" role="group">
@ -42,6 +42,21 @@
</div>
</div>
<div class="col-2">
@if ($o->zones->count() > 1)
<label for="flatten" class="form-label">Flatten Zones <i class="bi bi-info-circle" title="Treat this domain as a 2D domain"></i></label>
<div class="input-group">
<div class="btn-group" role="group">
<input type="radio" class="btn-check" name="flatten" id="flatten_yes" value="1" required @if(old('flatten',$o->flatten))checked @endif>
<label class="btn btn-outline-warning" for="flatten_yes">Yes</label>
<input type="radio" class="btn-check btn-danger" name="flatten" id="flatten_no" value="0" required @if(! old('flatten',$o->flatten))checked @endif>
<label class="btn btn-outline-success" for="flatten_no">No</label>
</div>
</div>
@endif
</div>
<div class="col-4">
@if ($o->managed())
@if ($o->nodelist_filename)