AdminSettingsService.php 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. <?php
  2. namespace App\Services;
  3. use App\Services\Internal\BeagleService;
  4. use App\User;
  5. use Illuminate\Support\Str;
  6. class AdminSettingsService
  7. {
  8. public static function getAll()
  9. {
  10. return [
  11. 'features' => self::getFeatures(),
  12. 'landing' => self::getLanding(),
  13. 'branding' => self::getBranding(),
  14. 'media' => self::getMedia(),
  15. 'rules' => self::getRules(),
  16. 'suggested_rules' => self::getSuggestedRules(),
  17. 'users' => self::getUsers(),
  18. 'posts' => self::getPosts(),
  19. 'platform' => self::getPlatform(),
  20. 'storage' => self::getStorage(),
  21. ];
  22. }
  23. public static function getFeatures()
  24. {
  25. $cloud_storage = (bool) config_cache('pixelfed.cloud_storage');
  26. $cloud_disk = config('filesystems.cloud');
  27. $cloud_ready = ! empty(config('filesystems.disks.'.$cloud_disk.'.key')) && ! empty(config('filesystems.disks.'.$cloud_disk.'.secret'));
  28. $openReg = (bool) config_cache('pixelfed.open_registration');
  29. $curOnboarding = (bool) config_cache('instance.curated_registration.enabled');
  30. $regState = $openReg ? 'open' : ($curOnboarding ? 'filtered' : 'closed');
  31. return [
  32. 'registration_status' => $regState,
  33. 'cloud_storage' => $cloud_ready && $cloud_storage,
  34. 'activitypub_enabled' => (bool) config_cache('federation.activitypub.enabled'),
  35. 'authorized_fetch' => (bool) config_cache('federation.activitypub.authorized_fetch'),
  36. 'account_migration' => (bool) config_cache('federation.migration'),
  37. 'mobile_apis' => (bool) config_cache('pixelfed.oauth_enabled'),
  38. 'stories' => (bool) config_cache('instance.stories.enabled'),
  39. 'instagram_import' => (bool) config_cache('pixelfed.import.instagram.enabled'),
  40. 'autospam_enabled' => (bool) config_cache('pixelfed.bouncer.enabled'),
  41. ];
  42. }
  43. public static function getLanding()
  44. {
  45. $availableAdmins = User::whereIsAdmin(true)->get();
  46. $currentAdmin = config_cache('instance.admin.pid');
  47. return [
  48. 'admins' => $availableAdmins,
  49. 'current_admin' => $currentAdmin,
  50. 'show_directory' => (bool) config_cache('instance.landing.show_directory'),
  51. 'show_explore' => (bool) config_cache('instance.landing.show_explore'),
  52. ];
  53. }
  54. public static function getBranding()
  55. {
  56. return [
  57. 'name' => config_cache('app.name'),
  58. 'short_description' => config_cache('app.short_description'),
  59. 'long_description' => config_cache('app.description'),
  60. ];
  61. }
  62. public static function getMedia()
  63. {
  64. return [
  65. 'max_photo_size' => config_cache('pixelfed.max_photo_size'),
  66. 'max_album_length' => config_cache('pixelfed.max_album_length'),
  67. 'image_quality' => config_cache('pixelfed.image_quality'),
  68. 'media_types' => config_cache('pixelfed.media_types'),
  69. 'optimize_image' => (bool) config_cache('pixelfed.optimize_image'),
  70. 'optimize_video' => (bool) config_cache('pixelfed.optimize_video'),
  71. ];
  72. }
  73. public static function getRules()
  74. {
  75. return config_cache('app.rules') ? json_decode(config_cache('app.rules'), true) : [];
  76. }
  77. public static function getSuggestedRules()
  78. {
  79. return BeagleService::getDefaultRules();
  80. }
  81. public static function getUsers()
  82. {
  83. $autoFollow = config_cache('account.autofollow_usernames');
  84. if (strlen($autoFollow) >= 2) {
  85. $autoFollow = explode(',', $autoFollow);
  86. } else {
  87. $autoFollow = [];
  88. }
  89. return [
  90. 'require_email_verification' => (bool) config_cache('pixelfed.enforce_email_verification'),
  91. 'enforce_account_limit' => (bool) config_cache('pixelfed.enforce_account_limit'),
  92. 'max_account_size' => config_cache('pixelfed.max_account_size'),
  93. 'admin_autofollow' => (bool) config_cache('account.autofollow'),
  94. 'admin_autofollow_accounts' => $autoFollow,
  95. 'max_user_blocks' => (int) config_cache('instance.user_filters.max_user_blocks'),
  96. 'max_user_mutes' => (int) config_cache('instance.user_filters.max_user_mutes'),
  97. 'max_domain_blocks' => (int) config_cache('instance.user_filters.max_domain_blocks'),
  98. ];
  99. }
  100. public static function getPosts()
  101. {
  102. return [
  103. 'max_caption_length' => config_cache('pixelfed.max_caption_length'),
  104. 'max_altext_length' => config_cache('pixelfed.max_altext_length'),
  105. ];
  106. }
  107. public static function getPlatform()
  108. {
  109. return [
  110. 'allow_app_registration' => (bool) config_cache('pixelfed.allow_app_registration'),
  111. 'app_registration_rate_limit_attempts' => config_cache('pixelfed.app_registration_rate_limit_attempts'),
  112. 'app_registration_rate_limit_decay' => config_cache('pixelfed.app_registration_rate_limit_decay'),
  113. 'app_registration_confirm_rate_limit_attempts' => config_cache('pixelfed.app_registration_confirm_rate_limit_attempts'),
  114. 'app_registration_confirm_rate_limit_decay' => config_cache('pixelfed.app_registration_confirm_rate_limit_decay'),
  115. 'allow_post_embeds' => (bool) config_cache('instance.embed.post'),
  116. 'allow_profile_embeds' => (bool) config_cache('instance.embed.profile'),
  117. 'captcha_enabled' => (bool) config_cache('captcha.enabled'),
  118. 'captcha_on_login' => (bool) config_cache('captcha.active.login'),
  119. 'captcha_on_register' => (bool) config_cache('captcha.active.register'),
  120. 'captcha_secret' => Str::of(config_cache('captcha.secret'))->mask('*', 4, -4),
  121. 'captcha_sitekey' => Str::of(config_cache('captcha.sitekey'))->mask('*', 4, -4),
  122. 'custom_emoji_enabled' => (bool) config_cache('federation.custom_emoji.enabled'),
  123. ];
  124. }
  125. public static function getStorage()
  126. {
  127. $cloud_storage = (bool) config_cache('pixelfed.cloud_storage');
  128. $cloud_disk = config('filesystems.cloud');
  129. $cloud_ready = ! empty(config('filesystems.disks.'.$cloud_disk.'.key')) && ! empty(config('filesystems.disks.'.$cloud_disk.'.secret'));
  130. $primaryDisk = (bool) $cloud_ready && $cloud_storage;
  131. $pkey = 'filesystems.disks.'.$cloud_disk.'.';
  132. $disk = [
  133. 'driver' => $cloud_disk,
  134. 'key' => Str::of(config_cache($pkey.'key'))->mask('*', 0, -2),
  135. 'secret' => Str::of(config_cache($pkey.'secret'))->mask('*', 0, -2),
  136. 'region' => config_cache($pkey.'region'),
  137. 'bucket' => config_cache($pkey.'bucket'),
  138. 'visibility' => config_cache($pkey.'visibility'),
  139. 'endpoint' => config_cache($pkey.'endpoint'),
  140. 'url' => config_cache($pkey.'url'),
  141. 'use_path_style_endpoint' => config_cache($pkey.'use_path_style_endpoint'),
  142. ];
  143. return [
  144. 'primary_disk' => $primaryDisk ? 'cloud' : 'local',
  145. 'cloud_ready' => (bool) $cloud_ready,
  146. 'cloud_disk' => $cloud_disk,
  147. 'disk_config' => $disk,
  148. ];
  149. }
  150. }