diff options
author | Arno Richter <oelna@oelna.de> | 2023-08-16 14:52:58 +0200 |
---|---|---|
committer | Arno Richter <oelna@oelna.de> | 2023-08-16 14:52:58 +0200 |
commit | 66c6658bac8b0e99b59e3b9f4eb285f38bcebcf5 (patch) | |
tree | fa54ab21d4c6122df124459030dd5c6af723f1af /lib/activitypub-actor.php | |
parent | ff2858b6ea8f586daa95e51ae21315f86cc5ded5 (diff) | |
download | microblog-66c6658bac8b0e99b59e3b9f4eb285f38bcebcf5.tar.gz microblog-66c6658bac8b0e99b59e3b9f4eb285f38bcebcf5.tar.bz2 microblog-66c6658bac8b0e99b59e3b9f4eb285f38bcebcf5.zip |
huge update to implement first version of activitypub support. closes #16. AP and subdir hosting are incompatible!
Diffstat (limited to 'lib/activitypub-actor.php')
-rw-r--r-- | lib/activitypub-actor.php | 55 |
1 files changed, 37 insertions, 18 deletions
diff --git a/lib/activitypub-actor.php b/lib/activitypub-actor.php index 705955b..b34f582 100644 --- a/lib/activitypub-actor.php +++ b/lib/activitypub-actor.php @@ -1,13 +1,26 @@ <?php + if(!$config['activitypub']) exit('ActivityPub is disabled via config file.'); + + $public_key = activitypub_get_key('public'); + + // generate a key pair, if neccessary + if(!$public_key) { + $key = activitypub_new_key('sha512', 4096, 'RSA'); + + if(!empty($key)) exit('Fatal error: Could not generate a new key!'); + $public_key = $key['key_public']; + } + + /* + // old, file-based key system if(!file_exists(ROOT.DS.'keys'.DS.'id_rsa')) { if(!is_dir(ROOT.DS.'keys')) { mkdir(ROOT.DS.'keys'); } // generate a key pair, if neccessary - - $rsa = openssl_pkey_new([ + $rsa = openssl_pkey_new([ 'digest_alg' => 'sha512', 'private_key_bits' => 4096, 'private_key_type' => OPENSSL_KEYTYPE_RSA, @@ -20,37 +33,43 @@ } else { $public_key = file_get_contents(ROOT.DS.'keys'.DS.'id_rsa.pub'); } + */ - - - /* + if(strpos($_SERVER['HTTP_ACCEPT'], 'application/activity+json') !== false): - $data = [ - 'subject' => 'acct:'.$actor.'@'.$domain, - 'links' => [ - 'rel' => 'self', - 'type' => 'application/activity+json', - 'href' => $config['url'].'/actor' - ] - ]; - */ + header('Content-Type: application/ld+json'); - header('Content-Type: application/ld+json'); - // echo(json_encode($data, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES)); ?>{ "@context": [ "https://www.w3.org/ns/activitystreams", "https://w3id.org/security/v1" ], - "id": "<?= $config['url'] ?>/actor", "type": "Person", + "name": "<?= trim($config['site_title']) ?>", + "summary": "<?= trim($config['site_claim']) ?>", "preferredUsername": "<?= ltrim($config['microblog_account'], '@') ?>", + "manuallyApprovesFollowers": false, + "discoverable": true, + "publishedDate": "2023-01-01T00:00:00Z", + "icon": { + "url": "<?= $config['url'] ?>/favicon-large.png", + "mediaType": "image/png", + "type": "Image" + }, "inbox": "<?= $config['url'] ?>/inbox", - + "outbox": "<?= $config['url'] ?>/outbox", + "followers": "<?= $config['url'] ?>/followers", "publicKey": { "id": "<?= $config['url'] ?>/actor#main-key", "owner": "<?= $config['url'] ?>/actor", "publicKeyPem": "<?= preg_replace('/\n/', '\n', $public_key) ?>" } } +<?php + else: + // this is for people who click through to the profile URL in their mastodon client + header('Location: '.$config['url']); + exit(); + endif; +?> |