gotty changes
This commit is contained in:
parent
951cfa0863
commit
19a9f82fe1
|
@ -84,84 +84,38 @@ function quickShell()
|
|||
$method_port = get_parameter('port', null);
|
||||
|
||||
// Retrieve main IP Address.
|
||||
$address = agents_get_address($agent_id);
|
||||
$agent_address = agents_get_address($agent_id);
|
||||
|
||||
ui_require_css_file('wizard');
|
||||
ui_require_css_file('discovery');
|
||||
|
||||
// Settings.
|
||||
// WebSocket host, where client should connect.
|
||||
if (isset($config['ws_port']) === false) {
|
||||
config_update_value('ws_port', 8080);
|
||||
// Initialize Gotty Client.
|
||||
if ($method === 'ssh') {
|
||||
// SSH.
|
||||
$args = '?arg='.$username.'@'.$agent_address;
|
||||
//$args = '?arg='.$username.'@172.16.0.1';
|
||||
$args .= '&arg=-p%20'.$method_port;
|
||||
} else if ($method == 'telnet') {
|
||||
// Telnet.
|
||||
$username = preg_replace('/[^a-zA-Z0-9\-\.]/', '', $username);
|
||||
$args = '?arg=-l%20'.$username;
|
||||
$args .= '&arg='.$agent_address;
|
||||
$args .= '&arg='.$method_port.'&arg=-E';
|
||||
}
|
||||
|
||||
if (empty($config['ws_proxy_url']) === true) {
|
||||
$ws_url = 'http://'.$_SERVER['SERVER_ADDR'].':'.$config['ws_port'];
|
||||
} else {
|
||||
preg_match('/\/\/(.*)/', $config['ws_proxy_url'], $matches);
|
||||
if (isset($_SERVER['HTTPS']) === true) {
|
||||
$ws_url = 'https://'.$matches[1];
|
||||
} else {
|
||||
$ws_url = 'http://'.$matches[1];
|
||||
}
|
||||
}
|
||||
|
||||
// Gotty settings. Internal communication (WS).
|
||||
if (isset($config['gotty_host']) === false) {
|
||||
config_update_value('gotty_host', '127.0.0.1');
|
||||
}
|
||||
|
||||
if (isset($config['gotty_telnet_port']) === false) {
|
||||
config_update_value('gotty_telnet_port', 8082);
|
||||
}
|
||||
|
||||
if (isset($config['gotty_ssh_port']) === false) {
|
||||
config_update_value('gotty_ssh_port', 8081);
|
||||
}
|
||||
|
||||
// Context to allow self-signed certs.
|
||||
$context = stream_context_create(
|
||||
[
|
||||
'http' => [ 'method' => 'GET'],
|
||||
'ssl' => [
|
||||
'verify_peer' => false,
|
||||
'verify_peer_name' => false,
|
||||
],
|
||||
]
|
||||
);
|
||||
$method_addr = ($method === 'ssh') ? $config['gotty_ssh_addr'] : $config['gotty_telnet_addr'];
|
||||
$address = (empty($method_addr) === true) ? $_SERVER['SERVER_ADDR'] : $method_addr;
|
||||
$use_ssl = ($method === 'ssh') ? $config['gotty_ssh_use_ssl'] : $config['gotty_telnet_use_ssl'];
|
||||
$protocol = ((bool) $use_ssl === true) ? 'https://' : 'http://';
|
||||
$port = ($method === 'ssh') ? $config['gotty_ssh_port'] : $config['gotty_telnet_port'];
|
||||
$connection_hash = ($method === 'ssh') ? $config['gotty_ssh_connection_hash'] : $config['gotty_telnet_connection_hash'];
|
||||
$gotty_addr = $protocol.$address.':'.$port.'/'.$connection_hash.'/'.$args;
|
||||
|
||||
// Username. Retrieve from form.
|
||||
if (empty($username) === true) {
|
||||
// No username provided, ask for it.
|
||||
$wiz = new Wizard();
|
||||
|
||||
$test = curl($ws_url, []);
|
||||
if ($test === false) {
|
||||
ui_print_error_message(__('WebService engine has not been started, please check documentation.'));
|
||||
$wiz->printForm(
|
||||
[
|
||||
'form' => [
|
||||
'method' => 'POST',
|
||||
'action' => '#',
|
||||
'id' => 'retry_form',
|
||||
],
|
||||
]
|
||||
);
|
||||
|
||||
html_print_action_buttons(
|
||||
html_print_submit_button(
|
||||
__('Retry'),
|
||||
'submit',
|
||||
false,
|
||||
[
|
||||
'icon' => 'next',
|
||||
'form' => 'retry_form',
|
||||
],
|
||||
true
|
||||
)
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
$wiz->printForm(
|
||||
[
|
||||
|
@ -221,114 +175,25 @@ function quickShell()
|
|||
return;
|
||||
}
|
||||
|
||||
// Initialize Gotty Client.
|
||||
$host = $config['gotty_host'];
|
||||
if ($method == 'ssh') {
|
||||
// SSH.
|
||||
$port = $config['gotty_ssh_port'];
|
||||
$command_arguments = "var args = '?arg=".$username.'@'.$address;
|
||||
$command_arguments .= '&arg=-p '.$method_port."';";
|
||||
} else if ($method == 'telnet') {
|
||||
// Telnet.
|
||||
$port = $config['gotty_telnet_port'];
|
||||
$username = preg_replace('/[^a-zA-Z0-9\-\.]/', '', $username);
|
||||
$command_arguments = "var args = '?arg=-l ".$username;
|
||||
$command_arguments .= '&arg='.$address;
|
||||
$command_arguments .= '&arg='.$method_port."&arg=-E';";
|
||||
} else {
|
||||
ui_print_error_message(__('Please use SSH or Telnet.'));
|
||||
return;
|
||||
}
|
||||
|
||||
// If rediretion is enabled, we will try to connect using
|
||||
// http:// or https:// endpoint.
|
||||
$test = get_headers($ws_url, false, $context);
|
||||
if ($test === false) {
|
||||
if (empty($wiz) === true) {
|
||||
$wiz = new Wizard();
|
||||
}
|
||||
|
||||
ui_print_error_message(__('WebService engine has not been started, please check documentation.'));
|
||||
echo $wiz->printGoBackButton('#');
|
||||
return;
|
||||
}
|
||||
|
||||
// Check credentials.
|
||||
$auth_str = '';
|
||||
$gotty_url = $host.':'.$port;
|
||||
if (empty($config['gotty_user']) === false
|
||||
&& empty($config['gotty_pass']) === false
|
||||
) {
|
||||
$auth_str = io_safe_output($config['gotty_user']);
|
||||
$auth_str .= ':'.io_output_password($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($wiz) === true) {
|
||||
$wiz = new Wizard();
|
||||
}
|
||||
|
||||
ui_print_error_message(__('WebService engine is not working properly, please check documentation.'));
|
||||
echo $wiz->printGoBackButton('#');
|
||||
return;
|
||||
}
|
||||
|
||||
// Override gotty client settings.
|
||||
if (empty($auth_str) === true) {
|
||||
$r .= "var gotty_auth_token = '';";
|
||||
} else {
|
||||
$r .= "var gotty_auth_token = '";
|
||||
$r .= $auth_str."';";
|
||||
}
|
||||
|
||||
// Set websocket target and method.
|
||||
$gotty = file_get_contents('http://'.$gotty_url.'/js/gotty.js');
|
||||
$url = "var url = (httpsEnabled ? 'wss://' : 'ws://') + window.location.host + window.location.pathname + 'ws';";
|
||||
if (empty($config['ws_proxy_url']) === true) {
|
||||
$new = "var url = (httpsEnabled ? 'wss://' : 'ws://')";
|
||||
$new .= " + window.location.host + ':";
|
||||
$new .= $config['ws_port'].'/'.$method."';";
|
||||
} else {
|
||||
$new = "var url = '";
|
||||
$new .= $config['ws_proxy_url'].'/'.$method."';";
|
||||
}
|
||||
|
||||
// Update firefox issue.
|
||||
$original = ' this.iframe_.src = \'#\';';
|
||||
$trick = 'this.iframe_.src = \'javascript:\';';
|
||||
|
||||
$r = str_replace($original, $trick, $r);
|
||||
|
||||
// Update url.
|
||||
$gotty = str_replace($url, $new, $gotty);
|
||||
|
||||
// Update websocket arguments.
|
||||
$args = 'var args = window.location.search;';
|
||||
$new = $command_arguments;
|
||||
|
||||
// Update arguments.
|
||||
$gotty = str_replace($args, $new, $gotty);
|
||||
|
||||
?>
|
||||
<style>#terminal {
|
||||
height: 650px;
|
||||
width: 100%;
|
||||
margin: 0px;
|
||||
padding: 0;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
min-height: calc(100vh - 205px);
|
||||
}
|
||||
#terminal > iframe {
|
||||
width:100%;
|
||||
height:100%;
|
||||
position: relative!important;
|
||||
flex-grow: 1;
|
||||
}
|
||||
</style>
|
||||
<div id="terminal"></div>
|
||||
<script type="text/javascript">
|
||||
<?php echo $r; ?>
|
||||
</script>
|
||||
<script type="text/javascript">
|
||||
<?php echo $gotty; ?>
|
||||
</script>
|
||||
|
||||
<div id="terminal"><iframe id="gotty-iframe" src="<?php echo $gotty_addr; ?>"></iframe></div>
|
||||
|
||||
<?php
|
||||
|
||||
}
|
||||
|
@ -359,17 +224,37 @@ function quickShellSettings()
|
|||
config_update_value('gotty_ssh_port', 8081);
|
||||
}
|
||||
|
||||
if (isset($config['gotty_ssh_user']) === false) {
|
||||
config_update_value('gotty_ssh_user', 'pandora');
|
||||
}
|
||||
|
||||
if (isset($config['gotty_telnet_user']) === false) {
|
||||
config_update_value('gotty_telnet_user', 'pandora');
|
||||
}
|
||||
|
||||
if (isset($config['gotty_ssh_pass']) === false) {
|
||||
config_update_value('gotty_ssh_pass', 'Pandor4!');
|
||||
}
|
||||
|
||||
if (isset($config['gotty_telnet_pass']) === false) {
|
||||
config_update_value('gotty_telnet_pass', 'Pandor4!');
|
||||
}
|
||||
|
||||
$changes = 0;
|
||||
$critical = 0;
|
||||
|
||||
// Parser.
|
||||
if (get_parameter('update_config', false) !== false) {
|
||||
// Gotty settings. Internal communication (WS).
|
||||
$gotty = get_parameter(
|
||||
'gotty',
|
||||
$gotty_ssh_addr = get_parameter(
|
||||
'gotty_ssh_addr',
|
||||
''
|
||||
);
|
||||
$gotty_host = get_parameter(
|
||||
'gotty_host',
|
||||
|
||||
$gotty_telnet_addr = get_parameter(
|
||||
'gotty_telnet_addr',
|
||||
''
|
||||
);
|
||||
|
||||
$gotty_ssh_port = get_parameter(
|
||||
'gotty_ssh_port',
|
||||
''
|
||||
|
@ -379,84 +264,116 @@ function quickShellSettings()
|
|||
''
|
||||
);
|
||||
|
||||
$gotty_user = get_parameter(
|
||||
'gotty_user',
|
||||
''
|
||||
$gotty_ssh_user = get_parameter(
|
||||
'gotty_ssh_user',
|
||||
'pandora'
|
||||
);
|
||||
|
||||
$gotty_pass = get_parameter(
|
||||
'gotty_pass',
|
||||
''
|
||||
$gotty_telnet_user = get_parameter(
|
||||
'gotty_telnet_user',
|
||||
'pandora'
|
||||
);
|
||||
|
||||
$gotty_pass = io_input_password($gotty_pass);
|
||||
$gotty_ssh_use_ssl = get_parameter(
|
||||
'gotty_ssh_use_ssl',
|
||||
false
|
||||
);
|
||||
|
||||
$changes = 0;
|
||||
$critical = 0;
|
||||
if ($config['gotty'] != $gotty) {
|
||||
config_update_value('gotty', $gotty);
|
||||
$changes++;
|
||||
$critical++;
|
||||
$gotty_telnet_use_ssl = get_parameter(
|
||||
'gotty_telnet_use_ssl',
|
||||
false
|
||||
);
|
||||
|
||||
$gotty_ssh_pass = get_parameter(
|
||||
'gotty_ssh_pass',
|
||||
'Pandor4!'
|
||||
);
|
||||
|
||||
$gotty_ssh_pass = io_input_password($gotty_ssh_pass);
|
||||
|
||||
$gotty_telnet_pass = get_parameter(
|
||||
'gotty_telnet_pass',
|
||||
'Pandor4!'
|
||||
);
|
||||
|
||||
$gotty_telnet_pass = io_input_password($gotty_telnet_pass);
|
||||
|
||||
if ($config['gotty_ssh_addr'] != $gotty_ssh_addr) {
|
||||
config_update_value('gotty_ssh_addr', $gotty_ssh_addr);
|
||||
}
|
||||
|
||||
if ($config['gotty_host'] != $gotty_host) {
|
||||
config_update_value('gotty_host', $gotty_host);
|
||||
$changes++;
|
||||
}
|
||||
|
||||
if ($config['gotty_telnet_port'] != $gotty_telnet_port) {
|
||||
config_update_value('gotty_telnet_port', $gotty_telnet_port);
|
||||
$changes++;
|
||||
if ($config['gotty_telnet_addr'] != $gotty_telnet_addr) {
|
||||
config_update_value('gotty_telnet_addr', $gotty_telnet_addr);
|
||||
}
|
||||
|
||||
if ($config['gotty_ssh_port'] != $gotty_ssh_port) {
|
||||
// Mark ssh gotty for restart (should kill the process in the current port).
|
||||
if ($config['restart_gotty_ssh_next_cron_port'] === ''
|
||||
|| $config['restart_gotty_ssh_next_cron_port'] === null
|
||||
) {
|
||||
config_update_value('restart_gotty_ssh_next_cron_port', $config['gotty_ssh_port']);
|
||||
}
|
||||
|
||||
config_update_value('gotty_ssh_port', $gotty_ssh_port);
|
||||
$changes++;
|
||||
}
|
||||
|
||||
if ($config['gotty_user'] != $gotty_user) {
|
||||
config_update_value('gotty_user', $gotty_user);
|
||||
$changes++;
|
||||
$critical++;
|
||||
if ($config['gotty_telnet_port'] != $gotty_telnet_port) {
|
||||
// Mark telnet gotty for restart (should kill the process in the current port).
|
||||
if ($config['restart_gotty_telnet_next_cron_port'] === ''
|
||||
|| $config['restart_gotty_telnet_next_cron_port'] === null
|
||||
) {
|
||||
config_update_value('restart_gotty_telnet_next_cron_port', $config['gotty_telnet_port']);
|
||||
}
|
||||
|
||||
config_update_value('gotty_telnet_port', $gotty_telnet_port);
|
||||
}
|
||||
|
||||
if ($config['gotty_pass'] != $gotty_pass) {
|
||||
$gotty_pass = io_input_password($gotty_pass);
|
||||
config_update_value('gotty_pass', $gotty_pass);
|
||||
$changes++;
|
||||
$critical++;
|
||||
if ($config['gotty_ssh_user'] != $gotty_ssh_user) {
|
||||
config_update_value('gotty_ssh_user', $gotty_ssh_user);
|
||||
}
|
||||
|
||||
if ($config['gotty_telnet_user'] != $gotty_telnet_user) {
|
||||
config_update_value('gotty_telnet_user', $gotty_telnet_user);
|
||||
}
|
||||
|
||||
if ($config['gotty_ssh_use_ssl'] != $gotty_ssh_use_ssl) {
|
||||
config_update_value('gotty_ssh_use_ssl', $gotty_ssh_use_ssl);
|
||||
}
|
||||
|
||||
if ($config['gotty_telnet_use_ssl'] != $gotty_telnet_use_ssl) {
|
||||
config_update_value('gotty_telnet_use_ssl', $gotty_telnet_use_ssl);
|
||||
}
|
||||
|
||||
if ($config['gotty_ssh_pass'] != $gotty_ssh_pass) {
|
||||
$gotty_ssh_pass = io_input_password($gotty_ssh_pass);
|
||||
config_update_value('gotty_ssh_pass', $gotty_ssh_pass);
|
||||
}
|
||||
|
||||
if ($config['gotty_telnet_pass'] != $gotty_telnet_pass) {
|
||||
$gotty_telnet_pass = io_input_password($gotty_telnet_pass);
|
||||
config_update_value('gotty_telnet_pass', $gotty_telnet_pass);
|
||||
}
|
||||
}
|
||||
|
||||
if ($changes > 0) {
|
||||
$msg = __('%d Updated', $changes);
|
||||
if ($critical > 0) {
|
||||
$msg = __(
|
||||
'%d Updated, please restart WebSocket engine service',
|
||||
$changes
|
||||
);
|
||||
}
|
||||
|
||||
ui_print_success_message($msg);
|
||||
}
|
||||
|
||||
// Form. Using old style.
|
||||
echo '<fieldset class="margin-bottom-10">';
|
||||
echo '<legend>'.__('Quickshell').'</legend>';
|
||||
echo '<legend>'.__('SSH connection parameters').'</legend>';
|
||||
|
||||
$t = new StdClass();
|
||||
$t->data = [];
|
||||
$t->width = '100%';
|
||||
$t->class = 'filter-table-adv';
|
||||
$t->data = [];
|
||||
$t->style = [];
|
||||
$t->style[0] = 'width: 50%;';
|
||||
$test_start = '<span id="test-gotty-spinner" class="invisible"> '.html_print_image('images/spinner.gif', true).'</span>';
|
||||
$test_start .= ' <span id="test-gotty-message" class="invisible"></span>';
|
||||
|
||||
$t->data[0][] = html_print_label_input_block(
|
||||
__('Gotty path'),
|
||||
$ssh_table = new StdClass();
|
||||
$ssh_table->data = [];
|
||||
$ssh_table->width = '100%';
|
||||
$ssh_table->class = 'filter-table-adv';
|
||||
$ssh_table->data = [];
|
||||
$ssh_table->style = [];
|
||||
$ssh_table->style[0] = 'width: 50%;';
|
||||
|
||||
$ssh_table->data[0][] = html_print_label_input_block(
|
||||
__('Gotty address'),
|
||||
html_print_input_text(
|
||||
'gotty',
|
||||
$config['gotty'],
|
||||
'gotty_ssh_addr',
|
||||
$config['gotty_ssh_addr'],
|
||||
'',
|
||||
30,
|
||||
100,
|
||||
|
@ -464,20 +381,8 @@ function quickShellSettings()
|
|||
)
|
||||
);
|
||||
|
||||
$t->data[0][] = html_print_label_input_block(
|
||||
__('Gotty host'),
|
||||
html_print_input_text(
|
||||
'gotty_host',
|
||||
$config['gotty_host'],
|
||||
'',
|
||||
30,
|
||||
100,
|
||||
true
|
||||
)
|
||||
);
|
||||
|
||||
$t->data[1][] = html_print_label_input_block(
|
||||
__('Gotty ssh port'),
|
||||
$ssh_table->data[0][] = html_print_label_input_block(
|
||||
__('Gotty port'),
|
||||
html_print_input_text(
|
||||
'gotty_ssh_port',
|
||||
$config['gotty_ssh_port'],
|
||||
|
@ -488,8 +393,88 @@ function quickShellSettings()
|
|||
)
|
||||
);
|
||||
|
||||
$t->data[1][] = html_print_label_input_block(
|
||||
__('Gotty telnet port'),
|
||||
$ssh_table->data[1][] = html_print_label_input_block(
|
||||
__('Gotty user'),
|
||||
html_print_input_text(
|
||||
'gotty_ssh_user',
|
||||
$config['gotty_ssh_user'],
|
||||
'',
|
||||
30,
|
||||
100,
|
||||
true
|
||||
)
|
||||
);
|
||||
|
||||
$ssh_table->data[1][] = html_print_label_input_block(
|
||||
__('Gotty password'),
|
||||
html_print_input_password(
|
||||
'gotty_ssh_pass',
|
||||
io_output_password($config['gotty_ssh_pass']),
|
||||
'',
|
||||
30,
|
||||
100,
|
||||
true
|
||||
)
|
||||
);
|
||||
|
||||
$ssh_table->data[2][] = html_print_label_input_block(
|
||||
__('Use SSL'),
|
||||
html_print_checkbox_switch(
|
||||
'gotty_ssh_use_ssl',
|
||||
1,
|
||||
$config['gotty_ssh_use_ssl'],
|
||||
true,
|
||||
$disable_agentaccess
|
||||
)
|
||||
);
|
||||
|
||||
// Test.
|
||||
$row = [];
|
||||
$test_start = '<span id="test-gotty-spinner-ssh" class="invisible"> '.html_print_image('images/spinner.gif', true).'</span>';
|
||||
$test_start .= ' <span id="test-gotty-message-ssh" class="invisible"></span>';
|
||||
|
||||
$ssh_table->data[2][] = html_print_button(
|
||||
__('Test'),
|
||||
'test-gotty-ssh',
|
||||
false,
|
||||
'handleTestSSH()',
|
||||
[
|
||||
'icon' => 'cog',
|
||||
'mode' => 'secondary',
|
||||
'style' => 'width: 115px;',
|
||||
],
|
||||
true
|
||||
).$test_start;
|
||||
|
||||
html_print_table($ssh_table);
|
||||
|
||||
echo '</fieldset>';
|
||||
|
||||
echo '<fieldset class="margin-bottom-10">';
|
||||
echo '<legend>'.__('Telnet connection parameters').'</legend>';
|
||||
|
||||
$telnet_table = new StdClass();
|
||||
$telnet_table->data = [];
|
||||
$telnet_table->width = '100%';
|
||||
$telnet_table->class = 'filter-table-adv';
|
||||
$telnet_table->data = [];
|
||||
$telnet_table->style = [];
|
||||
$telnet_table->style[0] = 'width: 50%;';
|
||||
|
||||
$telnet_table->data[0][] = html_print_label_input_block(
|
||||
__('Gotty address'),
|
||||
html_print_input_text(
|
||||
'gotty_telnet_addr',
|
||||
$config['gotty_telnet_addr'],
|
||||
'',
|
||||
30,
|
||||
100,
|
||||
true
|
||||
)
|
||||
);
|
||||
|
||||
$telnet_table->data[0][] = html_print_label_input_block(
|
||||
__('Gotty port'),
|
||||
html_print_input_text(
|
||||
'gotty_telnet_port',
|
||||
$config['gotty_telnet_port'],
|
||||
|
@ -500,18 +485,11 @@ function quickShellSettings()
|
|||
)
|
||||
);
|
||||
|
||||
$hidden = new stdClass();
|
||||
$hidden->data = [];
|
||||
$hidden->width = '100%';
|
||||
$hidden->class = 'filter-table-adv';
|
||||
$hidden->data = [];
|
||||
$hidden->style[0] = 'width: 50%;';
|
||||
|
||||
$hidden->data[0][] = html_print_label_input_block(
|
||||
$telnet_table->data[1][] = html_print_label_input_block(
|
||||
__('Gotty user'),
|
||||
html_print_input_text(
|
||||
'gotty_user',
|
||||
$config['gotty_user'],
|
||||
'gotty_telnet_user',
|
||||
$config['gotty_telnet_user'],
|
||||
'',
|
||||
30,
|
||||
100,
|
||||
|
@ -519,11 +497,11 @@ function quickShellSettings()
|
|||
)
|
||||
);
|
||||
|
||||
$hidden->data[0][] = html_print_label_input_block(
|
||||
$telnet_table->data[1][] = html_print_label_input_block(
|
||||
__('Gotty password'),
|
||||
html_print_input_password(
|
||||
'gotty_pass',
|
||||
io_output_password($config['gotty_pass']),
|
||||
'gotty_telnet_pass',
|
||||
io_output_password($config['gotty_telnet_pass']),
|
||||
'',
|
||||
30,
|
||||
100,
|
||||
|
@ -531,24 +509,71 @@ function quickShellSettings()
|
|||
)
|
||||
);
|
||||
|
||||
html_print_table($t);
|
||||
|
||||
ui_print_toggle(
|
||||
[
|
||||
'content' => html_print_table($hidden, true),
|
||||
'name' => __('Advanced options'),
|
||||
'clean' => false,
|
||||
'main_class' => 'no-border-imp',
|
||||
'container_class' => 'no-border-imp',
|
||||
]
|
||||
$telnet_table->data[2][] = html_print_label_input_block(
|
||||
__('Use SSL'),
|
||||
html_print_checkbox_switch(
|
||||
'gotty_telnet_use_ssl',
|
||||
1,
|
||||
$config['gotty_telnet_use_ssl'],
|
||||
true
|
||||
)
|
||||
);
|
||||
|
||||
echo '</fieldset>';
|
||||
// Test.
|
||||
$row = [];
|
||||
$test_start = '<span id="test-gotty-spinner-telnet" class="invisible"> '.html_print_image('images/spinner.gif', true).'</span>';
|
||||
$test_start .= ' <span id="test-gotty-message-telnet" class="invisible"></span>';
|
||||
|
||||
$telnet_table->data[2][] = html_print_button(
|
||||
__('Test'),
|
||||
'test-gotty-telnet',
|
||||
false,
|
||||
'handleTestTelnet()',
|
||||
[
|
||||
'icon' => 'cog',
|
||||
'mode' => 'secondary',
|
||||
'style' => 'width: 115px;',
|
||||
],
|
||||
true
|
||||
).$test_start;
|
||||
|
||||
html_print_table($telnet_table);
|
||||
html_print_input_hidden('update_config', 1);
|
||||
|
||||
echo '</fieldset>';
|
||||
}
|
||||
|
||||
|
||||
// This extension is usefull only if the agent has associated IP.
|
||||
if (is_ajax() === true) {
|
||||
$address = get_parameter('address');
|
||||
|
||||
if (isset($address) === true) {
|
||||
$ch = curl_init($address);
|
||||
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
|
||||
// Maximum time for the entire request.
|
||||
curl_setopt($ch, CURLOPT_TIMEOUT, 2);
|
||||
|
||||
// Maximum time to establish a connection.
|
||||
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 1);
|
||||
|
||||
curl_exec($ch);
|
||||
$response_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
||||
curl_close($ch);
|
||||
|
||||
if ($response_code === 200 || $response_code === 401) {
|
||||
$result = ['status' => 'success'];
|
||||
} else {
|
||||
$result = ['status' => 'error'];
|
||||
}
|
||||
|
||||
echo json_encode($result);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// This extension is useful only if the agent has associated IP.
|
||||
$agent_id = get_parameter('id_agente');
|
||||
if (empty($agent_id) === false
|
||||
&& get_parameter('sec2', '') == 'operation/agentes/ver_agente'
|
||||
|
@ -573,4 +598,139 @@ if (empty($agent_id) === false
|
|||
}
|
||||
}
|
||||
|
||||
echo '<script>';
|
||||
echo 'var server_addr = "'.$_SERVER['SERVER_ADDR'].'";';
|
||||
echo "function checkAddressReachability(address, callback) {
|
||||
$.ajax({
|
||||
url: 'ajax.php',
|
||||
data: {
|
||||
page: 'extensions/quick_shell',
|
||||
address
|
||||
},
|
||||
type: 'GET',
|
||||
async: false,
|
||||
dataType: 'json',
|
||||
success: function (data) {
|
||||
if (data.status === 'success') {
|
||||
callback(true);
|
||||
} else {
|
||||
callback(false);
|
||||
}
|
||||
},
|
||||
error: function () {
|
||||
callback(false);
|
||||
}
|
||||
});
|
||||
}";
|
||||
|
||||
$handle_test_telnet = "var handleTestTelnet = function (event) {
|
||||
var gotty_telnet_addr = $('input#text-gotty_telnet_addr').val();
|
||||
var gotty_telnet_port = $('input#text-gotty_telnet_port').val();
|
||||
var gotty_telnet_user = $('input#text-gotty_telnet_user').val();
|
||||
var gotty_telnet_password = $('input#password-gotty_telnet_pass').val();
|
||||
var gotty_telnet_use_ssl = $('input#checkbox-gotty_telnet_use_ssl').is(':checked');
|
||||
|
||||
if (gotty_telnet_addr === '') {
|
||||
url = (gotty_telnet_use_ssl ? 'https://' : 'http://') + server_addr + ':' + gotty_telnet_port;
|
||||
} else {
|
||||
url = (gotty_telnet_use_ssl ? 'https://' : 'http://') + gotty_telnet_addr + ':' + gotty_telnet_port;
|
||||
}
|
||||
|
||||
var showLoadingImage = function () {
|
||||
$('#button-test-gotty-telnet').children('div').attr('class', 'subIcon cog rotation secondary mini');
|
||||
}
|
||||
|
||||
var showSuccessImage = function () {
|
||||
$('#button-test-gotty-telnet').children('div').attr('class', 'subIcon tick secondary mini');
|
||||
}
|
||||
|
||||
var showFailureImage = function () {
|
||||
$('#button-test-gotty-telnet').children('div').attr('class', 'subIcon fail secondary mini');
|
||||
}
|
||||
|
||||
var hideMessage = function () {
|
||||
$('span#test-gotty-message-telnet').hide();
|
||||
}
|
||||
var showMessage = function () {
|
||||
$('span#test-gotty-message-telnet').show();
|
||||
}
|
||||
var changeTestMessage = function (message) {
|
||||
$('span#test-gotty-message-telnet').text(message);
|
||||
}
|
||||
|
||||
var errorMessage = '".__('Unable to connect.')."';
|
||||
|
||||
hideMessage();
|
||||
showLoadingImage();
|
||||
|
||||
checkAddressReachability(url, function(isReachable) {
|
||||
if (isReachable) {
|
||||
showSuccessImage();
|
||||
hideMessage();
|
||||
} else {
|
||||
showFailureImage();
|
||||
changeTestMessage(errorMessage);
|
||||
showMessage();
|
||||
}
|
||||
});
|
||||
|
||||
};";
|
||||
|
||||
$handle_test_ssh = "var handleTestSSH = function (event) {
|
||||
var gotty_ssh_addr = $('input#text-gotty_ssh_addr').val();
|
||||
var gotty_ssh_port = $('input#text-gotty_ssh_port').val();
|
||||
var gotty_ssh_user = $('input#text-gotty_ssh_user').val();
|
||||
var gotty_ssh_password = $('input#password-gotty_ssh_pass').val();
|
||||
var gotty_ssh_use_ssl = $('input#checkbox-gotty_ssh_use_ssl').is(':checked');
|
||||
|
||||
if (gotty_ssh_addr === '') {
|
||||
url = (gotty_ssh_use_ssl ? 'https://' : 'http://') + server_addr + ':' + gotty_ssh_port;
|
||||
} else {
|
||||
url = (gotty_ssh_use_ssl ? 'https://' : 'http://') + gotty_ssh_addr + ':' + gotty_ssh_port;
|
||||
}
|
||||
|
||||
var showLoadingImage = function () {
|
||||
$('#button-test-gotty-ssh').children('div').attr('class', 'subIcon cog rotation secondary mini');
|
||||
}
|
||||
|
||||
var showSuccessImage = function () {
|
||||
$('#button-test-gotty-ssh').children('div').attr('class', 'subIcon tick secondary mini');
|
||||
}
|
||||
|
||||
var showFailureImage = function () {
|
||||
$('#button-test-gotty-ssh').children('div').attr('class', 'subIcon fail secondary mini');
|
||||
}
|
||||
|
||||
var hideMessage = function () {
|
||||
$('span#test-gotty-message-ssh').hide();
|
||||
}
|
||||
var showMessage = function () {
|
||||
$('span#test-gotty-message-ssh').show();
|
||||
}
|
||||
var changeTestMessage = function (message) {
|
||||
$('span#test-gotty-message-ssh').text(message);
|
||||
}
|
||||
|
||||
var errorMessage = '".__('Unable to connect.')."';
|
||||
|
||||
|
||||
hideMessage();
|
||||
showLoadingImage();
|
||||
|
||||
checkAddressReachability(url, function(isReachable) {
|
||||
if (isReachable) {
|
||||
showSuccessImage();
|
||||
hideMessage();
|
||||
} else {
|
||||
showFailureImage();
|
||||
changeTestMessage(errorMessage);
|
||||
showMessage();
|
||||
}
|
||||
});
|
||||
};";
|
||||
|
||||
echo $handle_test_ssh;
|
||||
echo $handle_test_telnet;
|
||||
echo '</script>';
|
||||
|
||||
extensions_add_godmode_function('quickShellSettings');
|
||||
|
|
|
@ -1707,4 +1707,5 @@ enterprise/godmode/wizards/Applications.class.php
|
|||
enterprise/godmode/wizards/Cloud.class.php
|
||||
enterprise/images/wizard/applications.png
|
||||
enterprise/images/wizard/cloud.png
|
||||
enterprise/images/wizard/consoletasks.png
|
||||
enterprise/images/wizard/consoletasks.png
|
||||
pandora_websocket_engine
|
|
@ -485,7 +485,7 @@ if ($access_console_node === true) {
|
|||
$sub2['godmode/setup/setup§ion=notifications']['text'] = __('Notifications');
|
||||
$sub2['godmode/setup/setup§ion=notifications']['refr'] = 0;
|
||||
|
||||
$sub2['godmode/setup/setup§ion=websocket_engine']['text'] = __('Websocket Engine');
|
||||
$sub2['godmode/setup/setup§ion=websocket_engine']['text'] = __('QuickShell');
|
||||
$sub2['godmode/setup/setup§ion=websocket_engine']['refr'] = 0;
|
||||
|
||||
$sub2['godmode/setup/setup§ion=external_tools']['text'] = __('External Tools');
|
||||
|
|
|
@ -227,7 +227,7 @@ $buttons['websocket_engine'] = [
|
|||
'images/websocket_small.png',
|
||||
true,
|
||||
[
|
||||
'title' => __('Websocket engine'),
|
||||
'title' => __('QuickShell'),
|
||||
'class' => 'invert_filter',
|
||||
]
|
||||
).'</a>',
|
||||
|
@ -327,7 +327,7 @@ switch ($section) {
|
|||
|
||||
case 'websocket_engine':
|
||||
$buttons['websocket_engine']['active'] = true;
|
||||
$subpage = __('Pandora Websocket Engine');
|
||||
$subpage = __('QuickShell');
|
||||
$help_header = 'quickshell_settings';
|
||||
break;
|
||||
|
||||
|
|
|
@ -34,92 +34,20 @@ $url = ui_get_full_url(
|
|||
|
||||
echo '<form class="max_floating_element_size" id="form_setup" method="post" action="'.$url.'">';
|
||||
|
||||
echo '<fieldset class="margin-bottom-10">';
|
||||
echo '<legend>'.__('WebSocket settings').'</legend>';
|
||||
|
||||
$t = new StdClass();
|
||||
$t->data = [];
|
||||
$t->width = '100%';
|
||||
$t->class = 'databox filter-table-adv';
|
||||
$t->data = [];
|
||||
|
||||
$t->data[0][] = html_print_label_input_block(
|
||||
__('Bind address'),
|
||||
html_print_input_text(
|
||||
'ws_bind_address',
|
||||
$config['ws_bind_address'],
|
||||
'',
|
||||
30,
|
||||
100,
|
||||
true
|
||||
)
|
||||
);
|
||||
|
||||
$t->data[0][] = html_print_label_input_block(
|
||||
__('Bind port'),
|
||||
html_print_input_text(
|
||||
'ws_port',
|
||||
$config['ws_port'],
|
||||
'',
|
||||
30,
|
||||
100,
|
||||
true
|
||||
)
|
||||
);
|
||||
|
||||
$t->data[1][] = html_print_label_input_block(
|
||||
__('WebSocket proxy url'),
|
||||
html_print_input_text(
|
||||
'ws_proxy_url',
|
||||
$config['ws_proxy_url'],
|
||||
'',
|
||||
30,
|
||||
100,
|
||||
true
|
||||
)
|
||||
);
|
||||
|
||||
html_print_input_hidden('update_config', 1);
|
||||
|
||||
// Test.
|
||||
$row = [];
|
||||
$test_start = '<span id="test-gotty-spinner" class="invisible"> '.html_print_image('images/spinner.gif', true).'</span>';
|
||||
$test_start .= ' <span id="test-gotty-message" class="invisible"></span>';
|
||||
$row['gotty_test'] = html_print_label_input_block(
|
||||
__('Test connection'),
|
||||
html_print_button(
|
||||
__('Test'),
|
||||
'test-gotty',
|
||||
false,
|
||||
'handleTest()',
|
||||
[
|
||||
'icon' => 'cog',
|
||||
'mode' => 'secondary mini',
|
||||
'style' => 'width: 115px;',
|
||||
],
|
||||
true
|
||||
).$test_start,
|
||||
['div_class' => 'inline_flex row']
|
||||
);
|
||||
|
||||
$t->data['gotty_test'] = $row;
|
||||
|
||||
html_print_table($t);
|
||||
|
||||
echo '</fieldset>';
|
||||
|
||||
if (function_exists('quickShellSettings') === true) {
|
||||
quickShellSettings();
|
||||
}
|
||||
|
||||
$action_btns = html_print_submit_button(
|
||||
__('Update'),
|
||||
'update_button',
|
||||
false,
|
||||
[ 'icon' => 'update' ],
|
||||
true
|
||||
);
|
||||
|
||||
html_print_action_buttons(
|
||||
html_print_submit_button(
|
||||
__('Update'),
|
||||
'update_button',
|
||||
false,
|
||||
[ 'icon' => 'update' ],
|
||||
true
|
||||
)
|
||||
$action_btns
|
||||
);
|
||||
|
||||
echo '</form>';
|
||||
|
@ -186,10 +114,8 @@ $handle_test_js = "var handleTest = function (event) {
|
|||
hideLoadingImage();
|
||||
showMessage();
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
$('#button-test-ehorus').click(handleTest);";
|
||||
}";
|
||||
|
||||
echo $handle_test_js;
|
||||
echo '</script>';
|
||||
|
||||
|
|
|
@ -1,175 +0,0 @@
|
|||
#!/bin/bash
|
||||
# Copyright (c) 2005-2023 Pandora FMS
|
||||
#
|
||||
# /etc/init.d/websocket
|
||||
#
|
||||
# System startup script for Pandora FMS Console websocket engine
|
||||
#
|
||||
# Comments to support chkconfig on RedHat Linux
|
||||
# chkconfig: 2345 90 10
|
||||
# description: Pandora FMS Console webscoket engine startup script
|
||||
#
|
||||
# Comments to support LSB init script conventions
|
||||
### BEGIN INIT INFO
|
||||
# Provides: websocket
|
||||
# Required-Start: $syslog cron
|
||||
# Should-Start: $network cron mysql
|
||||
# Required-Stop: $syslog
|
||||
# Should-Stop: $network
|
||||
# Default-Start: 2 3 5
|
||||
# Default-Stop: 0 1 6
|
||||
# Short-Description: Pandora FMS Console websocket engine startup script
|
||||
# Description: Pandora FMS Console websocket engine startup script
|
||||
### END INIT INFO
|
||||
|
||||
if [ -x /lib/lsb/init-functions ]; then
|
||||
. /lib/lsb/init-functions
|
||||
fi
|
||||
|
||||
# If you want to run several pandora Console Websocket engines in this machine, just copy
|
||||
# this script to another name, editing PANDORA_HOME to the new .conf
|
||||
|
||||
export WS_ENGINE="/var/www/html/pandora_console/ws.php"
|
||||
export PHP=/usr/bin/php
|
||||
export WS_LOG="/var/log/pandora/web_socket.log"
|
||||
export GOTTY="/tmp/"
|
||||
|
||||
# Environment variables
|
||||
if [[ -z ${PANDORA_RB_PRODUCT_NAME} ]]; then
|
||||
PANDORA_RB_PRODUCT_NAME="Pandora FMS"
|
||||
fi
|
||||
if [[ -z ${PANDORA_RB_COPYRIGHT_NOTICE} ]]; then
|
||||
PANDORA_RB_COPYRIGHT_NOTICE="Pandora FMS"
|
||||
fi
|
||||
|
||||
export PANDORA_RB_PRODUCT_NAME=$PANDORA_RB_PRODUCT_NAME
|
||||
export PANDORA_RB_COPYRIGHT_NOTICE=$PANDORA_RB_COPYRIGHT_NOTICE
|
||||
|
||||
# Uses a wait limit before sending a KILL signal, before trying to stop
|
||||
# Pandora FMS Console Websocket engine nicely. Some big systems need some time before close
|
||||
# all pending tasks / threads.
|
||||
|
||||
export MAXWAIT=60
|
||||
|
||||
# Check for SUSE status scripts
|
||||
if [ -f /etc/rc.status ]
|
||||
then
|
||||
. /etc/rc.status
|
||||
rc_reset
|
||||
else
|
||||
# Define part of rc functions for non-suse systems
|
||||
function rc_status () {
|
||||
RETVAL=$?
|
||||
case $1 in
|
||||
-v) RETVAL=0;;
|
||||
esac
|
||||
}
|
||||
function rc_exit () { exit $RETVAL; }
|
||||
function rc_failed () { RETVAL=${1:-1}; }
|
||||
RETVAL=0
|
||||
fi
|
||||
|
||||
# This function replace pidof, not working in the same way in different linux distros
|
||||
|
||||
function pidof_pandora () {
|
||||
# This sets COLUMNS to XXX chars, because if command is run
|
||||
# in a "strech" term, ps aux don't report more than COLUMNS
|
||||
# characters and this will not work.
|
||||
COLUMNS=300
|
||||
PANDORA_PID=`ps aux | grep "$PHP $WS_ENGINE" | grep -v grep | tail -1 | awk '{ print $2 }'`
|
||||
echo $PANDORA_PID
|
||||
}
|
||||
|
||||
# Main script
|
||||
|
||||
if [ ! -x $GOTTY ]
|
||||
then
|
||||
echo "Gotty not found in $GOTTY"
|
||||
rc_failed 5 # program is not installed
|
||||
rc_exit
|
||||
fi
|
||||
|
||||
if [ ! -f $PHP ]
|
||||
then
|
||||
echo "$PHP not found, please install version >= 7.0"
|
||||
rc_failed 5 # program is not installed
|
||||
rc_exit
|
||||
fi
|
||||
|
||||
case "$1" in
|
||||
start)
|
||||
PANDORA_PID=`pidof_pandora`
|
||||
if [ ! -z "$PANDORA_PID" ]
|
||||
then
|
||||
echo "$PANDORA_RB_PRODUCT_NAME Console Websocket engine is currently running on this machine with PID ($PANDORA_PID)."
|
||||
rc_exit # running start on a service already running
|
||||
fi
|
||||
|
||||
export PERL_LWP_SSL_VERIFY_HOSTNAME=0
|
||||
$PHP $WS_ENGINE >> $WS_LOG 2>&1 &
|
||||
sleep 1
|
||||
|
||||
PANDORA_PID=`pidof_pandora`
|
||||
|
||||
if [ ! -z "$PANDORA_PID" ]
|
||||
then
|
||||
echo "$PANDORA_RB_PRODUCT_NAME Console Websocket engine is now running with PID $PANDORA_PID"
|
||||
rc_status -v
|
||||
else
|
||||
echo "Cannot start $PANDORA_RB_PRODUCT_NAME Console Websocket engine. Aborted."
|
||||
echo "Check $PANDORA_RB_PRODUCT_NAME log files at $WS_LOG"
|
||||
rc_failed 7 # program is not running
|
||||
fi
|
||||
;;
|
||||
|
||||
stop)
|
||||
PANDORA_PID=`pidof_pandora`
|
||||
if [ -z "$PANDORA_PID" ]
|
||||
then
|
||||
echo "$PANDORA_RB_PRODUCT_NAME Console Websocket engine is not running, cannot stop it."
|
||||
rc_exit # running stop on a service already stopped or not running
|
||||
else
|
||||
echo "Stopping $PANDORA_RB_PRODUCT_NAME Console Websocket engine"
|
||||
kill $PANDORA_PID > /dev/null 2>&1
|
||||
COUNTER=0
|
||||
|
||||
while [ $COUNTER -lt $MAXWAIT ]
|
||||
do
|
||||
_PID=`pidof_pandora`
|
||||
if [ "$_PID" != "$PANDORA_PID" ]
|
||||
then
|
||||
COUNTER=$MAXWAIT
|
||||
fi
|
||||
COUNTER=`expr $COUNTER + 1`
|
||||
sleep 1
|
||||
done
|
||||
|
||||
# Send a KILL -9 signal to process, if it's alive after 60secs, we need
|
||||
# to be sure is really dead, and not pretending...
|
||||
if [ "$_PID" = "$PANDORA_PID" ]
|
||||
then
|
||||
kill -9 $PANDORA_PID > /dev/null 2>&1
|
||||
fi
|
||||
rc_status -v
|
||||
fi
|
||||
;;
|
||||
status)
|
||||
PANDORA_PID=`pidof_pandora`
|
||||
if [ -z "$PANDORA_PID" ]
|
||||
then
|
||||
echo "$PANDORA_RB_PRODUCT_NAME Console Websocket engine is not running."
|
||||
rc_failed 7 # program is not running
|
||||
else
|
||||
echo "$PANDORA_RB_PRODUCT_NAME Console Websocket engine is running with PID $PANDORA_PID."
|
||||
rc_status
|
||||
fi
|
||||
;;
|
||||
force-reload|restart)
|
||||
$0 stop
|
||||
$0 start
|
||||
;;
|
||||
*)
|
||||
echo "Usage: $0 { start | stop | restart | status }"
|
||||
exit 1
|
||||
esac
|
||||
rc_exit
|
Loading…
Reference in New Issue