diff --git a/src/app_modules.js b/src/app_modules.js index 40bda84..9d23ee4 100644 --- a/src/app_modules.js +++ b/src/app_modules.js @@ -513,6 +513,32 @@ const SC_actions = { }; var SC_Personas = {}; // Listado precargado de personas: +function TS_decrypt(input, secret, callback) { + // if input starts with "SEA{" and ends with "}", then it's encrypted with SEA + // if not, it is encrypted with RSA + if (typeof input != "string") { + callback(input); + } else if (input.startsWith("SEA{") && input.endsWith("}")) { + Gun.SEA.decrypt(input, secret).then((decrypted) => { + callback(decrypted); + }); + } else if (input.startsWith("RSA{") && input.endsWith("}")) { + // ignore RSA{} + var data = input.slice(4, -1); + var decrypted = CryptoJS.AES.decrypt(data, secret).toString(CryptoJS.enc.Utf8); + callback(decrypted); + } +} +function TS_encrypt(input, secret, callback, mode = "RSA") { + if (mode == "SEA") { + Gun.TS_encrypt(input, secret).then((encrypted) => { + callback(encrypted); + }); + } else if (mode == "RSA") { + var encrypted = CryptoJS.AES.encrypt(input, secret).toString(); + callback("RSA{" + encrypted + "}"); + } +} gun .get(TABLE) .get("personas") @@ -527,7 +553,7 @@ gun } } if (typeof data == "string") { - SEA.decrypt(data, SECRET, (data) => { + TS_decrypt(data, SECRET, (data) => { add_row(data, key); }); } else { @@ -887,7 +913,7 @@ function TS_IndexElement( event.preventDefault(); event.stopPropagation(); data.Estado = state; - var enc = SEA.encrypt(data, SECRET, (encrypted) => { + var enc = TS_encrypt(data, SECRET, (encrypted) => { betterGunPut(ref.get(data._key), encrypted); toastr.success("Guardado!"); }); @@ -937,7 +963,7 @@ function TS_IndexElement( SC_Personas[data.Persona].Puntos = parseInt(SC_Personas[data.Persona].Puntos) + 1; toastr.success("¡Comada DE PAGO!"); } - SEA.encrypt(SC_Personas[data.Persona], SECRET, (encrypted) => { + TS_encrypt(SC_Personas[data.Persona], SECRET, (encrypted) => { betterGunPut( gun.get(TABLE).get("personas").get(data.Persona), encrypted @@ -1030,7 +1056,7 @@ function TS_IndexElement( render(); } if (typeof data == "string") { - SEA.decrypt(data, SECRET, (data) => { + TS_decrypt(data, SECRET, (data) => { add_row(data, key); }); } else { diff --git a/src/index.html b/src/index.html index 25635a7..c4bfb97 100644 --- a/src/index.html +++ b/src/index.html @@ -75,6 +75,7 @@
Hay una nueva versión de TeleSec.
Pulsa aqui para actualizar.
+ diff --git a/src/page/aulas.js b/src/page/aulas.js index de8e0cc..c1a1937 100644 --- a/src/page/aulas.js +++ b/src/page/aulas.js @@ -55,7 +55,7 @@ PAGES.aulas = { ); } if (typeof data == "string") { - SEA.decrypt(data, SECRET, (data) => { + TS_decrypt(data, SECRET, (data) => { add_row(data || {}); }); } else { @@ -137,7 +137,7 @@ PAGES.aulas = { document.getElementById(field_autor).value = data["Solicitante"] || ""; } if (typeof data == "string") { - SEA.decrypt(data, SECRET, (data) => { + TS_decrypt(data, SECRET, (data) => { load_data(data, "%E"); }); } else { @@ -150,7 +150,7 @@ PAGES.aulas = { Contenido: document.getElementById(field_contenido).value, Asunto: document.getElementById(field_asunto).value, }; - var enc = SEA.encrypt(data, SECRET, (encrypted) => { + var enc = TS_encrypt(data, SECRET, (encrypted) => { document.getElementById("actionStatus").style.display = "block"; betterGunPut(gun.get(TABLE).get("aulas_solicitudes").get(mid), encrypted); toastr.success("Guardado!"); @@ -272,7 +272,7 @@ PAGES.aulas = { document.getElementById(field_fecha).value = data["Fecha"] || CurrentISODate(); } if (typeof data == "string") { - SEA.decrypt(data, SECRET, (data) => { + TS_decrypt(data, SECRET, (data) => { load_data(data, "%E"); }); } else { @@ -286,7 +286,7 @@ PAGES.aulas = { Asunto: document.getElementById(field_asunto).value, Fecha: document.getElementById(field_fecha).value || CurrentISODate(), }; - var enc = SEA.encrypt(data, SECRET, (encrypted) => { + var enc = TS_encrypt(data, SECRET, (encrypted) => { document.getElementById("actionStatus").style.display = "block"; betterGunPut(gun.get(TABLE).get("aulas_informes").get(mid), encrypted); toastr.success("Guardado!"); diff --git a/src/page/avisos.js b/src/page/avisos.js index c871686..effc359 100644 --- a/src/page/avisos.js +++ b/src/page/avisos.js @@ -120,7 +120,7 @@ PAGES.avisos = { ); } if (typeof data == "string") { - SEA.decrypt(data, SECRET, (data) => { + TS_decrypt(data, SECRET, (data) => { load_data(data, "%E"); }); } else { @@ -147,7 +147,7 @@ PAGES.avisos = { .getElementById(field_estado) .value.replace("%%", "por_leer"), }; - var enc = SEA.encrypt(data, SECRET, (encrypted) => { + var enc = TS_encrypt(data, SECRET, (encrypted) => { document.getElementById("actionStatus").style.display = "block"; betterGunPut( gun.get(TABLE).get("notificaciones").get(mid), diff --git a/src/page/comedor.js b/src/page/comedor.js index ecb2c28..d21a94d 100644 --- a/src/page/comedor.js +++ b/src/page/comedor.js @@ -40,7 +40,7 @@ PAGES.comedor = { data["Platos"] || ""; } if (typeof data == "string") { - SEA.decrypt(data, SECRET, (data) => { + TS_decrypt(data, SECRET, (data) => { load_data(data, "%E"); }); } else { @@ -59,7 +59,7 @@ PAGES.comedor = { betterGunPut(gun.get(TABLE).get("comedor").get(mid), null); } - var enc = SEA.encrypt(data, SECRET, (encrypted) => { + var enc = TS_encrypt(data, SECRET, (encrypted) => { document.getElementById("actionStatus").style.display = "block"; betterGunPut(gun.get(TABLE).get("comedor").get(newDate), encrypted); toastr.success("Guardado!"); diff --git a/src/page/dataman.js b/src/page/dataman.js index 579cd66..2ebcbd6 100644 --- a/src/page/dataman.js +++ b/src/page/dataman.js @@ -75,7 +75,7 @@ PAGES.dataman = { var value = entry[1]; if (value != null) { if (typeof value == "string") { - SEA.decrypt(value, SECRET, (data) => { + TS_decrypt(value, SECRET, (data) => { output[modul][key] = data; }); } else { @@ -158,7 +158,7 @@ PAGES.dataman = { }); } else { Object.entries(JSON.parse(val)["data"]).forEach((entry) => { - var enc = SEA.encrypt(entry[1], SECRET, (encrypted) => { + var enc = TS_encrypt(entry[1], SECRET, (encrypted) => { betterGunPut(gun.get(TABLE).get(sel).get(entry[0]), encrypted); }); }); @@ -197,7 +197,7 @@ PAGES.dataman = { } } if (typeof data == "string") { - SEA.decrypt(data, SECRET, (data) => { + TS_decrypt(data, SECRET, (data) => { add_row(data, key); }); } else { diff --git a/src/page/materiales.js b/src/page/materiales.js index 030d0d3..dd5d292 100644 --- a/src/page/materiales.js +++ b/src/page/materiales.js @@ -74,7 +74,7 @@ PAGES.materiales = { document.getElementById(field_notas).value = data["Notas"] || ""; } if (typeof data == "string") { - SEA.decrypt(data, SECRET, (data) => { + TS_decrypt(data, SECRET, (data) => { load_data(data, "%E"); }); } else { @@ -91,7 +91,7 @@ PAGES.materiales = { Referencia: document.getElementById(field_referencia).value, Notas: document.getElementById(field_notas).value, }; - var enc = SEA.encrypt(data, SECRET, (encrypted) => { + var enc = TS_encrypt(data, SECRET, (encrypted) => { document.getElementById("actionStatus").style.display = "block"; betterGunPut(gun.get(TABLE).get("materiales").get(mid), encrypted); toastr.success("Guardado!"); @@ -159,7 +159,7 @@ PAGES.materiales = { select.appendChild(option); } if (typeof data === "string") { - SEA.decrypt(data, SECRET, (dec) => { + TS_decrypt(data, SECRET, (dec) => { if (dec) addUbicacion(dec); }); } else { diff --git a/src/page/notas.js b/src/page/notas.js index 2b81a88..1ee5855 100644 --- a/src/page/notas.js +++ b/src/page/notas.js @@ -70,7 +70,7 @@ PAGES.notas = { ); } if (typeof data == "string") { - SEA.decrypt(data, SECRET, (data) => { + TS_decrypt(data, SECRET, (data) => { load_data(data, "%E"); }); } else { @@ -83,7 +83,7 @@ PAGES.notas = { Contenido: document.getElementById(field_contenido).value, Asunto: document.getElementById(field_asunto).value, }; - var enc = SEA.encrypt(data, SECRET, (encrypted) => { + var enc = TS_encrypt(data, SECRET, (encrypted) => { document.getElementById("actionStatus").style.display = "block"; betterGunPut( gun.get(TABLE).get("notas").get(mid), diff --git a/src/page/personas.js b/src/page/personas.js index d173da8..e303883 100644 --- a/src/page/personas.js +++ b/src/page/personas.js @@ -94,7 +94,7 @@ PAGES.personas = { document.getElementById(field_notas).value = data["markdown"] || ""; } if (typeof data == "string") { - SEA.decrypt(data, SECRET, (data) => { + TS_decrypt(data, SECRET, (data) => { load_data(data, "%E"); }); } else { @@ -128,7 +128,7 @@ PAGES.personas = { Foto: resized, markdown: document.getElementById(field_notas).value, }; - var enc = SEA.encrypt(data, SECRET, (encrypted) => { + var enc = TS_encrypt(data, SECRET, (encrypted) => { document.getElementById("actionStatus").style.display = "block"; betterGunPut(gun.get(TABLE).get("personas").get(mid), encrypted); toastr.success("Guardado!"); diff --git a/src/page/resumen_diario.js b/src/page/resumen_diario.js index 6d7951c..266348b 100644 --- a/src/page/resumen_diario.js +++ b/src/page/resumen_diario.js @@ -72,7 +72,7 @@ PAGES.resumen_diario = { render_materialesLow(); } if (typeof data == "string") { - SEA.decrypt(data, SECRET, (data) => { + TS_decrypt(data, SECRET, (data) => { add_row(data, key); }); } else { @@ -134,7 +134,7 @@ PAGES.resumen_diario = { render_personasHigh(); } if (typeof data == "string") { - SEA.decrypt(data, SECRET, (data) => { + TS_decrypt(data, SECRET, (data) => { add_row(data, key); }); } else { @@ -155,7 +155,7 @@ PAGES.resumen_diario = { document.getElementById(table_comedor).innerHTML += data.Platos || "No hay platos registrados para hoy."; } if (typeof data == "string") { - SEA.decrypt(data, SECRET, (data) => { + TS_decrypt(data, SECRET, (data) => { add_row(data); }); } else { diff --git a/src/page/supercafe.js b/src/page/supercafe.js index c7025a0..3032027 100644 --- a/src/page/supercafe.js +++ b/src/page/supercafe.js @@ -98,7 +98,7 @@ PAGES.supercafe = { loadActions(); } if (typeof data == "string") { - SEA.decrypt(data, SECRET, (data) => { + TS_decrypt(data, SECRET, (data) => { load_data(data, "%E"); }); } else { @@ -119,7 +119,7 @@ PAGES.supercafe = { .getElementById(field_estado) .value.replace("%%", "Pedido"), }; - var enc = SEA.encrypt(data, SECRET, (encrypted) => { + var enc = TS_encrypt(data, SECRET, (encrypted) => { document.getElementById("actionStatus").style.display = "block"; betterGunPut(gun.get(TABLE).get("supercafe").get(mid), encrypted); toastr.success("Guardado!");