network info

This commit is contained in:
cv
2021-06-13 14:17:55 +02:00
parent f066e974e6
commit 17ddfb535f
7 changed files with 112 additions and 2 deletions
@@ -7,6 +7,7 @@ import {
block as blockDef,
} from '../data/eventsDefinition.js';
import { dbModel } from '../data/dataModel.js';
import { networkInterfaces } from 'os';
function getEventTitle() {
return data.event.title;
@@ -126,3 +127,35 @@ export const dbUpload = async (req, res) => {
res.status(400).send({ message: error });
}
};
/**
* @description Gets information on IPV4 non internal interfaces
* @returns {array} - Array of objects {name: ip}
*/
const getNetworkInterfaces = () => {
const nets = networkInterfaces();
const results = [];
for (const name of Object.keys(nets)) {
for (const net of nets[name]) {
// Skip over non-IPv4 and internal (i.e. 127.0.0.1) addresses
if (net.family === 'IPv4' && !net.internal) {
results.push({
name: name,
address: net.address,
});
}
}
}
return results;
};
// Create controller for POST request to '/ontime/info'
// Returns -
// TODO: Add version
export const getInfo = async (req, res) => {
const ni = getNetworkInterfaces();
res.status(200).send({
networkInterfaces: ni,
});
};
+8 -1
View File
@@ -2,10 +2,17 @@ import express from 'express';
import uploadJson from '../utils/upload.js';
export const router = express.Router();
import { dbDownload, dbUpload } from '../controllers/ontimeController.js';
import {
dbDownload,
dbUpload,
getInfo,
} from '../controllers/ontimeController.js';
// create route between controller and '/ontime/db' endpoint
router.get('/db', dbDownload);
// create route between controller and '/ontime/db' endpoint
router.post('/db', uploadJson, dbUpload);
// create route between controller and '/ontime/info' endpoint
router.get('/info', uploadJson, getInfo);