From 227ddf4879f1eb93cf566a22648fa1df61784590 Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Sun, 9 Jun 2019 17:15:01 -0600 Subject: [PATCH 01/14] Add Federation config --- config/federation.php | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 config/federation.php diff --git a/config/federation.php b/config/federation.php new file mode 100644 index 000000000..312a5783f --- /dev/null +++ b/config/federation.php @@ -0,0 +1,38 @@ + [ + 'enabled' => env('ACTIVITY_PUB', false), + 'outbox' => env('AP_OUTBOX', true), + 'inbox' => env('AP_INBOX', true), + 'sharedInbox' => env('AP_SHAREDINBOX', 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 From f3698d6c5265bf4b7a1141f0b7177e03f6166cfe Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Sun, 9 Jun 2019 17:15:35 -0600 Subject: [PATCH 02/14] Update FederationController --- app/Http/Controllers/FederationController.php | 45 +++++++++---------- 1 file changed, 22 insertions(+), 23 deletions(-) diff --git a/app/Http/Controllers/FederationController.php b/app/Http/Controllers/FederationController.php index d8941883f..6eb866b3b 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,6 +50,8 @@ class FederationController extends Controller public function remoteFollowStore(Request $request) { + return; + $this->authCheck(); $this->validate($request, [ 'url' => 'required|string', @@ -76,6 +76,8 @@ class FederationController extends Controller public function nodeinfoWellKnown() { + abort_if(!config('federation.nodeinfo.enabled'), 404); + $res = [ 'links' => [ [ @@ -90,6 +92,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 +154,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 +173,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 +203,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 +301,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 +324,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', From 610c4f34455f7fa30cc98ba77eeb4f21a48c09ca Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Sun, 9 Jun 2019 17:21:06 -0600 Subject: [PATCH 03/14] Update ProfileController --- app/Http/Controllers/ProfileController.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/Http/Controllers/ProfileController.php b/app/Http/Controllers/ProfileController.php index 52201dad1..f573d68e8 100644 --- a/app/Http/Controllers/ProfileController.php +++ b/app/Http/Controllers/ProfileController.php @@ -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); From b6553f82c64973346522034ee1f36f0d5c1bbfb1 Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Sun, 9 Jun 2019 17:22:37 -0600 Subject: [PATCH 04/14] Update ProfileController --- app/Http/Controllers/ProfileController.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/Http/Controllers/ProfileController.php b/app/Http/Controllers/ProfileController.php index f573d68e8..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); } From d7e6350f9f7643f2ead056a3b9239e565f9a31e7 Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Sun, 9 Jun 2019 17:23:13 -0600 Subject: [PATCH 05/14] Update ApiController --- app/Http/Controllers/ApiController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Http/Controllers/ApiController.php b/app/Http/Controllers/ApiController.php index ec440aef3..7f0423670 100644 --- a/app/Http/Controllers/ApiController.php +++ b/app/Http/Controllers/ApiController.php @@ -39,7 +39,7 @@ class ApiController extends BaseApiController ], 'activitypub' => [ - 'enabled' => config('pixelfed.activitypub_enabled'), + 'enabled' => config('federation.activitypub.enabled'), 'remote_follow' => config('pixelfed.remote_follow_enabled') ], From 1c9e823cade15f716019e6beadb44c2aa4a7be1f Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Sun, 9 Jun 2019 17:24:54 -0600 Subject: [PATCH 06/14] Update SearchController --- app/Http/Controllers/SearchController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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']; From ae116457bf1a564b6e73537fe36b7028d4d8ed17 Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Sun, 9 Jun 2019 17:25:17 -0600 Subject: [PATCH 07/14] Update federation config --- config/federation.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/config/federation.php b/config/federation.php index 312a5783f..2852f6436 100644 --- a/config/federation.php +++ b/config/federation.php @@ -17,6 +17,8 @@ return [ '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) From 7bad6adab5ea5cc779a7f8a2b6050d5cb17ffd38 Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Sun, 9 Jun 2019 17:26:24 -0600 Subject: [PATCH 08/14] Update StatusController --- app/Http/Controllers/StatusController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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); } From 00775447796f90af7505a7e2a6da44cb07e6251a Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Sun, 9 Jun 2019 17:27:04 -0600 Subject: [PATCH 09/14] Update StatusDelete --- app/Jobs/StatusPipeline/StatusDelete.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Jobs/StatusPipeline/StatusDelete.php b/app/Jobs/StatusPipeline/StatusDelete.php index fea254a8b..124232075 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); From 2f8d48a0d77c9599779dba10f2ceab0894611231 Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Sun, 9 Jun 2019 17:27:42 -0600 Subject: [PATCH 10/14] Update StatusEntityLexer --- app/Jobs/StatusPipeline/StatusEntityLexer.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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); } } From 4b06d3565a26334e6bf2d1109b88f3cd935411d7 Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Sun, 9 Jun 2019 17:28:42 -0600 Subject: [PATCH 11/14] Update admin settings view --- resources/views/admin/settings/config/general.blade.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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.

From 015c2f995453de6c4258f0ddc4c54ee12955e1a5 Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Sun, 9 Jun 2019 17:38:12 -0600 Subject: [PATCH 12/14] Update StatusPipeline --- app/Jobs/StatusPipeline/StatusActivityPubDeliver.php | 4 ++-- app/Jobs/StatusPipeline/StatusDelete.php | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) 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 124232075..cd5966389 100644 --- a/app/Jobs/StatusPipeline/StatusDelete.php +++ b/app/Jobs/StatusPipeline/StatusDelete.php @@ -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) { From 29022c6a79d20cdaa45753594d875498729d61b0 Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Sun, 9 Jun 2019 17:38:29 -0600 Subject: [PATCH 13/14] Update AP Helpers --- app/Util/ActivityPub/Helpers.php | 1 + 1 file changed, 1 insertion(+) 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; From 9879d3c9426ca04263bf3c4553b885fb2cda6a5e Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Sun, 9 Jun 2019 17:48:27 -0600 Subject: [PATCH 14/14] Update config var --- app/Http/Controllers/ApiController.php | 2 +- app/Http/Controllers/FederationController.php | 6 ++---- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/app/Http/Controllers/ApiController.php b/app/Http/Controllers/ApiController.php index 7f0423670..dfe48426d 100644 --- a/app/Http/Controllers/ApiController.php +++ b/app/Http/Controllers/ApiController.php @@ -40,7 +40,7 @@ class ApiController extends BaseApiController 'activitypub' => [ 'enabled' => config('federation.activitypub.enabled'), - 'remote_follow' => config('pixelfed.remote_follow_enabled') + 'remote_follow' => config('federation.activitypub.remoteFollow') ], 'ab' => [ diff --git a/app/Http/Controllers/FederationController.php b/app/Http/Controllers/FederationController.php index 6eb866b3b..5bf37aa65 100644 --- a/app/Http/Controllers/FederationController.php +++ b/app/Http/Controllers/FederationController.php @@ -51,15 +51,13 @@ 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');