Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- {{-- Copyright (c) 2015 - 2016 Dane Everitt <dane@daneeveritt.com> --}}
- {{-- Permission is hereby granted, free of charge, to any person obtaining a copy --}}
- {{-- of this software and associated documentation files (the "Software"), to deal --}}
- {{-- in the Software without restriction, including without limitation the rights --}}
- {{-- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell --}}
- {{-- copies of the Software, and to permit persons to whom the Software is --}}
- {{-- furnished to do so, subject to the following conditions: --}}
- {{-- The above copyright notice and this permission notice shall be included in all --}}
- {{-- copies or substantial portions of the Software. --}}
- {{-- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR --}}
- {{-- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, --}}
- {{-- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE --}}
- {{-- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER --}}
- {{-- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, --}}
- {{-- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE --}}
- {{-- SOFTWARE. --}}
- @extends('layouts.master')
- @section('title')
- Server Settings
- @endsection
- @section('scripts')
- @parent
- {!! Theme::js('js/vendor/typeahead/typeahead.min.js') !!}
- @endsection
- @section('content')
- <div class="col-md-12">
- <h3 class="nopad">Server Settings</h3><hr />
- <ul class="nav nav-tabs tabs_with_panel" id="config_tabs">
- @can('view-sftp', $server)<li class="active"><a href="#tab_sftp" data-toggle="tab">SFTP Settings</a></li>@endcan
- @can('view-startup', $server)<li><a href="#tab_startup" data-toggle="tab">Startup Configuration</a></li>@endcan
- @can('view-databases', $server)<li><a href="#tab_databases" data-toggle="tab">Databases</a></li>@endcan
- @can('view-databases', $server)<li><a href="#tab_mods" data-toggle="tab">Mods</a></li>@endcan
- </ul>
- <div class="tab-content">
- @can('view-sftp', $server)
- <div class="tab-pane active" id="tab_sftp">
- <div class="panel panel-default">
- <div class="panel-heading"></div>
- <div class="panel-body">
- <div class="row">
- <div class="form-group col-md-6">
- <label class="control-label">SFTP Connection Address:</label>
- <div>
- <input type="text" readonly="readonly" class="form-control" value="{{ $node->fqdn }}:{{ $node->daemonSFTP }}" />
- </div>
- </div>
- <div class="form-group col-md-6">
- <label class="control-label">SFTP Username:</label>
- <div>
- <input type="text" readonly="readonly" class="form-control" value="{{ $server->username }}" />
- </div>
- </div>
- </div>
- <div class="row">
- <div class="col-md-12">
- <div id="gen_pass" class=" alert alert-success" style="display:none;margin-bottom: 10px;"></div>
- </div>
- <div class="form-group col-md-6">
- @can('reset-sftp', $server)
- <form action="{{ route('server.settings.sftp', $server->uuidShort) }}" method="POST">
- <label class="control-label">New SFTP Password:</label>
- <div class="input-group">
- <input type="password" class="form-control" name="sftp_pass" />
- <span class="input-group-btn">
- {!! csrf_field() !!}
- <input type="submit" class="btn btn-primary btn-sm" value="Reset" />
- </span>
- </div>
- <p class="text-muted"><small>Passwords must meet the following requirements: at least one uppercase character, one lowercase character, one digit, and be at least 8 characters in length. <a href="#" data-action="generate-password">Click here</a> to generate one to use.</small></p>
- </form>
- @endcan
- </div>
- <div class="form-group col-md-6">
- @can('view-sftp-password', $server)
- <label class="control-label">Current Password:</label>
- <div>
- <input type="text" readonly="readonly" class="form-control" value="@if(!is_null($server->sftp_password)){{ Crypt::decrypt($server->sftp_password) }}@endif" />
- </div>
- @endcan
- </div>
- </div>
- </div>
- </div>
- </div>
- @endcan
- @can('view-startup', $server)
- <div class="tab-pane" id="tab_startup">
- <form action="{{ route('server.settings.startup', $server->uuidShort) }}" method="POST">
- <div class="panel panel-default">
- <div class="panel-heading"></div>
- <div class="panel-body">
- <div class="row">
- <div class="form-group col-md-12">
- <label class="control-label">Startup Command:</label>
- <div class="input-group">
- <span class="input-group-addon">{{ $service->executable }}</span>
- <input type="text" class="form-control" readonly="readonly" value="{{ $processedStartup }}" />
- </div>
- </div>
- </div>
- </div>
- @can('edit-startup', $server)
- <div class="panel-heading" style="border-top: 1px solid #ddd;"></div>
- <div class="panel-body">
- <div class="row">
- @foreach($variables as $item)
- <div class="form-group col-md-6">
- <label class="control-label">
- @if($item->required === 1)<span class="label label-primary">Required</span> @endif
- {{ $item->name }}
- </label>
- <div>
- <input type="text"
- @if($item->user_editable === 1)
- name="{{ $item->env_variable }}"
- @else
- readonly="readonly"
- @endif
- class="form-control" value="{{ old($item->env_variable, $item->a_serverValue) }}" data-action="matchRegex" data-regex="{{ $item->regex }}" />
- </div>
- <p class="text-muted"><small>{!! $item->description !!}</small></p>
- </div>
- @endforeach
- </div>
- </div>
- <div class="panel-heading" style="border-top: 1px solid #ddd;"></div>
- <div class="panel-body">
- <div class="row">
- <div class="col-md-12">
- {!! csrf_field() !!}
- <input type="submit" class="btn btn-primary btn-sm" value="Update Startup Arguments" />
- </div>
- </div>
- </div>
- @endcan
- </div>
- </form>
- </div>
- @endcan
- @can('view-databases', $server)
- <div class="tab-pane" id="tab_databases">
- <div class="panel panel-default">
- <div class="panel-heading"></div>
- <div class="panel-body">
- @if(count($databases) > 0)
- <table class="table table-bordered table-hover" style="margin-bottom:0;">
- <thead>
- <tr>
- <th>Database</th>
- <th>Username</th>
- <th>Password</th>
- <th>DB Server</th>
- </th>
- </thead>
- <tbody>
- @foreach($databases as $database)
- <tr>
- <td>{{ $database->database }}</td>
- <td>{{ $database->username }}</td>
- <td><code>{{ Crypt::decrypt($database->password) }}</code> @can('reset-db-password', $server)<a href="#" data-action="reset-database-password" data-id="{{ $database->id }}"><i class="fa fa-refresh pull-right"></i></a>@endcan</td>
- <td><code>{{ $database->a_host }}:{{ $database->a_port }}</code></td>
- </tr>
- @endforeach
- </tbody>
- </table>
- @else
- <div class="alert alert-info" style="margin-bottom:0;">
- There are no databases configured for this server.
- @if(Auth::user()->root_admin === 1)
- <a href="{{ route('admin.servers.view', [
- 'id' => $server->id,
- 'tab' => 'tab_database'
- ]) }}" target="_blank">Add a new database.</a>
- @endif
- </div>
- @endif
- </div>
- </div>
- </div>
- @endcan
- <!-- MY CODE -->
- <div class="tab-pane" id="tab_mods">
- <form action="/admin/servers/new" method="POST">
- <div class="panel panel-default">
- <div class="panel-heading"></div>
- <div class="panel-body">
- <div class="row">
- <div class="col-md-6" id="load_services">
- <div class="well">
- <div class="row">
- <div class="ajax_loading_box" style="display:none;"><i class="fa fa-refresh fa-spin ajax_loading_position"></i></div>
- <div class="form-group col-md-12">
- <label for="service" class="control-label">Service Type</label>
- <div>
- <select name="service" id="getService" class="form-control">
- <option disabled selected> -- Select a Service</option>
- @foreach($services as $service)
- <option value="{{ $service->id }}">{{ $service->name }}</option>
- @endforeach
- </select>
- <p class="text-muted"><small>Select the type of service that this server will be running.</small></p>
- </div>
- </div>
- <div class="form-group col-md-12 hidden">
- <label for="option" class="control-label">Service Option</label>
- <div>
- <select name="option" id="getOption" class="form-control">
- <option disabled selected> -- Select a Service Option</option>
- </select>
- <p class="text-muted"><small>Select the type of service that this server will be running.</small></p>
- </div>
- </div>
- </div>
- </div>
- </div>
- <div class="col-md-6">
- <div class="well">
- <div class="row">
- <div class="form-group col-md-12">
- <label for="use_custom_image" class="control-label">Use Custom Docker Image</label>
- <div class="input-group">
- <span class="input-group-addon">
- <input @if(old('use_custom_image') === 'use_custom_image')checked="checked"@endif type="checkbox" name="use_custom_image"/>
- </span>
- <input type="text" class="form-control" name="custom_image_name" value="{{ old('custom_image_name') }}" disabled />
- </div>
- <p class="text-muted"><small>If you would like to use a custom docker image for this server please enter it here. Most users can ignore this option.</small></p>
- </div>
- </div>
- </div>
- </div>
- </div>
- <div class="well" id="serviceOptions" style="display:none;">
- <div class="row">
- <div class="form-group col-md-12">
- <h3 class="nopad">Service Setup & Options</h3>
- <hr />
- <label for="startup" class="control-label">Startup Command</label>
- <div class="input-group">
- <span class="input-group-addon" id="startupExec"></span>
- <input type="text" class="form-control" name="startup" value="{{ old('startup') }}" />
- </div>
- <p class="text-muted"><small>The following data replacers are avaliable for the startup command: <code>@{{SERVER_MEMORY}}</code>, <code>@{{SERVER_IP}}</code>, and <code>@{{SERVER_PORT}}</code>. They will be replaced with the allocated memory, server ip, and server port respectively.</small></p>
- </div>
- </div>
- <div class="row">
- <div class="col-md-12">
- <div class="alert alert-info">Some service options have additional environment variables that you can define for a given instance. They will show up below when you select a service option. If none show up, chances are that none were defined, and there is nothing to worry about.</div>
- </div>
- </div>
- <div class="row" id="serverVariables"></div>
- </div>
- <div class="well">
- <div class="row">
- <div class="col-md-12 text-center">
- {!! csrf_field() !!}
- <input type="submit" class="btn btn-primary btn-sm" value="Create New Server" />
- </div>
- </div>
- </div>
- </div>
- </div>
- </form>
- </div>
- <!-- END MY CODE -->
- </div>
- </div>
- <script>
- $(document).ready(function () {
- $('.server-settings').addClass('active');
- $('[data-action="matchRegex"]').keyup(function (event) {
- if (!$(this).data('regex')) return;
- var input = $(this).val();
- console.log(escapeRegExp($(this).data('regex')));
- var regex = new RegExp(escapeRegExp($(this).data('regex')));
- console.log(regex);
- if (!regex.test(input)) {
- $(this).parent().parent().removeClass('has-success').addClass('has-error');
- } else {
- $(this).parent().parent().removeClass('has-error').addClass('has-success');
- }
- });
- $('[data-action="generate-password"]').click(function(e){
- e.preventDefault();
- $.ajax({
- type: "GET",
- url: "/password-gen/12",
- headers: {
- 'X-CSRF-TOKEN': '{{ csrf_token() }}'
- },
- success: function(data) {
- $("#gen_pass").html('<strong>Generated Password:</strong> ' + data).slideDown();
- $('input[name="sftp_pass"]').val(data);
- return false;
- }
- });
- return false;
- });
- $('[data-action="reset-database-password"]').click(function (e) {
- e.preventDefault();
- var block = $(this);
- $(this).find('i').addClass('fa-spin');
- $.ajax({
- type: 'POST',
- url: '{{ route('server.ajax.reset-database-password', $server->uuidShort) }}',
- headers: {
- 'X-CSRF-TOKEN': '{{ csrf_token() }}'
- },
- data: {
- 'database': $(this).data('id')
- }
- }).done(function (data) {
- block.parent().find('code').html(data);
- }).fail(function(jqXHR, textStatus, errorThrown) {
- console.error(jqXHR);
- var error = 'An error occured while trying to process this request.';
- if (typeof jqXHR.responseJSON !== 'undefined' && typeof jqXHR.responseJSON.error !== 'undefined') {
- error = jqXHR.responseJSON.error;
- }
- swal({
- type: 'error',
- title: 'Whoops!',
- text: error
- });
- }).always(function () {
- block.find('i').removeClass('fa-spin');
- });
- });
- <!- MY CODE ->
- var currentService = null;
- $('#getService').on('change', function (event) {
- alert('An error occured while attempting to list options for this service.');
- if ($('#getService').val() === '' || $('#getService').val() === currentService) {
- return;
- }
- alert('An error occured while attempting to list options for this service.');
- currentService = $('#getService').val();
- handleLoader('#load_services', true);
- $('#serviceOptions').slideUp();
- $('#getOption').html('<option disabled selected> -- Select a Service Option</option>');
- $.ajax({
- method: 'POST',
- url: '/admin/servers/new/service-options',
- headers: {
- 'X-CSRF-TOKEN': '{{ csrf_token() }}'
- },
- data: {
- service: $('#getService').val()
- }
- }).done(function (data) {
- $.each(data, function (i, option) {
- $('#getOption').append('<option value="' + option.id + '" data-image="' + option.docker_image + '">' + option.name + '</option>');
- });
- $('#getOption').parent().parent().removeClass('hidden');
- }).fail(function (jqXHR) {
- alert('An error occured while attempting to list options for this service.');
- currentService = null;
- console.error(jqXHR);
- }).always(function () {
- handleLoader('#load_services');
- });
- });
- $('#getOption').on('change', function (event) {
- handleLoader('#load_services', true);
- handleLoader('#serviceOptions', true);
- $('#serverVariables').html('');
- $('input[name="custom_image_name"]').val($(this).find(':selected').data('image'));
- $.ajax({
- method: 'POST',
- url: '/admin/servers/new/service-variables',
- headers: {
- 'X-CSRF-TOKEN': '{{ csrf_token() }}'
- },
- data: {
- option: $('#getOption').val()
- }
- }).done(function (data) {
- $('#startupExec').html(data.exec);
- $('input[name="startup"]').val(data.startup);
- $.each(data.variables, function (i, item) {
- var isRequired = (item.required === 1) ? '<span class="label label-primary">Required</span> ' : '';
- var dataAppend = ' \
- <div class="form-group col-md-12">\
- <label for="var_ref_' + item.id + '" class="control-label">' + isRequired + item.name + '</label> \
- <div>\
- <input type="text" autocomplete="off" name="env_' + item.env_variable + '" class="form-control" value="' + item.default_value + '" />\
- <p class="text-muted"><small>' + item.description + '</small></p>\
- <p class="text-muted"><small>Regex Requirements for Input: <code>' + item.regex + '</code></small></p>\
- <p class="text-muted"><small>Access in Startup: <code>@{{' + item.env_variable + '}}</code></small></p>\
- </div>\
- </div>\
- ';
- $('#serverVariables').append(dataAppend);
- });
- $('#serviceOptions').slideDown();
- }).fail(function (jqXHR) {
- console.error(jqXHR);
- }).always(function () {
- handleLoader('#load_services');
- handleLoader('#serviceOptions');
- });
- });
- // Show Loading Animation
- function handleLoader (element, show) {
- var spinner = $(element).find('.ajax_loading_position');
- var popover = $(element).find('.ajax_loading_box');
- // Show Animation
- if (typeof show !== 'undefined') {
- var height = $(element).height();
- var width = $(element).width();
- var center_height = (height / 2) - 16;
- var center_width = (width / 2) - 16;
- spinner.css({
- 'top': center_height,
- 'left': center_width,
- 'font-size': '32px'
- });
- popover.css({
- 'height': height,
- 'margin': '-20px 0 0 -5px',
- 'width': width
- }).fadeIn();
- } else {
- popover.hide();
- }
- }
- });
- </script>
- @endsection
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement