Plugins filter + #253

This commit is contained in:
Jokob-sk
2023-07-21 08:19:11 +10:00
parent 98745805d3
commit 43c0df086a
10 changed files with 68 additions and 26 deletions

View File

@@ -505,6 +505,7 @@ $lang['en_us'] = array(
'Plugins_Unprocessed_Events' => 'Unprocessed Events',
'Plugins_Objects' => 'Plugin Objects',
'Plugins_DeleteAll' => 'Delete all (filters are ignored)',
'Plugins_History' => 'Events History',
//////////////////////////////////////////////////////////////////
@@ -534,6 +535,8 @@ The arp-scan time itself depends on the number of IP addresses to check so set t
'TIMEZONE_description' => 'Time zone to display stats correctly. Find your time zone <a target="_blank" href="https://en.wikipedia.org/wiki/List_of_tz_database_time_zones" rel="nofollow">here</a>.',
'ENABLE_PLUGINS_name' => 'Enable Plugins',
'ENABLE_PLUGINS_description' => 'Enables the <a target="_blank" href="https://github.com/jokob-sk/Pi.Alert/tree/main/pialert/plugins">plugins</a> functionality. Loading plugins requires more hardware resources so you might want to disable them on low-powered system.',
'PLUGINS_KEEP_HIST_name' => 'Plugins History',
'PLUGINS_KEEP_HIST_description' => 'How many days of Plugins History scan entries should be kept (globally, not device specific!).',
'PIALERT_WEB_PROTECTION_name' => 'Enable login',
'PIALERT_WEB_PROTECTION_description' => 'When enabled a login dialog is displayed. Read below carefully if you get locked out of your instance.',
'PIALERT_WEB_PASSWORD_name' => 'Login password',
@@ -688,6 +691,7 @@ The arp-scan time itself depends on the number of IP addresses to check so set t
'PHOLUS_DAYS_DATA_name' => 'Data retention',
'PHOLUS_DAYS_DATA_description' => 'How many days of Pholus scan entries should be kept (globally, not device specific!) Enter <code>0</code> to disable.',
// Nmap
'Nmap_display_name' => 'Nmap',
'Nmap_icon' => '<i class="fa fa-ethernet"></i>',

View File

@@ -37,6 +37,7 @@ function initFields() {
getData();
}
}
// -----------------------------------------------------------------------------
@@ -353,7 +354,7 @@ function generateTabs()
</tbody>
</table>
<div class="plugin-obj-purge">
<button class="btn btn-primary" onclick="purgeAll('${pluginObj.unique_prefix}', 'Plugins_Objects' )"><?= lang('Gen_DeleteAll');?></button>
<button class="btn btn-primary" onclick="purgeAll('${pluginObj.unique_prefix}', 'Plugins_Objects' )"><?= lang('Plugins_DeleteAll');?></button>
</div>
</div>
<div id="eventsTarget_${pluginObj.unique_prefix}" class="tab-pane">
@@ -367,7 +368,7 @@ function generateTabs()
</tbody>
</table>
<div class="plugin-obj-purge">
<button class="btn btn-primary" onclick="purgeAll('${pluginObj.unique_prefix}', 'Plugins_Events' )"><?= lang('Gen_DeleteAll');?></button>
<button class="btn btn-primary" onclick="purgeAll('${pluginObj.unique_prefix}', 'Plugins_Events' )"><?= lang('Plugins_DeleteAll');?></button>
</div>
</div>
<div id="historyTarget_${pluginObj.unique_prefix}" class="tab-pane">
@@ -381,7 +382,7 @@ function generateTabs()
</tbody>
</table>
<div class="plugin-obj-purge">
<button class="btn btn-primary" onclick="purgeAll('${pluginObj.unique_prefix}', 'Plugins_History' )"><?= lang('Gen_DeleteAll');?></button>
<button class="btn btn-primary" onclick="purgeAll('${pluginObj.unique_prefix}', 'Plugins_History' )"><?= lang('Plugins_DeleteAll');?></button>
</div>
</div>
@@ -446,38 +447,37 @@ function initTabs()
}
// --------------------------------------------------------
// Filter method taht determines if an entry should be shown
// Filter method that determines if an entry should be shown
function shouldBeShown(entry, pluginObj)
{
if (pluginObj.hasOwnProperty('data_filters')) {
let dataFilters = pluginObj.data_filters;
// Loop through 'data_filters' array
// Loop through 'data_filters' array and appply filters on individual plugin entries
for (let i = 0; i < dataFilters.length; i++) {
compare_field_id = dataFilters[i].compare_field_id;
compare_column = dataFilters[i].compare_column;
compare_operator = dataFilters[i].compare_operator;
compare_js_wrapper = dataFilters[i].compare_js_wrapper;
compare_js_template = dataFilters[i].compare_js_template;
compare_use_quotes = dataFilters[i].compare_use_quotes;
compare_field_id_value = $(`#${compare_field_id}`).val();
if(compare_field_id_value != undefined && compare_field_id_value != '--')
{
// valid value
console.log(compare_field_id_value)
console.log(compare_column)
console.log(compare_operator)
console.log(entry[compare_column])
// valid value
// resolve the left and right part of the comparison
let left = compare_js_wrapper.replace('{value}', `"${compare_field_id_value}"`)
let right = compare_js_wrapper.replace('{value}', `"${entry[compare_column]}"`)
let left = compare_js_template.replace('{value}', `${compare_field_id_value}`)
let right = compare_js_template.replace('{value}', `${entry[compare_column]}`)
// include wrapper quotes if specified
compare_use_quotes ? quotes = '"' : quotes = ''
result = eval(
`${eval(left)}` +
` ${compare_operator} ` +
`${eval(right)}`
quotes + `${eval(left)}` + quotes +
` ${compare_operator} ` +
quotes + `${eval(right)}` + quotes
);
return result;