Compare commits
4 Commits
complete_p
...
3250792c9d
| Author | SHA1 | Date | |
|---|---|---|---|
| 3250792c9d | |||
| 16fa0db8ca | |||
| 661b01e1e6 | |||
| a6ad3e4e51 |
@@ -14,6 +14,9 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
require_once(__DIR__ . "/helpers.php");
|
||||
|
||||
class MatrixConnection {
|
||||
|
||||
private $hs;
|
||||
@@ -45,12 +48,8 @@ class MatrixConnection {
|
||||
|
||||
$url = "https://" . $this->hs . "/_matrix/client/r0/rooms/"
|
||||
. urlencode($room_id) . "/send/m.room.message?access_token=" . $this->at;
|
||||
$handle = curl_init($url);
|
||||
curl_setopt($handle, CURLOPT_RETURNTRANSFER, true);
|
||||
curl_setopt($handle, CURLOPT_CONNECTTIMEOUT, 5);
|
||||
curl_setopt($handle, CURLOPT_TIMEOUT, 60);
|
||||
$handle = getCurlHandle($url);
|
||||
curl_setopt($handle, CURLOPT_POSTFIELDS, json_encode($send_message));
|
||||
curl_setopt($handle, CURLOPT_HTTPHEADER, array("Content-Type: application/json"));
|
||||
|
||||
$response = $this->exec_curl_request($handle);
|
||||
return isset($response["event_id"]);
|
||||
@@ -70,37 +69,51 @@ class MatrixConnection {
|
||||
}
|
||||
|
||||
$url = "https://" . $this->hs . "/_matrix/client/r0/profile/@" . $username . ":" . $this->hs;
|
||||
$handle = curl_init($url);
|
||||
curl_setopt($handle, CURLOPT_RETURNTRANSFER, true);
|
||||
curl_setopt($handle, CURLOPT_CONNECTTIMEOUT, 5);
|
||||
curl_setopt($handle, CURLOPT_TIMEOUT, 60);
|
||||
curl_setopt($handle, CURLOPT_HTTPHEADER, array("Content-Type: application/json"));
|
||||
$handle = getCurlHandle($url);
|
||||
|
||||
$res = $this->exec_curl_request($handle);
|
||||
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) {
|
||||
if (!$username) {
|
||||
error_log("no username provided");
|
||||
}
|
||||
if (!$password) {
|
||||
error_log("no message to send");
|
||||
error_log("no password provided");
|
||||
}
|
||||
|
||||
$mac = hash_hmac('sha1', $username, $shared_secret);
|
||||
$nonce = $this->getRegisterNonce();
|
||||
//TODO allow registering of admin.
|
||||
$hmac_content = $nonce . "\x00" . $username . "\x00" . $password . "\x00notadmin";
|
||||
$mac = hash_hmac('sha1', $hmac_content, $shared_secret);
|
||||
|
||||
$data = array(
|
||||
"nonce" => $nonce,
|
||||
"username" => $username,
|
||||
"password" => $password,
|
||||
"mac" => $mac,
|
||||
);
|
||||
$url = "https://" . $this->hs . "/_matrix/client/v2_alpha/register";
|
||||
$handle = curl_init($url);
|
||||
curl_setopt($handle, CURLOPT_RETURNTRANSFER, true);
|
||||
curl_setopt($handle, CURLOPT_CONNECTTIMEOUT, 5);
|
||||
curl_setopt($handle, CURLOPT_TIMEOUT, 60);
|
||||
curl_setopt($handle, CURLOPT_HTTPHEADER, array("Content-Type: application/json"));
|
||||
$url = "https://" . $this->hs . "/_matrix/client/r0/admin/register";
|
||||
$handle = getCurlHandle($url);
|
||||
curl_setopt($handle, CURLOPT_POSTFIELDS, json_encode($data));
|
||||
|
||||
try {
|
||||
@@ -172,7 +185,6 @@ class MatrixMessage {
|
||||
function get_object() {
|
||||
return $this->message;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
@@ -30,4 +30,13 @@ function stripLocalpart($mxid) {
|
||||
return $localpart;
|
||||
}
|
||||
|
||||
function getCurlHandle($url) {
|
||||
$handle = curl_init($url);
|
||||
curl_setopt($handle, CURLOPT_RETURNTRANSFER, true);
|
||||
curl_setopt($handle, CURLOPT_CONNECTTIMEOUT, 5);
|
||||
curl_setopt($handle, CURLOPT_TIMEOUT, 60);
|
||||
curl_setopt($handle, CURLOPT_HTTPHEADER, array("Content-Type: application/json"));
|
||||
return $handle;
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -20,7 +20,7 @@ if (!isset($_SERVER['HTTPS'])) {
|
||||
}
|
||||
|
||||
require_once(__DIR__ . "/../language.php");
|
||||
if (!file_exists("../config.php")) {
|
||||
if (!file_exists(__DIR__ . "/../config.php")) {
|
||||
print($language["NO_CONFIGURATION"]);
|
||||
exit();
|
||||
}
|
||||
|
||||
@@ -51,18 +51,21 @@ try {
|
||||
$email = $user["email"];
|
||||
$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");
|
||||
$adminUrl = $config["webroot"] . "/verify_admin.php?t=" . $admin_token;
|
||||
$mxConn = new MatrixConnection($config["homeserver"], $config["access_token"]);
|
||||
$mxMsg = new MatrixMessage();
|
||||
$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,
|
||||
"@adminUrl" => $adminUrl
|
||||
]));
|
||||
if (isset($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,
|
||||
"@adminUrl" => $adminUrl
|
||||
]));
|
||||
@@ -76,7 +79,7 @@ try {
|
||||
$mx_db->setRegistrationStateVerify(
|
||||
($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("</head><body>");
|
||||
|
||||
@@ -60,6 +60,9 @@ try {
|
||||
$first_name = $user["first_name"];
|
||||
$last_name = $user["last_name"];
|
||||
$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"];
|
||||
$email = $user["email"];
|
||||
|
||||
@@ -99,7 +102,7 @@ try {
|
||||
// send registration_success
|
||||
$res = send_mail_registration_success(
|
||||
$config["homeserver"],
|
||||
$first_name . " " . $last_name,
|
||||
$call_name,
|
||||
$email,
|
||||
$username,
|
||||
// only send password when auto-created
|
||||
@@ -112,11 +115,11 @@ try {
|
||||
$mx_db->setRegistrationStateAdmin(RegisterState::PendingSendRegistrationMail, $token);
|
||||
}
|
||||
} 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->set_type("m.text");
|
||||
$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);
|
||||
throw new Exception("REGISTRATION_FAILED");
|
||||
@@ -129,7 +132,7 @@ try {
|
||||
} elseif ($action == RegisterState::RegistrationDeclined) {
|
||||
$mx_db->setRegistrationStateAdmin(RegisterState::RegistrationDeclined, $token);
|
||||
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("</head><body>");
|
||||
|
||||
Reference in New Issue
Block a user