Comparing version 0.0.5 to 0.1.0
#!/usr/bin/env node | ||
var app, argv, express, fslib, http, util, yargs; | ||
var app, argv, bodyParser, express, fslib, http, util, yargs, _ref; | ||
@@ -10,24 +10,47 @@ fslib = require('fs'); | ||
argv = require('yargs').usage('Start a shell server. Usage: $0').example('$0 -r ROUTES -p PORT', 'Start the shell server with the given config file')["default"]('p', 6333).alias('p', 'port').describe('p', 'Specified the listening port, default is 6333').demand('r').alias('r', 'routes').describe('r', 'Specified several route files').argv; | ||
argv = require('yargs').usage('Usage: $0 [-b bind ip] [-p port] [-c config file] [-t template files] template expression').example('$0 -b 127.0.0.1 -p 6333 -t example-routes/iptable.template', 'Start shrvr at 127.0.0.1:6333 follow the template example-routes/iptable.template')["default"]('p', 6333).option('b', { | ||
alias: 'bind-ip', | ||
describe: 'Specifies the IP address that shrvr binds to. Default bind all interfaces.', | ||
type: 'string', | ||
"default": '0.0.0.0' | ||
}).option('p', { | ||
alias: 'port', | ||
describe: 'Specifies the port shrvr listens on', | ||
"default": 6334 | ||
}).option('c', { | ||
alias: 'config', | ||
describe: 'Specifies a configuration file for shrvr.' | ||
}).option('t', { | ||
alias: 'templates', | ||
describe: 'Specifies the template files in order to load from, seprated by comma.' | ||
}).help('help').version("shrvr(Shell server) " + (require('../../package').version) + "\n", 'version').argv; | ||
express = require('express'); | ||
bodyParser = require('body-parser'); | ||
app = express(); | ||
argv.routes.split(/\s*,\s*/).forEach(function(filepath) { | ||
var routes; | ||
if (fslib.existsSync(filepath)) { | ||
routes = util.parseFile(filepath); | ||
} else { | ||
throw "Cannot find route file at: " + filepath; | ||
} | ||
return routes.forEach(function(route) { | ||
return app[route.verb](route.pathname, util.createHandler(route.command, route.safe)); | ||
app.set('trust proxy', true); | ||
app.use(bodyParser.json()); | ||
if ((_ref = argv.templates) != null) { | ||
_ref.split(/\s*,\s*/).forEach(function(filepath) { | ||
var template; | ||
if (fslib.existsSync(filepath)) { | ||
template = util.parseFile(filepath); | ||
} else { | ||
throw "Cannot parse template file: " + filepath; | ||
} | ||
return templates.forEach(function(route) { | ||
return app[route.verb](route.pathname, util.createHandler(route.command, route.safe)); | ||
}); | ||
}); | ||
}); | ||
} | ||
http = require('http'); | ||
http.createServer(app).listen(argv.p, function() { | ||
http.createServer(app).listen(argv.p, argv.b, function() { | ||
return console.log("Shrvr is listening on port " + argv.p); | ||
}); |
@@ -142,10 +142,10 @@ var exec, pathlib, util; | ||
return describe('#parse', function() { | ||
var addRule, deleteRule, iptablePath, text; | ||
var addRule, deleteRule, iptablePath; | ||
iptablePath = '/iptables/:source_ip/:port/:destination'; | ||
deleteRule = 'iptables -D PREROUTING -p tcp -s #source_ip --dport #port -j DNAT --to-destination #destination'; | ||
addRule = 'iptables -A PREROUTING -p tcp -s #source_ip --dport #port -j DNAT --to-destination #destination'; | ||
text = "alias iptable_path=" + iptablePath + "\nalias delete_rule=" + deleteRule + "\nalias add_rule=" + addRule + "\n"; | ||
text += 'POST iptable_path delete_rule && add_rule\nDELETE iptable_path delete_rule'; | ||
return it('should parse to routes', function(done) { | ||
var route; | ||
it('should parse to routes', function() { | ||
var route, text; | ||
text = "alias iptable_path=" + iptablePath + "\nalias delete_rule=" + deleteRule + "\nalias add_rule=" + addRule + "\n"; | ||
text += 'POST iptable_path delete_rule && add_rule\nDELETE iptable_path delete_rule'; | ||
route = util.parse(text); | ||
@@ -157,6 +157,14 @@ route[0].verb.should.eql('post'); | ||
route[1].pathname.should.eql(iptablePath); | ||
route[1].command.template.should.eql(deleteRule); | ||
return done(); | ||
return route[1].command.template.should.eql(deleteRule); | ||
}); | ||
return it('should parse to routes', function() { | ||
var route, text; | ||
text = "alias iptable_path=" + iptablePath + "\nalias delete_rule=" + deleteRule + "\nalias add_rule=" + addRule + "\n"; | ||
text += 'POST iptable_path delete_rule && add_rule && echo "delete_rule" | at now + 48hour'; | ||
route = util.parse(text); | ||
route[0].verb.should.eql('post'); | ||
route[0].pathname.should.eql(iptablePath); | ||
return route[0].command.template.should.eql(deleteRule + " && " + addRule + " && echo \"" + deleteRule + "\" | at now + 48hour"); | ||
}); | ||
}); | ||
}); |
{ | ||
"name": "shrvr", | ||
"version": "0.0.5", | ||
"version": "0.1.0", | ||
"description": "Shell server", | ||
@@ -5,0 +5,0 @@ "bin": { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
15722
32
6
10
319