some changes in discovery

This commit is contained in:
alejandro.campos@artica.es 2023-12-05 16:07:14 +01:00
parent 08e514e12c
commit 457f8e9448
6 changed files with 124 additions and 35 deletions

View File

@ -219,7 +219,7 @@ class Applications extends Wizard
'class' => 'agent_details_line',
'content' => ui_toggle(
Wizard::printBigButtonsList($not_defined_extensions, true),
'<span class="subsection_header_title">'.__('Not defined applications').'</span>',
'<span class="subsection_header_title">'.__('Not installed').'</span>',
'not_defined_apps',
'not_defined_apps',
false,

View File

@ -239,7 +239,7 @@ class Cloud extends Wizard
'class' => 'agent_details_line',
'content' => ui_toggle(
Wizard::printBigButtonsList($not_defined_extensions, true),
'<span class="subsection_header_title">'.__('Not defined applications').'</span>',
'<span class="subsection_header_title">'.__('Not installed').'</span>',
'not_defined_apps',
'not_defined_apps',
false,

View File

@ -142,7 +142,7 @@ class Custom extends Wizard
'class' => 'agent_details_line',
'content' => ui_toggle(
Wizard::printBigButtonsList($not_defined_extensions, true),
'<span class="subsection_header_title">'.__('Not defined applications').'</span>',
'<span class="subsection_header_title">'.__('Not installed').'</span>',
'not_defined_apps',
'not_defined_apps',
false,

View File

@ -697,6 +697,9 @@ class ManageExtensions extends HTML
$order,
);
$appsMetadata = self::loadDiscoveryAppsMetadata();
$flattenMetadata = array_merge(...array_values($appsMetadata));
$count = db_get_num_rows($sqlCount);
foreach ($data as $key => $row) {
@ -705,6 +708,15 @@ class ManageExtensions extends HTML
$logo = $this->defaultLogo;
}
$metadataImage = $flattenMetadata[$row['short_name']]['image'];
if (isset($metadataImage) === true
&& file_exists($config['homedir'].'/images/discovery/'.$metadataImage) === true
&& file_exists($this->path.'/'.$row['short_name'].'/logo.png') === false
) {
$logo = '/images/discovery/'.$metadataImage;
}
$logo = html_print_image($logo, true, ['style' => 'max-width: 30px; margin-right: 15px;']);
$data[$key]['name'] = $logo.io_safe_output($row['name']);
$data[$key]['short_name'] = $row['short_name'];
@ -1490,4 +1502,55 @@ class ManageExtensions extends HTML
}
/**
* Read metadata CSV from system and store data structure in memory.
*
* @return array Data structure.
*/
private static function loadDiscoveryAppsMetadata()
{
global $config;
// Open the CSV file for reading.
$fileHandle = fopen($config['homedir'].'/extras/discovery/DiscoveryApps.csv', 'r');
// Check if the file was opened successfully.
if ($fileHandle !== false) {
$csvData = [];
// Loop through each line in the CSV file.
while (($data = fgetcsv($fileHandle)) !== false) {
$csvData[] = explode(';', $data[0]);
}
// Close the file handle.
fclose($fileHandle);
}
$groupedArray = [];
foreach ($csvData as $item) {
$key = $item[2];
if (isset($groupedArray[$key]) === false) {
$groupedArray[$key] = [];
}
$itemShortName = $item[0];
unset($item[0]);
unset($item[2]);
$itemIns = [
'name' => $item[1],
'enterprise' => $item[3],
'image' => $item[4],
'url' => $item[5],
];
$groupedArray[$key][$itemShortName] = $itemIns;
}
return $groupedArray;
}
}

View File

@ -224,37 +224,32 @@ class ExtensionsDiscovery extends Wizard
// Print JS required for message management.
echo '<script>
function sanitizeHTML(input) {
var doc = new DOMParser().parseFromString(input, "text/html");
return doc.body.textContent || "";
}
function showExtensionMsg(msgs, url) {
function showExtensionMsg(msgs, url, title) {
var msgs_json = JSON.parse(msgs);
var url_str = "";
if (url != false) {
url_str = `<a href="${url}">'.__('here').'</a>`;
url_str = `<a target="_blank" class="link-important" href="${url}">'.__('here').'</a>`;
}
var markup = "<ul>";
var markup = "<ul class=\'\'>";
if (msgs_json.includes('.NOT_FOUND_MSG.')) {
markup += "<li>'.__('The required files for the application were not found').'</li>";
markup += "<li>&nbsp;&nbsp;&nbsp;'.__('The required files for the application were not found.').'</li>";
}
if (msgs_json.includes('.ENTERPRISE_MSG.')) {
markup += "<li>'.__('This discovery application is for Enterprise customers only').'</li>";
markup += "<li>&nbsp;&nbsp;&nbsp;'.__('This discovery application is for Enterprise customers only.').'</li>";
}
if (msgs_json.includes('.URL_MSG.')) {
markup += \'<li>'.__('You can download this application from').' \'+url_str+\'</li>\';
markup += \'<li>&nbsp;&nbsp;&nbsp;'.__('You can download this application from').' \'+url_str+\'.</li>\';
}
markup += "</ul>";
confirmDialog({
title: "'.__('Warning').'",
title: title,
message: markup,
hideOkButton: true,
ok: "'.__('OK').'",
@ -279,22 +274,26 @@ class ExtensionsDiscovery extends Wizard
$error_msgs = [];
if (isset($val['image']) === true
&& file_exists($config['homedir'].'/images/discovery/'.$val['image']) === true
&& file_exists($config['homedir'].$this->path.'/'.$short_name.'/'.$val['image']) === false
) {
$logo = '/images/discovery/'.$val['image'];
}
$url = ui_get_full_url(
'index.php?sec=gservers&sec2=godmode/servers/discovery&wiz='.$this->section.'&mode='.$extension['short_name']
);
if (self::iniFileExists($short_name) === false) {
// Set ghost mode and display not found message if ini file does not exist for extension.
$error_msgs[] = NOT_FOUND_MSG;
}
if (enterprise_installed() === false && ((bool) $val['enterprise'] === true)) {
// Display enterprise message if console is open and extension is enterprise.
$error_msgs[] = ENTERPRISE_MSG;
}
$url_href = false;
if (isset($val['url']) === true && $val['url'] !== '') {
if (isset($val['url']) === true
&& $val['url'] !== ''
) {
$url_href = $val['url'];
// Display URL message if an URL is defined in the metadata.
$error_msgs[] = URL_MSG;
@ -303,7 +302,7 @@ class ExtensionsDiscovery extends Wizard
if (empty($error_msgs) === false) {
$json_errors = json_encode($error_msgs);
// Display messages dialog if there are some.
$url = 'javascript: showExtensionMsg(\''.$json_errors.'\', \''.$url_href.'\');';
$url = 'javascript: showExtensionMsg(\''.$json_errors.'\', \''.$url_href.'\', \''.io_safe_input($val['name']).'\');';
}
$extensions[] = [
@ -319,6 +318,7 @@ class ExtensionsDiscovery extends Wizard
} else {
foreach ($rows as $key => $extension) {
$error_msgs = [];
$logo = $this->path.'/'.$extension['short_name'].'/'.$this->icon;
if (file_exists($config['homedir'].$logo) === false) {
$logo = $this->defaultLogo;
@ -331,33 +331,53 @@ class ExtensionsDiscovery extends Wizard
);
$url_href = false;
$iniFileExists = self::iniFileExists($extension['short_name']);
// Access metadata for current extension.
if (isset($sectionMetadata[$extension['short_name']]) === true) {
$itemData = $sectionMetadata[$extension['short_name']];
$mark_as_enterprise = (bool) $itemData['enterprise'];
if (isset($itemData['url']) === true && $itemData['url'] !== '') {
$url_href = $itemData['url'];
// Display URL message if an URL is defined in the metadata.
$error_msgs[] = URL_MSG;
if (isset($itemData) === true) {
if (isset($itemData['image']) === true
&& file_exists($config['homedir'].'/images/discovery/'.$itemData['image']) === true
&& file_exists($config['homedir'].$this->path.'/'.$extension['short_name'].'/'.$this->icon) === false
) {
$logo = '/images/discovery/'.$itemData['image'];
}
$mark_as_enterprise = (bool) $itemData['enterprise'];
if ($iniFileExists === false
&& isset($itemData['url']) === true
&& $itemData['url'] !== ''
) {
$url_href = $itemData['url'];
// Display URL message if an URL is defined in the metadata.
$error_msgs[] = URL_MSG;
}
if (enterprise_installed() === false
&& (bool) $itemData['enterprise'] === true
) {
// Set ghost mode and display enterprise message if console is open and extension is enterprise.
$error_msgs[] = ENTERPRISE_MSG;
$ghostMode = true;
}
$itemName = $itemData['name'];
}
}
if (self::iniFileExists($extension['short_name']) === false) {
if ($iniFileExists === false) {
// Set ghost mode and display not found message if ini file does not exist for extension.
$error_msgs[] = NOT_FOUND_MSG;
$ghostMode = true;
}
if (enterprise_installed() === false && ((bool) $itemData['enterprise'] === true)) {
// Set ghost mode and display enterprise message if console is open and extension is enterprise.
$error_msgs[] = ENTERPRISE_MSG;
$ghostMode = true;
}
if (empty($error_msgs) === false) {
$json_errors = json_encode($error_msgs);
// Display messages dialog if there are some.
$url = 'javascript: showExtensionMsg(\''.$json_errors.'\', \''.$url_href.'\');';
$url = 'javascript: showExtensionMsg(\''.$json_errors.'\', \''.$url_href.'\', \''.io_safe_input($itemName).'\');';
}
$extensions[] = [

View File

@ -12289,6 +12289,12 @@ div.parent_graph > p.legend_background > table > tbody > tr {
color: #82b92e;
text-decoration: none;
}
.link-important {
color: #82b92e !important;
text-decoration: none !important;
}
.signature a {
color: #82b92e;
text-decoration: none;