Add Admin Setting - Block anonymous connections (#740)

This commit is contained in:
Adam davis 2018-04-07 14:24:52 -04:00 committed by Calvin Montgomery
parent ef7bf1a319
commit 953428cad5
6 changed files with 54 additions and 2 deletions

View file

@ -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;

View file

@ -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);
}

View file

@ -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;

View file

@ -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) {

View file

@ -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

View file

@ -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));