Update FederationController

This commit is contained in:
Daniel Supernault 2019-06-09 17:15:35 -06:00
parent 227ddf4879
commit f3698d6c52
No known key found for this signature in database
GPG key ID: 0DEF1C662C9033F7

View file

@ -26,9 +26,7 @@ class FederationController extends Controller
{ {
public function authCheck() public function authCheck()
{ {
if (!Auth::check()) { abort_if(!Auth::check(), 403);
return abort(403);
}
} }
public function authorizeFollow(Request $request) public function authorizeFollow(Request $request)
@ -52,6 +50,8 @@ class FederationController extends Controller
public function remoteFollowStore(Request $request) public function remoteFollowStore(Request $request)
{ {
return;
$this->authCheck(); $this->authCheck();
$this->validate($request, [ $this->validate($request, [
'url' => 'required|string', 'url' => 'required|string',
@ -76,6 +76,8 @@ class FederationController extends Controller
public function nodeinfoWellKnown() public function nodeinfoWellKnown()
{ {
abort_if(!config('federation.nodeinfo.enabled'), 404);
$res = [ $res = [
'links' => [ 'links' => [
[ [
@ -90,6 +92,8 @@ class FederationController extends Controller
public function nodeinfo() public function nodeinfo()
{ {
abort_if(!config('federation.nodeinfo.enabled'), 404);
$res = Cache::remember('api:nodeinfo', now()->addMinutes(15), function () { $res = Cache::remember('api:nodeinfo', now()->addMinutes(15), function () {
$activeHalfYear = Cache::remember('api:nodeinfo:ahy', now()->addHours(12), function() { $activeHalfYear = Cache::remember('api:nodeinfo:ahy', now()->addHours(12), function() {
$count = collect([]); $count = collect([]);
@ -150,6 +154,8 @@ class FederationController extends Controller
public function webfinger(Request $request) public function webfinger(Request $request)
{ {
abort_if(!config('federation.webfinger.enabled'), 404);
$this->validate($request, ['resource'=>'required|string|min:3|max:255']); $this->validate($request, ['resource'=>'required|string|min:3|max:255']);
$resource = $request->input('resource'); $resource = $request->input('resource');
@ -167,22 +173,18 @@ class FederationController extends Controller
public function hostMeta(Request $request) public function hostMeta(Request $request)
{ {
abort_if(!config('federation.webfinger.enabled'), 404);
$path = route('well-known.webfinger'); $path = route('well-known.webfinger');
$xml = <<<XML $xml = '<?xml version="1.0" encoding="UTF-8"?><XRD xmlns="http://docs.oasis-open.org/ns/xri/xrd-1.0"><Link rel="lrdd" type="application/xrd+xml" template="{$path}?resource={uri}"/></XRD>';
<?xml version="1.0" encoding="UTF-8"?>
<XRD xmlns="http://docs.oasis-open.org/ns/xri/xrd-1.0">
<Link rel="lrdd" type="application/xrd+xml" template="{$path}?resource={uri}"/>
</XRD>
XML;
return response($xml)->header('Content-Type', 'application/xrd+xml'); return response($xml)->header('Content-Type', 'application/xrd+xml');
} }
public function userOutbox(Request $request, $username) public function userOutbox(Request $request, $username)
{ {
if (config('pixelfed.activitypub_enabled') == false) { abort_if(!config('federation.activitypub.enabled'), 404);
abort(403); abort_if(!config('federation.activitypub.outbox'), 404);
}
$profile = Profile::whereNull('remote_url')->whereUsername($username)->firstOrFail(); $profile = Profile::whereNull('remote_url')->whereUsername($username)->firstOrFail();
if($profile->status != null) { if($profile->status != null) {
@ -201,9 +203,8 @@ XML;
public function userInbox(Request $request, $username) public function userInbox(Request $request, $username)
{ {
if (config('pixelfed.activitypub_enabled') == false) { abort_if(!config('federation.activitypub.enabled'), 404);
abort(403); abort_if(!config('federation.activitypub.inbox'), 404);
}
$profile = Profile::whereNull('domain')->whereUsername($username)->firstOrFail(); $profile = Profile::whereNull('domain')->whereUsername($username)->firstOrFail();
if($profile->status != null) { if($profile->status != null) {
@ -300,15 +301,14 @@ XML;
public function userFollowing(Request $request, $username) public function userFollowing(Request $request, $username)
{ {
if (config('pixelfed.activitypub_enabled') == false) { abort_if(!config('federation.activitypub.enabled'), 404);
abort(403);
}
$profile = Profile::whereNull('remote_url') $profile = Profile::whereNull('remote_url')
->whereUsername($username) ->whereUsername($username)
->whereIsPrivate(false) ->whereIsPrivate(false)
->firstOrFail(); ->firstOrFail();
if($profile->status != null) { if($profile->status != null) {
return ProfileController::accountCheck($profile); return [];
} }
$obj = [ $obj = [
'@context' => 'https://www.w3.org/ns/activitystreams', '@context' => 'https://www.w3.org/ns/activitystreams',
@ -324,15 +324,14 @@ XML;
public function userFollowers(Request $request, $username) public function userFollowers(Request $request, $username)
{ {
if (config('pixelfed.activitypub_enabled') == false) { abort_if(!config('federation.activitypub.enabled'), 404);
abort(403);
}
$profile = Profile::whereNull('remote_url') $profile = Profile::whereNull('remote_url')
->whereUsername($username) ->whereUsername($username)
->whereIsPrivate(false) ->whereIsPrivate(false)
->firstOrFail(); ->firstOrFail();
if($profile->status != null) { if($profile->status != null) {
return ProfileController::accountCheck($profile); return [];
} }
$obj = [ $obj = [
'@context' => 'https://www.w3.org/ns/activitystreams', '@context' => 'https://www.w3.org/ns/activitystreams',