forked from lucaskahl/ninjaLAB
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
78 lines (68 loc) · 1.98 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
73
74
75
76
77
78
const { Notification } = require('electron');
const { exec } = require('child_process');
const path = require('path')
const Store = require('electron-store');
const store = new Store();
const network = (function() {
const module = {};
module.devices = [];
module._networkNotification = (title, body) => {
let iconAddress = path.join(__dirname, 'assets/logo.png');
const notif = {
title: title,
body: body,
icon: iconAddress
};
new Notification(notif).show();
}
module.getDevices = () => {
exec('networksetup -listallnetworkservices', (err, stdout, stderr) => {
if (err) {
console.log(err)
} else {
stdout.split(/\r?\n/).forEach(item => {
if (item.length > 0 && item !== 'An asterisk (*) denotes that a network service is disabled.') {
module.devices.push(item);
}
});
store.set('devices', module.devices);
}
})
};
module.getActiveDNS = (item) => {
exec(`networksetup -getdnsservers ${item}`, (err, stdout, stderr) => {
if (err) {
console.log(err)
} else {
console.log(stdout);
}
})
};
module.enableDNS = (item, dns) => {
exec(`networksetup -setdnsservers ${item} ${dns}`, (err, stdout, stderr) => {
if (err) {
module._networkNotification('ninjaLAB', 'Error on adding your DNS');
} else {
module._networkNotification('ninjaLAB', 'DNS added successfully');
}
});
}
module.disableDNS = (item) => {
exec(`networksetup -setdnsservers ${item} empty`, (err, stdout, stderr) => {
if (err) {
module._networkNotification('ninjaLAB', 'Error on removing your DNS');
} else {
module._networkNotification('ninjaLAB', 'DNS removed successfully');
}
});
}
return {
getDevices: module.getDevices,
getActiveDNS: module.getActiveDNS,
enableDNS: module.enableDNS,
disableDNS: module.disableDNS,
};
})();
module.exports = {
network: network
}