From 953428cad50c3bbf14b70e8485628fc88e608444 Mon Sep 17 00:00:00 2001 From: Adam davis <33336994+OneEighteenNoTwo@users.noreply.github.com> Date: Sat, 7 Apr 2018 14:24:52 -0400 Subject: [PATCH] Add Admin Setting - Block anonymous connections (#740) --- src/channel/anonymouscheck.js | 37 +++++++++++++++++++++++++++++++++++ src/channel/channel.js | 6 ++++-- src/channel/opts.js | 6 ++++++ src/user.js | 5 +++++ templates/channeloptions.pug | 1 + www/js/util.js | 1 + 6 files changed, 54 insertions(+), 2 deletions(-) create mode 100644 src/channel/anonymouscheck.js diff --git a/src/channel/anonymouscheck.js b/src/channel/anonymouscheck.js new file mode 100644 index 00000000..0eb008e2 --- /dev/null +++ b/src/channel/anonymouscheck.js @@ -0,0 +1,37 @@ +var ChannelModule = require("./module"); +var Flags = require("../flags"); + +function AnonymousCheck(channel) { + ChannelModule.apply(this, arguments); +} + +AnonymousCheck.prototype = Object.create(ChannelModule.prototype); + +AnonymousCheck.prototype.onUserPreJoin = function (user, data, cb) { + var chan = this.channel, + opts = this.channel.modules.options; + var anonymousBanned = opts.get("block_anonymous_users"); + + if (user.socket.disconnected) { + return cb("User disconnected", ChannelModule.DENY); + } + + if(anonymousBanned && user.isAnonymous()) { + user.socket.on("disconnect", function () { + if (!user.is(Flags.U_IN_CHANNEL)) { + cb("User disconnected", ChannelModule.DENY); + } + }); + + user.socket.emit("errorMsg", { msg : "This channel has blocked anonymous users. Please provide a user name to join."}); + user.waitFlag(Flags.U_LOGGED_IN, function () { + cb(null, ChannelModule.PASSTHROUGH); + }); + return; + } + else{ + cb(null, ChannelModule.PASSTHROUGH); + } +}; + +module.exports = AnonymousCheck; \ No newline at end of file diff --git a/src/channel/channel.js b/src/channel/channel.js index c8e8b999..78dbafc6 100644 --- a/src/channel/channel.js +++ b/src/channel/channel.js @@ -156,7 +156,8 @@ Channel.prototype.initModules = function () { "./poll" : "poll", "./kickban" : "kickban", "./ranks" : "rank", - "./accesscontrol" : "password" + "./accesscontrol" : "password", + "./anonymouscheck": "anoncheck" }; var self = this; @@ -418,7 +419,8 @@ Channel.prototype.acceptUser = function (user) { this.logger.log("[login] Accepted connection from Tor exit at " + user.displayip); - } else { + } + else { this.logger.log("[login] Accepted connection from " + user.displayip); } diff --git a/src/channel/opts.js b/src/channel/opts.js index 2ca4e570..79c57387 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 + 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 new_user_chat_delay: 0, // Minimum account/IP age to chat @@ -328,6 +329,11 @@ OptionsModule.prototype.handleSetOptions = function (user, data) { sendUpdate = true; } + if("block_anonymous_users" in data && user.account.effectiveRank >=3){ + this.opts.block_anonymous_users = Boolean(data.block_anonymous_users); + sendUpdate = true; + } + if ("allow_ascii_control" in data && user.account.effectiveRank >= 3) { this.opts.allow_ascii_control = Boolean(data.allow_ascii_control); sendUpdate = true; diff --git a/src/user.js b/src/user.js index ee504c69..842ad522 100644 --- a/src/user.js +++ b/src/user.js @@ -286,6 +286,11 @@ User.prototype.kick = function (reason) { this.socket.disconnect(); }; +User.prototype.isAnonymous = function(){ + var self = this; + return !self.is(Flags.U_LOGGED_IN); +}; + User.prototype.initAdminCallbacks = function () { var self = this; self.socket.on("borrow-rank", function (rank) { diff --git a/templates/channeloptions.pug b/templates/channeloptions.pug index 047f442d..58983e86 100644 --- a/templates/channeloptions.pug +++ b/templates/channeloptions.pug @@ -93,6 +93,7 @@ mixin adminoptions +textbox-auto("cs-externaljs", "External Javascript", "Script URL") +rcheckbox-auto("cs-show_public", "List channel publicly") +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)") +textbox-auto("cs-playlist_max_per_user", "Maximum # of videos per user") .form-group diff --git a/www/js/util.js b/www/js/util.js index af06b36c..69ee07e1 100644 --- a/www/js/util.js +++ b/www/js/util.js @@ -941,6 +941,7 @@ function handleModPermissions() { $("#cs-voteskip_ratio").val(CHANNEL.opts.voteskip_ratio); $("#cs-allow_dupes").prop("checked", CHANNEL.opts.allow_dupes); $("#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); $("#cs-playlist_max_per_user").val(CHANNEL.opts.playlist_max_per_user || 0); $("#cs-playlist_max_duration_per_user").val(formatTime(CHANNEL.opts.playlist_max_duration_per_user));