From 6a21a668bf6721d24ea5d2027c27b0b45e7afc75 Mon Sep 17 00:00:00 2001
From: Jose Gonzalez <jose.gonzalez@artica.es>
Date: Tue, 29 Sep 2020 09:44:20 +0200
Subject: [PATCH 1/4] Added control for reveal passwords

---
 .../godmode/setup/setup_general.php           |  7 +++++--
 pandora_console/include/functions_ui.php      | 20 +++++++++++++++++++
 .../include/javascript/pandora_ui.js          | 13 ++++++++++++
 3 files changed, 38 insertions(+), 2 deletions(-)

diff --git a/pandora_console/godmode/setup/setup_general.php b/pandora_console/godmode/setup/setup_general.php
index 0d8ce68e8e..e4aa1181a9 100644
--- a/pandora_console/godmode/setup/setup_general.php
+++ b/pandora_console/godmode/setup/setup_general.php
@@ -124,7 +124,8 @@ $table->data[$i][0] = __('Phantomjs bin directory');
 $table->data[$i++][1] = html_print_input_text('phantomjs_bin', io_safe_output($config['phantomjs_bin']), '', 30, 100, true);
 
 $table->data[$i][0] = __('Auto login (hash) password');
-$table->data[$i++][1] = html_print_input_password('loginhash_pwd', io_output_password($config['loginhash_pwd']), '', 15, 15, true);
+$table->data[$i][1] = html_print_input_password('loginhash_pwd', io_output_password($config['loginhash_pwd']), '', 15, 15, true);
+$table->data[$i++][1] .= ui_print_reveal_password('loginhash_pwd', true);
 
 $table->data[$i][0] = __('Time source');
 $sources['system'] = __('System');
@@ -162,7 +163,8 @@ if (isset($_POST['list_ACL_IPs_for_API'])) {
 $table->data[$i++][1] = html_print_textarea('list_ACL_IPs_for_API', 2, 25, $list_ACL_IPs_for_API, 'style="height: 50px; width: 300px"', true);
 
 $table->data[$i][0] = __('API password');
-$table->data[$i++][1] = html_print_input_password('api_password', io_output_password($config['api_password']), '', 25, 255, true);
+$table->data[$i][1] = html_print_input_password('api_password', io_output_password($config['api_password']), '', 25, 255, true);
+$table->data[$i++][1] .= ui_print_reveal_password('api_password', true);
 
 $table->data[$i][0] = __('Enable GIS features');
 $table->data[$i++][1] = html_print_checkbox_switch('activate_gis', 1, $config['activate_gis'], true);
@@ -384,6 +386,7 @@ $table_mail_conf->data[5][1] = html_print_input_text('email_username', $config['
 
 $table_mail_conf->data[6][0] = __('Email password');
 $table_mail_conf->data[6][1] = html_print_input_password('email_password', io_output_password($config['email_password']), '', 30, 100, true);
+$table_mail_conf->data[6][1] .= ui_print_reveal_password('email_password', true);
 
 $uniqid = uniqid();
 
diff --git a/pandora_console/include/functions_ui.php b/pandora_console/include/functions_ui.php
index ab6079fb36..2233b2fe95 100755
--- a/pandora_console/include/functions_ui.php
+++ b/pandora_console/include/functions_ui.php
@@ -6124,3 +6124,23 @@ function ui_print_message_dialog($title, $text, $id='', $img='', $text_button=''
         echo '</div>';
     echo '</div>';
 }
+
+
+/**
+ * Generate a button for reveal the content of the password field.
+ *
+ * @param string  $name   Name of the field.
+ * @param boolean $return If true, return the string with the formed element.
+ *
+ * @return string
+ */
+function ui_print_reveal_password(string $name, bool $return=false)
+{
+    $output = '&nbsp;<img class="clickable forced_title" id="reveal_password_'.$name.'" src="images/eye_show.png" onclick="reveal_password(\''.$name.'\')" data-use_title_for_force_title="1" data-title="'.__('Show password').'">';
+
+    if ($return === true) {
+        return $output;
+    }
+
+    echo $output;
+}
diff --git a/pandora_console/include/javascript/pandora_ui.js b/pandora_console/include/javascript/pandora_ui.js
index 2445473591..951db0e712 100644
--- a/pandora_console/include/javascript/pandora_ui.js
+++ b/pandora_console/include/javascript/pandora_ui.js
@@ -552,3 +552,16 @@ function infoMessage(data, idMsg) {
     })
     .show();
 }
+
+function reveal_password(name) {
+  var passwordElement = $("#password-" + name);
+  var revealElement = $("#reveal_password_" + name);
+
+  if (passwordElement.attr("type") == "password") {
+    passwordElement.attr("type", "text");
+    revealElement.attr("src", "images/eye_hide.png");
+  } else {
+    passwordElement.attr("type", "password");
+    revealElement.attr("src", "images/eye_show.png");
+  }
+}

From 9d0becc0122e7029bed214d1c84bd9cb5aa7d920 Mon Sep 17 00:00:00 2001
From: Jose Gonzalez <jose.gonzalez@artica.es>
Date: Tue, 29 Sep 2020 10:12:49 +0200
Subject: [PATCH 2/4] Added other password fields

---
 pandora_console/extensions/quick_shell.php       | 1 +
 pandora_console/godmode/setup/setup_auth.php     | 4 ++++
 pandora_console/godmode/setup/setup_ehorus.php   | 1 +
 pandora_console/godmode/setup/setup_integria.php | 2 ++
 4 files changed, 8 insertions(+)

diff --git a/pandora_console/extensions/quick_shell.php b/pandora_console/extensions/quick_shell.php
index 27807e6029..5505caa3af 100644
--- a/pandora_console/extensions/quick_shell.php
+++ b/pandora_console/extensions/quick_shell.php
@@ -468,6 +468,7 @@ function quickShellSettings()
         100,
         true
     );
+    $hidden->data[1][1] .= ui_print_reveal_password('gotty_pass', true);
 
     html_print_table($t);
 
diff --git a/pandora_console/godmode/setup/setup_auth.php b/pandora_console/godmode/setup/setup_auth.php
index db436224c3..eba3b44e0d 100644
--- a/pandora_console/godmode/setup/setup_auth.php
+++ b/pandora_console/godmode/setup/setup_auth.php
@@ -189,6 +189,10 @@ if (is_ajax()) {
                     100,
                     true
                 );
+                $row['control'] .= ui_print_reveal_password(
+                    'ldap_admin_pass',
+                    true
+                );
                 $table->data['ldap_admin_pass'] = $row;
             break;
 
diff --git a/pandora_console/godmode/setup/setup_ehorus.php b/pandora_console/godmode/setup/setup_ehorus.php
index 1c3650418b..1c522593ee 100644
--- a/pandora_console/godmode/setup/setup_ehorus.php
+++ b/pandora_console/godmode/setup/setup_ehorus.php
@@ -82,6 +82,7 @@ $table_remote->data['ehorus_user'] = $row;
 $row = [];
 $row['name'] = __('Password');
 $row['control'] = html_print_input_password('ehorus_pass', io_output_password($config['ehorus_pass']), '', 30, 100, true);
+$row['control'] .= ui_print_reveal_password('ehorus_pass', true);
 $table_remote->data['ehorus_pass'] = $row;
 
 // Directory hostname.
diff --git a/pandora_console/godmode/setup/setup_integria.php b/pandora_console/godmode/setup/setup_integria.php
index e172dda50b..0113c6f024 100644
--- a/pandora_console/godmode/setup/setup_integria.php
+++ b/pandora_console/godmode/setup/setup_integria.php
@@ -221,6 +221,7 @@ $table_remote->data['integria_user'] = $row;
 $row = [];
 $row['name'] = __('Password');
 $row['control'] = html_print_input_password('integria_pass', io_output_password($config['integria_pass']), '', 30, 100, true);
+$row['control'] .= ui_print_reveal_password('integria_pass', true);
 $table_remote->data['integria_pass'] = $row;
 
 // Integria hostname.
@@ -233,6 +234,7 @@ $table_remote->data['integria_hostname'] = $row;
 $row = [];
 $row['name'] = __('API Password');
 $row['control'] = html_print_input_password('integria_api_pass', io_output_password($config['integria_api_pass']), '', 30, 100, true);
+$row['control'] .= ui_print_reveal_password('integria_api_pass', true);
 $table_remote->data['integria_api_pass'] = $row;
 
 // Request timeout.

From 00b289a557f73cda6656c14aed17495a7f040800 Mon Sep 17 00:00:00 2001
From: Jose Gonzalez <jose.gonzalez@artica.es>
Date: Tue, 29 Sep 2020 12:21:52 +0200
Subject: [PATCH 3/4] Adapt functions for work in Metaconsole

---
 pandora_console/include/functions_ui.php         |  8 +++++++-
 pandora_console/include/javascript/pandora_ui.js | 11 +++++++++--
 2 files changed, 16 insertions(+), 3 deletions(-)

diff --git a/pandora_console/include/functions_ui.php b/pandora_console/include/functions_ui.php
index 2233b2fe95..a6fe8579c0 100755
--- a/pandora_console/include/functions_ui.php
+++ b/pandora_console/include/functions_ui.php
@@ -6136,7 +6136,13 @@ function ui_print_message_dialog($title, $text, $id='', $img='', $text_button=''
  */
 function ui_print_reveal_password(string $name, bool $return=false)
 {
-    $output = '&nbsp;<img class="clickable forced_title" id="reveal_password_'.$name.'" src="images/eye_show.png" onclick="reveal_password(\''.$name.'\')" data-use_title_for_force_title="1" data-title="'.__('Show password').'">';
+    if (is_metaconsole()) {
+        $imagePath = '../../images/';
+    } else {
+        $imagePath = 'images/';
+    }
+
+    $output = '&nbsp;<img class="clickable forced_title" id="reveal_password_'.$name.'" src="'.$imagePath.'eye_show.png" onclick="reveal_password(\''.$name.'\')" data-use_title_for_force_title="1" data-title="'.__('Show password').'">';
 
     if ($return === true) {
         return $output;
diff --git a/pandora_console/include/javascript/pandora_ui.js b/pandora_console/include/javascript/pandora_ui.js
index 951db0e712..c2b6a86e01 100644
--- a/pandora_console/include/javascript/pandora_ui.js
+++ b/pandora_console/include/javascript/pandora_ui.js
@@ -556,12 +556,19 @@ function infoMessage(data, idMsg) {
 function reveal_password(name) {
   var passwordElement = $("#password-" + name);
   var revealElement = $("#reveal_password_" + name);
+  var imagesPath = "";
+
+  if ($("#hidden-metaconsole_activated").val() == 1) {
+    imagesPath = "../../images/";
+  } else {
+    imagesPath = "images/";
+  }
 
   if (passwordElement.attr("type") == "password") {
     passwordElement.attr("type", "text");
-    revealElement.attr("src", "images/eye_hide.png");
+    revealElement.attr("src", imagesPath + "eye_hide.png");
   } else {
     passwordElement.attr("type", "password");
-    revealElement.attr("src", "images/eye_show.png");
+    revealElement.attr("src", imagesPath + "eye_show.png");
   }
 }

From 336f6924dfb2cdbba9a6174883e45074cc255cd5 Mon Sep 17 00:00:00 2001
From: Jose Gonzalez <jose.gonzalez@artica.es>
Date: Tue, 29 Sep 2020 12:22:29 +0200
Subject: [PATCH 4/4] Added images

---
 pandora_console/images/eye_hide.png | Bin 0 -> 647 bytes
 pandora_console/images/eye_show.png | Bin 0 -> 1365 bytes
 2 files changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 pandora_console/images/eye_hide.png
 create mode 100644 pandora_console/images/eye_show.png

diff --git a/pandora_console/images/eye_hide.png b/pandora_console/images/eye_hide.png
new file mode 100644
index 0000000000000000000000000000000000000000..8bed55e59977e35c254f877c03df36aedf39412b
GIT binary patch
literal 647
zcmV;20(kw2P)<h;3K|Lk000e1NJLTq000yK000yS1^@s6jfou%00004b3#c}2nYxW
zd<bNS0006$Nkl<ZIF03!F=!J}9LB%*5;;jQNd-H&7!ZObLt6q_bB;QA34u(awjo;(
z9kn<}2p9+?Aw!^ptwRW8xqCw#1W~!s!J>%GWaHovko20yJC5`{2QT3`qk?YwE%)BN
zKR>?jdk^^Ml}e>9x%c!hVb>|8&pVyY#o0fyXi!m<G^O+=fVAi6KnS4;AsU8ZT$Lp0
zUboxb4~0S>2qCwB04j>IMk%cUkbmXOvMflFG-|iogFqng9>69c#0FfE6-Bv4DShFA
z?Q+i7RaGUN^K}54X_|;cB4{?7OS-O~&*gFtX0W+K2e#ue@{n_0cN|9n3`V07iN#`9
z%H{Go#u$3N9snG2&Mz~@_5gq=iXuDC+&WZMbt#j{yaBK#gurAn!RqSjxKgQ@jYcD=
z>w3^VKZ8<Ask)%1J?Fb7guwCfF=ScB*4EY;N@-5l_1B*H$jlT4pe+DK0DyCTG#-zU
z&1O+36i_OaJ`+M-ITd)N%{xq|(=|fK9rvkaS(~P5J}MTAXOqdKzf>w64Tr-Nfaro$
zyQ->g%z?oCVrl>))9DnJWr<p?wjYnjzW}&K2pKu=b7z(S0E7^AP1Ekq_TG0GwQc(;
zrF5lSF2giU)a&(uZQCE6nC_?tobwIF*h@FV?^+YXFm5a_F9)}`w?Fm!{jb$(^)%-^
z3gCjfE6zD%jO{My@w*a<#3@;pALsM=x6|o#AcVO8)8XI94*=nCc;)2eB-CoP-uZmK
hXM~U^e+v8$^$pu2@V3TTc=!MS002ovPDHLkV1h`DB;Ei3

literal 0
HcmV?d00001

diff --git a/pandora_console/images/eye_show.png b/pandora_console/images/eye_show.png
new file mode 100644
index 0000000000000000000000000000000000000000..6447f0a0d7f0d745ac03873af01b6ee6cb616b74
GIT binary patch
literal 1365
zcmbVMZA=?w9DkrMU_%Y^;$$xI@nFc3wf9`PzT8PiU#^7`%DU2RjUQaE?G-N2yLvsK
zpdSiGh6BuWi6(nV8kQ{ZVT$a-J}g8+Hl4-~`(omZi7tN8WSLo<WH1+e3KaK&?1PtF
z?)m@k_xr#9pASPl9Y(``0|3An=;XrqTUUH5^#GJ@d}O+Sg$C6ZReR->I>IXga3|%s
z00U{hPY4Tqa`c^Vg*E^*{bD4lMuXjKLQb3cBF3CcXD}Opw)R|xPYehuj0=6D<Rt#Q
z@f88Zq?0&l4WeMiEA)$<V~Wr_))PsL4J4Q((S8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