Skip to content

Commit

Permalink
🔄Sync: Generate token/key buttons #838
Browse files Browse the repository at this point in the history
  • Loading branch information
jokob-sk committed Oct 19, 2024
1 parent e24903a commit 4f859b5
Show file tree
Hide file tree
Showing 15 changed files with 84 additions and 13 deletions.
29 changes: 29 additions & 0 deletions front/js/ui_components.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,35 @@ function initDeviceSelectors(devicesListAll_JSON) {
}, 10);
}

// -------------------------------------------------------------------
// Utility function to generate a random API token in the format t_<random string of specified length>
function generateApiToken(elem, length) {
// Retrieve and parse custom parameters from the element
let params = $(elem).attr("my-customparams")?.split(',').map(param => param.trim());
if (params && params.length >= 1) {
var targetElementID = params[0]; // Get the target element's ID
}

let targetElement = $('#' + targetElementID);

// Function to generate a random string of a specified length
function generateRandomString(len) {
let characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
let result = '';
for (let i = 0; i < len; i++) {
result += characters.charAt(Math.floor(Math.random() * characters.length));
}
return result;
}

// Generate the token in the format t_<random string of length>
let randomToken = 't_' + generateRandomString(length);

// Set the generated token as the value of the target element
if (targetElement.length) {
targetElement.val(randomToken);
}
}

// ----------------------------------------------
// Updates the icon preview
Expand Down
1 change: 1 addition & 0 deletions front/php/templates/language/ar_ar.json
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,7 @@
"Gen_Description": "",
"Gen_Error": "",
"Gen_Filter": "",
"Gen_Generate": "",
"Gen_LockedDB": "",
"Gen_Offline": "",
"Gen_Okay": "",
Expand Down
1 change: 1 addition & 0 deletions front/php/templates/language/cs_cz.json
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,7 @@
"Gen_Description": "",
"Gen_Error": "",
"Gen_Filter": "",
"Gen_Generate": "",
"Gen_LockedDB": "",
"Gen_Offline": "",
"Gen_Okay": "",
Expand Down
3 changes: 2 additions & 1 deletion front/php/templates/language/de_de.json
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,7 @@
"Gen_Description": "Beschreibung",
"Gen_Error": "Fehler",
"Gen_Filter": "Filter",
"Gen_Generate": "",
"Gen_LockedDB": "ERROR - DB eventuell gesperrt - Nutze die Konsole in den Entwickler Werkzeugen (F12) zur Überprüfung oder probiere es später erneut.",
"Gen_Offline": "Offline",
"Gen_Okay": "Ok",
Expand Down Expand Up @@ -782,4 +783,4 @@
"settings_update_item_warning": "",
"test_event_icon": "",
"test_event_tooltip": "Speichere die Änderungen, bevor Sie die Einstellungen testen."
}
}
1 change: 1 addition & 0 deletions front/php/templates/language/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,7 @@
"Gen_Description": "Description",
"Gen_Error": "Error",
"Gen_Filter": "Filter",
"Gen_Generate": "Generate",
"Gen_LockedDB": "ERROR - DB might be locked - Check F12 Dev tools -> Console or try later.",
"Gen_Offline": "Offline",
"Gen_Okay": "Ok",
Expand Down
3 changes: 2 additions & 1 deletion front/php/templates/language/es_es.json
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,7 @@
"Gen_Description": "Descripción",
"Gen_Error": "Error",
"Gen_Filter": "Filtro",
"Gen_Generate": "",
"Gen_LockedDB": "Fallo - La base de datos puede estar bloqueada - Pulsa F1 -> Ajustes de desarrolladores -> Consola o prueba más tarde.",
"Gen_Offline": "Desconectado",
"Gen_Okay": "Aceptar",
Expand Down Expand Up @@ -780,4 +781,4 @@
"settings_update_item_warning": "Actualice el valor a continuación. Tenga cuidado de seguir el formato anterior. <b>O la validación no se realiza.</b>",
"test_event_icon": "fa-vial-circle-check",
"test_event_tooltip": "Guarda tus cambios antes de probar nuevos ajustes."
}
}
3 changes: 2 additions & 1 deletion front/php/templates/language/fr_fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,7 @@
"Gen_Description": "Description",
"Gen_Error": "Erreur",
"Gen_Filter": "Filtrer",
"Gen_Generate": "",
"Gen_LockedDB": "Erreur - La base de données est peut-être verrouillée - Vérifier avec les outils de dév via F12 -> Console ou essayer plus tard.",
"Gen_Offline": "Hors ligne",
"Gen_Okay": "OK",
Expand Down Expand Up @@ -701,4 +702,4 @@
"settings_update_item_warning": "Mettre à jour la valeur ci-dessous. Veillez à bien suivre le même format qu'auparavant. <b>Il n'y a pas de pas de contrôle.</b>",
"test_event_icon": "fa-vial-circle-check",
"test_event_tooltip": "Enregistrer d'abord vos modifications avant de tester vôtre paramétrage."
}
}
3 changes: 2 additions & 1 deletion front/php/templates/language/it_it.json
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,7 @@
"Gen_Description": "Descrizione",
"Gen_Error": "Errore",
"Gen_Filter": "Filtro",
"Gen_Generate": "",
"Gen_LockedDB": "ERRORE: il DB potrebbe essere bloccato, controlla F12 Strumenti di sviluppo -> Console o riprova più tardi.",
"Gen_Offline": "Offline",
"Gen_Okay": "Ok",
Expand Down Expand Up @@ -701,4 +702,4 @@
"settings_update_item_warning": "Aggiorna il valore qui sotto. Fai attenzione a seguire il formato precedente. <b>La convalida non viene eseguita.</b>",
"test_event_icon": "fa-vial-circle-check",
"test_event_tooltip": "Salva le modifiche prima di provare le nuove impostazioni."
}
}
3 changes: 2 additions & 1 deletion front/php/templates/language/nb_no.json
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,7 @@
"Gen_Description": "",
"Gen_Error": "Feil",
"Gen_Filter": "Filter",
"Gen_Generate": "",
"Gen_LockedDB": "FEIL - DB kan være låst - Sjekk F12 Dev tools -> Konsoll eller prøv senere.",
"Gen_Offline": "Frakoblet",
"Gen_Okay": "Ok",
Expand Down Expand Up @@ -701,4 +702,4 @@
"settings_update_item_warning": "Oppdater verdien nedenfor. Pass på å følge forrige format. <b>Validering etterpå utføres ikke.</b>",
"test_event_icon": "fa-vial-circle-check",
"test_event_tooltip": "Lagre endringene først, før du tester innstillingene dine."
}
}
3 changes: 2 additions & 1 deletion front/php/templates/language/pl_pl.json
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,7 @@
"Gen_Description": "",
"Gen_Error": "Błąd",
"Gen_Filter": "Filtr",
"Gen_Generate": "",
"Gen_LockedDB": "BŁĄD - BAZA DANYCH może być zablokowana - Sprawdź F12 narzędzia dewelopera -> Konsola lub spróbuj ponownie później.",
"Gen_Offline": "Wyłączone",
"Gen_Okay": "Ok",
Expand Down Expand Up @@ -701,4 +702,4 @@
"settings_update_item_warning": "Zaktualizuj poniższą wartość. Zachowaj ostrożność i postępuj zgodnie z poprzednim formatem. <b>Walidacja nie jest wykonywana.</b>",
"test_event_icon": "fa-vial-circle-check",
"test_event_tooltip": "Zapisz zmiany zanim będziesz testować swoje ustawienia."
}
}
1 change: 1 addition & 0 deletions front/php/templates/language/pt_br.json
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,7 @@
"Gen_Description": "",
"Gen_Error": "Erro",
"Gen_Filter": "Filtro",
"Gen_Generate": "",
"Gen_LockedDB": "ERRO - O banco de dados pode estar bloqueado - Verifique F12 Ferramentas de desenvolvimento -> Console ou tente mais tarde.",
"Gen_Offline": "Offline",
"Gen_Okay": "Ok",
Expand Down
3 changes: 2 additions & 1 deletion front/php/templates/language/ru_ru.json
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,7 @@
"Gen_Description": "Описание",
"Gen_Error": "Ошибка",
"Gen_Filter": "Фильтр",
"Gen_Generate": "",
"Gen_LockedDB": "ОШИБКА - Возможно, база данных заблокирована. Проверьте инструменты разработчика F12 -> Консоль или повторите попытку позже.",
"Gen_Offline": "Оффлайн",
"Gen_Okay": "OK",
Expand Down Expand Up @@ -701,4 +702,4 @@
"settings_update_item_warning": "Обновить значение ниже. Будьте осторожны, следуя предыдущему формату. <b>Проверка не выполняется.</b>",
"test_event_icon": "fa-vial-circle-check",
"test_event_tooltip": "Сначала сохраните изменения, прежде чем проверять настройки."
}
}
1 change: 1 addition & 0 deletions front/php/templates/language/tr_tr.json
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,7 @@
"Gen_Description": "",
"Gen_Error": "Hata",
"Gen_Filter": "Filtre",
"Gen_Generate": "",
"Gen_LockedDB": "",
"Gen_Offline": "Çevrimdışı",
"Gen_Okay": "Tamam",
Expand Down
3 changes: 2 additions & 1 deletion front/php/templates/language/zh_cn.json
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,7 @@
"Gen_Description": "",
"Gen_Error": "错误",
"Gen_Filter": "筛选",
"Gen_Generate": "",
"Gen_LockedDB": "错误 - DB 可能被锁定 - 检查 F12 开发工具 -> 控制台或稍后重试。",
"Gen_Offline": "离线",
"Gen_Okay": "Ok",
Expand Down Expand Up @@ -701,4 +702,4 @@
"settings_update_item_warning": "更新下面的值。请注意遵循先前的格式。<b>未执行验证。</b>",
"test_event_icon": "",
"test_event_tooltip": "在测试设置之前,请先保存更改。"
}
}
39 changes: 34 additions & 5 deletions front/plugins/sync/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
},

"default_value": "unused",
"options": [
"options": [
"unused",
"once",
"schedule",
Expand Down Expand Up @@ -115,7 +115,21 @@
"type": {
"dataType": "string",
"elements": [
{ "elementType": "input", "elementOptions": [], "transformers": [] }
{
"elementType": "input",
"elementOptions": [{ "cssClasses": "col-xs-12" }],
"transformers": []
},
{
"elementType": "button",
"elementOptions": [
{ "getStringKey": "Gen_Generate" },
{ "customParams": "SYNC_api_token" },
{ "onClick": "generateApiToken(this, 20)" },
{ "cssClasses": "col-xs-12" }
],
"transformers": []
}
]
},
"maxLength": 50,
Expand All @@ -131,7 +145,7 @@
"description": [
{
"language_code": "en_us",
"string": "API token to secure communication. It's sent in the request header. The API token needs to be the same on the hub and on the nodes."
"string": "API token to secure communication, you can generate one or enter any value. It's sent in the request header. The API token needs to be the same on the hub and on the nodes."
}
]
},
Expand All @@ -140,7 +154,21 @@
"type": {
"dataType": "string",
"elements": [
{ "elementType": "input", "elementOptions": [], "transformers": [] }
{
"elementType": "input",
"elementOptions": [{ "cssClasses": "col-xs-12" }],
"transformers": []
},
{
"elementType": "button",
"elementOptions": [
{ "getStringKey": "Gen_Generate" },
{ "customParams": "SYNC_encryption_key" },
{ "onClick": "generateApiToken(this, 30)" },
{ "cssClasses": "col-xs-12" }
],
"transformers": []
}
]
},
"maxLength": 50,
Expand All @@ -159,7 +187,8 @@
"string": "Encryption key used to encrypt the data before sending and for decryption on the hub. The key needs to be the same on the hub and on the nodes."
}
]
},{
},
{
"function": "nodes",
"type": {
"dataType": "array",
Expand Down

0 comments on commit 4f859b5

Please sign in to comment.