PHP WebShell
Текущая директория: /opt/bitgo-express/node_modules/bitgo-express/bin
Просмотр файла: bitgo-express
#!/usr/bin/env node
var argumentParser = require('argparse').ArgumentParser;
var expressApp = require('../src/index.js');
var fs = require('fs');
var http = require('http');
var https = require('https');
var pjson = require('../node_modules/bitgo/package.json');
// Handle arguments
var getArgs = function () {
var parser = new argumentParser({
version: pjson.version,
addHelp: true,
description: 'BitGo-Express'
});
parser.addArgument(
['-p', '--port'], {
defaultValue: 3080,
help: 'Port to listen on'
});
parser.addArgument(
['-b', '--bind'], {
defaultValue: 'localhost',
help: 'Bind to given address to listen for connections (default: localhost)'
});
parser.addArgument(
['-e', '--env'], {
defaultValue: 'test',
help: 'BitGo environment to proxy against (prod, test)'
});
parser.addArgument(
['-d', '--debug'], {
action: 'storeTrue',
help: 'Debug logging'
});
parser.addArgument(
['-k', '--keypath'], {
help: 'Path to the SSL Key file (required if running production)'
});
parser.addArgument(
['-c', '--crtpath'], {
help: 'Path to the SSL Crt file (required if running production)'
});
parser.addArgument(
['-u', '--customrooturi'], {
help: 'Force custom root BitGo URI (e.g. https://test.bitgo.com)'
});
parser.addArgument(
['-n', '--custombitcoinnetwork'], {
help: 'Force custom bitcoin network (e.g. testnet)'
});
parser.addArgument(
['-l', '--logfile'], {
help: 'Filepath to write the access log'
});
parser.addArgument(
['--disablessl'], {
action: 'storeTrue',
help: 'Allow running against production in non-SSL mode (at your own risk!)'
});
return parser.parseArgs();
};
args = getArgs();
if (args.env === 'prod') {
if (args.bind !== 'localhost' && (!args.keypath || !args.crtpath)) {
if (!args.disablessl) {
throw new Error("Must provide keypath and crtpath for SSL when running against prod and listening on external interfaces!");
}
}
}
if ((!!args.keypath !== !!args.crtpath)) {
throw new Error("Must provide both keypath and crtpath!");
}
// Get express app
var app = expressApp(args);
// Start up http server
var server;
var baseUri = "http";
if (args.keypath && args.crtpath) {
// Run in SSL mode
var privateKey = fs.readFileSync(args.keypath, 'utf8');
var certificate = fs.readFileSync(args.crtpath, 'utf8');
var credentials = {key: privateKey, cert: certificate};
baseUri += "s";
server = https.createServer(credentials, app);
} else {
server = http.createServer(app);
}
server.listen(args.port, args.bind, function () {
baseUri += "://" + args.bind;
if (!((args.port == 80 && !args.keypath) || (args.port == 443 && args.keypath))) {
baseUri += ":" + args.port;
}
console.log('BitGo-Express running');
console.log('Environment: ' + args.env);
console.log('Base URI: ' + baseUri);
if (args.customrooturi) {
console.log('Custom root Uri: ' + args.customrooturi);
}
if (args.custombitcoinnetwork) {
console.log('Custom bitcoin network: ' + args.custombitcoinnetwork);
}
});
server.timeout = 300 * 1000; // 5 minutes
process.on('uncaughtException', function (err) {
console.log("Fatal error: " + err.message);
console.log(err.stack);
});
Выполнить команду
Для локальной разработки. Не используйте в интернете!