2019-01-30 16:18:44 +01:00
|
|
|
<?php
|
2019-03-04 13:12:01 +01:00
|
|
|
/**
|
|
|
|
* ______ ___ _______ _______ ________
|
|
|
|
* | __ \.-----.--.--.--| |.-----.----.-----. | ___| | | __|
|
|
|
|
* | __/| _ | | _ || _ | _| _ | | ___| |__ |
|
|
|
|
* |___| |___._|__|__|_____||_____|__| |___._| |___| |__|_|__|_______|
|
|
|
|
*
|
|
|
|
* ============================================================================
|
2020-11-27 13:52:35 +01:00
|
|
|
* Copyright (c) 2005-2021 Artica Soluciones Tecnologicas
|
2019-03-04 13:12:01 +01:00
|
|
|
* Please see http://pandorafms.org for full contribution list
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation for version 2.
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
* ============================================================================
|
|
|
|
*/
|
2016-05-04 19:19:07 +02:00
|
|
|
|
|
|
|
global $config;
|
|
|
|
|
2019-01-30 16:18:44 +01:00
|
|
|
check_login();
|
2016-05-04 19:19:07 +02:00
|
|
|
|
2016-05-05 18:26:06 +02:00
|
|
|
if (! check_acl($config['id_user'], 0, 'PM') && ! is_user_admin($config['id_user'])) {
|
2022-02-01 13:39:18 +01:00
|
|
|
db_pandora_audit(
|
|
|
|
AUDIT_LOG_ACL_VIOLATION,
|
|
|
|
'Trying to access Setup Management'
|
|
|
|
);
|
2019-01-30 16:18:44 +01:00
|
|
|
include 'general/noaccess.php';
|
|
|
|
return;
|
2016-05-04 19:19:07 +02:00
|
|
|
}
|
|
|
|
|
2019-03-11 09:37:08 +01:00
|
|
|
// Check custom field.
|
2016-05-09 19:22:10 +02:00
|
|
|
$custom_field = db_get_value('name', 'tagent_custom_fields', 'name', $config['ehorus_custom_field']);
|
|
|
|
$custom_field_exists = !empty($custom_field);
|
|
|
|
$custom_field_created = null;
|
|
|
|
if ($config['ehorus_enabled'] && !$custom_field_exists) {
|
2019-01-30 16:18:44 +01:00
|
|
|
$values = [
|
|
|
|
'name' => $config['ehorus_custom_field'],
|
|
|
|
'display_on_front' => 1,
|
|
|
|
];
|
|
|
|
$result = (bool) db_process_sql_insert('tagent_custom_fields', $values);
|
|
|
|
$custom_field_exists = $custom_field_created = $result;
|
2016-05-04 19:19:07 +02:00
|
|
|
}
|
|
|
|
|
2019-03-11 09:37:08 +01:00
|
|
|
// Enable table.
|
2016-05-05 18:26:06 +02:00
|
|
|
$table_enable = new StdClass();
|
2019-01-30 16:18:44 +01:00
|
|
|
$table_enable->data = [];
|
2016-05-05 18:26:06 +02:00
|
|
|
$table_enable->width = '100%';
|
|
|
|
$table_enable->id = 'ehorus-enable-setup';
|
|
|
|
$table_enable->class = 'databox filters';
|
|
|
|
$table_enable->size['name'] = '30%';
|
|
|
|
$table_enable->style['name'] = 'font-weight: bold';
|
|
|
|
|
2019-03-11 09:37:08 +01:00
|
|
|
// Enable eHorus.
|
2019-01-30 16:18:44 +01:00
|
|
|
$row = [];
|
2019-05-14 15:34:22 +02:00
|
|
|
$row['name'] = __('Enable eHorus');
|
2019-03-11 09:37:08 +01:00
|
|
|
$row['control'] = html_print_checkbox_switch('ehorus_enabled', 1, $config['ehorus_enabled'], true);
|
2016-05-05 18:26:06 +02:00
|
|
|
$table_enable->data['ehorus_enabled'] = $row;
|
|
|
|
|
2019-03-11 09:37:08 +01:00
|
|
|
// Remote config table.
|
2016-05-05 18:26:06 +02:00
|
|
|
$table_remote = new StdClass();
|
2019-01-30 16:18:44 +01:00
|
|
|
$table_remote->data = [];
|
2016-05-05 18:26:06 +02:00
|
|
|
$table_remote->width = '100%';
|
|
|
|
$table_remote->styleTable = 'margin-bottom: 10px;';
|
|
|
|
$table_remote->id = 'ehorus-remote-setup';
|
|
|
|
$table_remote->class = 'databox filters';
|
|
|
|
$table_remote->size['name'] = '30%';
|
|
|
|
$table_remote->style['name'] = 'font-weight: bold';
|
2016-05-04 19:19:07 +02:00
|
|
|
|
2019-05-13 15:15:14 +02:00
|
|
|
// Enable eHorus user configuration.
|
|
|
|
$row = [];
|
2019-05-28 17:19:13 +02:00
|
|
|
$row['name'] = ('eHorus configuration at user level');
|
2019-05-28 13:14:42 +02:00
|
|
|
$row['control'] = html_print_checkbox_switch('ehorus_user_level_conf', 1, $config['ehorus_user_level_conf'], true);
|
|
|
|
$table_remote->data['ehorus_user_level_conf'] = $row;
|
2019-05-13 15:15:14 +02:00
|
|
|
|
2019-03-11 09:37:08 +01:00
|
|
|
// User.
|
2019-01-30 16:18:44 +01:00
|
|
|
$row = [];
|
2016-05-04 19:19:07 +02:00
|
|
|
$row['name'] = __('User');
|
|
|
|
$row['control'] = html_print_input_text('ehorus_user', $config['ehorus_user'], '', 30, 100, true);
|
2016-05-05 18:26:06 +02:00
|
|
|
$table_remote->data['ehorus_user'] = $row;
|
2016-05-04 19:19:07 +02:00
|
|
|
|
2019-03-11 09:37:08 +01:00
|
|
|
// Pass.
|
2019-01-30 16:18:44 +01:00
|
|
|
$row = [];
|
2016-05-04 19:19:07 +02:00
|
|
|
$row['name'] = __('Password');
|
|
|
|
$row['control'] = html_print_input_password('ehorus_pass', io_output_password($config['ehorus_pass']), '', 30, 100, true);
|
2020-09-29 10:12:49 +02:00
|
|
|
$row['control'] .= ui_print_reveal_password('ehorus_pass', true);
|
2016-05-05 18:26:06 +02:00
|
|
|
$table_remote->data['ehorus_pass'] = $row;
|
2016-05-04 19:19:07 +02:00
|
|
|
|
2019-03-11 09:37:08 +01:00
|
|
|
// Directory hostname.
|
2019-01-30 16:18:44 +01:00
|
|
|
$row = [];
|
2016-05-04 19:19:07 +02:00
|
|
|
$row['name'] = __('API Hostname');
|
|
|
|
$row['control'] = html_print_input_text('ehorus_hostname', $config['ehorus_hostname'], '', 30, 100, true);
|
2016-05-05 18:26:06 +02:00
|
|
|
$table_remote->data['ehorus_hostname'] = $row;
|
2016-05-04 19:19:07 +02:00
|
|
|
|
2019-03-11 09:37:08 +01:00
|
|
|
// Directory port.
|
2019-01-30 16:18:44 +01:00
|
|
|
$row = [];
|
2016-05-04 19:19:07 +02:00
|
|
|
$row['name'] = __('API Port');
|
|
|
|
$row['control'] = html_print_input_text('ehorus_port', $config['ehorus_port'], '', 6, 100, true);
|
2016-05-05 18:26:06 +02:00
|
|
|
$table_remote->data['ehorus_port'] = $row;
|
2016-05-04 19:19:07 +02:00
|
|
|
|
2019-03-11 09:37:08 +01:00
|
|
|
// Request timeout.
|
2019-01-30 16:18:44 +01:00
|
|
|
$row = [];
|
2016-05-04 19:19:07 +02:00
|
|
|
$row['name'] = __('Request timeout');
|
|
|
|
$row['control'] = html_print_input_text('ehorus_req_timeout', $config['ehorus_req_timeout'], '', 3, 10, true);
|
2016-05-05 18:26:06 +02:00
|
|
|
$table_remote->data['ehorus_req_timeout'] = $row;
|
|
|
|
|
2019-03-11 09:37:08 +01:00
|
|
|
// Test.
|
2019-01-30 16:18:44 +01:00
|
|
|
$row = [];
|
2016-05-05 18:26:06 +02:00
|
|
|
$row['name'] = __('Test');
|
|
|
|
$row['control'] = html_print_button(__('Start'), 'test-ehorus', false, '', 'class="sub next"', true);
|
2021-03-11 15:40:23 +01:00
|
|
|
$row['control'] .= '<span id="test-ehorus-spinner" class="invisible"> '.html_print_image('images/spinner.gif', true).'</span>';
|
|
|
|
$row['control'] .= '<span id="test-ehorus-success" class="invisible"> '.html_print_image('images/status_sets/default/severity_normal.png', true).'</span>';
|
|
|
|
$row['control'] .= '<span id="test-ehorus-failure" class="invisible"> '.html_print_image('images/status_sets/default/severity_critical.png', true).'</span>';
|
|
|
|
$row['control'] .= ' <span id="test-ehorus-message" class="invisible"></span>';
|
2016-05-05 18:26:06 +02:00
|
|
|
$table_remote->data['ehorus_test'] = $row;
|
2019-05-13 15:00:29 +02:00
|
|
|
|
2019-03-11 09:37:08 +01:00
|
|
|
// Print.
|
2021-03-11 15:40:23 +01:00
|
|
|
echo '<div class="center pdd_b_20px">';
|
2016-05-09 19:22:10 +02:00
|
|
|
echo '<a target="_blank" rel="noopener noreferrer" href="http://ehorus.com">';
|
2022-01-17 10:22:30 +01:00
|
|
|
if ($config['style'] === 'pandora_black' && !is_metaconsole()) {
|
2022-03-09 17:20:24 +01:00
|
|
|
html_print_image(
|
|
|
|
'include/ehorus/images/ehorus-logo.png',
|
|
|
|
false,
|
|
|
|
['class' => 'w400px']
|
|
|
|
);
|
2021-06-09 15:12:47 +02:00
|
|
|
} else {
|
2022-03-09 17:20:24 +01:00
|
|
|
html_print_image(
|
|
|
|
'include/ehorus/images/ehorus-logo-grey.png',
|
|
|
|
false,
|
|
|
|
['class' => 'w400px']
|
|
|
|
);
|
2021-06-09 15:12:47 +02:00
|
|
|
}
|
|
|
|
|
2016-05-09 19:22:10 +02:00
|
|
|
echo '</a>';
|
|
|
|
echo '<br />';
|
2021-03-11 15:40:23 +01:00
|
|
|
echo '<div class="ehorus_title">';
|
2016-05-09 19:22:10 +02:00
|
|
|
echo __('Remote Management System');
|
|
|
|
echo '</div>';
|
2017-11-13 11:32:14 +01:00
|
|
|
echo '<a target="_blank" rel="noopener noreferrer" href="https://ehorus.com">';
|
|
|
|
echo 'https://ehorus.com';
|
2016-05-09 19:22:10 +02:00
|
|
|
echo '</a>';
|
|
|
|
echo '</div>';
|
|
|
|
|
|
|
|
if ($custom_field_created !== null) {
|
2019-01-30 16:18:44 +01:00
|
|
|
ui_print_result_message($custom_field_created, __('Custom field eHorusID created'), __('Error creating custom field'));
|
2016-05-05 18:26:06 +02:00
|
|
|
}
|
2019-01-30 16:18:44 +01:00
|
|
|
|
2016-05-09 19:22:10 +02:00
|
|
|
if ($custom_field_created) {
|
2019-01-30 16:18:44 +01:00
|
|
|
$info_messsage = __('eHorus has his own agent identifiers');
|
|
|
|
$info_messsage .= '. '.__('To store them, it will be necessary to use an agent custom field');
|
|
|
|
$info_messsage .= '.<br />'.__('Possibly the eHorus id will have to be filled in by hand for every agent').'.';
|
|
|
|
ui_print_info_message($info_messsage);
|
2016-05-05 18:26:06 +02:00
|
|
|
}
|
|
|
|
|
2016-05-09 19:22:10 +02:00
|
|
|
if ($config['ehorus_enabled'] && !$custom_field_exists) {
|
2019-01-30 16:18:44 +01:00
|
|
|
$error_message = __('The custom field does not exists already');
|
|
|
|
ui_print_error_message($error_message);
|
2016-05-09 19:22:10 +02:00
|
|
|
}
|
|
|
|
|
2019-05-10 15:00:21 +02:00
|
|
|
echo "<form method='post'>";
|
2019-03-11 09:37:08 +01:00
|
|
|
// Form enable.
|
2019-05-10 15:00:21 +02:00
|
|
|
echo '<div id="form_enable">';
|
2016-05-09 19:22:10 +02:00
|
|
|
html_print_input_hidden('update_config', 1);
|
|
|
|
html_print_table($table_enable);
|
2019-05-10 15:00:21 +02:00
|
|
|
echo '</div>';
|
2016-05-09 19:22:10 +02:00
|
|
|
|
2019-03-11 09:37:08 +01:00
|
|
|
// Form remote.
|
2019-05-10 15:00:21 +02:00
|
|
|
echo '<div id="form_remote">';
|
2019-01-30 16:18:44 +01:00
|
|
|
echo '<fieldset>';
|
|
|
|
echo '<legend>'.__('eHorus API').'</legend>';
|
|
|
|
html_print_input_hidden('update_config', 1);
|
|
|
|
html_print_table($table_remote);
|
2019-05-14 15:34:22 +02:00
|
|
|
|
2019-05-13 15:00:29 +02:00
|
|
|
echo '</fieldset>';
|
2019-05-14 15:34:22 +02:00
|
|
|
echo '</div>';
|
|
|
|
echo '<div class="action-buttons" style="width: '.$table_remote->width.'">';
|
|
|
|
html_print_submit_button(__('Update'), 'update_button', false, 'class="sub upd"');
|
2019-05-10 15:00:21 +02:00
|
|
|
echo '</div>';
|
2019-01-30 16:18:44 +01:00
|
|
|
echo '</form>';
|
2016-05-05 18:26:06 +02:00
|
|
|
|
2016-05-04 19:19:07 +02:00
|
|
|
?>
|
|
|
|
|
|
|
|
<script type="text/javascript">
|
2019-05-28 17:19:13 +02:00
|
|
|
|
|
|
|
if(!$('input:checkbox[name="ehorus_enabled"]').is(':checked'))
|
|
|
|
{
|
|
|
|
$('#form_remote').hide();
|
|
|
|
}
|
|
|
|
|
|
|
|
if($('input:checkbox[name="ehorus_user_level_conf"]').is(':checked'))
|
|
|
|
{
|
|
|
|
$('#ehorus-remote-setup-ehorus_user').hide();
|
|
|
|
$('#ehorus-remote-setup-ehorus_pass').hide()
|
2019-05-10 15:00:21 +02:00
|
|
|
}
|
2019-05-28 17:19:13 +02:00
|
|
|
|
|
|
|
|
2019-05-10 15:00:21 +02:00
|
|
|
$('#form_enable').css('margin-bottom','20px');
|
2019-01-30 16:18:44 +01:00
|
|
|
var showFields = function () {
|
2019-05-10 15:00:21 +02:00
|
|
|
$('#form_remote').show();
|
2019-01-30 16:18:44 +01:00
|
|
|
}
|
|
|
|
var hideFields = function () {
|
2019-05-10 15:00:21 +02:00
|
|
|
$('#form_remote').hide();
|
2019-01-30 16:18:44 +01:00
|
|
|
}
|
2019-05-28 17:19:13 +02:00
|
|
|
|
|
|
|
var hideUserPass = function () {
|
|
|
|
$('#ehorus-remote-setup-ehorus_user').hide();
|
|
|
|
$('#ehorus-remote-setup-ehorus_pass').hide();
|
|
|
|
}
|
|
|
|
|
|
|
|
var showUserPass = function () {
|
|
|
|
$('#ehorus-remote-setup-ehorus_user').show();
|
|
|
|
$('#ehorus-remote-setup-ehorus_pass').show();
|
|
|
|
}
|
|
|
|
|
2019-01-30 16:18:44 +01:00
|
|
|
var handleEnable = function (event) {
|
2019-03-11 09:37:08 +01:00
|
|
|
var is_checked = $('input:checkbox[name="ehorus_enabled"]').is(':checked');
|
|
|
|
if (event.target.value == '1' && is_checked) {
|
|
|
|
showFields();
|
2019-05-10 12:26:09 +02:00
|
|
|
$('input:checkbox[name="ehorus_enabled"]').attr('checked', true);
|
2019-03-11 09:37:08 +01:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
hideFields();
|
2019-05-10 12:26:09 +02:00
|
|
|
$('input:checkbox[name="ehorus_enabled"]').attr('checked', false);
|
2019-03-11 09:37:08 +01:00
|
|
|
};
|
2019-01-30 16:18:44 +01:00
|
|
|
}
|
2019-05-28 17:19:13 +02:00
|
|
|
|
|
|
|
var handleUserLevel = function(event) {
|
|
|
|
var is_checked = $('input:checkbox[name="ehorus_enabled"]').is(':checked');
|
|
|
|
var is_checked_userlevel = $('input:checkbox[name="ehorus_user_level_conf"]').is(':checked');
|
|
|
|
|
|
|
|
if (event.target.value == '1' && is_checked && !is_checked_userlevel) {
|
|
|
|
showUserPass();
|
|
|
|
$('input:checkbox[name="ehorus_user_level_conf"]').attr('checked', true);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
hideUserPass();
|
|
|
|
$('input:checkbox[name="ehorus_user_level_conf"]').attr('checked', false);
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2019-03-04 13:12:01 +01:00
|
|
|
$('input:checkbox[name="ehorus_enabled"]').change(handleEnable);
|
2019-05-28 17:19:13 +02:00
|
|
|
$('input:checkbox[name="ehorus_user_level_conf"]').change(handleUserLevel);
|
|
|
|
|
2019-01-30 16:18:44 +01:00
|
|
|
var handleTest = function (event) {
|
|
|
|
var user = $('input#text-ehorus_user').val();
|
|
|
|
var pass = $('input#password-ehorus_pass').val();
|
|
|
|
var host = $('input#text-ehorus_hostname').val();
|
|
|
|
var port = $('input#text-ehorus_port').val();
|
|
|
|
var timeout = Number.parseInt($('input#text-ehorus_req_timeout').val(), 10);
|
2019-05-28 17:19:13 +02:00
|
|
|
var is_checked_user_level = $('input:checkbox[name="ehorus_user_level_conf"]').is(':checked');
|
|
|
|
|
2019-01-30 16:18:44 +01:00
|
|
|
var timeoutMessage = '<?php echo __('Connection timeout'); ?>';
|
|
|
|
var badRequestMessage = '<?php echo __('Empty user or password'); ?>';
|
|
|
|
var notFoundMessage = '<?php echo __('User not found'); ?>';
|
|
|
|
var invalidPassMessage = '<?php echo __('Invalid password'); ?>';
|
|
|
|
|
|
|
|
var hideLoadingImage = function () {
|
|
|
|
$('span#test-ehorus-spinner').hide();
|
|
|
|
}
|
|
|
|
var showLoadingImage = function () {
|
|
|
|
$('span#test-ehorus-spinner').show();
|
|
|
|
}
|
|
|
|
var hideSuccessImage = function () {
|
|
|
|
$('span#test-ehorus-success').hide();
|
|
|
|
}
|
|
|
|
var showSuccessImage = function () {
|
|
|
|
$('span#test-ehorus-success').show();
|
|
|
|
}
|
|
|
|
var hideFailureImage = function () {
|
|
|
|
$('span#test-ehorus-failure').hide();
|
|
|
|
}
|
|
|
|
var showFailureImage = function () {
|
|
|
|
$('span#test-ehorus-failure').show();
|
|
|
|
}
|
|
|
|
var hideMessage = function () {
|
|
|
|
$('span#test-ehorus-message').hide();
|
|
|
|
}
|
|
|
|
var showMessage = function () {
|
|
|
|
$('span#test-ehorus-message').show();
|
|
|
|
}
|
|
|
|
var changeTestMessage = function (message) {
|
|
|
|
$('span#test-ehorus-message').text(message);
|
|
|
|
}
|
|
|
|
|
|
|
|
hideSuccessImage();
|
|
|
|
hideFailureImage();
|
|
|
|
hideMessage();
|
|
|
|
showLoadingImage();
|
2019-05-28 17:19:13 +02:00
|
|
|
|
2019-01-30 16:18:44 +01:00
|
|
|
$.ajax({
|
|
|
|
url: 'https://' + host + ':' + port + '/login',
|
|
|
|
type: 'POST',
|
|
|
|
dataType: 'json',
|
|
|
|
timeout: timeout ? timeout * 1000 : 0,
|
|
|
|
data: {
|
|
|
|
user: user,
|
|
|
|
pass: pass
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.done(function(data, textStatus, xhr) {
|
|
|
|
showSuccessImage();
|
|
|
|
})
|
|
|
|
.fail(function(xhr, textStatus, errorThrown) {
|
2019-05-28 17:19:13 +02:00
|
|
|
if((xhr.status === 400 || xhr.status === 403) && is_checked_user_level)
|
|
|
|
{
|
|
|
|
showSuccessImage();
|
|
|
|
return;
|
|
|
|
}else if (xhr.status === 400) {
|
2019-01-30 16:18:44 +01:00
|
|
|
changeTestMessage(badRequestMessage);
|
|
|
|
}
|
|
|
|
else if (xhr.status === 401 || xhr.status === 403) {
|
|
|
|
changeTestMessage(invalidPassMessage);
|
|
|
|
}
|
|
|
|
else if (xhr.status === 404) {
|
|
|
|
changeTestMessage(notFoundMessage);
|
|
|
|
}
|
|
|
|
else if (errorThrown === 'timeout') {
|
|
|
|
changeTestMessage(timeoutMessage);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
changeTestMessage(errorThrown);
|
|
|
|
}
|
2019-05-28 17:19:13 +02:00
|
|
|
|
|
|
|
showFailureImage();
|
2019-01-30 16:18:44 +01:00
|
|
|
showMessage();
|
|
|
|
})
|
|
|
|
.always(function(xhr, textStatus) {
|
|
|
|
hideLoadingImage();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
$('input#button-test-ehorus').click(handleTest);
|
2019-05-28 17:19:13 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
2016-05-04 19:19:07 +02:00
|
|
|
</script>
|