Added packet debug on web UI
This commit is contained in:
@@ -86,13 +86,44 @@ class Address extends Model
|
||||
* Find a record in the DB for a node string, eg: 10:1/1.0
|
||||
*
|
||||
* @param string $ftn
|
||||
* @return Node|null
|
||||
* @return Address|null
|
||||
* @throws Exception
|
||||
*/
|
||||
public static function findFTN(string $ftn): ?self
|
||||
{
|
||||
$matches = [];
|
||||
$ftn = self::parseFTN($ftn);
|
||||
|
||||
$o = (new self)->active()
|
||||
->select('addresses.*')
|
||||
->where('zones.zone_id',$ftn['z'])
|
||||
->where('host_id',$ftn['h'])
|
||||
->join('zones',['zones.id'=>'addresses.zone_id'])
|
||||
->join('domains',['domains.id'=>'zones.domain_id'])
|
||||
->where('zones.active',TRUE)
|
||||
->where('domains.active',TRUE)
|
||||
->where('addresses.active',TRUE)
|
||||
->where('node_id',$ftn['f'])
|
||||
->where('point_id',$ftn['p'])
|
||||
->when($ftn['d'],function($query,$domain) {
|
||||
$query->where('domains.name',$domain);
|
||||
})
|
||||
->when((! $ftn['d']),function($query) {
|
||||
$query->where('domains.default',TRUE);
|
||||
})
|
||||
->single();
|
||||
|
||||
return ($o && $o->system->active) ? $o : NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse a string and split it out as an FTN array
|
||||
*
|
||||
* @param string $ftn
|
||||
* @return array
|
||||
* @throws Exception
|
||||
*/
|
||||
public static function parseFTN(string $ftn): array
|
||||
{
|
||||
// http://ftsc.org/docs/frl-1028.002
|
||||
if (! preg_match('#^([0-9]+):([0-9]+)/([0-9]+)(.([0-9]+))?(@([a-z0-9\-_~]{0,8}))?$#',strtolower($ftn),$matches))
|
||||
throw new Exception('Invalid FTN: '.$ftn);
|
||||
@@ -102,29 +133,17 @@ class Address extends Model
|
||||
if (! $matches[$i] || ($matches[$i] > DomainController::NUMBER_MAX))
|
||||
throw new Exception('Invalid FTN: '.$ftn);
|
||||
}
|
||||
|
||||
if (isset($matches[5]) AND $matches[5] > DomainController::NUMBER_MAX)
|
||||
throw new Exception('Invalid FTN: '.$ftn);
|
||||
|
||||
$o = (new self)->active()
|
||||
->select('addresses.*')
|
||||
->where('zones.zone_id',$matches[1])
|
||||
->where('host_id',$matches[2])
|
||||
->join('zones',['zones.id'=>'addresses.zone_id'])
|
||||
->join('domains',['domains.id'=>'zones.domain_id'])
|
||||
->where('zones.active',TRUE)
|
||||
->where('domains.active',TRUE)
|
||||
->where('addresses.active',TRUE)
|
||||
->where('node_id',$matches[3])
|
||||
->where('point_id',(isset($matches[5]) AND $matches[5]) ? $matches[5] : 0)
|
||||
->when(isset($matches[7]),function($query) use ($matches) {
|
||||
$query->where('domains.name',$matches[7]);
|
||||
})
|
||||
->when((! isset($matches[7]) OR ! $matches[7]),function($query) {
|
||||
$query->where('domains.default',TRUE);
|
||||
})
|
||||
->single();
|
||||
|
||||
return ($o && $o->system->active) ? $o : NULL;
|
||||
return [
|
||||
'z'=>(int)$matches[1],
|
||||
'n'=>(int)$matches[2],
|
||||
'f'=>(int)$matches[3],
|
||||
'p'=>isset($matches[5]) && $matches[5] ? (int)$matches[5] : 0,
|
||||
'd'=>$matches[7] ?? NULL
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -4,6 +4,24 @@ namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
use App\Traits\ScopeActive;
|
||||
|
||||
class Software extends Model
|
||||
{
|
||||
use ScopeActive;
|
||||
|
||||
public const SOFTWARE_MAILER = 0x01;
|
||||
public const SOFTWARE_TOSSER = 0x02;
|
||||
|
||||
/* ATTRIBUTES */
|
||||
|
||||
public function getCodeAttribute($value)
|
||||
{
|
||||
return sprintf('%04X',$value);
|
||||
}
|
||||
|
||||
public function getNameAttribute($value)
|
||||
{
|
||||
return $value ?: 'Unknown';
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user