-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Now has an nft interface, albiet crude. Now flushes tables on init.
- Loading branch information
Dustyn Blackmore
committed
Apr 17, 2018
1 parent
8482d46
commit f04482f
Showing
3 changed files
with
98 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
const rules = require('./rules'); | ||
|
||
const nft = (dependencies) => { | ||
|
||
if (Object.keys(dependencies).includes('exec')) { | ||
return Object.assign( | ||
{}, | ||
nft, | ||
rules(dependencies.exec) | ||
) | ||
} | ||
|
||
return false; | ||
} | ||
|
||
module.exports = nft; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
function execute (exec, command) { | ||
return new Promise((resolve, reject) => { | ||
exec('nft ' + command, (error, stdout, stderr) => { | ||
if (error) { | ||
reject(error) | ||
} else { | ||
if (stdout) { | ||
resolve(stdout) | ||
} else { | ||
resolve(stderr) | ||
} | ||
} | ||
}) | ||
}) | ||
} | ||
|
||
|
||
function executeReturnHandle (exec, command) { | ||
return new Promise((resolve, reject) => { | ||
exec('nft --echo --handle ' + command, (error, stdout, stderr) => { | ||
if (error) { | ||
reject(error) | ||
} else { | ||
if (stdout) { | ||
let unparsedResult = stdout.split(' '); | ||
resolve(unparsedResult[unparsedResult.length - 1]); | ||
} else { | ||
resolve(stderr) | ||
} | ||
} | ||
}) | ||
}) | ||
} | ||
|
||
const rules = (exec) => ({ | ||
add: (rule) => { | ||
return executeReturnHandle(exec, rule); | ||
}, | ||
flush: () => { | ||
return execute(exec, 'flush ruleset'); | ||
}, | ||
inject: (filename) => { | ||
return execute(exec, '-f ' + filename); | ||
}, | ||
list: () => { | ||
return execute(exec, 'list ruleset'); | ||
}, | ||
removeByTableSetChainHandle: (table, set, chain, handle) => { | ||
return executeReturnHandle(exec, 'delete rule table ' + table + ' ' + set + ' ' + chain + ' ' + handle) | ||
} | ||
}) | ||
|
||
module.exports = rules; |