Added packet debug on web UI

This commit is contained in:
Deon George
2021-06-29 20:43:29 +10:00
parent dc86f7c008
commit 987b4040fb
17 changed files with 1095 additions and 792 deletions

View File

@@ -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
];
}
/**