diff --git a/conf/emails.conf b/conf/emails.conf index 6434e4d..55b2347 100644 --- a/conf/emails.conf +++ b/conf/emails.conf @@ -19,7 +19,7 @@ define("EMAIL_SITE", "https://linphone.org"); /* * The link to open when click on activation - * It can have a %link%, %username% and %algo% parameter + * It can have a %link%, %username%, %domain%, and %algo% parameter * * Default value: www.linphone.org */ diff --git a/flexisip-account-manager.spec b/flexisip-account-manager.spec index 3160dc9..6577717 100644 --- a/flexisip-account-manager.spec +++ b/flexisip-account-manager.spec @@ -8,7 +8,7 @@ #%define _datadir %{_datarootdir} #%define _docdir %{_datadir}/doc -%define build_number 22 +%define build_number 23 %define var_dir /var/opt/belledonne-communications %define opt_dir /opt/belledonne-communications/share/flexisip-account-manager %define env_file "$RPM_BUILD_ROOT/etc/flexisip-account-manager/flexiapi.env" diff --git a/src/misc/email.php b/src/misc/email.php index b12c79b..26211d8 100644 --- a/src/misc/email.php +++ b/src/misc/email.php @@ -65,7 +65,7 @@ function send_email($email, $subject, $text, $html) } } -function send_email_with_activation_link($email, $key, $username, $algo) +function send_email_with_activation_link($email, $key, $username, $domain, $algo) { if (!EMAIL_ENABLED) { Logger::getInstance()->warning("[EMAIL] Emails are disabled"); @@ -81,6 +81,7 @@ function send_email_with_activation_link($email, $key, $username, $algo) $link = $pageURL . EMAIL_ACTIVATION_LINK; $link = str_replace("%key%", $key, $link); $link = str_replace("%username%", $username, $link); + $link = str_replace("%domain%", $domain, $link); $link = str_replace("%algo%", $algo, $link); Logger::getInstance()->debug("[EMAIL] Activation link is " . $link); diff --git a/src/xmlrpc/accounts_email.php b/src/xmlrpc/accounts_email.php index bb10713..1393dc6 100644 --- a/src/xmlrpc/accounts_email.php +++ b/src/xmlrpc/accounts_email.php @@ -90,7 +90,7 @@ function xmlrpc_create_email_account($method, $args) } if (SEND_ACTIVATION_EMAIL && EMAIL_ENABLED) { - send_email_with_activation_link($email, $account->confirmation_key, $account->username, $algo); + send_email_with_activation_link($email, $account->confirmation_key, $account->username, $account->domain, $algo); } elseif (AUTO_ACTIVATE_ACCOUNT) { //TODO /*if (USE_IN_APP_PURCHASES) { @@ -177,7 +177,7 @@ function xmlrpc_create_email_md5_sha256_account($method, $args) } if (SEND_ACTIVATION_EMAIL && EMAIL_ENABLED) { - send_email_with_activation_link($email, $account->confirmation_key, $account->username, SHA256); + send_email_with_activation_link($email, $account->confirmation_key, $account->username, $account->domain, SHA256); } elseif (AUTO_ACTIVATE_ACCOUNT) { //TODO /*if (USE_IN_APP_PURCHASES) { diff --git a/src/xmlrpc/activation.php b/src/xmlrpc/activation.php new file mode 100644 index 0000000..7d4617a --- /dev/null +++ b/src/xmlrpc/activation.php @@ -0,0 +1,76 @@ +. +*/ + +include_once __DIR__ . '/../database/database.php'; + +include_once __DIR__ . '/../objects/account.php'; +include_once __DIR__ . '/../objects/password.php'; +include_once __DIR__ . '/../objects/alias.php'; +include_once __DIR__ . '/../objects/user_info.php'; + +include_once __DIR__ . '/../misc/utilities.php'; + +include_once __DIR__ . '/accounts_email.php'; +include_once __DIR__ . '/accounts_phone.php'; + +include_once __DIR__ . '/../misc/results_values.php'; + +function activate_email_account($user, $domain, $key, $algo) { + $domain = get_domain($domain); + $algo = get_algo($algo); + Logger::getInstance()->message("[HTTP] activate_email_account(" . $user . ", " . $domain . ", " . $key . ", " . $algo . ")"); + + if (!check_parameter($user)) { + return MISSING_USERNAME_PARAM; + } elseif ($algo == null) { + return ALGO_NOT_SUPPORTED; + } + + $database = new Database(); + $db = $database->getConnection(); + $account = new Account($db); + $account->username = $user; + $account->domain = $domain; + + if (!$account->getOne()) { + Logger::getInstance()->error("[HTTP] Account not found"); + return ACCOUNT_NOT_FOUND; + } elseif ($account->activated != "0") { + Logger::getInstance()->warning("[HTTP] Account already activated"); + return ACCOUNT_ALREADY_ACTIVATED; + } + + if (!is_key_matching($key, $account)) { + Logger::getInstance()->error("[HTTP] Key doesn't match"); + return KEY_DOESNT_MATCH; + } + + $account->activated = "1"; + $account->update(); + Logger::getInstance()->message("[HTTP] Account activated"); +} + +$user = $_GET["username"]; +$domain = $_GET["domain"]; +$key = $_GET["confirmation_key"]; +$algo = $_GET["algo"]; +activate_email_account($user, $domain, $key, $algo); + +?> \ No newline at end of file