change config to array
This commit is contained in:
@@ -1,8 +1,17 @@
|
|||||||
<?php
|
<?php
|
||||||
$homeserver = "example.com";
|
$config = [
|
||||||
$access_token = "To be used for sending the registration notification";
|
"homeserver" => "example.com",
|
||||||
$register_room = '$registerRoomID:example.com';
|
"access_token" => "To be used for sending the registration notification",
|
||||||
|
|
||||||
$webroot="https://myregisterdomain.net/";
|
// Which e-mail-adresse shall the bot use to send e-mails?
|
||||||
$howToURL = "https://my-url-for-storing-howTos.net";
|
"register_email" => 'register_bot@example.com',
|
||||||
|
// Where should the bot post registration requests to?
|
||||||
|
"register_room" => '$registerRoomID:example.com',
|
||||||
|
|
||||||
|
// Where is the public part of the bot located? make sure you have a / at the end
|
||||||
|
"webroot" => "https://myregisterdomain.net/",
|
||||||
|
|
||||||
|
// optional: Do you have a place where howTo's are located? If not leave this value out
|
||||||
|
"howToURL" => "https://my-url-for-storing-howTos.net",
|
||||||
|
]
|
||||||
?>
|
?>
|
||||||
|
|||||||
18
cron.php
18
cron.php
@@ -20,9 +20,9 @@ foreach ($mx_db->query($sql) as $row) {
|
|||||||
try {
|
try {
|
||||||
switch ($state) {
|
switch ($state) {
|
||||||
case RegisterState::PendingEmailSend:
|
case RegisterState::PendingEmailSend:
|
||||||
$verify_url = $webroot . "/verify.php?t=" . $row["verify_token"];
|
$verify_url = $config["webroot"] . "/verify.php?t=" . $row["verify_token"];
|
||||||
$success = send_mail_pending_verification(
|
$success = send_mail_pending_verification(
|
||||||
$homeserver,
|
$config["homeserver"],
|
||||||
$row["first_name"] . " " . $row["last_name"],
|
$row["first_name"] . " " . $row["last_name"],
|
||||||
$row["email"],
|
$row["email"],
|
||||||
$row["verify_url"]);
|
$row["verify_url"]);
|
||||||
@@ -35,8 +35,8 @@ foreach ($mx_db->query($sql) as $row) {
|
|||||||
break;
|
break;
|
||||||
case RegisterState::PendingAdminSend:
|
case RegisterState::PendingAdminSend:
|
||||||
require_once("MatrixConnection.php");
|
require_once("MatrixConnection.php");
|
||||||
$adminUrl = $webroot . "/verify_admin.php?t=" . $row["admin_token"];
|
$adminUrl = $config["webroot"] . "/verify_admin.php?t=" . $row["admin_token"];
|
||||||
$mxConn = new MatrixConnection($homeserver, $access_token);
|
$mxConn = new MatrixConnection($config["homeserver"], $config["access_token"]);
|
||||||
$mxMsg = new MatrixMessage();
|
$mxMsg = new MatrixMessage();
|
||||||
$mxMsg->set_body($first_name . ' ' . $last_name . " möchte sich registrieren und hat folgende Notiz hinterlassen:\r\n"
|
$mxMsg->set_body($first_name . ' ' . $last_name . " möchte sich registrieren und hat folgende Notiz hinterlassen:\r\n"
|
||||||
. $row["note"] . "\r\n"
|
. $row["note"] . "\r\n"
|
||||||
@@ -45,12 +45,12 @@ foreach ($mx_db->query($sql) as $row) {
|
|||||||
. $row["note"] . "<br />"
|
. $row["note"] . "<br />"
|
||||||
. "Zum Bearbeiten <a href=\"". $adminUrl . "\">hier</a> klicken");
|
. "Zum Bearbeiten <a href=\"". $adminUrl . "\">hier</a> klicken");
|
||||||
$mxMsg->set_type("m.text");
|
$mxMsg->set_type("m.text");
|
||||||
$response = $mxConn->send($register_room, $mxMsg);
|
$response = $mxConn->send($config["register_room"], $mxMsg);
|
||||||
|
|
||||||
if ($response) {
|
if ($response) {
|
||||||
$mx_db->setRegistrationStateById(RegisterState::PendingAdminVerify, $row["id"]);
|
$mx_db->setRegistrationStateById(RegisterState::PendingAdminVerify, $row["id"]);
|
||||||
|
|
||||||
send_mail_pending_approval($homeserver, $first_name . " " . $last_name, $email);
|
send_mail_pending_approval($config["homeserver"], $first_name . " " . $last_name, $email);
|
||||||
} else {
|
} else {
|
||||||
throw new Exception("Could not send notification for ".$row["first_name"]." ".$row["last_name"]."(".$row["id"].") to admins.");
|
throw new Exception("Could not send notification for ".$row["first_name"]." ".$row["last_name"]."(".$row["id"].") to admins.");
|
||||||
}
|
}
|
||||||
@@ -61,18 +61,18 @@ foreach ($mx_db->query($sql) as $row) {
|
|||||||
$password = addUser($row["first_name"], $row["last_name"], $row["username"], $row["email"]);
|
$password = addUser($row["first_name"], $row["last_name"], $row["username"], $row["email"]);
|
||||||
if ($password != NULL) {
|
if ($password != NULL) {
|
||||||
// send registration_success
|
// send registration_success
|
||||||
$res = send_mail_registration_success($homeserver, $first_name . " " . $last_name, $email, $username, $password, $howToURL);
|
$res = send_mail_registration_success($config["homeserver"], $first_name . " " . $last_name, $email, $username, $password, $config["howToURL"]);
|
||||||
if ($res) {
|
if ($res) {
|
||||||
$mx_db->setRegistrationStateById(RegisterState::AllDone, $row["id"]);
|
$mx_db->setRegistrationStateById(RegisterState::AllDone, $row["id"]);
|
||||||
} else {
|
} else {
|
||||||
$mx_db->setRegistrationStateById(RegisterState::PendingSendRegistrationMail, $row["id"]);
|
$mx_db->setRegistrationStateById(RegisterState::PendingSendRegistrationMail, $row["id"]);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
send_mail_registration_allowed_but_failed($homeserver, $first_name . " " . $last_name, $email);
|
send_mail_registration_allowed_but_failed($config["homeserver"], $first_name . " " . $last_name, $email);
|
||||||
$mxMsg = new MatrixMessage();
|
$mxMsg = new MatrixMessage();
|
||||||
$mxMsg->set_type("m.text");
|
$mxMsg->set_type("m.text");
|
||||||
$mxMsg->set_body("Fehler beim Registrieren von " . $first_name . " " . $last_name . ".");
|
$mxMsg->set_body("Fehler beim Registrieren von " . $first_name . " " . $last_name . ".");
|
||||||
$mxConn->send($register_room, $mxMsg);
|
$mxConn->send($config["register_room"], $mxMsg);
|
||||||
throw new Exception($language["REGISTRATION_FAILED"]);
|
throw new Exception($language["REGISTRATION_FAILED"]);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -60,10 +60,10 @@ if ($_SERVER["REQUEST_METHOD"] == "POST") {
|
|||||||
}
|
}
|
||||||
$verify_token = $res["verify_token"];
|
$verify_token = $res["verify_token"];
|
||||||
|
|
||||||
$verify_url = $webroot . "/verify.php?t=" . $verify_token;
|
$verify_url = $config["webroot"] . "/verify.php?t=" . $verify_token;
|
||||||
require_once "../mail_templates.php";
|
require_once "../mail_templates.php";
|
||||||
$success = send_mail_pending_verification(
|
$success = send_mail_pending_verification(
|
||||||
$homeserver,
|
$config["homeserver"],
|
||||||
$first_name . " " . $last_name,
|
$first_name . " " . $last_name,
|
||||||
$email,
|
$email,
|
||||||
$verify_url);
|
$verify_url);
|
||||||
@@ -82,12 +82,12 @@ if ($_SERVER["REQUEST_METHOD"] == "POST") {
|
|||||||
print("</head><body>");
|
print("</head><body>");
|
||||||
print("<h1>" . $language["REGISTRATION_REQUEST_FAILED"] . "</h1>");
|
print("<h1>" . $language["REGISTRATION_REQUEST_FAILED"] . "</h1>");
|
||||||
print("<p>" . $e->getMessage() . "</p>");
|
print("<p>" . $e->getMessage() . "</p>");
|
||||||
print("<a href=\"" . $webroot . "/register.php" . "\">Zur Registrierungsseite</a>");
|
print("<a href=\"" . $config["webroot"] . "/register.php" . "\">Zur Registrierungsseite</a>");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$_SESSION["token"] = bin2hex(random_bytes(16));
|
$_SESSION["token"] = bin2hex(random_bytes(16));
|
||||||
?>
|
?>
|
||||||
<title>Registriere dich für <?php echo $homeserver; ?></title>
|
<title>Registriere dich für <?php echo $config["homeserver"]; ?></title>
|
||||||
<link href="//netdna.bootstrapcdn.com/bootstrap/3.1.0/css/bootstrap.min.css" rel="stylesheet">
|
<link href="//netdna.bootstrapcdn.com/bootstrap/3.1.0/css/bootstrap.min.css" rel="stylesheet">
|
||||||
<style>
|
<style>
|
||||||
body{
|
body{
|
||||||
@@ -111,7 +111,7 @@ body{
|
|||||||
<div class="col-xs-12 col-sm-8 col-md-4 col-sm-offset-2 col-md-offset-4">
|
<div class="col-xs-12 col-sm-8 col-md-4 col-sm-offset-2 col-md-offset-4">
|
||||||
<div class="panel panel-default">
|
<div class="panel panel-default">
|
||||||
<div class="panel-heading">
|
<div class="panel-heading">
|
||||||
<h3 class="panel-title">Bitte für <?php echo $homeserver; ?> registrieren<small>2-Schritt-Registrierung</small></h3>
|
<h3 class="panel-title">Bitte für <?php echo $config["homeserver"]; ?> registrieren<small>2-Schritt-Registrierung</small></h3>
|
||||||
</div>
|
</div>
|
||||||
<div class="panel-body">
|
<div class="panel-body">
|
||||||
<form name="regForm" role="form" action="register.php" method="post">
|
<form name="regForm" role="form" action="register.php" method="post">
|
||||||
|
|||||||
@@ -39,8 +39,8 @@ try {
|
|||||||
$admin_token = $user["admin_token"];
|
$admin_token = $user["admin_token"];
|
||||||
|
|
||||||
require_once("../MatrixConnection.php");
|
require_once("../MatrixConnection.php");
|
||||||
$adminUrl = $webroot . "/verify_admin.php?t=" . $admin_token;
|
$adminUrl = $config["webroot"] . "/verify_admin.php?t=" . $admin_token;
|
||||||
$mxConn = new MatrixConnection($homeserver, $access_token);
|
$mxConn = new MatrixConnection($config["homeserver"], $config["access_token"]);
|
||||||
$mxMsg = new MatrixMessage();
|
$mxMsg = new MatrixMessage();
|
||||||
$mxMsg->set_body($first_name . ' ' . $last_name . "möchte sich registrieren und hat folgende Notiz hinterlassen:\r\n"
|
$mxMsg->set_body($first_name . ' ' . $last_name . "möchte sich registrieren und hat folgende Notiz hinterlassen:\r\n"
|
||||||
. $note . "\r\n"
|
. $note . "\r\n"
|
||||||
@@ -49,7 +49,7 @@ try {
|
|||||||
. $note . "<br />"
|
. $note . "<br />"
|
||||||
. "Zum Bearbeiten <a href=\"". $adminUrl . "\">hier</a> klicken");
|
. "Zum Bearbeiten <a href=\"". $adminUrl . "\">hier</a> klicken");
|
||||||
$mxMsg->set_type("m.text");
|
$mxMsg->set_type("m.text");
|
||||||
$response = $mxConn->send($register_room, $mxMsg);
|
$response = $mxConn->send($config["register_room"], $mxMsg);
|
||||||
|
|
||||||
if ($response) {
|
if ($response) {
|
||||||
$message = $language["SEND_MATRIX_FAIL"];
|
$message = $language["SEND_MATRIX_FAIL"];
|
||||||
@@ -58,19 +58,19 @@ try {
|
|||||||
($response ? RegisterState::PendingAdminVerify : RegisterState::PendingAdminSend),
|
($response ? RegisterState::PendingAdminVerify : RegisterState::PendingAdminSend),
|
||||||
$token);
|
$token);
|
||||||
|
|
||||||
send_mail_pending_approval($homeserver, $first_name . " " . $last_name, $email);
|
send_mail_pending_approval($config["homeserver"], $first_name . " " . $last_name, $email);
|
||||||
|
|
||||||
print("<title>" . $language["VERIFICATION_SUCEEDED"] . "</title>");
|
print("<title>" . $language["VERIFICATION_SUCEEDED"] . "</title>");
|
||||||
print("</head><body>");
|
print("</head><body>");
|
||||||
print("<h1>" . $language["VERIFICATION_SUCEEDED"] . "</h1>");
|
print("<h1>" . $language["VERIFICATION_SUCEEDED"] . "</h1>");
|
||||||
print("<p>" . $language["VERIFICATION_SUCCESS_BODY"] . "</p>");
|
print("<p>" . $language["VERIFICATION_SUCCESS_BODY"] . "</p>");
|
||||||
print("<a href=\"" . $webroot . "/register.php" . "\">Zur Registrierungsseite</a>");
|
print("<a href=\"" . $config["webroot"] . "/register.php" . "\">Zur Registrierungsseite</a>");
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
print("<title>" . $language["VERIFICATION_FAILED"] . "</title>");
|
print("<title>" . $language["VERIFICATION_FAILED"] . "</title>");
|
||||||
print("</head><body>");
|
print("</head><body>");
|
||||||
print("<h1>" . $language["VERIFICATION_FAILED"] . "</h1>");
|
print("<h1>" . $language["VERIFICATION_FAILED"] . "</h1>");
|
||||||
print("<p>" . $e->getMessage() . "</p>");
|
print("<p>" . $e->getMessage() . "</p>");
|
||||||
print("<a href=\"" . $webroot . "/register.php" . "\">Zur Registrierungsseite</a>");
|
print("<a href=\"" . $config["webroot"] . "/register.php" . "\">Zur Registrierungsseite</a>");
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
</body>
|
</body>
|
||||||
|
|||||||
@@ -56,24 +56,24 @@ try {
|
|||||||
|
|
||||||
// register user
|
// register user
|
||||||
require_once("../MatrixConnection.php");
|
require_once("../MatrixConnection.php");
|
||||||
$mxConn = new MatrixConnection($homeserver, $access_token);
|
$mxConn = new MatrixConnection($config["homeserver"], $config["access_token"]);
|
||||||
|
|
||||||
// generate a password with 8 characters
|
// generate a password with 8 characters
|
||||||
$password = addUser($first_name, $last_name, $username, $email);
|
$password = addUser($first_name, $last_name, $username, $email);
|
||||||
if ($password != NULL) {
|
if ($password != NULL) {
|
||||||
// send registration_success
|
// send registration_success
|
||||||
$res = send_mail_registration_success($homeserver, $first_name . " " . $last_name, $email, $username, $password, $howToURL);
|
$res = send_mail_registration_success($config["homeserver"], $first_name . " " . $last_name, $email, $username, $password, $config["howToURL"]);
|
||||||
if ($res) {
|
if ($res) {
|
||||||
$mx_db->setRegistrationStateAdmin(RegisterState::AllDone, $token);
|
$mx_db->setRegistrationStateAdmin(RegisterState::AllDone, $token);
|
||||||
} else {
|
} else {
|
||||||
$mx_db->setRegistrationStateAdmin(RegisterState::PendingSendRegistrationMail, $token);
|
$mx_db->setRegistrationStateAdmin(RegisterState::PendingSendRegistrationMail, $token);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
send_mail_registration_allowed_but_failed($homeserver, $first_name . " " . $last_name, $email);
|
send_mail_registration_allowed_but_failed($config["homeserver"], $first_name . " " . $last_name, $email);
|
||||||
$mxMsg = new MatrixMessage();
|
$mxMsg = new MatrixMessage();
|
||||||
$mxMsg->set_type("m.text");
|
$mxMsg->set_type("m.text");
|
||||||
$mxMsg->set_body("Fehler beim Registrieren von " . $first_name . " " . $last_name . ".");
|
$mxMsg->set_body("Fehler beim Registrieren von " . $first_name . " " . $last_name . ".");
|
||||||
$mxConn->send($register_room, $mxMsg);
|
$mxConn->send($config["register_room"], $mxMsg);
|
||||||
throw new Exception($language["REGISTRATION_FAILED"]);
|
throw new Exception($language["REGISTRATION_FAILED"]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -83,7 +83,7 @@ try {
|
|||||||
print("<p>" . $language["ADMIN_REGISTER_ACCEPTED_BODY"] . "</p>");
|
print("<p>" . $language["ADMIN_REGISTER_ACCEPTED_BODY"] . "</p>");
|
||||||
} elseif ($action == RegisterState::RegistrationDeclined) {
|
} elseif ($action == RegisterState::RegistrationDeclined) {
|
||||||
$mx_db->setRegistrationStateAdmin(RegisterState::RegistrationDeclined, $token);
|
$mx_db->setRegistrationStateAdmin(RegisterState::RegistrationDeclined, $token);
|
||||||
send_mail_registration_decline($homeserver, $first_name . " " . $last_name, $email, $decline_reason);
|
send_mail_registration_decline($config["homeserver"], $first_name . " " . $last_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>");
|
||||||
print("<h1>" . $language["ADMIN_VERIFY_SITE_TITLE"] . "</h1>");
|
print("<h1>" . $language["ADMIN_VERIFY_SITE_TITLE"] . "</h1>");
|
||||||
@@ -161,7 +161,7 @@ background: rgba(255, 255, 255, 0.8);
|
|||||||
print("</head><body>");
|
print("</head><body>");
|
||||||
print("<h1>" . $language["REGISTRATION_FAILED"] . "</h1>");
|
print("<h1>" . $language["REGISTRATION_FAILED"] . "</h1>");
|
||||||
print("<p>" . $e->getMessage() . "</p>");
|
print("<p>" . $e->getMessage() . "</p>");
|
||||||
print("<a href=\"" . $webroot . "/register.php" . "\">Zur Registrierungsseite</a>");
|
print("<a href=\"" . $config["webroot"] . "/register.php" . "\">Zur Registrierungsseite</a>");
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
</body>
|
</body>
|
||||||
|
|||||||
Reference in New Issue
Block a user