Remove /sioconfig for real

This commit is contained in:
Calvin Montgomery 2017-09-30 15:26:47 -07:00
parent a2be65aead
commit 3cd8bfa8c7
6 changed files with 25 additions and 69 deletions

View file

@ -2,7 +2,7 @@
"author": "Calvin Montgomery", "author": "Calvin Montgomery",
"name": "CyTube", "name": "CyTube",
"description": "Online media synchronizer and chat", "description": "Online media synchronizer and chat",
"version": "3.50.1", "version": "3.51.0",
"repository": { "repository": {
"url": "http://github.com/calzoneman/sync" "url": "http://github.com/calzoneman/sync"
}, },

View file

@ -330,20 +330,6 @@ function preprocessConfig(cfg) {
cfg.io["ipv4-default"] = cfg.io["ipv4-ssl"] || cfg.io["ipv4-nossl"]; cfg.io["ipv4-default"] = cfg.io["ipv4-ssl"] || cfg.io["ipv4-nossl"];
cfg.io["ipv6-default"] = cfg.io["ipv6-ssl"] || cfg.io["ipv6-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 // Generate RegExps for reserved names
var reserved = cfg["reserved-names"]; var reserved = cfg["reserved-names"];
for (var key in reserved) { for (var key in reserved) {

View file

@ -6,6 +6,8 @@ var Logger = require("../logger");
var db = require("../database"); var db = require("../database");
var Config = require("../config"); var Config = require("../config");
let ioConfig;
function checkAdmin(cb) { function checkAdmin(cb) {
return async function (req, res) { return async function (req, res) {
const user = await webserver.authorize(req); const user = await webserver.authorize(req);
@ -28,16 +30,17 @@ function checkAdmin(cb) {
* Handles a request for the ACP * Handles a request for the ACP
*/ */
function handleAcp(req, res, user) { function handleAcp(req, res, user) {
var sio; const ioServers = ioConfig.getSocketEndpoints();
if (req.secure || req.header("x-forwarded-proto") === "https") { const chosenServer = ioServers[0];
sio = Config.get("https.domain") + ":" + Config.get("https.default-port");
} else { if (!chosenServer) {
sio = Config.get("io.domain") + ":" + Config.get("io.default-port"); res.status(500).text("No suitable socket.io address for ACP");
return;
} }
sio += "/socket.io/socket.io.js";
sendPug(res, "acp", { 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 = { module.exports = {
init: function (app) { init: function (app, _ioConfig) {
ioConfig = _ioConfig;
app.get("/acp", checkAdmin(handleAcp)); app.get("/acp", checkAdmin(handleAcp));
app.get("/acp/syslog", checkAdmin(handleReadSyslog)); app.get("/acp/syslog", checkAdmin(handleReadSyslog));
app.get("/acp/errlog", checkAdmin(handleReadErrlog)); app.get("/acp/errlog", checkAdmin(handleReadErrlog));

View file

@ -64,37 +64,6 @@ function initPrometheus(app) {
}, 5 * 60 * 1000).unref(); }, 5 * 60 * 1000).unref();
} }
/**
* Legacy socket.io configuration endpoint. This is being migrated to
* /socketconfig/<channel name>.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) { function initializeErrorHandlers(app) {
app.use((req, res, next) => { app.use((req, res, next) => {
return next(new HTTPError(`No route for ${req.path}`, { return next(new HTTPError(`No route for ${req.path}`, {
@ -232,12 +201,11 @@ module.exports = {
require('./routes/channel')(app, ioConfig, chanPath); require('./routes/channel')(app, ioConfig, chanPath);
require('./routes/index')(app, channelIndex, webConfig.getMaxIndexEntries()); require('./routes/index')(app, channelIndex, webConfig.getMaxIndexEntries());
app.get('/sioconfig(.json)?', handleLegacySocketConfig);
require('./routes/socketconfig')(app, clusterClient); require('./routes/socketconfig')(app, clusterClient);
require('./routes/contact')(app, webConfig); require('./routes/contact')(app, webConfig);
require('./auth').init(app); require('./auth').init(app);
require('./account').init(app, globalMessageBus, emailConfig, emailController); require('./account').init(app, globalMessageBus, emailConfig, emailController);
require('./acp').init(app); require('./acp').init(app, ioConfig);
require('../google2vtt').attach(app); require('../google2vtt').attach(app);
require('./routes/google_drive_userscript')(app); require('./routes/google_drive_userscript')(app);
require('./routes/ustream_bypass')(app); require('./routes/ustream_bypass')(app);

View file

@ -118,18 +118,12 @@ html(lang="en")
select#acp-eventlog-filter.form-control(multiple="multiple", style="max-width: 25%") select#acp-eventlog-filter.form-control(multiple="multiple", style="max-width: 25%")
button#acp-eventlog-refresh.btn.btn-default Refresh button#acp-eventlog-refresh.btn.btn-default Refresh
pre#acp-eventlog-text 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 include footer
+footer() +footer()
script(src=sioSource) script(src=sioSource)
script(src="/sioconfig") script(type="text/javascript").
window.IO_SERVERS = !{ioServers};
script(src="/js/util.js") script(src="/js/util.js")
script(src="/js/paginator.js") script(src="/js/paginator.js")
script(src="/js/acp.js") script(src="/js/acp.js")

View file

@ -1,9 +1,12 @@
(function () { (function () {
var opts = {}; var chosenServer = IO_SERVERS[0]; // Is the array even necessary for the ACP?
if (location.protocol === "https:") {
opts.secure = true; var opts = {
} secure: chosenServer.secure
window.socket = io.connect(IO_URL, opts); };
window.socket = io.connect(chosenServer.url, opts);
window.socket.on("connect", function () { window.socket.on("connect", function () {
window.socket.emit("initACP"); window.socket.emit("initACP");
window.socket.emit("acp-list-activechannels"); window.socket.emit("acp-list-activechannels");