move API calls to correct place

main
lub 2 weeks ago
parent 8635dd1c7c
commit 4c48543331

@ -7,6 +7,7 @@
define('ACCESS_TOKEN', 'at_bsef'); define('ACCESS_TOKEN', 'at_bsef');
define('REGISTRATION_PASSWORD', 'asef'); define('REGISTRATION_PASSWORD', 'asef');
define('REGISTRATION_API_URL', 'http://synapse:8008/_synapse/admin/v1/register'); 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) { if ($_GET['secret'] === REGISTRATION_PASSWORD) {
?> ?>
@ -28,11 +29,20 @@ if ($_GET['secret'] === REGISTRATION_PASSWORD) {
$username = filter_var($_POST['username'], FILTER_SANITIZE_FULL_SPECIAL_CHARS); $username = filter_var($_POST['username'], FILTER_SANITIZE_FULL_SPECIAL_CHARS);
var_dump($_POST); 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 = [ $options = [
'http' => [ 'http' => [
'method' => 'POST', 'method' => 'POST',
'header' => 'authorization: Bearer '.ACCESS_TOKEN, 'header' => 'authorization: Bearer '.ACCESS_TOKEN,
'content-type: application/json' 'content-type: application/json',
'content' => json_encode($content);
] ]
]; ];
$context = stream_context_create($options); $context = stream_context_create($options);
@ -59,14 +69,6 @@ Also consider using a password manager.<br>
<?php <?php
} }
$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 = [ $options = [
'http' => [ 'http' => [
'method' => 'POST', 'method' => 'POST',
@ -76,8 +78,8 @@ Also consider using a password manager.<br>
] ]
]; ];
$context = stream_context_create($options); $context = stream_context_create($options);
$result = file_get_contents(REGISTRATION_API_URL, false, $context); $message = file_get_contents(EVENT_API_URL, false, $context);
if ($result === FALSE) { if ($message === FALSE) {
# something with errors # something with errors
} else { } else {
# success # success

Loading…
Cancel
Save