From 99354f8c71c479d7530fdd5e4178bfcc3c7e4a25 Mon Sep 17 00:00:00 2001 From: "elly1989@rocketmail.com" Date: Tue, 31 Jul 2012 20:42:10 +0000 Subject: [PATCH] More gifts from FPstation. This fetches a list of known proxies and stops people from connecting whilst using them. Proxies are often used for nefarious reasons. It needs to be kept as up-to-date as possible, so it autoupdates every 6+ hours or so to ensure the database is relatively up-to-date. Like the previous commit, I'd only really recommend it if the other stuff isn't getting the job done. git-svn-id: http://tgstation13.googlecode.com/svn/trunk@4257 316c924e-a436-60f5-8080-3fe189b3f50e --- code/datums/configuration.dm | 4 ++ code/game/algorithm.dm | 6 ++- code/modules/admin/IsBanned.dm | 8 +++ code/modules/admin/ToRban.dm | 90 +++++++++++++++++++++++++++++++ code/modules/admin/admin_verbs.dm | 2 + config/config.txt | 3 ++ tgstation.dme | 1 + 7 files changed, 112 insertions(+), 2 deletions(-) create mode 100644 code/modules/admin/ToRban.dm diff --git a/code/datums/configuration.dm b/code/datums/configuration.dm index cbfcd3bef13..d62589be825 100644 --- a/code/datums/configuration.dm +++ b/code/datums/configuration.dm @@ -49,6 +49,7 @@ var/usewhitelist = 0 var/kick_inactive = 0 //force disconnect for inactive players var/load_jobs_from_txt = 0 + var/ToRban = 0 var/server var/banappeals @@ -313,6 +314,9 @@ if("humans_need_surnames") humans_need_surnames = 1 + if("tor_ban") + ToRban = 1 + else diary << "Unknown setting in configuration: '[name]'" diff --git a/code/game/algorithm.dm b/code/game/algorithm.dm index 6fb0970dad5..61b0a3bcae6 100644 --- a/code/game/algorithm.dm +++ b/code/game/algorithm.dm @@ -26,8 +26,10 @@ Starting up. [time2text(world.timeofday, "hh:mm.ss")] process_ghost_teleport_locs() //Sets up ghost teleport locations. sleep_offline = 1 - if (config.kick_inactive) - spawn(30) + spawn(3000) //so we aren't adding to the round-start lag + if(config.ToRban) + ToRban_autoupdate() + if(config.kick_inactive) KickInactiveClients() #define INACTIVITY_KICK 6000 //10 minutes in ticks (approx.) diff --git a/code/modules/admin/IsBanned.dm b/code/modules/admin/IsBanned.dm index 8b1cc612aa0..dc965873eb8 100644 --- a/code/modules/admin/IsBanned.dm +++ b/code/modules/admin/IsBanned.dm @@ -9,6 +9,14 @@ world/IsBanned(key,address,computer_id) message_admins("\blue Failed Login: [key] - Guests not allowed") return list("reason"="guest", "desc"="\nReason: Guests not allowed.brb") + //check if the IP address is a known TOR node + if( config && config.ToRban && ToRban_isbanned(address) ) + log_access("Failed Login: [src] - Banned: ToR - BYOND Version: [byond_version]") + message_admins("\blue Failed Login: [src] - Banned: ToR - BYOND Version: [byond_version]") + //ban their computer_id and ckey for posterity + AddBan(ckey(key), computer_id, "Use of ToR", "Automated Ban", 0, 0) + return list("reason"="Using ToR", "desc"="\nReason: The network you are using to connect has been banned.\nIf you believe this is a mistake, please request help at [config.banappeals]") + //Ban Checking . = CheckBan( ckey(key), computer_id, address ) if(.) diff --git a/code/modules/admin/ToRban.dm b/code/modules/admin/ToRban.dm new file mode 100644 index 00000000000..5f6dcbe460c --- /dev/null +++ b/code/modules/admin/ToRban.dm @@ -0,0 +1,90 @@ +//By Carnwennan +//fetches an external list and processes it into a list of ip addresses. +//It then stores the processed list into a savefile for later use +#define TORFILE "data/ToR_ban.bdb" +#define TOR_UPDATE_INTERVAL 216000 //~6 hours + +/proc/ToRban_isbanned(var/ip_address) + var/savefile/F = new(TORFILE) + if(F) + if( ip_address in F.dir ) + return 1 + return 0 + +/proc/ToRban_autoupdate() + var/savefile/F = new(TORFILE) + if(F) + var/last_update + F["last_update"] >> last_update + if((last_update + TOR_UPDATE_INTERVAL) < world.realtime) //we haven't updated for a while + ToRban_update() + return + +/proc/ToRban_update() + spawn(0) + diary << "Downloading updated ToR data..." + var/http[] = world.Export("http://exitlist.torproject.org/exit-addresses") + + var/rawtext = file2text(http["CONTENT"]) + if(rawtext) + var/list/rawlist = tg_text2list(rawtext,"\n") + if(rawlist.len) + fdel(TORFILE) + var/savefile/F = new(TORFILE) + for( var/line in rawlist ) + if(!line) continue + if( copytext(line,1,12) == "ExitAddress" ) + var/cleaned = copytext(line,13,length(line)-19) + if(!cleaned) continue + F[cleaned] << 1 + F["last_update"] << world.realtime + diary << "ToR data updated!" + if(usr) usr << "ToRban updated." + return 1 + diary << "ToR data update aborted: no data." + return 0 + +/client/proc/ToRban(task in list("update","toggle","show","remove","remove all","find")) + set name = "ToRban" + set category = "Server" + if(!holder) return + switch(task) + if("update") + ToRban_update() + if("toggle") + if(config) + if(config.ToRban) + config.ToRban = 0 + message_admins("ToR banning disabled.") + else + config.ToRban = 1 + message_admins("ToR banning enabled.") + if("show") + var/savefile/F = new(TORFILE) + var/dat + if( length(F.dir) ) + for( var/i=1, i<=length(F.dir), i++ ) + dat += "#[i] [F.dir[i]]" + dat = "[dat]
" + else + dat = "No addresses in list." + src << browse(dat,"window=ToRban_show") + if("remove") + var/savefile/F = new(TORFILE) + var/choice = input(src,"Please select an IP address to remove from the ToR banlist:","Remove ToR ban",null) as null|anything in F.dir + if(choice) + F.dir.Remove(choice) + src << "Address removed" + if("remove all") + src << "[TORFILE] was [fdel(TORFILE)?"":"not "]removed." + if("find") + var/input = input(src,"Please input an IP address to search for:","Find ToR ban",null) as null|text + if(input) + if(ToRban_isbanned(input)) + src << "Address is a known ToR address" + else + src << "Address is not a known ToR address" + return + +#undef TORFILE +#undef TOR_UPDATE_INTERVAL \ No newline at end of file diff --git a/code/modules/admin/admin_verbs.dm b/code/modules/admin/admin_verbs.dm index 8f8d0d7389f..1b26e1c32ed 100644 --- a/code/modules/admin/admin_verbs.dm +++ b/code/modules/admin/admin_verbs.dm @@ -254,6 +254,7 @@ verbs += /client/proc/deadmin_self verbs += /client/proc/Set_Holiday //Force-set a Holiday verbs += /client/proc/admin_memo + verbs += /client/proc/ToRban //ToRban frontend to access its features. //verbs += /client/proc/cmd_mass_modify_object_variables --Merged with view variables //verbs += /client/proc/cmd_admin_explosion --Merged with view variables //verbs += /client/proc/cmd_admin_emp --Merged with view variables @@ -412,6 +413,7 @@ verbs -= /client/proc/admin_memo verbs -= /client/proc/investigate_show //investigate in-game mishaps using various logs. verbs -= /client/proc/toggle_log_hrefs + verbs -= /client/proc/ToRban verbs -= /proc/possess verbs -= /proc/release //verbs -= /client/proc/give_spell --Merged with view variables diff --git a/config/config.txt b/config/config.txt index eab32a5494b..b79435f950e 100644 --- a/config/config.txt +++ b/config/config.txt @@ -162,3 +162,6 @@ TICKCOMP 0 ## if uncommented this adds a random surname to a player's name if they only specify one name HUMANS_NEED_SURNAMES + +## Uncomment this to ban use of ToR +#TOR_BAN \ No newline at end of file diff --git a/tgstation.dme b/tgstation.dme index 39b1bcbe67c..756773258cb 100644 --- a/tgstation.dme +++ b/tgstation.dme @@ -781,6 +781,7 @@ #include "code\modules\admin\newbanjob.dm" #include "code\modules\admin\player_notes.dm" #include "code\modules\admin\player_panel.dm" +#include "code\modules\admin\ToRban.dm" #include "code\modules\admin\DB ban\functions.dm" #include "code\modules\admin\verbs\adminhelp.dm" #include "code\modules\admin\verbs\adminjump.dm"