Validate macros on SQL

This commit is contained in:
Félix Suárez 2024-03-25 15:34:16 -06:00
parent 2054d5b081
commit b67ff002d6
1 changed files with 16 additions and 6 deletions

View File

@ -2408,10 +2408,15 @@ switch ($action) {
$values['server_name'] = get_parameter('combo_server_sql'); $values['server_name'] = get_parameter('combo_server_sql');
if ($sql !== '') { if ($sql !== '') {
// Replaces possible macros to check the validity of the query
$macros_sql = $sql;
$macros_sql = str_replace('_start_date_', '0', $macros_sql);
$macros_sql = str_replace('_end_date_', 'NOW()', $macros_sql);
if ($values['server_name'] === 'all') { if ($values['server_name'] === 'all') {
$servers_connection = metaconsole_get_connections(); $servers_connection = metaconsole_get_connections();
foreach ($servers_connection as $key => $s) { foreach ($servers_connection as $key => $s) {
$good_format = db_validate_sql($sql, $s['server_name']); $good_format = db_validate_sql($macros_sql, $s['server_name']);
} }
// Reconnected in nodo if exist. // Reconnected in nodo if exist.
@ -2423,9 +2428,9 @@ switch ($action) {
} }
} else if ($server_id === 0) { } else if ($server_id === 0) {
// Connect with node if not exist conexion. // Connect with node if not exist conexion.
$good_format = db_validate_sql($sql, (is_metaconsole() === true) ? $values['server_name'] : false); $good_format = db_validate_sql($macros_sql, (is_metaconsole() === true) ? $values['server_name'] : false);
} else { } else {
$good_format = db_validate_sql($sql); $good_format = db_validate_sql($macros_sql);
} }
} }
} else if ($values['type'] == 'url') { } else if ($values['type'] == 'url') {
@ -3353,10 +3358,15 @@ switch ($action) {
if ($sql !== '') { if ($sql !== '') {
// Replaces possible macros to check the validity of the query
$macros_sql = $sql;
$macros_sql = str_replace('_start_date_', '0', $macros_sql);
$macros_sql = str_replace('_end_date_', 'NOW()', $macros_sql);
if ($values['server_name'] === 'all') { if ($values['server_name'] === 'all') {
$servers_connection = metaconsole_get_connections(); $servers_connection = metaconsole_get_connections();
foreach ($servers_connection as $key => $s) { foreach ($servers_connection as $key => $s) {
$good_format = db_validate_sql($sql, $s['server_name']); $good_format = db_validate_sql($macros_sql, $s['server_name']);
} }
// Reconnected in nodo if exist. // Reconnected in nodo if exist.
@ -3368,9 +3378,9 @@ switch ($action) {
} }
} else if ($server_id === 0) { } else if ($server_id === 0) {
// Connect with node if not exist conexion. // Connect with node if not exist conexion.
$good_format = db_validate_sql($sql, (is_metaconsole() === true) ? $values['server_name'] : false); $good_format = db_validate_sql($macros_sql, (is_metaconsole() === true) ? $values['server_name'] : false);
} else { } else {
$good_format = db_validate_sql($sql); $good_format = db_validate_sql($macros_sql);
} }
} }
} else if ($values['type'] == 'url') { } else if ($values['type'] == 'url') {