From b71082ccdb3d821210b1b572ebde1839e3d23dac Mon Sep 17 00:00:00 2001
From: Alejandro Gallardo Escobar
Date: Thu, 11 Dec 2014 16:09:17 +0100
Subject: [PATCH 01/15] Added a class to perform google autenticator checks
---
pandora_console/include/auth/GAuth/Auth.php | 356 ++++++++++++++++++++
1 file changed, 356 insertions(+)
create mode 100644 pandora_console/include/auth/GAuth/Auth.php
diff --git a/pandora_console/include/auth/GAuth/Auth.php b/pandora_console/include/auth/GAuth/Auth.php
new file mode 100644
index 0000000000..2aa859238d
--- /dev/null
+++ b/pandora_console/include/auth/GAuth/Auth.php
@@ -0,0 +1,356 @@
+
+ * @package GAuth
+ * @license MIT
+ */
+
+class Auth
+{
+ /**
+ * Internal lookup table
+ * @var array
+ */
+ private $lookup = array();
+
+ /**
+ * Initialization key
+ * @var string
+ */
+ private $initKey = null;
+
+ /**
+ * Seconds between key refreshes
+ * @var integer
+ */
+ private $refreshSeconds = 30;
+
+ /**
+ * Length of codes to generate
+ * @var integer
+ */
+ private $codeLength = 6;
+
+ /**
+ * Range plus/minus for "window of opportunity" on allowed codes
+ * @var integer
+ */
+ private $range = 2;
+
+ /**
+ * Initialize the object and set up the lookup table
+ * Optionally the Initialization key
+ *
+ * @param string $initKey Initialization key
+ */
+ public function __construct($initKey = null)
+ {
+ $this->buildLookup();
+
+ if ($initKey !== null) {
+ $this->setInitKey($initKey);
+ }
+ }
+
+ /**
+ * Build the base32 lookup table
+ *
+ * @return null
+ */
+ public function buildLookup()
+ {
+ $lookup = array_combine(
+ array_merge(range('A', 'Z'), range(2, 7)),
+ range(0, 31)
+ );
+ $this->setLookup($lookup);
+ }
+
+ /**
+ * Get the current "range" value
+ * @return integer Range value
+ */
+ public function getRange()
+ {
+ return $this->range;
+ }
+
+ /**
+ * Set the "range" value
+ *
+ * @param integer $range Range value
+ * @return \GAuth\Auth instance
+ */
+ public function setRange($range)
+ {
+ if (!is_numeric($range)) {
+ throw new \InvalidArgumentException('Invalid window range');
+ }
+ $this->range = $range;
+ return $this;
+ }
+
+ /**
+ * Set the initialization key for the object
+ *
+ * @param string $key Initialization key
+ * @throws \InvalidArgumentException If hash is not valid base32
+ * @return \GAuth\Auth instance
+ */
+ public function setInitKey($key)
+ {
+ if (preg_match('/^['.implode('', array_keys($this->getLookup())).']+$/', $key) == false) {
+ throw new \InvalidArgumentException('Invalid base32 hash!');
+ }
+ $this->initKey = $key;
+ return $this;
+ }
+
+ /**
+ * Get the current Initialization key
+ *
+ * @return string Initialization key
+ */
+ public function getInitKey()
+ {
+ return $this->initKey;
+ }
+
+ /**
+ * Set the contents of the internal lookup table
+ *
+ * @param array $lookup Lookup data set
+ * @throws \InvalidArgumentException If lookup given is not an array
+ * @return \GAuth\Auth instance
+ */
+ public function setLookup($lookup)
+ {
+ if (!is_array($lookup)) {
+ throw new \InvalidArgumentException('Lookup value must be an array');
+ }
+ $this->lookup = $lookup;
+ return $this;
+ }
+
+ /**
+ * Get the current lookup data set
+ *
+ * @return array Lookup data
+ */
+ public function getLookup()
+ {
+ return $this->lookup;
+ }
+
+ /**
+ * Get the number of seconds for code refresh currently set
+ *
+ * @return integer Refresh in seconds
+ */
+ public function getRefresh()
+ {
+ return $this->refreshSeconds;
+ }
+
+ /**
+ * Set the number of seconds to refresh codes
+ *
+ * @param integer $seconds Seconds to refresh
+ * @throws \InvalidArgumentException If seconds value is not numeric
+ * @return \GAuth\Auth instance
+ */
+ public function setRefresh($seconds)
+ {
+ if (!is_numeric($seconds)) {
+ throw \InvalidArgumentException('Seconds must be numeric');
+ }
+ $this->refreshSeconds = $seconds;
+ return $this;
+ }
+
+ /**
+ * Get the current length for generated codes
+ *
+ * @return integer Code length
+ */
+ public function getCodeLength()
+ {
+ return $this->codeLength;
+ }
+
+ /**
+ * Set the length of the generated codes
+ *
+ * @param integer $length Code length
+ * @return \GAuth\Auth instance
+ */
+ public function setCodeLength($length)
+ {
+ $this->codeLength = $length;
+ return $this;
+ }
+
+ /**
+ * Validate the given code
+ *
+ * @param string $code Code entered by user
+ * @param string $initKey Initialization key
+ * @param string $timestamp Timestamp for calculation
+ * @param integer $range Seconds before/after to validate hash against
+ * @throws \InvalidArgumentException If incorrect code length
+ * @return boolean Pass/fail of validation
+ */
+ public function validateCode($code, $initKey = null, $timestamp = null, $range = null)
+ {
+ if (strlen($code) !== $this->getCodeLength()) {
+ throw new \InvalidArgumentException('Incorrect code length');
+ }
+
+ $range = ($range == null) ? $this->getRange() : $range;
+ $timestamp = ($timestamp == null) ? $this->generateTimestamp() : $timestamp;
+ $initKey = ($initKey == null) ? $this->getInitKey() : $initKey;
+
+ $binary = $this->base32_decode($initKey);
+
+ for ($time = ($timestamp - $range); $time <= ($timestamp + $range); $time++) {
+ if ($this->generateOneTime($binary, $time) == $code) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ /**
+ * Generate a one-time code
+ *
+ * @param string $initKey Initialization key [optional]
+ * @param string $timestamp Timestamp for calculation [optional]
+ * @return string Geneerated code/hash
+ */
+ public function generateOneTime($initKey = null, $timestamp = null)
+ {
+ $initKey = ($initKey == null) ? $this->getInitKey() : $initKey;
+ $timestamp = ($timestamp == null) ? $this->generateTimestamp() : $timestamp;
+
+ $hash = hash_hmac (
+ 'sha1',
+ pack('N*', 0) . pack('N*', $timestamp),
+ $initKey,
+ true
+ );
+
+ return str_pad($this->truncateHash($hash), $this->getCodeLength(), '0', STR_PAD_LEFT);
+ }
+
+ /**
+ * Generate a code/hash
+ * Useful for making Initialization codes
+ *
+ * @param integer $length Length for the generated code
+ * @return string Generated code
+ */
+ public function generateCode($length = 16)
+ {
+ $lookup = implode('', array_keys($this->getLookup()));
+ $code = '';
+
+ for ($i = 0; $i < $length; $i++) {
+ $code .= $lookup[mt_rand(0, strlen($lookup)-1)];
+ }
+
+ return $code;
+ }
+
+ /**
+ * Geenrate the timestamp for the calculation
+ *
+ * @return integer Timestamp
+ */
+ public function generateTimestamp()
+ {
+ return floor(microtime(true)/$this->getRefresh());
+ }
+
+ /**
+ * Truncate the given hash down to just what we need
+ *
+ * @param string $hash Hash to truncate
+ * @return string Truncated hash value
+ */
+ public function truncateHash($hash)
+ {
+ $offset = ord($hash[19]) & 0xf;
+
+ return (
+ ((ord($hash[$offset+0]) & 0x7f) << 24 ) |
+ ((ord($hash[$offset+1]) & 0xff) << 16 ) |
+ ((ord($hash[$offset+2]) & 0xff) << 8 ) |
+ (ord($hash[$offset+3]) & 0xff)
+ ) % pow(10, $this->getCodeLength());
+ }
+
+ /**
+ * Base32 decoding function
+ *
+ * @param string base32 encoded hash
+ * @throws \InvalidArgumentException When hash is not valid
+ * @return string Binary value of hash
+ */
+ public function base32_decode($hash)
+ {
+ $lookup = $this->getLookup();
+
+ if (preg_match('/^['.implode('', array_keys($lookup)).']+$/', $hash) == false) {
+ throw new \InvalidArgumentException('Invalid base32 hash!');
+ }
+
+ $hash = strtoupper($hash);
+ $buffer = 0;
+ $length = 0;
+ $binary = '';
+
+ for ($i = 0; $i < strlen($hash); $i++) {
+ $buffer = $buffer << 5;
+ $buffer += $lookup[$hash[$i]];
+ $length += 5;
+
+ if ($length >= 8) {
+ $length -= 8;
+ $binary .= chr(($buffer & (0xFF << $length)) >> $length);
+ }
+ }
+
+ return $binary;
+ }
+}
\ No newline at end of file
From 3c1dbbdc73e306ab9c9b15aa597a8be2f52bb98f Mon Sep 17 00:00:00 2001
From: Alejandro Gallardo Escobar
Date: Thu, 11 Dec 2014 16:10:15 +0100
Subject: [PATCH 02/15] File with double auth utilities to be accessed by ajax
---
.../include/ajax/double_auth.ajax.php | 522 ++++++++++++++++++
1 file changed, 522 insertions(+)
create mode 100644 pandora_console/include/ajax/double_auth.ajax.php
diff --git a/pandora_console/include/ajax/double_auth.ajax.php b/pandora_console/include/ajax/double_auth.ajax.php
new file mode 100644
index 0000000000..770749e683
--- /dev/null
+++ b/pandora_console/include/ajax/double_auth.ajax.php
@@ -0,0 +1,522 @@
+generateCode($secret_lenght);
+
+ echo json_encode($code);
+ return;
+}
+
+// Validate the provided secret with a code provided by the user.
+// If the parameter 'save' is set to true, the secret will
+// be stored into the database.
+// The results can be true, false or 1 if the validation is true
+// but the secret can't be stored into the database.
+$validate_double_auth_code = (bool) get_parameter('validate_double_auth_code');
+if ($validate_double_auth_code) {
+ $result = false;
+
+ $secret = (string) get_parameter('secret');
+
+ if (!empty($secret) && strlen($secret) === $secret_lenght) {
+ $code = (string) get_parameter('code');
+
+ if (!empty($code) && strlen($code) === $code_lenght) {
+ $save = (bool) get_parameter('save');
+
+ if (!empty($code)) {
+ $gAuth = new \GAuth\Auth($secret);
+ $result = $gAuth->validateCode($code);
+ }
+
+ if ($result && $save) {
+ // Delete the actual value (if exists)
+ $where = array(
+ 'id_user' => $id_user
+ );
+ db_process_sql_delete('tuser_double_auth', $where);
+
+ // Insert the new value
+ $values = array(
+ 'id_user' => $id_user,
+ 'secret' => $secret
+ );
+ $result = (bool) db_process_sql_insert('tuser_double_auth', $values);
+
+ if (!$result) {
+ $result = 1;
+ }
+ }
+ }
+ }
+
+ echo json_encode($result);
+ return;
+}
+
+// Set the provided secret to the user
+$save_double_auth_secret = (bool) get_parameter('save_double_auth_secret');
+if ($save_double_auth_secret) {
+ $result = false;
+
+ $secret = (string) get_parameter('secret');
+
+ if (strlen($secret) === $secret_lenght) {
+ // Delete the actual value (if exists)
+ $where = array(
+ 'id_user' => $id_user
+ );
+ db_process_sql_delete('tuser_double_auth', $where);
+ // Insert the new value
+ $values = array(
+ 'id_user' => $id_user,
+ 'secret' => $secret
+ );
+ $result = (bool) db_process_sql_insert('tuser_double_auth', $values);
+ }
+
+ echo json_encode($result);
+ return;
+}
+
+// Disable the double auth for the user
+$deactivate_double_auth = (bool) get_parameter('deactivate_double_auth');
+if ($deactivate_double_auth) {
+ $result = false;
+
+ // Delete the actual value (if exists)
+ $where = array(
+ 'id_user' => $id_user
+ );
+ $result = db_process_sql_delete('tuser_double_auth', $where);
+
+ echo json_encode($result);
+ return;
+}
+
+// Get the info page to the container dialog
+$get_double_auth_data_page = (bool) get_parameter('get_double_auth_data_page');
+if ($get_double_auth_data_page) {
+ $secret = db_get_value('secret', 'tuser_double_auth', 'id_user', $id_user);
+
+ if (empty($secret)) {
+ return;
+ }
+
+ $html = '';
+ $html .= "";
+ $html .= "
";
+ $html .= __('This is the private code that you should use with your authenticator app') . ". ";
+ $html .= __('You could enter the code manually or use the QR code to add it automatically') . ".";
+ $html .= "
";
+ $html .= "
";
+ $html .= "";
+ $html .= __('Code') . ":
$secret";
+ $html .= "
";
+ $html .= __('QR') . ":
";
+ $html .= "
";
+ $html .= "
";
+
+ ob_clean();
+?>
+
+";
+ $html .= "";
+ $html .= __('You are about to activate the double authentication') . ". ";
+ $html .= __('With this option enabled, your account access will be more secure,
+ cause a code generated by other application will be required after the login') . ". ";
+ $html .= "
";
+ $html .= "";
+ $html .= __('You will need to install the app from the following link before continue') . ". ";
+ $html .= "
";
+ $html .= "";
+ $html .= "
";
+ $html .= "";
+ $html .= html_print_button(__('Download the app'), 'google_authenticator_download', false, '', '', true);
+ $html .= "
";
+ $html .= "
";
+ $html .= "";
+ $html .= html_print_button(__('Continue'), 'continue_to_generate', false, '', '', true);
+ $html .= "
";
+
+ ob_clean();
+?>
+
+generateCode($secret_lenght);
+
+ $html = '';
+ $html .= "";
+ $html .= "
";
+ $html .= "" . __('A private code has been generated') . ".";
+ $html .= "
";
+ $html .= "
";
+ $html .= "";
+ $html .= "
";
+ $html .= __('Before continue, you should create a new entry into the authenticator app') . ". ";
+ $html .= __('You could enter the code manually or use the QR code to add it automatically') . ".";
+ $html .= "
";
+ $html .= "
";
+ $html .= "";
+ $html .= __('Code') . ":
$secret";
+ $html .= "
";
+ $html .= __('QR') . ":
";
+ $html .= "
";
+ $html .= "
";
+ $html .= html_print_button(__('Refresh code'), 'continue_to_generate', false, '', '', true);
+ $html .= " ";
+ $html .= html_print_button(__('Continue'), 'continue_to_validate', false, '', '', true);
+ $html .= "
";
+
+ ob_clean();
+?>
+
+";
+ $html .= "";
+ $html .= __('Introduce a code generated by the app') . ". ";
+ $html .= __('If the code is valid, the double authentication will be activated') . ".";
+ $html .= "
";
+ $html .= "";
+ $html .= "
";
+ $html .= "";
+ $html .= html_print_input_text('code', '', '', 50, $secret_lenght, true);
+ $html .= "
";
+ $html .= "
";
+ $html .= "
";
+ $html .= html_print_button(__('Validate code'), 'continue_to_validate', false, '', '', true);
+ $html .= html_print_image ("images/spinner.gif", true);
+ $html .= "
";
+ $html .= "
";
+
+ ob_clean();
+?>
+
+
\ No newline at end of file
From d399ccbd1feea7bcbdc0b330267b78a6469b7d21 Mon Sep 17 00:00:00 2001
From: Alejandro Gallardo Escobar
Date: Thu, 11 Dec 2014 16:11:21 +0100
Subject: [PATCH 03/15] Added a new table called 'tuser_double_auth'
---
.../extras/pandoradb_migrate_5.1_to_6.0.mysql.sql | 12 ++++++++++++
.../extras/pandoradb_migrate_5.1_to_6.0.oracle.sql | 14 +++++++++++++-
.../pandoradb_migrate_5.1_to_6.0.postgreSQL.sql | 12 +++++++++++-
pandora_console/pandoradb.oracle.sql | 11 +++++++++++
pandora_console/pandoradb.postgreSQL.sql | 9 +++++++++
pandora_console/pandoradb.sql | 12 ++++++++++++
6 files changed, 68 insertions(+), 2 deletions(-)
diff --git a/pandora_console/extras/pandoradb_migrate_5.1_to_6.0.mysql.sql b/pandora_console/extras/pandoradb_migrate_5.1_to_6.0.mysql.sql
index b5a8ca7aa3..1f6e37bcac 100755
--- a/pandora_console/extras/pandoradb_migrate_5.1_to_6.0.mysql.sql
+++ b/pandora_console/extras/pandoradb_migrate_5.1_to_6.0.mysql.sql
@@ -14,3 +14,15 @@ ALTER TABLE tlayout_data ADD COLUMN `border_width` INTEGER UNSIGNED NOT NULL def
ALTER TABLE tlayout_data ADD COLUMN `border_color` varchar(200) DEFAULT "";
ALTER TABLE tlayout_data ADD COLUMN `fill_color` varchar(200) DEFAULT "";
+/* 2014/12/10 */
+-- ----------------------------------------------------------------------
+-- Table `tuser_double_auth`
+-- ----------------------------------------------------------------------
+CREATE TABLE IF NOT EXISTS `tuser_double_auth` (
+ `id` int(10) unsigned NOT NULL auto_increment,
+ `id_user` varchar(60) NOT NULL,
+ `secret` varchar(20) NOT NULL,
+ PRIMARY KEY (`id`),
+ UNIQUE (`id_user`),
+ FOREIGN KEY (`id_user`) REFERENCES tusuario(`id_user`) ON DELETE CASCADE
+) ENGINE=InnoDB DEFAULT CHARSET=utf8;
\ No newline at end of file
diff --git a/pandora_console/extras/pandoradb_migrate_5.1_to_6.0.oracle.sql b/pandora_console/extras/pandoradb_migrate_5.1_to_6.0.oracle.sql
index 182394c445..b3cdb6b13c 100755
--- a/pandora_console/extras/pandoradb_migrate_5.1_to_6.0.oracle.sql
+++ b/pandora_console/extras/pandoradb_migrate_5.1_to_6.0.oracle.sql
@@ -12,4 +12,16 @@ ALTER TABLE tlayout_data DROP COLUMN no_link_color;
ALTER TABLE tlayout_data DROP COLUMN label_color;
ALTER TABLE tlayout_data ADD COLUMN border_width INTEGER NOT NULL default 0;
ALTER TABLE tlayout_data ADD COLUMN border_color varchar(200) DEFAULT "";
-ALTER TABLE tlayout_data ADD COLUMN fill_color varchar(200) DEFAULT "";
\ No newline at end of file
+ALTER TABLE tlayout_data ADD COLUMN fill_color varchar(200) DEFAULT "";
+
+/* 2014/12/10 */
+-- ----------------------------------------------------------------------
+-- Table `tuser_double_auth`
+-- ----------------------------------------------------------------------
+CREATE TABLE tuser_double_auth (
+ id NUMBER(10, 0) NOT NULL PRIMARY KEY,
+ id_user VARCHAR2(60) NOT NULL REFERENCES tusuario(id_user) ON DELETE CASCADE,
+ secret VARCHAR2(20) NOT NULL
+);
+CREATE SEQUENCE tuser_double_auth_s INCREMENT BY 1 START WITH 1;
+CREATE OR REPLACE TRIGGER tuser_double_auth_inc BEFORE INSERT ON tuser_double_auth REFERENCING NEW AS NEW FOR EACH ROW BEGIN SELECT tuser_double_auth_s.nextval INTO :NEW.ID FROM dual; END tuser_double_auth_inc;;
\ No newline at end of file
diff --git a/pandora_console/extras/pandoradb_migrate_5.1_to_6.0.postgreSQL.sql b/pandora_console/extras/pandoradb_migrate_5.1_to_6.0.postgreSQL.sql
index 81ae7e6c05..8fa2e6346c 100755
--- a/pandora_console/extras/pandoradb_migrate_5.1_to_6.0.postgreSQL.sql
+++ b/pandora_console/extras/pandoradb_migrate_5.1_to_6.0.postgreSQL.sql
@@ -12,4 +12,14 @@ ALTER TABLE "tlayout_data" DROP COLUMN "no_link_color";
ALTER TABLE "tlayout_data" DROP COLUMN "label_color";
ALTER TABLE "tlayout_data" ADD COLUMN "border_width" INTEGER NOT NULL default 0;
ALTER TABLE "tlayout_data" ADD COLUMN "border_color" varchar(200) DEFAULT "";
-ALTER TABLE "tlayout_data" ADD COLUMN "fill_color" varchar(200) DEFAULT "";
\ No newline at end of file
+ALTER TABLE "tlayout_data" ADD COLUMN "fill_color" varchar(200) DEFAULT "";
+
+/* 2014/12/10 */
+-- ----------------------------------------------------------------------
+-- Table `tuser_double_auth`
+-- ----------------------------------------------------------------------
+CREATE TABLE "tuser_double_auth" (
+ "id" SERIAL NOT NULL PRIMARY KEY,
+ "id_user" varchar(60) NOT NULL UNIQUE REFERENCES "tusuario"("id_user") ON DELETE CASCADE,
+ "secret" varchar(20) NOT NULL
+);
\ No newline at end of file
diff --git a/pandora_console/pandoradb.oracle.sql b/pandora_console/pandoradb.oracle.sql
index a97ba1e163..a7af86524b 100755
--- a/pandora_console/pandoradb.oracle.sql
+++ b/pandora_console/pandoradb.oracle.sql
@@ -1047,6 +1047,17 @@ CREATE TABLE tusuario_perfil (
CREATE SEQUENCE tusuario_perfil_s INCREMENT BY 1 START WITH 1;
CREATE OR REPLACE TRIGGER tusuario_perfil_inc BEFORE INSERT ON tusuario_perfil REFERENCING NEW AS NEW FOR EACH ROW BEGIN SELECT tusuario_perfil_s.nextval INTO :NEW.ID_UP FROM dual; END tusuario_perfil_inc;;
+-- ----------------------------------------------------------------------
+-- Table `tuser_double_auth`
+-- ----------------------------------------------------------------------
+CREATE TABLE tuser_double_auth (
+ id NUMBER(10, 0) NOT NULL PRIMARY KEY,
+ id_user VARCHAR2(60) NOT NULL REFERENCES tusuario(id_user) ON DELETE CASCADE,
+ secret VARCHAR2(20) NOT NULL
+);
+CREATE SEQUENCE tuser_double_auth_s INCREMENT BY 1 START WITH 1;
+CREATE OR REPLACE TRIGGER tuser_double_auth_inc BEFORE INSERT ON tuser_double_auth REFERENCING NEW AS NEW FOR EACH ROW BEGIN SELECT tuser_double_auth_s.nextval INTO :NEW.ID FROM dual; END tuser_double_auth_inc;;
+
-- ---------------------------------------------------------------------
-- Table "tnews"
-- ---------------------------------------------------------------------
diff --git a/pandora_console/pandoradb.postgreSQL.sql b/pandora_console/pandoradb.postgreSQL.sql
index 20fd07b0ae..1ae3d6f4c5 100755
--- a/pandora_console/pandoradb.postgreSQL.sql
+++ b/pandora_console/pandoradb.postgreSQL.sql
@@ -926,6 +926,15 @@ CREATE TABLE "tusuario_perfil" (
"tags" text NOT NULL
);
+-- ----------------------------------------------------------------------
+-- Table `tuser_double_auth`
+-- ----------------------------------------------------------------------
+CREATE TABLE "tuser_double_auth" (
+ "id" SERIAL NOT NULL PRIMARY KEY,
+ "id_user" varchar(60) NOT NULL UNIQUE REFERENCES "tusuario"("id_user") ON DELETE CASCADE,
+ "secret" varchar(20) NOT NULL
+);
+
-- -----------------------------------------------------
-- Table `tnews`
-- -----------------------------------------------------
diff --git a/pandora_console/pandoradb.sql b/pandora_console/pandoradb.sql
index 376ae670aa..6abc69e96c 100755
--- a/pandora_console/pandoradb.sql
+++ b/pandora_console/pandoradb.sql
@@ -999,6 +999,18 @@ CREATE TABLE IF NOT EXISTS `tusuario_perfil` (
PRIMARY KEY (`id_up`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
+-- ----------------------------------------------------------------------
+-- Table `tuser_double_auth`
+-- ----------------------------------------------------------------------
+CREATE TABLE IF NOT EXISTS `tuser_double_auth` (
+ `id` int(10) unsigned NOT NULL auto_increment,
+ `id_user` varchar(60) NOT NULL,
+ `secret` varchar(20) NOT NULL,
+ PRIMARY KEY (`id`),
+ UNIQUE (`id_user`),
+ FOREIGN KEY (`id_user`) REFERENCES tusuario(`id_user`) ON DELETE CASCADE
+) ENGINE=InnoDB DEFAULT CHARSET=utf8;
+
-- ----------------------------------------------------------------------
-- Table `tnews`
-- ----------------------------------------------------------------------
From 33c678914410f1a6a3d24b219a8174306ef6a8c4 Mon Sep 17 00:00:00 2001
From: Alejandro Gallardo Escobar
Date: Thu, 11 Dec 2014 16:12:27 +0100
Subject: [PATCH 04/15] Added an option to allow the users to enable the 2 step
auth
---
pandora_console/godmode/setup/setup_auth.php | 9 +++++++++
pandora_console/include/functions_config.php | 2 ++
2 files changed, 11 insertions(+)
diff --git a/pandora_console/godmode/setup/setup_auth.php b/pandora_console/godmode/setup/setup_auth.php
index 2c29c91633..1a077e1542 100644
--- a/pandora_console/godmode/setup/setup_auth.php
+++ b/pandora_console/godmode/setup/setup_auth.php
@@ -94,6 +94,15 @@ if (enterprise_installed()) {
add_enterprise_auth_options($table, 12);
}
+// Enable double authentication
+$row = array();
+$row[] = __('Double authentication')
+ . ui_print_help_tip(__("If this option is enabled, the users can use double authentication with their accounts"), true);
+$row[] = __('Yes').' '.html_print_radio_button('double_auth_enabled', 1, '', $config['double_auth_enabled'], true)
+ .' '
+ . __('No').' '.html_print_radio_button('double_auth_enabled', 0, '', $config['double_auth_enabled'], true);
+$table->data[] = $row;
+
echo '
';
break;
+ case 'double_auth':
+ if (!empty ($page) && !empty ($sec)) {
+ foreach ($_POST as $key => $value) {
+ html_print_input_hidden ($key, $value);
+ }
+ }
+ echo '';
+ echo __('Authenticator code') . '
';
+ echo '
';
+ echo '';
+ html_print_input_text_extended ("auth_code", '', "auth_code", '', '', '' , false, '', 'class="login login_password"', false, true);
+ echo '
';
+ echo '';
+ html_print_submit_button(__("Check code") . ' >', "login_button", false, 'class="sub next_login"');
+ echo '
';
+ break;
default:
if (isset($error_info)) {
echo '' . $error_info['title'] . '
';
diff --git a/pandora_console/index.php b/pandora_console/index.php
index d054197723..e53f31354e 100755
--- a/pandora_console/index.php
+++ b/pandora_console/index.php
@@ -167,176 +167,283 @@ if (strlen($search) > 0) {
$searchPage = true;
}
-// Login process
-if (! isset ($config['id_user']) && isset ($_GET["login"])) {
- include_once('include/functions_db.php'); //Include it to use escape_string_sql function
-
- $config["auth_error"] = ""; //Set this to the error message from the authorization mechanism
- $nick = get_parameter_post ("nick"); //This is the variable with the login
- $pass = get_parameter_post ("pass"); //This is the variable with the password
- $nick = db_escape_string_sql($nick);
- $pass = db_escape_string_sql($pass);
-
- // process_user_login is a virtual function which should be defined in each auth file.
- // It accepts username and password. The rest should be internal to the auth file.
- // The auth file can set $config["auth_error"] to an informative error output or reference their internal error messages to it
- // process_user_login should return false in case of errors or invalid login, the nickname if correct
- $nick_in_db = process_user_login ($nick, $pass);
-
- $expired_pass = false;
-
- if (($nick_in_db != false) && ((!is_user_admin($nick)
- || $config['enable_pass_policy_admin']))
- && (defined('PANDORA_ENTERPRISE'))
- && ($config['enable_pass_policy'])) {
- include_once(ENTERPRISE_DIR . "/include/auth/mysql.php");
+// Login process
+if (! isset ($config['id_user'])) {
+ if (isset ($_GET["login"])) {
+ include_once('include/functions_db.php'); //Include it to use escape_string_sql function
- $blocked = login_check_blocked($nick);
-
- if ($blocked) {
- require_once ('general/login_page.php');
- db_pandora_audit("Password expired", "Password expired: ".$nick, $nick);
- while (@ob_end_flush ());
- exit ("