This commit is contained in:
Calvin Montgomery 2018-10-21 22:12:49 -07:00
parent 0bc866dbfa
commit 5b86fb3187
4 changed files with 89 additions and 41 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.58.3", "version": "3.58.4",
"repository": { "repository": {
"url": "http://github.com/calzoneman/sync" "url": "http://github.com/calzoneman/sync"
}, },

View File

@ -1,5 +1,6 @@
var ChannelModule = require("./module"); const ChannelModule = require("./module");
var XSS = require("../xss"); const XSS = require("../xss");
const { hash } = require('../util/hash');
const TYPE_SETCSS = { const TYPE_SETCSS = {
css: "string" css: "string"
@ -23,6 +24,28 @@ function CustomizationModule(_channel) {
CustomizationModule.prototype = Object.create(ChannelModule.prototype); CustomizationModule.prototype = Object.create(ChannelModule.prototype);
Object.defineProperty(CustomizationModule.prototype, 'css', {
get() {
return this._css;
},
set(val) {
this._css = val;
this.cssHash = hash('md5', val, 'base64');
}
});
Object.defineProperty(CustomizationModule.prototype, 'js', {
get() {
return this._js;
},
set(val) {
this._js = val;
this.jsHash = hash('md5', val, 'base64');
}
});
CustomizationModule.prototype.load = function (data) { CustomizationModule.prototype.load = function (data) {
if ("css" in data) { if ("css" in data) {
this.css = data.css; this.css = data.css;
@ -69,7 +92,9 @@ CustomizationModule.prototype.onUserPostJoin = function (user) {
CustomizationModule.prototype.sendCSSJS = function (users) { CustomizationModule.prototype.sendCSSJS = function (users) {
var data = { var data = {
css: this.css, css: this.css,
js: this.js cssHash: this.cssHash,
js: this.js,
jsHash: this.jsHash
}; };
users.forEach(function (u) { users.forEach(function (u) {
u.socket.emit("channelCSSJS", data); u.socket.emit("channelCSSJS", data);
@ -89,11 +114,15 @@ CustomizationModule.prototype.handleSetCSS = function (user, data) {
return; return;
} }
this.dirty = true; let oldHash = this.cssHash;
// TODO: consider sending back an error instead of silently truncating
this.css = data.css.substring(0, 20000); this.css = data.css.substring(0, 20000);
this.sendCSSJS(this.channel.users);
this.channel.logger.log("[mod] " + user.getName() + " updated the channel CSS"); if (oldHash !== this.cssHash) {
this.dirty = true;
this.sendCSSJS(this.channel.users);
this.channel.logger.log("[mod] " + user.getName() + " updated the channel CSS");
}
}; };
CustomizationModule.prototype.handleSetJS = function (user, data) { CustomizationModule.prototype.handleSetJS = function (user, data) {
@ -102,11 +131,14 @@ CustomizationModule.prototype.handleSetJS = function (user, data) {
return; return;
} }
this.dirty = true; let oldHash = this.jsHash;
this.js = data.js.substring(0, 20000); this.js = data.js.substring(0, 20000);
this.sendCSSJS(this.channel.users);
this.channel.logger.log("[mod] " + user.getName() + " updated the channel JS"); if (oldHash !== this.jsHash) {
this.dirty = true;
this.sendCSSJS(this.channel.users);
this.channel.logger.log("[mod] " + user.getName() + " updated the channel JS");
}
}; };
CustomizationModule.prototype.handleSetMotd = function (user, data) { CustomizationModule.prototype.handleSetMotd = function (user, data) {

View File

@ -296,42 +296,54 @@ Callbacks = {
}, },
channelCSSJS: function(data) { channelCSSJS: function(data) {
$("#chancss").remove(); if (CyTube.channelCustomizations.cssHash !== data.cssHash) {
CHANNEL.css = data.css; $("#chancss").remove();
$("#cs-csstext").val(data.css); CHANNEL.css = data.css;
if(data.css && !USEROPTS.ignore_channelcss) { $("#cs-csstext").val(data.css);
$("<style/>").attr("type", "text/css") if(data.css && !USEROPTS.ignore_channelcss) {
.attr("id", "chancss") $("<style/>").attr("type", "text/css")
.text(data.css) .attr("id", "chancss")
.appendTo($("head")); .text(data.css)
.appendTo($("head"));
}
if (data.cssHash) {
CyTube.channelCustomizations.cssHash = data.cssHash;
}
} }
$("#chanjs").remove(); if (CyTube.channelCustomizations.jsHash !== data.jsHash) {
CHANNEL.js = data.js; $("#chanjs").remove();
$("#cs-jstext").val(data.js); CHANNEL.js = data.js;
$("#cs-jstext").val(data.js);
if(data.js && !USEROPTS.ignore_channeljs) { if(data.js && !USEROPTS.ignore_channeljs) {
var viewSource = document.createElement("button"); var viewSource = document.createElement("button");
viewSource.className = "btn btn-danger"; viewSource.className = "btn btn-danger";
viewSource.textContent = "View inline script source"; viewSource.textContent = "View inline script source";
viewSource.onclick = function () { viewSource.onclick = function () {
var content = document.createElement("pre"); var content = document.createElement("pre");
content.textContent = data.js; content.textContent = data.js;
modalAlert({ modalAlert({
title: "Inline JS", title: "Inline JS",
htmlContent: content.outerHTML, htmlContent: content.outerHTML,
dismissText: "Close" dismissText: "Close"
});
};
checkScriptAccess(viewSource, "embedded", function (pref) {
if (pref === "ALLOW") {
$("<script/>").attr("type", "text/javascript")
.attr("id", "chanjs")
.text(data.js)
.appendTo($("body"));
}
}); });
}; }
checkScriptAccess(viewSource, "embedded", function (pref) { if (data.jsHash) {
if (pref === "ALLOW") { CyTube.channelCustomizations.jsHash = data.jsHash;
$("<script/>").attr("type", "text/javascript") }
.attr("id", "chanjs")
.text(data.js)
.appendTo($("body"));
}
});
} }
}, },

View File

@ -76,6 +76,10 @@ CyTube.ui = {
CyTube.featureFlag = { CyTube.featureFlag = {
efficientEmotes: true efficientEmotes: true
}; };
CyTube.channelCustomizations = {
cssHash: null,
jsHash: null
};
CyTube._internal_do_not_use_or_you_will_be_banned = {}; CyTube._internal_do_not_use_or_you_will_be_banned = {};
function getOpt(k) { function getOpt(k) {