aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--index.php11
-rw-r--r--lib/activitypub-actor.php56
-rw-r--r--lib/activitypub-webfinger.php22
3 files changed, 89 insertions, 0 deletions
diff --git a/index.php b/index.php
index e82cf27..9429f19 100644
--- a/index.php
+++ b/index.php
@@ -38,6 +38,17 @@
case 'xmlrpc':
require_once(ROOT.DS.'lib'.DS.'xmlrpc.php');
break;
+ case '.well-known':
+ if(!empty(path(1)) && path(1) == 'webfinger') {
+ require_once(ROOT.DS.'lib'.DS.'activitypub-webfinger.php');
+ } else {
+ http_response_code(404);
+ die();
+ }
+ break;
+ case 'actor':
+ require_once(ROOT.DS.'lib'.DS.'activitypub-actor.php');
+ break;
default:
// redirect everything else to the homepage
if(!empty(path(0)) && path(0) != 'page') {
diff --git a/lib/activitypub-actor.php b/lib/activitypub-actor.php
new file mode 100644
index 0000000..705955b
--- /dev/null
+++ b/lib/activitypub-actor.php
@@ -0,0 +1,56 @@
+<?php
+
+ 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([
+ 'digest_alg' => 'sha512',
+ 'private_key_bits' => 4096,
+ 'private_key_type' => OPENSSL_KEYTYPE_RSA,
+ ]);
+ openssl_pkey_export($rsa, $private_key);
+ $public_key = openssl_pkey_get_details($rsa)['key'];
+
+ file_put_contents(ROOT.DS.'keys'.DS.'id_rsa', $private_key);
+ file_put_contents(ROOT.DS.'keys'.DS.'id_rsa.pub', $public_key);
+ } else {
+ $public_key = file_get_contents(ROOT.DS.'keys'.DS.'id_rsa.pub');
+ }
+
+
+
+ /*
+
+ $data = [
+ 'subject' => 'acct:'.$actor.'@'.$domain,
+ 'links' => [
+ 'rel' => 'self',
+ 'type' => 'application/activity+json',
+ 'href' => $config['url'].'/actor'
+ ]
+ ];
+ */
+
+ 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",
+ "preferredUsername": "<?= ltrim($config['microblog_account'], '@') ?>",
+ "inbox": "<?= $config['url'] ?>/inbox",
+
+ "publicKey": {
+ "id": "<?= $config['url'] ?>/actor#main-key",
+ "owner": "<?= $config['url'] ?>/actor",
+ "publicKeyPem": "<?= preg_replace('/\n/', '\n', $public_key) ?>"
+ }
+}
diff --git a/lib/activitypub-webfinger.php b/lib/activitypub-webfinger.php
new file mode 100644
index 0000000..2ad44fb
--- /dev/null
+++ b/lib/activitypub-webfinger.php
@@ -0,0 +1,22 @@
+<?php
+
+ // todo: handle empty usernames
+
+ $actor = ltrim($config['microblog_account'], '@');
+ $url = parse_url($config['url']);
+ $domain = $url['host'];
+ if(!empty($url['path'])) $domain .= rtrim($url['path'], '/');
+
+ $data = [
+ 'subject' => 'acct:'.$actor.'@'.$domain,
+ 'links' => [
+ [
+ 'rel' => 'self',
+ 'type' => 'application/activity+json',
+ 'href' => $config['url'].'/actor'
+ ]
+ ]
+ ];
+
+ header('Content-Type: application/ld+json');
+ echo(json_encode($data, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES));