From 7d17b5eb53022183b245bd18de5a9f5afb492bac Mon Sep 17 00:00:00 2001 From: louispaulb Date: Wed, 25 Mar 2026 10:37:33 -0400 Subject: [PATCH] =?UTF-8?q?Initial=20commit=20=E2=80=94=20Targo=20Device?= =?UTF-8?q?=20Monitor?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Standalone dashboard reading from Oktopus MongoDB. Displays: serial, MAC, WAN IP, firmware, uptime, WiFi signal/clients, CPU/RAM usage with visual bars. Auto-refresh 30s. Co-Authored-By: Claude Opus 4.6 (1M context) --- index.html | 149 +++++++++++++++++++++++++++++++++++++++++++++++++++ package.json | 17 ++++++ server.js | 45 ++++++++++++++++ 3 files changed, 211 insertions(+) create mode 100644 index.html create mode 100644 package.json create mode 100644 server.js diff --git a/index.html b/index.html new file mode 100644 index 0000000..575bb24 --- /dev/null +++ b/index.html @@ -0,0 +1,149 @@ + + + + + +Targo β€” Device Monitor + + + +
+

πŸ“‘ Targo Device Monitor

+ 0 + + +
+ +
+
+ + + + diff --git a/package.json b/package.json new file mode 100644 index 0000000..3502ad2 --- /dev/null +++ b/package.json @@ -0,0 +1,17 @@ +{ + "name": "device-monitor", + "version": "1.0.0", + "description": "", + "main": "server.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1", + "start": "node server.js" + }, + "keywords": [], + "author": "", + "license": "ISC", + "type": "commonjs", + "dependencies": { + "mongodb": "^7.1.1" + } +} diff --git a/server.js b/server.js new file mode 100644 index 0000000..cdea2e5 --- /dev/null +++ b/server.js @@ -0,0 +1,45 @@ +const http = require('http'); +const fs = require('fs'); +const { MongoClient } = require('mongodb'); +const path = require('path'); + +const PORT = 3002; +const MONGO_URI = 'mongodb://localhost:27017'; + +let db; + +async function connectDB() { + const client = new MongoClient(MONGO_URI); + await client.connect(); + db = client.db('oktopus'); + console.log('Connected to MongoDB'); +} + +const server = http.createServer(async (req, res) => { + if (req.url === '/api/monitor/devices') { + try { + const devices = await db.collection('devices').find({}).toArray(); + res.writeHead(200, { 'Content-Type': 'application/json' }); + res.end(JSON.stringify(devices)); + } catch (e) { + res.writeHead(500); res.end(JSON.stringify({ error: e.message })); + } + } else { + // Serve static files + let filePath = req.url === '/' ? '/index.html' : req.url; + filePath = path.join(__dirname, filePath); + try { + const content = fs.readFileSync(filePath); + const ext = path.extname(filePath); + const types = { '.html': 'text/html', '.css': 'text/css', '.js': 'application/javascript' }; + res.writeHead(200, { 'Content-Type': types[ext] || 'text/plain' }); + res.end(content); + } catch { + res.writeHead(404); res.end('Not found'); + } + } +}); + +connectDB().then(() => { + server.listen(PORT, () => console.log(`Device Monitor: http://localhost:${PORT}`)); +});