예제 #1
0
 public function view(Request $request, $id)
 {
     $service = Models\Service::find($id);
     if (!$service) {
         throw new NotFoundHttpException('No service by that ID was found.');
     }
     $options = Models\ServiceOptions::select('id', 'name', 'description', 'tag', 'docker_image')->where('parent_service', $service->id)->get();
     foreach ($options as &$opt) {
         $opt->variables = Models\ServiceVariables::where('option_id', $opt->id)->get();
     }
     return ['service' => $service, 'options' => $options];
 }
예제 #2
0
 public function delete($id)
 {
     $option = Models\ServiceOptions::findOrFail($id);
     $servers = Models\Server::where('option', $option->id)->get();
     if (count($servers) !== 0) {
         throw new DisplayException('You cannot delete an option that has servers attached to it currently.');
     }
     DB::beginTransaction();
     try {
         Models\ServiceVariables::where('option_id', $option->id)->delete();
         $option->delete();
         DB::commit();
     } catch (\Exception $ex) {
         DB::rollBack();
         throw $ex;
     }
 }
예제 #3
0
 public function delete($id)
 {
     $service = Models\Service::findOrFail($id);
     $servers = Models\Server::where('service', $service->id)->get();
     $options = Models\ServiceOptions::select('id')->where('parent_service', $service->id);
     if (count($servers) !== 0) {
         throw new DisplayException('You cannot delete a service that has servers associated with it.');
     }
     DB::beginTransaction();
     try {
         Models\ServiceVariables::whereIn('option_id', $options->get()->toArray())->delete();
         $options->delete();
         $service->delete();
         DB::commit();
     } catch (\Exception $ex) {
         DB::rollBack();
         throw $ex;
     }
 }
예제 #4
0
 /**
  * Renders server settings page.
  *
  * @param  \Illuminate\Http\Request $request
  * @return \Illuminate\Contracts\View\View
  */
 public function getSettings(Request $request, $uuid)
 {
     $server = Models\Server::getByUUID($uuid);
     $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'))->leftJoin('server_variables', 'server_variables.variable_id', '=', 'service_variables.id')->where('service_variables.option_id', $server->option)->where('server_variables.server_id', $server->id)->get();
     $service = Models\Service::select(DB::raw('IFNULL(service_options.executable, services.executable) as executable'))->leftJoin('service_options', 'service_options.parent_service', '=', 'services.id')->where('service_options.id', $server->option)->where('services.id', $server->service)->first();
     $serverVariables = ['{{SERVER_MEMORY}}' => $server->memory, '{{SERVER_IP}}' => $allocation->ip, '{{SERVER_PORT}}' => $allocation->port];
     $processed = str_replace(array_keys($serverVariables), array_values($serverVariables), $server->startup);
     foreach ($variables as &$variable) {
         $replace = $variable->user_viewable === 1 ? $variable->a_serverValue : '**';
         $processed = str_replace('{{' . $variable->env_variable . '}}', $replace, $processed);
     }
     return view('server.settings', ['server' => $server, 'databases' => Models\Database::select('databases.*', 'database_servers.host as a_host', 'database_servers.port as a_port')->where('server_id', $server->id)->join('database_servers', 'database_servers.id', '=', 'databases.db_server')->get(), 'node' => Models\Node::find($server->node), 'variables' => $variables->where('user_viewable', 1), 'service' => $service, 'processedStartup' => $processed]);
 }
예제 #5
0
 private function addVariables()
 {
     Models\ServiceVariables::create(['option_id' => $this->option['mumble']->id, 'name' => 'Maximum Users', 'description' => 'Maximum concurrent users on the mumble server.', 'env_variable' => 'MAX_USERS', 'default_value' => '100', 'user_viewable' => 1, 'user_editable' => 0, 'required' => 1, 'regex' => '/^(\\d){1,6}$/']);
     Models\ServiceVariables::create(['option_id' => $this->option['mumble']->id, 'name' => 'Server Version', 'description' => 'Version of Mumble Server to download and use.', 'env_variable' => 'MUMBLE_VERSION', 'default_value' => '1.2.16', 'user_viewable' => 1, 'user_editable' => 1, 'required' => 1, 'regex' => '/^([0-9_\\.-]{5,8})$/']);
     Models\ServiceVariables::create(['option_id' => $this->option['ts3']->id, 'name' => 'Server Version', 'description' => 'The version of Teamspeak 3 to use when running the server.', 'env_variable' => 'T_VERSION', 'default_value' => '3.0.13.4', 'user_viewable' => 1, 'user_editable' => 1, 'required' => 1, 'regex' => '/^([0-9_\\.-]{5,10})$/']);
 }
 private function addVariables()
 {
     Models\ServiceVariables::create(['option_id' => $this->option['tshock']->id, 'name' => 'TShock Version', 'description' => 'Which version of TShock to install and use.', 'env_variable' => 'T_VERSION', 'default_value' => '4.3.17', 'user_viewable' => 1, 'user_editable' => 1, 'required' => 1, 'regex' => '/^([0-9_\\.-]{5,10})$/']);
     Models\ServiceVariables::create(['option_id' => $this->option['tshock']->id, 'name' => 'Maximum Slots', 'description' => 'Total number of slots to allow on the server.', 'env_variable' => 'MAX_SLOTS', 'default_value' => '20', 'user_viewable' => 1, 'user_editable' => 0, 'required' => 1, 'regex' => '/^(\\d){1,3}$/']);
 }
예제 #7
0
 public function updateStartup($id, array $data, $admin = false)
 {
     $server = Models\Server::findOrFail($id);
     DB::beginTransaction();
     try {
         // Check the startup
         if (isset($data['startup'])) {
             $server->startup = $data['startup'];
             $server->save();
         }
         // Check those Variables
         $variables = Models\ServiceVariables::select('service_variables.*', DB::raw('COALESCE(server_variables.variable_value, service_variables.default_value) as a_currentValue'))->leftJoin('server_variables', 'server_variables.variable_id', '=', 'service_variables.id')->where('option_id', $server->option)->get();
         $variableList = [];
         if ($variables) {
             foreach ($variables as &$variable) {
                 // Move on if the new data wasn't even sent
                 if (!isset($data[$variable->env_variable])) {
                     $variableList = array_merge($variableList, [['id' => $variable->id, 'env' => $variable->env_variable, 'val' => $variable->a_currentValue]]);
                     continue;
                 }
                 // Update Empty but skip validation
                 if (empty($data[$variable->env_variable])) {
                     $variableList = array_merge($variableList, [['id' => $variable->id, 'env' => $variable->env_variable, 'val' => null]]);
                     continue;
                 }
                 // Is the variable required?
                 // @TODO: is this even logical to perform this check?
                 if (isset($data[$variable->env_variable]) && empty($data[$variable->env_variable])) {
                     if ($variable->required === 1) {
                         throw new DisplayException('A required service option variable field (' . $variable->env_variable . ') was included in this request but was left blank.');
                     }
                 }
                 // Variable hidden and/or not user editable
                 if (($variable->user_viewable === 0 || $variable->user_editable === 0) && !$admin) {
                     throw new DisplayException('A service option variable field (' . $variable->env_variable . ') does not exist or you do not have permission to edit it.');
                 }
                 // Check aganist Regex Pattern
                 if (!is_null($variable->regex) && !preg_match($variable->regex, $data[$variable->env_variable])) {
                     throw new DisplayException('Failed to validate service option variable field (' . $variable->env_variable . ') aganist regex (' . $variable->regex . ').');
                 }
                 $variableList = array_merge($variableList, [['id' => $variable->id, 'env' => $variable->env_variable, 'val' => $data[$variable->env_variable]]]);
             }
         }
         // Add Variables
         $environmentVariables = [];
         $environmentVariables = array_merge($environmentVariables, ['STARTUP' => $server->startup]);
         foreach ($variableList as $item) {
             $environmentVariables = array_merge($environmentVariables, [$item['env'] => $item['val']]);
             // Update model or make a new record if it doesn't exist.
             $model = Models\ServerVariables::firstOrNew(['variable_id' => $item['id'], 'server_id' => $server->id]);
             $model->variable_value = $item['val'];
             $model->save();
         }
         $node = Models\Node::getByID($server->node);
         $client = Models\Node::guzzleRequest($server->node);
         $client->request('PATCH', '/server', ['headers' => ['X-Access-Server' => $server->uuid, 'X-Access-Token' => $node->daemonSecret], 'json' => ['build' => ['env|overwrite' => $environmentVariables]]]);
         DB::commit();
         return true;
     } catch (\GuzzleHttp\Exception\TransferException $ex) {
         DB::rollBack();
         throw new DisplayException('An error occured while attempting to update the server configuration.', $ex);
     } catch (\Exception $ex) {
         DB::rollBack();
         throw $ex;
     }
 }
 private function addCustomVariables()
 {
     Models\ServiceVariables::create(['option_id' => $this->option['custom']->id, 'name' => 'Game ID', 'description' => 'The ID corresponding to the game to download and run using SRCDS.', 'env_variable' => 'SRCDS_APPID', 'default_value' => '', 'user_viewable' => 1, 'user_editable' => 0, 'required' => 1, 'regex' => '/^(\\d){1,6}$/']);
     Models\ServiceVariables::create(['option_id' => $this->option['custom']->id, 'name' => 'Game Name', 'description' => 'The name corresponding to the game to download and run using SRCDS.', 'env_variable' => 'SRCDS_GAME', 'default_value' => '', 'user_viewable' => 1, 'user_editable' => 0, 'required' => 1, 'regex' => '/^(.*)$/']);
 }
 private function addBungeecordVariables()
 {
     Models\ServiceVariables::create(['option_id' => $this->option['bungeecord']->id, 'name' => 'Bungeecord Version', 'description' => 'The version of Bungeecord to download and use.', 'env_variable' => 'BUNGE_VERSION', 'default_value' => 'latest', 'user_viewable' => 1, 'user_editable' => 1, 'required' => 1, 'regex' => '/^(latest|[\\d]{3,5})$/']);
     Models\ServiceVariables::create(['option_id' => $this->option['bungeecord']->id, 'name' => 'Bungeecord Jar File', 'description' => 'The name of the Jarfile to use when running Bungeecord.', 'env_variable' => 'SERVER_JARFILE', 'default_value' => 'bungeecord.jar', 'user_viewable' => 1, 'user_editable' => 1, 'required' => 1, 'regex' => '/^([\\w\\d._-]+)(\\.jar)$/']);
 }
예제 #10
0
 /**
  * Returns a JSON tree of all avaliable variables for a given service option.
  *
  * @param  \Illuminate\Http\Request $request
  * @return \Illuminate\Contracts\View\View
  */
 public function postNewServerServiceVariables(Request $request)
 {
     if (!$request->input('option')) {
         return response()->json(['error' => 'Missing option in request.'], 500);
     }
     $option = Models\ServiceOptions::select(DB::raw('COALESCE(service_options.executable, services.executable) as executable'), DB::raw('COALESCE(service_options.startup, services.startup) as startup'))->leftJoin('services', 'services.id', '=', 'service_options.parent_service')->where('service_options.id', $request->input('option'))->first();
     return response()->json(['variables' => Models\ServiceVariables::where('option_id', $request->input('option'))->get(), 'exec' => $option->executable, 'startup' => $option->startup]);
 }
예제 #11
0
 public function getOption(Request $request, $service, $option)
 {
     $opt = Models\ServiceOptions::findOrFail($option);
     return view('admin.services.options.view', ['service' => Models\Service::findOrFail($opt->parent_service), 'option' => $opt, 'variables' => Models\ServiceVariables::where('option_id', $option)->get(), 'servers' => Models\Server::select('servers.*', 'users.email as a_ownerEmail')->join('users', 'users.id', '=', 'servers.owner')->where('option', $option)->paginate(10)]);
 }