Added Advanced Config editor to Admin Panel

+ .ENV editor for NGINX users
This commit is contained in:
Julian Prieber 2022-06-13 17:47:24 +02:00
parent 1002cfb0ae
commit b5baeecab9
3 changed files with 81 additions and 0 deletions

View File

@ -208,4 +208,30 @@ class AdminController extends Controller
return view('panel/phpinfo');
}
//Shows config file editor page
public function showFileEditor(request $request)
{
return view('/panel/config');
}
//Saves advanced config
public function editAC(request $request)
{
$AdvancedConfig = $request->AdvancedConfig;
file_put_contents('config/advanced-config.php', $AdvancedConfig);
return view('/panel/config');
}
//Saves .env config
public function editENV(request $request)
{
$AdvancedConfig = $request->AdvancedConfig;
file_put_contents('.env', $AdvancedConfig);
return view('/panel/config');
}
}

View File

@ -0,0 +1,51 @@
@extends( ($_SERVER['QUERY_STRING'] === 'restore-defaults') ? 'layouts.lang' : 'layouts.sidebar')
@if($_SERVER['QUERY_STRING'] === 'restore-defaults')
<?php
copy(base_path('storage/templates/advanced-config.php'), base_path('config/advanced-config.php'));
echo "<meta http-equiv=\"refresh\" content=\"0; " . url()->current() . "/../../panel/advanced-config\" />";
?>
@else
@section('content')
@if(str_ends_with($_SERVER['REQUEST_URI'], 'advanced-config'))
<h2 class="mb-4"><i class="bi bi-pencil-square"> Advanced config</i></h2>
<p>Allows editing the frontend of your site. Amongst other things, this file allows customization of:<br>
Home Page, links, titles, Google Analytics and meta tags.</p>
<form action="{{ route('editAC') }}" method="post">
@csrf
<div class="form-group col-lg-8">
<label>Advanced Configuration file.</label>
<pre><textarea class="form-control" name="AdvancedConfig" rows="280">{{ file_get_contents('config/advanced-config.php') }}</textarea></pre>
</div>
<button type="submit" class="mt-3 ml-3 btn btn-info">Save</button>
<a class="mt-3 ml-3 btn btn-primary confirmation" href="{{url('/panel/advanced-config?restore-defaults')}}">Restore defaults</a>
<script type="text/javascript">
var elems = document.getElementsByClassName('confirmation');
var confirmIt = function (e) {
if (!confirm('Are you sure?')) e.preventDefault();
};
for (var i = 0, l = elems.length; i < l; i++) {
elems[i].addEventListener('click', confirmIt, false);
}
</script>
</form>
@elseif(str_ends_with($_SERVER['REQUEST_URI'], 'env'))
<h2 class="mb-4"><i class="bi bi-pencil-square"> ENV</i></h2>
<form action="{{ route('editENV') }}" method="post">
@csrf
<div class="form-group col-lg-8">
<label>.env</label>
<pre><textarea class="form-control" name="AdvancedConfig" rows="80">{{ file_get_contents('.env') }}</textarea></pre>
</div>
<button type="submit" class="mt-3 ml-3 btn btn-info">Save</button>
</form>
@endif
@endsection
@endif

View File

@ -99,6 +99,10 @@ Route::get('/panel/edit-user/{id}', [AdminController::class, 'showUser'])->name(
Route::post('/panel/edit-user/{id}', [AdminController::class, 'editUser'])->name('editUser');
Route::get('/panel/pages', [AdminController::class, 'showSitePage'])->name('showSitePage');
Route::post('/panel/pages', [AdminController::class, 'editSitePage'])->name('editSitePage');
Route::get('/panel/advanced-config', [AdminController::class, 'showFileEditor'])->name('showFileEditor');
Route::post('/panel/advanced-config', [AdminController::class, 'editAC'])->name('editAC');
Route::get('/panel/env', [AdminController::class, 'showFileEditor'])->name('showFileEditor');
Route::post('/panel/env', [AdminController::class, 'editENV'])->name('editENV');
Route::get('/panel/site', [AdminController::class, 'showSite'])->name('showSite');
Route::post('/panel/site', [AdminController::class, 'editSite'])->name('editSite');
Route::get('/panel/phpinfo', [AdminController::class, 'phpinfo'])->name('phpinfo');