From 94bbf62c264cd57555a9437082fde3140ff7ab7c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Vest=C3=B8l?= Date: Fri, 8 Jun 2018 09:33:19 +0200 Subject: [PATCH] Added support for both https AND http, config is now untracked by git --- README.md | 28 +++++++++++++++++----------- config.json => config.json.dist | 17 +++++++++++++---- master.js | 13 +++++++------ 3 files changed, 37 insertions(+), 21 deletions(-) rename config.json => config.json.dist (64%) diff --git a/README.md b/README.md index 3c95657a..685fecc8 100644 --- a/README.md +++ b/README.md @@ -70,17 +70,19 @@ NodeJS does not support EOL ubuntu releases. Make sure you are on the most recen Master and all slaves: - sudo curl -sL https://deb.nodesource.com/setup_9.x | sudo -E bash - \ - sudo apt install -y nodejs python-dev git wget curl tar build-essential \ - sudo npm install pm2 -g \ - git clone https://github.com/Danielv123/factorioClusterio.git \ - cd factorioClusterio \ - npm install \ - curl -o factorio.tar.gz -L https://www.factorio.com/get-download/latest/headless/linux64 \ + sudo curl -sL https://deb.nodesource.com/setup_9.x | sudo -E bash - + sudo apt install -y nodejs python-dev git wget curl tar build-essential + sudo npm install pm2 -g + git clone https://github.com/Danielv123/factorioClusterio.git + cd factorioClusterio + curl -o factorio.tar.gz -L https://www.factorio.com/get-download/latest/headless/linux64 tar -xf factorio.tar.gz + npm install downloads and installs nodejs, pm2, git and clusterio. To specify a version, change "latest" in the link to a version number like 0.14.21. +*Copy config.json.dist to config.json* - Otherwise it will crash, as you'd expect. + **Master** pm2 start master.js --name master @@ -141,17 +143,21 @@ reboot when you are done, then proceed to the next steps. *reboots matter* 1. download and run https://puu.sh/toFHl/01eebbb333.bat -2. You do not *need* to follow the given instructions, but you should +2. Copy config.json.dist to config.json -3. type `node master.js` +3. You do not *need* to follow the given instructions, but you should + +4. type `node master.js` **Server Host** 1. download and run https://puu.sh/toFHl/01eebbb333.bat -2. Follow the instructions given +2. Copy config.json.dist to config.json -3. Type `node client.js start [instancename]` to create a new instance. +3. Follow the instructions given + +4. Type `node client.js start [instancename]` to create a new instance. To connect to a master server running on a remote machine, open config.json with your favourite text editor (notepad++). You can also set it up to use the official server browser. diff --git a/config.json b/config.json.dist similarity index 64% rename from config.json rename to config.json.dist index 01aba037..1e26b5ad 100644 --- a/config.json +++ b/config.json.dist @@ -7,18 +7,27 @@ "__comment2": "IP the master web server runs at, can be ignored on the master system", "masterIP": "localhost", + + "__commentMasterPort": "HTTP port for the master to listen to, set to 0 or an empty string to not listen for HTTP requests", "masterPort": 8080, + + "__commentsslPort": "HTTPS port for the master to listen to. Set to 0 or an empty string to not use HTTPS.", + "sslPort": 443, + "sslCert": "database/certificates/cert.crt", + "sslPrivKey": "database/certificates/cert.key", + + "__commentMasterAuthToken": "Authentication token to connect to the master server. Find it in secret-api-token.txt on the master.", "masterAuthToken": "", - "__commentAuthSecret": "This is a long random string generated by keyboard mashing. Please mash you own string for security.", - "masterAuthSecret": "anfeåpvunuennuusnvzunsrevunåzeufnewnufasiojfåqwoiuajknwkjfdabewfkjadfnewåfundjkcvnewmfqewrmn123", + "__commentAuthSecret": "This is a long random string used for generating authentication tokens. Do not share. Regenerates when secret-api-token.txt is deleted.", + "masterAuthSecret": "", - "__comment3": "Your factorio.com username for factorio MP services, also username will be admin", + "__comment3": "Your factorio.com username for factorio MP services, also username will be admin on new instances", "username": "", "__comment4": "Token from your factorio.com profile page. Required for MP and mod manager services.", "token": "", - "factorio_version": "0.16.41", "__comment7": "Used for communication with the mod portal, not needed if you manage mods by hand", + "factorio_version": "0.16.41", "__comment5": "General user settings", "verify_user_identity": false, diff --git a/master.js b/master.js index 24bdfa8e..806ce048 100644 --- a/master.js +++ b/master.js @@ -911,15 +911,16 @@ app.get("/api/getFactorioLocale", function(req,res){ httpRequestDurationMilliseconds.labels(req.route.path).observe(Date.now()-reqStartTime); }); }); -if(config.masterPort == 443){ - var privateKey = fs.readFileSync( 'privatekey.pem' ); - var certificate = fs.readFileSync( 'certificate.pem' ); +if(config.sslPort){ + var certificate = fs.readFileSync( 'database/certificates/cert.crt' ); + var privateKey = fs.readFileSync( 'database/certificates/cert.key' ); - server = https.createServer({ + httpsServer = https.createServer({ key: privateKey, cert: certificate - }, app).listen(443); -} else { + }, app).listen(config.sslPort); +} +if(config.masterPort){ server = require("http").Server(app); server.listen(config.masterPort || 8080, function () { console.log("Listening on port %s...", server.address().port);