diff --git a/pandora_console/godmode/setup/setup_ehorus.php b/pandora_console/godmode/setup/setup_ehorus.php index 833648b27b..86df28528b 100644 --- a/pandora_console/godmode/setup/setup_ehorus.php +++ b/pandora_console/godmode/setup/setup_ehorus.php @@ -20,89 +20,265 @@ global $config; check_login (); -if (! check_acl($config['id_user'], 0, "PM") && ! is_user_admin($config['id_user'])) { - db_pandora_audit("ACL Violation", "Trying to access Setup Management"); - require ("general/noaccess.php"); +if (! check_acl($config['id_user'], 0, 'PM') && ! is_user_admin($config['id_user'])) { + db_pandora_audit('ACL Violation', 'Trying to access Setup Management'); + require ('general/noaccess.php'); return; } -$table = new StdClass(); -$table->data = array(); -$table->width = '100%'; -$table->id = 'ehorus-setup'; -$table->class = 'databox filters'; -$table->size['name'] = '30%'; -$table->style['name'] = "font-weight: bold"; - -if (!$config['ehorus_enabled']) { - $table->rowstyle = array(); - $table->rowstyle['ehorus_user'] = 'display: none'; - $table->rowstyle['ehorus_pass'] = 'display: none'; - $table->rowstyle['ehorus_hostname'] = 'display: none'; - $table->rowstyle['ehorus_port'] = 'display: none'; - $table->rowstyle['ehorus_req_timeout'] = 'display: none'; +// Check custom field +$custom_field_exists = false; +if (!empty($config['ehorus_custom_field'])) { + $custom_field = db_get_value('name', 'tagent_custom_fields', 'name', $config['ehorus_custom_field']); + $custom_field_exists = !empty($custom_field); } +$create_custom_field = (bool) get_parameter('create_custom_field'); +if ($create_custom_field) { + $result = (bool) db_process_sql_insert('tagent_custom_fields', array('name' => $config['ehorus_custom_field'])); + ui_print_result_message($result, __('Custom field for eHorus ID created'), __('Error creating custom field')); + $custom_field_exists = $result; +} + +/* Enable table */ + +$table_enable = new StdClass(); +$table_enable->data = array(); +$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'; // Enable eHorus $row = array(); $row['name'] = __('Enable eHorus'); $row['control'] = __('Yes').' '.html_print_radio_button ('ehorus_enabled', 1, '', $config['ehorus_enabled'], true).'  '; $row['control'] .= __('No').' '.html_print_radio_button ('ehorus_enabled', 0, '', $config['ehorus_enabled'], true); -$table->data['ehorus_enabled'] = $row; +$row['button'] = html_print_submit_button(__('Update'), 'update_button', false, 'class="sub upd"', true); +$table_enable->data['ehorus_enabled'] = $row; + +/* Agents config table */ + +$table_agents = new StdClass(); +$table_agents->data = array(); +$table_agents->width = '100%'; +$table_agents->styleTable = 'margin-bottom: 10px;'; +$table_agents->id = 'ehorus-agents-setup'; +$table_agents->class = 'databox filters'; +$table_agents->size['name'] = '30%'; +$table_agents->style['name'] = 'font-weight: bold'; + +// Custom Fields +$row = array(); +$row['name'] = __('Custom field name'); +$row['control'] = html_print_input_text('ehorus_custom_field', $config['ehorus_custom_field'], '', 30, 100, true); +$row['button'] = html_print_submit_button(__('Use'), 'use_custom_field', false, 'class="sub upd"', true); +$row['button'] .= ' ' . html_print_submit_button(__('Create and use'), 'create_custom_field', false, 'class="sub upd"', true); +$row['button'] .= ui_print_help_tip(__('The previous item will not be deleted or modified by performing this operations'), true); +$table_agents->data['ehorus_custom_field'] = $row; + +/* Remote config table */ + +$table_remote = new StdClass(); +$table_remote->data = array(); +$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'; // User $row = array(); $row['name'] = __('User'); $row['control'] = html_print_input_text('ehorus_user', $config['ehorus_user'], '', 30, 100, true); -$table->data['ehorus_user'] = $row; +$table_remote->data['ehorus_user'] = $row; // Pass $row = array(); $row['name'] = __('Password'); $row['control'] = html_print_input_password('ehorus_pass', io_output_password($config['ehorus_pass']), '', 30, 100, true); -$table->data['ehorus_pass'] = $row; +$table_remote->data['ehorus_pass'] = $row; // Directory hostname $row = array(); $row['name'] = __('API Hostname'); $row['control'] = html_print_input_text('ehorus_hostname', $config['ehorus_hostname'], '', 30, 100, true); $row['control'] .= ui_print_help_tip(__('Hostname of the eHorus API') . '. ' . __('Without protocol and port') . '. ' . __('e.g., switch.ehorus.com'), true); -$table->data['ehorus_hostname'] = $row; +$table_remote->data['ehorus_hostname'] = $row; // Directory port $row = array(); $row['name'] = __('API Port'); $row['control'] = html_print_input_text('ehorus_port', $config['ehorus_port'], '', 6, 100, true); $row['control'] .= ui_print_help_tip(__('e.g., 18080'), true); -$table->data['ehorus_port'] = $row; +$table_remote->data['ehorus_port'] = $row; // Request timeout $row = array(); $row['name'] = __('Request timeout'); $row['control'] = html_print_input_text('ehorus_req_timeout', $config['ehorus_req_timeout'], '', 3, 10, true); $row['control'] .= ui_print_help_tip(__('Time in seconds to set the maximum time of the requests to the eHorus API') . '. ' . __('0 to disable'), true); -$table->data['ehorus_req_timeout'] = $row; +$table_remote->data['ehorus_req_timeout'] = $row; -// Form -echo '
'; +// Test +$row = array(); +$row['name'] = __('Test'); +$row['control'] = html_print_button(__('Start'), 'test-ehorus', false, '', 'class="sub next"', true); +$row['control'] .= ''; +$row['control'] .= ''; +$row['control'] .= ''; +$row['control'] .= ' '; +$table_remote->data['ehorus_test'] = $row; + +/* Print */ + +// Form enable +echo ''; +if (!$config['ehorus_enabled']) { + $info_page = "http://ehorus.com/"; + $link = 'this'; + $info_messsage = __('eHorus is a web based remote management system which allows you to easily connect to machines that have internet connection'); + $info_messsage .= '. ' . __('Forget about firewalls and proxies'); + $info_messsage .= '. ' . sprintf(__('Check %s for more info'), $link) . '.'; + ui_print_info_message($info_messsage); +} html_print_input_hidden('update_config', 1); -html_print_table($table); -echo '
'; -html_print_submit_button(__('Update'), 'update_button', false, 'class="sub upd"'); -echo '
'; +html_print_table($table_enable); echo '
'; + +// Form agents +if ($config['ehorus_enabled']) { + echo '
'; + $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 .= '.
' . __('Possibly the eHorus id will have to be filled by hand for every agent') . '.'; + ui_print_info_message($info_messsage); + + if (!$custom_field_exists) { + $error_message = __('The custom field does not exists already'); + ui_print_error_message($error_message); + } + echo "
"; + echo "" . __('Pandora agents') . ""; + html_print_input_hidden('update_config', 1); + html_print_table($table_agents); + echo "
"; + echo '
'; +} + +// Form remote +if ($config['ehorus_enabled']) { + echo '
'; + echo "
"; + echo "" . __('eHorus API') . ""; + html_print_input_hidden ('update_config', 1); + html_print_table($table_remote); + echo '
'; + html_print_submit_button(__('Update'), 'update_button', false, 'class="sub upd"'); + echo '
'; + echo "
"; + echo '
'; +} + ?> diff --git a/pandora_console/include/functions_config.php b/pandora_console/include/functions_config.php index 373cba3d51..31ae6ffbe0 100644 --- a/pandora_console/include/functions_config.php +++ b/pandora_console/include/functions_config.php @@ -637,18 +637,20 @@ function config_update_config () { $error_update[] = __('Delay'); break; case 'ehorus': - if (!config_update_value('ehorus_enabled', (int) get_parameter('ehorus_enabled'))) + if (!config_update_value('ehorus_enabled', (int) get_parameter('ehorus_enabled', $config['ehorus_enabled']))) $error_update[] = __('Enable eHorus'); - if (!config_update_value('ehorus_user', get_parameter('ehorus_user'))) + if (!config_update_value('ehorus_user', (string) get_parameter('ehorus_user', $config['ehorus_user']))) $error_update[] = __('eHorus user'); - if (!config_update_value('ehorus_pass', io_input_password(get_parameter('ehorus_pass')))) + if (!config_update_value('ehorus_pass', io_input_password((string) get_parameter('ehorus_pass', $config['ehorus_pass'])))) $error_update[] = __('eHorus password'); - if (!config_update_value('ehorus_hostname', get_parameter('ehorus_hostname'))) + if (!config_update_value('ehorus_hostname', (string) get_parameter('ehorus_hostname', $config['ehorus_hostname']))) $error_update[] = __('eHorus API hostname'); - if (!config_update_value('ehorus_port', (int) get_parameter('ehorus_port'))) + if (!config_update_value('ehorus_port', (int) get_parameter('ehorus_port', $config['ehorus_port']))) $error_update[] = __('eHorus API port'); - if (!config_update_value('ehorus_req_timeout', (int) get_parameter('ehorus_req_timeout'))) + if (!config_update_value('ehorus_req_timeout', (int) get_parameter('ehorus_req_timeout', $config['ehorus_req_timeout']))) $error_update[] = __('eHorus request timeout'); + if (!config_update_value('ehorus_custom_field', (string) get_parameter('ehorus_custom_field', $config['ehorus_custom_field']))) + $error_update[] = __('eHorus id custom field'); break; }