From 84c5fdae43ac127741c8d0683fa7dbf79c52b6f4 Mon Sep 17 00:00:00 2001 From: jokob-sk Date: Fri, 22 Nov 2024 10:12:35 +1100 Subject: [PATCH] Settings app.conf RW check + VNDRPDT plugin --- front/js/common.js | 9 +++- front/php/templates/language/ar_ar.json | 1 + front/php/templates/language/ca_ca.json | 1 + front/php/templates/language/cs_cz.json | 1 + front/php/templates/language/de_de.json | 1 + front/php/templates/language/en_us.json | 1 + front/php/templates/language/es_es.json | 1 + front/php/templates/language/fr_fr.json | 1 + front/php/templates/language/it_it.json | 1 + front/php/templates/language/nb_no.json | 1 + front/php/templates/language/pl_pl.json | 1 + front/php/templates/language/pt_br.json | 1 + front/php/templates/language/ru_ru.json | 1 + front/php/templates/language/tr_tr.json | 1 + front/php/templates/language/zh_cn.json | 1 + front/plugins/vendor_update/script.py | 1 + front/settings.php | 57 ++++++++++++++----------- server/graphql_server/graphql_schema.py | 2 +- 18 files changed, 54 insertions(+), 29 deletions(-) diff --git a/front/js/common.js b/front/js/common.js index 1582683c..b16585cc 100755 --- a/front/js/common.js +++ b/front/js/common.js @@ -1312,9 +1312,12 @@ async function isGraphQLServerRunning() { // ----------------------------------------------------------------------------- // Check if the code has been executed before by checking sessionStorage function isAppInitialized() { - const completedCallsCount_final = getLangCode() == 'en_us' ? 3 : 4; + + completedCalls = parseInt(getCache("completedCallsCount")); + shouldBeCompletedCalls = getLangCode() == 'en_us' ? 3 : 4; + return ( - parseInt(getCache("completedCallsCount")) >= completedCallsCount_final + completedCalls >= shouldBeCompletedCalls ); } @@ -1325,6 +1328,8 @@ async function executeOnce() { if (!isAppInitialized()) { try { + console.log("HERE"); + await waitForGraphQLServer(); // Wait for the server to start await cacheDevices(); diff --git a/front/php/templates/language/ar_ar.json b/front/php/templates/language/ar_ar.json index 256fb3fe..f785a50b 100755 --- a/front/php/templates/language/ar_ar.json +++ b/front/php/templates/language/ar_ar.json @@ -711,6 +711,7 @@ "settings_publishers_icon": "", "settings_publishers_info": "", "settings_publishers_label": "", + "settings_readonly": "", "settings_saved": "", "settings_system_icon": "", "settings_system_label": "", diff --git a/front/php/templates/language/ca_ca.json b/front/php/templates/language/ca_ca.json index e10c4e61..4b402364 100755 --- a/front/php/templates/language/ca_ca.json +++ b/front/php/templates/language/ca_ca.json @@ -711,6 +711,7 @@ "settings_publishers_icon": "", "settings_publishers_info": "", "settings_publishers_label": "", + "settings_readonly": "", "settings_saved": "", "settings_system_icon": "", "settings_system_label": "", diff --git a/front/php/templates/language/cs_cz.json b/front/php/templates/language/cs_cz.json index 256fb3fe..f785a50b 100755 --- a/front/php/templates/language/cs_cz.json +++ b/front/php/templates/language/cs_cz.json @@ -711,6 +711,7 @@ "settings_publishers_icon": "", "settings_publishers_info": "", "settings_publishers_label": "", + "settings_readonly": "", "settings_saved": "", "settings_system_icon": "", "settings_system_label": "", diff --git a/front/php/templates/language/de_de.json b/front/php/templates/language/de_de.json index 12600cb4..5043f183 100755 --- a/front/php/templates/language/de_de.json +++ b/front/php/templates/language/de_de.json @@ -792,6 +792,7 @@ "settings_publishers_icon": "", "settings_publishers_info": "Lade mehr Veröffentlicher mit den geladene Plugins-Einstellungen", "settings_publishers_label": "Veröffentlicher", + "settings_readonly": "", "settings_saved": "
Einstellungen gespeichert.
Wird geladen...

", "settings_system_icon": "", "settings_system_label": "System", diff --git a/front/php/templates/language/en_us.json b/front/php/templates/language/en_us.json index 2e2062b4..9f0aa0cc 100755 --- a/front/php/templates/language/en_us.json +++ b/front/php/templates/language/en_us.json @@ -711,6 +711,7 @@ "settings_publishers_icon": "fa-solid fa-paper-plane", "settings_publishers_info": "Load more Publishers with the LOADED_PLUGINS setting", "settings_publishers_label": "Publishers", + "settings_readonly": "Can't READ or WRITE app.conf. Try restarting the container and read the file permissions documentation", "settings_saved": "
Settings saved.
Reloading...

", "settings_system_icon": "fa-solid fa-gear", "settings_system_label": "System", diff --git a/front/php/templates/language/es_es.json b/front/php/templates/language/es_es.json index 992bed24..547d5478 100755 --- a/front/php/templates/language/es_es.json +++ b/front/php/templates/language/es_es.json @@ -790,6 +790,7 @@ "settings_publishers_icon": "fa-solid fa-paper-plane", "settings_publishers_info": "Cargue más editor@s con el ajuste LOADED_PLUGINS", "settings_publishers_label": "Editores", + "settings_readonly": "", "settings_saved": "
Ajustes guardados.

Recargando...

", "settings_system_icon": "fa-solid fa-gear", "settings_system_label": "Sistema", diff --git a/front/php/templates/language/fr_fr.json b/front/php/templates/language/fr_fr.json index 83e649ab..bcea0541 100755 --- a/front/php/templates/language/fr_fr.json +++ b/front/php/templates/language/fr_fr.json @@ -711,6 +711,7 @@ "settings_publishers_icon": "fa-solid fa-paper-plane", "settings_publishers_info": "Charger plus de passerelles de publication avec le paramètre LOADED_PLUGINS", "settings_publishers_label": "Passerelles de publication", + "settings_readonly": "", "settings_saved": "
Paramètres enregistrés.
Rechargement...

", "settings_system_icon": "fa-solid fa-gear", "settings_system_label": "Système", diff --git a/front/php/templates/language/it_it.json b/front/php/templates/language/it_it.json index ab6f3cfb..395fb6bd 100755 --- a/front/php/templates/language/it_it.json +++ b/front/php/templates/language/it_it.json @@ -711,6 +711,7 @@ "settings_publishers_icon": "fa-solid fa-paper-plane", "settings_publishers_info": "Carica più editori con l'impostazione LOADED_PLUGINS", "settings_publishers_label": "Editori", + "settings_readonly": "", "settings_saved": "
Impostazioni salvate.
Aggiornamento in corso...

", "settings_system_icon": "fa-solid fa-gear", "settings_system_label": "Sistema", diff --git a/front/php/templates/language/nb_no.json b/front/php/templates/language/nb_no.json index d2fe8fd9..16f3f5f0 100755 --- a/front/php/templates/language/nb_no.json +++ b/front/php/templates/language/nb_no.json @@ -711,6 +711,7 @@ "settings_publishers_icon": "fa-solid fa-paper-plane", "settings_publishers_info": "", "settings_publishers_label": "Utgivere", + "settings_readonly": "", "settings_saved": "
Innstillinger lagret.
Laster inn på nytt...

", "settings_system_icon": "fa-solid fa-gear", "settings_system_label": "System", diff --git a/front/php/templates/language/pl_pl.json b/front/php/templates/language/pl_pl.json index 37ebbb34..61d693d2 100755 --- a/front/php/templates/language/pl_pl.json +++ b/front/php/templates/language/pl_pl.json @@ -711,6 +711,7 @@ "settings_publishers_icon": "fa-solid fa-paper-plane", "settings_publishers_info": "", "settings_publishers_label": "Wydawcy", + "settings_readonly": "", "settings_saved": "
Ustawienia zapisane.
Przeładowanie...

", "settings_system_icon": "fa-solid fa-gear", "settings_system_label": "System", diff --git a/front/php/templates/language/pt_br.json b/front/php/templates/language/pt_br.json index 7d48b1f3..fc086f05 100755 --- a/front/php/templates/language/pt_br.json +++ b/front/php/templates/language/pt_br.json @@ -711,6 +711,7 @@ "settings_publishers_icon": "", "settings_publishers_info": "", "settings_publishers_label": "", + "settings_readonly": "", "settings_saved": "", "settings_system_icon": "", "settings_system_label": "", diff --git a/front/php/templates/language/ru_ru.json b/front/php/templates/language/ru_ru.json index 28dae2b1..d8aa5862 100755 --- a/front/php/templates/language/ru_ru.json +++ b/front/php/templates/language/ru_ru.json @@ -711,6 +711,7 @@ "settings_publishers_icon": "fa-solid fa-paper-plane", "settings_publishers_info": "Загрузите больше нотификаторов с помощью настройки LOADED_PLUGINS", "settings_publishers_label": "Уведомления", + "settings_readonly": "", "settings_saved": "
Настройки сохранены.
Перезагрузка...

", "settings_system_icon": "fa-solid fa-gear", "settings_system_label": "Система", diff --git a/front/php/templates/language/tr_tr.json b/front/php/templates/language/tr_tr.json index cfcbe048..d6d788a1 100755 --- a/front/php/templates/language/tr_tr.json +++ b/front/php/templates/language/tr_tr.json @@ -711,6 +711,7 @@ "settings_publishers_icon": "", "settings_publishers_info": "", "settings_publishers_label": "", + "settings_readonly": "", "settings_saved": "", "settings_system_icon": "", "settings_system_label": "Sistem", diff --git a/front/php/templates/language/zh_cn.json b/front/php/templates/language/zh_cn.json index 7e4cd6ee..06c0266f 100755 --- a/front/php/templates/language/zh_cn.json +++ b/front/php/templates/language/zh_cn.json @@ -711,6 +711,7 @@ "settings_publishers_icon": "", "settings_publishers_info": "使用 LOADED_PLUGINS 设置加载更多发布商", "settings_publishers_label": "出版商", + "settings_readonly": "", "settings_saved": "
设置已保存。
正在加载...

", "settings_system_icon": "", "settings_system_label": "系统", diff --git a/front/plugins/vendor_update/script.py b/front/plugins/vendor_update/script.py index 16c44268..842a4b84 100755 --- a/front/plugins/vendor_update/script.py +++ b/front/plugins/vendor_update/script.py @@ -91,6 +91,7 @@ def update_vendors (dbPath, plugin_objects): devVendor FROM Devices WHERE devVendor = '(unknown)' + OR devVendor = '(Unknown)' OR devVendor = '' OR devVendor IS NULL """) diff --git a/front/settings.php b/front/settings.php index f7ec5800..5b0e2648 100755 --- a/front/settings.php +++ b/front/settings.php @@ -176,6 +176,8 @@ $settingsJSON_DB = json_encode($settings, JSON_HEX_TAG | JSON_HEX_AMP | JSON_HEX // Get plugin and settings data from API endpoints function getData(){ + console.log("in getData"); + $.get('api/table_settings.json?nocache=' + Date.now(), function(res) { settingsData = res["data"]; @@ -819,8 +821,6 @@ $settingsJSON_DB = json_encode($settings, JSON_HEX_TAG | JSON_HEX_AMP | JSON_HEX } } - - @@ -829,41 +829,46 @@ $settingsJSON_DB = json_encode($settings, JSON_HEX_TAG | JSON_HEX_AMP | JSON_HEX function handleLoadingDialog() { + // Check if app config is read only + const canReadAndWriteConfig = ; - // check if config file has been updated - $.get('api/app_state.json?nocache=' + Date.now(), function(appState) { + if(!canReadAndWriteConfig) + { + showMessage (getString("settings_readonly"), 10000, "modal_red"); + console.log(`app.conf seems to be read only (canRWConfig: ${canReadAndWriteConfig}`); + } else + { + // check if config file has been updated + $.get('api/app_state.json?nocache=' + Date.now(), function(appState) { + + fileModificationTime = ; - fileModificationTime = ; + // console.log(appState["settingsImported"]*1000) + importedMiliseconds = parseInt((appState["settingsImported"]*1000)); + humanReadable = (new Date(importedMiliseconds)).toLocaleString("en-UK", { timeZone: "" }); - // console.log(appState["settingsImported"]*1000) - importedMiliseconds = parseInt((appState["settingsImported"]*1000)); + // check if displayed settings are outdated + if(appState["showSpinner"] || fileModificationTime > importedMiliseconds) + { + showSpinner("settings_old") - humanReadable = (new Date(importedMiliseconds)).toLocaleString("en-UK", { timeZone: "" }); + setTimeout("handleLoadingDialog()", 1000); - // console.log(humanReadable.replaceAll('"', '')) + } else + { + checkInitialization(); + } - // check if displayed settings are outdated - - if(appState["showSpinner"] || fileModificationTime > importedMiliseconds) - { - - showSpinner("settings_old") + document.getElementById('lastImportedTime').innerHTML = humanReadable; + }) - setTimeout("handleLoadingDialog()", 1000); - - } else - { - checkInitialization(); - } - - - document.getElementById('lastImportedTime').innerHTML = humanReadable; - }) + } } function checkInitialization() { + if (isAppInitialized()) { // App is initialized, hide spinner and proceed with initialization console.log("App initialized, proceeding..."); @@ -880,7 +885,7 @@ $settingsJSON_DB = json_encode($settings, JSON_HEX_TAG | JSON_HEX_AMP | JSON_HEX // Check again after a delay setTimeout(checkInitialization, 1000); } -} + } showSpinner() diff --git a/server/graphql_server/graphql_schema.py b/server/graphql_server/graphql_schema.py index 4d49b0ad..5b57936e 100755 --- a/server/graphql_server/graphql_schema.py +++ b/server/graphql_server/graphql_schema.py @@ -149,7 +149,7 @@ class Query(ObjectType): if options.search: # Define static list of searchable fields searchable_fields = [ - "devName", "devMac", "devOwner", "devType", "devVendor", + "devName", "devMac", "devOwner", "devType", "devVendor", "devLastIP" "devGroup", "devComments", "devLocation", "devStatus", "devSSID", "devSite", "devSourcePlugin", "devSyncHubNode" ]