tidy up
rodzic
911ba84220
commit
a4360594df
35
index.php
35
index.php
|
@ -16,6 +16,7 @@
|
|||
// Set up the Actor's information
|
||||
$username = rawurlencode("example"); // Encoded as it is often used as part of a URl
|
||||
$realName = "E. Xample. Jr.";
|
||||
$summary = "Some text about the user.";
|
||||
$server = $_SERVER['SERVER_NAME']; // Domain name this is hosted on
|
||||
|
||||
// Generate locally or from https://cryptotools.net/rsagen
|
||||
|
@ -36,7 +37,7 @@
|
|||
$requestData = print_r( $_REQUEST, true );
|
||||
$serverData = print_r( $_SERVER, true );
|
||||
|
||||
// Get the type of request
|
||||
// Get the type of request - used in the log filename
|
||||
if ( isset( $body["type"] ) ) {
|
||||
$type = " " . $body["type"];
|
||||
} else {
|
||||
|
@ -48,8 +49,10 @@
|
|||
// Filename for the log
|
||||
$filename = "{$timestamp}{$type}.txt";
|
||||
|
||||
// Save headers and request data to the timestamped file
|
||||
file_put_contents( $filename,
|
||||
// Save headers and request data to the timestamped file in the logs directory
|
||||
if( ! is_dir( "logs" ) ) { mkdir( "logs"); }
|
||||
|
||||
file_put_contents( "logs/{$filename}",
|
||||
"Headers: \n$headers \n\n" .
|
||||
"Body Data: \n$bodyData \n\n" .
|
||||
"POST Data: \n$postData \n\n" .
|
||||
|
@ -64,10 +67,10 @@
|
|||
$path = $_GET["path"];
|
||||
switch ($path) {
|
||||
case "":
|
||||
echo "Silence";
|
||||
die();
|
||||
case ".well-known/webfinger":
|
||||
webfinger();
|
||||
case "{$username}":
|
||||
case rawurldecode( $username ):
|
||||
username();
|
||||
case "following":
|
||||
following();
|
||||
|
@ -118,7 +121,7 @@
|
|||
"inbox" => "https://{$server}/inbox",
|
||||
"preferredUsername" => rawurldecode($username),
|
||||
"name" => "{$realName}",
|
||||
"summary" => "A single file ActivityPub server.",
|
||||
"summary" => "{$summary}",
|
||||
"url" => "https://{$server}",
|
||||
"manuallyApprovesFollowers" => true,
|
||||
"discoverable" => true,
|
||||
|
@ -236,7 +239,12 @@
|
|||
|
||||
$signer = openssl_get_privatekey( $key_private );
|
||||
$stringToSign = "(request-target): post $path\nhost: $host\ndate: $date\ndigest: SHA-256=$digest";
|
||||
openssl_sign($stringToSign, $signature, $signer, OPENSSL_ALGO_SHA256);
|
||||
openssl_sign(
|
||||
$stringToSign,
|
||||
$signature,
|
||||
$signer,
|
||||
OPENSSL_ALGO_SHA256
|
||||
);
|
||||
$signature_b64 = base64_encode( $signature );
|
||||
|
||||
$header = 'keyId="' . $keyId . '",algorithm="rsa-sha256",headers="(request-target) host date digest",signature="' . $signature_b64 . '"';
|
||||
|
@ -317,13 +325,15 @@ HTML;
|
|||
// Get the posted content
|
||||
$content = $_POST["content"];
|
||||
|
||||
// Current time
|
||||
// Current time - ISO8601
|
||||
$timestamp = date( "c" );
|
||||
|
||||
// Outgoing Message ID
|
||||
$guid = uuid();
|
||||
|
||||
// Construct the Note
|
||||
// contentMap is used to prevent unnecessary "translate this post" pop ups
|
||||
// hardcoded to English
|
||||
$note = [
|
||||
"@context" => array(
|
||||
"https://www.w3.org/ns/activitystreams"
|
||||
|
@ -358,6 +368,8 @@ HTML;
|
|||
|
||||
// Save the permalink
|
||||
$note_json = json_encode( $note );
|
||||
// Check for posts/ directory and create it
|
||||
if( ! is_dir( "posts" ) ) { mkdir( "posts"); }
|
||||
file_put_contents( "posts/{$guid}.json", print_r( $note_json, true ) );
|
||||
|
||||
// Read existing users and get their hosts
|
||||
|
@ -384,7 +396,12 @@ HTML;
|
|||
|
||||
$signer = openssl_get_privatekey( $key_private );
|
||||
$stringToSign = "(request-target): post $path\nhost: $host\ndate: $date\ndigest: SHA-256=$digest";
|
||||
openssl_sign( $stringToSign, $signature, $signer, OPENSSL_ALGO_SHA256 );
|
||||
openssl_sign(
|
||||
$stringToSign,
|
||||
$signature,
|
||||
$signer,
|
||||
OPENSSL_ALGO_SHA256
|
||||
);
|
||||
$signature_b64 = base64_encode( $signature );
|
||||
|
||||
$header = 'keyId="' . $keyId . '",algorithm="rsa-sha256",headers="(request-target) host date digest",signature="' . $signature_b64 . '"';
|
||||
|
|
Ładowanie…
Reference in New Issue