Abstract address session() details

This commit is contained in:
Deon George 2024-06-14 15:09:04 +10:00
parent 0304967e80
commit df2873287c
14 changed files with 70 additions and 29 deletions

View File

@ -372,7 +372,7 @@ abstract class Packet extends FTNBase implements \Iterator, \Countable
'H' => $date->format('H'), // Hour
'M' => $date->format('i'), // Minute
'S' => $date->format('s'), // Second
'password' => strtoupper((! is_null($passwd)) ? $passwd : $o->session('pktpass')), // Packet Password
'password' => strtoupper((! is_null($passwd)) ? $passwd : $o->pass_packet), // Packet Password
];
}
@ -505,7 +505,7 @@ abstract class Packet extends FTNBase implements \Iterator, \Countable
public function password(string $password=NULL): self
{
if ($password && (strlen($password) < 9))
$this->pass_p = $password;
$this->pass_p = strtoupper($password);
return $this;
}

View File

@ -82,7 +82,7 @@ final class FSC39 extends Packet
$this->tftn_p->host_id, // Dest Net
(Setup::PRODUCT_ID & 0xff), // Product Code Lo
Setup::PRODUCT_VERSION_MAJ, // Product Version Major
$this->pass_p ?: $this->tftn_p->session('pktpass'), // Packet Password
$this->pass_p ?: $this->tftn_p->pass_packet, // Packet Password
$this->fftn_p->zone->zone_id, // Orig Zone
$this->tftn_p->zone->zone_id, // Dest Zone
'', // Reserved

View File

@ -69,7 +69,7 @@ final class FSC45 extends Packet
$this->tftn_p->host_id, // Dest Net
(Setup::PRODUCT_ID & 0xff), // Product Code
Setup::PRODUCT_VERSION_MAJ, // Product Version
$this->pass_p ?: $this->tftn_p->session('pktpass'), // Packet Password
$this->pass_p ?: $this->tftn_p->pass_packet, // Packet Password
$this->fftn_p->zone->zone_id, // Orig Zone
$this->tftn_p->zone->zone_id, // Dest Zone
$this->fftn_p->zone->domain->name, // Orig Domain

View File

@ -82,7 +82,7 @@ final class FSC48 extends Packet
$this->tftn_p->host_id, // Dest Net
(Setup::PRODUCT_ID & 0xff), // Product Code Lo
Setup::PRODUCT_VERSION_MAJ, // Product Version Major
$this->pass_p ?: $this->tftn_p->session('pktpass'), // Packet Password
$this->pass_p ?: $this->tftn_p->pass_packet, // Packet Password
$this->fftn_p->zone->zone_id, // Orig Zone
$this->tftn_p->zone->zone_id, // Dest Zone
$this->fftn_p->point_id ? $this->fftn_p->host_id : 0x00, // Aux Net

View File

@ -75,7 +75,7 @@ final class FTS1 extends Packet
$this->tftn_p->host_id, // Dest Net
(Setup::PRODUCT_ID & 0xff), // Product Code Lo
Setup::PRODUCT_VERSION_MAJ, // Product Version Major
$this->pass_p ?: $this->tftn_p->session('pktpass'), // Packet Password
$this->pass_p ?: $this->tftn_p->pass_packet, // Packet Password
$this->fftn_p->zone->zone_id, // Orig Zone
$this->tftn_p->zone->zone_id, // Dest Zone
'', // Reserved

View File

@ -106,7 +106,7 @@ class Tic extends FTNBase
$result->put('REPLACES',$this->file->replaces);
$result->put('AREA',$this->file->filearea->name);
$result->put('AREADESC',$this->file->filearea->description);
if ($x=strtoupper($this->to->session('ticpass')))
if ($x=$this->to->pass_tic)
$result->put('PW',$x);
$result->put('CRC',sprintf("%X",$this->file->crc));
@ -351,7 +351,7 @@ class Tic extends FTNBase
throw new SizeMismatchException(sprintf('TIC file size [%d] doesnt match file [%s] (%d)',$this->file->size,$fs->path($rel_path_name),$y));
// Validate Password
if (strtoupper($pw) !== ($y=strtoupper($this->file->fftn->session('ticpass'))))
if (strtoupper($pw) !== ($y=$this->file->fftn->pass_tic))
throw new InvalidPasswordException(sprintf('TIC file PASSWORD [%s] doesnt match system [%s] (%s)',$pw,$this->file->fftn->ftn,$y));
// Validate Sender is linked

View File

@ -86,9 +86,9 @@ class Node
case 'password':
// If we have already authed, we'll use that password.
if ($this->ftns_authed->count())
return $this->ftns_authed->first()->session('sespass');
return $this->ftns_authed->first()->pass_session;
else
return ($this->ftns->count() && ($x=$this->ftns->first()->session('sespass'))) ? $x : '-';
return ($this->ftns->count() && ($x=$this->ftns->first()->pass_session)) ? $x : '-';
// Return how long our session has been connected
case 'session_time':
@ -194,7 +194,7 @@ class Node
throw new Exception('Already authed');
foreach ($this->ftns as $o) {
if (! $sespass=$o->session('sespass'))
if (! $sespass=$o->pass_session)
continue;
// If we have challenge, then we are doing MD5

View File

@ -575,7 +575,7 @@ class SystemController extends Controller
session()->flash('accordion','filearea');
// Ensure we have session details for this address.
if (! $ao->session('sespass'))
if (! $ao->pass_session)
return redirect()->back()->withErrors('System doesnt belong to this network');
$ao->fileareas()->syncWithPivotValues($request->get('id',[]),['subscribed'=>Carbon::now()]);

View File

@ -95,7 +95,7 @@ class PacketProcess implements ShouldQueue
}
// Check the packet password
if (strtoupper($pkt->fftn->session('pktpass')) !== strtoupper($pkt->password)) {
if ($pkt->fftn->pass_packet !== strtoupper($pkt->password)) {
Log::error(sprintf('%s:! Packet from [%s] with password [%s] is invalid.',self::LOGKEY,$pkt->fftn->ftn,$pkt->password));
Notification::route('netmail',$pkt->fftn)->notify(new PacketPasswordInvalid($pkt->password,$f->pktName()));

View File

@ -40,7 +40,6 @@ use App\Traits\{QueryCacheableConfig,ScopeActive};
class Address extends Model
{
use QueryCacheableConfig,ScopeActive,SoftDeletes;
const CACHE_KEY = 0;
private const LOGKEY = 'MA-';
@ -386,6 +385,18 @@ class Address extends Model
->FTNorder();
}
/**
* Select to support returning FTN address
*
* @param $query
* @return void
*/
public function scopeFTN($query)
{
return $query->select(['zone_id','host_id','node_id','point_id'])
->with('zone.domain');
}
public function scopeFTNOrder($query)
{
return $query
@ -744,11 +755,21 @@ class Address extends Model
return sprintf('%s.%d',$this->getFTN3DAttribute(),$this->point_id);
}
public function getIsDefaultRouteAttribute(): bool
{
return ! is_null($this->session('default'));
}
public function getIsDownAttribute(): bool
{
return $this->role & self::NODE_DOWN;
}
public function getIsHostedAttribute(): bool
{
return ! is_null($this->getPassSessionAttribute());
}
public function getIsHoldAttribute(): bool
{
return $this->role & self::NODE_HOLD;
@ -816,6 +837,26 @@ class Address extends Model
}
}
public function getPassFixAttribute(): ?string
{
return strtoupper($this->session('fixpass'));
}
public function getPassPacketAttribute(): ?string
{
return strtoupper($this->session('pktpass'));
}
public function getPassSessionAttribute(): ?string
{
return $this->session('sespass');
}
public function getPassTicAttribute(): ?string
{
return strtoupper($this->session('ticpass'));
}
/* METHODS */
/**
@ -902,11 +943,11 @@ class Address extends Model
public function downlinks(): Collection
{
// We have no session data for this address, by definition it has no children
if (! $this->session('sespass') && (! our_address()->pluck('id')->contains($this->id)))
if (! $this->is_hosted && (! our_address()->pluck('id')->contains($this->id)))
return new Collection;
// If this system is not marked to default route for this address
if (! $this->session('default')) {
if (! $this->is_default_route) {
$children = $this->children();
// We route everything for this domain
@ -1284,7 +1325,7 @@ class Address extends Model
* @param string $type
* @return string|null
*/
public function session(string $type): ?string
private function session(string $type): ?string
{
return ($this->exists && ($x=$this->system->sessions->where('id',$this->zone_id)->first())) ? ($x->pivot->{$type} ?: '') : NULL;
}
@ -1302,7 +1343,7 @@ class Address extends Model
return NULL;
// If we have session password, then we are the parent
if ($x=$this->session('sespass'))
if ($this->is_hosted)
return $this;
if ($x=$this->parent()?->uplink()) {

View File

@ -134,7 +134,7 @@
@foreach ($o->zones->sortBy('zone_id') as $oz)
@foreach ($oz->addresses as $ao)
<tr>
<td><a href="{{ url('system/addedit',[$ao->system_id]) }}">{{ $ao->system->full_name($ao) }}</a> @auth<span class="float-end"><small>@if($ao->session('sespass'))<sup>{{ $ao->session('default') ? '**' : '*' }}</sup>@elseif($ao->system->setup)<sup class="success">+</sup>@endif[{{ $ao->system_id }}]</small></span>@endauth</td>
<td><a href="{{ url('system/addedit',[$ao->system_id]) }}">{{ $ao->system->full_name($ao) }}</a> @auth<span class="float-end"><small>@if($ao->is_hosted)<sup>{{ $ao->is_default ? '**' : '*' }}</sup>@elseif($ao->system->setup)<sup class="success">+</sup>@endif[{{ $ao->system_id }}]</small></span>@endauth</td>
<td>{{ $ao->system->sysop }}</td>
<td>{{ $ao->system->location }}</td>
<td>{{ $ao->ftn4d }}</td>

View File

@ -178,7 +178,7 @@
<tbody>
@foreach ($o->addresses as $ao)
<tr>
<td><a href="{{ url('system/addedit',[$ao->system_id]) }}">{{ $ao->system->full_name($ao) }}</a> @auth<span class="float-end"><small>@if($ao->session('sespass'))<sup>{{ $ao->session('default') ? '**' : '*' }}</sup>@elseif($ao->system->setup)<sup class="success">+</sup>@endif[{{ $ao->system_id }}]</small></span>@endauth</td>
<td><a href="{{ url('system/addedit',[$ao->system_id]) }}">{{ $ao->system->full_name($ao) }}</a> @auth<span class="float-end"><small>@if($ao->is_hosted)<sup>{{ $ao->is_default ? '**' : '*' }}</sup>@elseif($ao->system->setup)<sup class="success">+</sup>@endif[{{ $ao->system_id }}]</small></span>@endauth</td>
<td>{{ $ao->ftn_3d }}</td>
<td>{{ $ao->system->last_session ? $ao->system->last_session->format('Y-m-d H:i') : '-' }}</td>
<td>{{ ($x=$o->waiting($ao))->count() ? $x->first()->datetime->format('Y-m-d H:i') : '-' }}</td>

View File

@ -57,7 +57,7 @@
<label for="subject" class="form-label">Subject</label>
<div class="input-group">
<span class="input-group-text @error('subject') is-invalid @enderror"><i class="bi bi-wifi"></i></span>
<input type="text" class="form-control" id="subject" placeholder="Areafix Password" name="subject" value="{{ old('subject',$ao->session('fixpass')) }}">
<input type="text" class="form-control" id="subject" placeholder="Areafix Password" name="subject" value="{{ old('subject',$ao->pass_fix) }}">
<span class="invalid-feedback" role="alert">
@error('subject')
{{ $message }}

View File

@ -62,7 +62,7 @@ Move Address
</span>
</div>
@if ($o->session('sespass'))
@if ($o->is_hosted)
<div class="col-3" id="session-remove">
<label for="remsess" class="form-label">Remove Session Details for Zone</label>
<div class="input-group has-validation">
@ -119,7 +119,7 @@ Move Address
$(document).ready(function() {
$('#system_id').select2();
@if ($o->session('sespass'))
@if ($o->is_hosted)
$('#remove_yes').on('change',function() {
if (! $('#session-remove').hasClass('d-none'))
$('#session-remove').addClass('d-none');