This repository has been archived by the owner on Jun 13, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
index.js
executable file
·72 lines (64 loc) · 2.43 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/usr/bin/env node
var fs = require('fs');
var ejs = require('ejs');
var express = require('express');
var morgan = require('morgan');
var os = require('os');
var config = require('minimist')(process.argv.slice(2), {
string: ["theme","listen","interface","port","title","reload"],
boolean: "errors",
default: {ip:"127.0.0.1",port:"8000",theme:"simplex",errors:false,title:"SWMPjs | {hostname}",interface:"eth0",reload:"60"},
unknown:function(arg){
console.log("Available arguments:");
console.log("\t--errors\tfalse\tshow errors?.");
console.log("\t--listen\t127.0.0.1\taddress to listen on");
console.log("\t--theme\tsimplex\tpick a stylesheet from the css/themes directory");
console.log("\t--port\t8000\tWhat port to listen on?");
console.log("\t--interface\teth0\tWhat interface to report IP for?");
console.log("\t--reload\t60\tHow often to refresh the page (in seconds)?");
}
});
var system = require('./lib/system.js');
var app = express();
var getTitle = function(){
return config.title.replace("{hostname}",os.hostname())
.replace("{ip}",system.getLanIp([],config).join(" "))
.replace("{os}",system.getOperatingSystem([]))
.replace("{kernel}",system.getKernel([]));
}
app.use(morgan('combined'));
app.set('trust proxy', 'loopback,uniquelocal');
app.set('view engine','ejs');
app.get('/', function(req, res){
var errors = [];
var data = {
hostname: system.getSystemHostname(errors),
ip: system.getLanIp(errors,config),
cores: system.getCpuCoresNumber(errors),
os: system.getOperatingSystem(errors),
kernel: system.getKernel(errors),
uptime: system.getUptime(errors),
bootTime: system.getBootupTime(errors),
cpumodel: system.getCpuModel(errors),
cpufrequency: system.getCpuFrequency(errors),
cpucache: system.getCpuCacheSize(errors),
cputemp: system.getCpuTemperature(errors),
cpudata: system.getCpuLoadData(errors),
ramdata: system.getRamInfo(errors),
swap: system.getSwapData(errors),
network: system.getNetworkData(errors),
disk: system.getDiskData(errors),
errors: errors,
title: getTitle(),
config: {
theme: req.query && req.query.theme ? req.query.theme : config.theme,
reload: config.reload,
show_errors: config.errors
}
}
res.render('index.ejs', data);
});
app.use('/js', express.static(__dirname+'/js'));
app.use('/css', express.static(__dirname+'/css'));
app.use('/', express.static(__dirname,{extensions: ['svg','png','ico']}));
app.listen(parseInt(config.port),config.listen);