Merge branch 'ent-12905-deprecar-eliminar-discovery-legacy' into 'develop'

Ent 12905 Deprecar (eliminar) discovery legacy

See merge request artica/pandorafms!6960
This commit is contained in:
Daniel Rodriguez 2024-03-21 13:23:16 +00:00
commit 50d95d5120
8 changed files with 7794 additions and 703 deletions

View File

@ -1738,3 +1738,12 @@ extensions/files_repo/sql/files_repo.sql
extensions/files_repo
extensions/resource_exportation.php
extensions/resource_registration.php
enterprise/include/class/Aws.cloud.php
enterprise/include/class/Azure.cloud.php
enterprise/include/class/DB2.app.php
enterprise/include/class/Google.cloud.php
enterprise/include/class/MicrosoftSQLServer.app.php
enterprise/include/class/MySQL.app.php
enterprise/include/class/Oracle.app.php
enterprise/include/class/SAP.app.php
enterprise/include/class/VMware.app.php

File diff suppressed because one or more lines are too long

View File

@ -81,16 +81,6 @@ if ((bool) check_acl($config['id_user'], 0, 'AR') === true
if ((bool) check_acl($config['id_user'], 0, 'AW') === true) {
// Applications.
$sub2 = [];
// Check if app has been migrated.
if (enterprise_installed() === true) {
(ManageExtensions::isMigrated('pandorafms.mssql') === true) ?: ($sub2['godmode/servers/discovery&wiz=app&mode=MicrosoftSQLServer']['text'] = __('Microsoft SQL Server (legacy)'));
(ManageExtensions::isMigrated('pandorafms.mysql') === true) ?: ($sub2['godmode/servers/discovery&wiz=app&mode=mysql']['text'] = __('Mysql (legacy)'));
(ManageExtensions::isMigrated('pandorafms.oracle') === true) ?: ($sub2['godmode/servers/discovery&wiz=app&mode=oracle']['text'] = __('Oracle (legacy)'));
(ManageExtensions::isMigrated('pandorafms.vmware') === true) ?: ($sub2['godmode/servers/discovery&wiz=app&mode=vmware']['text'] = __('VMware (legacy)'));
(ManageExtensions::isMigrated('pandorafms.sap.desert') === true) ?: ($sub2['godmode/servers/discovery&wiz=app&mode=SAP']['text'] = __('SAP (legacy)'));
(ManageExtensions::isMigrated('pandorafms.db2') === true) ?: ($sub2['godmode/servers/discovery&wiz=app&mode=DB2']['text'] = __('DB2 (legacy)'));
}
$extensions = ManageExtensions::getExtensionBySection('app');
if ($extensions !== false) {
foreach ($extensions as $key => $extension) {
@ -112,13 +102,6 @@ if ((bool) check_acl($config['id_user'], 0, 'AR') === true
// Cloud.
$sub2 = [];
if (enterprise_installed() === true) {
(ManageExtensions::isMigrated('pandorafms.aws.ec2') === true) ?: (ManageExtensions::isMigrated('pandorafms.aws.s3') === true) ?: (ManageExtensions::isMigrated('pandorafms.aws.rds') === true) ?: ($sub2['godmode/servers/discovery&wiz=cloud&mode=amazonws']['text'] = __('Amazon Web Services (legacy)'));
(ManageExtensions::isMigrated('pandorafms.azure.mc') === true) ?: ($sub2['godmode/servers/discovery&wiz=cloud&mode=azure']['text'] = __('Microsoft Azure (legacy)'));
(ManageExtensions::isMigrated('pandorafms.azure.gcp.ce') === true) ?: ($sub2['godmode/servers/discovery&wiz=cloud&mode=gcp']['text'] = __('Google Compute Platform (legacy)'));
}
$extensions = ManageExtensions::getExtensionBySection('cloud');
if ($extensions !== false) {
foreach ($extensions as $key => $extension) {

View File

@ -82,9 +82,6 @@ class Applications extends Wizard
'index.php?sec=gservers&sec2=godmode/servers/discovery&wiz=app'
);
// Print Warning Message.
$this->printWarningMessage();
return $this;
}
@ -108,148 +105,71 @@ class Applications extends Wizard
);
$mode = get_parameter('mode', null);
// Load application wizards.
$enterprise_classes = glob(
$config['homedir'].'/'.ENTERPRISE_DIR.'/include/class/*.app.php'
);
$extensions = new ExtensionsDiscovery('app', $mode);
foreach ($enterprise_classes as $classpath) {
enterprise_include_once(
'include/class/'.basename($classpath)
);
if ($mode !== null) {
// Load extension if exist.
$extensions->run();
return;
}
switch ($mode) {
case 'DB2':
$classname_selected = 'DB2';
break;
case 'SAP':
$classname_selected = 'SAP';
break;
case 'vmware':
$classname_selected = 'VMware';
break;
case 'mysql':
$classname_selected = 'MySQL';
break;
case 'oracle':
$classname_selected = 'Oracle';
break;
case 'MicrosoftSQLServer':
$classname_selected = 'MicrosoftSQLServer';
break;
default:
$classname_selected = null;
break;
}
// Else: class not found pseudo exception.
if ($classname_selected !== null) {
$wiz = new $classname_selected($this->page);
// Check if app has been migrated.
if (method_exists($wiz, 'isMigrated') === true) {
if ($wiz->isMigrated() === true) {
ui_print_info_message(__('This legacy app has been migrated to new discovery 2.0 system'));
return false;
}
}
$result = $wiz->run();
if (is_array($result) === true) {
return $result;
}
}
if ($classname_selected === null) {
if ($mode !== null) {
// Load extension if exist.
$extensions->run();
return;
}
// Load classes and print selector.
$wiz_data = [];
foreach ($enterprise_classes as $classpath) {
$classname = basename($classpath, '.app.php');
$obj = new $classname();
if (method_exists($obj, 'isMigrated') === true) {
if ($obj->isMigrated() === true) {
continue;
}
}
$wiz_data[] = $obj->load();
}
$wiz_data = array_merge($wiz_data, $extensions->loadExtensions());
$this->prepareBreadcrum(
$this->prepareBreadcrum(
[
[
[
'link' => ui_get_full_url(
'index.php?sec=gservers&sec2=godmode/servers/discovery'
),
'label' => __('Discovery'),
],
[
'link' => ui_get_full_url(
'index.php?sec=gservers&sec2=godmode/servers/discovery&wiz=app'
),
'label' => __('Applications'),
'selected' => true,
],
]
);
// Header.
ui_print_page_header(
__('Applications'),
'',
false,
'',
true,
'',
false,
'',
GENERIC_SIZE_TEXT,
'',
$this->printHeader(true)
);
Wizard::printBigButtonsList($wiz_data);
$not_defined_extensions = $extensions->loadExtensions(true);
$output = html_print_div(
[
'class' => 'agent_details_line',
'content' => ui_toggle(
Wizard::printBigButtonsList($not_defined_extensions, true),
'<span class="subsection_header_title">'.__('Not installed').'</span>',
'not_defined_apps',
'not_defined_apps',
false,
true,
'',
'',
'box-flat white_table_graph w100p'
'link' => ui_get_full_url(
'index.php?sec=gservers&sec2=godmode/servers/discovery'
),
'label' => __('Discovery'),
],
);
[
'link' => ui_get_full_url(
'index.php?sec=gservers&sec2=godmode/servers/discovery&wiz=app'
),
'label' => __('Applications'),
'selected' => true,
],
]
);
echo $output;
// Header.
ui_print_page_header(
__('Applications'),
'',
false,
'',
true,
'',
false,
'',
GENERIC_SIZE_TEXT,
'',
$this->printHeader(true)
);
echo '<div class="app_mssg"><i>*'.__('All company names used here are for identification purposes only. Use of these names, logos, and brands does not imply endorsement.').'</i></div>';
}
Wizard::printBigButtonsList($extensions->loadExtensions());
$not_defined_extensions = $extensions->loadExtensions(true);
$output = html_print_div(
[
'class' => 'agent_details_line',
'content' => ui_toggle(
Wizard::printBigButtonsList($not_defined_extensions, true),
'<span class="subsection_header_title">'.__('Not installed').'</span>',
'not_defined_apps',
'not_defined_apps',
false,
true,
'',
'',
'box-flat white_table_graph w100p'
),
],
);
echo $output;
echo '<div class="app_mssg"><i>*'.__('All company names used here are for identification purposes only. Use of these names, logos, and brands does not imply endorsement.').'</i></div>';
return $result;
}

View File

@ -114,8 +114,6 @@ class Cloud extends Wizard
*/
public function run()
{
global $config;
// Load styles.
parent::run();
@ -127,139 +125,71 @@ class Cloud extends Wizard
$mode = get_parameter('mode', null);
// Load cloud wizards.
$enterprise_classes = glob(
$config['homedir'].'/'.ENTERPRISE_DIR.'/include/class/*.cloud.php'
);
$extensions = new ExtensionsDiscovery('cloud', $mode);
foreach ($enterprise_classes as $classpath) {
enterprise_include_once(
'include/class/'.basename($classpath)
);
if ($mode !== null) {
// Load extension if exist.
$extensions->run();
return;
}
switch ($mode) {
case 'amazonws':
$classname_selected = 'Aws';
break;
case 'azure':
$classname_selected = 'Azure';
break;
case 'gcp':
$classname_selected = 'Google';
break;
default:
$classname_selected = null;
break;
}
// Else: class not found pseudo exception.
if ($classname_selected !== null) {
$wiz = new $classname_selected($this->page);
// Check if app has been migrated.
if (method_exists($wiz, 'isMigrated') === true) {
if ($wiz->isMigrated() === true) {
ui_print_info_message(__('This legacy app has been migrated to new discovery 2.0 system'));
return false;
}
}
$result = $wiz->run();
if (is_array($result) === true) {
return $result;
}
}
if ($classname_selected === null) {
if ($mode !== null) {
// Load extension if exist.
$extensions->run();
return;
}
// Load classes and print selector.
$wiz_data = [];
foreach ($enterprise_classes as $classpath) {
$classname = basename($classpath, '.cloud.php');
$obj = new $classname();
// Check if legacy has been migrated.
if (method_exists($obj, 'isMigrated') === true) {
if ($obj->isMigrated() === true) {
continue;
}
}
$wiz_data[] = $obj->load();
}
$wiz_data = array_merge($wiz_data, $extensions->loadExtensions());
$this->prepareBreadcrum(
// Load classes and print selector.
$this->prepareBreadcrum(
[
[
[
'link' => ui_get_full_url(
'index.php?sec=gservers&sec2=godmode/servers/discovery'
),
'label' => __('Discovery'),
],
[
'link' => $this->url,
'label' => __('Cloud'),
'selected' => true,
],
],
true
);
// Header.
ui_print_page_header(
__('Cloud'),
'',
false,
'',
true,
'',
false,
'',
GENERIC_SIZE_TEXT,
'',
$this->printHeader(true)
);
Wizard::printBigButtonsList($wiz_data);
$not_defined_extensions = $extensions->loadExtensions(true);
$output = html_print_div(
[
'class' => 'agent_details_line',
'content' => ui_toggle(
Wizard::printBigButtonsList($not_defined_extensions, true),
'<span class="subsection_header_title">'.__('Not installed').'</span>',
'not_defined_apps',
'not_defined_apps',
false,
true,
'',
'',
'box-flat white_table_graph w100p'
'link' => ui_get_full_url(
'index.php?sec=gservers&sec2=godmode/servers/discovery'
),
'label' => __('Discovery'),
],
);
[
'link' => $this->url,
'label' => __('Cloud'),
'selected' => true,
],
],
true
);
echo $output;
// Header.
ui_print_page_header(
__('Cloud'),
'',
false,
'',
true,
'',
false,
'',
GENERIC_SIZE_TEXT,
'',
$this->printHeader(true)
);
echo '<div class="app_mssg"><i>*'.__('All company names used here are for identification purposes only. Use of these names, logos, and brands does not imply endorsement.').'</i></div>';
}
Wizard::printBigButtonsList($extensions->loadExtensions());
// Print Warning Message.
$this->printWarningMessage();
$not_defined_extensions = $extensions->loadExtensions(true);
return $result;
$output = html_print_div(
[
'class' => 'agent_details_line',
'content' => ui_toggle(
Wizard::printBigButtonsList($not_defined_extensions, true),
'<span class="subsection_header_title">'.__('Not installed').'</span>',
'not_defined_apps',
'not_defined_apps',
false,
true,
'',
'',
'box-flat white_table_graph w100p'
),
],
);
echo $output;
echo '<div class="app_mssg"><i>*'.__('All company names used here are for identification purposes only. Use of these names, logos, and brands does not imply endorsement.').'</i></div>';
}

View File

@ -222,10 +222,6 @@ class DiscoveryTaskList extends HTML
html_print_action_buttons($this->printForm($form, true));
}
// Warning Message.
$wizar_main = new Wizard();
$wizar_main->printWarningMessage();
return $ret;
}

View File

@ -767,24 +767,6 @@ class ManageExtensions extends HTML
],
);
}
$migrationHash = $this->canMigrate($row['short_name']);
if ($migrationHash !== false && empty($migrationHash) !== true) {
// Migrate button.
$data[$key]['actions'] .= html_print_input_image(
'button_migrate-'.$row['short_name'],
'images/reset.png',
'',
'',
true,
[
'onclick' => 'show_migration_form(\''.$row['short_name'].'\',\''.$migrationHash.'\')',
'title' => __('Migrate old discovery tasks.'),
'alt' => __('Migrate old discovery tasks.'),
'class' => 'main_menu_icon invert_filter',
]
);
}
}
if (empty($data) === true) {
@ -1123,386 +1105,6 @@ class ManageExtensions extends HTML
}
/**
* Checks if the discovery app can be migrated to .disco system.
* If app is migrated or is not in .ini file, it cannot be migrated.
*
* @param string $shortName Short name of the discovery app.
*
* @return string App hash, false in case hash doesnt exist on ini file, or is already migraeted..
*/
private function canMigrate(string $shortName='')
{
global $config;
if (empty($shortName) === true) {
return false;
}
// 1. Check if app is already migrated:
// Get migrated Discovery Apps from config.
$migratedAppsJson = db_get_value('value', 'tconfig', 'token', 'migrated_discovery_apps');
if ($migratedAppsJson === false || empty($migratedAppsJson) === true) {
return false;
}
// Decode JSON migrated apps.
$migrateApps = json_decode(io_safe_output($migratedAppsJson), true);
if (json_last_error() !== JSON_ERROR_NONE) {
return false;
}
// Check app migrated.
if (array_key_exists($shortName, $migrateApps)) {
if (empty($migrateApps[$shortName]) === false && (bool) $migrateApps[$shortName] === true) {
// Already migrated.
return false;
}
}
// 2. If app not migrated yet, check DiscoveryApplicationsMigrateCodes.ini
// Path to the INI file
$filePath = $config['homedir'].'/extras/discovery/DiscoveryApplicationsMigrateCodes.ini';
// Parse the INI file.
$migrationCodes = parse_ini_file($filePath, true);
if ($migrationCodes === false) {
return false;
}
// Check shortname in ini file.
if (array_key_exists($shortName, $migrationCodes) === false) {
return false;
} else {
return $migrationCodes[$shortName];
}
// All checks ok, discovery app can be migrated.
return false;
}
/**
* Prints html for migrate modal
*
* @return void
*/
public function loadMigrateModal()
{
$shortname = get_parameter('shortname', null);
$hash = get_parameter('hash', null);
$form = [
'action' => '#',
'id' => 'modal_migrate_form',
'onsubmit' => 'return false;',
'class' => 'modal',
'name' => 'migrate_form',
];
$inputs = [];
$migrateMessage = __(
'All legacy tasks for this application will be migrated to the new .disco package system. All configurations and executions will be managed with the new system. This process will not be reversible.</br></br>'
);
$migrateMessage .= _('Please check the migration code for the application before proceeding.');
$inputs[] = [
'wrapper' => 'div',
'block_id' => 'div_migrate_message',
'class' => 'hole flex-row flex-items-center w98p',
'direct' => 1,
'block_content' => [
[
'label' => $migrateMessage,
'arguments' => [
'class' => 'first_lbl w98p',
'name' => 'lbl_migrate_message',
'id' => 'lbl_migrate_message',
],
],
],
];
$inputs[] = [
'label' => __('Applicattion hash'),
'id' => 'div-hash',
'arguments' => [
'name' => 'hash',
'type' => 'text',
'value' => $hash,
'return' => true,
],
];
$inputs[] = [
'block_id' => 'migrate_buttons',
'class' => 'flex-row flex-items-center w98p',
'direct' => 1,
'block_content' => [
[
'arguments' => [
'name' => 'cancel',
'label' => __('Cancel'),
'type' => 'button',
'attributes' => [
'icon' => 'left',
'mode' => 'secondary',
'class' => 'sub cancel float-left',
],
],
],
[
'arguments' => [
'name' => 'migrate',
'label' => __('Migrate'),
'type' => 'submit',
'attributes' => [
'icon' => 'wand',
'class' => 'sub wand float-right',
],
],
],
],
];
$spinner = '<div id="migration-spinner" class="invisible spinner-fixed"></div>';
$migration_form = $this->printForm(
[
'form' => $form,
'inputs' => $inputs,
],
true,
);
echo $migration_form.$spinner;
}
/**
* Migrate app to new .disco system
*
* @return true if success, false in case of error.
*/
public function migrateApp()
{
global $config;
$hash = get_parameter('hash', false);
$shortName = get_parameter('shortName', false);
if ($hash === false || $shortName === false) {
return false;
}
// 1. Gets md5
try {
$console_md5 = $this->calculateDirectoryMD5($shortName, false);
$server_md5 = $this->calculateDirectoryMD5($shortName, true);
} catch (Exception $e) {
$return = [
'error' => $e->getMessage(),
];
echo json_encode($return);
return;
}
if ($console_md5 === false || $server_md5 === false) {
$return = [
'error' => __('Error calculating app MD5'),
];
echo json_encode($return);
return;
}
// 2. Checks MD5
if ($hash === $console_md5 && $hash === $server_md5) {
// Init migration script.
$return = $this->executeMigrationScript($shortName);
} else {
$return = [
'error' => __('App hash does not match.'),
];
}
// Add shotrname to return for showing messages.
$return['shortname'] = $shortName;
echo \json_encode($return);
}
/**
* Calculates directory MD% and saves it into array
*
* @param string $shortName Shorname of app.
* @param boolean $server If true, perform checks into server folder.
*
* @return $md5 Array of md5 of filess.
*/
private function calculateDirectoryMD5($shortName, $server)
{
global $config;
$md5List = [];
$serverPath = $config['remote_config'].'/discovery/'.$shortName;
$consolePath = $config['homedir'].'/'.$this->path.'/'.$shortName;
if ($server === true) {
$directory = $serverPath;
} else {
$directory = $consolePath;
}
$iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($directory));
foreach ($iterator as $file) {
if ($file->isFile()) {
$md5List[] = md5_file($file->getPathname());
}
}
if ($server === true) {
$console_ini = $consolePath.'/discovery_definition.ini';
$logo = $consolePath.'/logo.png';
if (file_exists($console_ini)) {
$md5List[] = md5_file($console_ini);
}
if (file_exists($logo)) {
$md5List[] = md5_file($logo);
}
}
sort($md5List);
$concatenatedChecksums = implode('', $md5List);
return md5($concatenatedChecksums);
}
/**
* Executed migration script for app
*
* @param string $shortName Shortname of the app.
*
* @return true on success, false in case of error.
*/
private function executeMigrationScript(string $shortName)
{
global $config;
$dblock = db_get_lock('migrate-working');
// Try to get a lock from DB.
if ($dblock !== 1) {
// Locked!
return false;
}
$scriptName = preg_replace('/^pandorafms\.(\w+\.?\w*)$/m', 'migrate.$1.sql', $shortName);
$script_path = $config['homedir'].'/extras/discovery/migration_scripts/'.$scriptName;
if (file_exists($script_path) === false) {
$return = [
'error' => __('Migration script '.$scriptName.' could not be found'),
];
} else {
try {
$res = db_process_file($script_path, false);
} catch (\Exception $e) {
$return = [
'error' => $e->getMessage(),
];
} finally {
db_release_lock('migrate_working');
}
if ($res === true) {
$migrateAppsJson = io_safe_output(
db_get_value(
'value',
'tconfig',
'token',
'migrated_discovery_apps'
)
);
$migrateApps = json_decode(
$migrateAppsJson,
true
);
$migrateApps[$shortName] = 1;
$migratedAppsJson = json_encode($migrateApps);
if (json_last_error() === JSON_ERROR_NONE) {
config_update_value(
'migrated_discovery_apps',
$migratedAppsJson
);
} else {
$return = [
'error' => __('Error decoding migrated apps json.'),
];
}
$return = [
'result' => __('App migrated successfully'),
'shortName' => $shortName,
];
} else {
$return = [
'error' => __('Error migrating app'),
];
}
}
return $return;
}
/**
* Check if legacy app has been migrated.
*
* @param string $shortName Shorn name of the app.
*
* @return boolean
*/
static public function isMigrated($shortName)
{
global $config;
$migrateAppsJson = io_safe_output(
db_get_value(
'value',
'tconfig',
'token',
'migrated_discovery_apps'
)
);
$migratedApps = json_decode($migrateAppsJson, true);
if (json_last_error() !== JSON_ERROR_NONE) {
return false;
}
if (array_key_exists($shortName, $migratedApps) === true && empty($migratedApps[$shortName] === false)) {
return (bool) $migratedApps[$shortName];
} else {
return false;
}
}
/**
* Read metadata CSV from system and store data structure in memory.
*

View File

@ -584,28 +584,4 @@ class Wizard
}
/**
* Generates warning message.
*
* @return void Warning message.
*/
public function printWarningMessage()
{
return ui_print_warning_message(
__(
'Starting with version 773, the new modular system of discovery 2.0 has been implemented. The current
discovery (1.0) and its defined tasks will continue to function normally until the next LTS version,
in which migration to the new system will be mandatory.
The tasks of the current discovery (1.0) will be marked as legacy although it will not affect their
operation, it will only be a visual indicator to identify and differentiate the tasks of discovery 1.0
from those of the new version 2.0.
In the intermediate versions between the 773 and the next LTS version, more applications of the new
discovery 2.0 will be added. Both new and those that will come to replace the applications of the
current discovery 1.0. In addition, an automatic migration tool for legacy (1.0) tasks to the new 2.0
model will be included.'
)
);
}
}