Deprecate legacy global ban junk

This commit is contained in:
Calvin Montgomery 2017-06-05 23:18:20 -07:00
parent b23a858a8c
commit 00a65a1584
3 changed files with 13 additions and 107 deletions

View File

@ -2,7 +2,7 @@
"author": "Calvin Montgomery",
"name": "CyTube",
"description": "Online media synchronizer and chat",
"version": "3.37.0",
"version": "3.38.0",
"repository": {
"url": "http://github.com/calzoneman/sync"
},

View File

@ -278,22 +278,18 @@ function init(user) {
s.on("acp-force-unload", handleForceUnload.bind(this, user));
s.on("acp-list-stats", handleListStats.bind(this, user));
db.listGlobalBans(function (err, bans) {
if (err) {
user.socket.emit("errMessage", {
msg: err
});
return;
}
var flat = [];
for (var ip in bans) {
flat.push({
ip: ip,
note: bans[ip].reason
});
}
user.socket.emit("acp-gbanlist", flat);
const globalBanDB = db.getGlobalBanDB();
globalBanDB.listGlobalBans().then(bans => {
// Why is it called reason in the DB and note in the socket frame?
// Who knows...
const mappedBans = bans.map(ban => {
return { ip: ban.ip, note: ban.reason };
});
user.socket.emit("acp-gbanlist", mappedBans);
}).catch(error => {
user.socket.emit("errMessage", {
msg: error.message
});
});
Logger.eventlog.log("[acp] Initialized ACP for " + eventUsername(user));
}

View File

@ -11,7 +11,6 @@ import { GlobalBanDB } from './db/globalban';
const LOGGER = LoggerFactory.getLogger('database');
var global_ipbans = {};
let db = null;
let globalBanDB = null;
@ -64,7 +63,6 @@ module.exports.init = function (newDB) {
process.nextTick(legacySetup);
});
global_ipbans = {};
module.exports.users = require("./database/accounts");
module.exports.channels = require("./database/channels");
};
@ -89,8 +87,6 @@ function legacySetup() {
require("./database/update").checkVersion();
module.exports.loadAnnouncement();
});
// Refresh global IP bans
module.exports.listGlobalBans();
}
/**
@ -130,92 +126,6 @@ function blackHole() {
}
/* REGION global bans */
/**
* Check if an IP address is globally banned
*/
module.exports.isGlobalIPBanned = function (ip, callback) {
var range = util.getIPRange(ip);
var wrange = util.getWideIPRange(ip);
var banned = ip in global_ipbans ||
range in global_ipbans ||
wrange in global_ipbans;
if (callback) {
callback(null, banned);
}
return banned;
};
/**
* Retrieve all global bans from the database.
* Cache locally in global_bans
*/
module.exports.listGlobalBans = function (callback) {
if (typeof callback !== "function") {
callback = blackHole;
}
module.exports.query("SELECT * FROM global_bans WHERE 1", function (err, res) {
if (err) {
callback(err, null);
return;
}
global_ipbans = {};
for (var i = 0; i < res.length; i++) {
global_ipbans[res[i].ip] = res[i];
}
callback(null, global_ipbans);
});
};
/**
* Globally ban by IP
*/
module.exports.globalBanIP = function (ip, reason, callback) {
if (typeof callback !== "function") {
callback = blackHole;
}
var query = "INSERT INTO global_bans (ip, reason) VALUES (?, ?)" +
" ON DUPLICATE KEY UPDATE reason=?";
module.exports.query(query, [ip, reason, reason], function (err, res) {
if(err) {
callback(err, null);
return;
}
module.exports.listGlobalBans();
callback(null, res);
});
};
/**
* Remove a global IP ban
*/
module.exports.globalUnbanIP = function (ip, callback) {
if (typeof callback !== "function") {
callback = blackHole;
}
var query = "DELETE FROM global_bans WHERE ip=?";
module.exports.query(query, [ip], function (err, res) {
if(err) {
callback(err, null);
return;
}
module.exports.listGlobalBans();
callback(null, res);
});
};
/* END REGION */
/* password recovery */
/**