mirror of
https://github.com/Kovah/LinkAce.git
synced 2025-01-29 10:59:49 +01:00
Add a system settings page accessible by admins
This commit is contained in:
parent
61bc634d4a
commit
2181885867
63
app/Http/Controllers/App/SystemSettingsController.php
Normal file
63
app/Http/Controllers/App/SystemSettingsController.php
Normal file
@ -0,0 +1,63 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\App;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Setting;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
/**
|
||||
* Class SystemSettingsController
|
||||
*
|
||||
* @package App\Http\Controllers\App
|
||||
*/
|
||||
class SystemSettingsController extends Controller
|
||||
{
|
||||
/**
|
||||
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
|
||||
*/
|
||||
public function getSystemSettings()
|
||||
{
|
||||
if (!auth()->user()->hasRole('admin')) {
|
||||
abort(403);
|
||||
}
|
||||
|
||||
return view('actions.settings.system');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
*/
|
||||
public function saveSystemSettings(Request $request)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate a new API token for the current user
|
||||
*
|
||||
* @param Request $request
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function generateCronToken(Request $request)
|
||||
{
|
||||
if (!auth()->user()->hasRole('admin')) {
|
||||
abort(403);
|
||||
}
|
||||
|
||||
$new_token = Str::random(32);
|
||||
|
||||
Setting::updateOrCreate(
|
||||
[
|
||||
'key' => 'cron_token',
|
||||
'user_id' => null,
|
||||
],
|
||||
['value' => $new_token]
|
||||
);
|
||||
|
||||
return response()->json([
|
||||
'new_token' => $new_token,
|
||||
]);
|
||||
}
|
||||
}
|
@ -4,6 +4,7 @@ return [
|
||||
'user_settings' => 'User Settings',
|
||||
'account_settings' => 'Account Settings',
|
||||
'app_settings' => 'Application Settings',
|
||||
'system_settings' => 'System Settings',
|
||||
|
||||
'timezone' => 'Timezone',
|
||||
'date_format' => 'Date Format',
|
||||
@ -37,7 +38,15 @@ return [
|
||||
'api_token' => 'API Token',
|
||||
'api_token_generate' => 'Generate Token',
|
||||
'api_token_generate_confirm' => 'Do you really want to generate a new token?',
|
||||
'api_token_help' => 'The API token can be used to access LinkAce from other application or scripts as well as running the cron job which checks links if they exist and runs the backup tasks.',
|
||||
'api_token_generate_info' => 'Caution: If you already have an API token, generating a new one will break all existing integrations as well as the cron job!',
|
||||
'api_token_help' => 'The API token can be used to access LinkAce from other application or scripts.',
|
||||
'api_token_generate_info' => 'Caution: If you already have an API token, generating a new one will break all existing integrations!',
|
||||
'api_token_generate_failure' => 'A new API token could not be generated. Please check your browser console and application logs for more information.',
|
||||
|
||||
'cron_token' => 'Cron Token',
|
||||
'cron_token_generate' => 'Generate Token',
|
||||
'cron_token_generate_confirm' => 'Do you really want to generate a new token?',
|
||||
'cron_token_help' => 'The cron token is needed to run the cron service which checks for dead links or running backups.',
|
||||
'cron_token_url' => 'Point your cron to the following URL: <span id="cron-url">:route</span>',
|
||||
'cron_token_generate_info' => 'Caution: If you already have an cron token, generating a new one will break the existing cron job!',
|
||||
'cron_token_generate_failure' => 'A new cron token could not be generated. Please check your browser console and application logs for more information.',
|
||||
];
|
||||
|
73
resources/views/actions/settings/partials/cron.blade.php
Normal file
73
resources/views/actions/settings/partials/cron.blade.php
Normal file
@ -0,0 +1,73 @@
|
||||
<div class="card">
|
||||
<div class="card-header">
|
||||
@lang('settings.cron_token')
|
||||
</div>
|
||||
<div class="card-body">
|
||||
|
||||
<p>@lang('settings.cron_token_help')</p>
|
||||
|
||||
<div class="input-group mb-3">
|
||||
<input type="text" id="cron-token" class="form-control" value="{{ systemsettings('cron_token') }}"
|
||||
readonly aria-readonly="true" aria-label="@lang('settings.cron_token_generate')"
|
||||
aria-describedby="cron-token-generate">
|
||||
<div class="input-group-append">
|
||||
<button class="btn btn-outline-danger" type="button" id="cron-token-generate">
|
||||
<i class="fa fa-recycle mr-1"></i> @lang('settings.cron_token_generate')
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<p id="cron-token-generate-failure" class="small text-danger" style="display:none">
|
||||
@lang('settings.cron_token_generate_failure')
|
||||
</p>
|
||||
|
||||
<p class="small text-warning">@lang('settings.cron_token_generate_info')</p>
|
||||
|
||||
@if(systemsettings('cron_token'))
|
||||
<p>
|
||||
@lang('settings.cron_token_url', [
|
||||
'route' => route('cron', ['token' => systemsettings('cron_token')])
|
||||
])
|
||||
</p>
|
||||
@endif
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@push('scripts')
|
||||
<script>
|
||||
$('#cron-token-generate').click(function (e) {
|
||||
var $btn = $(e.currentTarget);
|
||||
var $cronUrl = $('#cron-url');
|
||||
|
||||
$btn.prop('disabled', true);
|
||||
$cronUrl.text('');
|
||||
|
||||
if (confirm('@lang('settings.cron_token_generate_confirm')')) {
|
||||
|
||||
$.ajax({
|
||||
method: 'POST',
|
||||
url: '{{ route('generate-cron-token') }}',
|
||||
dataType: 'json',
|
||||
data: {_token: '{{ csrf_token() }}'}
|
||||
}).done(function (response) {
|
||||
if (typeof response.new_token !== 'undefined') {
|
||||
$('#cron-token').val(response.new_token);
|
||||
$cronUrl.text('{{ route('cron', ['token' => '']) }}/' + response.new_token);
|
||||
|
||||
window.setTimeout(function () {
|
||||
$btn.prop('disabled', false);
|
||||
}, 5000);
|
||||
} else {
|
||||
$('#cron-token-generate-failure').show();
|
||||
}
|
||||
}).fail(function () {
|
||||
$('#cron-token-generate-failure').show();
|
||||
});
|
||||
|
||||
} else {
|
||||
$btn.prop('disabled', false);
|
||||
}
|
||||
});
|
||||
</script>
|
||||
@endpush
|
7
resources/views/actions/settings/system.blade.php
Normal file
7
resources/views/actions/settings/system.blade.php
Normal file
@ -0,0 +1,7 @@
|
||||
@extends('layouts.app')
|
||||
|
||||
@section('content')
|
||||
|
||||
@include('actions.settings.partials.cron')
|
||||
|
||||
@endsection
|
@ -94,6 +94,12 @@
|
||||
<a href="{{ route('get-export') }}" class="dropdown-item">
|
||||
@lang('export.export')
|
||||
</a>
|
||||
@role('admin')
|
||||
<div class="dropdown-divider"></div>
|
||||
<a href="{{ route('get-sysstemsettings') }}" class="dropdown-item">
|
||||
@lang('settings.system_settings')
|
||||
</a>
|
||||
@endrole
|
||||
</div>
|
||||
</li>
|
||||
@endguest
|
||||
|
@ -65,6 +65,10 @@ Route::group(['middleware' => ['auth']], function () {
|
||||
Route::post('settings/change-password', 'App\UserSettingsController@changeUserPassword')->name('change-user-password');
|
||||
Route::post('settings/generate-api-token', 'App\UserSettingsController@generateApiToken')->name('generate-api-token');
|
||||
|
||||
Route::get('settings/system', 'App\SystemSettingsController@getSystemSettings')->name('get-sysstemsettings');
|
||||
Route::post('settings/system', 'App\SystemSettingsController@saveSystemSettings')->name('save-settings-system');
|
||||
Route::post('settings/generate-cron-token', 'App\SystemSettingsController@generateCronToken')->name('generate-cron-token');
|
||||
|
||||
Route::post('ajax/tags', 'API\AjaxController@getTags')->name('ajax-tags');
|
||||
});
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user