Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
DB_HOST = 'localhost'
DB_PORT = 3306
DB_USER = 'root'
DB_PASS = ''
DB_NAME = 'test'
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,5 @@ node_modules/
.Spotlight-V100
.Trashes
ehthumbs.db
Thumbs.db
Thumbs.db
.env
9 changes: 9 additions & 0 deletions Documentation.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
webserver.post '/api/storage'

table -> tabla
key -> entrada
value -> valor

Si solo hay table -> devolver todos los datos de la tabla
Si table y key -> devolver solo ese key
Si table + key + valor -> actualizar el dato
6 changes: 6 additions & 0 deletions backend/routes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
app.get('/dashboard', (req, res) => {
res.render('dashboard', {
title: "Dashboard",
publicIP: "192.168.1.1"
});
});
40 changes: 0 additions & 40 deletions backend/server.js

This file was deleted.

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
70 changes: 70 additions & 0 deletions legacy-files/scripts/pages/settings.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
// Load fields
async function populate(user_id) {
let account = JSON.parse(localStorage.getItem("account")) // cargar localstorage

document.getElementById("selector_language").value = account[user_id].language
document.getElementById("selector_background").value = account[user_id].background
document.getElementById("selector_theme").value = account[user_id].theme

console.log(account[user_id].username)
document.getElementById("user_name").textContent = account[user_id].username
document.getElementById("user_avatar").src = `https://gravatar.com/avatar/${await sha256(account[user_id].email)}`
console.log(account[user_id].email)
}

if(document.getElementById('show-password')){
document.getElementById('show-password').addEventListener('click', () => {
const element = document.getElementById('new-passwd')
element.type = element.type === 'password' ? 'text' : 'password'
})
}


// Funcion que guarda hash - solo se usa para la contraseña por ahora
async function changeValueSHA(user_id, element, db_value) {
let account = JSON.parse(localStorage.getItem("account"))

const contenido = document.getElementById(element)?.value
if (!contenido) {
console.error('Contenido vacío')
document.getElementById('settingsPaswdchgAlertbox').textContent = 'Contenido vacío'
document.getElementById('settingsPaswdchgAlertbox').style.color = 'red'
return
}

const oldValue = account[user_id][db_value]
const newHash = await sha256(contenido)

console.log(`Old ${db_value}: ${oldValue}`)
console.log(`New ${db_value}: ${newHash}`)

account[user_id][db_value] = newHash

localStorage.setItem("account", JSON.stringify(account))

log(`${db_value} changed`,'OpenFi Account','Warn',`${db_value} de ${account[user_id].username} ha sido cambiada.`)

console.log('Password updated correctly')
console.log(`Old ${db_value}: ${oldValue}`)
console.log(`New ${db_value}: ${newHash}`)
window.parent.updatePage('logs', document.querySelector('.nav_menu li[data-page="logs"]'), true)
}



// Funcion usada para cambiar valor
function changeValue(user_id, element_id, db_value) {
let account = JSON.parse(localStorage.getItem("account")) // cargar localstorage

const contenido = document.getElementById(element_id).value
if (contenido == undefined) {
console.error('Contenido vacío')
return
}
console.log(`settings.js > changeValue: Cambiado ${db_value} a ${contenido}`)

account[user_id][db_value] = contenido

localStorage.setItem("account", JSON.stringify(account)) // guardar localstorage
window.top.location.reload()
}
82 changes: 82 additions & 0 deletions notas.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
webserver.post('/api/storage', (req, res) => {
const { table, key, value } = req.body;

// Devolver tabla
if (table && !key && !value) {
const query = `SELECT * FROM ${table}`
conection.query( query, function(error, rows) {
console.log(rows)

// Si no encuentra nada, devuelve null
if (rows.length === 0) {
return res.json({
action: 'get',
key: key,
value: null
});
}

// Devuelve el valor encontrado
res.json({
action: 'get',
key: key,
value: rows[0].setting_value
});
}
);
}

// ======== ACCIÓN: GUARDAR (set) ========
else if (action === 'set') {
// Validar que value esté presente
if (value === undefined) {
return res.status(400).json({
error: 'El campo "value" es requerido para la acción "set"'
});
}

conection.query(
'INSERT INTO settings (setting_key, setting_value) VALUES (?, ?) ON DUPLICATE KEY UPDATE setting_value = ?',
[key, value, value],
(error, result) => {
if (error) {
return res.status(500).json({ error: error.message });
}

res.json({
action: 'set',
success: true,
key: key,
value: value
});
}
);
}

// ======== ACCIÓN: ELIMINAR (delete) ========
else if (action === 'delete') {
conection.query(
'DELETE FROM settings WHERE setting_key = ?',
[key],
(error, result) => {
if (error) {
return res.status(500).json({ error: error.message });
}

res.json({
action: 'delete',
success: true,
key: key,
deleted: result.affectedRows > 0
});
}
);
}

// ======== ACCIÓN NO VÁLIDA ========
else {
res.status(400).json({
error: 'Acción no válida. Usa: "get", "set" o "delete"'
});
}
});
Loading