Add RSA to TeleSec (more efficient)
This commit is contained in:
@@ -513,6 +513,32 @@ const SC_actions = {
|
|||||||
};
|
};
|
||||||
var SC_Personas = {};
|
var SC_Personas = {};
|
||||||
// Listado precargado de 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
|
gun
|
||||||
.get(TABLE)
|
.get(TABLE)
|
||||||
.get("personas")
|
.get("personas")
|
||||||
@@ -527,7 +553,7 @@ gun
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (typeof data == "string") {
|
if (typeof data == "string") {
|
||||||
SEA.decrypt(data, SECRET, (data) => {
|
TS_decrypt(data, SECRET, (data) => {
|
||||||
add_row(data, key);
|
add_row(data, key);
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
@@ -887,7 +913,7 @@ function TS_IndexElement(
|
|||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
data.Estado = state;
|
data.Estado = state;
|
||||||
var enc = SEA.encrypt(data, SECRET, (encrypted) => {
|
var enc = TS_encrypt(data, SECRET, (encrypted) => {
|
||||||
betterGunPut(ref.get(data._key), encrypted);
|
betterGunPut(ref.get(data._key), encrypted);
|
||||||
toastr.success("Guardado!");
|
toastr.success("Guardado!");
|
||||||
});
|
});
|
||||||
@@ -937,7 +963,7 @@ function TS_IndexElement(
|
|||||||
SC_Personas[data.Persona].Puntos = parseInt(SC_Personas[data.Persona].Puntos) + 1;
|
SC_Personas[data.Persona].Puntos = parseInt(SC_Personas[data.Persona].Puntos) + 1;
|
||||||
toastr.success("¡Comada DE PAGO!");
|
toastr.success("¡Comada DE PAGO!");
|
||||||
}
|
}
|
||||||
SEA.encrypt(SC_Personas[data.Persona], SECRET, (encrypted) => {
|
TS_encrypt(SC_Personas[data.Persona], SECRET, (encrypted) => {
|
||||||
betterGunPut(
|
betterGunPut(
|
||||||
gun.get(TABLE).get("personas").get(data.Persona),
|
gun.get(TABLE).get("personas").get(data.Persona),
|
||||||
encrypted
|
encrypted
|
||||||
@@ -1030,7 +1056,7 @@ function TS_IndexElement(
|
|||||||
render();
|
render();
|
||||||
}
|
}
|
||||||
if (typeof data == "string") {
|
if (typeof data == "string") {
|
||||||
SEA.decrypt(data, SECRET, (data) => {
|
TS_decrypt(data, SECRET, (data) => {
|
||||||
add_row(data, key);
|
add_row(data, key);
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -75,6 +75,7 @@
|
|||||||
<div id="snackbar">
|
<div id="snackbar">
|
||||||
Hay una nueva versión de TeleSec.<br /><a id="reload">Pulsa aqui para actualizar.</a>
|
Hay una nueva versión de TeleSec.<br /><a id="reload">Pulsa aqui para actualizar.</a>
|
||||||
</div>
|
</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/showdown.min.js"></script>
|
||||||
<script src="static/qrcode/html5-qrcode.min.js"></script>
|
<script src="static/qrcode/html5-qrcode.min.js"></script>
|
||||||
<script src="static/qrcode/barcode.js"></script>
|
<script src="static/qrcode/barcode.js"></script>
|
||||||
|
|||||||
@@ -55,7 +55,7 @@ PAGES.aulas = {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
if (typeof data == "string") {
|
if (typeof data == "string") {
|
||||||
SEA.decrypt(data, SECRET, (data) => {
|
TS_decrypt(data, SECRET, (data) => {
|
||||||
add_row(data || {});
|
add_row(data || {});
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
@@ -137,7 +137,7 @@ PAGES.aulas = {
|
|||||||
document.getElementById(field_autor).value = data["Solicitante"] || "";
|
document.getElementById(field_autor).value = data["Solicitante"] || "";
|
||||||
}
|
}
|
||||||
if (typeof data == "string") {
|
if (typeof data == "string") {
|
||||||
SEA.decrypt(data, SECRET, (data) => {
|
TS_decrypt(data, SECRET, (data) => {
|
||||||
load_data(data, "%E");
|
load_data(data, "%E");
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
@@ -150,7 +150,7 @@ PAGES.aulas = {
|
|||||||
Contenido: document.getElementById(field_contenido).value,
|
Contenido: document.getElementById(field_contenido).value,
|
||||||
Asunto: document.getElementById(field_asunto).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";
|
document.getElementById("actionStatus").style.display = "block";
|
||||||
betterGunPut(gun.get(TABLE).get("aulas_solicitudes").get(mid), encrypted);
|
betterGunPut(gun.get(TABLE).get("aulas_solicitudes").get(mid), encrypted);
|
||||||
toastr.success("Guardado!");
|
toastr.success("Guardado!");
|
||||||
@@ -272,7 +272,7 @@ PAGES.aulas = {
|
|||||||
document.getElementById(field_fecha).value = data["Fecha"] || CurrentISODate();
|
document.getElementById(field_fecha).value = data["Fecha"] || CurrentISODate();
|
||||||
}
|
}
|
||||||
if (typeof data == "string") {
|
if (typeof data == "string") {
|
||||||
SEA.decrypt(data, SECRET, (data) => {
|
TS_decrypt(data, SECRET, (data) => {
|
||||||
load_data(data, "%E");
|
load_data(data, "%E");
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
@@ -286,7 +286,7 @@ PAGES.aulas = {
|
|||||||
Asunto: document.getElementById(field_asunto).value,
|
Asunto: document.getElementById(field_asunto).value,
|
||||||
Fecha: document.getElementById(field_fecha).value || CurrentISODate(),
|
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";
|
document.getElementById("actionStatus").style.display = "block";
|
||||||
betterGunPut(gun.get(TABLE).get("aulas_informes").get(mid), encrypted);
|
betterGunPut(gun.get(TABLE).get("aulas_informes").get(mid), encrypted);
|
||||||
toastr.success("Guardado!");
|
toastr.success("Guardado!");
|
||||||
|
|||||||
@@ -120,7 +120,7 @@ PAGES.avisos = {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
if (typeof data == "string") {
|
if (typeof data == "string") {
|
||||||
SEA.decrypt(data, SECRET, (data) => {
|
TS_decrypt(data, SECRET, (data) => {
|
||||||
load_data(data, "%E");
|
load_data(data, "%E");
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
@@ -147,7 +147,7 @@ PAGES.avisos = {
|
|||||||
.getElementById(field_estado)
|
.getElementById(field_estado)
|
||||||
.value.replace("%%", "por_leer"),
|
.value.replace("%%", "por_leer"),
|
||||||
};
|
};
|
||||||
var enc = SEA.encrypt(data, SECRET, (encrypted) => {
|
var enc = TS_encrypt(data, SECRET, (encrypted) => {
|
||||||
document.getElementById("actionStatus").style.display = "block";
|
document.getElementById("actionStatus").style.display = "block";
|
||||||
betterGunPut(
|
betterGunPut(
|
||||||
gun.get(TABLE).get("notificaciones").get(mid),
|
gun.get(TABLE).get("notificaciones").get(mid),
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ PAGES.comedor = {
|
|||||||
data["Platos"] || "";
|
data["Platos"] || "";
|
||||||
}
|
}
|
||||||
if (typeof data == "string") {
|
if (typeof data == "string") {
|
||||||
SEA.decrypt(data, SECRET, (data) => {
|
TS_decrypt(data, SECRET, (data) => {
|
||||||
load_data(data, "%E");
|
load_data(data, "%E");
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
@@ -59,7 +59,7 @@ PAGES.comedor = {
|
|||||||
betterGunPut(gun.get(TABLE).get("comedor").get(mid), null);
|
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";
|
document.getElementById("actionStatus").style.display = "block";
|
||||||
betterGunPut(gun.get(TABLE).get("comedor").get(newDate), encrypted);
|
betterGunPut(gun.get(TABLE).get("comedor").get(newDate), encrypted);
|
||||||
toastr.success("Guardado!");
|
toastr.success("Guardado!");
|
||||||
|
|||||||
@@ -75,7 +75,7 @@ PAGES.dataman = {
|
|||||||
var value = entry[1];
|
var value = entry[1];
|
||||||
if (value != null) {
|
if (value != null) {
|
||||||
if (typeof value == "string") {
|
if (typeof value == "string") {
|
||||||
SEA.decrypt(value, SECRET, (data) => {
|
TS_decrypt(value, SECRET, (data) => {
|
||||||
output[modul][key] = data;
|
output[modul][key] = data;
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
@@ -158,7 +158,7 @@ PAGES.dataman = {
|
|||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
Object.entries(JSON.parse(val)["data"]).forEach((entry) => {
|
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);
|
betterGunPut(gun.get(TABLE).get(sel).get(entry[0]), encrypted);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -197,7 +197,7 @@ PAGES.dataman = {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (typeof data == "string") {
|
if (typeof data == "string") {
|
||||||
SEA.decrypt(data, SECRET, (data) => {
|
TS_decrypt(data, SECRET, (data) => {
|
||||||
add_row(data, key);
|
add_row(data, key);
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -74,7 +74,7 @@ PAGES.materiales = {
|
|||||||
document.getElementById(field_notas).value = data["Notas"] || "";
|
document.getElementById(field_notas).value = data["Notas"] || "";
|
||||||
}
|
}
|
||||||
if (typeof data == "string") {
|
if (typeof data == "string") {
|
||||||
SEA.decrypt(data, SECRET, (data) => {
|
TS_decrypt(data, SECRET, (data) => {
|
||||||
load_data(data, "%E");
|
load_data(data, "%E");
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
@@ -91,7 +91,7 @@ PAGES.materiales = {
|
|||||||
Referencia: document.getElementById(field_referencia).value,
|
Referencia: document.getElementById(field_referencia).value,
|
||||||
Notas: document.getElementById(field_notas).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";
|
document.getElementById("actionStatus").style.display = "block";
|
||||||
betterGunPut(gun.get(TABLE).get("materiales").get(mid), encrypted);
|
betterGunPut(gun.get(TABLE).get("materiales").get(mid), encrypted);
|
||||||
toastr.success("Guardado!");
|
toastr.success("Guardado!");
|
||||||
@@ -159,7 +159,7 @@ PAGES.materiales = {
|
|||||||
select.appendChild(option);
|
select.appendChild(option);
|
||||||
}
|
}
|
||||||
if (typeof data === "string") {
|
if (typeof data === "string") {
|
||||||
SEA.decrypt(data, SECRET, (dec) => {
|
TS_decrypt(data, SECRET, (dec) => {
|
||||||
if (dec) addUbicacion(dec);
|
if (dec) addUbicacion(dec);
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -70,7 +70,7 @@ PAGES.notas = {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
if (typeof data == "string") {
|
if (typeof data == "string") {
|
||||||
SEA.decrypt(data, SECRET, (data) => {
|
TS_decrypt(data, SECRET, (data) => {
|
||||||
load_data(data, "%E");
|
load_data(data, "%E");
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
@@ -83,7 +83,7 @@ PAGES.notas = {
|
|||||||
Contenido: document.getElementById(field_contenido).value,
|
Contenido: document.getElementById(field_contenido).value,
|
||||||
Asunto: document.getElementById(field_asunto).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";
|
document.getElementById("actionStatus").style.display = "block";
|
||||||
betterGunPut(
|
betterGunPut(
|
||||||
gun.get(TABLE).get("notas").get(mid),
|
gun.get(TABLE).get("notas").get(mid),
|
||||||
|
|||||||
@@ -94,7 +94,7 @@ PAGES.personas = {
|
|||||||
document.getElementById(field_notas).value = data["markdown"] || "";
|
document.getElementById(field_notas).value = data["markdown"] || "";
|
||||||
}
|
}
|
||||||
if (typeof data == "string") {
|
if (typeof data == "string") {
|
||||||
SEA.decrypt(data, SECRET, (data) => {
|
TS_decrypt(data, SECRET, (data) => {
|
||||||
load_data(data, "%E");
|
load_data(data, "%E");
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
@@ -128,7 +128,7 @@ PAGES.personas = {
|
|||||||
Foto: resized,
|
Foto: resized,
|
||||||
markdown: document.getElementById(field_notas).value,
|
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";
|
document.getElementById("actionStatus").style.display = "block";
|
||||||
betterGunPut(gun.get(TABLE).get("personas").get(mid), encrypted);
|
betterGunPut(gun.get(TABLE).get("personas").get(mid), encrypted);
|
||||||
toastr.success("Guardado!");
|
toastr.success("Guardado!");
|
||||||
|
|||||||
@@ -72,7 +72,7 @@ PAGES.resumen_diario = {
|
|||||||
render_materialesLow();
|
render_materialesLow();
|
||||||
}
|
}
|
||||||
if (typeof data == "string") {
|
if (typeof data == "string") {
|
||||||
SEA.decrypt(data, SECRET, (data) => {
|
TS_decrypt(data, SECRET, (data) => {
|
||||||
add_row(data, key);
|
add_row(data, key);
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
@@ -134,7 +134,7 @@ PAGES.resumen_diario = {
|
|||||||
render_personasHigh();
|
render_personasHigh();
|
||||||
}
|
}
|
||||||
if (typeof data == "string") {
|
if (typeof data == "string") {
|
||||||
SEA.decrypt(data, SECRET, (data) => {
|
TS_decrypt(data, SECRET, (data) => {
|
||||||
add_row(data, key);
|
add_row(data, key);
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
@@ -155,7 +155,7 @@ PAGES.resumen_diario = {
|
|||||||
document.getElementById(table_comedor).innerHTML += data.Platos || "No hay platos registrados para hoy.";
|
document.getElementById(table_comedor).innerHTML += data.Platos || "No hay platos registrados para hoy.";
|
||||||
}
|
}
|
||||||
if (typeof data == "string") {
|
if (typeof data == "string") {
|
||||||
SEA.decrypt(data, SECRET, (data) => {
|
TS_decrypt(data, SECRET, (data) => {
|
||||||
add_row(data);
|
add_row(data);
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -98,7 +98,7 @@ PAGES.supercafe = {
|
|||||||
loadActions();
|
loadActions();
|
||||||
}
|
}
|
||||||
if (typeof data == "string") {
|
if (typeof data == "string") {
|
||||||
SEA.decrypt(data, SECRET, (data) => {
|
TS_decrypt(data, SECRET, (data) => {
|
||||||
load_data(data, "%E");
|
load_data(data, "%E");
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
@@ -119,7 +119,7 @@ PAGES.supercafe = {
|
|||||||
.getElementById(field_estado)
|
.getElementById(field_estado)
|
||||||
.value.replace("%%", "Pedido"),
|
.value.replace("%%", "Pedido"),
|
||||||
};
|
};
|
||||||
var enc = SEA.encrypt(data, SECRET, (encrypted) => {
|
var enc = TS_encrypt(data, SECRET, (encrypted) => {
|
||||||
document.getElementById("actionStatus").style.display = "block";
|
document.getElementById("actionStatus").style.display = "block";
|
||||||
betterGunPut(gun.get(TABLE).get("supercafe").get(mid), encrypted);
|
betterGunPut(gun.get(TABLE).get("supercafe").get(mid), encrypted);
|
||||||
toastr.success("Guardado!");
|
toastr.success("Guardado!");
|
||||||
|
|||||||
Reference in New Issue
Block a user