Skip to content

Commit

Permalink
Fixes #2.
Browse files Browse the repository at this point in the history
  • Loading branch information
diosney committed Jul 3, 2014
1 parent ce4e551 commit 1fd1dc9
Show file tree
Hide file tree
Showing 21 changed files with 113 additions and 21 deletions.
18 changes: 17 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,23 @@ Basically the only system requirement is that the **netfilter** framework to be
sure is installed by default in Linux based OSes.

Other requirement is about permission levels. To properly execute the provided methods the application that uses the
module must have the proper `sudo` privileges.
module must have the proper `sudo` privileges. One way to do it could be by adding a custom user to the system:

`sudo adduser --system --no-create-home netfilter`

then add its permissions at `/etc/sudoers` file:

`netfilter ALL= NOPASSWD: /sbin/iptables, /sbin/ip6tables, /sbin/ipset`

and then execute the commands with `sudo: true`:

iptables.flush({
sudo: true
}, function (error) {
if (error) {
console.log(error);
}
});

## Issues

Expand Down
6 changes: 5 additions & 1 deletion lib/ipset/add.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,14 @@ module.exports = function (options, cb) {
throw new Error('Invalid arguments. Signature: (options, callback?)');
}

var ipset_cmd = (options.sudo)
? 'sudo'
: '';

/*
* Build cmd to execute.
*/
var cmd = ['ipset', 'add', '-exist'];
var cmd = [ipset_cmd, 'ipset', 'add', '-exist'];
var args = [];

/*
Expand Down
6 changes: 5 additions & 1 deletion lib/ipset/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,14 @@ module.exports = function (options, cb) {
throw new Error('Invalid arguments. Signature: (options, callback?)');
}

var ipset_cmd = (options.sudo)
? 'sudo'
: '';

/*
* Build cmd to execute.
*/
var cmd = ['ipset', 'create', '-exist'];
var cmd = [ipset_cmd, 'ipset', 'create', '-exist'];
var args = [];

/*
Expand Down
6 changes: 5 additions & 1 deletion lib/ipset/del.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,14 @@ module.exports = function (options, cb) {
throw new Error('Invalid arguments. Signature: (options, callback?)');
}

var ipset_cmd = (options.sudo)
? 'sudo'
: '';

/*
* Build cmd to execute.
*/
var cmd = ['ipset', 'del', '-exist'];
var cmd = [ipset_cmd, 'ipset', 'del', '-exist'];
var args = [];

/*
Expand Down
6 changes: 5 additions & 1 deletion lib/ipset/destroy.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,14 @@ module.exports = function (/* options?, cb */) {
throw new Error('Invalid arguments. Signature: [options,] callback');
}

var ipset_cmd = (options.sudo)
? 'sudo'
: '';

/*
* Build cmd to execute.
*/
var cmd = ['ipset', 'destroy'];
var cmd = [ipset_cmd, 'ipset', 'destroy'];
var args = [];

/*
Expand Down
6 changes: 5 additions & 1 deletion lib/ipset/flush.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,14 @@ module.exports = function (/* options?, cb */) {
throw new Error('Invalid arguments. Signature: [options,] callback');
}

var ipset_cmd = (options.sudo)
? 'sudo'
: '';

/*
* Build cmd to execute.
*/
var cmd = ['ipset', 'flush'];
var cmd = [ipset_cmd, 'ipset', 'flush'];
var args = [];

/*
Expand Down
6 changes: 5 additions & 1 deletion lib/ipset/rename.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,14 @@ module.exports = function (options, cb) {
throw new Error('Invalid arguments. Signature: (options, callback?)');
}

var ipset_cmd = (options.sudo)
? 'sudo'
: '';

/*
* Build cmd to execute.
*/
var cmd = ['ipset', 'rename'];
var cmd = [ipset_cmd, 'ipset', 'rename'];
var args = [];

/*
Expand Down
6 changes: 5 additions & 1 deletion lib/ipset/swap.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,14 @@ module.exports = function (options, cb) {
throw new Error('Invalid arguments. Signature: (options, callback?)');
}

var ipset_cmd = (options.sudo)
? 'sudo'
: '';

/*
* Build cmd to execute.
*/
var cmd = ['ipset', 'swap'];
var cmd = [ipset_cmd, 'ipset', 'swap'];
var args = [];

/*
Expand Down
6 changes: 5 additions & 1 deletion lib/ipset/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,14 @@ module.exports = function (options, cb) {
throw new Error('Invalid arguments. Signature: (options, callback?)');
}

var ipset_cmd = (options.sudo)
? 'sudo'
: '';

/*
* Build cmd to execute.
*/
var cmd = ['ipset', 'test'];
var cmd = [ipset_cmd, 'ipset', 'test'];
var args = [];

/*
Expand Down
6 changes: 5 additions & 1 deletion lib/ipset/version.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,14 @@ module.exports = function (cb) {
throw new Error('Invalid arguments. Signature: (callback)');
}

var ipset_cmd = (options.sudo)
? 'sudo'
: '';

/*
* Build cmd to execute.
*/
var cmd = ['ipset', 'version'];
var cmd = [ipset_cmd, 'ipset', 'version'];

/*
* Execute command.
Expand Down
6 changes: 5 additions & 1 deletion lib/iptables/append.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@ module.exports = function (options, cb) {
? options.table
: tables.filter;

var ipt_cmd = (options.ipv6)
var ipt_cmd = (options.sudo)
? 'sudo '
: '';

ipt_cmd += (options.ipv6)
? 'ip6tables'
: 'iptables';

Expand Down
6 changes: 5 additions & 1 deletion lib/iptables/delete.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@ module.exports = function (options, cb) {
? options.table
: tables.filter;

var ipt_cmd = (options.ipv6)
var ipt_cmd = (options.sudo)
? 'sudo '
: '';

ipt_cmd += (options.ipv6)
? 'ip6tables'
: 'iptables';

Expand Down
6 changes: 5 additions & 1 deletion lib/iptables/delete_chain.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,11 @@ module.exports = function (/* options?, cb */) {
? options.table
: tables.filter;

var ipt_cmd = (options.ipv6)
var ipt_cmd = (options.sudo)
? 'sudo '
: '';

ipt_cmd += (options.ipv6)
? 'ip6tables'
: 'iptables';

Expand Down
6 changes: 5 additions & 1 deletion lib/iptables/flush.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,11 @@ module.exports = function (/* options?, cb */) {
? options.table
: tables.filter;

var ipt_cmd = (options.ipv6)
var ipt_cmd = (options.sudo)
? 'sudo '
: '';

ipt_cmd += (options.ipv6)
? 'ip6tables'
: 'iptables';

Expand Down
6 changes: 5 additions & 1 deletion lib/iptables/insert.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@ module.exports = function (options, cb) {
? options.table
: tables.filter;

var ipt_cmd = (options.ipv6)
var ipt_cmd = (options.sudo)
? 'sudo '
: '';

ipt_cmd += (options.ipv6)
? 'ip6tables'
: 'iptables';

Expand Down
6 changes: 5 additions & 1 deletion lib/iptables/new.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@ module.exports = function (options, cb) {
? options.table
: tables.filter;

var ipt_cmd = (options.ipv6)
var ipt_cmd = (options.sudo)
? 'sudo '
: '';

ipt_cmd += (options.ipv6)
? 'ip6tables'
: 'iptables';

Expand Down
6 changes: 5 additions & 1 deletion lib/iptables/policy.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@ module.exports = function (options, cb) {
? options.table
: tables.filter;

var ipt_cmd = (options.ipv6)
var ipt_cmd = (options.sudo)
? 'sudo '
: '';

ipt_cmd += (options.ipv6)
? 'ip6tables'
: 'iptables';

Expand Down
6 changes: 5 additions & 1 deletion lib/iptables/rename.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@ module.exports = function (options, cb) {
? options.table
: tables.filter;

var ipt_cmd = (options.ipv6)
var ipt_cmd = (options.sudo)
? 'sudo '
: '';

ipt_cmd += (options.ipv6)
? 'ip6tables'
: 'iptables';

Expand Down
6 changes: 5 additions & 1 deletion lib/iptables/replace.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@ module.exports = function (options, cb) {
? options.table
: tables.filter;

var ipt_cmd = (options.ipv6)
var ipt_cmd = (options.sudo)
? 'sudo '
: '';

ipt_cmd += (options.ipv6)
? 'ip6tables'
: 'iptables';

Expand Down
6 changes: 5 additions & 1 deletion lib/iptables/zero.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,11 @@ module.exports = function (/* options?, cb */) {
? options.table
: tables.filter;

var ipt_cmd = (options.ipv6)
var ipt_cmd = (options.sudo)
? 'sudo '
: '';

ipt_cmd += (options.ipv6)
? 'ip6tables'
: 'iptables';

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name" : "netfilter",
"version" : "0.2.1",
"version" : "0.2.2",
"description" : "Packet filtering framework. Wrapper to provide netfilter capabilities from Node.js",
"main" : "index.js",
"keywords" : [
Expand Down

0 comments on commit 1fd1dc9

Please sign in to comment.