2019-02-07 18:59:38 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Controllers\Admin;
|
|
|
|
|
2021-05-08 04:19:58 +00:00
|
|
|
use App\Models\ConfigCache;
|
2024-03-05 07:05:05 +00:00
|
|
|
use App\Models\InstanceActor;
|
|
|
|
use App\Page;
|
|
|
|
use App\Profile;
|
2023-05-07 11:08:45 +00:00
|
|
|
use App\Services\AccountService;
|
2021-05-08 04:19:58 +00:00
|
|
|
use App\Services\ConfigCacheService;
|
2024-03-05 07:05:05 +00:00
|
|
|
use App\User;
|
2021-05-19 08:01:33 +00:00
|
|
|
use App\Util\Site\Config;
|
2024-03-05 07:05:05 +00:00
|
|
|
use Artisan;
|
|
|
|
use Cache;
|
|
|
|
use DB;
|
|
|
|
use Illuminate\Http\Request;
|
2019-02-07 18:59:38 +00:00
|
|
|
|
|
|
|
trait AdminSettingsController
|
|
|
|
{
|
2024-02-19 11:00:31 +00:00
|
|
|
public function settings(Request $request)
|
|
|
|
{
|
|
|
|
$cloud_storage = ConfigCacheService::get('pixelfed.cloud_storage');
|
|
|
|
$cloud_disk = config('filesystems.cloud');
|
2024-03-05 07:05:05 +00:00
|
|
|
$cloud_ready = ! empty(config('filesystems.disks.'.$cloud_disk.'.key')) && ! empty(config('filesystems.disks.'.$cloud_disk.'.secret'));
|
2024-02-19 11:00:31 +00:00
|
|
|
$types = explode(',', ConfigCacheService::get('pixelfed.media_types'));
|
|
|
|
$rules = ConfigCacheService::get('app.rules') ? json_decode(ConfigCacheService::get('app.rules'), true) : null;
|
|
|
|
$jpeg = in_array('image/jpg', $types) || in_array('image/jpeg', $types);
|
|
|
|
$png = in_array('image/png', $types);
|
|
|
|
$gif = in_array('image/gif', $types);
|
|
|
|
$mp4 = in_array('video/mp4', $types);
|
|
|
|
$webp = in_array('image/webp', $types);
|
|
|
|
|
|
|
|
$availableAdmins = User::whereIsAdmin(true)->get();
|
|
|
|
$currentAdmin = config_cache('instance.admin.pid') ? AccountService::get(config_cache('instance.admin.pid'), true) : null;
|
|
|
|
$openReg = (bool) config_cache('pixelfed.open_registration');
|
|
|
|
$curOnboarding = (bool) config_cache('instance.curated_registration.enabled');
|
|
|
|
$regState = $openReg ? 'open' : ($curOnboarding ? 'filtered' : 'closed');
|
2024-03-05 07:05:05 +00:00
|
|
|
$accountMigration = (bool) config_cache('federation.migration');
|
2024-02-19 11:00:31 +00:00
|
|
|
|
|
|
|
return view('admin.settings.home', compact(
|
|
|
|
'jpeg',
|
|
|
|
'png',
|
|
|
|
'gif',
|
|
|
|
'mp4',
|
|
|
|
'webp',
|
|
|
|
'rules',
|
|
|
|
'cloud_storage',
|
|
|
|
'cloud_disk',
|
|
|
|
'cloud_ready',
|
|
|
|
'availableAdmins',
|
|
|
|
'currentAdmin',
|
2024-03-05 07:05:05 +00:00
|
|
|
'regState',
|
|
|
|
'accountMigration'
|
2024-02-19 11:00:31 +00:00
|
|
|
));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function settingsHomeStore(Request $request)
|
|
|
|
{
|
|
|
|
$this->validate($request, [
|
|
|
|
'name' => 'nullable|string',
|
|
|
|
'short_description' => 'nullable',
|
|
|
|
'long_description' => 'nullable',
|
|
|
|
'max_photo_size' => 'nullable|integer|min:1',
|
|
|
|
'max_album_length' => 'nullable|integer|min:1|max:100',
|
|
|
|
'image_quality' => 'nullable|integer|min:1|max:100',
|
|
|
|
'type_jpeg' => 'nullable',
|
|
|
|
'type_png' => 'nullable',
|
|
|
|
'type_gif' => 'nullable',
|
|
|
|
'type_mp4' => 'nullable',
|
|
|
|
'type_webp' => 'nullable',
|
|
|
|
'admin_account_id' => 'nullable',
|
2024-03-05 07:05:05 +00:00
|
|
|
'regs' => 'required|in:open,filtered,closed',
|
|
|
|
'account_migration' => 'nullable',
|
2024-02-19 11:00:31 +00:00
|
|
|
]);
|
|
|
|
|
|
|
|
$orb = false;
|
|
|
|
$cob = false;
|
2024-03-05 07:05:05 +00:00
|
|
|
switch ($request->input('regs')) {
|
2024-02-19 11:00:31 +00:00
|
|
|
case 'open':
|
|
|
|
$orb = true;
|
|
|
|
$cob = false;
|
2024-03-05 07:05:05 +00:00
|
|
|
break;
|
2024-02-19 11:00:31 +00:00
|
|
|
|
|
|
|
case 'filtered':
|
|
|
|
$orb = false;
|
|
|
|
$cob = true;
|
2024-03-05 07:05:05 +00:00
|
|
|
break;
|
2024-02-19 11:00:31 +00:00
|
|
|
|
|
|
|
case 'closed':
|
|
|
|
$orb = false;
|
|
|
|
$cob = false;
|
2024-03-05 07:05:05 +00:00
|
|
|
break;
|
2024-02-19 11:00:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ConfigCacheService::put('pixelfed.open_registration', (bool) $orb);
|
|
|
|
ConfigCacheService::put('instance.curated_registration.enabled', (bool) $cob);
|
|
|
|
|
2024-03-05 07:05:05 +00:00
|
|
|
if ($request->filled('admin_account_id')) {
|
2024-02-19 11:00:31 +00:00
|
|
|
ConfigCacheService::put('instance.admin.pid', $request->admin_account_id);
|
|
|
|
Cache::forget('api:v1:instance-data:contact');
|
|
|
|
Cache::forget('api:v1:instance-data-response-v1');
|
|
|
|
}
|
2024-03-05 07:05:05 +00:00
|
|
|
if ($request->filled('rule_delete')) {
|
2024-02-19 11:00:31 +00:00
|
|
|
$index = (int) $request->input('rule_delete');
|
|
|
|
$rules = ConfigCacheService::get('app.rules');
|
|
|
|
$json = json_decode($rules, true);
|
2024-03-05 07:05:05 +00:00
|
|
|
if (! $rules || empty($json)) {
|
2024-02-19 11:00:31 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
unset($json[$index]);
|
|
|
|
$json = json_encode(array_values($json));
|
|
|
|
ConfigCacheService::put('app.rules', $json);
|
|
|
|
Cache::forget('api:v1:instance-data:rules');
|
|
|
|
Cache::forget('api:v1:instance-data-response-v1');
|
2024-03-05 07:05:05 +00:00
|
|
|
|
2024-02-19 11:00:31 +00:00
|
|
|
return 200;
|
|
|
|
}
|
|
|
|
|
|
|
|
$media_types = explode(',', config_cache('pixelfed.media_types'));
|
|
|
|
$media_types_original = $media_types;
|
|
|
|
|
|
|
|
$mimes = [
|
|
|
|
'type_jpeg' => 'image/jpeg',
|
|
|
|
'type_png' => 'image/png',
|
|
|
|
'type_gif' => 'image/gif',
|
|
|
|
'type_mp4' => 'video/mp4',
|
|
|
|
'type_webp' => 'image/webp',
|
|
|
|
];
|
|
|
|
|
|
|
|
foreach ($mimes as $key => $value) {
|
2024-03-05 07:05:05 +00:00
|
|
|
if ($request->input($key) == 'on') {
|
|
|
|
if (! in_array($value, $media_types)) {
|
2024-02-19 11:00:31 +00:00
|
|
|
array_push($media_types, $value);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$media_types = array_diff($media_types, [$value]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-03-05 07:05:05 +00:00
|
|
|
if ($media_types !== $media_types_original) {
|
2024-02-19 11:00:31 +00:00
|
|
|
ConfigCacheService::put('pixelfed.media_types', implode(',', array_unique($media_types)));
|
|
|
|
}
|
|
|
|
|
|
|
|
$keys = [
|
|
|
|
'name' => 'app.name',
|
|
|
|
'short_description' => 'app.short_description',
|
|
|
|
'long_description' => 'app.description',
|
|
|
|
'max_photo_size' => 'pixelfed.max_photo_size',
|
|
|
|
'max_album_length' => 'pixelfed.max_album_length',
|
|
|
|
'image_quality' => 'pixelfed.image_quality',
|
|
|
|
'account_limit' => 'pixelfed.max_account_size',
|
|
|
|
'custom_css' => 'uikit.custom.css',
|
|
|
|
'custom_js' => 'uikit.custom.js',
|
2024-03-05 07:05:05 +00:00
|
|
|
'about_title' => 'about.title',
|
2024-02-19 11:00:31 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
foreach ($keys as $key => $value) {
|
|
|
|
$cc = ConfigCache::whereK($value)->first();
|
|
|
|
$val = $request->input($key);
|
2024-03-05 07:05:05 +00:00
|
|
|
if ($cc && $cc->v != $val) {
|
2024-02-19 11:00:31 +00:00
|
|
|
ConfigCacheService::put($value, $val);
|
2024-03-05 07:05:05 +00:00
|
|
|
} elseif (! empty($val)) {
|
2024-02-19 11:00:31 +00:00
|
|
|
ConfigCacheService::put($value, $val);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$bools = [
|
|
|
|
'activitypub' => 'federation.activitypub.enabled',
|
|
|
|
// 'open_registration' => 'pixelfed.open_registration',
|
|
|
|
'mobile_apis' => 'pixelfed.oauth_enabled',
|
|
|
|
'stories' => 'instance.stories.enabled',
|
|
|
|
'ig_import' => 'pixelfed.import.instagram.enabled',
|
|
|
|
'spam_detection' => 'pixelfed.bouncer.enabled',
|
|
|
|
'require_email_verification' => 'pixelfed.enforce_email_verification',
|
|
|
|
'enforce_account_limit' => 'pixelfed.enforce_account_limit',
|
|
|
|
'show_custom_css' => 'uikit.show_custom.css',
|
|
|
|
'show_custom_js' => 'uikit.show_custom.js',
|
|
|
|
'cloud_storage' => 'pixelfed.cloud_storage',
|
|
|
|
'account_autofollow' => 'account.autofollow',
|
|
|
|
'show_directory' => 'instance.landing.show_directory',
|
|
|
|
'show_explore_feed' => 'instance.landing.show_explore',
|
2024-03-05 07:05:05 +00:00
|
|
|
'account_migration' => 'federation.migration',
|
2024-02-19 11:00:31 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
foreach ($bools as $key => $value) {
|
|
|
|
$active = $request->input($key) == 'on';
|
|
|
|
|
2024-03-05 07:05:05 +00:00
|
|
|
if ($key == 'activitypub' && $active && ! InstanceActor::exists()) {
|
2024-02-19 11:00:31 +00:00
|
|
|
Artisan::call('instance:actor');
|
|
|
|
}
|
|
|
|
|
2024-03-05 07:05:05 +00:00
|
|
|
if ($key == 'mobile_apis' &&
|
2024-02-19 11:00:31 +00:00
|
|
|
$active &&
|
2024-03-05 07:05:05 +00:00
|
|
|
! file_exists(storage_path('oauth-public.key')) &&
|
|
|
|
! file_exists(storage_path('oauth-private.key'))
|
2024-02-19 11:00:31 +00:00
|
|
|
) {
|
|
|
|
Artisan::call('passport:keys');
|
|
|
|
Artisan::call('route:cache');
|
|
|
|
}
|
|
|
|
|
2024-03-05 07:05:05 +00:00
|
|
|
if (config_cache($value) !== $active) {
|
2024-02-19 11:00:31 +00:00
|
|
|
ConfigCacheService::put($value, (bool) $active);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-03-05 07:05:05 +00:00
|
|
|
if ($request->filled('new_rule')) {
|
2024-02-19 11:00:31 +00:00
|
|
|
$rules = ConfigCacheService::get('app.rules');
|
|
|
|
$val = $request->input('new_rule');
|
2024-03-05 07:05:05 +00:00
|
|
|
if (! $rules) {
|
2024-02-19 11:00:31 +00:00
|
|
|
ConfigCacheService::put('app.rules', json_encode([$val]));
|
|
|
|
} else {
|
|
|
|
$json = json_decode($rules, true);
|
|
|
|
$json[] = $val;
|
|
|
|
ConfigCacheService::put('app.rules', json_encode(array_values($json)));
|
|
|
|
}
|
|
|
|
Cache::forget('api:v1:instance-data:rules');
|
|
|
|
Cache::forget('api:v1:instance-data-response-v1');
|
|
|
|
}
|
|
|
|
|
2024-03-05 07:05:05 +00:00
|
|
|
if ($request->filled('account_autofollow_usernames')) {
|
2024-02-19 11:00:31 +00:00
|
|
|
$usernames = explode(',', $request->input('account_autofollow_usernames'));
|
|
|
|
$names = [];
|
|
|
|
|
2024-03-05 07:05:05 +00:00
|
|
|
foreach ($usernames as $n) {
|
2024-02-19 11:00:31 +00:00
|
|
|
$p = Profile::whereUsername($n)->first();
|
2024-03-05 07:05:05 +00:00
|
|
|
if (! $p) {
|
2024-02-19 11:00:31 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
array_push($names, $p->username);
|
|
|
|
}
|
|
|
|
|
|
|
|
ConfigCacheService::put('account.autofollow_usernames', implode(',', $names));
|
|
|
|
}
|
|
|
|
|
|
|
|
Cache::forget(Config::CACHE_KEY);
|
|
|
|
|
|
|
|
return redirect('/i/admin/settings')->with('status', 'Successfully updated settings!');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function settingsBackups(Request $request)
|
|
|
|
{
|
|
|
|
$path = storage_path('app/'.config('app.name'));
|
|
|
|
$files = is_dir($path) ? new \DirectoryIterator($path) : [];
|
2024-03-05 07:05:05 +00:00
|
|
|
|
2024-02-19 11:00:31 +00:00
|
|
|
return view('admin.settings.backups', compact('files'));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function settingsMaintenance(Request $request)
|
|
|
|
{
|
|
|
|
return view('admin.settings.maintenance');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function settingsStorage(Request $request)
|
|
|
|
{
|
|
|
|
$storage = [];
|
2024-03-05 07:05:05 +00:00
|
|
|
|
2024-02-19 11:00:31 +00:00
|
|
|
return view('admin.settings.storage', compact('storage'));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function settingsFeatures(Request $request)
|
|
|
|
{
|
|
|
|
return view('admin.settings.features');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function settingsPages(Request $request)
|
|
|
|
{
|
|
|
|
$pages = Page::orderByDesc('updated_at')->paginate(10);
|
2024-03-05 07:05:05 +00:00
|
|
|
|
2024-02-19 11:00:31 +00:00
|
|
|
return view('admin.pages.home', compact('pages'));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function settingsPageEdit(Request $request)
|
|
|
|
{
|
|
|
|
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':
|
2024-03-05 07:05:05 +00:00
|
|
|
$exp = DB::raw('select version();');
|
|
|
|
$expQuery = $exp->getValue(DB::connection()->getQueryGrammar());
|
|
|
|
$sys['database'] = [
|
|
|
|
'name' => 'Postgres',
|
|
|
|
'version' => explode(' ', DB::select($expQuery)[0]->version)[1],
|
|
|
|
];
|
|
|
|
break;
|
2024-02-19 11:00:31 +00:00
|
|
|
|
|
|
|
case 'mysql':
|
2024-03-05 07:05:05 +00:00
|
|
|
$exp = DB::raw('select version()');
|
|
|
|
$expQuery = $exp->getValue(DB::connection()->getQueryGrammar());
|
|
|
|
$sys['database'] = [
|
|
|
|
'name' => 'MySQL',
|
|
|
|
'version' => DB::select($expQuery)[0]->{'version()'},
|
|
|
|
];
|
|
|
|
break;
|
2024-02-19 11:00:31 +00:00
|
|
|
|
|
|
|
default:
|
2024-03-05 07:05:05 +00:00
|
|
|
$sys['database'] = [
|
|
|
|
'name' => 'Unknown',
|
|
|
|
'version' => '?',
|
|
|
|
];
|
|
|
|
break;
|
2024-02-19 11:00:31 +00:00
|
|
|
}
|
2024-03-05 07:05:05 +00:00
|
|
|
|
2024-02-19 11:00:31 +00:00
|
|
|
return view('admin.settings.system', compact('sys'));
|
|
|
|
}
|
2021-05-08 04:19:58 +00:00
|
|
|
}
|