This commit is contained in:
calzoneman 2013-05-27 15:43:37 -04:00
parent e19f38f75b
commit cc8c2d8463
3 changed files with 37 additions and 10 deletions

4
api.js
View File

@ -292,7 +292,7 @@ function handleGlobalBans(params, req, res) {
}); });
return; return;
} }
var result = Database.addGlobalBan(ip, reason); var result = Database.globalBanIP(ip, reason);
sendJSON(res, { sendJSON(res, {
success: result, success: result,
ip: ip, ip: ip,
@ -307,7 +307,7 @@ function handleGlobalBans(params, req, res) {
}); });
return; return;
} }
var result = Database.liftGlobalBan(ip); var result = Database.globalUnbanIP(ip);
sendJSON(res, { sendJSON(res, {
success: result, success: result,
ip: ip, ip: ip,

View File

@ -137,6 +137,7 @@ function refreshGlobalBans() {
global_bans[rows[i].ip] = rows[i].note; global_bans[rows[i].ip] = rows[i].note;
} }
} }
return global_bans;
} }
function globalBanIP(ip, reason) { function globalBanIP(ip, reason) {
@ -169,8 +170,12 @@ function globalUnbanIP(ip) {
/* REGION Channel Registration/Loading */ /* REGION Channel Registration/Loading */
function registerChannel(name) { function registerChannel(name) {
if(!name.match(/^[a-zA-Z0-9-_]+$/)) {
return false;
}
var db = getConnection(); var db = getConnection();
if(!db) { return false; if(!db) {
return false;
} }
// Library table // Library table
@ -234,6 +239,9 @@ function registerChannel(name) {
} }
function loadChannel(chan) { function loadChannel(chan) {
if(!name.match(/^[a-zA-Z0-9-_]+$/)) {
return false;
}
var db = getConnection(); var db = getConnection();
if(!db) { if(!db) {
return; return;
@ -309,7 +317,7 @@ function loadChannel(chan) {
} }
function deleteChannel(name) { function deleteChannel(name) {
if(!/[a-zA-Z0-9-_]+/.test(name)) { if(!name.match(/^[a-zA-Z0-9-_]+$/)) {
return false; return false;
} }
@ -344,6 +352,9 @@ function deleteChannel(name) {
/* REGION Channel data */ /* REGION Channel data */
function getChannelRank(chan, name) { function getChannelRank(chan, name) {
if(!chan.match(/^[a-zA-Z0-9-_]+$/)) {
return false;
}
var db = getConnection(); var db = getConnection();
if(!db) { if(!db) {
return 0; return 0;
@ -394,6 +405,9 @@ function getChannelRank(chan, name) {
} }
function setChannelRank(chan, name, rank) { function setChannelRank(chan, name, rank) {
if(!chan.match(/^[a-zA-Z0-9-_]+$/)) {
return false;
}
var db = getConnection(); var db = getConnection();
if(!db) { if(!db) {
return false; return false;
@ -413,12 +427,11 @@ function setChannelRank(chan, name, rank) {
} }
function listChannelRanks(chan) { function listChannelRanks(chan) {
var db = getConnection(); if(!chan.match(/^[a-zA-Z0-9-_]+$/)) {
if(!db) {
return []; return [];
} }
var db = getConnection();
if(!chan.registered) { if(!db) {
return []; return [];
} }
@ -429,7 +442,6 @@ function listChannelRanks(chan) {
var results = db.querySync(query); var results = db.querySync(query);
if(!results) { if(!results) {
Logger.errlog.log("! Failed to list ranks: " + chan);
return []; return [];
} }
@ -437,6 +449,9 @@ function listChannelRanks(chan) {
} }
function addToLibrary(chan, media) { function addToLibrary(chan, media) {
if(!chan.match(/^[a-zA-Z0-9-_]+$/)) {
return false;
}
var db = getConnection(); var db = getConnection();
if(!db) { if(!db) {
return false; return false;
@ -454,6 +469,9 @@ function addToLibrary(chan, media) {
} }
function removeFromLibrary(chan, id) { function removeFromLibrary(chan, id) {
if(!chan.match(/^[a-zA-Z0-9-_]+$/)) {
return false;
}
var db = getConnection(); var db = getConnection();
if(!db) { if(!db) {
return false; return false;
@ -468,6 +486,9 @@ function removeFromLibrary(chan, id) {
} }
function channelBan(chan, ip, name, banby) { function channelBan(chan, ip, name, banby) {
if(!chan.match(/^[a-zA-Z0-9-_]+$/)) {
return false;
}
var db = getConnection(); var db = getConnection();
if(!db) { if(!db) {
return false; return false;
@ -485,6 +506,9 @@ function channelBan(chan, ip, name, banby) {
} }
function channelUnbanIP(chan, ip) { function channelUnbanIP(chan, ip) {
if(!chan.match(/^[a-zA-Z0-9-_]+$/)) {
return false;
}
var db = getConnection(); var db = getConnection();
if(!db) { if(!db) {
return false; return false;
@ -499,6 +523,9 @@ function channelUnbanIP(chan, ip) {
} }
function channelUnbanName(chan, name) { function channelUnbanName(chan, name) {
if(!chan.match(/^[a-zA-Z0-9-_]+$/)) {
return false;
}
var db = getConnection(); var db = getConnection();
if(!db) { if(!db) {
return false; return false;

View File

@ -1,4 +1,4 @@
var Database = require("../database-new"); var Database = require("../database");
Database.setup(require("../config-testing")); Database.setup(require("../config-testing"));
var assert = require("assert"); var assert = require("assert");
var db = Database.getConnection(); var db = Database.getConnection();