diff --git a/DOCUMENTATION/SYSTEM_ADMINISTRATORS/socialfy-another-domain/README.md b/DOCUMENTATION/SYSTEM_ADMINISTRATORS/socialfy-another-domain/README.md new file mode 100644 index 0000000000..eb510f1c13 --- /dev/null +++ b/DOCUMENTATION/SYSTEM_ADMINISTRATORS/socialfy-another-domain/README.md @@ -0,0 +1,15 @@ +#Simple way to Webfinger enable your domain -- needs PHP + +##Step 1 + +Put the 'dot-well-known' on your website, so it loads at: + + https://another_cool.org/.well-known/ + +(Remember the . at the beginning of this one, which is common practice +for "hidden" files and why we have renamed it "dot-") + +## Step 2 + +Edit the .well-known/webfinger/index.php file and replace "https://www.example.org/gnusocial/index.php" with the domain name +you're hosting the .well-known handler on. diff --git a/DOCUMENTATION/SYSTEM_ADMINISTRATORS/socialfy-another-domain/README.txt b/DOCUMENTATION/SYSTEM_ADMINISTRATORS/socialfy-another-domain/README.txt deleted file mode 100644 index 7cb01ed2ef..0000000000 --- a/DOCUMENTATION/SYSTEM_ADMINISTRATORS/socialfy-another-domain/README.txt +++ /dev/null @@ -1,56 +0,0 @@ -Initial simple way to Webfinger enable your domain -- needs PHP. -================================================================ - -This guide needs some updating, since it will only guide you to present -XML data (while the curl command likely gives you JSON). The workaround -is to simply make curl get 'webfinger.xml' instead, and/or have another -file that contains JSON, but that requires editing the PHP file as well. - -Step 1 -====== - -Put the 'dot-well-known' on your website, so it loads at: - - https://example.com/.well-known/ - -(Remember the . at the beginning of this one, which is common practice -for "hidden" files and why we have renamed it "dot-") - -Step 2 -====== - -Edit the .well-known/host-meta file and replace "example.com" with the -domain name you're hosting the .well-known directory on. - -Using vim you can do this as a quick method: - $ vim .well-known/host-meta [ENTER] - :%s/example.com/domain.com/ [ENTER] - :wq [ENTER] - -Step 3 -====== - -For each user on your site, and this might only be you... - -In the webfinger directory, make a copy of the example@example.com.xml file -so that it's called (replace username and example.com with appropriate -values, the domain name should be the same as you're "socialifying"): - - username@example.com.xml - -Then edit the file contents, replacing "social.example.com" with your -GNU social instance's base path, and change the user ID number (and -nickname for the FOAF link) to that of your account on your social -site. If you don't know your user ID number, you can see this on your -GNU social profile page by looking at the destination URLs in the -Feeds links. - -PROTIP: You can get the bulk of the contents (note the element though) - from curling down your real webfinger data: -$ curl https://social.example.com/.well-known/webfinger?resource=acct:username@social.example.com - -Finally -======= - -Using this method, though fiddly, you can now be @user@domain without -the need for any prefixes for subdomains, etc. diff --git a/DOCUMENTATION/SYSTEM_ADMINISTRATORS/socialfy-another-domain/dot-well-known/host-meta b/DOCUMENTATION/SYSTEM_ADMINISTRATORS/socialfy-another-domain/dot-well-known/host-meta deleted file mode 100644 index bba942f673..0000000000 --- a/DOCUMENTATION/SYSTEM_ADMINISTRATORS/socialfy-another-domain/dot-well-known/host-meta +++ /dev/null @@ -1,5 +0,0 @@ - - - - diff --git a/DOCUMENTATION/SYSTEM_ADMINISTRATORS/socialfy-another-domain/dot-well-known/webfinger/example@example.com.xml b/DOCUMENTATION/SYSTEM_ADMINISTRATORS/socialfy-another-domain/dot-well-known/webfinger/example@example.com.xml deleted file mode 100644 index 3e8c9de678..0000000000 --- a/DOCUMENTATION/SYSTEM_ADMINISTRATORS/socialfy-another-domain/dot-well-known/webfinger/example@example.com.xml +++ /dev/null @@ -1,35 +0,0 @@ - - - acct:username@example.com - acct:username@social.example.com - https://social.example.com/user/1 - - - - - - - - - - - - - - - - diff --git a/DOCUMENTATION/SYSTEM_ADMINISTRATORS/socialfy-another-domain/dot-well-known/webfinger/index.php b/DOCUMENTATION/SYSTEM_ADMINISTRATORS/socialfy-another-domain/dot-well-known/webfinger/index.php index 91071bc4c3..e7176c07f7 100644 --- a/DOCUMENTATION/SYSTEM_ADMINISTRATORS/socialfy-another-domain/dot-well-known/webfinger/index.php +++ b/DOCUMENTATION/SYSTEM_ADMINISTRATORS/socialfy-another-domain/dot-well-known/webfinger/index.php @@ -1,43 +1,56 @@ . +// FIXME: REPLACE \/ here +define('MY_GNUSOCIAL', 'https://www.example.org/gnusocial/index.php'); + +/** + * This is a general solution for when you can't have your GNU social instance in the domain root and for when you want to + * socialfy from another domain. */ - -// basename should make sure we can't escape this directory -$u = basename($_GET['resource']); - -if (!strpos($u, '@')) { - throw new Exception('Bad resource'); - exit(1); +// From https://www.php.net/manual/en/function.getallheaders.php#84262 (joyview at gmail dot com) +if (!function_exists('getallheaders')) { + function getallheaders() + { + $headers = []; + foreach ($_SERVER as $name => $value) { + if (substr($name, 0, 5) == 'HTTP_') { + $headers[str_replace(' ', '-', ucwords(strtolower(str_replace('_', ' ', substr($name, 5)))))] = $value; + } + } + return $headers; + } } +$ch = curl_init(); +curl_setopt($ch, CURLOPT_HTTPHEADER, getallheaders()); +curl_setopt($ch, CURLOPT_URL, MY_GNUSOCIAL . str_replace('webfinger/', 'webfinger', $_SERVER['REQUEST_URI'])); +curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); +curl_setopt($ch, CURLOPT_HEADER, true); +$response = curl_exec($ch); +$header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE); +$body = substr($response, $header_size); +// From https://stackoverflow.com/a/10590242 (c.hill) +function get_headers_from_curl_response($response) +{ + $headers = array(); -if (mb_strpos($u, 'acct:')===0) { - $u = substr($u, 5); + $header_text = substr($response, 0, strpos($response, "\r\n\r\n")); + + foreach (explode("\r\n", $header_text) as $i => $line) { + if ($i === 0) { + $headers['http_code'] = $line; + } else { + list($key, $value) = explode(': ', $line); + + $headers[$key] = $value; + } + } + + return $headers; } - -// Just to be a little bit safer, you know, with all the unicode stuff going on -$u = filter_var($u, FILTER_SANITIZE_EMAIL); - -$f = $u . ".xml"; - -if (file_exists($f)) { - header('Content-Disposition: attachment; filename="'.urlencode($f).'"'); - header('Content-type: application/xrd+xml'); - echo file_get_contents($f); +$headers = get_headers_from_curl_response($response); +foreach ($headers as $name => $value) { + header("{$name}: $value"); } +echo $body; +curl_close($ch);