mirror of
https://github.com/jokob-sk/NetAlertX.git
synced 2025-12-07 09:36:05 -08:00
Plugins 0.4 - UI work + refactoring
This commit is contained in:
@@ -465,13 +465,15 @@ def importConfigs ():
|
|||||||
# -----------------
|
# -----------------
|
||||||
plugins = get_plugins_configs()
|
plugins = get_plugins_configs()
|
||||||
|
|
||||||
mylog('none', ['[', timeNow(), '] Plugins: Number of dynamically loaded plugins: ', len(plugins.dict)])
|
mylog('none', ['[', timeNow(), '] Plugins: Number of dynamically loaded plugins: ', len(plugins.list)])
|
||||||
|
|
||||||
# handle plugins
|
# handle plugins
|
||||||
for plugin in plugins.list:
|
for plugin in plugins.list:
|
||||||
print_plugin_info(plugin, ['display_name','description'])
|
print_plugin_info(plugin, ['display_name','description'])
|
||||||
|
|
||||||
pref = plugin["unique_prefix"]
|
pref = plugin["unique_prefix"]
|
||||||
|
|
||||||
|
# if plugin["enabled"] == 'true':
|
||||||
|
|
||||||
# collect plugin level language strings
|
# collect plugin level language strings
|
||||||
collect_lang_strings(plugin, pref)
|
collect_lang_strings(plugin, pref)
|
||||||
@@ -3657,25 +3659,25 @@ def isNewVersion():
|
|||||||
return newVersionAvailable
|
return newVersionAvailable
|
||||||
|
|
||||||
|
|
||||||
|
#-------------------------------------------------------------------------------
|
||||||
#-------------------------------------------------------------------------------
|
#-------------------------------------------------------------------------------
|
||||||
# Plugins
|
# Plugins
|
||||||
#-------------------------------------------------------------------------------
|
#-------------------------------------------------------------------------------
|
||||||
|
#-------------------------------------------------------------------------------
|
||||||
def get_plugins_configs():
|
def get_plugins_configs():
|
||||||
|
|
||||||
pluginsDict = []
|
pluginsDict = []
|
||||||
pluginsList = []
|
pluginsList = []
|
||||||
|
|
||||||
for root, dirs, files in os.walk(pluginsPath):
|
for root, dirs, files in os.walk(pluginsPath):
|
||||||
for d in dirs: # Loop over directories, not files
|
for d in dirs: # Loop over directories, not files
|
||||||
pluginsDict.append(json.loads(get_file_content(pluginsPath + "/" + d + '/config.json'), object_hook=custom_plugin_decoder))
|
|
||||||
pluginsList.append(json.loads(get_file_content(pluginsPath + "/" + d + '/config.json')))
|
pluginsList.append(json.loads(get_file_content(pluginsPath + "/" + d + '/config.json')))
|
||||||
|
|
||||||
return plugins_class(pluginsDict, pluginsList)
|
return plugins_class(pluginsDict, pluginsList)
|
||||||
|
|
||||||
#-------------------------------------------------------------------------------
|
#-------------------------------------------------------------------------------
|
||||||
class plugins_class:
|
class plugins_class:
|
||||||
def __init__(self, dict, list):
|
def __init__(self, list):
|
||||||
self.dict = dict
|
|
||||||
self.list = list
|
self.list = list
|
||||||
|
|
||||||
#-------------------------------------------------------------------------------
|
#-------------------------------------------------------------------------------
|
||||||
|
|||||||
@@ -7,9 +7,9 @@ services:
|
|||||||
network_mode: "host"
|
network_mode: "host"
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
volumes:
|
volumes:
|
||||||
- ${APP_DATA_LOCATION}/pialert/config2:/home/pi/pialert/config
|
- ${APP_DATA_LOCATION}/pialert/config:/home/pi/pialert/config
|
||||||
# - ${APP_DATA_LOCATION}/pialert/db/pialert.db:/home/pi/pialert/db/pialert.db
|
# - ${APP_DATA_LOCATION}/pialert/db/pialert.db:/home/pi/pialert/db/pialert.db
|
||||||
- ${APP_DATA_LOCATION}/pialert/db2:/home/pi/pialert/db
|
- ${APP_DATA_LOCATION}/pialert/db:/home/pi/pialert/db
|
||||||
# (optional) useful for debugging if you have issues setting up the container
|
# (optional) useful for debugging if you have issues setting up the container
|
||||||
- ${LOGS_LOCATION}:/home/pi/pialert/front/log
|
- ${LOGS_LOCATION}:/home/pi/pialert/front/log
|
||||||
# DELETE START anyone trying to use this file: comment out / delete BELOW lines, they are only for development purposes
|
# DELETE START anyone trying to use this file: comment out / delete BELOW lines, they are only for development purposes
|
||||||
|
|||||||
@@ -67,7 +67,7 @@
|
|||||||
case 'create': create($skipCache, $defaultValue, $expireMinutes, $dbtable, $columns, $values ); break;
|
case 'create': create($skipCache, $defaultValue, $expireMinutes, $dbtable, $columns, $values ); break;
|
||||||
// case 'read' : read($skipCache, $defaultValue, $expireMinutes, $dbtable, $columns, $values); break;
|
// case 'read' : read($skipCache, $defaultValue, $expireMinutes, $dbtable, $columns, $values); break;
|
||||||
case 'update': update($key, $id, $skipCache, $defaultValue, $expireMinutes, $dbtable, $columns, $values); break;
|
case 'update': update($key, $id, $skipCache, $defaultValue, $expireMinutes, $dbtable, $columns, $values); break;
|
||||||
// case 'delete': delete($skipCache, $defaultValue, $expireMinutes, $dbtable, $columns, $values); break;
|
case 'delete': delete($key, $id, $dbtable); break;
|
||||||
default: logServerConsole ('Action: '. $action); break;
|
default: logServerConsole ('Action: '. $action); break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -80,6 +80,7 @@ function update($key, $id, $skipCache, $defaultValue, $expireMinutes, $dbtable,
|
|||||||
|
|
||||||
global $db;
|
global $db;
|
||||||
|
|
||||||
|
// handle one or multiple columns
|
||||||
if(strpos($columns, ',') !== false)
|
if(strpos($columns, ',') !== false)
|
||||||
{
|
{
|
||||||
$columnsArr = explode(",", $columns);
|
$columnsArr = explode(",", $columns);
|
||||||
@@ -88,6 +89,7 @@ function update($key, $id, $skipCache, $defaultValue, $expireMinutes, $dbtable,
|
|||||||
$columnsArr = array($columns);
|
$columnsArr = array($columns);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// handle one or multiple values
|
||||||
if(strpos($values, ',') !== false)
|
if(strpos($values, ',') !== false)
|
||||||
{
|
{
|
||||||
$valuesArr = explode(",", $values);
|
$valuesArr = explode(",", $values);
|
||||||
@@ -145,7 +147,33 @@ function create($skipCache, $defaultValue, $expireMinutes, $dbtable, $columns, $
|
|||||||
$result = $db->query($sql);
|
$result = $db->query($sql);
|
||||||
|
|
||||||
if (! $result == TRUE) {
|
if (! $result == TRUE) {
|
||||||
echo "Error creating etry\n\n$sql \n\n". $db->lastErrorMsg();
|
echo "Error creating entry\n\n$sql \n\n". $db->lastErrorMsg();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
// delete
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
function delete($key, $id, $dbtable)
|
||||||
|
{
|
||||||
|
global $db;
|
||||||
|
|
||||||
|
// handle one or multiple ids
|
||||||
|
if(strpos($id, ',') !== false)
|
||||||
|
{
|
||||||
|
$idsArr = explode(",", $id);
|
||||||
|
}else
|
||||||
|
{
|
||||||
|
$idsArr = array($id);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Insert new value
|
||||||
|
$sql = 'DELETE FROM '.$dbtable.' WHERE "'.$key.'" IN ('. $id .')';
|
||||||
|
$result = $db->query($sql);
|
||||||
|
|
||||||
|
if (! $result == TRUE) {
|
||||||
|
echo "Error deleting entry\n\n$sql \n\n". $db->lastErrorMsg();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -49,8 +49,6 @@ function getFormControl(dbColumnDef, value, index) {
|
|||||||
break;
|
break;
|
||||||
case 'textboxsave':
|
case 'textboxsave':
|
||||||
|
|
||||||
console.log(value)
|
|
||||||
|
|
||||||
value = value == 'null' ? '' : value; // hide 'null' values
|
value = value == 'null' ? '' : value; // hide 'null' values
|
||||||
|
|
||||||
id = `${dbColumnDef.column}_${index}`
|
id = `${dbColumnDef.column}_${index}`
|
||||||
@@ -207,6 +205,8 @@ function generateTabs()
|
|||||||
|
|
||||||
$.each(pluginDefinitions, function(index, obj) {
|
$.each(pluginDefinitions, function(index, obj) {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
headersHtml = ""
|
headersHtml = ""
|
||||||
// headers = []
|
// headers = []
|
||||||
colDefinitions = []
|
colDefinitions = []
|
||||||
@@ -235,7 +235,7 @@ function generateTabs()
|
|||||||
{
|
{
|
||||||
clm += '<td>'+ pluginUnprocessedEvents[i][colDefinitions[j].column] +'</td>'
|
clm += '<td>'+ pluginUnprocessedEvents[i][colDefinitions[j].column] +'</td>'
|
||||||
}
|
}
|
||||||
evRows += '<tr>' + clm + '</tr>'
|
evRows += `<tr data-my-index="${pluginUnprocessedEvents[i]["Index"]}" >${clm}</tr>`
|
||||||
eveCount++;
|
eveCount++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -252,7 +252,7 @@ function generateTabs()
|
|||||||
{
|
{
|
||||||
clm += '<td>'+ pluginHistory[i][colDefinitions[j].column] +'</td>'
|
clm += '<td>'+ pluginHistory[i][colDefinitions[j].column] +'</td>'
|
||||||
}
|
}
|
||||||
hiRows += '<tr>' + clm + '</tr>'
|
hiRows += `<tr data-my-index="${pluginHistory[i]["Index"]}" >${clm}</tr>`
|
||||||
histCount++;
|
histCount++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -269,7 +269,7 @@ function generateTabs()
|
|||||||
{
|
{
|
||||||
clm += '<td>'+ getFormControl(colDefinitions[j], pluginObjects[i][colDefinitions[j].column], pluginObjects[i]["Index"]) +'</td>'
|
clm += '<td>'+ getFormControl(colDefinitions[j], pluginObjects[i][colDefinitions[j].column], pluginObjects[i]["Index"]) +'</td>'
|
||||||
}
|
}
|
||||||
obRows += '<tr>' + clm + '</tr>'
|
obRows += `<tr data-my-index="${pluginObjects[i]["Index"]}" >${clm}</tr>`
|
||||||
obCount++;
|
obCount++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -280,7 +280,7 @@ function generateTabs()
|
|||||||
<div id="${obj.unique_prefix}" class="tab-pane ${activetab}">
|
<div id="${obj.unique_prefix}" class="tab-pane ${activetab}">
|
||||||
<div class="nav-tabs-custom" style="margin-bottom: 0px">
|
<div class="nav-tabs-custom" style="margin-bottom: 0px">
|
||||||
<ul class="nav nav-tabs">
|
<ul class="nav nav-tabs">
|
||||||
<li class="active">
|
<li class="active" >
|
||||||
<a href="#objectsTarget_${obj.unique_prefix}" data-toggle="tab" >
|
<a href="#objectsTarget_${obj.unique_prefix}" data-toggle="tab" >
|
||||||
|
|
||||||
<i class="fa fa-cube"></i> <?= lang('Plugins_Objects');?> (${obCount})
|
<i class="fa fa-cube"></i> <?= lang('Plugins_Objects');?> (${obCount})
|
||||||
@@ -288,7 +288,7 @@ function generateTabs()
|
|||||||
</a>
|
</a>
|
||||||
</li>
|
</li>
|
||||||
|
|
||||||
<li>
|
<li >
|
||||||
<a href="#eventsTarget_${obj.unique_prefix}" data-toggle="tab" >
|
<a href="#eventsTarget_${obj.unique_prefix}" data-toggle="tab" >
|
||||||
|
|
||||||
<i class="fa fa-bolt"></i> <?= lang('Plugins_Unprocessed_Events');?> (${eveCount})
|
<i class="fa fa-bolt"></i> <?= lang('Plugins_Unprocessed_Events');?> (${eveCount})
|
||||||
@@ -296,7 +296,7 @@ function generateTabs()
|
|||||||
</a>
|
</a>
|
||||||
</li>
|
</li>
|
||||||
|
|
||||||
<li>
|
<li >
|
||||||
<a href="#historyTarget_${obj.unique_prefix}" data-toggle="tab" >
|
<a href="#historyTarget_${obj.unique_prefix}" data-toggle="tab" >
|
||||||
|
|
||||||
<i class="fa fa-clock"></i> <?= lang('Plugins_History');?> (${histCount})
|
<i class="fa fa-clock"></i> <?= lang('Plugins_History');?> (${histCount})
|
||||||
@@ -311,7 +311,7 @@ function generateTabs()
|
|||||||
<div class="tab-content">
|
<div class="tab-content">
|
||||||
|
|
||||||
<div id="objectsTarget_${obj.unique_prefix}" class="tab-pane ${activetab}">
|
<div id="objectsTarget_${obj.unique_prefix}" class="tab-pane ${activetab}">
|
||||||
<table class="table table-striped">
|
<table class="table table-striped" data-my-dbtable="Plugins_Objects">
|
||||||
<tbody>
|
<tbody>
|
||||||
<tr>
|
<tr>
|
||||||
${headersHtml}
|
${headersHtml}
|
||||||
@@ -319,9 +319,12 @@ function generateTabs()
|
|||||||
${obRows}
|
${obRows}
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
|
<div class="plugin-obj-purge">
|
||||||
|
<button class="btn btn-primary" onclick="purgeAll('${obj.unique_prefix}', 'Plugins_Objects' )"><?= lang('Gen_Purge');?></button>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div id="eventsTarget_${obj.unique_prefix}" class="tab-pane">
|
<div id="eventsTarget_${obj.unique_prefix}" class="tab-pane">
|
||||||
<table class="table table-striped">
|
<table class="table table-striped" data-my-dbtable="Plugins_Events">
|
||||||
|
|
||||||
<tbody>
|
<tbody>
|
||||||
<tr>
|
<tr>
|
||||||
@@ -330,9 +333,12 @@ function generateTabs()
|
|||||||
${evRows}
|
${evRows}
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
|
<div class="plugin-obj-purge">
|
||||||
|
<button class="btn btn-primary" onclick="purgeAll('${obj.unique_prefix}', 'Plugins_Events' )"><?= lang('Gen_Purge');?></button>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div id="historyTarget_${obj.unique_prefix}" class="tab-pane">
|
<div id="historyTarget_${obj.unique_prefix}" class="tab-pane">
|
||||||
<table class="table table-striped">
|
<table class="table table-striped" data-my-dbtable="Plugins_History">
|
||||||
|
|
||||||
<tbody>
|
<tbody>
|
||||||
<tr>
|
<tr>
|
||||||
@@ -341,7 +347,11 @@ function generateTabs()
|
|||||||
${hiRows}
|
${hiRows}
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
</div>
|
<div class="plugin-obj-purge">
|
||||||
|
<button class="btn btn-primary" onclick="purgeAll('${obj.unique_prefix}', 'Plugins_History' )"><?= lang('Gen_Purge');?></button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -356,8 +366,72 @@ function generateTabs()
|
|||||||
|
|
||||||
activetab = '' // only first tab is active
|
activetab = '' // only first tab is active
|
||||||
});
|
});
|
||||||
|
|
||||||
|
initTabs()
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// --------------------------------------------------------
|
||||||
|
var lastPrefix = ''
|
||||||
|
function initTabs()
|
||||||
|
{
|
||||||
|
// events on tab change
|
||||||
|
$('a[data-toggle="tab"]').on('shown.bs.tab', function (e) {
|
||||||
|
var target = $(e.target).attr("href") // activated tab
|
||||||
|
|
||||||
|
// save the last prefix
|
||||||
|
if(target.includes('_') == false )
|
||||||
|
{
|
||||||
|
lastPrefix = target.split('#')[1]
|
||||||
|
}
|
||||||
|
|
||||||
|
// show the objectsTarget if no specific pane selected or if selected is
|
||||||
|
|
||||||
|
if($('#objectsTarget_'+ lastPrefix).is(":hidden") && $('#eventsTarget_'+ lastPrefix).is(":hidden") && $('#historyTarget_'+ lastPrefix).is(":hidden"))
|
||||||
|
{
|
||||||
|
$('#objectsTarget_'+ lastPrefix).show();
|
||||||
|
} else
|
||||||
|
{
|
||||||
|
$('#objectsTarget_'+ lastPrefix).hide();
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
}
|
||||||
|
// --------------------------------------------------------
|
||||||
|
plugPrefix = ''
|
||||||
|
dbTable = ''
|
||||||
|
|
||||||
|
function purgeAll(callback) {
|
||||||
|
plugPrefix = arguments[0]; // plugin prefix
|
||||||
|
dbTable = arguments[1]; // DB table
|
||||||
|
// Ask
|
||||||
|
showModalWarning('<?= lang('Gen_Purge');?>' + ' ' + plugPrefix + ' ' + dbTable , '<?= lang('Gen_AreYouSure');?>',
|
||||||
|
'<?= lang('Gen_Cancel');?>', '<?= lang('Gen_Okay');?>', "purgeAllExecute");
|
||||||
|
}
|
||||||
|
|
||||||
|
// --------------------------------------------------------
|
||||||
|
dbIndexes = ''
|
||||||
|
|
||||||
|
function purgeAllExecute() {
|
||||||
|
|
||||||
|
// Execute
|
||||||
|
// console.log("targetLogFile:" + targetLogFile)
|
||||||
|
// console.log("logFileAction:" + logFileAction)
|
||||||
|
|
||||||
|
idArr = $('#NMAPSRV table[data-my-dbtable="Plugins_Objects"] tr[data-my-index]').map(function(){return $(this).attr("data-my-index");}).get();
|
||||||
|
|
||||||
|
$.ajax({
|
||||||
|
method: "POST",
|
||||||
|
url: "php/server/dbHelper.php",
|
||||||
|
data: { action: "delete", dbtable: 'Plugins_Objects', key: 'Index', id:idArr.toString() },
|
||||||
|
success: function(data, textStatus) {
|
||||||
|
showModalOk ('Result', data );
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
getData()
|
getData()
|
||||||
|
|||||||
@@ -1,11 +1,12 @@
|
|||||||
{
|
{
|
||||||
"code_name": "nmap_services",
|
"code_name": "nmap_services",
|
||||||
"unique_prefix": "NMAPSRV",
|
"unique_prefix": "NMAPSRV",
|
||||||
|
"enabled": true,
|
||||||
"data_source": "pialert-db-query",
|
"data_source": "pialert-db-query",
|
||||||
"localized": ["display_name", "description", "icon"],
|
"localized": ["display_name", "description", "icon"],
|
||||||
"display_name" : [{
|
"display_name" : [{
|
||||||
"language_code":"en_us",
|
"language_code":"en_us",
|
||||||
"string" : "Services"
|
"string" : "Services (NMAP)"
|
||||||
}],
|
}],
|
||||||
"icon":[{
|
"icon":[{
|
||||||
"language_code":"en_us",
|
"language_code":"en_us",
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
{
|
{
|
||||||
"code_name": "website_monitor",
|
"code_name": "website_monitor",
|
||||||
"unique_prefix": "WEBMON",
|
"unique_prefix": "WEBMON",
|
||||||
|
"enabled": true,
|
||||||
"data_source": "python-script",
|
"data_source": "python-script",
|
||||||
"localized": ["display_name", "description", "icon"],
|
"localized": ["display_name", "description", "icon"],
|
||||||
"display_name" : [{
|
"display_name" : [{
|
||||||
|
|||||||
Reference in New Issue
Block a user