diff --git a/app/Http/Controllers/Admin/AdminSettingsController.php b/app/Http/Controllers/Admin/AdminSettingsController.php index ab5b838f..6c5f3cd5 100644 --- a/app/Http/Controllers/Admin/AdminSettingsController.php +++ b/app/Http/Controllers/Admin/AdminSettingsController.php @@ -11,41 +11,79 @@ use App\Util\Lexer\PrettyNumber; trait AdminSettingsController { - public function settings(Request $request) - { - return view('admin.settings.home'); - } + public function settings(Request $request) + { + return view('admin.settings.home'); + } - public function settingsBackups(Request $request) - { - $path = storage_path('app/'.config('app.name')); - $files = is_dir($path) ? new \DirectoryIterator($path) : []; - return view('admin.settings.backups', compact('files')); - } + public function settingsBackups(Request $request) + { + $path = storage_path('app/'.config('app.name')); + $files = is_dir($path) ? new \DirectoryIterator($path) : []; + return view('admin.settings.backups', compact('files')); + } - public function settingsConfig(Request $request) - { - $editor = []; - $config = file_get_contents(base_path('.env')); - return view('admin.settings.config', compact('editor', 'config')); - } + public function settingsConfig(Request $request) + { + $editor = config('pixelfed.admin.env_editor'); + $config = !$editor ? false : file_get_contents(base_path('.env')); + $backup = !$editor ? false : file_get_contents(base_path('.env.backup')); + return view('admin.settings.config', compact('editor', 'config', 'backup')); + } - public function settingsMaintenance(Request $request) - { - return view('admin.settings.maintenance'); - } + public function settingsConfigStore(Request $request) + { + if(config('pixelfed.admin.env_editor') !== true) { + abort(400); + } + $res = $request->input('res'); - public function settingsStorage(Request $request) - { - $storage = []; - return view('admin.settings.storage', compact('storage')); - } + $old = file_get_contents(app()->environmentFilePath()); + if(empty($old) || $old != $res) { + $oldFile = fopen(app()->environmentFilePath().'.backup', 'w'); + fwrite($oldFile, $old); + fclose($oldFile); + } + + $file = fopen(app()->environmentFilePath(), 'w'); + fwrite($file, $res); + fclose($file); + Artisan::call('config:cache'); + return ['msg' => 200]; + } + + public function settingsConfigRestore(Request $request) + { + if(config('pixelfed.admin.env_editor') !== true) { + abort(400); + } + $res = file_get_contents(app()->environmentFilePath().'.backup'); + if(empty($res)) { + abort(400, 'No backup exists.'); + } + $file = fopen(app()->environmentFilePath(), 'w'); + fwrite($file, $res); + fclose($file); + Artisan::call('config:cache'); + return ['msg' => 200]; + } + + public function settingsMaintenance(Request $request) + { + return view('admin.settings.maintenance'); + } + + public function settingsStorage(Request $request) + { + $storage = []; + return view('admin.settings.storage', compact('storage')); + } + + public function settingsFeatures(Request $request) + { + return view('admin.settings.features'); + } - public function settingsFeatures(Request $request) - { - return view('admin.settings.features'); - } - public function settingsHomeStore(Request $request) { $this->validate($request, [ @@ -57,7 +95,7 @@ trait AdminSettingsController public function settingsPages(Request $request) { - $pages = Page::orderByDesc('updated_at')->paginate(10); + $pages = Page::orderByDesc('updated_at')->paginate(10); return view('admin.pages.home', compact('pages')); } @@ -66,35 +104,35 @@ trait AdminSettingsController return view('admin.pages.edit'); } - public function settingsSystem(Request $request) - { - $sys = [ - 'pixelfed' => config('pixelfed.version'), - 'php' => phpversion(), - 'laravel' => app()->version(), - ]; - switch (config('database.default')) { - case 'pgsql': - $sys['database'] = [ - 'name' => 'Postgres', - 'version' => explode(' ', DB::select(DB::raw('select version();'))[0]->version)[1] - ]; - break; + public function settingsSystem(Request $request) + { + $sys = [ + 'pixelfed' => config('pixelfed.version'), + 'php' => phpversion(), + 'laravel' => app()->version(), + ]; + switch (config('database.default')) { + case 'pgsql': + $sys['database'] = [ + 'name' => 'Postgres', + 'version' => explode(' ', DB::select(DB::raw('select version();'))[0]->version)[1] + ]; + break; - case 'mysql': - $sys['database'] = [ - 'name' => 'MySQL', - 'version' => DB::select( DB::raw("select version()") )[0]->{'version()'} - ]; - break; - - default: - $sys['database'] = [ - 'name' => 'Unknown', - 'version' => '?' - ]; - break; - } - return view('admin.settings.system', compact('sys')); - } + case 'mysql': + $sys['database'] = [ + 'name' => 'MySQL', + 'version' => DB::select( DB::raw("select version()") )[0]->{'version()'} + ]; + break; + + default: + $sys['database'] = [ + 'name' => 'Unknown', + 'version' => '?' + ]; + break; + } + return view('admin.settings.system', compact('sys')); + } } \ No newline at end of file diff --git a/config/pixelfed.php b/config/pixelfed.php index 7356fb2e..301c5315 100644 --- a/config/pixelfed.php +++ b/config/pixelfed.php @@ -274,4 +274,8 @@ return [ 'sanitizer' => [ 'restrict_html_types' => env('RESTRICT_HTML_TYPES', true) ], + + 'admin' => [ + 'env_editor' => env('ADMIN_ENV_EDITOR', false) + ], ]; diff --git a/resources/views/admin/settings/config.blade.php b/resources/views/admin/settings/config.blade.php index 8a9d017d..024ebc4c 100644 --- a/resources/views/admin/settings/config.blade.php +++ b/resources/views/admin/settings/config.blade.php @@ -5,10 +5,80 @@ @section('section')
Configuration Editor is disabled
+To enable it, add ADMIN_ENV_EDITOR=true
to .env
then run php artisan config:cache
Edit configuration settings
++ Warning: Editing the .env file may cause issues if you change the wrong setting or set the wrong value. +
- Feature Unavailable: This feature will be released in a future version. -
-@endsection \ No newline at end of file +