From: Chris Porter Date: Sat, 11 Feb 2006 01:32:00 +0000 (+0000) Subject: Added misc flag to noperserv. X-Git-Url: https://jfr.im/git/irc/quakenet/newserv.git/commitdiff_plain/cc3768c4e7fba0b6a8f75c42b8d295d5ad6de4da Added misc flag to noperserv. Added geoip module. Modified nterfacer_country to use geoip module. Added country broadcast to noperserv. --- diff --git a/geoip/Makefile b/geoip/Makefile new file mode 100644 index 00000000..68f7794c --- /dev/null +++ b/geoip/Makefile @@ -0,0 +1,6 @@ + +.PHONY: all +all: geoip.so + +geoip.so: geoip.o libGeoIP/GeoIP.o + ld -shared -Bdynamic -o $@ $^ diff --git a/geoip/geoip.c b/geoip/geoip.c new file mode 100644 index 00000000..47f30245 --- /dev/null +++ b/geoip/geoip.c @@ -0,0 +1,107 @@ +/* + Geoip module + Copyright (C) 2004-2006 Chris Porter. +*/ + +#include "../nick/nick.h" +#include "../core/error.h" +#include "../core/config.h" +#include "../core/hooks.h" +#include "../control/control.h" + +#include "geoip.h" + +int geoip_totals[COUNTRY_MAX + 1]; +int geoip_nickext = -1; +GeoIP *gi = NULL; + +void geoip_setupuser(nick *np); + +void geoip_new_nick(int hook, void *args); +void geoip_quit(int hook, void *args); +void geoip_whois_handler(int hooknum, void *arg); + +void _init(void) { + int i; + nick *np; + sstring *filename; + + filename = getcopyconfigitem("geoip", "db", "GeoIP.dat", 256); + gi = GeoIP_new(GEOIP_MEMORY_CACHE, filename->content); + freesstring(filename); + + if(!gi) + return; + + geoip_nickext = registernickext("geoip"); + if(geoip_nickext == -1) + return; /* PPA: registerchanext produces an error, however the module should stop loading */ + + memset(geoip_totals, 0, sizeof(geoip_totals)); + + for(i=0;inext) + geoip_setupuser(np); + + registerhook(HOOK_NICK_LOSTNICK, &geoip_quit); + registerhook(HOOK_NICK_NEWNICK, &geoip_new_nick); + registerhook(HOOK_CONTROL_WHOISREQUEST, &geoip_whois_handler); +} + +void _fini(void) { + if(gi) + GeoIP_delete(gi); + + if(geoip_nickext == -1) + return; + + releasenickext(geoip_nickext); + + deregisterhook(HOOK_NICK_NEWNICK, &geoip_new_nick); + deregisterhook(HOOK_NICK_LOSTNICK, &geoip_quit); + deregisterhook(HOOK_CONTROL_WHOISREQUEST, &geoip_whois_handler); +} + +void geoip_setupuser(nick *np) { + int country = GeoIP_id_by_ipnum(gi, np->ipaddress); + if((country < COUNTRY_MIN) || (country > COUNTRY_MAX)) + return; + + geoip_totals[country]++; + np->exts[geoip_nickext] = (void *)(long)country; +} + +void geoip_new_nick(int hook, void *args) { + geoip_setupuser((nick *)args); +} + +void geoip_quit(int hook, void *args) { + int item; + nick *np = (nick *)args; + + item = (int)((long)np->exts[geoip_nickext]); + + if((item < COUNTRY_MIN) || (item > COUNTRY_MAX)) + return; + + geoip_totals[item]--; +} + +void geoip_whois_handler(int hooknum, void *arg) { + int item; + char message[512], *longcountry, *shortcountry, *shortcountry3; + nick *np = (nick *)arg; + + if(!np) + return; + + item = (int)((long)np->exts[geoip_nickext]); + if((item < COUNTRY_MIN) || (item > COUNTRY_MAX)) + return; + + if(GeoIP_country_info_by_id(item, &shortcountry, &shortcountry3, &longcountry)) { + snprintf(message, sizeof(message), "Country : %s (%s)", shortcountry, longcountry); + triggerhook(HOOK_CONTROL_WHOISREPLY, message); + } +} + diff --git a/geoip/geoip.h b/geoip/geoip.h new file mode 100644 index 00000000..0d5f9fcc --- /dev/null +++ b/geoip/geoip.h @@ -0,0 +1,7 @@ +#include "libGeoIP/GeoIP.h" + +#define COUNTRY_MIN 0 +#define COUNTRY_MAX 246 + +extern int geoip_totals[COUNTRY_MAX + 1]; + diff --git a/nterface/libGeoIP/GeoIP.c b/geoip/libGeoIP/GeoIP.c similarity index 100% rename from nterface/libGeoIP/GeoIP.c rename to geoip/libGeoIP/GeoIP.c diff --git a/nterface/libGeoIP/GeoIP.h b/geoip/libGeoIP/GeoIP.h similarity index 100% rename from nterface/libGeoIP/GeoIP.h rename to geoip/libGeoIP/GeoIP.h diff --git a/noperserv/Makefile b/noperserv/Makefile index 7d4b879f..7edabd1f 100644 --- a/noperserv/Makefile +++ b/noperserv/Makefile @@ -1,9 +1,12 @@ .PHONY: all -all: noperserv.so noperserv_commands.so +all: noperserv.so noperserv_commands.so noperserv_fakeuser.so noperserv.so: noperserv.o noperserv_db.o noperserv_hooks.o noperserv_policy.o ld -shared -Bdynamic ${LIBPGSQL} -o $@ $^ noperserv_commands.so: noperserv_commands.o ld -shared -Bdynamic ${LIBPGSQL} -o $@ $^ + +noperserv_fakeuser.so: noperserv_fakeuser.o + ld -shared -Bdynamic ${LIBPGSQL} -o $@ $^ diff --git a/noperserv/noperserv.c b/noperserv/noperserv.c index 43b16006..bd793c06 100644 --- a/noperserv/noperserv.c +++ b/noperserv/noperserv.c @@ -60,6 +60,7 @@ const flag no_noticeflags[] = { { 'O', NL_OPERING }, /* when someone opers */ { 'n', NL_NOTICES }, /* turn off to receive notices instead of privmsgs */ { 'A', NL_ALL_COMMANDS }, /* all commands sent */ + { 'I', NL_MISC }, /* misc stuff */ { '\0', 0 } }; @@ -81,7 +82,22 @@ void _init() { noperserv_setup_hooks(); registercontrolhelpcmd("hello", NO_OPERED | NO_AUTHED, 1, &noperserv_hello, "Syntax: HELLO ?nickname|#authname?\nCreates an account on the service for the specified nick, or if one isn't supplied, your nickname."); - registercontrolhelpcmd("userflags", NO_ACCOUNT, 2, &noperserv_userflags, "Syntax: USERFLAGS ?modifications?\nViews and modifies user permissions.\nIf no nickname or authname is supplied, you are substituted for it.\nIf no flags are supplied, flags are just displayed instead of modified."); + registercontrolhelpcmd("userflags", NO_ACCOUNT, 2, &noperserv_userflags, + "Syntax: USERFLAGS ?modifications?\n" + " Views and modifies user permissions.\n" + " If no nickname or authname is supplied, you are substituted for it.\n" + " If no flags are supplied, flags are just displayed instead of modified." + " Flags:\n" + " +o: Operator\n" + " +s: Staff member\n" + " +S: Security team member\n" + " +d: NOperserv developer\n" + " +t: Trust queue worker\n" + " Additional flags may show up in SHOWCOMMANDS but are not userflags as such:\n" + " +r: Authed user\n" + " +d: Registered NOperserv user\n" + " +L: Legacy command\n" + ); registercontrolhelpcmd("noticeflags", NO_ACCOUNT, 1, &noperserv_noticeflags, "Syntax: NOTICEFLAGS ?(nickname|#authname)|flags?\n" " This command can view and modify your own notice flags, and view that of other users.\n" @@ -94,12 +110,13 @@ void _init() { " +h: Shows when glines are played automatically (hits)\n" " +c: Clone information\n" " +C: CLEARCHAN command\n" - " +f: FAKEUSER command\n" + " +f: FAKEUSER commands\n" " +b: BROADCAST commands\n" " +o: Operation commands, such as insmod, rmmod, die, etc\n" " +O: /OPER\n" + " +I: Misc commands (resync)\n" " +n: Sends notices instead of privmsgs\n" - " +A: Every single command sent to the service\n" + " +A: Every single command sent to the service (spammy)\n" ); registercontrolhelpcmd("deluser", NO_OPERED | NO_ACCOUNT, 2, &noperserv_deluser, "Syntax: DELUSER \nDeletes the specified user."); diff --git a/noperserv/noperserv_commands.c b/noperserv/noperserv_commands.c index b3bba801..0f2fa25a 100644 --- a/noperserv/noperserv_commands.c +++ b/noperserv/noperserv_commands.c @@ -2,6 +2,7 @@ #include #include #include +#include #include #include "../control/control.h" @@ -9,6 +10,7 @@ #include "../lib/irc_string.h" #include "../lib/strlfunc.h" #include "../localuser/localuserchannel.h" +#include "../geoip/geoip.h" int controlkill(void *sender, int cargc, char **cargv); int controlopchan(void *sender, int cargc, char **cargv); @@ -20,6 +22,7 @@ int controlbroadcast(void *sender, int cargc, char **cargv); int controlobroadcast(void *sender, int cargc, char **cargv); int controlmbroadcast(void *sender, int cargc, char **cargv); int controlsbroadcast(void *sender, int cargc, char **cargv); +int controlcbroadcast(void *sender, int cargc, char **cargv); void _init() { registercontrolhelpcmd("kill", NO_OPER, 2, &controlkill, "Usage: kill ?reason?\nKill specified user with given reason (or 'Killed')."); @@ -33,8 +36,9 @@ void _init() { registercontrolhelpcmd("broadcast", NO_OPER, 1, &controlbroadcast, "Usage: broadcast \nSends a message to all users."); registercontrolhelpcmd("obroadcast", NO_OPER, 1, &controlobroadcast, "Usage: obroadcast \nSends a message to all IRC operators."); - registercontrolhelpcmd("mbroadcast", NO_OPER, 2, &controlmbroadcast, "Usage: mbroadcast \nSends a message to all users matching the mask."); + registercontrolhelpcmd("mbroadcast", NO_OPER, 2, &controlmbroadcast, "Usage: mbroadcast \nSends a message to all users matching the mask"); registercontrolhelpcmd("sbroadcast", NO_OPER, 2, &controlsbroadcast, "Usage: sbroadcast \nSends a message to all users on specific server(s)."); + registercontrolhelpcmd("cbroadcast", NO_OPER, 2, &controlcbroadcast, "Usage: sbroadcast <2 letter country> \nSends a message to all users in the specified country (GeoIP must be loaded) ."); } void _fini() { @@ -113,6 +117,8 @@ int controlresync(void *sender, int cargc, char **cargv) { return CMD_ERROR; } + controlwall(NO_OPER, NL_KICKS, "%s/%s RESYNC'ed %s", np->nick, np->authname, cp->index->name->content); + irc_send("%s CM %s o", mynumeric->content, cp->index->name->content); localsetmodeinit(&changes, cp, mynick); @@ -254,7 +260,7 @@ int controlsbroadcast(void *sender, int cargc, char **cargv) { if(cargc<2) return CMD_USAGE; - controlwall(NO_OPER, NL_BROADCASTS, "%s/%s sent a sbroadcast to %s: %s", np->nick, np->authname, cargv[0], cargv[1]); + controlwall(NO_OPER, NL_BROADCASTS, "%s/%s sent an sbroadcast to %s: %s", np->nick, np->authname, cargv[0], cargv[1]); irc_send("%s O $%s :(sBroadcast) %s", longtonumeric(mynick->numeric,5), cargv[0], cargv[1]); @@ -281,3 +287,41 @@ int controlobroadcast(void *sender, int cargc, char **cargv) { return CMD_OK; } + +const char GeoIP_country_code[247][3] = { "--","AP","EU","AD","AE","AF","AG","AI","AL","AM","AN","AO","AQ","AR","AS","AT","AU","AW","AZ","BA","BB","BD","BE","BF","BG","BH","BI","BJ","BM","BN","BO","BR","BS","BT","BV","BW","BY","BZ","CA","CC","CD","CF","CG","CH","CI","CK","CL","CM","CN","CO","CR","CU","CV","CX","CY","CZ","DE","DJ","DK","DM","DO","DZ","EC","EE","EG","EH","ER","ES","ET","FI","FJ","FK","FM","FO","FR","FX","GA","GB","GD","GE","GF","GH","GI","GL","GM","GN","GP","GQ","GR","GS","GT","GU","GW","GY","HK","HM","HN","HR","HT","HU","ID","IE","IL","IN","IO","IQ","IR","IS","IT","JM","JO","JP","KE","KG","KH","KI","KM","KN","KP","KR","KW","KY","KZ","LA","LB","LC","LI","LK","LR","LS","LT","LU","LV","LY","MA","MC","MD","MG","MH","MK","ML","MM","MN","MO","MP","MQ","MR","MS","MT","MU","MV","MW","MX","MY","MZ","NA","NC","NE","NF","NG","NI","NL","NO","NP","NR","NU","NZ","OM","PA","PE","PF","PG","PH","PK","PL","PM","PN","PR","PS","PT","PW","PY","QA","RE","RO","RU","RW","SA","SB","SC","SD","SE","SG","SH","SI","SJ","SK","SL","SM","SN","SO","SR","ST","SV","SY","SZ","TC","TD","TF","TG","TH","TJ","TK","TM","TN","TO","TP","TR","TT","TV","TW","TZ","UA","UG","UM","US","UY","UZ","VA","VC","VE","VG","VI","VN","VU","WF","WS","YE","YT","YU","ZA","ZM","ZR","ZW","A1","A2","O1"}; + +int controlcbroadcast(void *sender, int cargc, char **cargv) { + nick *np = (nick *)sender, *nip; + int i, ext, target; + + if(cargc < 2) + return CMD_USAGE; + + ext = findnickext("geoip"); + if(ext == -1) + controlreply(np, "Geoip module not loaded."); + + target = COUNTRY_MIN - 1; + for(i=COUNTRY_MIN;inick, np->authname, cargv[0], cargv[1]); + + for(i=0;inext) + if(nip && ((int)((long)nip->exts[ext]) == target)) + controlnotice(nip, "(cBroadcast) %s", cargv[1]); + + controlreply(np, "Message cbroadcasted."); + + return CMD_OK; +} diff --git a/nterface/Makefile b/nterface/Makefile index 6fea4e42..459e4749 100644 --- a/nterface/Makefile +++ b/nterface/Makefile @@ -14,7 +14,7 @@ nterfacer_relay.so: nterfacer_relay.o nterfacer_chanstats.so: nterfacer_chanstats.o ld -shared -Bdynamic -o $@ $^ -nterfacer_country.so: libGeoIP/GeoIP.o nterfacer_country.o +nterfacer_country.so: nterfacer_country.o ld -shared -Bdynamic -o $@ $^ nterfacer_spamscan2.so: nterfacer_spamscan2.o diff --git a/nterface/nterfacer_country.c b/nterface/nterfacer_country.c index f91893ab..5fe7dd1b 100644 --- a/nterface/nterfacer_country.c +++ b/nterface/nterfacer_country.c @@ -5,77 +5,36 @@ #include "../nick/nick.h" #include "../core/error.h" -#include "../core/config.h" -#include "../core/hooks.h" +#include "../geoip/geoip.h" #include "library.h" #include "nterfacer_control.h" -#include "libGeoIP/GeoIP.h" +int country_nickext = -1; struct handler *hl = NULL, *hl2 = NULL; -#define COUNTRY_MIN 0 -#define COUNTRY_MAX 246 - -unsigned int totals[COUNTRY_MAX + 1]; -int country_nickext = -1; -GeoIP *gi = NULL; - -void country_setupuser(nick *np); int handle_countrytotals(struct rline *li, int argc, char **argv); int handle_countrywhois(struct rline *li, int argc, char **argv); -void country_new_nick(int hook, void *args); -void country_quit(int hook, void *args); - void _init(void) { - int i; - nick *np; - sstring *filename; - if(!n_node) { Error("nterfacer_country", ERR_ERROR, "Unable to register country as nterfacer_control isn't loaded!"); return; } - filename = getcopyconfigitem("nterfacer", "geoipdb", "GeoIP.dat", 256); - gi = GeoIP_new(GEOIP_MEMORY_CACHE, filename->content); - freesstring(filename); - - if(!gi) - return; - - country_nickext = registernickext("nterfacer_country"); + country_nickext = findnickext("geoip"); if(country_nickext == -1) return; /* PPA: registerchanext produces an error, however the module should stop loading */ hl = register_handler(n_node, "countrytotals", 0, handle_countrytotals); hl2 = register_handler(n_node, "countrywhois", 1, handle_countrywhois); - memset(totals, 0, sizeof(totals)); - - for(i=0;inext) { - country_setupuser(np); - } - } - - registerhook(HOOK_NICK_LOSTNICK, &country_quit); - registerhook(HOOK_NICK_NEWNICK, &country_new_nick); } void _fini(void) { - if(gi) - GeoIP_delete(gi); - if(country_nickext == -1) return; - releasenickext(country_nickext); - - deregisterhook(HOOK_NICK_NEWNICK, &country_new_nick); - deregisterhook(HOOK_NICK_LOSTNICK, &country_quit); - if(hl2) deregister_handler(hl2); if(hl) @@ -85,33 +44,12 @@ void _fini(void) { int handle_countrytotals(struct rline *li, int argc, char **argv) { int i; for(i=COUNTRY_MIN;i<=COUNTRY_MAX;i++) - if(ri_append(li, "%d", totals[i]) == BF_OVER) + if(ri_append(li, "%d", geoip_totals[i]) == BF_OVER) return ri_error(li, BF_OVER, "Buffer overflow."); return ri_final(li); } -void country_setupuser(nick *np) { - int country = GeoIP_id_by_ipnum(gi, np->ipaddress); - if((country < COUNTRY_MIN) || (country > COUNTRY_MAX)) - return; - - totals[country]++; - np->exts[country_nickext] = (void *)&totals[country]; -} - -void country_new_nick(int hook, void *args) { - country_setupuser((nick *)args); -} - -void country_quit(int hook, void *args) { - nick *np = (nick *)args; - - unsigned int *item; - if((item = (unsigned int *)np->exts[country_nickext])) - (*item)--; -} - int handle_countrywhois(struct rline *li, int argc, char **argv) { int result; char *longcountry, *shortcountry, *shortcountry3; @@ -120,7 +58,7 @@ int handle_countrywhois(struct rline *li, int argc, char **argv) { if(!np) return ri_error(li, ERR_TARGET_NOT_FOUND, "User not online"); - result = GeoIP_id_by_ipnum(gi, np->ipaddress); + result = (int)((long)np->exts[country_nickext]); if((result < COUNTRY_MIN) || (result > COUNTRY_MAX)) result = -1;