Plugins 0.4 - UI work + refactoring

This commit is contained in:
Jokob-sk
2023-03-09 22:30:36 +11:00
parent 176a436ad4
commit 5a8be94cdc
6 changed files with 131 additions and 25 deletions

View File

@@ -67,7 +67,7 @@
case 'create': create($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 'delete': delete($skipCache, $defaultValue, $expireMinutes, $dbtable, $columns, $values); break;
case 'delete': delete($key, $id, $dbtable); break;
default: logServerConsole ('Action: '. $action); break;
}
}
@@ -80,6 +80,7 @@ function update($key, $id, $skipCache, $defaultValue, $expireMinutes, $dbtable,
global $db;
// handle one or multiple columns
if(strpos($columns, ',') !== false)
{
$columnsArr = explode(",", $columns);
@@ -88,6 +89,7 @@ function update($key, $id, $skipCache, $defaultValue, $expireMinutes, $dbtable,
$columnsArr = array($columns);
}
// handle one or multiple values
if(strpos($values, ',') !== false)
{
$valuesArr = explode(",", $values);
@@ -145,7 +147,33 @@ function create($skipCache, $defaultValue, $expireMinutes, $dbtable, $columns, $
$result = $db->query($sql);
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;
}
}

View File

@@ -49,8 +49,6 @@ function getFormControl(dbColumnDef, value, index) {
break;
case 'textboxsave':
console.log(value)
value = value == 'null' ? '' : value; // hide 'null' values
id = `${dbColumnDef.column}_${index}`
@@ -207,6 +205,8 @@ function generateTabs()
$.each(pluginDefinitions, function(index, obj) {
headersHtml = ""
// headers = []
colDefinitions = []
@@ -235,7 +235,7 @@ function generateTabs()
{
clm += '<td>'+ pluginUnprocessedEvents[i][colDefinitions[j].column] +'</td>'
}
evRows += '<tr>' + clm + '</tr>'
evRows += `<tr data-my-index="${pluginUnprocessedEvents[i]["Index"]}" >${clm}</tr>`
eveCount++;
}
}
@@ -252,7 +252,7 @@ function generateTabs()
{
clm += '<td>'+ pluginHistory[i][colDefinitions[j].column] +'</td>'
}
hiRows += '<tr>' + clm + '</tr>'
hiRows += `<tr data-my-index="${pluginHistory[i]["Index"]}" >${clm}</tr>`
histCount++;
}
}
@@ -269,7 +269,7 @@ function generateTabs()
{
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++;
}
}
@@ -280,7 +280,7 @@ function generateTabs()
<div id="${obj.unique_prefix}" class="tab-pane ${activetab}">
<div class="nav-tabs-custom" style="margin-bottom: 0px">
<ul class="nav nav-tabs">
<li class="active">
<li class="active" >
<a href="#objectsTarget_${obj.unique_prefix}" data-toggle="tab" >
<i class="fa fa-cube"></i> <?= lang('Plugins_Objects');?> (${obCount})
@@ -288,7 +288,7 @@ function generateTabs()
</a>
</li>
<li>
<li >
<a href="#eventsTarget_${obj.unique_prefix}" data-toggle="tab" >
<i class="fa fa-bolt"></i> <?= lang('Plugins_Unprocessed_Events');?> (${eveCount})
@@ -296,7 +296,7 @@ function generateTabs()
</a>
</li>
<li>
<li >
<a href="#historyTarget_${obj.unique_prefix}" data-toggle="tab" >
<i class="fa fa-clock"></i> <?= lang('Plugins_History');?> (${histCount})
@@ -311,7 +311,7 @@ function generateTabs()
<div class="tab-content">
<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>
<tr>
${headersHtml}
@@ -319,9 +319,12 @@ function generateTabs()
${obRows}
</tbody>
</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 id="eventsTarget_${obj.unique_prefix}" class="tab-pane">
<table class="table table-striped">
<table class="table table-striped" data-my-dbtable="Plugins_Events">
<tbody>
<tr>
@@ -330,9 +333,12 @@ function generateTabs()
${evRows}
</tbody>
</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 id="historyTarget_${obj.unique_prefix}" class="tab-pane">
<table class="table table-striped">
<table class="table table-striped" data-my-dbtable="Plugins_History">
<tbody>
<tr>
@@ -341,7 +347,11 @@ function generateTabs()
${hiRows}
</tbody>
</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>
@@ -356,8 +366,72 @@ function generateTabs()
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()

View File

@@ -1,11 +1,12 @@
{
"code_name": "nmap_services",
"unique_prefix": "NMAPSRV",
"unique_prefix": "NMAPSRV",
"enabled": true,
"data_source": "pialert-db-query",
"localized": ["display_name", "description", "icon"],
"display_name" : [{
"language_code":"en_us",
"string" : "Services"
"string" : "Services (NMAP)"
}],
"icon":[{
"language_code":"en_us",

View File

@@ -1,6 +1,7 @@
{
"code_name": "website_monitor",
"unique_prefix": "WEBMON",
"unique_prefix": "WEBMON",
"enabled": true,
"data_source": "python-script",
"localized": ["display_name", "description", "icon"],
"display_name" : [{