mirror of
https://github.com/jokob-sk/NetAlertX.git
synced 2025-12-07 09:36:05 -08:00
Sync Hub fix + overriddenByEnv
This commit is contained in:
@@ -8,7 +8,7 @@ There are 3 artifacts that can be used to backup the application:
|
|||||||
| File | Description | Limitations |
|
| File | Description | Limitations |
|
||||||
|-----------------------|-------------------------------|-------------------------------|
|
|-----------------------|-------------------------------|-------------------------------|
|
||||||
| `/db/app.db` | Database file(s) | The database file might be in an uncommitted state or corrupted |
|
| `/db/app.db` | Database file(s) | The database file might be in an uncommitted state or corrupted |
|
||||||
| `/config/app.conf` | Configuration file | Can be overriden with the [`APP_CONF_OVERRIDE` env variable](https://github.com/jokob-sk/NetAlertX/tree/main/dockerfiles#docker-environment-variables). |
|
| `/config/app.conf` | Configuration file | Can be overridden with the [`APP_CONF_OVERRIDE` env variable](https://github.com/jokob-sk/NetAlertX/tree/main/dockerfiles#docker-environment-variables). |
|
||||||
| `/config/devices.csv` | CSV file containing device information | Doesn't contain historical data |
|
| `/config/devices.csv` | CSV file containing device information | Doesn't contain historical data |
|
||||||
|
|
||||||
## Data and backup storage
|
## Data and backup storage
|
||||||
|
|||||||
@@ -1034,7 +1034,7 @@ var mouse = $.widget("ui.mouse", {
|
|||||||
return this.mouseDelayMet;
|
return this.mouseDelayMet;
|
||||||
},
|
},
|
||||||
|
|
||||||
// These are placeholder methods, to be overriden by extending plugin
|
// These are placeholder methods, to be overridden by extending plugin
|
||||||
_mouseStart: function(/* event */) {},
|
_mouseStart: function(/* event */) {},
|
||||||
_mouseDrag: function(/* event */) {},
|
_mouseDrag: function(/* event */) {},
|
||||||
_mouseStop: function(/* event */) {},
|
_mouseStop: function(/* event */) {},
|
||||||
|
|||||||
@@ -783,7 +783,7 @@
|
|||||||
setCache(key, target.replaceAll(":","_")+'_id') // _id is added so it doesn't conflict with AdminLTE tab behavior
|
setCache(key, target.replaceAll(":","_")+'_id') // _id is added so it doesn't conflict with AdminLTE tab behavior
|
||||||
}
|
}
|
||||||
|
|
||||||
// get the tab id from the cookie (already overriden by the target)
|
// get the tab id from the cookie (already overridden by the target)
|
||||||
if(!emptyArr.includes(getCache(key)))
|
if(!emptyArr.includes(getCache(key)))
|
||||||
{
|
{
|
||||||
selectedTab = getCache(key);
|
selectedTab = getCache(key);
|
||||||
|
|||||||
@@ -420,7 +420,7 @@ $settingsJSON_DB = json_encode($settings, JSON_HEX_TAG | JSON_HEX_AMP | JSON_HEX
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
// OVERRIDE
|
// OVERRIDE
|
||||||
// surface settings override functionality if the setting is a template that can be overriden with user defined values
|
// surface settings override functionality if the setting is a template that can be overridden with user defined values
|
||||||
// if the setting is a json of the correct structure, handle like a template setting
|
// if the setting is a json of the correct structure, handle like a template setting
|
||||||
|
|
||||||
let overrideHtml = "";
|
let overrideHtml = "";
|
||||||
@@ -428,7 +428,7 @@ $settingsJSON_DB = json_encode($settings, JSON_HEX_TAG | JSON_HEX_AMP | JSON_HEX
|
|||||||
//pre-check if this is a json object that needs value extraction
|
//pre-check if this is a json object that needs value extraction
|
||||||
|
|
||||||
let overridable = false; // indicates if the setting is overridable
|
let overridable = false; // indicates if the setting is overridable
|
||||||
let override = false; // If the setting is set to be overriden by the user or by default
|
let override = false; // If the setting is set to be overridden by the user or by default
|
||||||
let readonly = ""; // helper variable to make text input readonly
|
let readonly = ""; // helper variable to make text input readonly
|
||||||
let disabled = ""; // helper variable to make checkbox input readonly
|
let disabled = ""; // helper variable to make checkbox input readonly
|
||||||
|
|
||||||
|
|||||||
@@ -213,15 +213,16 @@ class DB():
|
|||||||
self.sql.execute(""" DROP TABLE IF EXISTS Settings;""")
|
self.sql.execute(""" DROP TABLE IF EXISTS Settings;""")
|
||||||
self.sql.execute("""
|
self.sql.execute("""
|
||||||
CREATE TABLE "Settings" (
|
CREATE TABLE "Settings" (
|
||||||
"Code_Name" TEXT,
|
"Code_Name" TEXT,
|
||||||
"Display_Name" TEXT,
|
"Display_Name" TEXT,
|
||||||
"Description" TEXT,
|
"Description" TEXT,
|
||||||
"Type" TEXT,
|
"Type" TEXT,
|
||||||
"Options" TEXT,
|
"Options" TEXT,
|
||||||
"RegEx" TEXT,
|
"RegEx" TEXT,
|
||||||
"Value" TEXT,
|
"Group" TEXT,
|
||||||
"Group" TEXT,
|
"Value" TEXT,
|
||||||
"Events" TEXT
|
"Events" TEXT,
|
||||||
|
"OverriddenByEnv" INTEGER
|
||||||
);
|
);
|
||||||
""")
|
""")
|
||||||
|
|
||||||
|
|||||||
@@ -319,7 +319,7 @@ def get_setting_value(key):
|
|||||||
set_type = 'Error: Not handled'
|
set_type = 'Error: Not handled'
|
||||||
set_value = 'Error: Not handled'
|
set_value = 'Error: Not handled'
|
||||||
|
|
||||||
set_value = setting["Value"] # Setting value (Value (upper case) = user overriden default_value)
|
set_value = setting["Value"] # Setting value (Value (upper case) = user overridden default_value)
|
||||||
set_type = setting["Type"] # Setting type # lower case "type" - default json value vs uppper-case "Type" (= from user defined settings)
|
set_type = setting["Type"] # Setting type # lower case "type" - default json value vs uppper-case "Type" (= from user defined settings)
|
||||||
|
|
||||||
value = setting_value_to_python_type(set_type, set_value)
|
value = setting_value_to_python_type(set_type, set_value)
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ from notification import write_notification
|
|||||||
|
|
||||||
#-------------------------------------------------------------------------------
|
#-------------------------------------------------------------------------------
|
||||||
# managing application settings, ensuring SQL safety for user input, and updating internal configuration lists
|
# managing application settings, ensuring SQL safety for user input, and updating internal configuration lists
|
||||||
def ccd(key, default, config_dir, name, inputtype, options, group, events=None, desc="", regex="", setJsonMetadata=None, overrideTemplate=None, forceDefault=False):
|
def ccd(key, default, config_dir, name, inputtype, options, group, events=None, desc="", regex="", setJsonMetadata=None, overrideTemplate=None, forceDefault=False, overriddenByEnv=0):
|
||||||
if events is None:
|
if events is None:
|
||||||
events = []
|
events = []
|
||||||
if setJsonMetadata is None:
|
if setJsonMetadata is None:
|
||||||
@@ -50,8 +50,8 @@ def ccd(key, default, config_dir, name, inputtype, options, group, events=None,
|
|||||||
result = result.replace('\'', "{s-quote}")
|
result = result.replace('\'', "{s-quote}")
|
||||||
|
|
||||||
# Create the tuples
|
# Create the tuples
|
||||||
sql_safe_tuple = (key, name, desc, str(inputtype), options, regex, str(result), group, str(events))
|
sql_safe_tuple = (key, name, desc, str(inputtype), options, regex, str(result), group, str(events), overriddenByEnv)
|
||||||
settings_tuple = (key, name, desc, inputtype, options, regex, result, group, str(events))
|
settings_tuple = (key, name, desc, inputtype, options, regex, result, group, str(events), overriddenByEnv)
|
||||||
|
|
||||||
# Update or append the tuples in the lists
|
# Update or append the tuples in the lists
|
||||||
conf.mySettingsSQLsafe = update_or_append(conf.mySettingsSQLsafe, sql_safe_tuple, key)
|
conf.mySettingsSQLsafe = update_or_append(conf.mySettingsSQLsafe, sql_safe_tuple, key)
|
||||||
@@ -59,7 +59,7 @@ def ccd(key, default, config_dir, name, inputtype, options, group, events=None,
|
|||||||
|
|
||||||
# Save metadata in dummy setting if not a metadata key
|
# Save metadata in dummy setting if not a metadata key
|
||||||
if '__metadata' not in key:
|
if '__metadata' not in key:
|
||||||
metadata_tuple = (f'{key}__metadata', "metadata name", "metadata desc", '{"dataType":"json", "elements": [{"elementType" : "textarea", "elementOptions" : [{"readonly": "true"}] ,"transformers": []}]}', '[]', "", json.dumps(setJsonMetadata), group, '[]')
|
metadata_tuple = (f'{key}__metadata', "metadata name", "metadata desc", '{"dataType":"json", "elements": [{"elementType" : "textarea", "elementOptions" : [{"readonly": "true"}] ,"transformers": []}]}', '[]', "", json.dumps(setJsonMetadata), group, '[]', overriddenByEnv)
|
||||||
conf.mySettingsSQLsafe = update_or_append(conf.mySettingsSQLsafe, metadata_tuple, f'{key}__metadata')
|
conf.mySettingsSQLsafe = update_or_append(conf.mySettingsSQLsafe, metadata_tuple, f'{key}__metadata')
|
||||||
conf.mySettings = update_or_append(conf.mySettings, metadata_tuple, f'{key}__metadata')
|
conf.mySettings = update_or_append(conf.mySettings, metadata_tuple, f'{key}__metadata')
|
||||||
|
|
||||||
@@ -298,7 +298,7 @@ def importConfigs (db, all_plugins):
|
|||||||
# -----------------
|
# -----------------
|
||||||
# Plugins END
|
# Plugins END
|
||||||
|
|
||||||
# TODO check app_conf_override.json
|
# HANDLE APP_CONF_OVERRIDE via app_conf_override.json
|
||||||
# Assuming fullConfFolder is defined elsewhere
|
# Assuming fullConfFolder is defined elsewhere
|
||||||
app_conf_override_path = fullConfFolder + '/app_conf_override.json'
|
app_conf_override_path = fullConfFolder + '/app_conf_override.json'
|
||||||
|
|
||||||
@@ -315,12 +315,12 @@ def importConfigs (db, all_plugins):
|
|||||||
# Log the value being passed
|
# Log the value being passed
|
||||||
# ccd(key, default, config_dir, name, inputtype, options, group, events=None, desc="", regex="", setJsonMetadata=None, overrideTemplate=None, forceDefault=False)
|
# ccd(key, default, config_dir, name, inputtype, options, group, events=None, desc="", regex="", setJsonMetadata=None, overrideTemplate=None, forceDefault=False)
|
||||||
mylog('debug', [f"[Config] Setting override {setting_name} with value: {value}"])
|
mylog('debug', [f"[Config] Setting override {setting_name} with value: {value}"])
|
||||||
ccd(setting_name, value, c_d, '_KEEP_', '_KEEP_', '_KEEP_', '_KEEP_', None, "_KEEP_", "", None, None, True)
|
ccd(setting_name, value, c_d, '_KEEP_', '_KEEP_', '_KEEP_', '_KEEP_', None, "_KEEP_", "", None, None, True, 1)
|
||||||
else:
|
else:
|
||||||
# Convert to string and log
|
# Convert to string and log
|
||||||
# ccd(key, default, config_dir, name, inputtype, options, group, events=None, desc="", regex="", setJsonMetadata=None, overrideTemplate=None, forceDefault=False)
|
# ccd(key, default, config_dir, name, inputtype, options, group, events=None, desc="", regex="", setJsonMetadata=None, overrideTemplate=None, forceDefault=False)
|
||||||
mylog('debug', [f"[Config] Setting override {setting_name} with value: {str(value)}"])
|
mylog('debug', [f"[Config] Setting override {setting_name} with value: {str(value)}"])
|
||||||
ccd(setting_name, str(value), c_d, '_KEEP_', '_KEEP_', '_KEEP_', '_KEEP_', None, "_KEEP_", "", None, None, True)
|
ccd(setting_name, str(value), c_d, '_KEEP_', '_KEEP_', '_KEEP_', '_KEEP_', None, "_KEEP_", "", None, None, True, 1)
|
||||||
|
|
||||||
except json.JSONDecodeError:
|
except json.JSONDecodeError:
|
||||||
mylog('none', [f"[Config] [ERROR] Setting override decoding JSON from {app_conf_override_path}"])
|
mylog('none', [f"[Config] [ERROR] Setting override decoding JSON from {app_conf_override_path}"])
|
||||||
@@ -348,8 +348,9 @@ def importConfigs (db, all_plugins):
|
|||||||
|
|
||||||
# Insert settings into the DB
|
# Insert settings into the DB
|
||||||
sql.execute ("DELETE FROM Settings")
|
sql.execute ("DELETE FROM Settings")
|
||||||
|
# mylog('debug', [f"[Config] conf.mySettingsSQLsafe : '{conf.mySettingsSQLsafe}'"])
|
||||||
sql.executemany ("""INSERT INTO Settings ("Code_Name", "Display_Name", "Description", "Type", "Options",
|
sql.executemany ("""INSERT INTO Settings ("Code_Name", "Display_Name", "Description", "Type", "Options",
|
||||||
"RegEx", "Value", "Group", "Events" ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)""", conf.mySettingsSQLsafe)
|
"RegEx", "Value", "Group", "Events", "OverriddenByEnv" ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)""", conf.mySettingsSQLsafe)
|
||||||
|
|
||||||
db.commitDB()
|
db.commitDB()
|
||||||
|
|
||||||
|
|||||||
@@ -249,6 +249,10 @@ def execute_plugin(db, all_plugins, plugin, pluginsState = plugins_state() ):
|
|||||||
for line in newLines:
|
for line in newLines:
|
||||||
columns = line.split("|")
|
columns = line.split("|")
|
||||||
# There have to be 9 or 13 columns
|
# There have to be 9 or 13 columns
|
||||||
|
if len(columns) not in [9, 13]:
|
||||||
|
mylog('none', [f'[Plugins] Wrong number of input values, must be 9 or 13, got {len(columns)} from: {line}'])
|
||||||
|
continue # Skip lines with incorrect number of columns
|
||||||
|
|
||||||
# Common part of the SQL parameters
|
# Common part of the SQL parameters
|
||||||
base_params = [
|
base_params = [
|
||||||
0, # "Index" placeholder
|
0, # "Index" placeholder
|
||||||
@@ -284,8 +288,6 @@ def execute_plugin(db, all_plugins, plugin, pluginsState = plugins_state() ):
|
|||||||
'null', # "HelpVal3"
|
'null', # "HelpVal3"
|
||||||
'null' # "HelpVal4"
|
'null' # "HelpVal4"
|
||||||
])
|
])
|
||||||
else:
|
|
||||||
mylog('none', [f'[Plugins] Wrong number of input values, must be 9 or 13, got {len(columns)} from: {line} '])
|
|
||||||
|
|
||||||
# Create a tuple containing values to be inserted into the database.
|
# Create a tuple containing values to be inserted into the database.
|
||||||
# Each value corresponds to a column in the table in the order of the columns.
|
# Each value corresponds to a column in the table in the order of the columns.
|
||||||
|
|||||||
Reference in New Issue
Block a user