Add RSA to TeleSec (more efficient)

This commit is contained in:
naielv
2025-09-09 15:25:06 +02:00
parent 34f61777c3
commit c50c29f743
11 changed files with 55 additions and 28 deletions

View File

@@ -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 {

View File

@@ -75,6 +75,7 @@
<div id="snackbar">
Hay una nueva versión de TeleSec.<br /><a id="reload">Pulsa aqui para actualizar.</a>
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/crypto-js/3.1.2/rollups/aes.js" integrity="sha256-/H4YS+7aYb9kJ5OKhFYPUjSJdrtV6AeyJOtTkw6X72o=" crossorigin="anonymous"></script>
<script src="static/showdown.min.js"></script>
<script src="static/qrcode/html5-qrcode.min.js"></script>
<script src="static/qrcode/barcode.js"></script>

View File

@@ -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!");

View File

@@ -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),

View File

@@ -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!");

View File

@@ -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 {

View File

@@ -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 {

View File

@@ -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),

View File

@@ -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!");

View File

@@ -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 {

View File

@@ -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!");