Move DomainController::NODE* to Address::NODE*, make role mandatory in the database, change logic so that mail generated by the host comes from a node address.

This commit is contained in:
Deon George
2022-01-24 22:56:13 +11:00
parent efa7195633
commit d660d5a6df
15 changed files with 143 additions and 110 deletions

View File

@@ -9,17 +9,6 @@ use App\Models\{Address,Domain,Zone};
class DomainController extends Controller
{
public const NODE_ACTIVE = 0; // Active
public const NODE_ZC = 1<<0; // Zone
public const NODE_RC = 1<<1; // Region
public const NODE_NC = 1<<2; // Host
public const NODE_HC = 1<<3; // Hub
public const NODE_POINT = 1<<4; // Point
public const NODE_PVT = 1<<5; // Pvt
public const NODE_HOLD = 1<<6; // Hold
public const NODE_DOWN = 1<<7; // Down
public const NODE_UNKNOWN = 1<<8; // Down
// http://ftsc.org/docs/frl-1002.001
public const NUMBER_MAX = 0x7fff;
@@ -65,7 +54,7 @@ class DomainController extends Controller
*/
public function api_hosts(Zone $o,int $region): Collection
{
$oo = Address::where('role',self::NODE_NC)
$oo = Address::where('role',Address::NODE_NC)
->where('zone_id',$o->id)
->when($region,function($query,$region) { return $query->where('region_id',$region)->where('node_id',0); })
->when((! $region),function($query) use ($region) { return $query->where('region_id',0); })
@@ -107,7 +96,7 @@ class DomainController extends Controller
*/
public function api_regions(Zone $o): Collection
{
$oo = Address::where('role',self::NODE_RC)
$oo = Address::where('role',Address::NODE_RC)
->where('zone_id',$o->id)
->where('node_id',0)
->where('point_id',0)

View File

@@ -53,13 +53,13 @@ class SystemController extends Controller
->where('host_id',0)
->where('node_id',0)
->where('point_id',0)
->where('role',DomainController::NODE_RC);
->where('role',Address::NODE_RC);
})
// Check that a host doesnt already exist
->orWhere(function($query) use ($value) {
return $query->where('host_id',$value)
->where('point_id',0)
->where('role',DomainController::NODE_NC);
->where('role',Address::NODE_NC);
});
if ($o->count()) {
@@ -75,7 +75,7 @@ class SystemController extends Controller
$oo->host_id = 0;
$oo->node_id = 0;
$oo->point_id = 0;
$oo->role = DomainController::NODE_RC;
$oo->role = Address::NODE_RC;
$oo->active = TRUE;
$o->addresses()->save($oo);
@@ -92,12 +92,12 @@ class SystemController extends Controller
$o = Address::where(function($query) use ($value) {
return $query->where(function($query) use ($value) {
return $query->where('region_id',$value)
->where('role',DomainController::NODE_RC);
->where('role',Address::NODE_RC);
})
// Check that a host doesnt already exist
->orWhere(function($query) use ($value) {
return $query->where('host_id',$value)
->where('role',DomainController::NODE_NC);
->where('role',Address::NODE_NC);
});
})
->where('zone_id',$request->post('zone_id'))
@@ -119,7 +119,7 @@ class SystemController extends Controller
->where('host_id',$request->post('host_id_new'))
->where('node_id',$value)
->where('point_id',0)
->where('role',DomainController::NODE_RC);
->where('role',Address::NODE_RC);
});
if ($o->count()) {
@@ -147,7 +147,7 @@ class SystemController extends Controller
'host_id'=>$request->host_id_new,
'node_id'=>0,
'point_id'=>0,
'role'=>DomainController::NODE_NC,
'role'=>Address::NODE_NC,
]);
}
@@ -161,7 +161,7 @@ class SystemController extends Controller
$oo->host_id = $request->post('host_id_new');
$oo->node_id = $request->post('node_id_new');
$oo->point_id = 0;
$oo->role = DomainController::NODE_NC;
$oo->role = Address::NODE_NC;
$oo->active = TRUE;
$o->addresses()->save($oo);
@@ -204,7 +204,7 @@ class SystemController extends Controller
$oo->node_id = $request->post('node_id');
$oo->point_id = $request->post('point_id');
$oo->hub_id = $request->post('hub_id') > 0 ? $request->post('hub_id') : NULL;
$oo->role = (! $oo->point_id) && $request->post('hub') ? DomainController::NODE_HC : NULL;
$oo->role = (! $oo->point_id) && $request->post('hub') ? Address::NODE_HC : Address::NODE_ACTIVE;
$oo->active = TRUE;
$o->addresses()->save($oo);
@@ -242,7 +242,7 @@ class SystemController extends Controller
$zo = Zone::findOrFail($validate['zone_id']);
// If this session is for the ZC, it now becomes the default.
if (in_array(DomainController::NODE_ZC,$o->match($zo)->pluck('role')->toArray())) {
if ($o->match($zo,Address::NODE_ZC)->count()) {
SystemZone::where('default',TRUE)->update(['default'=>FALSE]);
$validate['default'] = TRUE;
}

View File

@@ -93,7 +93,7 @@ class ZoneController extends Controller
'host_id'=>0,
'node_id'=>0,
'point_id'=>0,
'role'=>DomainController::NODE_ZC,
'role'=>Address::NODE_ZC,
]);
}
@@ -121,7 +121,7 @@ class ZoneController extends Controller
$default = $o->systems->where('pivot.default',TRUE);
if ($default->count() && $default->first()->addresses->pluck('role')->search(DomainController::NODE_ZC) !== FALSE)
if ($default->count() && $default->first()->addresses->pluck('role')->search(Address::NODE_ZC) !== FALSE)
abort(412);
if ($default->count() && ($default->first()->id != $request->sid))