From 4c4854333137184a860f29c2da09c807dfdf3290 Mon Sep 17 00:00:00 2001 From: lub Date: Fri, 1 Aug 2025 12:42:34 +0000 Subject: [PATCH] move API calls to correct place --- index.php | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/index.php b/index.php index 87b3db2..670c3dc 100644 --- a/index.php +++ b/index.php @@ -7,6 +7,7 @@ define('ACCESS_TOKEN', 'at_bsef'); define('REGISTRATION_PASSWORD', 'asef'); define('REGISTRATION_API_URL', 'http://synapse:8008/_synapse/admin/v1/register'); +define('EVENT_API_URL', 'http://synapse:8008/_matrix/client/v3/rooms/{roomId}/send/{eventType}/{txnId}') if ($_GET['secret'] === REGISTRATION_PASSWORD) { ?> @@ -28,11 +29,20 @@ if ($_GET['secret'] === REGISTRATION_PASSWORD) { $username = filter_var($_POST['username'], FILTER_SANITIZE_FULL_SPECIAL_CHARS); var_dump($_POST); + $content = [ + nonce => $_POST['nonce'], + username => $_POST['username'], + password => $_POST['password'] + admin = false + ]; + $content->mac = hash_hmac('sha1', $content->nonce."\s".$content->username."\s".$content->password."\s".$content->admin + $options = [ 'http' => [ 'method' => 'POST', 'header' => 'authorization: Bearer '.ACCESS_TOKEN, - 'content-type: application/json' + 'content-type: application/json', + 'content' => json_encode($content); ] ]; $context = stream_context_create($options); @@ -59,14 +69,6 @@ Also consider using a password manager.
$_POST['nonce'], - username => $_POST['username'], - password => $_POST['password'] - admin = false - ]; - $content->mac = hash_hmac('sha1', $content->nonce."\s".$content->username."\s".$content->password."\s".$content->admin - $options = [ 'http' => [ 'method' => 'POST', @@ -76,8 +78,8 @@ Also consider using a password manager.
] ]; $context = stream_context_create($options); - $result = file_get_contents(REGISTRATION_API_URL, false, $context); - if ($result === FALSE) { + $message = file_get_contents(EVENT_API_URL, false, $context); + if ($message === FALSE) { # something with errors } else { # success