aboutsummaryrefslogtreecommitdiff
path: root/lib/activitypub-actor.php
diff options
context:
space:
mode:
Diffstat (limited to 'lib/activitypub-actor.php')
-rw-r--r--lib/activitypub-actor.php55
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;
+?>