diff --git a/package.json b/package.json index 4340c232..8f978036 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "author": "Calvin Montgomery", "name": "CyTube", "description": "Online media synchronizer and chat", - "version": "3.50.1", + "version": "3.51.0", "repository": { "url": "http://github.com/calzoneman/sync" }, diff --git a/src/config.js b/src/config.js index 6f088c91..38405d96 100644 --- a/src/config.js +++ b/src/config.js @@ -330,20 +330,6 @@ function preprocessConfig(cfg) { cfg.io["ipv4-default"] = cfg.io["ipv4-ssl"] || cfg.io["ipv4-nossl"]; cfg.io["ipv6-default"] = cfg.io["ipv6-ssl"] || cfg.io["ipv6-nossl"]; - // sioconfig - // TODO this whole thing is messy, need to redo how the socket address is sent - var sioconfigjson = { - "ipv4-nossl": cfg.io["ipv4-nossl"], - "ipv4-ssl": cfg.io["ipv4-ssl"], - "ipv6-nossl": cfg.io["ipv6-nossl"], - "ipv6-ssl": cfg.io["ipv6-ssl"] - }; - - var sioconfig = JSON.stringify(sioconfigjson); - sioconfig = "var IO_URLS=" + sioconfig + ";"; - cfg.sioconfigjson = sioconfigjson; - cfg.sioconfig = sioconfig; - // Generate RegExps for reserved names var reserved = cfg["reserved-names"]; for (var key in reserved) { diff --git a/src/web/acp.js b/src/web/acp.js index ac47ea51..926c12eb 100644 --- a/src/web/acp.js +++ b/src/web/acp.js @@ -6,6 +6,8 @@ var Logger = require("../logger"); var db = require("../database"); var Config = require("../config"); +let ioConfig; + function checkAdmin(cb) { return async function (req, res) { const user = await webserver.authorize(req); @@ -28,16 +30,17 @@ function checkAdmin(cb) { * Handles a request for the ACP */ function handleAcp(req, res, user) { - var sio; - if (req.secure || req.header("x-forwarded-proto") === "https") { - sio = Config.get("https.domain") + ":" + Config.get("https.default-port"); - } else { - sio = Config.get("io.domain") + ":" + Config.get("io.default-port"); + const ioServers = ioConfig.getSocketEndpoints(); + const chosenServer = ioServers[0]; + + if (!chosenServer) { + res.status(500).text("No suitable socket.io address for ACP"); + return; } - sio += "/socket.io/socket.io.js"; sendPug(res, "acp", { - sioSource: sio + ioServers: JSON.stringify(ioServers), + sioSource: `${chosenServer.url}/socket.io/socket.io.js` }); } @@ -104,7 +107,9 @@ function handleReadChanlog(req, res) { } module.exports = { - init: function (app) { + init: function (app, _ioConfig) { + ioConfig = _ioConfig; + app.get("/acp", checkAdmin(handleAcp)); app.get("/acp/syslog", checkAdmin(handleReadSyslog)); app.get("/acp/errlog", checkAdmin(handleReadErrlog)); diff --git a/src/web/webserver.js b/src/web/webserver.js index 0c14ddbb..3f761463 100644 --- a/src/web/webserver.js +++ b/src/web/webserver.js @@ -64,37 +64,6 @@ function initPrometheus(app) { }, 5 * 60 * 1000).unref(); } -/** - * Legacy socket.io configuration endpoint. This is being migrated to - * /socketconfig/.json (see ./routes/socketconfig.js) - */ -function handleLegacySocketConfig(req, res) { - if (/\.json$/.test(req.path)) { - res.json(Config.get('sioconfigjson')); - return; - } - - res.type('application/javascript'); - - var sioconfig = Config.get('sioconfig'); - var iourl; - var ip = req.realIP; - var ipv6 = false; - - if (net.isIPv6(ip)) { - iourl = Config.get('io.ipv6-default'); - ipv6 = true; - } - - if (!iourl) { - iourl = Config.get('io.ipv4-default'); - } - - sioconfig += 'var IO_URL=\'' + iourl + '\';'; - sioconfig += 'var IO_V6=' + ipv6 + ';'; - res.send(sioconfig); -} - function initializeErrorHandlers(app) { app.use((req, res, next) => { return next(new HTTPError(`No route for ${req.path}`, { @@ -232,12 +201,11 @@ module.exports = { require('./routes/channel')(app, ioConfig, chanPath); require('./routes/index')(app, channelIndex, webConfig.getMaxIndexEntries()); - app.get('/sioconfig(.json)?', handleLegacySocketConfig); require('./routes/socketconfig')(app, clusterClient); require('./routes/contact')(app, webConfig); require('./auth').init(app); require('./account').init(app, globalMessageBus, emailConfig, emailController); - require('./acp').init(app); + require('./acp').init(app, ioConfig); require('../google2vtt').attach(app); require('./routes/google_drive_userscript')(app); require('./routes/ustream_bypass')(app); diff --git a/templates/acp.pug b/templates/acp.pug index c2993f0d..70ad48e4 100644 --- a/templates/acp.pug +++ b/templates/acp.pug @@ -118,18 +118,12 @@ html(lang="en") select#acp-eventlog-filter.form-control(multiple="multiple", style="max-width: 25%") button#acp-eventlog-refresh.btn.btn-default Refresh pre#acp-eventlog-text - #acp-stats.acp-panel.col-md-12(style="display: none") - h3 User Count - canvas#stat_users(width="1140", height="400") - h3 Channel Count - canvas#stat_channels(width="1140", height="400") - h3 Memory Usage - canvas#stat_mem(width="1140", height="400") include footer +footer() script(src=sioSource) - script(src="/sioconfig") + script(type="text/javascript"). + window.IO_SERVERS = !{ioServers}; script(src="/js/util.js") script(src="/js/paginator.js") script(src="/js/acp.js") diff --git a/www/js/acp.js b/www/js/acp.js index 09c8d5e4..c46451d5 100644 --- a/www/js/acp.js +++ b/www/js/acp.js @@ -1,9 +1,12 @@ (function () { - var opts = {}; - if (location.protocol === "https:") { - opts.secure = true; - } - window.socket = io.connect(IO_URL, opts); + var chosenServer = IO_SERVERS[0]; // Is the array even necessary for the ACP? + + var opts = { + secure: chosenServer.secure + }; + + window.socket = io.connect(chosenServer.url, opts); + window.socket.on("connect", function () { window.socket.emit("initACP"); window.socket.emit("acp-list-activechannels");