Deleting Plugin Objects was not possible #1486

Signed-off-by: jokob-sk <jokob.sk@gmail.com>
This commit is contained in:
jokob-sk
2026-02-05 11:57:37 +11:00
parent 76d37edc63
commit 1b6dc94bae
4 changed files with 29 additions and 16 deletions

View File

@@ -572,7 +572,7 @@ function purgeAllExecute() {
data: JSON.stringify({ data: JSON.stringify({
dbtable: dbTable, dbtable: dbTable,
columnName: 'Plugin', columnName: 'Plugin',
id: plugPrefix id: [plugPrefix]
}), }),
contentType: "application/json", contentType: "application/json",
success: function(response, textStatus) { success: function(response, textStatus) {
@@ -603,15 +603,18 @@ function deleteListed(plugPrefixArg, dbTableArg) {
// Ask for confirmation // Ask for confirmation
showModalWarning(`${getString('Gen_Purge')} ${plugPrefix} ${dbTable}`, `${getString('Gen_AreYouSure')} (${idArr.length})`, showModalWarning(`${getString('Gen_Purge')} ${plugPrefix} ${dbTable}`, `${getString('Gen_AreYouSure')} (${idArr.length})`,
`${getString('Gen_Cancel')}`, `${getString('Gen_Okay')}`, "deleteListedExecute"); `${getString('Gen_Cancel')}`, `${getString('Gen_Okay')}`, () => deleteListedExecute(idArr));
} }
// -------------------------------------------------------- // --------------------------------------------------------
function deleteListedExecute() { function deleteListedExecute(idArr) {
const apiBase = getApiBase(); const apiBase = getApiBase();
const apiToken = getSetting("API_TOKEN"); const apiToken = getSetting("API_TOKEN");
const url = `${apiBase}/dbquery/delete`; const url = `${apiBase}/dbquery/delete`;
console.log(idArr);
$.ajax({ $.ajax({
method: "POST", method: "POST",
url: url, url: url,
@@ -619,7 +622,7 @@ function deleteListedExecute() {
data: JSON.stringify({ data: JSON.stringify({
dbtable: dbTable, dbtable: dbTable,
columnName: 'Index', columnName: 'Index',
id: idArr.toString() id: idArr
}), }),
contentType: "application/json", contentType: "application/json",
success: function(response, textStatus) { success: function(response, textStatus) {

View File

@@ -1287,14 +1287,22 @@ def dbquery_update(payload=None):
def dbquery_delete(payload=None): def dbquery_delete(payload=None):
data = request.get_json() or {} data = request.get_json() or {}
required = ["columnName", "id", "dbtable"] required = ["columnName", "id", "dbtable"]
if not all(data.get(k) for k in required): if not all(k in data and data[k] for k in required):
return jsonify({"success": False, "message": "ERROR: Missing parameters", "error": "Missing required 'columnName', 'id', or 'dbtable' query parameter"}), 400 return jsonify({
"success": False,
"message": "ERROR: Missing parameters",
"error": "Missing required 'columnName', 'id', or 'dbtable' query parameter"
}), 400
return delete_query( dbtable = data["dbtable"]
column_name=data["columnName"], column_name = data["columnName"]
ids=data["id"], ids = data["id"]
dbtable=data["dbtable"],
) # Ensure ids is a list
if not isinstance(ids, list):
ids = [ids]
return delete_query(column_name, ids, dbtable)
# -------------------------- # --------------------------

View File

@@ -11,6 +11,7 @@ INSTALL_PATH = os.getenv("NETALERTX_APP", "/app")
sys.path.extend([f"{INSTALL_PATH}/front/plugins", f"{INSTALL_PATH}/server"]) sys.path.extend([f"{INSTALL_PATH}/front/plugins", f"{INSTALL_PATH}/server"])
from database import get_temp_db_connection # noqa: E402 [flake8 lint suppression] from database import get_temp_db_connection # noqa: E402 [flake8 lint suppression]
from logger import mylog # noqa: E402 [flake8 lint suppression]
def read_query(raw_sql_b64): def read_query(raw_sql_b64):
@@ -82,17 +83,18 @@ def delete_query(column_name, ids, dbtable):
conn = get_temp_db_connection() conn = get_temp_db_connection()
cur = conn.cursor() cur = conn.cursor()
if not isinstance(ids, list):
ids = [ids]
deleted_count = 0 deleted_count = 0
for id_val in ids: for id_val in ids:
sql = f"DELETE FROM {dbtable} WHERE {column_name} = ?" # Wrap table and column in quotes to handle reserved words
sql = f'DELETE FROM "{dbtable}" WHERE "{column_name}" = ?'
mylog("debug", f"[delete_query] sql {sql} with id={id_val}")
cur.execute(sql, (id_val,)) cur.execute(sql, (id_val,))
deleted_count += cur.rowcount deleted_count += cur.rowcount
conn.commit() conn.commit()
conn.close() conn.close()
return jsonify({"success": True, "deleted_count": deleted_count}) return jsonify({"success": True, "deleted_count": deleted_count})
except Exception as e: except Exception as e:
return jsonify({"success": False, "error": str(e)}), 400 return jsonify({"success": False, "error": str(e)}), 400

View File

@@ -44,7 +44,7 @@ ALLOWED_NMAP_MODES = Literal[
NOTIFICATION_LEVELS = Literal["info", "warning", "error", "alert", "interrupt"] NOTIFICATION_LEVELS = Literal["info", "warning", "error", "alert", "interrupt"]
ALLOWED_TABLES = Literal["Devices", "Events", "Sessions", "Settings", "CurrentScan", "Online_History", "Plugins_Objects"] ALLOWED_TABLES = Literal["Devices", "Events", "Sessions", "Settings", "CurrentScan", "Online_History", "Plugins_Objects", "Plugins_History"]
ALLOWED_LOG_FILES = Literal[ ALLOWED_LOG_FILES = Literal[
"app.log", "app_front.log", "IP_changes.log", "stdout.log", "stderr.log", "app.log", "app_front.log", "IP_changes.log", "stdout.log", "stderr.log",