Merge branch 'ent-8365-ncm-fase-3' into 'develop'

Ent 8365 ncm fase 3

See merge request artica/pandorafms!6612
This commit is contained in:
Rafael Ameijeiras 2023-12-14 08:40:31 +00:00
commit f3d190a8bb
18 changed files with 1734 additions and 83 deletions

File diff suppressed because it is too large Load Diff

View File

@ -1062,7 +1062,13 @@ switch ($action) {
break;
case 'ncm':
$idAgent = $item['id_agent'];
$id_agent_ncm = json_decode($item['ncm_agents']);
$ncm_group = $item['id_group'];
break;
case 'ncm_backups':
$id_agent_ncm = json_decode($item['ncm_agents']);
$ncm_group = $item['id_group'];
break;
case 'top_n_agents_sh':
@ -2079,6 +2085,71 @@ if (is_metaconsole() === true) {
?>
</td>
</tr>
<tr id="row_ncm_group" class="datos">
<td class="bolder"><?php echo __('Group NCM'); ?></td>
<td >
<?php
echo '<div class="w250px inline padding-right-2-imp">';
$url = ui_get_full_url('ajax.php');
html_print_input_hidden('url_ajax', $url, false, false, false, 'url_ajax');
if (check_acl($config['id_user'], 0, 'RW')) {
html_print_select_groups(
$config['id_user'],
'RW',
true,
'ncm_group',
$ncm_group,
'filterNcmAgentChange()',
);
} else if (check_acl($config['id_user'], 0, 'RM')) {
html_print_select_groups(
$config['id_user'],
'RM',
true,
'ncm_group',
$ncm_group,
'filterNcmAgentChange()',
);
}
echo '</div>';
?>
</td>
</tr>
<tr id="row_ncm_agent">
<td class="bolder"><?php echo __('Agent NCM'); ?></td>
<td >
<?php
echo '<div class="w250px inline padding-right-2-imp">';
$all_agents = agents_get_agents_selected($ncm_group);
html_print_select(
$all_agents,
'agent_ncm[]',
$id_agent_ncm,
'',
__('Any'),
0,
false,
true,
true,
'',
false,
'width: 100%;',
false,
false,
false,
'',
false,
false,
false,
false,
true,
true,
);
echo '</div>';
?>
</td>
</tr>
<tr id="row_source" class="datos">
<td class="bolder"><?php echo __('Source'); ?></td>
<td >
@ -7305,6 +7376,10 @@ function chooseType() {
$('#agent_autocomplete_events').show();
// NCM fields.
$("#row_ncm_group").hide();
$("#row_ncm_agent").hide();
switch (type) {
case 'event_report_group':
$("#row_description").show();
@ -8168,7 +8243,13 @@ function chooseType() {
break;
case 'ncm':
$("#row_agent").show();
$("#row_ncm_group").show();
$("#row_ncm_agent").show();
break;
case 'ncm_backups':
$("#row_ncm_group").show();
$("#row_ncm_agent").show();
break;
case 'top_n_agents_sh':
@ -8551,4 +8632,43 @@ $(document).ready(function () {
});
});
// Ncm agent filter by group.
function filterNcmAgentChange() {
var idGroup = $("#ncm_group").val();
const url_ajax = $("#url_ajax").val();
$.ajax({
url: url_ajax,
type: "POST",
dataType: "json",
async: false,
data: {
page: "operation/agentes/ver_agente",
get_ncm_agents: 1,
id_group: idGroup,
privilege: "AW",
keys_prefix: "_"
},
success: function(data) {
$("#agent_ncm").empty();
var optionAny = $("<option></option>")
.attr("value",0)
.html("Any");
// Add any option.
$("#agent_ncm").append(optionAny);
data.map(item => {
var option = $("<option></option>")
.attr("value", item.id_agent)
.html(item.alias);
// Add agents options.
$("#agent_ncm").append(option);
});
},
error: function(err) {
console.error(err);
}
});
}
</script>

View File

@ -2061,6 +2061,20 @@ switch ($action) {
$good_format = true;
break;
case 'ncm_backups':
$agents_ncm = get_parameter('agent_ncm');
$values['ncm_agents'] = json_encode($agents_ncm);
$values['id_group'] = get_parameter('ncm_group');
$good_format = true;
break;
case 'ncm':
$agents_ncm = get_parameter('agent_ncm');
$values['ncm_agents'] = json_encode($agents_ncm);
$values['id_group'] = get_parameter('ncm_group');
$good_format = true;
break;
case 'vuls_severity_graph':
$values['id_group'] = get_parameter('combo_group');
$good_format = true;
@ -2131,7 +2145,10 @@ switch ($action) {
break;
}
if (isset($values['id_agent']) === false) {
$values['id_agent'] = get_parameter('id_agent');
}
$values['id_gs'] = get_parameter('id_custom_graph');
$values['id_agent_module'] = '';
@ -2247,7 +2264,10 @@ switch ($action) {
$values['id_module_group'] = get_parameter(
'combo_modulegroup'
);
if (isset($values['id_group']) === false) {
$values['id_group'] = get_parameter('combo_group');
}
if ($values['server_name'] == '') {
$values['server_name'] = get_parameter(
@ -3057,6 +3077,21 @@ switch ($action) {
$good_format = true;
break;
case 'ncm_backups':
$agents_ncm = get_parameter('agent_ncm');
$values['ncm_agents'] = json_encode($agents_ncm);
$values['id_group'] = get_parameter('ncm_group');
$good_format = true;
break;
case 'ncm':
$agents_ncm = get_parameter('agent_ncm');
$values['ncm_agents'] = json_encode($agents_ncm);
$values['id_agent'] = get_parameter('agent_ncm');
$values['id_group'] = get_parameter('ncm_group');
$good_format = true;
break;
case 'vuls_severity_graph':
$values['id_group'] = get_parameter('combo_group');
$good_format = true;
@ -3133,7 +3168,10 @@ switch ($action) {
);
}
if (isset($values['id_agent']) === false) {
$values['id_agent'] = get_parameter('id_agent');
}
$values['id_gs'] = get_parameter('id_custom_graph');
if (($values['type'] == 'alert_report_agent')
|| ($values['type'] == 'event_report_agent')
@ -3247,7 +3285,9 @@ switch ($action) {
$values['id_module_group'] = get_parameter(
'combo_modulegroup'
);
if (isset($values['id_group']) === false) {
$values['id_group'] = get_parameter('combo_group');
}
if ((($values['type'] == 'custom_graph')

View File

@ -896,6 +896,35 @@ echo '<legend>'.__('Mail configuration').'</legend>';
echo '</fieldset>';
echo '<fieldset class="margin-bottom-10">';
echo '<legend>'.__('NCM Configuration').'</legend>';
$table_ncm_config = new stdClass();
$table_ncm_config->width = '100%';
$table_ncm_config->class = 'databox filter-table-adv';
$table_ncm_config->size = [];
$table_ncm_config->size[0] = '50%';
$table_ncm_config->data = [];
$table_ncm_config->data[0][] = html_print_label_input_block(
__('FTP server IP').ui_print_help_tip(__('This value will be used by TFTP_SERVER_IP macro in NCM scripts.'), true),
html_print_input_text(
'tftp_server_ip',
$config['tftp_server_ip'],
'',
false,
255,
true,
false,
false,
'',
'w50p'
)
);
html_print_table($table_ncm_config);
echo '</fieldset>';
html_print_action_buttons(
html_print_submit_button(

View File

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<svg width="20px" height="20px" viewBox="0 0 20 20" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<title>donut</title>
<g id="donut" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
<path d="M10,1 C14.9705627,1 19,5.02943725 19,10 C19,14.9705627 14.9705627,19 10,19 C5.02943725,19 1,14.9705627 1,10 C1,5.02943725 5.02943725,1 10,1 Z M10,6 C7.790861,6 6,7.790861 6,10 C6,12.209139 7.790861,14 10,14 C12.209139,14 14,12.209139 14,10 C14,7.790861 12.209139,6 10,6 Z" id="Oval" fill="#484848" fill-rule="nonzero"></path>
</g>
</svg>

After

Width:  |  Height:  |  Size: 649 B

View File

@ -431,6 +431,10 @@ function config_update_config()
if (config_update_value('inventory_changes_blacklist', implode(',', $inventory_changes_blacklist), true) === false) {
$error_update[] = __('Inventory changes blacklist');
}
if (config_update_value('tftp_server_ip', (string) get_parameter('tftp_server_ip'), true) === false) {
$error_update[] = __('Ftp server ip');
}
break;
case 'enterprise':

View File

@ -973,7 +973,15 @@ function reporting_make_reporting_data(
break;
case 'ncm':
$report['contents'][] = reporting_ncm_config(
$report['contents'][] = reporting_ncm_list(
$report,
$content,
$pdf
);
break;
case 'ncm_backups':
$report['contents'][] = reporting_ncm_backups(
$report,
$content,
$pdf

View File

@ -480,7 +480,11 @@ function reporting_html_print_report($report, $mini=false, $report_info=1, $cust
break;
case 'ncm':
reporting_html_ncm_config($table, $item);
reporting_html_ncm_list($table, $item);
break;
case 'ncm_backups':
reporting_html_ncm_backups($table, $item);
break;
case 'top_n_agents_sh':
@ -7747,40 +7751,146 @@ function reporting_html_permissions($table, $item, $pdf=0)
/**
* HTML content for ncm configuration diff report.
* HTML content for ncm devices list.
*
* @param array $item Content generated by reporting_ncm_config.
* @param array $item Content generated by reporting_ncm_list.
*
* @return string HTML code.
*/
function reporting_html_ncm_config($table, $item, $pdf=0)
function reporting_html_ncm_list($table, $item, $pdf=0)
{
$key = uniqid();
// Create table diff.
$table_ncm = new stdClass();
$table_ncm->width = '100%';
$table_ncm->class = 'info_table';
$table_ncm->styleTable = 'table-layout: fixed;';
$table_ncm->titleclass = 'title_table_pdf';
$table_ncm->align = [];
$table_ncm->align['name'] = 'left';
$table_ncm->align['ip'] = 'left';
$table_ncm->align['vendor'] = 'left';
$table_ncm->align['model'] = 'left';
$table_ncm->align['firmware'] = 'left';
$table_ncm->align['last_backup_date'] = 'left';
$table_ncm->headstyle['name'] = 'text-align: left';
$table_ncm->headstyle['ip'] = 'text-align: left';
$table_ncm->headstyle['vendor'] = 'text-align: left';
$table_ncm->headstyle['model'] = 'text-align: left';
$table_ncm->headstyle['firmware'] = 'text-align: left';
$table_ncm->headstyle['last_backup_date'] = 'text-align: left';
$table_ncm->head = [];
$table_ncm->head['name'] = __('Name');
$table_ncm->head['ip'] = __('Ip');
$table_ncm->head['vendor'] = __('Vendor');
$table_ncm->head['model'] = __('Model');
$table_ncm->head['firmware'] = __('Firmware');
$table_ncm->head['last_backup_date'] = __('Last backup date');
$table_ncm->data = [];
foreach ($item['data'] as $key => $row) {
$title = $row['last_error'];
if (empty($title) === true) {
$title = null;
}
$table_ncm->data[] = [
$row['alias'],
$row['direccion'],
$row['vendor'],
$row['model'],
$row['firmware'],
$row['last_backup_date'],
];
}
if ($pdf === 0) {
ui_require_javascript_file('diff2html-ui.min');
ui_require_css_file('diff2html.min');
$script = "$(document).ready(function() {
const configuration = {
drawFileList: false,
collapsed: true,
matching: 'lines',
outputFormat: 'side-by-side',
};
const diff2htmlUi = new Diff2HtmlUI(
document.getElementById('".$key."'),
atob('".base64_encode($item['data'])."'),
configuration
$table->colspan['data']['cell'] = 3;
$table->cellstyle['data']['cell'] = 'text-align: left;';
$table->data['data']['cell'] = html_print_table(
$table_ncm,
true
);
diff2htmlUi.draw();
});";
$content = '<div class="w100p" id="'.$key.'"></div class="w100p">';
$content .= '<script>'.$script.'</script>';
$table->data[1] = $content;
$table->colspan[1][0] = 2;
} else {
$content = '<div style="text-align:left;margin-left: 14px;">';
$content .= str_replace("\n", '<br>', $item['data']);
$content .= '</div>';
return $content;
$table_ncm->titleclass = 'title_table_pdf';
$table_ncm->titlestyle = 'text-align:left;';
return html_print_table(
$table_ncm,
true
);
}
}
/**
* HTML content for ncm backup report.
*
* @param array $item Content generated by reporting_ncm_backups.
*
* @return string HTML code.
*/
function reporting_html_ncm_backups($table, $item, $pdf=0)
{
ui_require_css_file('diff2html.min');
ui_require_css_file('highlight.min');
ui_require_css_file('highlight/vs.min');
ui_require_javascript_file('diff2html-ui.min');
ui_require_javascript_file('highlight.min');
ui_require_javascript_file('highlightjs-line-numbers.min');
ui_require_javascript_file('languages/plaintext.min');
ui_require_javascript_file('jquery', ENTERPRISE_DIR.'/include/javascript/');
ui_require_javascript_file('functions_ncm', ENTERPRISE_DIR.'/include/javascript/');
// Create table diff.
foreach ($item['data'] as $ncm_agent_key => $ncm_agent) {
$table_ncm = new stdClass();
if ($pdf === 1) {
$table_ncm->width = '100%';
}
$table_ncm->class = 'info_table';
$table_ncm->styleTable = 'table-layout: fixed;';
$table_ncm->headstyle[0] = 'width: 250px';
$table_ncm->head = [];
$table_ncm->head[0] = __('Date');
$table_ncm->head[1] = __('Diff');
$table_ncm->id = 'ncm_backups';
$table_ncm->name = 'ncm_backups';
$table_ncm->title = $ncm_agent['caption'];
$row = [];
foreach ($ncm_agent['data'] as $ncm_agent_data) {
if ($pdf === 1) {
$row[] = [
$ncm_agent_data['updated_at'],
($ncm_agent_data['diffstr'] === '') ? $ncm_agent_data['diff'] : str_replace("\n", '<br>', $ncm_agent_data['diffstr']),
];
} else {
$row[] = [
$ncm_agent_data['updated_at'],
$ncm_agent_data['diff'],
];
}
$table_ncm->data = $row;
}
$table->colspan[$ncm_agent_key]['cell'] = 3;
$table->cellstyle[$ncm_agent_key]['cell'] = 'text-align: left;';
$table->data[$ncm_agent_key]['cell'] = html_print_table(
$table_ncm,
true
);
}
if ($pdf === 1) {
$table->width = '100%';
return html_print_table(
$table,
true
);
}
}

View File

@ -967,9 +967,14 @@ function reports_get_report_types($template=false, $not_editor=false)
];
}
$types['ncm_backups'] = [
'optgroup' => __('NCM'),
'name' => __('NCM configuration changes'),
];
$types['ncm'] = [
'optgroup' => __('NCM'),
'name' => __('Network configuration changes'),
'name' => __('NCM devices list'),
];
if (enterprise_installed() === true) {

View File

@ -104,11 +104,8 @@ function load_modal(settings) {
width = settings.onshow.width;
}
if (settings.modal.overlay == undefined) {
settings.modal.overlay = {
opacity: 0.5,
background: "black"
};
if (settings.modal.overlay === true) {
$("body").append("<div id='modal_overlay'class='ui-widget-overlay'></div>");
}
if (settings.beforeClose == undefined) {
@ -496,7 +493,6 @@ function load_modal(settings) {
settings.onshow.maxHeight != undefined
? settings.onshow.maxHeight
: "auto",
overlay: settings.modal.overlay,
position: {
my: "top+20%",
at: "top",
@ -518,6 +514,7 @@ function load_modal(settings) {
if (settings.cleanup != undefined) {
settings.cleanup();
}
$("#modal_overlay").remove();
},
beforeClose: settings.beforeClose()
});

View File

@ -365,3 +365,9 @@ input[type="submit"].ui-button-dialog {
.ui_tpicker_time {
margin-left: 10px !important;
}
.ui-widget-overlay {
background: #aaa !important;
opacity: 0.3 !important;
z-index: 1114;
}

View File

@ -1,10 +1,3 @@
span.select2.select2-container.select2-container--default {
max-width: 175px !important;
width: 175px !important;
}
.edit_discovery_input b {
display: flex;
flex-direction: row;
align-items: center;
.select2-selection__rendered {
max-width: 600px;
}

View File

@ -12878,6 +12878,10 @@ tr.shown td.details-control {
top: -92px;
}
#ncm_backups > caption > h4 {
color: black;
}
.tags_selected_container > span.select2 {
background-color: white !important;
}

View File

@ -28,6 +28,7 @@
use PandoraFMS\Enterprise\Metaconsole\Node;
use PandoraFMS\ITSM\ITSM;
use PandoraFMS\Enterprise\NetworkManager;
global $config;
@ -74,6 +75,7 @@ if (is_ajax()) {
$get_node_agent = (bool) get_parameter('get_node_agent', false);
$get_agent_inventory_modules = (bool) get_parameter('get_agent_inventory_modules', false);
$get_agent_inventory_dates = (bool) get_parameter('get_agent_inventory_dates', false);
$get_ncm_agents = (bool) get_parameter('get_ncm_agents', false);
$refresh_contact = get_parameter('refresh_contact', 0);
@ -215,6 +217,30 @@ if (is_ajax()) {
return;
}
// Get ncm Agent.
if ($get_ncm_agents === true) {
$fields = [
'`tncm_agent`.id_agent',
'`tagente`.alias',
];
$id_group = (int) get_parameter('id_group');
$filter['filter_id_group'] = $id_group;
// Retrieve data.
$ncm_data = NetworkManager::agents(
// Fields.
$fields,
// Filter.
$filter,
);
echo json_encode($ncm_data);
return;
}
if ($get_modules_group_json === true) {
$id_group = (int) get_parameter('id_module_group', 0);
$id_agents = get_parameter('id_agents', null);

View File

@ -335,6 +335,7 @@ $table2->data[0][3] = $html_menu_export;
$searchForm = '<form method="post" action="'.$url.'&pure='.$config['pure'].'" class="mrgn_right_0px">';
$searchForm .= html_print_table($table2, true);
$searchForm .= html_print_input_hidden('id_report', $id_report, true);
$Actionbuttons = '';
if ((bool) is_metaconsole() === true) {
$Actionbuttons .= html_print_submit_button(

View File

@ -1638,6 +1638,7 @@ CREATE TABLE IF NOT EXISTS `treport_content` (
`cat_security_hardening` INT NOT NULL DEFAULT 0,
`ignore_skipped` INT NOT NULL DEFAULT 0,
`status_of_check` TINYTEXT,
`ncm_agents` MEDIUMTEXT,
`check_unknowns_graph` tinyint DEFAULT '0',
PRIMARY KEY(`id_rc`),
FOREIGN KEY (`id_report`) REFERENCES treport(`id_report`)
@ -4187,6 +4188,29 @@ CREATE TABLE IF NOT EXISTS `tncm_template_scripts` (
FOREIGN KEY (`id_script`) REFERENCES `tncm_script`(`id`) ON UPDATE CASCADE ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=UTF8MB4;
-- ----------------------------------------------------------------------
-- Table `tncm_agent_data_template`
-- ----------------------------------------------------------------------
CREATE TABLE IF NOT EXISTS `tncm_agent_data_template` (
`id` SERIAL,
`name` TEXT,
`vendors` TEXT,
`models` TEXT,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=UTF8MB4;
-- ----------------------------------------------------------------------
-- Table `tncm_agent_data_template_scripts`
-- ----------------------------------------------------------------------
CREATE TABLE IF NOT EXISTS `tncm_agent_data_template_scripts` (
`id` SERIAL,
`id_agent_data_template` BIGINT UNSIGNED NOT NULL,
`id_script` BIGINT UNSIGNED NOT NULL,
PRIMARY KEY (`id`),
FOREIGN KEY (`id_agent_data_template`) REFERENCES `tncm_agent_data_template`(`id`) ON UPDATE CASCADE ON DELETE CASCADE,
FOREIGN KEY (`id_script`) REFERENCES `tncm_script`(`id`) ON UPDATE CASCADE ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=UTF8MB4;
-- ----------------------------------------------------------------------
-- Table `tncm_agent`
-- ----------------------------------------------------------------------
@ -4202,10 +4226,13 @@ CREATE TABLE IF NOT EXISTS `tncm_agent` (
`updated_at` BIGINT NOT NULL DEFAULT 0,
`config_backup_id` BIGINT UNSIGNED DEFAULT NULL,
`id_template` BIGINT UNSIGNED,
`id_agent_data_template` BIGINT UNSIGNED,
`execute_type` INT UNSIGNED NOT NULL DEFAULT 0,
`execute` INT UNSIGNED NOT NULL DEFAULT 0,
`cron_interval` VARCHAR(100) DEFAULT '',
`agent_data_cron_interval` VARCHAR(100) DEFAULT '',
`event_on_change` INT UNSIGNED DEFAULT null,
`agent_data_event_on_change` INT UNSIGNED DEFAULT null,
`last_error` TEXT,
PRIMARY KEY (`id_agent`),
FOREIGN KEY (`id_agent`) REFERENCES `tagente`(`id_agente`) ON UPDATE CASCADE ON DELETE CASCADE,
@ -4222,6 +4249,7 @@ CREATE TABLE IF NOT EXISTS `tncm_agent_data` (
`id` SERIAL,
`id_agent` INT UNSIGNED NOT NULL,
`script_type` INT UNSIGNED NOT NULL,
`id_agent_data` INT NOT NULL DEFAULT 0,
`data` LONGBLOB,
`status` INT NOT NULL DEFAULT 5,
`updated_at` BIGINT NOT NULL DEFAULT 0,
@ -4235,8 +4263,10 @@ CREATE TABLE IF NOT EXISTS `tncm_queue` (
`id` SERIAL,
`id_agent` INT UNSIGNED NOT NULL,
`id_script` BIGINT UNSIGNED NOT NULL,
`id_agent_data` bigint unsigned,
`utimestamp` INT UNSIGNED NOT NULL,
`scheduled` INT UNSIGNED DEFAULT NULL,
`snippet` TEXT NULL,
FOREIGN KEY (`id_agent`) REFERENCES `tagente`(`id_agente`) ON UPDATE CASCADE ON DELETE CASCADE,
FOREIGN KEY (`id_script`) REFERENCES `tncm_script`(`id`) ON UPDATE CASCADE ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=UTF8MB4;

View File

@ -2524,11 +2524,31 @@ INSERT INTO `tncm_vendor` (`id`, `name`) VALUES
(11, 'Netlink'),
(12, 'Ascom'),
(13, 'Synology Inc.'),
(14, 'Fujitsu Network Communications, Inc.');
(14, 'Fujitsu Network Communications, Inc.'),
(15, 'Juniper'),
(16, 'Palo&#x20;Alto'),
(17, 'A10'),
(18, 'Aruba');
INSERT INTO `tncm_model` VALUES (1,1,'7200');
INSERT INTO `tncm_model` VALUES
(1,1,'7200'),
(2,1,'Cisco-Generic'),
(3,15,'Juniper-Generic'),
(4,16,'Palo&#x20;Alto-Generic'),
(5,17,'A10-Generic'),
(6,4,'Alcatel-Generic'),
(7,18,'Aruba-Generic'),
(8,3,'Mikrotik-Generic');
INSERT INTO `tncm_template` VALUES (1,'cisco-base','[\"1\"]','[\"1\"]');
INSERT INTO `tncm_template` VALUES
(1,'cisco-base','[\"1\"]','[\"1\"]'),
(2,'Cisco-Generic','[\"1\"]','[\"2\"]'),
(3,'Juniper-Generic','[\"15\"]','[\"3\"]'),
(4,'Palo&#x20;Alto-Generic','[\"16\"]','[\"4\"]'),
(5,'A10-Generic','[\"17\"]','[\"5\"]'),
(6,'Alcatel-Generic','[\"4\"]','[\"6\"]'),
(7,'Aruba-Generic','[\"18\"]','[\"7\"]'),
(8,'Mikrotik-Generic','[\"3\"]','[\"8\"]');
INSERT INTO `tncm_script` VALUES
(1,0,'enable&#x0d;&#x0a;expect:Password:&#92;s*&#x0d;&#x0a;_enablepass_&#x0d;&#x0a;exit'),
@ -2536,9 +2556,125 @@ INSERT INTO `tncm_script` VALUES
(3,2,'enable&#x0d;&#x0a;expect:Password:&#92;s*&#x0d;&#x0a;_enablepass_&#x0d;&#x0a;term&#x20;length&#x20;0&#x0d;&#x0a;config&#x20;terminal&#x0d;&#x0a;_applyconfigbackup_&#x0d;&#x0a;exit&#x0d;&#x0a;'),
(4,3,'enable&#x0d;&#x0a;expect:Password:&#92;s*&#x0d;&#x0a;_enablepass_&#x0d;&#x0a;term&#x20;length&#x20;0&#x0d;&#x0a;capture:show&#x20;version&#x20;|&#x20;i&#x20;IOS&#x20;Software&#x0d;&#x0a;exit&#x0d;&#x0a;'),
(5,5,'enable&#x0d;&#x0a;expect:Password:&#92;s*&#x0d;&#x0a;_enablepass_&#x0d;&#x0a;term&#x20;length&#x20;0&#x0d;&#x0a;config&#x20;term&#x0d;&#x0a;end&#x0d;&#x0a;end&#x0d;&#x0a;exit&#x0d;&#x0a;'),
(6,4,'copy&#x20;tftp&#x20;flash&#x0d;&#x0a;expect:&#92;]&#92;?&#x0d;&#x0a;_TFTP_SERVER_IP_&#x0d;&#x0a;expect:&#92;]&#92;?&#x0d;&#x0a;_SOURCE_FILE_NAME_&#x0d;&#x0a;expect:&#92;]&#92;?&#x0d;&#x0a;_DESTINATION_FILE_NAME_&#x0d;&#x0a;show&#x20;flash&#x0d;&#x0a;reload&#x0d;&#x0a;expect:confirm&#x0d;&#x0a;y&#x0d;&#x0a;config&#x20;terminal&#x0d;&#x0a;boot&#x20;system&#x20;_DESTINATION_FILE_NAME_');
(6,4,'copy&#x20;tftp&#x20;flash&#x0d;&#x0a;expect:&#92;]&#92;?&#x0d;&#x0a;_TFTP_SERVER_IP_&#x0d;&#x0a;expect:&#92;]&#92;?&#x0d;&#x0a;_SOURCE_FILE_NAME_&#x0d;&#x0a;expect:&#92;]&#92;?&#x0d;&#x0a;firmware.bin&#x0d;&#x0a;show&#x20;flash&#x0d;&#x0a;reload&#x0d;&#x0a;expect:confirm&#x0d;&#x0a;y&#x0d;&#x0a;config&#x20;terminal&#x0d;&#x0a;boot&#x20;system&#x20;firmware.bin'),
(7,0,'enable&#92;n&#x0d;&#x0a;expect:Password:&#92;s*&#x0d;&#x0a;_enablepass_&#92;n&#x0d;&#x0a;exit&#92;n'),
(8,1,'enable&#92;n&#x0d;&#x0a;expect:Password:&#92;s*&#x0d;&#x0a;_enablepass_&#92;n&#x0d;&#x0a;term&#x20;length&#x20;0&#92;n&#x0d;&#x0a;capture:show&#x20;running-config&#92;n&#x0d;&#x0a;exit&#92;n'),
(9,2,'enable&#92;n&#x0d;&#x0a;expect:Password:&#92;s*&#x0d;&#x0a;_enablepass_&#92;n&#x0d;&#x0a;term&#x20;length&#x20;0&#92;n&#x0d;&#x0a;config&#x20;terminal&#92;n&#x0d;&#x0a;_applyconfigbackup_&#92;n&#x0d;&#x0a;exit&#92;n'),
(10,3,'enable&#92;n&#x0d;&#x0a;expect:Password:&#92;s*&#x0d;&#x0a;_enablepass_&#92;n&#x0d;&#x0a;term&#x20;length&#x20;0&#92;n&#x0d;&#x0a;capture:show&#x20;version&#x20;|&#x20;i&#x20;IOS&#x20;Software&#92;n&#x0d;&#x0a;exit&#92;n'),
(11,4,'copy&#x20;tftp&#x20;flash&#92;n&#x0d;&#x0a;expect:&#92;]&#92;?&#x0d;&#x0a;_TFTP_SERVER_IP_&#92;n&#x0d;&#x0a;expect:&#92;]&#92;?&#x0d;&#x0a;_SOURCE_FILE_NAME_&#92;n&#x0d;&#x0a;expect:&#92;]&#92;?&#x0d;&#x0a;firmware.bin&#92;n&#x0d;&#x0a;show&#x20;flash&#92;n&#x0d;&#x0a;reload&#92;n&#x0d;&#x0a;expect:confirm&#x0d;&#x0a;y&#92;n&#x0d;&#x0a;config&#x20;terminal&#92;n&#x0d;&#x0a;boot&#x20;system&#x20;firmware.bin&#92;n'),
(12,5,''),
(13,7,'enable&#92;n&#x0d;&#x0a;expect:Password:&#92;s*&#x0d;&#x0a;_enablepass_&#92;n&#x0d;&#x0a;term&#x20;length&#x20;0&#92;n&#x0d;&#x0a;capture:show&#x20;version&#x20;|&#x20;i&#x20;IOS&#x20;Software&#92;n&#x0d;&#x0a;exit&#92;n'),
(14,0,'expect:root@%&#x0d;&#x0a;cli&#92;n&#x0d;&#x0a;exit&#92;n'),
(15,1,'expect:root@%&#x0d;&#x0a;cli&#92;n&#x0d;&#x0a;expect:root&gt;&#x0d;&#x0a;capture:show&#x20;configuration&#x20;|&#x20;no-more&#92;n&#x0d;&#x0a;capture:&#92;n&#x0d;&#x0a;quit&#92;n&#x0d;&#x0a;expect:root@%&#x0d;&#x0a;exit&#92;n'),
(16,2,'expect:root@%&#x0d;&#x0a;cli&#92;n&#x0d;&#x0a;expect:root&gt;&#x0d;&#x0a;configure&#92;n&#x0d;&#x0a;load&#x20;override&#x20;terminal&#92;n&#x0d;&#x0a;_applyconfigbackup_&#92;n&#x0d;&#x0a;commit&#92;n&#x0d;&#x0a;exit&#92;n'),
(17,3,'expect:root@%&#x0d;&#x0a;cli&#92;n&#x0d;&#x0a;expect:root&gt;&#x0d;&#x0a;capture:show&#x20;version|match&#x20;Junos:&#92;n&#x0d;&#x0a;capture:&#x20;&#92;n&#x0d;&#x0a;quit&#92;n&#x0d;&#x0a;expect:root@%&#x0d;&#x0a;exit&#92;n'),
(18,4,'expect:root@%&#x0d;&#x0a;cli&#92;n&#x0d;&#x0a;expect:root&gt;&#x0d;&#x0a;save&#x20;software&#x20;from&#x20;tftp&#x20;_TFTP_SERVER_IP_&#x20;_FIRMWARE_NAME_&#x20;to&#x20;flash&#92;n&#x0d;&#x0a;reset&#92;n&#x0d;&#x0a;exit&#92;n'),
(19,5,''),
(20,7,'expect:root@%&#x0d;&#x0a;cli&#92;n&#x0d;&#x0a;expect:root&gt;&#x0d;&#x0a;capture:show&#x20;version|match&#x20;Junos:&#92;n&#x0d;&#x0a;capture:&#x20;&#92;n&#x0d;&#x0a;quit&#92;n&#x0d;&#x0a;expect:root@%&#x0d;&#x0a;exit&#92;n'),
(21,0,'sleep:1&#x0d;&#x0a;exit&#92;n'),
(22,1,'set&#x20;cli&#x20;pager&#x20;off&#x20;&#92;n&#x0d;&#x0a;capture:show&#x20;config&#x20;running&#92;n&#x0d;&#x0a;exit&#92;n'),
(23,2,'set&#x20;cli&#x20;terminal&#x20;width&#x20;500&#92;n&#x0d;&#x0a;set&#x20;cli&#x20;scripting-mode&#x20;on&#92;n&#x0d;&#x0a;configure&#92;n&#x0d;&#x0a;_applyconfigbackup_&#92;n&#x0d;&#x0a;commit&#92;n'),
(24,3,'set&#x20;cli&#x20;pager&#x20;off&#x20;&#92;n&#x0d;&#x0a;capture:show&#x20;system&#x20;info&#x20;|&#x20;match&#x20;app-version:&#92;n&#x0d;&#x0a;sleep:1&#x20;&#x0d;&#x0a;expect:app-version:&#92;s*&#x0d;&#x0a;exit&#x20;&#92;n'),
(25,4,'tftp&#x20;import&#x20;software&#x20;from&#x20;_TFTP_SERVER_IP_&#x20;file&#x20;_FIRMWARE_NAME_&#92;n&#x0d;&#x0a;request&#x20;system&#x20;software&#x20;install&#x20;version&#92;n&#x0d;&#x0a;reboot&#92;n&#x0d;&#x0a;exit&#92;n'),
(26,5,''),
(27,7,'set&#x20;cli&#x20;pager&#x20;off&#x20;&#92;n&#x0d;&#x0a;capture:show&#x20;system&#x20;info&#x20;|&#x20;match&#x20;app-version:&#92;n&#x0d;&#x0a;sleep:1&#x20;&#x0d;&#x0a;expect:app-version:&#92;s*&#x0d;&#x0a;exit&#x20;&#92;n'),
(28,0,'sleep:1&#x0d;&#x0a;enable&#92;n&#x0d;&#x0a;expect:Password:&#92;s*&#x0d;&#x0a;_enablepass_&#92;n'),
(29,1,'sleep:1&#x0d;&#x0a;enable&#92;n&#x0d;&#x0a;expect:Password:&#92;s*&#x0d;&#x0a;_enablepass_&#92;n&#x0d;&#x0a;capture:show&#x20;running-config&#92;n&#x0d;&#x0a;exit&#92;n'),
(30,2,'sleep:1&#x0d;&#x0a;enable&#92;n&#x0d;&#x0a;expect:Password:&#92;s*&#x0d;&#x0a;_enablepass_&#92;n&#x0d;&#x0a;configure&#92;n&#x0d;&#x0a;_applyconfigbackup_&#92;n&#x0d;&#x0a;exit&#92;n'),
(31,3,'sleep:1&#x0d;&#x0a;enable&#92;n&#x0d;&#x0a;expect:Password:&#92;s*&#x0d;&#x0a;_enablepass_&#92;n&#x0d;&#x0a;capture:show&#x20;version&#92;n&#x0d;&#x0a;exit&#92;n'),
(32,4,'sleep:1&#x0d;&#x0a;enable&#92;n&#x0d;&#x0a;expect:Password:&#92;s*&#x0d;&#x0a;_enablepass_&#92;n&#x0d;&#x0a;configure&#92;n&#x0d;&#x0a;expect:&#40;config&#41;&#x0d;&#x0a;restore&#x20;_TFTP_SERVER_IP_/_FIRMWARE_NAME_&#92;n&#x0d;&#x0a;expect:Password:&#92;s*&#x0d;&#x0a;_enablepass_&#92;n&#x0d;&#x0a;expect:skip&#x20;port&#x20;map&#x0d;&#x0a;yes&#92;n&#x0d;&#x0a;expect:&#x20;see&#x20;the&#x20;diff&#x0d;&#x0a;yes&#92;n&#x0d;&#x0a;sleep:1&#x0d;&#x0a;expect:Proceed&#x20;with&#x20;reboot&#x0d;&#x0a;yes&#92;n&#x0d;&#x0a;expect:eof'),
(33,5,''),
(34,7,'sleep:1&#x0d;&#x0a;enable&#92;n&#x0d;&#x0a;expect:Password:&#92;s*&#x0d;&#x0a;_enablepass_&#92;n&#x0d;&#x0a;capture:show&#x20;version&#92;n&#x0d;&#x0a;exit&#92;n'),
(35,0,'enable&#92;n&#x0d;&#x0a;expect:Password:&#92;s*&#x0d;&#x0a;_enablepass_&#92;n&#x0d;&#x0a;exit&#92;n'),
(36,1,'enable&#92;n&#x0d;&#x0a;expect:Password:&#92;s*&#x0d;&#x0a;_enablepass_&#92;n&#x0d;&#x0a;capture:admin&#x20;display-config&#92;n&#x0d;&#x0a;logout&#92;n'),
(37,2,''),
(38,3,'enable&#92;n&#x0d;&#x0a;expect:Password:&#92;s*&#x0d;&#x0a;_enablepass_&#92;n&#x0d;&#x0a;capture:show&#x20;version&#92;n&#x0d;&#x0a;logout&#92;n'),
(39,4,''),
(40,5,''),
(41,7,'enable&#92;n&#x0d;&#x0a;expect:Password:&#92;s*&#x0d;&#x0a;_enablepass_&#92;n&#x0d;&#x0a;capture:show&#x20;version&#92;n&#x0d;&#x0a;logout&#92;n'),
(42,0,'enable&#92;n&#x0d;&#x0a;expect:Password:&#92;s*&#x0d;&#x0a;_enablepass_&#92;n&#x0d;&#x0a;exit&#92;n'),
(43,1,'enable&#92;n&#x0d;&#x0a;expect:Password:&#92;s*&#x0d;&#x0a;_enablepass_&#92;n&#x0d;&#x0a;capture:show&#x20;running-config&#92;n&#x0d;&#x0a;exit&#92;n'),
(44,2,'configure&#x20;terminal&#92;n&#x0d;&#x0a;load&#x20;replace&#x20;/var/tmp/file.conf&#92;n&#x0d;&#x0a;end&#92;n&#x0d;&#x0a;write&#x20;memory&#92;n&#x0d;&#x0a;exit&#92;n'),
(45,3,'enable&#92;n&#x0d;&#x0a;expect:Password:&#92;s*&#x0d;&#x0a;_enablepass_&#92;n&#x0d;&#x0a;capture:show&#x20;version&#92;n&#x0d;&#x0a;exit&#92;n'),
(46,4,'copy&#x20;tftp&#x20;flash&#x20;_TFTP_SERVER_IP_&#x20;firmware.bin.swi&#x20;secondary&#92;n&#x0d;&#x0a;boot&#x20;system&#x20;flash&#x20;secondary&#92;n&#x0d;&#x0a;copy&#x20;tftp&#x20;flash&#x20;&#x20;_TFTP_SERVER_IP_&#x20;firmware.bin&#x20;primary&#92;n&#x0d;&#x0a;boot&#x20;system&#x20;flash&#x20;primary&#92;n'),
(47,5,''),
(48,7,'enable&#92;n&#x0d;&#x0a;expect:Password:&#92;s*&#x0d;&#x0a;_enablepass_&#92;n&#x0d;&#x0a;capture:show&#x20;version&#92;n&#x0d;&#x0a;exit&#92;n'),
(49,0,'sleep:1&#x0d;&#x0a;exit&#92;n&#92;r'),
(50,1,'sleep:1&#x0d;&#x0a;capture:system&#x20;resource&#x20;print&#92;n&#92;r&#x20;&#x0d;&#x0a;exit&#92;n&#92;r'),
(51,2,'sleep:1&#x0d;&#x0a;system&#x20;backup&#x20;load&#x20;name=_nameBackup_&#x20;password=_passwordBackup_&#92;n&#92;r&#x0d;&#x0a;expect:Restore&#x0d;&#x0a;yes&#92;n&#92;r&#x0d;&#x0a;exit&#92;n&#92;r'),
(52,3,'sleep:1&#x0d;&#x0a;capture:/system&#x20;package&#x20;print&#92;n&#92;r&#x20;&#x0d;&#x0a;exit&#92;n&#92;r'),
(53,4,'sleep:1&#x0d;&#x0a;/system&#x20;routerboard&#x20;upgrade&#92;n&#92;r&#x0d;&#x0a;expect:Do&#x0d;&#x0a;yes&#92;n&#92;r&#x0d;&#x0a;exit&#92;n&#92;r'),
(54,5,''),
(55,7,'sleep:1&#x0d;&#x0a;capture:/system&#x20;package&#x20;print&#92;n&#92;r&#x20;&#x0d;&#x0a;exit&#92;n&#92;r'),
(56,6,'snippet');
INSERT INTO `tncm_template_scripts`(`id_template`, `id_script`) VALUES (1,1),(1,2),(1,3),(1,4),(1,5),(1,6);
INSERT INTO `tncm_template_scripts`(`id_template`, `id_script`) VALUES
(1,1),
(1,2),
(1,3),
(1,4),
(1,5),
(1,6),
(2,7),
(2,8),
(2,9),
(2,10),
(2,11),
(2,12),
(3,14),
(3,15),
(3,16),
(3,17),
(3,18),
(3,19),
(4,21),
(4,22),
(4,23),
(4,24),
(4,25),
(4,26),
(5,28),
(5,29),
(5,30),
(5,31),
(5,32),
(5,33),
(6,35),
(6,36),
(6,37),
(6,38),
(6,39),
(6,40),
(7,42),
(7,43),
(7,44),
(7,45),
(7,46),
(7,47),
(8,49),
(8,50),
(8,51),
(8,52),
(8,53),
(8,54);
INSERT INTO `tncm_agent_data_template` VALUES
(1,'Cisco-Generic','[\"1\"]','[\"2\"]'),
(2,'Juniper-Generic','[\"15\"]','[\"3\"]'),
(3,'Palo&#x20;Alto-Generic','[\"16\"]','[\"4\"]'),
(4,'A10-Generic','[\"17\"]','[\"5\"]'),
(5,'Alcatel-Generic','[\"4\"]','[\"6\"]'),
(6,'Aruba-Generic','[\"18\"]','[\"7\"]'),
(7,'Mikrotik-Generic','[\"3\"]','[\"8\"]');
INSERT INTO `tncm_agent_data_template_scripts`(`id_agent_data_template`, `id_script`) VALUES
(1,13),
(2,20),
(3,27),
(4,34),
(5,41),
(6,48),
(7,55);
INSERT INTO `talert_calendar` VALUES (1, 'Default', 0, 'Default calendar');

View File

@ -39,7 +39,7 @@ def _print_debug(
####
# Internal use only: Get AES cipher
#########################################################################################
def _get_cipher(
def _get_cipher_AES(
password: str = _PASSWORD
) -> AES:
'''
@ -78,7 +78,7 @@ def encrypt_AES(
Returns:
str: The encrypted string in base64 encoding.
'''
cipher = _get_cipher(password)
cipher = _get_cipher_AES(password)
try:
msg_padded = pad(str_to_encrypt.encode(), AES.block_size, style='pkcs7')
@ -106,7 +106,7 @@ def decrypt_AES(
Returns:
str: The decrypted string.
'''
cipher = _get_cipher(password)
cipher = _get_cipher_AES(password)
try:
decrypted_str = unpad(cipher.decrypt(base64.b64decode(str_to_decrypt)), AES.block_size, style='pkcs7').decode().strip()
@ -114,3 +114,83 @@ def decrypt_AES(
decrypted_str = ''
return decrypted_str
####
# Internal use only: Get Rijndael cipher
#########################################################################################
def _get_cipher_Rijndael(
password: str = _PASSWORD
) -> AES:
'''
Internal use only: Get Rijndael cipher for encryption and decryption.
Args:
password (str): The password used to derive the encryption key.
Returns:
AES: An AES cipher instance for encryption and decryption.
'''
key = b''
msg = password.encode('utf-8')
hash_obj = hmac.new(key, msg, hashlib.sha256)
hash_result = hash_obj.digest()
hash_base64 = base64.b64encode(hash_result)[:16].decode()
return AES.new(hash_base64.encode(), AES.MODE_ECB)
####
# Return encrypted string
#########################################################################################
def encrypt_Rijndael(
str_to_encrypt: str = "",
password: str = _PASSWORD
) -> str:
'''
Encrypt a string using Rijndael encryption.
Args:
str_to_encrypt (str): The string to be encrypted.
password (str): The password used to derive the encryption key.
Returns:
str: The encrypted string in base64 encoding.
'''
cipher = _get_cipher_Rijndael(password)
try:
padded_data = str_to_encrypt.encode()
missing = 16 - (len(padded_data) % 16)
padded_data += bytes([0] * missing) if missing != 16 else b''
b64str = base64.b64encode(cipher.encrypt(padded_data)).decode()
except:
b64str = ''
return b64str
####
# Return decrypted string
#########################################################################################
def decrypt_Rijndael(
str_to_decrypt: str = "",
password: str = _PASSWORD
) -> str:
'''
Decrypt an encrypted string using Rijndael decryption.
Args:
str_to_decrypt (str): The encrypted string to be decrypted.
password (str): The password used to derive the encryption key.
Returns:
str: The decrypted string.
'''
cipher = _get_cipher_Rijndael(password)
try:
decrypted_data = cipher.decrypt(base64.b64decode(str_to_decrypt))
decrypted_str = decrypted_data.rstrip(b'\x00').decode()
except:
decrypted_str = ''
return decrypted_str