diff --git a/front/js/settings_utils.js b/front/js/settings_utils.js index 4b903728..cfc0f7ff 100755 --- a/front/js/settings_utils.js +++ b/front/js/settings_utils.js @@ -245,18 +245,28 @@ function settingsCollectedCorrectly(settingsArray, settingsJSON_DB) { // ------------------------------------------------------------------- // --------------------------------------------------------- -function addList(element) +function addList(element, clearInput = true) { const fromId = $(element).attr('my-input-from'); const toId = $(element).attr('my-input-to'); + + input = $(`#${fromId}`).val(); + + console.log(input); + console.log(toId); + console.log($(`#${toId}`)); + $(`#${toId}`).append($("").attr("value", input).text(input)); // clear input - $(`#${fromId}`).val(""); - + if (clearInput) + { + $(`#${fromId}`).val(""); + } + settingsChanged(); } // --------------------------------------------------------- @@ -340,6 +350,8 @@ function initListInteractionOptions(selectorId) { // Perform action based on click count if (clickCounter === 1) { // Single-click action + // btoa(iconHtml.replace(/"/g, "'") <-- encode + // atob() <--- decode showModalFieldInput( ` ${getString('Gen_Update_Value')}`, getString('settings_update_item_warning'), @@ -480,7 +492,7 @@ function getParam(targetId, key, skipCache = false) { // --------------------------------------------------------- // generate a list of options for a input select - function generateInputOptions(pluginsData, set, input, isMultiSelect = false) + function generateOptions(pluginsData, set, input, isMultiSelect = false, isValueSource = true) { multi = isMultiSelect ? "multiple" : ""; @@ -492,15 +504,19 @@ function getParam(targetId, key, skipCache = false) { var targetLocation = set['Code_Name'] + "_initSettingDropdown"; // execute AJAX callabck + SQL query resolution - initSettingDropdown(set['Code_Name'] , valuesArray, targetLocation, generateDropdownOptions) + initSettingDropdown(set['Code_Name'] , valuesArray, targetLocation, generateDropdownOptions); + // generate different ID depending on if it's the source for the value to be saved or only used as an input + isValueSource ? id = set['Code_Name'] : id = set['Code_Name'] + '_input'; + // main selection dropdown wrapper input += ` + id="${id}" + ${multi}> diff --git a/front/maintenance.php b/front/maintenance.php index 8c53a259..c7ed68d5 100755 --- a/front/maintenance.php +++ b/front/maintenance.php @@ -390,7 +390,7 @@ $db->close(); - = lang('Maintenance_Tool_ExportCSV');?> + = lang('Maintenance_Tool_ExportCSV');?> = lang('Maintenance_Tool_ExportCSV_text');?> @@ -640,11 +640,6 @@ function restartBackend() { // ----------------------------------------------------------- // Export CSV -function askExportCSV() { - // Ask - showModalWarning('= lang('Maintenance_Tool_ExportCSV_noti');?>', '= lang('Maintenance_Tool_ExportCSV_noti_text');?>', - '= lang('Gen_Cancel');?>', '= lang('Gen_Okay');?>', 'ExportCSV'); -} function ExportCSV() { // Execute diff --git a/front/network.php b/front/network.php index 41243882..a3639efc 100755 --- a/front/network.php +++ b/front/network.php @@ -528,8 +528,10 @@ for(var i in list) { //... of the current node - if(list[i].parentMac == node.mac && !hiddenMacs.includes(list[i].parentMac)) + + if(list[i].parentMac.toLowerCase() == node.mac.toLowerCase() && !hiddenMacs.includes(list[i].parentMac)) { + visibleNodesCount++ // and process them @@ -570,7 +572,6 @@ function getHierarchy() { - for(i in deviceListGlobal) { if(deviceListGlobal[i].mac == 'Internet') @@ -618,7 +619,7 @@ // Handle network node click - select correct tab in teh bottom table function handleNodeClick(event) { - console.log(event.target.offsetParent.offsetParent) + // console.log(event.target.offsetParent.offsetParent) const targetTabMAC = $(event.target.offsetParent.offsetParent).attr("data-mytreemacmain"); @@ -728,7 +729,7 @@ onNodeClick: (nodeData) => handleNodeClick(nodeData), relationnalField: "children", }); - + console.log(myHierarchy) myTree.refresh(myHierarchy); diff --git a/front/php/server/util.php b/front/php/server/util.php index 7db787b4..8f0e5f26 100755 --- a/front/php/server/util.php +++ b/front/php/server/util.php @@ -353,7 +353,7 @@ function saveSettings() } $txt .= $settingKey . "=" . $val . "\n"; - } elseif ($settingType == 'text.multiselect' || $settingType == 'subnets' || $settingType == 'list' || $settingType == 'list.select') { + } elseif ($settingType == 'text.multiselect' || $settingType == 'subnets' || $settingType == 'list' || $settingType == 'list.select' || $settingType == 'list.base64') { $temp = ''; if(is_array($settingValue) == FALSE) diff --git a/front/plugins/internet_ip/config.json b/front/plugins/internet_ip/config.json index ebfaf8cb..f3315a8f 100755 --- a/front/plugins/internet_ip/config.json +++ b/front/plugins/internet_ip/config.json @@ -279,7 +279,7 @@ "description": [ { "language_code": "en_us", - "string": "Send a notification if selected values change. Use CTRL + Click to select/deselect. Watched_Value1 is Previous IP (not recommended)Watched_Value2 unusedWatched_Value3 unused Watched_Value4 unused " + "string": "Send a notification if selected values change. Use CTRL + Click to select/deselect. Watched_Value1 is Previous IP (not recommended)Watched_Value2 unusedWatched_Value3 unused Watched_Value4 type " }, { "language_code": "de_de", @@ -426,6 +426,22 @@ } ] }, + { + "column": "Watched_Value4", + "mapped_to_column": "cur_Type", + "css_classes": "col-sm-2", + "show": false, + "type": "label", + "default_value": "", + "options": [], + "localized": ["name"], + "name": [ + { + "language_code": "en_us", + "string": "Type" + } + ] + }, { "column": "Dummy", "mapped_to_column": "cur_ScanMethod", diff --git a/front/plugins/internet_ip/script.py b/front/plugins/internet_ip/script.py index 8a5d7693..3c1ab38e 100755 --- a/front/plugins/internet_ip/script.py +++ b/front/plugins/internet_ip/script.py @@ -71,7 +71,7 @@ def main(): watched1 = f'Previous IP: {PREV_IP}', watched2 = cmd_output.replace('\n',''), watched3 = retries_needed, - watched4 = '', + watched4 = 'Gateway', extra = f'Previous IP: {PREV_IP}', foreignKey = 'Internet') diff --git a/front/plugins/newdev_template/config.json b/front/plugins/newdev_template/config.json index dafe94fb..69f23a0c 100755 --- a/front/plugins/newdev_template/config.json +++ b/front/plugins/newdev_template/config.json @@ -630,7 +630,7 @@ }, { "function": "NAME_CLEANUP_REGEX", - "type": "list", + "type": "list.base64", "default_value": ["XC5fYWlycGxheQ==", "XC5fdGNw", "XC5sb2NhbGRvbWFpbg==", "XC5sb2NhbA==", "XC5fZXNwaG9tZWxpYg==", "XC5fZ29vZ2xlY2FzdA==", "XC5sYW4=", "XC5ob21l", "LVthLWZBLUYwLTldezMyfQ==", "Iy4q" ], "options": [], "localized": ["name", "description"], diff --git a/front/plugins/omada_sdn_imp/config.json b/front/plugins/omada_sdn_imp/config.json index 01ec798d..6ec693f2 100755 --- a/front/plugins/omada_sdn_imp/config.json +++ b/front/plugins/omada_sdn_imp/config.json @@ -434,7 +434,7 @@ }, { "column": "Extra", - "mapped_to_column": "cur_NetworkSite", + "mapped_to_column": "cur_Type", "css_classes": "col-sm-2", "show": false, "type": "label", diff --git a/front/plugins/omada_sdn_imp/omada_sdn.py b/front/plugins/omada_sdn_imp/omada_sdn.py index 27075812..cd8f2998 100755 --- a/front/plugins/omada_sdn_imp/omada_sdn.py +++ b/front/plugins/omada_sdn_imp/omada_sdn.py @@ -65,7 +65,7 @@ def main(): mylog('verbose', [f'[{pluginName}] New entries: "{len(new_devices)}"']) # log result - plugin_objects.write_result_file() + # plugin_objects.write_result_file() return 0 diff --git a/front/settings.php b/front/settings.php index a12fbf8d..a77dbead 100755 --- a/front/settings.php +++ b/front/settings.php @@ -26,12 +26,9 @@ $settingsJson = json_decode($data); // get settings from the DB global $db; -global $settingKeyOfLists; $result = $db->query("SELECT * FROM Settings"); -// array -$settingKeyOfLists = array(); $settings = array(); while ($row = $result -> fetchArray (SQLITE3_ASSOC)) { @@ -52,7 +49,6 @@ $settingsJSON_DB = json_encode($settings, JSON_HEX_TAG | JSON_HEX_AMP | JSON_HEX ?> - @@ -253,7 +249,6 @@ $settingsJSON_DB = json_encode($settings, JSON_HEX_TAG | JSON_HEX_AMP | JSON_HEX function initSettingsPage(settingsData, pluginsData){ const settingPluginPrefixes = []; - const settingKeyOfLists = []; const enabledDeviceScanners = getPluginsByType(pluginsData, "device_scanner", true); const enabledOthers = getPluginsByType(pluginsData, "other", true); @@ -470,11 +465,11 @@ $settingsJSON_DB = json_encode($settings, JSON_HEX_TAG | JSON_HEX_AMP | JSON_HEX // --- process text --- if(setType.includes(".select")) { - inputHtml = generateInputOptions(pluginsData, set, inputHtml, isMultiSelect = false) + inputHtml = generateOptions(pluginsData, set, inputHtml, isMultiSelect = false) } else if(setType.includes(".multiselect")) { - inputHtml = generateInputOptions(pluginsData, set, inputHtml, isMultiSelect = true) + inputHtml = generateOptions(pluginsData, set, inputHtml, isMultiSelect = true) } else{ // if it's overridable set readonly accordingly @@ -507,7 +502,7 @@ $settingsJSON_DB = json_encode($settings, JSON_HEX_TAG | JSON_HEX_AMP | JSON_HEX inputHtml = ``; } else if (setType === 'integer.select') { - inputHtml = generateInputOptions(pluginsData, set, inputHtml) + inputHtml = generateOptions(pluginsData, set, inputHtml) } else if (setType === 'subnets') { // --- process subnets --- @@ -543,18 +538,20 @@ $settingsJSON_DB = json_encode($settings, JSON_HEX_TAG | JSON_HEX_AMP | JSON_HEX ${getString("Gen_Remove_All")} `; - } else if (setType === 'list' || setType === 'list.select' || setType === 'list.readonly') { + } else if (setType.startsWith('list')) { // --- process list --- - settingKeyOfLists.push(codeName); - inputHtml += ` ` if(setType.includes(".select")) // not tested { - inputHtml += generateInputOptions(pluginsData, set, inputHtml, isMultiSelect = false) + inputHtml += generateOptions(pluginsData, set, inputHtml, isMultiSelect = false, isValueSource = false) + } + else if(setType.includes(".multiselect")) + { + inputHtml += generateOptions(pluginsData, set, inputHtml, isMultiSelect = true) } else { @@ -565,7 +562,7 @@ $settingsJSON_DB = json_encode($settings, JSON_HEX_TAG | JSON_HEX_AMP | JSON_HEX inputHtml += ` - ${getString("Gen_Add")} + ${getString("Gen_Add")} @@ -623,7 +620,7 @@ $settingsJSON_DB = json_encode($settings, JSON_HEX_TAG | JSON_HEX_AMP | JSON_HEX $(`#${prefix} .panel-body`).append(setHtml); // init remove and edit listitem click gestures - if(['subnets', 'list' ].includes(setType)) + if(['subnets'].includes(setType) || setType.startsWith('list')) { initListInteractionOptions(codeName) } @@ -640,8 +637,6 @@ $settingsJSON_DB = json_encode($settings, JSON_HEX_TAG | JSON_HEX_AMP | JSON_HEX } - - // display the name of the first person // echo $settingsJson[0]->name; var settingsNumberDB = ; @@ -671,52 +666,58 @@ $settingsJSON_DB = json_encode($settings, JSON_HEX_TAG | JSON_HEX_AMP | JSON_HEX var settingsArray = []; // collect values for each of the different input form controls - const noConversion = ['text', 'integer', 'string', 'password', 'readonly', 'text.select', 'list.select', 'integer.select', 'text.multiselect']; + const noConversion = ['text', 'integer', 'string', 'password', 'readonly', 'text.select', 'integer.select', 'text.multiselect']; // get settings to determine setting type to store values appropriately $.get('api/table_settings.json?nocache=' + Date.now(), function(res) { - - settingsJSON = res; + // loop through the settings definitions from the json + res["data"].forEach(set => { + + prefix = set["Group"] + setType = set["Type"] + setCodeName = set["Code_Name"] + + if (noConversion.includes(setType)) { + + settingsArray.push([prefix, setCodeName, setType, $('#'+setCodeName).val()]); + + } else if (setType === 'boolean' || setType === 'integer.checkbox') { - data = settingsJSON["data"]; - - data.forEach(set => { - if (noConversion.includes(set['Type'])) { - - settingsArray.push([set["Group"], set["Code_Name"], set["Type"], $('#'+set["Code_Name"]).val()]); - - } else if (set['Type'] === 'boolean' || set['Type'] === 'integer.checkbox') { - - const temp = $(`#${set["Code_Name"]}`).is(':checked') ? 1 : 0; - settingsArray.push([set["Group"], set["Code_Name"], set["Type"], temp]); + const temp = $(`#${setCodeName}`).is(':checked') ? 1 : 0; + settingsArray.push([prefix, setCodeName, setType, temp]); - } else if (set['Type'] === 'list' || set['Type'] === 'subnets') { + } else if (setType.startsWith('list') || setType === 'subnets') { + const temps = []; - $(`#${set["Code_Name"]} option`).each(function (i, selected) { + $(`#${setCodeName} option`).each(function (i, selected) { const vl = $(selected).val(); if (vl !== '') { temps.push(vl); } }); - settingsArray.push([set["Group"], set["Code_Name"], set["Type"], JSON.stringify(temps)]); - } else if (set['Type'] === 'json') { - const temps = $('#'+set["Code_Name"]).val(); - settingsArray.push([set["Group"], set["Code_Name"], set["Type"], temps]); - } else if (set['Type'] === 'password.SHA256') { + + settingsArray.push([prefix, setCodeName, setType, JSON.stringify(temps)]); + } else if (setType === 'json') { + const temps = $('#'+setCodeName).val(); + settingsArray.push([prefix, setCodeName, setType, temps]); + } else if (setType === 'password.SHA256') { // save value as SHA256 if value isn't SHA256 already - var temps = $('#'+set["Code_Name"]).val(); + var temps = $('#'+setCodeName).val(); if(temps != "" && !isSHA256(temps)) { temps = CryptoJS.SHA256(temps).toString(CryptoJS.enc.Hex); } - settingsArray.push([set["Group"], set["Code_Name"], set["Type"], temps]); + settingsArray.push([prefix, setCodeName, setType, temps]); } }); // sanity check to make sure settings were loaded & collected correctly if(settingsCollectedCorrectly(settingsArray, settingsJSON_DB)) { + + // console.log(settingsArray); + // trigger a save settings event in the backend $.ajax({ method: "POST", diff --git a/server/helper.py b/server/helper.py index 13b82320..77b7420e 100755 --- a/server/helper.py +++ b/server/helper.py @@ -314,7 +314,7 @@ def get_setting_value(key): # Convert the setting value to the corresponding python type def setting_value_to_python_type(set_type, set_value): - value = '' + value = '----not processed----' # Handle different types of settings if set_type in ['text', 'string', 'password', 'password.SHA256', 'readonly', 'text.select']: @@ -332,23 +332,35 @@ def setting_value_to_python_type(set_type, set_value): elif set_type in ['integer.select', 'integer']: value = int(set_value) - # belwo covers 'text.multiselect', 'list', 'subnets', 'list.select', 'textarea.list', 'list' - elif set_type in ['text.multiselect', 'list', 'subnets', 'list.select', 'textarea.list'] or 'list' in set_type: - # Handle string + # belwo covers 'text.multiselect', 'list', 'subnets', 'list.select', 'list' + elif set_type in ['subnets' ] or 'list' in set_type: mylog('debug', [f'[SETTINGS] Handling set_type: "{set_type}", set_value: "{set_value}"']) + # Handle string if isinstance(set_value, str): value = json.loads(set_value.replace("'", "\"")) - # Assuming set_value is a list in this case - elif isinstance(set_value, list): + + # Assuming set_value is a list at this point + if isinstance(set_value, list): + if 'base64' in set_type: + tmp_value = [] + for item in set_value: + tmp_value.append(base64.b64decode(item)) + + set_value = tmp_value + value = set_value + elif set_type == '.template': # Assuming set_value is a JSON object in this case value = json.loads(set_value) - else: + + # log debug info if not processed + if value == '----not processed----': mylog('none', [f'[SETTINGS] ⚠ ERROR - set_type not handled:{set_type}']) - mylog('none', [f'[SETTINGS] ⚠ ERROR - setting json:{json.dumps(setting)}']) + mylog('none', [f'[SETTINGS] ⚠ ERROR - setting json:{json.dumps(set_value)}']) + value = '' return value
CTRL + Click
Watched_Value1
Watched_Value2
Watched_Value3
Watched_Value4