Add IP Aliasing (#72)

* complete support for IP Alias's throughout panel

Includes a database change and probably better allocation handling
anyways

closes #37
This commit is contained in:
Dane Everitt 2016-08-31 16:03:37 -04:00 committed by GitHub
parent f1a3008a50
commit e8c175f385
14 changed files with 206 additions and 76 deletions

View file

@ -52,10 +52,17 @@ class ServersController extends Controller
public function getIndex(Request $request)
{
return view('admin.servers.index', [
'servers' => Models\Server::select('servers.*', 'nodes.name as a_nodeName', 'users.email as a_ownerEmail')
->join('nodes', 'servers.node', '=', 'nodes.id')
->join('users', 'servers.owner', '=', 'users.id')
->paginate(20),
'servers' => Models\Server::select(
'servers.*',
'nodes.name as a_nodeName',
'users.email as a_ownerEmail',
'allocations.ip',
'allocations.port',
'allocations.ip_alias'
)->join('nodes', 'servers.node', '=', 'nodes.id')
->join('users', 'servers.owner', '=', 'users.id')
->join('allocations', 'servers.allocation', '=', 'allocations.id')
->paginate(20),
]);
}
@ -76,12 +83,16 @@ class ServersController extends Controller
'locations.long as a_locationName',
'services.name as a_serviceName',
'services.executable as a_serviceExecutable',
'service_options.name as a_servceOptionName'
'service_options.name as a_servceOptionName',
'allocations.ip',
'allocations.port',
'allocations.ip_alias'
)->join('nodes', 'servers.node', '=', 'nodes.id')
->join('users', 'servers.owner', '=', 'users.id')
->join('locations', 'nodes.location', '=', 'locations.id')
->join('services', 'servers.service', '=', 'services.id')
->join('service_options', 'servers.option', '=', 'service_options.id')
->join('allocations', 'servers.allocation', '=', 'allocations.id')
->where('servers.id', $id)
->first();
@ -91,8 +102,8 @@ class ServersController extends Controller
return view('admin.servers.view', [
'server' => $server,
'assigned' => Models\Allocation::select('id', 'ip', 'port')->where('assigned_to', $id)->orderBy('ip', 'asc')->orderBy('port', 'asc')->get(),
'unassigned' => Models\Allocation::select('id', 'ip', 'port')->where('node', $server->node)->whereNull('assigned_to')->orderBy('ip', 'asc')->orderBy('port', 'asc')->get(),
'assigned' => Models\Allocation::where('assigned_to', $id)->orderBy('ip', 'asc')->orderBy('port', 'asc')->get(),
'unassigned' => Models\Allocation::where('node', $server->node)->whereNull('assigned_to')->orderBy('ip', 'asc')->orderBy('port', 'asc')->get(),
'startup' => Models\ServiceVariables::select('service_variables.*', 'server_variables.variable_value as a_serverValue')
->join('server_variables', 'server_variables.variable_id', '=', 'service_variables.id')
->where('service_variables.option_id', $server->option)

View file

@ -194,9 +194,11 @@ class AjaxController extends Controller
{
$server = Server::getByUUID($uuid);
$allocation = Models\Allocation::findOrFail($server->allocation);
$this->authorize('set-connection', $server);
if ($request->input('connection') === $server->ip . ':' . $server->port) {
if ($request->input('connection') === $allocation->ip . ':' . $allocation->port) {
return response()->json([
'error' => 'You are already using this as your default connection.'
], 409);

View file

@ -195,11 +195,8 @@ class ServerController extends Controller
public function getSettings(Request $request, $uuid)
{
$server = Models\Server::getByUUID($uuid);
// $variables = Models\ServiceVariables::select('service_variables.*', 'server_variables.variable_value as a_serverValue')
// ->join('server_variables', 'server_variables.variable_id', '=', 'service_variables.id')
// ->where('service_variables.option_id', $server->option)
// ->where('server_variables.server_id', $server->id)
// ->get();
$allocation = Models\Allocation::findOrFail($server->allocation);
$variables = Models\ServiceVariables::select(
'service_variables.*',
DB::raw('COALESCE(server_variables.variable_value, service_variables.default_value) as a_serverValue')
@ -217,8 +214,8 @@ class ServerController extends Controller
$serverVariables = [
'{{SERVER_MEMORY}}' => $server->memory,
'{{SERVER_IP}}' => $server->ip,
'{{SERVER_PORT}}' => $server->port,
'{{SERVER_IP}}' => $allocation->ip,
'{{SERVER_PORT}}' => $allocation->port,
];
$processed = str_replace(array_keys($serverVariables), array_values($serverVariables), $server->startup);

View file

@ -124,10 +124,16 @@ class Server extends Model
public static function getUserServers($paginate = null)
{
$query = self::select('servers.*', 'nodes.name as nodeName', 'locations.short as a_locationShort')
->join('nodes', 'servers.node', '=', 'nodes.id')
->join('locations', 'nodes.location', '=', 'locations.id')
->where('active', 1);
$query = self::select(
'servers.*',
'nodes.name as nodeName',
'locations.short as a_locationShort',
'allocations.ip_alias',
'allocations.port'
)->join('nodes', 'servers.node', '=', 'nodes.id')
->join('locations', 'nodes.location', '=', 'locations.id')
->join('allocations', 'servers.allocation', '=', 'allocations.id')
->where('active', 1);
if (self::$user->root_admin !== 1) {
$query->whereIn('servers.id', Subuser::accessServers());

View file

@ -213,8 +213,7 @@ class ServerRepository
'io' => $data['io'],
'cpu' => $data['cpu'],
'oom_disabled' => (isset($data['oom_disabled'])) ? true : false,
'ip' => $data['ip'],
'port' => $data['port'],
'allocation' => $allocation->id,
'service' => $data['service'],
'option' => $data['option'],
'startup' => $data['startup'],
@ -253,11 +252,11 @@ class ServerRepository
'user' => $server->username,
'build' => [
'default' => [
'ip' => $server->ip,
'port' => (int) $server->port
'ip' => $allocation->ip,
'port' => (int) $allocation->port
],
'ports' => [
(string) $server->ip => [ (int) $server->port ]
(string) $allocation->ip => [ (int) $allocation->port ]
],
'env' => $environmentVariables,
'memory' => (int) $server->memory,
@ -413,17 +412,20 @@ class ServerRepository
try {
$server = Models\Server::findOrFail($id);
$allocation = Models\Allocation::findOrFail($server->allocation);
if (isset($data['default'])) {
list($ip, $port) = explode(':', $data['default']);
if ($ip !== $server->ip || $port !== $server->port) {
$allocation = Models\Allocation::where('ip', $ip)->where('port', $port)->where('assigned_to', $server->id)->first();
if (!$allocation) {
if ($ip !== $allocation->ip || $port !== $allocation->port) {
$selection = Models\Allocation::where('ip', $ip)->where('port', $port)->where('assigned_to', $server->id)->first();
if (!$selection) {
throw new DisplayException('The requested default connection (' . $ip . ':' . $port . ') is not allocated to this server.');
}
$server->ip = $ip;
$server->port = $port;
$server->allocation = $selection->id;
// Re-Run to keep updated for rest of function
$allocation = Models\Allocation::findOrFail($server->allocation);
}
}
@ -437,7 +439,7 @@ class ServerRepository
}
// Can't remove the assigned IP/Port combo
if ($ip === $server->ip && $port === $server->port) {
if ($ip === $allocation->ip && $port === $allocation->port) {
continue;
}
@ -513,8 +515,8 @@ class ServerRepository
'json' => [
'build' => [
'default' => [
'ip' => $server->ip,
'port' => (int) $server->port
'ip' => $allocation->ip,
'port' => (int) $allocation->port
],
'ports|overwrite' => $additionalAssignments,
'memory' => (int) $server->memory,