diff --git a/modules/configure-commander.js b/modules/configure-commander.js index 1b5076a..526e633 100644 --- a/modules/configure-commander.js +++ b/modules/configure-commander.js @@ -2,21 +2,32 @@ exports.setup = function(args){ const program = require('commander'); program .version('2.5.0') + // Server Config .option('-p, --port ', 'Select Port', /^\d+$/i, 3000) - .option('-t, --tunnel', 'Use nat-pmp to configure port fowarding') - .option('-g, --gateway ', 'Manually set gateway IP for the tunnel option') - .option('-r, --refresh ', 'Refresh rate', /^\d+$/i) - .option('-o, --protocol ', 'Protocol for tunneling', /^(upnp|natpnp)$/i, 'natpnp') + .option('-i, --userinterface ', 'Specify folder name that will be served as the UI', 'public') + .option('-s, --secret ', 'Set the login secret key') + + // SSL + .option('-c, --cert ', 'SSL Certificate File') + .option('-k, --key ', 'SSL Key File') + + // User System .option('-u, --user ', 'Set Username') .option('-x, --password ', 'Set Password') .option('-e, --email ', 'Set User Email (optional)') .option('-G, --guest ', 'Set Guest Username') .option('-X, --guestpassword ', 'Set Guest Password') + + // Port Forwarding + .option('-t, --tunnel', 'Use nat-pmp to configure port fowarding') + .option('-g, --gateway ', 'Manually set gateway IP for the tunnel option') + .option('-r, --refresh ', 'Refresh rate', /^\d+$/i) + .option('-o, --protocol ', 'Protocol for tunneling', /^(upnp|natpnp)$/i, 'natpnp') + + // DB .option('-d, --database ', 'Specify Database Filepath', 'mstreamdb.lite') - .option('-i, --userinterface ', 'Specify folder name that will be served as the UI', 'public') - .option('-s, --secret ', 'Set the login secret key') .option('-D, --databaseplugin ', '', /^(sqlite|beets)$/i, 'sqlite') // TODO: Add support for other DBs when ready - .option('-c, --beetscommand ', 'Does not work right now') + .option('-B, --beetscommand ', 'Does not work right now') .parse(args); @@ -83,6 +94,13 @@ exports.setup = function(args){ } } + // SSL stuff + if(program.key && program.cert){ + program3.ssl = {}; + program3.ssl.key = program.key; + program3.ssl.cert = program.cert; + } + return program3; } diff --git a/mstream.js b/mstream.js index 1123ea1..7d0a913 100755 --- a/mstream.js +++ b/mstream.js @@ -3,7 +3,7 @@ module.exports = function (program) { // TODO: Verify program variable - const server = require('http').createServer(); + const express = require('express'); const mstream = express(); const fs = require('fs'); // File System @@ -11,7 +11,19 @@ module.exports = function (program) { const bodyParser = require('body-parser'); const uuidV4 = require('uuid/v4'); + var server; + if(program.ssl && program.ssl.cert && program.ssl.key){ + // TODO: Verify files are real + + server = require('https').createServer({ + key: fs.readFileSync(program.ssl.key), + cert: fs.readFileSync( program.ssl.cert) + }); + }else{ + console.log('SSL DISABLED'); + server = require('http').createServer(); + } // Magic Middleware Things mstream.use(bodyParser.json()); // support json encoded bodies @@ -70,7 +82,7 @@ module.exports = function (program) { req.parsedJSON = JSON.parse(req.body.json); next(); }catch(err){ - res.status(507).send(JSON.stringify({'Error':'Could Not Decoded JSON'})); + res.status(507).json({'Error':'Could Not Decoded JSON'}); } }); @@ -127,12 +139,12 @@ module.exports = function (program) { // TODO: Add individual song mstream.get('/db/add-songs', function(req, res){ - res.send('Coming Soon!'); + res.status(500).json( {error: 'Coming Soon'} ); }); // TODO: Get Album Art calls mstream.post( '/get-album-art', function(req, res){ - res.send('Coming Soon!'); + res.status(500).json( {error: 'Coming Soon'} ); }); mstream.post( '/scrape-user-info', function(req, res){