From 9512216ed66ec91b4e3a607d59888b132ad6b648 Mon Sep 17 00:00:00 2001 From: Alejandro Gallardo Escobar Date: Thu, 11 Dec 2014 18:19:47 +0100 Subject: [PATCH] Moved some functions --- pandora_console/include/functions.php | 53 ++++++++++++++++++++++++++- pandora_console/index.php | 4 +- 2 files changed, 54 insertions(+), 3 deletions(-) diff --git a/pandora_console/include/functions.php b/pandora_console/include/functions.php index 0b28d59cee..a059d60399 100644 --- a/pandora_console/include/functions.php +++ b/pandora_console/include/functions.php @@ -2225,4 +2225,55 @@ function print_audit_csv ($data) { } } -?> +/** + * Validate the code given to surpass the 2 step authentication + * + * @param string User name + * @param string Code given by the authenticator app + * + * @return -1 if the parameters introduced are incorrect, + * there is a problem accessing the user secret or + * if an exception are launched. + * true if the code is valid. + * false if the code is invalid. + */ +function validate_double_auth_code ($user, $code) { + global $config; + require_once ($config['homedir'].'/include/auth/GAuth/Auth.php'); + $result = false; + + if (empty($user) || empty($code)) { + $result = -1; + } + else { + $secret = db_get_value('secret', 'tuser_double_auth', 'id_user', $user); + + if ($secret === false) { + $result = -1; + } + else if (!empty($secret)) { + try { + $gAuth = new \GAuth\Auth($secret); + $result = $gAuth->validateCode($code); + } catch (Exception $e) { + $result = -1; + } + } + } + + return $result; +} + +/** + * Get if the 2 step authentication is enabled for the user given + * + * @param string User name + * + * @return true if the user has the double auth enabled or false otherwise. + */ +function is_double_auth_enabled ($user) { + $result = (bool) db_get_value('id', 'tuser_double_auth', 'id_user', $user); + + return $result; +} +?> \ No newline at end of file diff --git a/pandora_console/index.php b/pandora_console/index.php index e53f31354e..dbbd51a439 100755 --- a/pandora_console/index.php +++ b/pandora_console/index.php @@ -204,7 +204,7 @@ if (! isset ($config['id_user'])) { $code = (string) get_parameter_post ("auth_code"); if (!empty($code)) { - $result = login_validate_double_auth_code($nick, $code); + $result = validate_double_auth_code($nick, $code); if ($result === true) { // Double auth success @@ -314,7 +314,7 @@ if (! isset ($config['id_user'])) { //login ok and password has not expired // Double auth check - if ((!isset ($double_auth_success) || !$double_auth_success) && login_is_double_auth_enabled($nick_in_db)) { + if ((!isset ($double_auth_success) || !$double_auth_success) && is_double_auth_enabled($nick_in_db)) { // Store this values in the session to know if the user login was correct $_SESSION['prepared_login_da'] = array( 'id_user' => $nick_in_db,