UNPKG

firewall

Version:

Add or remove system firewall rules from Node.js. Currently only Windows.

56 lines (47 loc) 1.1 kB
var run = require('spawnx'), release = require('os').release; var firewall = {}; var netsh = 'netsh.exe'; firewall.add_rule = function(param, cb) { var cmd; if (parseFloat(release()) >= 6.0) { // vista or higher cmd = [netsh, 'advfirewall', 'firewall', 'add', 'rule', 'name=' + param.desc, 'dir=in', 'action=allow', 'program="' + param.bin + '"', 'enable=yes']; } else { cmd = [netsh, 'firewall', 'add', 'allowedprogram', param.bin, param.desc, 'ENABLE']; } run(cmd, { detached: true }, cb); } firewall.remove_rule = function(param, cb) { var cmd; if (parseFloat(release()) >= 6.0) { cmd = [netsh, 'advfirewall', 'firewall', 'delete', 'rule', 'name=' + param.desc]; } else { cmd = [netsh, 'firewall', 'delete', 'allowedprogram', param.bin]; } run(cmd, { detached: true }, cb); } module.exports = firewall;