UNPKG

mecano

Version:

Common functions for system deployment.

48 lines (45 loc) 1.35 kB
// Generated by CoffeeScript 1.9.1 var iptables; module.exports = function(options, callback) { if (typeof options.log === "function") { options.log("Mecano `iptables`: list existing rules"); } return this.execute({ cmd: "service iptables status &>/dev/null && iptables -S", ssh: options.ssh, log: options.log, stdout: options.stdout, stderr: options.stderr, code_skipped: 3 }, (function(_this) { return function(err, executed, stdout) { var cmd, newrules, oldrules; if (err) { return callback(err); } if (!executed) { return callback(Error("Service iptables not started")); } oldrules = iptables.parse(stdout); newrules = iptables.normalize(options.rules); cmd = iptables.cmd(oldrules, newrules); if (!cmd.length) { return callback(); } if (typeof options.log === "function") { options.log("Mecano `iptables`: modify rules"); } return _this.execute({ cmd: (cmd.join('; ')) + "; service iptables save;", ssh: options.ssh, log: options.log, trap_on_error: true, stdout: options.stdout, stderr: options.stderr }, function(err, executed) { return callback(err, true); }); }; })(this)); }; iptables = require('./misc/iptables');