Compare commits
2 Commits
661b01e1e6
...
3250792c9d
| Author | SHA1 | Date | |
|---|---|---|---|
| 3250792c9d | |||
| 16fa0db8ca |
@@ -75,6 +75,25 @@ class MatrixConnection {
|
|||||||
return !(isset($res["errcode"]) && $res["errcode"] == "M_UNKNOWN");
|
return !(isset($res["errcode"]) && $res["errcode"] == "M_UNKNOWN");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getRegisterNonce() {
|
||||||
|
$url = "https://" . $this->hs . "/_matrix/client/r0/admin/register";
|
||||||
|
$handle = getCurlHandle($url);
|
||||||
|
|
||||||
|
try {
|
||||||
|
$response = $this->exec_curl_request($handle);
|
||||||
|
if (is_array($response) && isset($response["nonce"])) {
|
||||||
|
return $response["nonce"];
|
||||||
|
}
|
||||||
|
throw new Exception("INVALID_RESPONSE_FROM_SERVER");
|
||||||
|
} catch (Exception $e) {
|
||||||
|
if (strcmp("AUTHENTICATION_FAILED", $e->getMessage()) == 0) {
|
||||||
|
throw new Exception("WRONG_REGISTRATION_SHARED_SECRET");
|
||||||
|
} else {
|
||||||
|
throw $e;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function register($username, $password, $shared_secret) {
|
function register($username, $password, $shared_secret) {
|
||||||
if (!$username) {
|
if (!$username) {
|
||||||
error_log("no username provided");
|
error_log("no username provided");
|
||||||
@@ -82,15 +101,18 @@ class MatrixConnection {
|
|||||||
if (!$password) {
|
if (!$password) {
|
||||||
error_log("no password provided");
|
error_log("no password provided");
|
||||||
}
|
}
|
||||||
|
$nonce = $this->getRegisterNonce();
|
||||||
$mac = hash_hmac('sha1', $username, $shared_secret);
|
//TODO allow registering of admin.
|
||||||
|
$hmac_content = $nonce . "\x00" . $username . "\x00" . $password . "\x00notadmin";
|
||||||
|
$mac = hash_hmac('sha1', $hmac_content, $shared_secret);
|
||||||
|
|
||||||
$data = array(
|
$data = array(
|
||||||
|
"nonce" => $nonce,
|
||||||
"username" => $username,
|
"username" => $username,
|
||||||
"password" => $password,
|
"password" => $password,
|
||||||
"mac" => $mac,
|
"mac" => $mac,
|
||||||
);
|
);
|
||||||
$url = "https://" . $this->hs . "/_matrix/client/v2_alpha/register";
|
$url = "https://" . $this->hs . "/_matrix/client/r0/admin/register";
|
||||||
$handle = getCurlHandle($url);
|
$handle = getCurlHandle($url);
|
||||||
curl_setopt($handle, CURLOPT_POSTFIELDS, json_encode($data));
|
curl_setopt($handle, CURLOPT_POSTFIELDS, json_encode($data));
|
||||||
|
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ if (!isset($_SERVER['HTTPS'])) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
require_once(__DIR__ . "/../language.php");
|
require_once(__DIR__ . "/../language.php");
|
||||||
if (!file_exists("../config.php")) {
|
if (!file_exists(__DIR__ . "/../config.php")) {
|
||||||
print($language["NO_CONFIGURATION"]);
|
print($language["NO_CONFIGURATION"]);
|
||||||
exit();
|
exit();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -51,18 +51,21 @@ try {
|
|||||||
$email = $user["email"];
|
$email = $user["email"];
|
||||||
$admin_token = $user["admin_token"];
|
$admin_token = $user["admin_token"];
|
||||||
|
|
||||||
|
// we have 2 cases: first and last name or just the username
|
||||||
|
$call_name = strlen($first_name . $last_name) > 0 ? $first_name . " " . $last_name : $username;
|
||||||
|
|
||||||
require_once(__DIR__ . "/../MatrixConnection.php");
|
require_once(__DIR__ . "/../MatrixConnection.php");
|
||||||
$adminUrl = $config["webroot"] . "/verify_admin.php?t=" . $admin_token;
|
$adminUrl = $config["webroot"] . "/verify_admin.php?t=" . $admin_token;
|
||||||
$mxConn = new MatrixConnection($config["homeserver"], $config["access_token"]);
|
$mxConn = new MatrixConnection($config["homeserver"], $config["access_token"]);
|
||||||
$mxMsg = new MatrixMessage();
|
$mxMsg = new MatrixMessage();
|
||||||
$mxMsg->set_body(strtr($language["MSG_USER_WANTS_REGISTER"], [
|
$mxMsg->set_body(strtr($language["MSG_USER_WANTS_REGISTER"], [
|
||||||
"@name" => (strlen($first_name . $last_name) > 0 ? $first_name . " " . $last_name : $username),
|
"@name" => $call_name,
|
||||||
"@note" => $note,
|
"@note" => $note,
|
||||||
"@adminUrl" => $adminUrl
|
"@adminUrl" => $adminUrl
|
||||||
]));
|
]));
|
||||||
if (isset($language["MSG_USER_WANTS_REGISTER_FORMATTED"])) {
|
if (isset($language["MSG_USER_WANTS_REGISTER_FORMATTED"])) {
|
||||||
$mxMsg->set_formatted_body(strtr($language["MSG_USER_WANTS_REGISTER_FORMATTED"], [
|
$mxMsg->set_formatted_body(strtr($language["MSG_USER_WANTS_REGISTER_FORMATTED"], [
|
||||||
"@name" => (strlen($first_name . $last_name) > 0 ? $first_name . " " . $last_name : $username),
|
"@name" => $call_name,
|
||||||
"@note" => $note,
|
"@note" => $note,
|
||||||
"@adminUrl" => $adminUrl
|
"@adminUrl" => $adminUrl
|
||||||
]));
|
]));
|
||||||
@@ -76,7 +79,7 @@ try {
|
|||||||
$mx_db->setRegistrationStateVerify(
|
$mx_db->setRegistrationStateVerify(
|
||||||
($response ? RegisterState::PendingAdminVerify : RegisterState::PendingAdminSend), $token);
|
($response ? RegisterState::PendingAdminVerify : RegisterState::PendingAdminSend), $token);
|
||||||
|
|
||||||
send_mail_pending_approval($config["homeserver"], $first_name . " " . $last_name, $email);
|
send_mail_pending_approval($config["homeserver"], $call_name, $email);
|
||||||
|
|
||||||
print("<title>" . $language["VERIFICATION_SUCEEDED"] . "</title>");
|
print("<title>" . $language["VERIFICATION_SUCEEDED"] . "</title>");
|
||||||
print("</head><body>");
|
print("</head><body>");
|
||||||
|
|||||||
@@ -60,6 +60,9 @@ try {
|
|||||||
$first_name = $user["first_name"];
|
$first_name = $user["first_name"];
|
||||||
$last_name = $user["last_name"];
|
$last_name = $user["last_name"];
|
||||||
$username = $user["username"];
|
$username = $user["username"];
|
||||||
|
// we have 2 cases: first and last name or just the username
|
||||||
|
$call_name = strlen($first_name . $last_name) > 0 ? $first_name . " " . $last_name : $username;
|
||||||
|
|
||||||
$note = $user["note"];
|
$note = $user["note"];
|
||||||
$email = $user["email"];
|
$email = $user["email"];
|
||||||
|
|
||||||
@@ -99,7 +102,7 @@ try {
|
|||||||
// send registration_success
|
// send registration_success
|
||||||
$res = send_mail_registration_success(
|
$res = send_mail_registration_success(
|
||||||
$config["homeserver"],
|
$config["homeserver"],
|
||||||
$first_name . " " . $last_name,
|
$call_name,
|
||||||
$email,
|
$email,
|
||||||
$username,
|
$username,
|
||||||
// only send password when auto-created
|
// only send password when auto-created
|
||||||
@@ -112,11 +115,11 @@ try {
|
|||||||
$mx_db->setRegistrationStateAdmin(RegisterState::PendingSendRegistrationMail, $token);
|
$mx_db->setRegistrationStateAdmin(RegisterState::PendingSendRegistrationMail, $token);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
send_mail_registration_allowed_but_failed($config["homeserver"], $first_name . " " . $last_name, $email);
|
send_mail_registration_allowed_but_failed($config["homeserver"], $call_name, $email);
|
||||||
$mxMsg = new MatrixMessage();
|
$mxMsg = new MatrixMessage();
|
||||||
$mxMsg->set_type("m.text");
|
$mxMsg->set_type("m.text");
|
||||||
$mxMsg->set_body(strtr($language["REGISTRATION_FAILED_FOR"], [
|
$mxMsg->set_body(strtr($language["REGISTRATION_FAILED_FOR"], [
|
||||||
"@name" => strlen($first_name . $last_name) > 0 ? $first_name . " " . $last_name : $username,
|
"@name" => $call_name,
|
||||||
]));
|
]));
|
||||||
$mxConn->send($config["register_room"], $mxMsg);
|
$mxConn->send($config["register_room"], $mxMsg);
|
||||||
throw new Exception("REGISTRATION_FAILED");
|
throw new Exception("REGISTRATION_FAILED");
|
||||||
@@ -129,7 +132,7 @@ try {
|
|||||||
} elseif ($action == RegisterState::RegistrationDeclined) {
|
} elseif ($action == RegisterState::RegistrationDeclined) {
|
||||||
$mx_db->setRegistrationStateAdmin(RegisterState::RegistrationDeclined, $token);
|
$mx_db->setRegistrationStateAdmin(RegisterState::RegistrationDeclined, $token);
|
||||||
send_mail_registration_decline(
|
send_mail_registration_decline(
|
||||||
$config["homeserver"], strlen($first_name . $last_name) > 0 ? $first_name . " " . $last_name : $username, $email, $decline_reason
|
$config["homeserver"], $call_name, $email, $decline_reason
|
||||||
);
|
);
|
||||||
print("<title>" . $language["ADMIN_VERIFY_SITE_TITLE"] . "</title>");
|
print("<title>" . $language["ADMIN_VERIFY_SITE_TITLE"] . "</title>");
|
||||||
print("</head><body>");
|
print("</head><body>");
|
||||||
|
|||||||
Reference in New Issue
Block a user