diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..16c7f44 --- /dev/null +++ b/.env.example @@ -0,0 +1,5 @@ +DB_HOST = 'localhost' +DB_PORT = 3306 +DB_USER = 'root' +DB_PASS = '' +DB_NAME = 'test' \ No newline at end of file diff --git a/.gitignore b/.gitignore index 8ab4f9d..a128a44 100644 --- a/.gitignore +++ b/.gitignore @@ -29,4 +29,5 @@ node_modules/ .Spotlight-V100 .Trashes ehthumbs.db -Thumbs.db \ No newline at end of file +Thumbs.db +.env diff --git a/Documentation.md b/Documentation.md new file mode 100644 index 0000000..59f27ea --- /dev/null +++ b/Documentation.md @@ -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 \ No newline at end of file diff --git a/backend/routes.js b/backend/routes.js new file mode 100644 index 0000000..10b6a2f --- /dev/null +++ b/backend/routes.js @@ -0,0 +1,6 @@ +app.get('/dashboard', (req, res) => { + res.render('dashboard', { + title: "Dashboard", + publicIP: "192.168.1.1" + }); +}); diff --git a/backend/server.js b/backend/server.js deleted file mode 100644 index e28517e..0000000 --- a/backend/server.js +++ /dev/null @@ -1,40 +0,0 @@ -const express = require("express"); -const crypto = require('crypto'); -const fs = require("fs"); -const path = require("path"); - -const app = express(); -const PORT = process.env.PORT; - -app.use(express.json()); -app.use(express.static(path.join(__dirname, "../public"))); - -// Control de JSON -app.get("/api/devices", (req, res) => { - const data = fs.readFileSync("./server/data.json", "utf-8"); - res.json(JSON.parse(data).usuarios); -}); -app.post("/api/devices", (req, res) => { - const nuevoUsuario = req.body; - - const data = JSON.parse(fs.readFileSync("./server/data.json", "utf-8")); - data.usuarios.push(nuevoUsuario); - - fs.writeFileSync("./server/data.json", JSON.stringify(data, null, 2)); - res.json({ mensaje: "Usuario guardado" }); -}); - -// Generar hash -app.post('/api/hash', (req, res) => { - const { text } = req.body; - if (!text) return res.status(400).json({ error: "no hay valor" }); - - const hash = crypto.createHash('sha256').update(text).digest('hex'); - res.json({ hash }); -}); - - -app.listen(PORT, () => { - console.log(`Servidor corriendo en http://localhost:${PORT}`); - console.log('ready'); -}); diff --git a/public/dashboard/dashboard.html b/legacy-files/dashboard/dashboard.html similarity index 100% rename from public/dashboard/dashboard.html rename to legacy-files/dashboard/dashboard.html diff --git a/public/dashboard/devices.html b/legacy-files/dashboard/devices.html similarity index 100% rename from public/dashboard/devices.html rename to legacy-files/dashboard/devices.html diff --git a/public/dashboard/information.html b/legacy-files/dashboard/information.html similarity index 100% rename from public/dashboard/information.html rename to legacy-files/dashboard/information.html diff --git a/public/dashboard/logs.html b/legacy-files/dashboard/logs.html similarity index 100% rename from public/dashboard/logs.html rename to legacy-files/dashboard/logs.html diff --git a/public/dashboard/network.html b/legacy-files/dashboard/network.html similarity index 100% rename from public/dashboard/network.html rename to legacy-files/dashboard/network.html diff --git a/public/dashboard/settings.html b/legacy-files/dashboard/settings.html similarity index 100% rename from public/dashboard/settings.html rename to legacy-files/dashboard/settings.html diff --git a/public/dashboard/topology.html b/legacy-files/dashboard/topology.html similarity index 100% rename from public/dashboard/topology.html rename to legacy-files/dashboard/topology.html diff --git a/public/dashboard/wifi.html b/legacy-files/dashboard/wifi.html similarity index 100% rename from public/dashboard/wifi.html rename to legacy-files/dashboard/wifi.html diff --git a/public/data/db.js b/legacy-files/data/db.js similarity index 100% rename from public/data/db.js rename to legacy-files/data/db.js diff --git a/public/index.html b/legacy-files/index.html similarity index 100% rename from public/index.html rename to legacy-files/index.html diff --git a/public/login.html b/legacy-files/login.html similarity index 100% rename from public/login.html rename to legacy-files/login.html diff --git a/public/main.html b/legacy-files/main.html similarity index 100% rename from public/main.html rename to legacy-files/main.html diff --git a/public/scripts/actions.js b/legacy-files/scripts/actions.js similarity index 100% rename from public/scripts/actions.js rename to legacy-files/scripts/actions.js diff --git a/public/scripts/navigation.js b/legacy-files/scripts/navigation.js similarity index 100% rename from public/scripts/navigation.js rename to legacy-files/scripts/navigation.js diff --git a/public/scripts/pages/devices.js b/legacy-files/scripts/pages/devices.js similarity index 100% rename from public/scripts/pages/devices.js rename to legacy-files/scripts/pages/devices.js diff --git a/public/scripts/pages/information.js b/legacy-files/scripts/pages/information.js similarity index 100% rename from public/scripts/pages/information.js rename to legacy-files/scripts/pages/information.js diff --git a/public/scripts/pages/login.js b/legacy-files/scripts/pages/login.js similarity index 100% rename from public/scripts/pages/login.js rename to legacy-files/scripts/pages/login.js diff --git a/public/scripts/pages/logs.js b/legacy-files/scripts/pages/logs.js similarity index 100% rename from public/scripts/pages/logs.js rename to legacy-files/scripts/pages/logs.js diff --git a/public/scripts/pages/network.js b/legacy-files/scripts/pages/network.js similarity index 100% rename from public/scripts/pages/network.js rename to legacy-files/scripts/pages/network.js diff --git a/legacy-files/scripts/pages/settings.js b/legacy-files/scripts/pages/settings.js new file mode 100644 index 0000000..98b4674 --- /dev/null +++ b/legacy-files/scripts/pages/settings.js @@ -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() +} \ No newline at end of file diff --git a/notas.txt b/notas.txt new file mode 100644 index 0000000..e91e018 --- /dev/null +++ b/notas.txt @@ -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"' + }); + } +}); \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 63cbad3..d93b49a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,6 +9,8 @@ "version": "1.0.0", "license": "ISC", "dependencies": { + "ejs": "^4.0.1", + "ejs-mate": "^4.0.0", "express": "^5.2.1", "mysql2": "^3.16.0" } @@ -26,6 +28,12 @@ "node": ">= 0.6" } }, + "node_modules/async": { + "version": "3.2.6", + "resolved": "https://registry.npmjs.org/async/-/async-3.2.6.tgz", + "integrity": "sha512-htCUDlxyyCLMgaM3xXg0C0LW2xqfuQ6p05pCEIsXuyQ+a1koYKTuBMzRNwmybfLgvJDMd0r1LTn4+E0Ti6C2AA==", + "license": "MIT" + }, "node_modules/aws-ssl-profiles": { "version": "1.1.2", "resolved": "https://registry.npmjs.org/aws-ssl-profiles/-/aws-ssl-profiles-1.1.2.tgz", @@ -35,6 +43,12 @@ "node": ">= 6.0.0" } }, + "node_modules/balanced-match": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.2.tgz", + "integrity": "sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==", + "license": "MIT" + }, "node_modules/body-parser": { "version": "2.2.2", "resolved": "https://registry.npmjs.org/body-parser/-/body-parser-2.2.2.tgz", @@ -59,6 +73,15 @@ "url": "https://opencollective.com/express" } }, + "node_modules/brace-expansion": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-2.0.2.tgz", + "integrity": "sha512-Jt0vHyM+jmUBqojB7E1NIYadt0vI0Qxjxd2TErW94wDz+E2LAm5vKMXXwg6ZZBTHPuUlDgQHKXvjGBdfcF1ZDQ==", + "license": "MIT", + "dependencies": { + "balanced-match": "^1.0.0" + } + }, "node_modules/bytes": { "version": "3.1.2", "resolved": "https://registry.npmjs.org/bytes/-/bytes-3.1.2.tgz", @@ -192,6 +215,48 @@ "integrity": "sha512-WMwm9LhRUo+WUaRN+vRuETqG89IgZphVSNkdFgeb6sS/E4OrDIN7t48CAewSHXc6C8lefD8KKfr5vY61brQlow==", "license": "MIT" }, + "node_modules/ejs": { + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/ejs/-/ejs-4.0.1.tgz", + "integrity": "sha512-krvQtxc0btwSm/nvnt1UpnaFDFVJpJ0fdckmALpCgShsr/iGYHTnJiUliZTgmzq/UxTX33TtOQVKaNigMQp/6Q==", + "license": "Apache-2.0", + "dependencies": { + "jake": "^10.9.1" + }, + "bin": { + "ejs": "bin/cli.js" + }, + "engines": { + "node": ">=0.12.18" + } + }, + "node_modules/ejs-mate": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/ejs-mate/-/ejs-mate-4.0.0.tgz", + "integrity": "sha512-AYRN19jgrTHIuzbe2mQU5SEmTw6Ja/lVo+e9NKLLsCMdaKrk7D/SFr3QroiGnbDAi6moBezBSAdYQoyLbYzfuA==", + "license": "MIT", + "dependencies": { + "ejs": "^3.1.7" + }, + "engines": { + "node": ">=10.0.0" + } + }, + "node_modules/ejs-mate/node_modules/ejs": { + "version": "3.1.10", + "resolved": "https://registry.npmjs.org/ejs/-/ejs-3.1.10.tgz", + "integrity": "sha512-UeJmFfOrAQS8OJWPZ4qtgHyWExa088/MtK5UEyoJGFH67cDEXkZSviOiKRCZ4Xij0zxI3JECgYs3oKx+AizQBA==", + "license": "Apache-2.0", + "dependencies": { + "jake": "^10.8.5" + }, + "bin": { + "ejs": "bin/cli.js" + }, + "engines": { + "node": ">=0.10.0" + } + }, "node_modules/encodeurl": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/encodeurl/-/encodeurl-2.0.0.tgz", @@ -289,6 +354,15 @@ "url": "https://opencollective.com/express" } }, + "node_modules/filelist": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/filelist/-/filelist-1.0.4.tgz", + "integrity": "sha512-w1cEuf3S+DrLCQL7ET6kz+gmlJdbq9J7yXCSjK/OZCPA+qEN1WyF4ZAf0YYJa4/shHJra2t/d/r8SV4Ji+x+8Q==", + "license": "Apache-2.0", + "dependencies": { + "minimatch": "^5.0.1" + } + }, "node_modules/finalhandler": { "version": "2.1.1", "resolved": "https://registry.npmjs.org/finalhandler/-/finalhandler-2.1.1.tgz", @@ -482,6 +556,23 @@ "integrity": "sha512-Ks/IoX00TtClbGQr4TWXemAnktAQvYB7HzcCxDGqEZU6oCmb2INHuOoKxbtR+HFkmYWBKv/dOZtGRiAjDhj92g==", "license": "MIT" }, + "node_modules/jake": { + "version": "10.9.4", + "resolved": "https://registry.npmjs.org/jake/-/jake-10.9.4.tgz", + "integrity": "sha512-wpHYzhxiVQL+IV05BLE2Xn34zW1S223hvjtqk0+gsPrwd/8JNLXJgZZM/iPFsYc1xyphF+6M6EvdE5E9MBGkDA==", + "license": "Apache-2.0", + "dependencies": { + "async": "^3.2.6", + "filelist": "^1.0.4", + "picocolors": "^1.1.1" + }, + "bin": { + "jake": "bin/cli.js" + }, + "engines": { + "node": ">=10" + } + }, "node_modules/long": { "version": "5.3.2", "resolved": "https://registry.npmjs.org/long/-/long-5.3.2.tgz", @@ -558,6 +649,18 @@ "url": "https://opencollective.com/express" } }, + "node_modules/minimatch": { + "version": "5.1.6", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-5.1.6.tgz", + "integrity": "sha512-lKwV/1brpG6mBUFHtb7NUmtABCb2WZZmm2wNiOA5hAb8VdCS4B3dtMWyvcoViccwAW/COERjXLt0zP1zXUN26g==", + "license": "ISC", + "dependencies": { + "brace-expansion": "^2.0.1" + }, + "engines": { + "node": ">=10" + } + }, "node_modules/ms": { "version": "2.1.3", "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz", @@ -657,6 +760,12 @@ "url": "https://opencollective.com/express" } }, + "node_modules/picocolors": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/picocolors/-/picocolors-1.1.1.tgz", + "integrity": "sha512-xceH2snhtb5M9liqDsmEw56le376mTZkEX/jEb/RxNFyegNul7eNslCXP9FDj/Lcu0X8KEyMceP2ntpaHrDEVA==", + "license": "ISC" + }, "node_modules/proxy-addr": { "version": "2.0.7", "resolved": "https://registry.npmjs.org/proxy-addr/-/proxy-addr-2.0.7.tgz", diff --git a/package.json b/package.json index b4bdcd9..578aed7 100644 --- a/package.json +++ b/package.json @@ -19,6 +19,8 @@ }, "homepage": "https://github.com/Coll147/OpenFi#readme", "dependencies": { + "ejs": "^4.0.1", + "ejs-mate": "^4.0.0", "express": "^5.2.1", "mysql2": "^3.16.0" } diff --git a/public/scripts/global.js b/public/scripts/global.js new file mode 100644 index 0000000..a645e0c --- /dev/null +++ b/public/scripts/global.js @@ -0,0 +1,32 @@ +// === Funciones globales === + +async function loadDB(table, key, value) { + const res = await fetch('/api/storage', { + method: 'POST', + headers: { 'Content-Type': 'application/json' }, + body: JSON.stringify({ table: 'userdata' }) + }); + + const data = await res.json(); + + console.log(data); + + return(data) +} + + +async function sha256(value) { + const res = await fetch('/api/hash', { + method: 'POST', + headers: { 'Content-Type': 'application/json' }, + body: JSON.stringify({ value }) + }); + + const data = await res.json(); + const hash = data.hash; + + console.log(value) + console.log(hash); + + return(hash) +} \ No newline at end of file diff --git a/public/scripts/pages/settings.js b/public/scripts/pages/settings.js index 98b4674..08ff0a9 100644 --- a/public/scripts/pages/settings.js +++ b/public/scripts/pages/settings.js @@ -1,70 +1,27 @@ -// Load fields +// === Funciones === + async function populate(user_id) { - let account = JSON.parse(localStorage.getItem("account")) // cargar localstorage + let db_data = await loadDB('userdata'); + const userdata = db_data[0]; + db_data = null; - 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 + document.getElementById("selector_language").value = userdata.language + document.getElementById("selector_background").value = userdata.background + document.getElementById("selector_theme").value = userdata.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) + console.log(userdata.username) + document.getElementById("user_name").textContent = userdata.username + document.getElementById("user_avatar").src = `https://gravatar.com/avatar/${await sha256(userdata.email)}` + console.log(userdata.email) } + + +// === Eventos === + 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() } \ No newline at end of file diff --git a/public/styles/main-default.css b/public/styles/main-default.css index 781f6de..7232ad0 100644 --- a/public/styles/main-default.css +++ b/public/styles/main-default.css @@ -1,5 +1,7 @@ /* themes config on actions.js */ + + /* ===== Estilo general ===== */ * { box-sizing: border-box; @@ -89,7 +91,7 @@ body { display: flex; flex-direction: column; margin: 20px; - height: 100%; + height: calc(100% - 40px); } .main_header { diff --git a/server.js b/server.js new file mode 100644 index 0000000..c8672ab --- /dev/null +++ b/server.js @@ -0,0 +1,109 @@ +const express = require("express"); +const engine = require('ejs-mate'); +const mysql = require('mysql2'); +const crypto = require("crypto"); +const fs = require("fs"); +const path = require("path"); +const { loadEnvFile } = require('node:process'); +loadEnvFile("./.env"); + + +const conection = mysql.createConnection({ + host: process.env.DB_HOST, + port: process.env.DB_PORT, + user: process.env.DB_USER, + password: process.env.DB_PASS, + database: process.env.DB_NAME +}); + +const webserver = express(); +const PORT = process.env.PORT || 3000; + +webserver.use(express.json()); + +// Static files +webserver.use(express.static("public")); + +// Views & EJS +webserver.engine('ejs', engine); +webserver.set('views', path.join(__dirname, 'views')); +webserver.set('view engine', 'ejs'); + + +// API +webserver.post('/api/hash', (req, res) => { + const { value } = req.body; + + const hash = crypto.createHash('sha256').update(value).digest('hex'); + res.json({ hash }); + console.log(hash) +}); + +webserver.post('/api/storage', (req, res) => { + const { table, key, value } = req.body; + + if (table && !key && !value) { + const query = 'SELECT * FROM ??' + conection.query(query, [table], (error,rows) => { + console.log(rows) + + return res.json(rows); + }) + } +}) + +// Web routes +webserver.get("/", (req, res) => { + res.render("pages/dashboard", { + title: "OpenFi", + publicIP: "192.168.1.1" + }); +}); + +webserver.get("/dashboard/dashboard", (req, res) => { + res.render("pages/dashboard", { + title: "OpenFi - Dashboard", + publicIP: "192.168.1.1" + }); +}); +webserver.get("/dashboard/topology", (req, res) => { + res.render("pages/topology", { + title: "OpenFi - Topology", + }); +}); +webserver.get("/dashboard/devices", (req, res) => { + res.render("pages/devices", { + title: "OpenFi - Devices", + }); +}); +webserver.get("/dashboard/logs", (req, res) => { + res.render("pages/logs", { + title: "OpenFi - Logs", + }); +}); +webserver.get("/dashboard/wifi", (req, res) => { + res.render("pages/wifi", { + title: "OpenFi - Wifi", + }); +}); +webserver.get("/dashboard/network", (req, res) => { + res.render("pages/network", { + title: "OpenFi - Network", + }); +}); +webserver.get("/dashboard/settings", (req, res) => { + res.render("pages/settings", { + title: "OpenFi - Settings", + }); +}); +webserver.get("/dashboard/information", (req, res) => { + res.render("pages/information", { + title: "OpenFi - Information", + }); +}); + + +// INICIO SERVIDOR +webserver.listen(PORT, () => { + console.log(`Servidor corriendo en http://localhost:${PORT}`); +}); \ No newline at end of file diff --git a/start.js b/start.js index 91ae501..cda9877 100644 --- a/start.js +++ b/start.js @@ -1,4 +1,4 @@ const port = process.argv[2] || 3000; process.env.PORT = port; -require('./backend/server.js'); \ No newline at end of file +require('./server'); \ No newline at end of file diff --git a/views/main.ejs b/views/main.ejs new file mode 100644 index 0000000..b8ee996 --- /dev/null +++ b/views/main.ejs @@ -0,0 +1,44 @@ + + + + + <%= title %> + + + + + + + + <%- include ('partials/navbar') %> + + +
+ <%- body -%> +
+ + + + + diff --git a/views/pages/dashboard.ejs b/views/pages/dashboard.ejs new file mode 100644 index 0000000..cd22093 --- /dev/null +++ b/views/pages/dashboard.ejs @@ -0,0 +1,71 @@ +<% layout('main') -%> + + +
+
+

Dashboard

+
+ +
+ +
+
+

Internet

+

[Online]

+

Public IP: 192.168.1.1

+

Latency: 10ms

+

Download: 150Mbps

+

Upload: 50Mbps

+
+ +
+

Devices

+

[All Working]

+

APs: 3

+

Switches: 2

+

Gateways: 1

+
+ +
+

Clients

+

[Optimal Experience]

+

Wireless: 30

+

Wired: 15

+
+
+ +
+
+

Throughput

+
+ placeholder +
+
+ +
+

Recent Alerts

+
+ Update available for <device> + 2 minutes ago +
+
+ High CPU usage on <gateway> + 12 minutes ago +
+
+ Internet connection restored + 14 minutes ago +
+
+ New login from 192.168.5.23 + 20 minutes ago +
+
+ Internet connection lost + 25 minutes ago +
+
+
+ +
+
\ No newline at end of file diff --git a/views/pages/devices.ejs b/views/pages/devices.ejs new file mode 100644 index 0000000..4ea481c --- /dev/null +++ b/views/pages/devices.ejs @@ -0,0 +1,51 @@ +<% layout('main') -%> + + +
+
+

Devices

+ +
+ +
+
+ + + + + + + + + + + + + + + +
DEVICEIP ADDRESSSTATUSUPTIMEMODELVERSIONACTIONS
+
+ + +
+ +
+ + + \ No newline at end of file diff --git a/views/pages/information.ejs b/views/pages/information.ejs new file mode 100644 index 0000000..d489fe9 --- /dev/null +++ b/views/pages/information.ejs @@ -0,0 +1,37 @@ +<% layout('main') -%> + + +
+
+

Information

+
+ +
+
+ +
+
+

Links

+

Github: coll147/OpenFi

+

Discord: Invite Link

+

Contact: contact@coll147.com

+
+
+ +
+
+

Latest Updates

+
+ Author: +
+
+ Commit: +
+
+ Info:

+
+
+
+ +
+
\ No newline at end of file diff --git a/views/pages/logs.ejs b/views/pages/logs.ejs new file mode 100644 index 0000000..949902c --- /dev/null +++ b/views/pages/logs.ejs @@ -0,0 +1,49 @@ +<% layout('main') -%> + + +
+ +
+

Logs

+ + +
+ +
+ +
+ + + + + + + + + + + + + + + + +
EventDeviceTime RiskInformation
+
+ + + +
+
\ No newline at end of file diff --git a/views/pages/network.ejs b/views/pages/network.ejs new file mode 100644 index 0000000..4ae4cf0 --- /dev/null +++ b/views/pages/network.ejs @@ -0,0 +1,31 @@ +<% layout('main') -%> + + +
+
+

Network

+
+ +
+
+ + + + + + + + + + + + +
NameRouterSubnetConcesions
+
+ + +
+ +
\ No newline at end of file diff --git a/views/pages/settings.ejs b/views/pages/settings.ejs new file mode 100644 index 0000000..11ec2f4 --- /dev/null +++ b/views/pages/settings.ejs @@ -0,0 +1,82 @@ +<% layout('main') -%> + + +
+ +
+

Settings

+
+ +
+
+ +
+
+

Interface

+
+

Language:

+ +
+
+

Background:

+ +
+
+

Theme:

+ +
+
+ +
+

Account

+
+ + +
+
+ mystery
+ + +
+
+
+ + +
+
+ + +
+
+ +
+

Profile

+
+

+
+
+ + + +
+
+ +
+
+
+
+ + + + \ No newline at end of file diff --git a/views/pages/topology.ejs b/views/pages/topology.ejs new file mode 100644 index 0000000..8f7486f --- /dev/null +++ b/views/pages/topology.ejs @@ -0,0 +1,20 @@ +<% layout('main') -%> + + +
+
+

Topology

+
+ +
+
+ por hacer +
+ + +
+ +
\ No newline at end of file diff --git a/views/pages/wifi.ejs b/views/pages/wifi.ejs new file mode 100644 index 0000000..c92c3c4 --- /dev/null +++ b/views/pages/wifi.ejs @@ -0,0 +1,20 @@ +<% layout('main') -%> + + +
+
+

Wi-Fi

+
+ +
+
+ por hacer +
+ + +
+ +
\ No newline at end of file diff --git a/views/partials/navbar.ejs b/views/partials/navbar.ejs new file mode 100644 index 0000000..80acb8e --- /dev/null +++ b/views/partials/navbar.ejs @@ -0,0 +1,18 @@ + \ No newline at end of file