major refactoring

This commit is contained in:
calzoneman 2013-10-11 16:31:40 -05:00
parent 542461a533
commit f2c996ebfa
9 changed files with 815 additions and 810 deletions

View File

@ -11,6 +11,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
var Server = require("./lib/server"); var Server = require("./lib/server");
var Config = require("./lib/config"); var Config = require("./lib/config");
var Logger = require("./lib/logger");
Config.load("cfg.json", function (cfg) { Config.load("cfg.json", function (cfg) {
var sv = Server.init(cfg); var sv = Server.init(cfg);

View File

@ -10,170 +10,170 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
*/ */
var Logger = require("./logger"); var Logger = require("./logger");
var Server = require("./server");
var ActionLog = require("./actionlog");
module.exports = function (Server) { module.exports = {
var db = Server.db; init: function (user) {
var ActionLog = Server.actionlog; var sv = Server.getServer();
return { var db = sv.db;
init: function(user) { ActionLog.record(user.ip, user.name, "acp-init");
ActionLog.record(user.ip, user.name, "acp-init"); user.socket.on("acp-announce", function(data) {
user.socket.on("acp-announce", function(data) { ActionLog.record(user.ip, user.name, "acp-announce", data);
ActionLog.record(user.ip, user.name, "acp-announce", data); sv.announcement = data;
Server.announcement = data; sv.io.sockets.emit("announcement", data);
Server.io.sockets.emit("announcement", data); if (sv.cfg["enable-ssl"])
if (Server.cfg["enable-ssl"]) sv.ioSecure.sockets.emit("announcement", data);
Server.sslio.sockets.emit("announcement", data); });
});
user.socket.on("acp-announce-clear", function() { user.socket.on("acp-announce-clear", function() {
ActionLog.record(user.ip, user.name, "acp-announce-clear"); ActionLog.record(user.ip, user.name, "acp-announce-clear");
Server.announcement = null; sv.announcement = null;
}); });
user.socket.on("acp-global-ban", function(data) { user.socket.on("acp-global-ban", function(data) {
ActionLog.record(user.ip, user.name, "acp-global-ban", data.ip); ActionLog.record(user.ip, user.name, "acp-global-ban", data.ip);
db.setGlobalIPBan(data.ip, data.note, function (err, res) { db.setGlobalIPBan(data.ip, data.note, function (err, res) {
db.listGlobalIPBans(function (err, res) { db.listGlobalIPBans(function (err, res) {
res = res || []; res = res || [];
user.socket.emit("acp-global-banlist", res); user.socket.emit("acp-global-banlist", res);
});
}); });
}); });
});
user.socket.on("acp-global-unban", function(ip) { user.socket.on("acp-global-unban", function(ip) {
ActionLog.record(user.ip, user.name, "acp-global-unban", ip); ActionLog.record(user.ip, user.name, "acp-global-unban", ip);
db.clearGlobalIPBan(ip, function (err, res) { db.clearGlobalIPBan(ip, function (err, res) {
db.listGlobalIPBans(function (err, res) { db.listGlobalIPBans(function (err, res) {
res = res || []; res = res || [];
user.socket.emit("acp-global-banlist", res); user.socket.emit("acp-global-banlist", res);
});
}); });
}); });
});
db.listGlobalIPBans(function (err, res) { db.listGlobalIPBans(function (err, res) {
res = res || [];
user.socket.emit("acp-global-banlist", res);
});
user.socket.on("acp-lookup-user", function(name) {
db.searchUser(name, function (err, res) {
res = res || []; res = res || [];
user.socket.emit("acp-global-banlist", res); user.socket.emit("acp-userdata", res);
}); });
});
user.socket.on("acp-lookup-user", function(name) { user.socket.on("acp-lookup-channel", function (data) {
db.searchUser(name, function (err, res) { db.searchChannel(data.field, data.value, function (e, res) {
res = res || []; res = res || [];
user.socket.emit("acp-userdata", res); user.socket.emit("acp-channeldata", res);
});
}); });
});
user.socket.on("acp-lookup-channel", function (data) { user.socket.on("acp-reset-password", function(data) {
db.searchChannel(data.field, data.value, function (e, res) { db.getGlobalRank(data.name, function (err, rank) {
res = res || []; if(err || rank >= user.global_rank)
user.socket.emit("acp-channeldata", res);
});
});
user.socket.on("acp-reset-password", function(data) {
db.getGlobalRank(data.name, function (err, rank) {
if(err || rank >= user.global_rank)
return;
db.genPasswordReset(user.ip, data.name, data.email,
function (err, hash) {
var pkt = {
success: !err
};
if(err) {
pkt.error = err;
} else {
pkt.hash = hash;
}
user.socket.emit("acp-reset-password", pkt);
ActionLog.record(user.ip, user.name,
"acp-reset-password", data.name);
});
});
});
user.socket.on("acp-set-rank", function(data) {
if(data.rank < 1 || data.rank >= user.global_rank)
return; return;
db.getGlobalRank(data.name, function (err, rank) { db.genPasswordReset(user.ip, data.name, data.email,
if(err || rank >= user.global_rank) function (err, hash) {
return; var pkt = {
success: !err
};
db.setGlobalRank(data.name, data.rank, if(err) {
function (err, res) { pkt.error = err;
ActionLog.record(user.ip, user.name, "acp-set-rank", } else {
data); pkt.hash = hash;
if(!err) }
user.socket.emit("acp-set-rank", data);
}); user.socket.emit("acp-reset-password", pkt);
ActionLog.record(user.ip, user.name,
"acp-reset-password", data.name);
}); });
}); });
});
user.socket.on("acp-list-loaded", function() { user.socket.on("acp-set-rank", function(data) {
var chans = []; if(data.rank < 1 || data.rank >= user.global_rank)
var all = Server.channels; return;
for(var c in all) {
var chan = all[c];
chans.push({ db.getGlobalRank(data.name, function (err, rank) {
name: chan.name, if(err || rank >= user.global_rank)
title: chan.opts.pagetitle, return;
usercount: chan.users.length,
mediatitle: chan.playlist.current ? chan.playlist.current.media.title : "-",
is_public: chan.opts.show_public,
registered: chan.registered
});
}
user.socket.emit("acp-list-loaded", chans); db.setGlobalRank(data.name, data.rank,
}); function (err, res) {
ActionLog.record(user.ip, user.name, "acp-set-rank",
user.socket.on("acp-channel-unload", function(data) { data);
if(Server.isChannelLoaded(data.name)) {
var c = Server.getChannel(data.name);
if(!c)
return;
ActionLog.record(user.ip, user.name, "acp-channel-unload");
c.initialized = data.save;
// copy the list of users to prevent concurrent
// modification
var users = Array.prototype.slice.call(c.users);
users.forEach(function (u) {
c.kick(u, "Channel shutting down");
});
// At this point c should be unloaded
// if it's still loaded, kill it
if(Server.isChannelLoaded(data.name))
Server.unloadChannel(Server.getChannel(data.name));
}
});
user.socket.on("acp-actionlog-list", function () {
ActionLog.listActionTypes(function (err, types) {
if(!err) if(!err)
user.socket.emit("acp-actionlog-list", types); user.socket.emit("acp-set-rank", data);
}); });
}); });
});
user.socket.on("acp-actionlog-clear", function(data) { user.socket.on("acp-list-loaded", function() {
ActionLog.clear(data); var chans = [];
ActionLog.record(user.ip, user.name, "acp-actionlog-clear", data); var all = sv.channels;
}); for(var c in all) {
var chan = all[c];
user.socket.on("acp-actionlog-clear-one", function(data) { chans.push({
ActionLog.clearOne(data); name: chan.name,
ActionLog.record(user.ip, user.name, "acp-actionlog-clear-one", data); title: chan.opts.pagetitle,
}); usercount: chan.users.length,
mediatitle: chan.playlist.current ? chan.playlist.current.media.title : "-",
user.socket.on("acp-view-stats", function () { is_public: chan.opts.show_public,
db.listStats(function (err, res) { registered: chan.registered
if(!err)
user.socket.emit("acp-view-stats", res);
}); });
}
user.socket.emit("acp-list-loaded", chans);
});
user.socket.on("acp-channel-unload", function(data) {
if(sv.isChannelLoaded(data.name)) {
var c = sv.getChannel(data.name);
if(!c)
return;
ActionLog.record(user.ip, user.name, "acp-channel-unload");
c.initialized = data.save;
// copy the list of users to prevent concurrent
// modification
var users = Array.prototype.slice.call(c.users);
users.forEach(function (u) {
c.kick(u, "Channel shutting down");
});
// At this point c should be unloaded
// if it's still loaded, kill it
if(sv.isChannelLoaded(data.name))
sv.unloadChannel(sv.getChannel(data.name));
}
});
user.socket.on("acp-actionlog-list", function () {
ActionLog.listActionTypes(function (err, types) {
if(!err)
user.socket.emit("acp-actionlog-list", types);
}); });
} });
user.socket.on("acp-actionlog-clear", function(data) {
ActionLog.clear(data);
ActionLog.record(user.ip, user.name, "acp-actionlog-clear", data);
});
user.socket.on("acp-actionlog-clear-one", function(data) {
ActionLog.clearOne(data);
ActionLog.record(user.ip, user.name, "acp-actionlog-clear-one", data);
});
user.socket.on("acp-view-stats", function () {
db.listStats(function (err, res) {
if(!err)
user.socket.emit("acp-view-stats", res);
});
});
} }
} }

View File

@ -10,49 +10,53 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
*/ */
var Logger = require("./logger"); var Logger = require("./logger");
var Server = require("./server");
module.exports = function (Server) { module.exports = {
var db = Server.db; record: function (ip, name, action, args) {
return { var db = Server.getServer().db;
record: function (ip, name, action, args) { if(!args)
if(!args) args = "";
else {
try {
args = JSON.stringify(args);
} catch(e) {
args = ""; args = "";
else {
try {
args = JSON.stringify(args);
} catch(e) {
args = "";
}
} }
db.recordAction(ip, name, action, args);
},
clear: function (actions) {
db.clearActions(actions);
},
clearOne: function (item) {
db.clearSingleAction(item);
},
throttleRegistrations: function (ip, callback) {
db.recentRegistrationCount(ip, function (err, count) {
if(err) {
callback(err, null);
return;
}
callback(null, count > 4);
});
},
listActionTypes: function (callback) {
db.listActionTypes(callback);
},
listActions: function (types, callback) {
db.listActions(types, callback);
} }
};
db.recordAction(ip, name, action, args);
},
clear: function (actions) {
var db = Server.getServer().db;
db.clearActions(actions);
},
clearOne: function (item) {
var db = Server.getServer().db;
db.clearSingleAction(item);
},
throttleRegistrations: function (ip, callback) {
var db = Server.getServer().db;
db.recentRegistrationCount(ip, function (err, count) {
if(err) {
callback(err, null);
return;
}
callback(null, count > 4);
});
},
listActionTypes: function (callback) {
var db = Server.getServer().db;
db.listActionTypes(callback);
},
listActions: function (types, callback) {
var db = Server.getServer().db;
db.listActions(types, callback);
}
}; };

View File

@ -13,9 +13,9 @@ var Logger = require("./logger");
var fs = require("fs"); var fs = require("fs");
var path = require("path"); var path = require("path");
var $util = require("./utilities"); var $util = require("./utilities");
var ActionLog = require("./actionlog");
module.exports = function (Server) { module.exports = function (Server) {
var ActionLog = Server.actionlog;
function getIP(req) { function getIP(req) {
var raw = req.connection.remoteAddress; var raw = req.connection.remoteAddress;
var forward = req.header("x-forwarded-for"); var forward = req.header("x-forwarded-for");

View File

@ -12,24 +12,25 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
var fs = require("fs"); var fs = require("fs");
var path = require("path"); var path = require("path");
var url = require("url");
var Poll = require("./poll.js").Poll; var Poll = require("./poll.js").Poll;
var Media = require("./media.js").Media; var Media = require("./media.js").Media;
var Logger = require("./logger.js"); var Logger = require("./logger.js");
var Rank = require("./rank.js");
var ChatCommand = require("./chatcommand.js"); var ChatCommand = require("./chatcommand.js");
var Filter = require("./filter.js").Filter; var Filter = require("./filter.js").Filter;
var Playlist = require("./playlist"); var Playlist = require("./playlist");
var sanitize = require("validator").sanitize; var sanitize = require("validator").sanitize;
var $util = require("./utilities"); var $util = require("./utilities");
var url = require("url");
var AsyncQueue = require("./asyncqueue"); var AsyncQueue = require("./asyncqueue");
var ActionLog = require("./actionlog");
var InfoGetter = require("./get-info");
var Channel = function(name, Server) { var Channel = function(name) {
var self = this; var self = this;
Logger.syslog.log("Opening channel " + name); Logger.syslog.log("Opening channel " + name);
self.initialized = false; self.initialized = false;
self.dbloaded = false; self.dbloaded = false;
self.server = Server; self.server = Server.getServer();
self.name = name; self.name = name;
self.canonical_name = name.toLowerCase(); self.canonical_name = name.toLowerCase();
@ -384,7 +385,7 @@ Channel.prototype.tryReadLog = function (user) {
Channel.prototype.tryRegister = function (user) { Channel.prototype.tryRegister = function (user) {
var self = this; var self = this;
if(self.registered) { if(self.registered) {
self.server.actionlog.record(user.ip, user.name, "channel-register-failure", ActionLog.record(user.ip, user.name, "channel-register-failure",
[self.name, "Channel already registered"]); [self.name, "Channel already registered"]);
user.socket.emit("registerChannel", { user.socket.emit("registerChannel", {
success: false, success: false,
@ -392,7 +393,7 @@ Channel.prototype.tryRegister = function (user) {
}); });
} }
else if(!user.loggedIn) { else if(!user.loggedIn) {
self.server.actionlog.record(user.ip, user.name, "channel-register-failure", ActionLog.record(user.ip, user.name, "channel-register-failure",
[self.name, "Not logged in"]); [self.name, "Not logged in"]);
user.socket.emit("registerChannel", { user.socket.emit("registerChannel", {
success: false, success: false,
@ -400,8 +401,8 @@ Channel.prototype.tryRegister = function (user) {
}); });
} }
else if(!Rank.hasPermission(user, "registerChannel")) { else if(user.rank < 10) {
self.server.actionlog.record(user.ip, user.name, "channel-register-failure", ActionLog.record(user.ip, user.name, "channel-register-failure",
[self.name, "Insufficient permissions"]); [self.name, "Insufficient permissions"]);
user.socket.emit("registerChannel", { user.socket.emit("registerChannel", {
success: false, success: false,
@ -419,7 +420,7 @@ Channel.prototype.tryRegister = function (user) {
return; return;
} }
self.server.actionlog.record(user.ip, user.name, ActionLog.record(user.ip, user.name,
"channel-register-success", self.name); "channel-register-success", self.name);
if (self.dead) if (self.dead)
return; return;
@ -927,7 +928,7 @@ Channel.prototype.sendBanlist = function(user) {
var name = this.ipbans[ip][0]; var name = this.ipbans[ip][0];
var ip_hidden = this.hideIP(ip); var ip_hidden = this.hideIP(ip);
var disp = ip; var disp = ip;
if(user.rank < Rank.Siteadmin) { if(user.rank < 255) {
disp = $util.maskIP(ip); disp = $util.maskIP(ip);
} }
ents.push({ ents.push({
@ -971,7 +972,7 @@ Channel.prototype.sendRankStuff = function(user) {
} }
Channel.prototype.sendChannelRanks = function(user) { Channel.prototype.sendChannelRanks = function(user) {
if(Rank.hasPermission(user, "acl") && this.registered) { if(user.rank >= 3 && this.registered) {
this.server.db.listChannelRanks(this.name, function (err, res) { this.server.db.listChannelRanks(this.name, function (err, res) {
if(err) { if(err) {
user.socket.emit("errorMsg", { user.socket.emit("errorMsg", {
@ -1031,9 +1032,9 @@ Channel.prototype.sendAll = function(message, data) {
this.server.ioSecure.sockets.in(this.name).emit(message, data); this.server.ioSecure.sockets.in(this.name).emit(message, data);
} }
Channel.prototype.sendAllWithPermission = function(perm, msg, data) { Channel.prototype.sendAllWithRank = function(rank, msg, data) {
for(var i = 0; i < this.users.length; i++) { for(var i = 0; i < this.users.length; i++) {
if(Rank.hasPermission(this.users[i], perm)) { if(this.users[i].rank >= rank) {
this.users[i].socket.emit(msg, data); this.users[i].socket.emit(msg, data);
} }
} }
@ -1101,7 +1102,7 @@ Channel.prototype.broadcastNewUser = function(user) {
profile: user.profile profile: user.profile
}); });
if(user.rank > Rank.Guest) { if(user.rank > 0) {
self.saveRank(user); self.saveRank(user);
} }
@ -1209,7 +1210,7 @@ Channel.prototype.broadcastBanlist = function() {
} }
for(var i = 0; i < this.users.length; i++) { for(var i = 0; i < this.users.length; i++) {
if(this.hasPermission(this.users[i], "ban")) { if(this.hasPermission(this.users[i], "ban")) {
if(this.users[i].rank >= Rank.Siteadmin) { if(this.users[i].rank >= 255) {
this.users[i].socket.emit("banlist", adminents); this.users[i].socket.emit("banlist", adminents);
} }
else { else {
@ -1248,8 +1249,7 @@ Channel.prototype.broadcastVoteskipUpdate = function() {
var count = this.calcVoteskipMax(); var count = this.calcVoteskipMax();
var need = this.voteskip ? Math.ceil(count * this.opts.voteskip_ratio) : 0; var need = this.voteskip ? Math.ceil(count * this.opts.voteskip_ratio) : 0;
for(var i = 0; i < this.users.length; i++) { for(var i = 0; i < this.users.length; i++) {
if(Rank.hasPermission(this.users[i], "seeVoteskip") || if(this.users[i].rank >= 1.5) {
this.leader == this.users[i]) {
this.users[i].socket.emit("voteskip", { this.users[i].socket.emit("voteskip", {
count: amt, count: amt,
need: need need: need
@ -1332,7 +1332,7 @@ Channel.prototype.tryQueue = function(user, data) {
sustained: 1 sustained: 1
}; };
if (user.rank >= Rank.Moderator || this.leader == user) { if (user.rank >= 2 || this.leader == user) {
limit = { limit = {
burst: 10, burst: 10,
sustained: 2 sustained: 2
@ -1471,8 +1471,8 @@ Channel.prototype.addMedia = function(data, user) {
self.plqueue.queue(function (q) { self.plqueue.queue(function (q) {
if (self.dead) if (self.dead)
return; return;
self.server.infogetter.getMedia(data.id, data.type, InfoGetter.getMedia(data.id, data.type,
function (e, vids) { function (e, vids) {
if (e) { if (e) {
user.socket.emit("queueFail", { user.socket.emit("queueFail", {
msg: e, msg: e,
@ -1506,8 +1506,8 @@ Channel.prototype.addMedia = function(data, user) {
if (self.dead) if (self.dead)
return; return;
var cb = afterData.bind(self, q, false); var cb = afterData.bind(self, q, false);
self.server.infogetter.getMedia(data.id, data.type, InfoGetter.getMedia(data.id, data.type,
function (e, m) { function (e, m) {
if (self.dead) if (self.dead)
return; return;
if (e) { if (e) {
@ -1550,8 +1550,8 @@ Channel.prototype.addMedia = function(data, user) {
afterData.bind(self, q, true)(item); afterData.bind(self, q, true)(item);
} else { } else {
self.server.infogetter.getMedia(data.id, data.type, InfoGetter.getMedia(data.id, data.type,
function (e, m) { function (e, m) {
if (self.dead) if (self.dead)
return; return;
if (e) { if (e) {
@ -1671,7 +1671,7 @@ Channel.prototype.tryDequeue = function(user, data) {
Channel.prototype.tryUncache = function(user, data) { Channel.prototype.tryUncache = function(user, data) {
var self = this; var self = this;
if(!Rank.hasPermission(user, "uncache")) { if(user.rank < 2) {
return; return;
} }
if(typeof data.id != "string") { if(typeof data.id != "string") {
@ -1923,7 +1923,7 @@ Channel.prototype.setLock = function(locked) {
} }
Channel.prototype.trySetLock = function(user, data) { Channel.prototype.trySetLock = function(user, data) {
if(!Rank.hasPermission(user, "qlock")) { if(user.rank < 2) {
return; return;
} }
@ -1936,7 +1936,7 @@ Channel.prototype.trySetLock = function(user, data) {
} }
Channel.prototype.tryToggleLock = function(user) { Channel.prototype.tryToggleLock = function(user) {
if(!Rank.hasPermission(user, "qlock")) { if(user.rank < 2) {
return; return;
} }
@ -2028,7 +2028,7 @@ Channel.prototype.tryMoveFilter = function(user, data) {
} }
Channel.prototype.tryUpdatePermissions = function(user, perms) { Channel.prototype.tryUpdatePermissions = function(user, perms) {
if(!Rank.hasPermission(user, "channelperms")) { if(user.rank < 3) {
return; return;
} }
for(var key in perms) { for(var key in perms) {
@ -2039,7 +2039,7 @@ Channel.prototype.tryUpdatePermissions = function(user, perms) {
} }
Channel.prototype.tryUpdateOptions = function(user, data) { Channel.prototype.tryUpdateOptions = function(user, data) {
if(!Rank.hasPermission(user, "channelOpts")) { if(user.rank < 2) {
return; return;
} }
@ -2058,7 +2058,7 @@ Channel.prototype.tryUpdateOptions = function(user, data) {
for(var key in this.opts) { for(var key in this.opts) {
if(key in data) { if(key in data) {
if(key in adminonly && user.rank < Rank.Owner) { if(key in adminonly && user.rank < 3) {
continue; continue;
} }
if(key === "afk_timeout" && this.opts[key] != data[key]) { if(key === "afk_timeout" && this.opts[key] != data[key]) {
@ -2075,7 +2075,7 @@ Channel.prototype.tryUpdateOptions = function(user, data) {
} }
Channel.prototype.trySetCSS = function(user, data) { Channel.prototype.trySetCSS = function(user, data) {
if(!Rank.hasPermission(user, "setcss")) { if(user.rank < 3) {
return; return;
} }
@ -2092,7 +2092,7 @@ Channel.prototype.trySetCSS = function(user, data) {
} }
Channel.prototype.trySetJS = function(user, data) { Channel.prototype.trySetJS = function(user, data) {
if(!Rank.hasPermission(user, "setjs")) { if(user.rank < 3) {
return; return;
} }
@ -2234,7 +2234,7 @@ Channel.prototype.sendMessage = function(username, msg, msgclass, data) {
Channel.prototype.trySetRank = function(user, data) { Channel.prototype.trySetRank = function(user, data) {
var self = this; var self = this;
if(!Rank.hasPermission(user, "promote")) if(user.rank < 2)
return; return;
if(typeof data.user !== "string" || typeof data.rank !== "number") if(typeof data.user !== "string" || typeof data.rank !== "number")
@ -2265,7 +2265,7 @@ Channel.prototype.trySetRank = function(user, data) {
self.logger.log("*** " + user.name + " set " + self.logger.log("*** " + user.name + " set " +
data.user + "'s rank to " + data.rank); data.user + "'s rank to " + data.rank);
self.sendAllWithPermission("acl", "setChannelRank", data); self.sendAllWithRank(3, "setChannelRank", data);
}); });
} }
self.broadcastUserUpdate(receiver); self.broadcastUserUpdate(receiver);
@ -2286,7 +2286,7 @@ Channel.prototype.trySetRank = function(user, data) {
self.logger.log("*** " + user.name + " set " + self.logger.log("*** " + user.name + " set " +
data.user + "'s rank to " + data.rank); data.user + "'s rank to " + data.rank);
self.sendAllWithPermission("acl", "setChannelRank", data); self.sendAllWithRank(3, "setChannelRank", data);
}); });
}); });
} }
@ -2329,7 +2329,7 @@ Channel.prototype.changeLeader = function(name) {
} }
Channel.prototype.tryChangeLeader = function(user, data) { Channel.prototype.tryChangeLeader = function(user, data) {
if(!Rank.hasPermission(user, "assignLeader")) { if(user.rank < 2) {
return; return;
} }

View File

@ -9,8 +9,6 @@ The above copyright notice and this permission notice shall be included in all c
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/ */
var Rank = require("./rank.js");
var Poll = require("./poll.js").Poll;
var Logger = require("./logger.js"); var Logger = require("./logger.js");
function handle(chan, user, msg, data) { function handle(chan, user, msg, data) {
@ -19,7 +17,7 @@ function handle(chan, user, msg, data) {
else if(msg.indexOf("/sp ") == 0) else if(msg.indexOf("/sp ") == 0)
chan.sendMessage(user.name, msg.substring(4), "spoiler", data); chan.sendMessage(user.name, msg.substring(4), "spoiler", data);
else if(msg.indexOf("/say ") == 0) { else if(msg.indexOf("/say ") == 0) {
if(Rank.hasPermission(user, "shout") || chan.leader == user) { if(user.rank >= 1.5) {
chan.sendMessage(user.name, msg.substring(5), "shout", data); chan.sendMessage(user.name, msg.substring(5), "shout", data);
} }
} }
@ -27,12 +25,12 @@ function handle(chan, user, msg, data) {
user.setAFK(!user.meta.afk); user.setAFK(!user.meta.afk);
} }
else if(msg.indexOf("/m ") == 0) { else if(msg.indexOf("/m ") == 0) {
if(user.rank >= Rank.Moderator) { if(user.rank >= 2) {
chan.chainMessage(user, msg.substring(3), {modflair: user.rank}) chan.chainMessage(user, msg.substring(3), {modflair: user.rank})
} }
} }
else if(msg.indexOf("/a ") == 0) { else if(msg.indexOf("/a ") == 0) {
if(user.rank >= Rank.Siteadmin) { if(user.rank >= 255) {
var flair = { var flair = {
superadminflair: { superadminflair: {
labelclass: "label-important", labelclass: "label-important",
@ -241,7 +239,7 @@ function handleDrink(chan, user, msg, data) {
} }
function handleClear(chan, user) { function handleClear(chan, user) {
if(user.rank < Rank.Moderator) { if(user.rank < 2) {
return; return;
} }

File diff suppressed because it is too large Load Diff

View File

@ -9,6 +9,29 @@ The above copyright notice and this permission notice shall be included in all c
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/ */
var singleton = null;
module.exports = {
init: function (cfg) {
Logger.syslog.log("Starting CyTube v" + VERSION);
var chanlogpath = path.join(__dirname, "../chanlogs");
fs.exists(chanlogpath, function (exists) {
exists || fs.mkdir(chanlogpath);
});
var chandumppath = path.join(__dirname, "../chandump");
fs.exists(chandumppath, function (exists) {
exists || fs.mkdir(chandumppath);
});
singleton = new Server(cfg);
return singleton;
},
getServer: function () {
return singleton;
}
};
var path = require("path"); var path = require("path");
var fs = require("fs"); var fs = require("fs");
var http = require("http"); var http = require("http");
@ -36,7 +59,6 @@ var Server = function (cfg) {
self.ioSecure = null; self.ioSecure = null;
self.ipCount = {}; self.ipCount = {};
self.db = null; self.db = null;
self.acp = null;
self.api = null; self.api = null;
self.announcement = null; self.announcement = null;
self.httplog = null; self.httplog = null;
@ -46,8 +68,7 @@ var Server = function (cfg) {
// database init ------------------------------------------------------ // database init ------------------------------------------------------
var Database = require("./database"); var Database = require("./database");
self.db = new Database(self.cfg); self.db = new Database(self.cfg);
// TODO self.db.init(); self.actionlog = require("./actionlog");
self.actionlog = require("./actionlog")(self);
self.httplog = new Logger.Logger(path.join(__dirname, self.httplog = new Logger.Logger(path.join(__dirname,
"../httpaccess.log")); "../httpaccess.log"));
// webserver init ----------------------------------------------------- // webserver init -----------------------------------------------------
@ -139,15 +160,12 @@ var Server = function (cfg) {
self.handleSocketConnection(sock); self.handleSocketConnection(sock);
}); });
// acp init -----------------------------------------------------------
self.acp = require("./acp")(self);
// background tasks init ---------------------------------------------- // background tasks init ----------------------------------------------
require("./bgtask")(self); require("./bgtask")(self);
// media metadata retriever init -------------------------------------- // media metadata retriever init --------------------------------------
// TODO make the constructor just accept cfg? // TODO make the constructor just accept cfg?
self.infogetter = require("./get-info")(self); self.infogetter = require("./get-info");
}; };
Server.prototype.getHTTPIP = function (req) { Server.prototype.getHTTPIP = function (req) {
@ -190,7 +208,7 @@ Server.prototype.getChannel = function (name) {
return this.channels[i]; return this.channels[i];
} }
var c = new Channel(name, this); var c = new Channel(name);
this.channels.push(c); this.channels.push(c);
return c; return c;
}; };
@ -268,7 +286,7 @@ Server.prototype.handleSocketConnection = function (socket) {
} }
Logger.syslog.log("Accepted socket from " + ip); Logger.syslog.log("Accepted socket from " + ip);
new User(socket, self); new User(socket);
}; };
Server.prototype.shutdown = function () { Server.prototype.shutdown = function () {
@ -283,25 +301,3 @@ Server.prototype.shutdown = function () {
process.exit(0); process.exit(0);
}; };
var singleton = null;
module.exports = {
init: function (cfg) {
Logger.syslog.log("Starting CyTube v" + VERSION);
var chanlogpath = path.join(__dirname, "../chanlogs");
fs.exists(chanlogpath, function (exists) {
exists || fs.mkdir(chanlogpath);
});
var chandumppath = path.join(__dirname, "../chandump");
fs.exists(chandumppath, function (exists) {
exists || fs.mkdir(chandumppath);
});
singleton = new Server(cfg);
return singleton;
},
getServer: function () {
return singleton;
}
};

View File

@ -9,21 +9,24 @@ The above copyright notice and this permission notice shall be included in all c
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/ */
var Rank = require("./rank.js");
var Channel = require("./channel.js").Channel; var Channel = require("./channel.js").Channel;
var Logger = require("./logger.js"); var Logger = require("./logger.js");
var $util = require("./utilities"); var $util = require("./utilities");
var ActionLog = require("./actionlog");
var Server = require("./server");
var ACP = require("./acp");
var InfoGetter = require("./get-info");
// Represents a client connected via socket.io // Represents a client connected via socket.io
var User = function (socket, Server) { var User = function (socket) {
this.ip = socket._ip; this.ip = socket._ip;
this.server = Server; this.server = Server.getServer();
this.socket = socket; this.socket = socket;
this.loggedIn = false; this.loggedIn = false;
this.loggingIn = false; this.loggingIn = false;
this.saverank = false; this.saverank = false;
this.rank = Rank.Anonymous; this.rank = -1
this.global_rank = Rank.Anonymous; this.global_rank = -1;
this.channel = null; this.channel = null;
this.name = ""; this.name = "";
this.meta = { this.meta = {
@ -42,8 +45,8 @@ var User = function (socket, Server) {
this.autoAFK(); this.autoAFK();
this.initCallbacks(); this.initCallbacks();
if (Server.announcement !== null) { if (this.server.announcement !== null) {
this.socket.emit("announcement", Server.announcement); this.socket.emit("announcement", this.server.announcement);
} }
}; };
@ -321,7 +324,7 @@ User.prototype.initCallbacks = function () {
self.socket.on("searchMedia", function (data) { self.socket.on("searchMedia", function (data) {
if (self.inChannel()) { if (self.inChannel()) {
if (data.source == "yt") { if (data.source == "yt") {
var searchfn = self.server.infogetter.Getters.ytSearch; var searchfn = InfoGetter.Getters.ytSearch;
searchfn(data.query.split(" "), function (e, vids) { searchfn(data.query.split(" "), function (e, vids) {
if (!e) { if (!e) {
self.socket.emit("searchResults", { self.socket.emit("searchResults", {
@ -556,8 +559,8 @@ User.prototype.initCallbacks = function () {
}); });
self.socket.on("acp-init", function () { self.socket.on("acp-init", function () {
if (self.global_rank >= Rank.Siteadmin) if (self.global_rank >= 255)
self.server.acp.init(self); ACP.init(self);
}); });
self.socket.on("borrow-rank", function (rank) { self.socket.on("borrow-rank", function (rank) {
@ -662,7 +665,7 @@ User.prototype.login = function (name, pw, session) {
self.server.db.userLogin(name, pw, session, function (err, row) { self.server.db.userLogin(name, pw, session, function (err, row) {
if (err) { if (err) {
self.loggingIn = false; self.loggingIn = false;
self.server.actionlog.record(self.ip, name, "login-failure", ActionLog.record(self.ip, name, "login-failure",
err); err);
self.socket.emit("login", { self.socket.emit("login", {
success: false, success: false,
@ -686,7 +689,7 @@ User.prototype.login = function (name, pw, session) {
} }
// Record logins for administrator accounts // Record logins for administrator accounts
if (self.global_rank >= 255) if (self.global_rank >= 255)
self.server.actionlog.record(self.ip, name, "login-success"); ActionLog.record(self.ip, name, "login-success");
self.loggedIn = true; self.loggedIn = true;
self.loggingIn = false; self.loggingIn = false;
self.socket.emit("login", { self.socket.emit("login", {