diff --git a/app/Http/Controllers/ApiController.php b/app/Http/Controllers/ApiController.php index ec440aef3..dfe48426d 100644 --- a/app/Http/Controllers/ApiController.php +++ b/app/Http/Controllers/ApiController.php @@ -39,8 +39,8 @@ class ApiController extends BaseApiController ], 'activitypub' => [ - 'enabled' => config('pixelfed.activitypub_enabled'), - 'remote_follow' => config('pixelfed.remote_follow_enabled') + 'enabled' => config('federation.activitypub.enabled'), + 'remote_follow' => config('federation.activitypub.remoteFollow') ], 'ab' => [ diff --git a/app/Http/Controllers/FederationController.php b/app/Http/Controllers/FederationController.php index d8941883f..5bf37aa65 100644 --- a/app/Http/Controllers/FederationController.php +++ b/app/Http/Controllers/FederationController.php @@ -26,9 +26,7 @@ class FederationController extends Controller { public function authCheck() { - if (!Auth::check()) { - return abort(403); - } + abort_if(!Auth::check(), 403); } public function authorizeFollow(Request $request) @@ -52,14 +50,14 @@ class FederationController extends Controller public function remoteFollowStore(Request $request) { + return; + $this->authCheck(); $this->validate($request, [ 'url' => 'required|string', ]); - if (config('pixelfed.remote_follow_enabled') !== true) { - abort(403); - } + abort_if(!config('federation.activitypub.remoteFollow'), 403); $follower = Auth::user()->profile; $url = $request->input('url'); @@ -76,6 +74,8 @@ class FederationController extends Controller public function nodeinfoWellKnown() { + abort_if(!config('federation.nodeinfo.enabled'), 404); + $res = [ 'links' => [ [ @@ -90,6 +90,8 @@ class FederationController extends Controller public function nodeinfo() { + abort_if(!config('federation.nodeinfo.enabled'), 404); + $res = Cache::remember('api:nodeinfo', now()->addMinutes(15), function () { $activeHalfYear = Cache::remember('api:nodeinfo:ahy', now()->addHours(12), function() { $count = collect([]); @@ -150,6 +152,8 @@ class FederationController extends Controller public function webfinger(Request $request) { + abort_if(!config('federation.webfinger.enabled'), 404); + $this->validate($request, ['resource'=>'required|string|min:3|max:255']); $resource = $request->input('resource'); @@ -167,22 +171,18 @@ class FederationController extends Controller public function hostMeta(Request $request) { + abort_if(!config('federation.webfinger.enabled'), 404); + $path = route('well-known.webfinger'); - $xml = << - - - -XML; + $xml = ''; return response($xml)->header('Content-Type', 'application/xrd+xml'); } public function userOutbox(Request $request, $username) { - if (config('pixelfed.activitypub_enabled') == false) { - abort(403); - } + abort_if(!config('federation.activitypub.enabled'), 404); + abort_if(!config('federation.activitypub.outbox'), 404); $profile = Profile::whereNull('remote_url')->whereUsername($username)->firstOrFail(); if($profile->status != null) { @@ -201,9 +201,8 @@ XML; public function userInbox(Request $request, $username) { - if (config('pixelfed.activitypub_enabled') == false) { - abort(403); - } + abort_if(!config('federation.activitypub.enabled'), 404); + abort_if(!config('federation.activitypub.inbox'), 404); $profile = Profile::whereNull('domain')->whereUsername($username)->firstOrFail(); if($profile->status != null) { @@ -300,15 +299,14 @@ XML; public function userFollowing(Request $request, $username) { - if (config('pixelfed.activitypub_enabled') == false) { - abort(403); - } + abort_if(!config('federation.activitypub.enabled'), 404); + $profile = Profile::whereNull('remote_url') ->whereUsername($username) ->whereIsPrivate(false) ->firstOrFail(); if($profile->status != null) { - return ProfileController::accountCheck($profile); + return []; } $obj = [ '@context' => 'https://www.w3.org/ns/activitystreams', @@ -324,15 +322,14 @@ XML; public function userFollowers(Request $request, $username) { - if (config('pixelfed.activitypub_enabled') == false) { - abort(403); - } + abort_if(!config('federation.activitypub.enabled'), 404); + $profile = Profile::whereNull('remote_url') ->whereUsername($username) ->whereIsPrivate(false) ->firstOrFail(); if($profile->status != null) { - return ProfileController::accountCheck($profile); + return []; } $obj = [ '@context' => 'https://www.w3.org/ns/activitystreams', diff --git a/app/Http/Controllers/ProfileController.php b/app/Http/Controllers/ProfileController.php index 52201dad1..7050bb6d7 100644 --- a/app/Http/Controllers/ProfileController.php +++ b/app/Http/Controllers/ProfileController.php @@ -51,7 +51,7 @@ class ProfileController extends Controller $settings = $user->user->settings; } - if ($request->wantsJson() && config('pixelfed.activitypub_enabled')) { + if ($request->wantsJson() && config('federation.activitypub.enabled')) { return $this->showActivityPub($request, $user); } @@ -90,7 +90,7 @@ class ProfileController extends Controller $user = Profile::whereUsername($username)->firstOrFail(); $settings = User::whereUsername($username)->firstOrFail()->settings; - if ($request->wantsJson() && config('pixelfed.activitypub_enabled')) { + if ($request->wantsJson() && config('federation.activitypub.enabled')) { return $this->showActivityPub($request, $user); } @@ -150,6 +150,8 @@ class ProfileController extends Controller public function showActivityPub(Request $request, $user) { + abort_if(!config('federation.activitypub.enabled'), 404); + if($user->status != null) { return ProfileController::accountCheck($user); } @@ -161,6 +163,8 @@ class ProfileController extends Controller public function showAtomFeed(Request $request, $user) { + abort_if(!config('federation.atom.enabled'), 404); + $profile = $user = Profile::whereNull('status')->whereNull('domain')->whereUsername($user)->whereIsPrivate(false)->firstOrFail(); if($profile->status != null) { return $this->accountCheck($profile); diff --git a/app/Http/Controllers/SearchController.php b/app/Http/Controllers/SearchController.php index 4bf750591..676118cd8 100644 --- a/app/Http/Controllers/SearchController.php +++ b/app/Http/Controllers/SearchController.php @@ -36,7 +36,7 @@ class SearchController extends Controller $hash = hash('sha256', $tag); $tokens = Cache::remember('api:search:tag:'.$hash, now()->addMinutes(5), function () use ($tag) { $tokens = []; - if(Helpers::validateUrl($tag) != false && config('pixelfed.activitypub_enabled') == true && config('pixelfed.remote_follow_enabled') == true) { + if(Helpers::validateUrl($tag) != false && config('federation.activitypub.enabled') == true && config('federation.activitypub.remoteFollow') == true) { $remote = Helpers::fetchFromUrl($tag); if(isset($remote['type']) && in_array($remote['type'], ['Create', 'Person']) == true) { $type = $remote['type']; diff --git a/app/Http/Controllers/StatusController.php b/app/Http/Controllers/StatusController.php index fbf3acc28..649ab2da1 100644 --- a/app/Http/Controllers/StatusController.php +++ b/app/Http/Controllers/StatusController.php @@ -51,7 +51,7 @@ class StatusController extends Controller } } - if ($request->wantsJson() && config('pixelfed.activitypub_enabled')) { + if ($request->wantsJson() && config('federation.activitypub.enabled')) { return $this->showActivityPub($request, $status); } diff --git a/app/Jobs/StatusPipeline/StatusActivityPubDeliver.php b/app/Jobs/StatusPipeline/StatusActivityPubDeliver.php index 06f22a85d..a2b6d6f93 100644 --- a/app/Jobs/StatusPipeline/StatusActivityPubDeliver.php +++ b/app/Jobs/StatusPipeline/StatusActivityPubDeliver.php @@ -71,7 +71,7 @@ class StatusActivityPubDeliver implements ShouldQueue $payload = json_encode($activity); $client = new Client([ - 'timeout' => config('pixelfed.ap_delivery_timeout') + 'timeout' => config('federation.activitypub.delivery.timeout') ]); $requests = function($audience) use ($client, $activity, $profile, $payload) { @@ -90,7 +90,7 @@ class StatusActivityPubDeliver implements ShouldQueue }; $pool = new Pool($client, $requests($audience), [ - 'concurrency' => config('pixelfed.ap_delivery_concurrency'), + 'concurrency' => config('federation.activitypub.delivery.concurrency'), 'fulfilled' => function ($response, $index) { }, 'rejected' => function ($reason, $index) { diff --git a/app/Jobs/StatusPipeline/StatusDelete.php b/app/Jobs/StatusPipeline/StatusDelete.php index fea254a8b..cd5966389 100644 --- a/app/Jobs/StatusPipeline/StatusDelete.php +++ b/app/Jobs/StatusPipeline/StatusDelete.php @@ -55,7 +55,7 @@ class StatusDelete implements ShouldQueue { $status = $this->status; - if(config('pixelfed.activitypub_enabled') == true) { + if(config('federation.activitypub.enabled') == true) { $this->fanoutDelete($status); } else { $this->unlinkRemoveMedia($status); @@ -125,7 +125,7 @@ class StatusDelete implements ShouldQueue $payload = json_encode($activity); $client = new Client([ - 'timeout' => config('pixelfed.ap_delivery_timeout') + 'timeout' => config('federation.activitypub.delivery.timeout') ]); $requests = function($audience) use ($client, $activity, $profile, $payload) { @@ -144,7 +144,7 @@ class StatusDelete implements ShouldQueue }; $pool = new Pool($client, $requests($audience), [ - 'concurrency' => config('pixelfed.ap_delivery_concurrency'), + 'concurrency' => config('federation.activitypub.delivery.concurrency'), 'fulfilled' => function ($response, $index) { }, 'rejected' => function ($reason, $index) { diff --git a/app/Jobs/StatusPipeline/StatusEntityLexer.php b/app/Jobs/StatusPipeline/StatusEntityLexer.php index df1ed6775..ecad11e1e 100644 --- a/app/Jobs/StatusPipeline/StatusEntityLexer.php +++ b/app/Jobs/StatusPipeline/StatusEntityLexer.php @@ -112,7 +112,7 @@ class StatusEntityLexer implements ShouldQueue $status = $this->status; foreach ($mentions as $mention) { - $mentioned = Profile::whereNull('domain')->whereUsername($mention)->firstOrFail(); + $mentioned = Profile::whereUsername($mention)->first(); if (empty($mentioned) || !isset($mentioned->id)) { continue; @@ -132,7 +132,7 @@ class StatusEntityLexer implements ShouldQueue public function deliver() { - if(config('pixelfed.activitypub_enabled') == true) { + if(config('federation.activitypub.enabled') == true) { StatusActivityPubDeliver::dispatch($this->status); } } diff --git a/app/Util/ActivityPub/Helpers.php b/app/Util/ActivityPub/Helpers.php index d9c69e6bf..03e4cfdcd 100644 --- a/app/Util/ActivityPub/Helpers.php +++ b/app/Util/ActivityPub/Helpers.php @@ -357,6 +357,7 @@ class Helpers { $fdata = new File($file); $path = Storage::putFile($storagePath, $fdata, 'public'); $media = new Media(); + $media->remote_media = true; $media->status_id = $status->id; $media->profile_id = $status->profile_id; $media->user_id = null; diff --git a/config/federation.php b/config/federation.php new file mode 100644 index 000000000..2852f6436 --- /dev/null +++ b/config/federation.php @@ -0,0 +1,40 @@ + [ + 'enabled' => env('ACTIVITY_PUB', false), + 'outbox' => env('AP_OUTBOX', true), + 'inbox' => env('AP_INBOX', true), + 'sharedInbox' => env('AP_SHAREDINBOX', false), + + 'remoteFollow' => false, + + 'delivery' => [ + 'timeout' => env('ACTIVITYPUB_DELIVERY_TIMEOUT', 2.0), + 'concurrency' => env('ACTIVITYPUB_DELIVERY_CONCURRENCY', 10) + ] + ], + + 'atom' => [ + 'enabled' => env('ATOM_FEEDS', true), + ], + + 'nodeinfo' => [ + 'enabled' => env('NODEINFO', true), + ], + + 'webfinger' => [ + 'enabled' => env('WEBFINGER', true) + ], + +]; \ No newline at end of file diff --git a/resources/views/admin/settings/config/general.blade.php b/resources/views/admin/settings/config/general.blade.php index 480ec2dad..7c55cb41f 100644 --- a/resources/views/admin/settings/config/general.blade.php +++ b/resources/views/admin/settings/config/general.blade.php @@ -28,9 +28,9 @@
- +

Enable for federation support.