Thread: [X2serv-cvs] CVS: x2/source commands.c,1.172,1.173 commands.h,1.26,1.27 config.h,1.68,1.69 parse.c,1
Brought to you by:
sirvulcan
From: Alex S. <ru...@us...> - 2003-02-17 08:58:52
|
Update of /cvsroot/x2serv/x2/source In directory sc8-pr-cvs1:/tmp/cvs-serv3399/source Modified Files: commands.c commands.h config.h parse.c server.c Log Message: This patch adds two features to help fight spam and abuse IP address range support in superglines: For the host part of the mask, use ip|ip as the range. No wildcards can be used with the range. spammer command: glines a spammer for 2 days, by nick, and logs their IP and advertizing details, so you can track them. Index: commands.c =================================================================== RCS file: /cvsroot/x2serv/x2/source/commands.c,v retrieving revision 1.172 retrieving revision 1.173 diff -C2 -r1.172 -r1.173 *** commands.c 13 Feb 2003 08:25:55 -0000 1.172 --- commands.c 17 Feb 2003 08:58:48 -0000 1.173 *************** *** 172,175 **** --- 172,176 ---- { "GLINE", c_gline, NONE, 0, 0, 0, T, T }, { "SGLINE", c_sgline, NONE, 0, 0, 0, T, T }, + { "SPAMMER", c_spammer, NONE, 0, 0, 0, T, T }, { "UNGLINE", c_ungline, NONE, 0, 0, 0, T, T }, { "UNSGLINE", c_unsgline, NONE, 0, 0, 0, T, T }, *************** *** 2107,2110 **** --- 2108,2155 ---- } + int c_spammer(C_PARAM) + { + char* nick; + char reason[MAXLEN]; + char* buff; + char Address[MAXLEN]; + char* IP; + UserListType target; + FILE *SPAMFILE; + + nick = (char *) mysep(&rest, " "); + if (!nick) + { + send_to_user(uptr, "\002Usage: SPAMMER <nick> <reason>\002"); + return(FALSE); + } + buff = (char *) mysep(&rest, "\0"); + if(!buff || !*buff) + buff = ""; + sprintf(reason, "(added by %s) We do not allow advertizing on AfterNET! (%s)\002", uptr->Nick, target->Nick); + if((target = FindNick(nick, UsersN))) + { + if (IsModeK(target)) + { + send_to_user(uptr, "\002Cannot spamsassanate a service!\002"); + return(FALSE); + } + IP = unsigned32ToDotQuad(target->IP); + sprintf(Address, "*@%s", IP); + send_gline(Address, 86400*2, "%s", reason); + ProcessAddGline(Address, 86400*2, reason); + if((SPAMFILE = fopen(SPAMFILENAME, "a"))) + { + fprintf(SPAMFILE, "%s - %s (%s!%s@%s) - [%s] %s\n", time2str(time(NULL)), IP, target->Nick, target->UserID, target->Address, buff, reason); + fclose(SPAMFILE); + } + return(TRUE); + } + else + { + send_to_user(uptr, "That user is not online. Check spelling and try again."); + return(FALSE); + } + } int c_unglineall(C_PARAM) Index: commands.h =================================================================== RCS file: /cvsroot/x2serv/x2/source/commands.h,v retrieving revision 1.26 retrieving revision 1.27 diff -C2 -r1.26 -r1.27 *** commands.h 25 Apr 2001 06:05:40 -0000 1.26 --- commands.h 17 Feb 2003 08:58:49 -0000 1.27 *************** *** 59,62 **** --- 59,63 ---- int c_gline(C_PARAM); int c_sgline(C_PARAM); + int c_spammer(C_PARAM); int c_unglineall(C_PARAM); int c_ungline(C_PARAM); Index: config.h =================================================================== RCS file: /cvsroot/x2serv/x2/source/config.h,v retrieving revision 1.68 retrieving revision 1.69 diff -C2 -r1.68 -r1.69 *** config.h 13 Feb 2003 09:18:06 -0000 1.68 --- config.h 17 Feb 2003 08:58:49 -0000 1.69 *************** *** 53,58 **** #define MESSAGEFILENAME "x2.news" /* this isnt working yet.. */ #define GATEFILENAME "wingate.log" /* detected wingates written to disk */ #define ProcFilePath "x2.pid" ! #define AccountingLog "accounting.log" /* Every command is logged */ #define ExpiredChanLog "expired.log" /* Log for expired Channels */ #define DefaultConfigFile "x2.conf" --- 53,59 ---- #define MESSAGEFILENAME "x2.news" /* this isnt working yet.. */ #define GATEFILENAME "wingate.log" /* detected wingates written to disk */ + #define SPAMFILENAME "spammer.log" /* logs from .spammer command */ #define ProcFilePath "x2.pid" ! #define AccountingLog "command.log" /* Every command is logged */ #define ExpiredChanLog "expired.log" /* Log for expired Channels */ #define DefaultConfigFile "x2.conf" Index: parse.c =================================================================== RCS file: /cvsroot/x2serv/x2/source/parse.c,v retrieving revision 1.74 retrieving revision 1.75 diff -C2 -r1.74 -r1.75 *** parse.c 25 Jan 2003 03:31:12 -0000 1.74 --- parse.c 17 Feb 2003 08:58:49 -0000 1.75 *************** *** 425,429 **** if(!NETBURSTING) SendMOTD(UserPtr); ! if(UserPtr) { char* dq = unsigned32ToDotQuad(IP); --- 425,429 ---- if(!NETBURSTING) SendMOTD(UserPtr); ! if(UserPtr) { char* dq = unsigned32ToDotQuad(IP); Index: server.c =================================================================== RCS file: /cvsroot/x2serv/x2/source/server.c,v retrieving revision 1.17 retrieving revision 1.18 diff -C2 -r1.17 -r1.18 *** server.c 6 Jun 2001 10:54:18 -0000 1.17 --- server.c 17 Feb 2003 08:58:49 -0000 1.18 *************** *** 95,117 **** { char uhr[MAXLEN]; GlineListType *gptr; char Address[MAXLEN]; char reason[MAXLEN]; if(UserPtr == NULL) ! return(FALSE); sprintf(uhr, "%s!%s@%s$%s", UserPtr->Nick, UserPtr->UserID, UserPtr->Address, UserPtr->RealName); ! gptr = SuperGlines; while(gptr) { ! if(!matches(gptr->address, uhr)) ! { ! sprintf(Address, "*@%s", IP); ! sprintf(reason, "Added automatically from SuperGline(%s)", gptr->reason); ! send_gline(Address, 3600, "%s", reason); ! ProcessAddGline(Address, 3600, reason); ! return(TRUE); ! } gptr = gptr->Next; } --- 95,169 ---- { char uhr[MAXLEN]; + char ur[MAXLEN]; GlineListType *gptr; char Address[MAXLEN]; char reason[MAXLEN]; + Debug(DBGINFO, "Starting SuperGlineCheck"); if(UserPtr == NULL) ! return(FALSE); sprintf(uhr, "%s!%s@%s$%s", UserPtr->Nick, UserPtr->UserID, UserPtr->Address, UserPtr->RealName); ! sprintf(ur, "%s!%s@$%s", UserPtr->Nick, UserPtr->UserID, UserPtr->RealName); gptr = SuperGlines; while(gptr) { ! if(strchr(gptr->address, '|') && (strchr(gptr->address, '$') == NULL || strchr(gptr->address, '|') < strchr(gptr->address, '$'))) ! { ! /* the sgline has an ip range for a host. */ ! char *ip, *buff; ! unsigned long int rangestart, rangeend; ! char addy[MAXLEN]; ! char *a = addy; ! ! Debug(DBGINFO, "Testing %s versus %s", gptr->address, ur); ! strcpy(addy, gptr->address); ! buff = (char *) mysep(&a, "@"); ! buff = mysep(&a, "$"); ! if(!buff) ! return(FALSE); ! /* now buff is the host part only */ ! ip = mysep(&buff, "|"); ! rangestart = ntohl(inet_addr(ip)); ! if(rangestart == 0) ! return(FALSE); ! ip = mysep(&buff, "|"); ! rangeend = ntohl(inet_addr(ip)); ! if(rangeend == 0) ! return(FALSE); ! /* now rangestart and rangeend have our ranges.. */ ! if(UserPtr->IP >= rangestart && UserPtr->IP <= rangeend) ! { ! char *begin,*end ; ! char urbuff[MAXLEN]; ! /* Now match the rest; build an address without host part. */ ! strcpy(a, gptr->address); ! begin = mysep(&a, "@"); ! end = mysep(&a, "$"); ! end = mysep(&a, "|"); ! ! if(!begin || !end) ! return(FALSE); ! sprintf(urbuff, "%s@$%s", begin, end); ! if(!matches(urbuff, ur)) ! { ! sprintf(Address, "*@%s", IP); ! sprintf(reason, "Added automatically from SuperGline(%s)", gptr->reason); ! send_gline(Address, 3600, "%s", reason); ! ProcessAddGline(Address, 3600, reason); ! return(TRUE); ! } ! } ! } ! else ! { ! if(!matches(gptr->address, uhr)) ! { ! sprintf(Address, "*@%s", IP); ! sprintf(reason, "Added automatically from SuperGline(%s)", gptr->reason); ! send_gline(Address, 3600, "%s", reason); ! ProcessAddGline(Address, 3600, reason); ! return(TRUE); ! } ! } gptr = gptr->Next; } |