|
|
@ -4,19 +4,32 @@
|
|
|
|
<title>I M NINJA | Registration</title>
|
|
|
|
<title>I M NINJA | Registration</title>
|
|
|
|
|
|
|
|
|
|
|
|
<?php
|
|
|
|
<?php
|
|
|
|
define('ACCESS_TOKEN', 'at_bsef');
|
|
|
|
define('ACCESS_TOKEN', file_get_contents('/run/secrets/access_token'));
|
|
|
|
define('REGISTRATION_PASSWORD', 'asef');
|
|
|
|
define('REGISTRATION_PASSWORD', file_get_contents('/run/secrets/registration_password'));
|
|
|
|
define('REGISTRATION_API_URL', 'http://synapse:8008/_synapse/admin/v1/register');
|
|
|
|
define('REGISTRATION_SHARED_SECRET', file_get_contents('/run/secrets/registration_shared_secret'));
|
|
|
|
define('EVENT_API_URL', 'http://synapse:8008/_matrix/client/v3/rooms/{roomId}/send/{eventType}/{txnId}')
|
|
|
|
|
|
|
|
if ($_GET['secret'] === REGISTRATION_PASSWORD) {
|
|
|
|
# !qToRyKgjEuHZbzqeKv:imninja.net
|
|
|
|
|
|
|
|
define('ROOM_ID', $_ENV['ROOM_ID']);
|
|
|
|
|
|
|
|
# http://synapse:8008
|
|
|
|
|
|
|
|
define('SYNAPSE_URL', $_ENV['SYNAPSE_URL']);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (isset($_GET['secret']) && $_GET['secret'] === REGISTRATION_PASSWORD) {
|
|
|
|
|
|
|
|
$ch = curl_init();
|
|
|
|
|
|
|
|
curl_setopt($ch, CURLOPT_URL, SYNAPSE_URL.'/_synapse/admin/v1/register');
|
|
|
|
|
|
|
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
|
|
|
|
|
|
|
$response = curl_exec($ch);
|
|
|
|
|
|
|
|
if (curl_error($ch) || curl_getinfo($ch, CURLINFO_HTTP_CODE) !== 200) {
|
|
|
|
|
|
|
|
echo 'Error retrieving nonce. Please try again later.';
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
$nonce = json_decode($response)->nonce;
|
|
|
|
?>
|
|
|
|
?>
|
|
|
|
|
|
|
|
|
|
|
|
<form action="" method="post">
|
|
|
|
<form action="/" method="post">
|
|
|
|
<input type="hidden" name="secret" value="<?php echo REGISTRATION_PASSWORD ?>">
|
|
|
|
<input type="hidden" name="secret" value="<?php echo REGISTRATION_PASSWORD ?>">
|
|
|
|
<input type="hiddeN" name="nonce" value="<?php echo filter_var(file_get_contents(REGISTRATION_API_URL), FILTER_SANITIZE_FULL_SPECIAL_CHARS) ?>">
|
|
|
|
<input type="hidden" name="nonce" value="<?php echo filter_var($nonce, FILTER_SANITIZE_FULL_SPECIAL_CHARS) ?>">
|
|
|
|
|
|
|
|
|
|
|
|
Username:<br>
|
|
|
|
Username:<br>
|
|
|
|
<input type="text" name="username"><br>
|
|
|
|
<input type="text" name="username" style="text-transform: lowercase"><br>
|
|
|
|
<br>
|
|
|
|
<br>
|
|
|
|
Password:<br>
|
|
|
|
Password:<br>
|
|
|
|
<input type="password" name="password"><br>
|
|
|
|
<input type="password" name="password"><br>
|
|
|
@ -25,32 +38,32 @@ if ($_GET['secret'] === REGISTRATION_PASSWORD) {
|
|
|
|
</form>
|
|
|
|
</form>
|
|
|
|
|
|
|
|
|
|
|
|
<?php
|
|
|
|
<?php
|
|
|
|
} elseif ($_POST['secret'] === REGISTRATION_PASSWORD) {
|
|
|
|
}
|
|
|
|
$username = filter_var($_POST['username'], FILTER_SANITIZE_FULL_SPECIAL_CHARS);
|
|
|
|
} elseif (isset($_POST['nonce']) && isset($_POST['secret']) && $_POST['secret'] === REGISTRATION_PASSWORD) {
|
|
|
|
var_dump($_POST);
|
|
|
|
$username = filter_var(strtolower($_POST['username']), FILTER_SANITIZE_FULL_SPECIAL_CHARS);
|
|
|
|
|
|
|
|
|
|
|
|
$content = [
|
|
|
|
$content = [
|
|
|
|
nonce => $_POST['nonce'],
|
|
|
|
'nonce' => $_POST['nonce'],
|
|
|
|
username => $_POST['username'],
|
|
|
|
'username' => $username,
|
|
|
|
password => $_POST['password']
|
|
|
|
'password' => $_POST['password'],
|
|
|
|
admin = false
|
|
|
|
'admin' => 'notadmin'
|
|
|
|
];
|
|
|
|
];
|
|
|
|
$content->mac = hash_hmac('sha1', $content->nonce."\s".$content->username."\s".$content->password."\s".$content->admin
|
|
|
|
$content['mac'] = hash_hmac('sha1', $content['nonce']."\s".$content['username']."\s".$content['password']."\s".$content['admin'], REGISTRATION_SHARED_SECRET);
|
|
|
|
|
|
|
|
|
|
|
|
$options = [
|
|
|
|
$ch = curl_init();
|
|
|
|
'http' => [
|
|
|
|
curl_setopt($ch, CURLOPT_URL, SYNAPSE_URL.'/_synapse/admin/v1/register');
|
|
|
|
'method' => 'POST',
|
|
|
|
curl_setopt($ch, CURLOPT_POST, true);
|
|
|
|
'header' => 'authorization: Bearer '.ACCESS_TOKEN,
|
|
|
|
curl_setopt($ch, CURLOPT_HTTPHEADER, [
|
|
|
|
'content-type: application/json',
|
|
|
|
'content-type: application/json'
|
|
|
|
'content' => json_encode($content);
|
|
|
|
]);
|
|
|
|
]
|
|
|
|
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($content));
|
|
|
|
];
|
|
|
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
|
|
|
$context = stream_context_create($options);
|
|
|
|
$response = curl_exec($ch);
|
|
|
|
$registration = file_get_contents($url, false, $context);
|
|
|
|
if (curl_error($ch) || curl_getinfo($ch, CURLINFO_HTTP_CODE) !== 200) {
|
|
|
|
if ($registration === false) {
|
|
|
|
$decoded_response = json_decode($resposne);
|
|
|
|
?>
|
|
|
|
?>
|
|
|
|
|
|
|
|
|
|
|
|
Registration for "<?php echo $username ?>"unsuccessful. Please try again later.
|
|
|
|
Registration for "<?php echo $username ?>" unsuccessful. Please try again later.
|
|
|
|
|
|
|
|
|
|
|
|
<?php
|
|
|
|
<?php
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
@ -60,29 +73,41 @@ Registration successful. To start using it please install a Matrix client like <
|
|
|
|
<br>
|
|
|
|
<br>
|
|
|
|
Server: <strong>imninja.net</strong><br>
|
|
|
|
Server: <strong>imninja.net</strong><br>
|
|
|
|
Username: <strong><?php echo $username ?></strong><br>
|
|
|
|
Username: <strong><?php echo $username ?></strong><br>
|
|
|
|
|
|
|
|
Matrix ID: <strong><?php echo filter_var($decoded_response->user_id, FILTER_SANITIZE_FULL_SPECIAL_CHARS) ?></strong><br>
|
|
|
|
Password: <strong>* * * * *</strong><br>
|
|
|
|
Password: <strong>* * * * *</strong><br>
|
|
|
|
<br>
|
|
|
|
<br>
|
|
|
|
For password recovery purposes it's recommended to set an email address after you successfully logged on to your new Matrix account.<br>
|
|
|
|
For password recovery purposes it's recommended to set an email address after you successfully logged on to your new Matrix account.<br>
|
|
|
|
<br>
|
|
|
|
<br>
|
|
|
|
Also consider using a password manager.<br>
|
|
|
|
Also consider using a password manager.<br>
|
|
|
|
|
|
|
|
<br>
|
|
|
|
|
|
|
|
|
|
|
|
<?php
|
|
|
|
<?php
|
|
|
|
}
|
|
|
|
echo var_dump($decoded_response);
|
|
|
|
|
|
|
|
|
|
|
|
$options = [
|
|
|
|
# logout out of session that exists after registering
|
|
|
|
'http' => [
|
|
|
|
$ch = curl_init();
|
|
|
|
'method' => 'POST',
|
|
|
|
curl_setopt($ch, CURLOPT_URL, SYNAPSE_URL.'/_matrix/client/v3/logout');
|
|
|
|
'header' => 'authorization: Bearer '.ACCESS_TOKEN,
|
|
|
|
curl_setopt($ch, CURLOPT_POST, true);
|
|
|
|
'content-type: application/json',
|
|
|
|
curl_setopt($ch, CURLOPT_HTTPHEADER, [
|
|
|
|
'content' => json_encode($content);
|
|
|
|
'authorization: Bearer '.$decoded_response->access_token
|
|
|
|
]
|
|
|
|
]);
|
|
|
|
];
|
|
|
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
|
|
|
$context = stream_context_create($options);
|
|
|
|
curl_exec($ch);
|
|
|
|
$message = file_get_contents(EVENT_API_URL, false, $context);
|
|
|
|
|
|
|
|
if ($message === FALSE) {
|
|
|
|
# send admin message
|
|
|
|
# something with errors
|
|
|
|
$ch = curl_init();
|
|
|
|
} else {
|
|
|
|
curl_setopt($ch, CURLOPT_URL, SYNAPSE_URL.'/_matrix/client/v3/rooms/'.ROOM_ID.'/send/m.room.message/'.$nonce);
|
|
|
|
# success
|
|
|
|
curl_setopt($ch, CURLOPT_PUT, true);
|
|
|
|
|
|
|
|
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode([
|
|
|
|
|
|
|
|
'body' => $decoded_response->user_id.' just registered',
|
|
|
|
|
|
|
|
'msgtype' => 'm.text'
|
|
|
|
|
|
|
|
]));
|
|
|
|
|
|
|
|
curl_setopt($ch, CURLOPT_HTTPHEADER, [
|
|
|
|
|
|
|
|
'authorization: Bearer '.ACCESS_TOKEN,
|
|
|
|
|
|
|
|
'content-type: application/json'
|
|
|
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
|
|
|
|
|
|
|
curl_exec($ch);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
echo 'Invalid URL';
|
|
|
|
echo 'Invalid URL';
|
|
|
|