From 8d9c4682c7da5b748e1760d07a48d1aa29d51c57 Mon Sep 17 00:00:00 2001 From: fbsanchez Date: Wed, 17 Jul 2019 20:37:13 +0200 Subject: [PATCH] WIP Agent repository --- pandora_console/extras/mr/30.sql | 17 +++- .../pandoradb_migrate_6.0_to_7.0.mysql.sql | 19 +++- pandora_console/godmode/menu.php | 1 + pandora_console/godmode/servers/discovery.php | 4 +- .../godmode/wizards/HostDevices.class.php | 21 +++- .../include/functions_credential_store.php | 2 + pandora_console/include/javascript/pandora.js | 97 +++++++++++++++++++ .../include/styles/agent_repository.css | 29 ++++++ pandora_console/pandoradb.sql | 17 ++++ 9 files changed, 202 insertions(+), 5 deletions(-) create mode 100644 pandora_console/include/styles/agent_repository.css diff --git a/pandora_console/extras/mr/30.sql b/pandora_console/extras/mr/30.sql index 8c66c7b0a6..e8a9703835 100644 --- a/pandora_console/extras/mr/30.sql +++ b/pandora_console/extras/mr/30.sql @@ -38,7 +38,22 @@ CREATE TABLE `tdeployment_hosts` ( FOREIGN KEY (`id_cs`) REFERENCES `tcredential_store` (`identifier`) ON UPDATE CASCADE ON DELETE SET NULL, FOREIGN KEY (`id_os`) REFERENCES tconfig_os(`id_os`) - ON UPDATE CASCADE ON DELETE CASCADE + ON UPDATE CASCADE ON DELETE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8; +CREATE TABLE `tagent_repository` ( + `id` SERIAL, + `id_os` INT(10) UNSIGNED DEFAULT 0, + `arch` ENUM('x64', 'x86') DEFAULT 'x64', + `version` VARCHAR(10) DEFAULT '', + `path` text, + `uploaded_by` VARCHAR(100) DEFAULT '', + `uploaded` bigint(20) NOT NULL DEFAULT 0 COMMENT "When it was deployed", + `last_err` text, + PRIMARY KEY (`id`), + FOREIGN KEY (`id_os`) REFERENCES tconfig_os(`id_os`) + ON UPDATE CASCADE ON DELETE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + + COMMIT; diff --git a/pandora_console/extras/pandoradb_migrate_6.0_to_7.0.mysql.sql b/pandora_console/extras/pandoradb_migrate_6.0_to_7.0.mysql.sql index 3fb25af44f..60c74f4a60 100644 --- a/pandora_console/extras/pandoradb_migrate_6.0_to_7.0.mysql.sql +++ b/pandora_console/extras/pandoradb_migrate_6.0_to_7.0.mysql.sql @@ -2253,5 +2253,22 @@ CREATE TABLE `tdeployment_hosts` ( FOREIGN KEY (`id_cs`) REFERENCES `tcredential_store` (`identifier`) ON UPDATE CASCADE ON DELETE SET NULL, FOREIGN KEY (`id_os`) REFERENCES tconfig_os(`id_os`) - ON UPDATE CASCADE ON DELETE CASCADE + ON UPDATE CASCADE ON DELETE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +-- --------------------------------------------------------------------- +-- Table `tagent_repository` +-- --------------------------------------------------------------------- +CREATE TABLE `tagent_repository` ( + `id` SERIAL, + `id_os` INT(10) UNSIGNED DEFAULT 0, + `arch` ENUM('x64', 'x86') DEFAULT 'x64', + `version` VARCHAR(10) DEFAULT '', + `path` text, + `uploaded_by` VARCHAR(100) DEFAULT '', + `uploaded` bigint(20) NOT NULL DEFAULT 0 COMMENT "When it was deployed", + `last_err` text, + PRIMARY KEY (`id`), + FOREIGN KEY (`id_os`) REFERENCES tconfig_os(`id_os`) + ON UPDATE CASCADE ON DELETE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8; diff --git a/pandora_console/godmode/menu.php b/pandora_console/godmode/menu.php index c9d9902b86..000a105257 100644 --- a/pandora_console/godmode/menu.php +++ b/pandora_console/godmode/menu.php @@ -129,6 +129,7 @@ if (check_acl($config['id_user'], 0, 'PM')) { $sub['godmode/modules/manage_network_templates']['id'] = 'Module templates'; enterprise_hook('inventory_submenu'); enterprise_hook('autoconfiguration_menu'); + enterprise_hook('agent_repository_menu'); } if (check_acl($config['id_user'], 0, 'AW')) { diff --git a/pandora_console/godmode/servers/discovery.php b/pandora_console/godmode/servers/discovery.php index edf7cc989e..3f2166bb39 100755 --- a/pandora_console/godmode/servers/discovery.php +++ b/pandora_console/godmode/servers/discovery.php @@ -93,7 +93,7 @@ function cl_load_cmp($a, $b) $classes = glob($config['homedir'].'/godmode/wizards/*.class.php'); if (enterprise_installed()) { $ent_classes = glob( - $config['homedir'].'/enterprise/godmode/wizards/*.class.php' + $config['homedir'].'/'.ENTERPRISE_DIR.'/godmode/wizards/*.class.php' ); if ($ent_classes === false) { $ent_classes = []; @@ -142,7 +142,7 @@ if ($classname_selected === null) { } } - // Show hints if there is no task + // Show hints if there is no task. if (get_parameter('discovery_hint', 0)) { ui_require_css_file('discovery-hint'); ui_print_info_message(__('You must create a task first')); diff --git a/pandora_console/godmode/wizards/HostDevices.class.php b/pandora_console/godmode/wizards/HostDevices.class.php index 210717ff1b..fb9fba2cdd 100755 --- a/pandora_console/godmode/wizards/HostDevices.class.php +++ b/pandora_console/godmode/wizards/HostDevices.class.php @@ -156,11 +156,30 @@ class HostDevices extends Wizard ), 'label' => __('Discovery'), ], + [ + 'link' => ui_get_full_url( + 'index.php?sec=gservers&sec2=godmode/servers/discovery&wiz=hd' + ), + 'label' => __('Host & Devices'), + 'selected' => true, + ], ], true ); - ui_print_page_header(__('Host & devices'), '', false, '', true, '', false, '', GENERIC_SIZE_TEXT, '', $this->printHeader(true)); + ui_print_page_header( + __('Host & devices'), + '', + false, + '', + true, + '', + false, + '', + GENERIC_SIZE_TEXT, + '', + $this->printHeader(true) + ); $this->printBigButtonsList($buttons); return; diff --git a/pandora_console/include/functions_credential_store.php b/pandora_console/include/functions_credential_store.php index 048c2bba00..1b64bba116 100644 --- a/pandora_console/include/functions_credential_store.php +++ b/pandora_console/include/functions_credential_store.php @@ -331,6 +331,8 @@ function print_inputs($values=null) case 'CUSTOM': $user_label = __('Account ID'); $pass_label = __('Password'); + $extra1 = false; + $extra2 = false; default: // Use defaults. break; diff --git a/pandora_console/include/javascript/pandora.js b/pandora_console/include/javascript/pandora.js index 0fa503f81f..05009e7292 100644 --- a/pandora_console/include/javascript/pandora.js +++ b/pandora_console/include/javascript/pandora.js @@ -1870,3 +1870,100 @@ function logo_preview(icon_name, icon_path, incoming_options) { // console.log(err); } } + +// Advanced Form control. +/* global $ */ +/* exported load_modal */ +function load_modal(settings) { + var AJAX_RUNNING = 0; + var data = new FormData(); + if (settings.extradata) { + settings.extradata.forEach(function(item) { + if (item.value != undefined) data.append(item.name, item.value); + }); + } + data.append("page", settings.onshow.page); + data.append("method", settings.onshow.method); + + var width = 630; + if (settings.onshow.width) { + width = settings.onshow.width; + } + + $.ajax({ + method: "post", + url: settings.url, + processData: false, + contentType: false, + data: data, + success: function(data) { + settings.target.html(data); + settings.target.dialog({ + resizable: true, + draggable: true, + modal: true, + title: settings.modal.title, + width: width, + overlay: { + opacity: 0.5, + background: "black" + }, + buttons: [ + { + class: + "ui-widget ui-state-default ui-corner-all ui-button-text-only sub upd submit-cancel", + text: settings.modal.cancel, + click: function() { + $(this).dialog("close"); + settings.cleanup(); + } + }, + { + class: + "ui-widget ui-state-default ui-corner-all ui-button-text-only sub ok submit-next", + text: settings.modal.ok, + click: function() { + if (AJAX_RUNNING) return; + AJAX_RUNNING = 1; + var formdata = new FormData(); + if (settings.extradata) { + settings.extradata.forEach(function(item) { + if (item.value != undefined) + formdata.append(item.name, item.value); + }); + } + formdata.append("page", settings.onsubmit.page); + formdata.append("method", settings.onsubmit.method); + + $("#" + settings.form + " :input").each(function() { + if (this.type == "file") { + if ($(this).prop("files")[0]) { + formdata.append(this.name, $(this).prop("files")[0]); + } + } else { + formdata.append(this.name, $(this).val()); + } + }); + + $.ajax({ + method: "post", + url: settings.url, + processData: false, + contentType: false, + data: formdata, + success: function(data) { + settings.ajax_callback(data); + AJAX_RUNNING = 0; + } + }); + } + } + ], + closeOnEscape: false, + open: function() { + $(".ui-dialog-titlebar-close").hide(); + } + }); + } + }); +} diff --git a/pandora_console/include/styles/agent_repository.css b/pandora_console/include/styles/agent_repository.css new file mode 100644 index 0000000000..4f0794338d --- /dev/null +++ b/pandora_console/include/styles/agent_repository.css @@ -0,0 +1,29 @@ +ul.wizard li > label:not(.p-switch) { + width: auto; +} + +form.top-action-buttons ul.wizard { + display: flex; + flex-direction: row; +} + +ul.wizard li { + margin-right: 1em; +} + +form.modal ul.wizard li { + display: flex; + flex-direction: row; + width: 90%; + margin: 0.5em auto; + justify-items: center; +} + +form.modal ul.wizard li * { + flex: 1; +} + +ul.wizard li.flex-indep { + flex: 1; + margin: 0; +} diff --git a/pandora_console/pandoradb.sql b/pandora_console/pandoradb.sql index 704e64ae2d..57c3f5c59b 100644 --- a/pandora_console/pandoradb.sql +++ b/pandora_console/pandoradb.sql @@ -3646,3 +3646,20 @@ CREATE TABLE IF NOT EXISTS `tvisual_console_elements_cache` ( ON DELETE CASCADE ON UPDATE CASCADE ) engine=InnoDB DEFAULT CHARSET=utf8; + +-- --------------------------------------------------------------------- +-- Table `tagent_repository` +-- --------------------------------------------------------------------- +CREATE TABLE `tagent_repository` ( + `id` SERIAL, + `id_os` INT(10) UNSIGNED DEFAULT 0, + `arch` ENUM('x64', 'x86') DEFAULT 'x64', + `version` VARCHAR(10) DEFAULT '', + `path` text, + `uploaded_by` VARCHAR(100) DEFAULT '', + `uploaded` bigint(20) NOT NULL DEFAULT 0 COMMENT "When it was deployed", + `last_err` text, + PRIMARY KEY (`id`), + FOREIGN KEY (`id_os`) REFERENCES tconfig_os(`id_os`) + ON UPDATE CASCADE ON DELETE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8;