commit 7d17b5eb53022183b245bd18de5a9f5afb492bac Author: louispaulb Date: Wed Mar 25 10:37:33 2026 -0400 Initial commit β€” Targo Device Monitor 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) 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}`)); +});