Commit e1b0a06d authored by nanahira's avatar nanahira

support ssl for all dashboards

parent 820ce5ca
......@@ -8,6 +8,7 @@
TODO:带参数运行时执行对应操作后退出
*/
var http = require('http');
var https = require('https');
var sqlite3 = require('sqlite3').verbose();
var fs = require('fs');
var execSync = require('child_process').execSync;
......@@ -22,7 +23,8 @@ var auth = require('./ygopro-auth.js');
var constants = loadJSON('./data/constants.json');
var settings = loadJSON('./config/config.json');
config=settings.modules.pre_util;
config = settings.modules.pre_util;
ssl_config = settings.modules.http.ssl;
//全卡HTML列表
var cardHTMLs=[];
......@@ -403,7 +405,7 @@ var packDatas = function () {
}
//建立一个http服务器,接收API操作
http.createServer(function (req, res) {
function requestListener(req, res) {
var u = url.parse(req.url, true);
if (!auth.auth(u.query.username, u.query.password, "pre_dashboard", "pre_dashboard")) {
......@@ -463,4 +465,16 @@ http.createServer(function (req, res) {
res.end("400");
}
}).listen(config.port);
}
if (ssl_config.enabled) {
const ssl_cert = fs.readFileSync(ssl_config.cert);
const ssl_key = fs.readFileSync(ssl_config.key);
const options = {
cert: ssl_cert,
key: ssl_key
}
https.createServer(options, requestListener).listen(config.port);
} else {
http.createServer(requestListener).listen(config.port);
}
......@@ -7,6 +7,7 @@
不带参数运行时,会建立一个服务器,调用API执行对应操作
*/
var http = require('http');
var https = require('https');
var fs = require('fs');
var url = require('url');
var request = require('request');
......@@ -19,8 +20,9 @@ var loadJSON = require('load-json-file').sync;
var auth = require('./ygopro-auth.js');
var settings = loadJSON('./config/config.json');
config=settings.modules.tournament_mode;
challonge_config=settings.modules.challonge;
config = settings.modules.tournament_mode;
challonge_config = settings.modules.challonge;
ssl_config = settings.modules.http.ssl;
var challonge;
if (challonge_config.enabled) {
......@@ -214,7 +216,7 @@ var receiveDecks = function(files) {
}
//建立一个http服务器,接收API操作
http.createServer(function (req, res) {
function requestListener(req, res) {
var u = url.parse(req.url, true);
/*if (u.query.password !== config.password) {
......@@ -315,4 +317,16 @@ http.createServer(function (req, res) {
res.end("400");
}
}).listen(config.port);
}
if (ssl_config.enabled) {
const ssl_cert = fs.readFileSync(ssl_config.cert);
const ssl_key = fs.readFileSync(ssl_config.key);
const options = {
cert: ssl_cert,
key: ssl_key
}
https.createServer(options, requestListener).listen(config.port);
} else {
http.createServer(requestListener).listen(config.port);
}
......@@ -8,6 +8,7 @@
TODO:带参数运行时执行对应操作后退出
*/
var http = require('http');
var https = require('https');
var sqlite3 = require('sqlite3').verbose();
var fs = require('fs');
var execSync = require('child_process').execSync;
......@@ -23,7 +24,8 @@ var auth = require('./ygopro-auth.js');
var constants = loadJSON('./data/constants.json');
var settings = loadJSON('./config/config.json');
config=settings.modules.update_util;
config = settings.modules.update_util;
ssl_config = settings.modules.http.ssl;
//全卡名称列表
var cardNames={};
......@@ -208,7 +210,7 @@ var pushHTMLs = function() {
//建立一个http服务器,接收API操作
http.createServer(function (req, res) {
function requestListener(req, res) {
var u = url.parse(req.url, true);
if (!auth.auth(u.query.username, u.query.password, "update_dashboard", "update_dashboard")) {
......@@ -271,4 +273,16 @@ http.createServer(function (req, res) {
res.end("400");
}
}).listen(config.port);
}
if (ssl_config.enabled) {
const ssl_cert = fs.readFileSync(ssl_config.cert);
const ssl_key = fs.readFileSync(ssl_config.key);
const options = {
cert: ssl_cert,
key: ssl_key
}
https.createServer(options, requestListener).listen(config.port);
} else {
http.createServer(requestListener).listen(config.port);
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment