From b984c31bf8ef963551b6c4a1613ccb19c8f592b3 Mon Sep 17 00:00:00 2001 From: ECHibiki Date: Sat, 22 Dec 2018 14:43:39 -0500 Subject: [PATCH] Add Anonymous posting --- src/channel/anonymouspost.js | 19 +++++++++++++++++++ src/channel/channel.js | 22 ++++++++++++++++------ src/channel/opts.js | 6 ++++++ src/user.js | 7 +++---- templates/channeloptions.pug | 1 + www/js/util.js | 1 + 6 files changed, 46 insertions(+), 10 deletions(-) create mode 100644 src/channel/anonymouspost.js diff --git a/src/channel/anonymouspost.js b/src/channel/anonymouspost.js new file mode 100644 index 00000000..d53cbd3d --- /dev/null +++ b/src/channel/anonymouspost.js @@ -0,0 +1,19 @@ +var ChannelModule = require("./module"); +var Flags = require("../flags"); + +function AnonymousPost(_channel) { + ChannelModule.apply(this, arguments); +} + +AnonymousPost.prototype = Object.create(ChannelModule.prototype); + +AnonymousPost.prototype.onUserPreJoin = function (user, data, cb) { + const opts = this.channel.modules.options; + var anonymousPosting = opts.get("allow_anon_chat"); + user.guestLogin("Anonymous"); + + cb(null, ChannelModule.PASSTHROUGH); + +}; + +module.exports = AnonymousPost; diff --git a/src/channel/channel.js b/src/channel/channel.js index c1d9c68d..61a2aca6 100644 --- a/src/channel/channel.js +++ b/src/channel/channel.js @@ -159,7 +159,8 @@ Channel.prototype.initModules = function () { "./kickban" : "kickban", "./ranks" : "rank", "./accesscontrol" : "password", - "./anonymouscheck": "anoncheck" + "./anonymouscheck": "anoncheck", + "./anonymouspost" : "anonpost" }; var self = this; @@ -435,13 +436,22 @@ Channel.prototype.acceptUser = function (user) { var self = this; user.waitFlag(Flags.U_LOGGED_IN, function () { - for (var i = 0; i < self.users.length; i++) { - if (self.users[i] !== user && - self.users[i].getLowerName() === user.getLowerName()) { - self.users[i].kick("Duplicate login"); + if(!self.modules.options.get("allow_anon_chat")){ + for (var i = 0; i < self.users.length; i++) { + if (self.users[i] !== user && + self.users[i].getLowerName() === user.getLowerName()) { + self.users[i].kick("Duplicate login"); + } + } + } + else{ + for (var i = 0; i < self.users.length; i++) { + if (self.users[i] !== user && + self.users[i].realip == user.realip) { + self.users[i].kick("Duplicate login"); + } } } - var loginStr = "[login] " + user.displayip + " logged in as " + user.getName(); if (user.account.globalRank === 0) loginStr += " (guest)"; loginStr += " (aliases: " + user.account.aliases.join(",") + ")"; diff --git a/src/channel/opts.js b/src/channel/opts.js index 29a12dc9..4a4c1a6f 100644 --- a/src/channel/opts.js +++ b/src/channel/opts.js @@ -28,6 +28,7 @@ function OptionsModule(_channel) { password: false, // Channel password (false -> no password required for entry) allow_dupes: false, // Allow duplicate videos on the playlist torbanned: false, // Block connections from Tor exit nodes + allow_anon_chat: true, // Disables guest loggin for anonymous posting block_anonymous_users: false, //Only allow connections from registered users. allow_ascii_control: false,// Allow ASCII control characters (\x00-\x1f) playlist_max_per_user: 0, // Maximum number of playlist items per user @@ -334,6 +335,11 @@ OptionsModule.prototype.handleSetOptions = function (user, data) { sendUpdate = true; } + if("allow_anon_chat" in data && user.account.effectiveRank >=3){ + this.opts.allow_anon_chat = Boolean(data.allow_anon_chat); + sendUpdate = true; + } + if("block_anonymous_users" in data && user.account.effectiveRank >=3){ this.opts.block_anonymous_users = Boolean(data.block_anonymous_users); sendUpdate = true; diff --git a/src/user.js b/src/user.js index a8149712..a0c630c7 100644 --- a/src/user.js +++ b/src/user.js @@ -360,7 +360,7 @@ var lastguestlogin = {}; User.prototype.guestLogin = function (name) { var self = this; - if (self.realip in lastguestlogin) { + if (!self.channel.modules.options.get("allow_anon_chat") && self.realip in lastguestlogin) { var diff = (Date.now() - lastguestlogin[self.realip]) / 1000; if (diff < Config.get("guest-login-delay")) { self.socket.emit("login", { @@ -381,7 +381,7 @@ User.prototype.guestLogin = function (name) { return; } - if (name.match(Config.get("reserved-names.usernames"))) { + if (!self.channel.modules.options.get("allow_anon_chat") && name.match(Config.get("reserved-names.usernames"))) { LOGGER.warn( 'Rejecting attempt by %s to use reserved username "%s"', self.realip, @@ -414,7 +414,7 @@ User.prototype.guestLogin = function (name) { return; } - if (self.inChannel()) { + if (!self.channel.modules.options.get("allow_anon_chat") && self.inChannel()) { var nameLower = name.toLowerCase(); for (var i = 0; i < self.channel.users.length; i++) { if (self.channel.users[i].getLowerName() === nameLower) { @@ -426,7 +426,6 @@ User.prototype.guestLogin = function (name) { } } } - // Login succeeded lastguestlogin[self.realip] = Date.now(); diff --git a/templates/channeloptions.pug b/templates/channeloptions.pug index 58983e86..23c78891 100644 --- a/templates/channeloptions.pug +++ b/templates/channeloptions.pug @@ -92,6 +92,7 @@ mixin adminoptions +textbox-auto("cs-externalcss", "External CSS", "Stylesheet URL") +textbox-auto("cs-externaljs", "External Javascript", "Script URL") +rcheckbox-auto("cs-show_public", "List channel publicly") + +rcheckbox-auto("cs-allow_anon_chat", "Allow anonymous chat") +rcheckbox-auto("cs-torbanned", "Block connections from Tor") +rcheckbox-auto("cs-block_anonymous_users", "Block anonymous users") +rcheckbox-auto("cs-allow_ascii_control", "Allow ASCII control characters (e.g. newlines)") diff --git a/www/js/util.js b/www/js/util.js index 6942352a..001c4587 100644 --- a/www/js/util.js +++ b/www/js/util.js @@ -961,6 +961,7 @@ function handleModPermissions() { $("#cs-allow_voteskip").prop("checked", CHANNEL.opts.allow_voteskip); $("#cs-voteskip_ratio").val(CHANNEL.opts.voteskip_ratio); $("#cs-allow_dupes").prop("checked", CHANNEL.opts.allow_dupes); + $("#cs-allow_anon_chat").prop("checked", CHANNEL.opts.allow_anon_chat); $("#cs-torbanned").prop("checked", CHANNEL.opts.torbanned); $("#cs-block_anonymous_users").prop("checked", CHANNEL.opts.block_anonymous_users); $("#cs-allow_ascii_control").prop("checked", CHANNEL.opts.allow_ascii_control); -- 2.11.4.GIT