quickShell auth

This commit is contained in:
fbsanchez 2019-10-24 12:05:00 +02:00
parent 276879d8ee
commit 045d42d2bb
2 changed files with 26 additions and 17 deletions

View File

@ -212,7 +212,17 @@ function quickShell()
return; return;
} }
$r = file_get_contents('http://'.$host.':'.$port.'/js/hterm.js'); // Check credentials.
$auth_str = '';
$gotty_url = $host.':'.$port;
if (empty($config['gotty_user']) === false
&& empty($config['gotty_pass']) === false
) {
$auth_str = $config['gotty_user'].':'.$config['gotty_pass'];
$gotty_url = $auth_str.'@'.$host.':'.$port;
}
$r = file_get_contents('http://'.$gotty_url.'/js/hterm.js');
if (empty($r) === true) { if (empty($r) === true) {
if (empty($wiz) === true) { if (empty($wiz) === true) {
$wiz = new Wizard(); $wiz = new Wizard();
@ -224,17 +234,15 @@ function quickShell()
} }
// Override gotty client settings. // Override gotty client settings.
if (empty($config['gotty_user']) if (empty($auth_str) === true) {
&& empty($config['gotty_pass'])
) {
$r .= "var gotty_auth_token = '';"; $r .= "var gotty_auth_token = '';";
} else { } else {
$r .= "var gotty_auth_token = '"; $r .= "var gotty_auth_token = '";
$r .= $config['gotty_user'].':'.$config['gotty_pass']."';"; $r .= $auth_str."';";
} }
// Set websocket target and method. // Set websocket target and method.
$gotty = file_get_contents('http://'.$host.':'.$port.'/js/gotty.js'); $gotty = file_get_contents('http://'.$gotty_url.'/js/gotty.js');
$url = "var url = (httpsEnabled ? 'wss://' : 'ws://') + window.location.host + window.location.pathname + 'ws';"; $url = "var url = (httpsEnabled ? 'wss://' : 'ws://') + window.location.host + window.location.pathname + 'ws';";
if (empty($config['ws_proxy_url']) === true) { if (empty($config['ws_proxy_url']) === true) {
$new = "var url = (httpsEnabled ? 'wss://' : 'ws://')"; $new = "var url = (httpsEnabled ? 'wss://' : 'ws://')";
@ -316,9 +324,11 @@ function quickShellSettings()
$gotty_pass = get_parameter( $gotty_pass = get_parameter(
'gotty_pass', 'gotty_pass',
$config['gotty_pass'] io_output_password($config['gotty_pass'])
); );
$gotty_pass = io_input_password($gotty_pass);
$changes = 0; $changes = 0;
$critical = 0; $critical = 0;
if ($config['gotty'] != $gotty) { if ($config['gotty'] != $gotty) {
@ -358,12 +368,12 @@ function quickShellSettings()
ui_print_page_header(__('QuickShell settings')); ui_print_page_header(__('QuickShell settings'));
if ($changes > 0) { if ($changes > 0) {
$msg = __('%d Updated', $changes);
if ($critical > 0) {
$msg = __( $msg = __(
'%d Updated, please restart WebSocket engine service', '%d Updated, please restart WebSocket engine service',
$changes $changes
); );
if ($critical > 0) {
$msg = __('%d Updated', $changes);
} }
ui_print_success_message($msg); ui_print_success_message($msg);
@ -423,9 +433,9 @@ function quickShellSettings()
[ [
'label' => __('Gotty password'), 'label' => __('Gotty password'),
'arguments' => [ 'arguments' => [
'type' => 'text', 'type' => 'password',
'name' => 'gotty_pass', 'name' => 'gotty_pass',
'value' => $config['gotty_pass'], 'value' => io_output_password($config['gotty_pass']),
], ],
], ],
[ [
@ -441,8 +451,6 @@ function quickShellSettings()
true true
); );
return;
} }

View File

@ -108,7 +108,8 @@ if (substr($os, 0, 3) !== 'win') {
if (empty($config['gotty_user']) === false if (empty($config['gotty_user']) === false
&& empty($config['gotty_pass']) === false && empty($config['gotty_pass']) === false
) { ) {
$gotty_creds = " -c '".$gotty_user.':'.$gotty_pass."'"; $gotty_pass = io_output_password($config['gotty_pass']);
$gotty_creds = " -c '".$config['gotty_user'].':'.$gotty_pass."'";
} }
// Kill previous gotty running. // Kill previous gotty running.