-
Notifications
You must be signed in to change notification settings - Fork 1
/
MMM-portscan.js
105 lines (88 loc) · 2.9 KB
/
MMM-portscan.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
/* Magic Mirror
* Module: MMM-portscan
* https://github.com/Wanztwurst/MMM-portscan
* License: GPLv3
*/
Module.register('MMM-portscan', {
defaults: {
updateInterval: 10, // in seconds
textalign: 'left',
color_open: '#00ff00',
color_closed: '#ff0000',
hosts: [
{
hostname: '127.0.0.1',
ports: [
{port: 80, displayedName: 'http'},
{port: 42}
]
},
{
hostname: 'github.com',
displayedName: 'GitHub',
ports: [
{port: 80},
{port: 22, displayedName: 'ssh'}
]
}
]
},
payload: {},
start: function () {
// Log.info('Starting module: ' + this.name);
Log.info(this.config);
this.payload = this.config.hosts;
this.update();
setInterval(
this.update.bind(this),
this.config.updateInterval * 1000
);
},
update: function () {
this.sendSocketNotification('PORTSCAN_REQUEST', this.payload);
},
socketNotificationReceived: function (notification, payload) {
if (notification === 'PORTSCAN_RESPONSE') {
//Log.info(payload);
if (payload) {
this.payload = payload;
this.updateDom();
}
}
},
getStyles: function() {
return ["portscan.css"];
},
getDom: function () {
var self = this;
var wrapper = document.createElement("div");
this.payload.forEach(function(host) {
var hostDiv = document.createElement("div");
//console.log(self.config);
hostDiv.style.textAlign = self.config.textalign;
// name
var nameDiv = document.createElement("div");
nameDiv.innerHTML = host.displayedName !== undefined ? host.displayedName : host.hostname;;
nameDiv.className = "bright";
hostDiv.appendChild(nameDiv);
// ports
host.ports.forEach(function(port) {
var portDiv = document.createElement("div");
var classes = "small ";
if(port.isOpen === false) {
classes += "port-closed";
portDiv.style.color = self.config.color_closed;
} else if(port.isOpen === true) {
classes += "port-open";
portDiv.style.color = self.config.color_open;
}
portDiv.className = classes;
portDiv.innerHTML = port.displayedName !== undefined ? port.displayedName : port.port;
hostDiv.appendChild(portDiv);
});
// add host to wrapping container
wrapper.appendChild(hostDiv);
});
return wrapper;
}
});