Skip to content

Commit b5baeec

Browse files
committed
Added Advanced Config editor to Admin Panel
+ .ENV editor for NGINX users
1 parent 1002cfb commit b5baeec

File tree

3 files changed

+81
-0
lines changed

3 files changed

+81
-0
lines changed

app/Http/Controllers/AdminController.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,4 +208,30 @@ public function phpinfo()
208208
return view('panel/phpinfo');
209209
}
210210

211+
//Shows config file editor page
212+
public function showFileEditor(request $request)
213+
{
214+
return view('/panel/config');
215+
}
216+
217+
//Saves advanced config
218+
public function editAC(request $request)
219+
{
220+
$AdvancedConfig = $request->AdvancedConfig;
221+
222+
file_put_contents('config/advanced-config.php', $AdvancedConfig);
223+
224+
return view('/panel/config');
225+
}
226+
227+
//Saves .env config
228+
public function editENV(request $request)
229+
{
230+
$AdvancedConfig = $request->AdvancedConfig;
231+
232+
file_put_contents('.env', $AdvancedConfig);
233+
234+
return view('/panel/config');
235+
}
236+
211237
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
@extends( ($_SERVER['QUERY_STRING'] === 'restore-defaults') ? 'layouts.lang' : 'layouts.sidebar')
2+
3+
@if($_SERVER['QUERY_STRING'] === 'restore-defaults')
4+
<?php
5+
copy(base_path('storage/templates/advanced-config.php'), base_path('config/advanced-config.php'));
6+
echo "<meta http-equiv=\"refresh\" content=\"0; " . url()->current() . "/../../panel/advanced-config\" />";
7+
?>
8+
@else
9+
10+
@section('content')
11+
12+
13+
@if(str_ends_with($_SERVER['REQUEST_URI'], 'advanced-config'))
14+
<h2 class="mb-4"><i class="bi bi-pencil-square"> Advanced config</i></h2>
15+
<p>Allows editing the frontend of your site. Amongst other things, this file allows customization of:<br>
16+
Home Page, links, titles, Google Analytics and meta tags.</p>
17+
<form action="{{ route('editAC') }}" method="post">
18+
@csrf
19+
<div class="form-group col-lg-8">
20+
<label>Advanced Configuration file.</label>
21+
<pre><textarea class="form-control" name="AdvancedConfig" rows="280">{{ file_get_contents('config/advanced-config.php') }}</textarea></pre>
22+
</div>
23+
<button type="submit" class="mt-3 ml-3 btn btn-info">Save</button>
24+
<a class="mt-3 ml-3 btn btn-primary confirmation" href="{{url('/panel/advanced-config?restore-defaults')}}">Restore defaults</a>
25+
<script type="text/javascript">
26+
var elems = document.getElementsByClassName('confirmation');
27+
var confirmIt = function (e) {
28+
if (!confirm('Are you sure?')) e.preventDefault();
29+
};
30+
for (var i = 0, l = elems.length; i < l; i++) {
31+
elems[i].addEventListener('click', confirmIt, false);
32+
}
33+
</script>
34+
</form>
35+
@elseif(str_ends_with($_SERVER['REQUEST_URI'], 'env'))
36+
<h2 class="mb-4"><i class="bi bi-pencil-square"> ENV</i></h2>
37+
38+
<form action="{{ route('editENV') }}" method="post">
39+
@csrf
40+
<div class="form-group col-lg-8">
41+
<label>.env</label>
42+
<pre><textarea class="form-control" name="AdvancedConfig" rows="80">{{ file_get_contents('.env') }}</textarea></pre>
43+
</div>
44+
<button type="submit" class="mt-3 ml-3 btn btn-info">Save</button>
45+
</form>
46+
@endif
47+
48+
49+
50+
@endsection
51+
@endif

routes/web.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,10 @@
9999
Route::post('/panel/edit-user/{id}', [AdminController::class, 'editUser'])->name('editUser');
100100
Route::get('/panel/pages', [AdminController::class, 'showSitePage'])->name('showSitePage');
101101
Route::post('/panel/pages', [AdminController::class, 'editSitePage'])->name('editSitePage');
102+
Route::get('/panel/advanced-config', [AdminController::class, 'showFileEditor'])->name('showFileEditor');
103+
Route::post('/panel/advanced-config', [AdminController::class, 'editAC'])->name('editAC');
104+
Route::get('/panel/env', [AdminController::class, 'showFileEditor'])->name('showFileEditor');
105+
Route::post('/panel/env', [AdminController::class, 'editENV'])->name('editENV');
102106
Route::get('/panel/site', [AdminController::class, 'showSite'])->name('showSite');
103107
Route::post('/panel/site', [AdminController::class, 'editSite'])->name('editSite');
104108
Route::get('/panel/phpinfo', [AdminController::class, 'phpinfo'])->name('phpinfo');

0 commit comments

Comments
 (0)