Thread: [X2serv-cvs] [CVS] Module x2: Change committed (Page 2)
Brought to you by:
sirvulcan
From: Reed L. <r3...@us...> - 2004-06-28 21:46:42
|
Committer : Reed Loden <r3...@us...> CVSROOT : /cvsroot/x2serv Module : x2 Commit time: 2004-06-28 21:46:33 UTC Modified files: source/parse.c source/send.c Log message: Fixed problem with X2 not recognizing numerics. Corrected some commands that had not had their syntax changed over to new P10. ---------------------- diff included ---------------------- Index: x2/source/parse.c diff -u x2/source/parse.c:1.89 x2/source/parse.c:1.90 --- x2/source/parse.c:1.89 Sat Jun 26 14:02:16 2004 +++ x2/source/parse.c Mon Jun 28 14:46:22 2004 @@ -97,9 +97,6 @@ { "FA", m_fakehost, TRUE, FALSE }, { "OM", m_noop, TRUE, TRUE }, { "CM", m_noop, TRUE, TRUE }, - { "401", m_logerror, TRUE, TRUE }, - { "402", m_logerror, TRUE, TRUE }, - { "443", m_logerror, TRUE, TRUE }, /* user is already on channel (invite attempt error) */ { NULL, NULL, FALSE, FALSE } }; /* *INDENT-ON* */ @@ -1570,6 +1567,21 @@ if((strlen(Sender) > 2) && !(UserPtr = FindNumnick(Sender, UsersU))) Debug(DBGINFO, "Sender %s not found", Sender); +/*** Check if maybe its a numeric ***/ + if(isdigit(Command[0]) && ServerPtr) /* If first letter is a number and a server sent it.. */ + { + int num = 0; + if((num = atoi(Command))) /* if num is non zero.. */ + { + char* target; + UserListType TmpUserPtr; + target = (char *) strtok(rest, " "); + rest = (char *) strtok(NULL, "\r\n"); + TmpUserPtr = FindNumnick(target, UsersU); + ProcessNumeric(ServerPtr, num, TmpUserPtr, rest); + return(0); + } + } for(i=0;server_commands[i].name;i++) { if(!strcasecmp(server_commands[i].name, Command)) Index: x2/source/send.c diff -u x2/source/send.c:1.38 x2/source/send.c:1.39 --- x2/source/send.c:1.38 Sat Jun 26 14:02:16 2004 +++ x2/source/send.c Mon Jun 28 14:46:23 2004 @@ -138,7 +138,8 @@ * returns the status, not our uplink. This is important * for getting good away status. */ - send_command_from_nick("W %s :%s", uptr->Numnick[0], uptr->Nick); + send_command_from_nick("W %c%c :%s", uptr->Numnick[0], + uptr->Numnick[1], uptr->Nick); } void send_chanmode(ChannelListType cptr, char *format, ...) @@ -538,7 +539,7 @@ { TempChanPtr->NumOfNicks++; /* Note that we joined the channel */ sendtosock(Sock, "%s B %s %lu %s:o", - convert2y[ServiceNumeric], /* servers numnick */ + ServNum, /* servers numnick */ TempChanPtr->Name, /* #channel */ TempChanPtr->CreationDate, /* Hopefully already set by other side BURST */ NumNick); /* My nick is joining, and had ops.. */ ----------------------- End of diff ----------------------- |
From: Alex S. <ru...@us...> - 2004-07-02 15:34:41
|
Committer : Alex Schumann <ru...@us...> CVSROOT : /cvsroot/x2serv Module : x2 Commit time: 2004-07-02 15:34:34 UTC Added files: conf/x2.news.example Removed files: conf/x2.news Log message: sick of forgetting to delete the news file. changing it to an example ---------------------- diff included ---------------------- Index: x2/conf/x2.news diff -u x2/conf/x2.news:1.2 x2/conf/x2.news:removed --- x2/conf/x2.news:1.2 Sun Oct 26 13:17:36 2003 +++ x2/conf/x2.news Fri Jul 2 08:34:35 2004 @@ -1,17 +0,0 @@ - A note from The X2 Author: --------------------------------- -Your network has recently upgraded -to X2 version 5.2! Congratulations! -This news file is displayed once to -every manager, owner, or coowner in -every channel. It can be used to -educate about new features, bugs, or -other cservice related events. You -can read the news at any time with -the NEWS command. -Please let your X2 operator know they -can change this news file by editing -x2.news in the main X2 5.2 directory. -Thanks, - -Rubin (ru...@af...) - X2 author/maintainer Index: x2/conf/x2.news.example diff -u /dev/null x2/conf/x2.news.example:1.1 --- /dev/null Fri Jul 2 08:34:35 2004 +++ x2/conf/x2.news.example Fri Jul 2 08:34:24 2004 @@ -0,0 +1,17 @@ + A note from The X2 Author: +-------------------------------- +Your network has recently upgraded +to X2 version 5.2! Congratulations! +This news file is displayed once to +every manager, owner, or coowner in +every channel. It can be used to +educate about new features, bugs, or +other cservice related events. You +can read the news at any time with +the NEWS command. +Please let your X2 operator know they +can change this news file by editing +x2.news in the main X2 5.2 directory. +Thanks, + -Rubin (ru...@af...) + X2 author/maintainer ----------------------- End of diff ----------------------- |
From: Alex S. <ru...@us...> - 2004-07-04 18:18:41
|
Committer : Alex Schumann <ru...@us...> CVSROOT : /cvsroot/x2serv Module : x2 Commit time: 2004-07-04 17:03:20 UTC Modified files: source/send.c source/send.h source/server.c Log message: Passing char to %s causes core files - go figure ;) CheckGline() updated to handle double-char numerics and not to crash.. ---------------------- diff included ---------------------- Index: x2/source/send.c diff -u x2/source/send.c:1.39 x2/source/send.c:1.40 --- x2/source/send.c:1.39 Mon Jun 28 14:46:23 2004 +++ x2/source/send.c Sun Jul 4 10:03:09 2004 @@ -223,7 +223,7 @@ send_command_from_server("GL * +%s %lu :%s", mask, duration, buff); } -void send_gline_to_server(char num, char *mask, time_t duration, char *format, ...) +void send_gline_to_server(char num1, char num2, char *mask, time_t duration, char *format, ...) { va_list args; char buff[LINEBUFFSIZE]; @@ -232,7 +232,7 @@ vsprintf(buff, format, args); va_end(args); - send_command_from_server("GL %s +%s %lu :%s", num, mask, duration, buff); + send_command_from_server("GL %c%c +%s %lu :%s", num1, num2, mask, duration, buff); } void send_ungline(char *mask) Index: x2/source/send.h diff -u x2/source/send.h:1.12 x2/source/send.h:1.13 --- x2/source/send.h:1.12 Mon Feb 4 01:55:46 2002 +++ x2/source/send.h Sun Jul 4 10:03:09 2004 @@ -18,7 +18,7 @@ void send_wallchops(ChannelListType cptr, char *format, ...); void send_kill(UserListType uptr, char *format, ...); void send_gline(char *mask, time_t duration, char *format, ...); -void send_gline_to_server(char num, char *mask, time_t duration, char *format, ...); +void send_gline_to_server(char num1, char num2, char *mask, time_t duration, char *format, ...); void send_ungline(char *mask); void send_settime(time_t thetime); void send_opchan(ChannelListType cptr); Index: x2/source/server.c diff -u x2/source/server.c:1.23 x2/source/server.c:1.24 --- x2/source/server.c:1.23 Wed Jun 9 16:40:31 2004 +++ x2/source/server.c Sun Jul 4 10:03:09 2004 @@ -83,7 +83,7 @@ { if(!matches(gptr->address, uhr) && gptr->time > NetTime()) { - send_gline_to_server(UserPtr->Numnick[0], gptr->address, gptr->time - NetTime(), "%s", gptr->reason); + send_gline_to_server(UserPtr->Numnick[0],UserPtr->Numnick[1], gptr->address, gptr->time - NetTime(), "%s", gptr->reason); return(TRUE); } gptr = gptr->Next; ----------------------- End of diff ----------------------- |
From: Alex S. <ru...@us...> - 2004-07-05 02:53:50
|
Committer : Alex Schumann <ru...@us...> CVSROOT : /cvsroot/x2serv Module : x2 Commit time: 2004-07-04 20:42:29 UTC Modified files: source/accounting.c source/chan.c source/commands.c source/config.h source/help.c source/main.c source/misc.c source/misc.h source/parse.c source/parse.h source/route.c source/set.c source/set.h Log message: Removed c++ style comments and fixed -Wall -pedantec warnings Added support for halfops and ban exceptions (+h and +e channel modes) (by support i mean - doesnt puke .. it doesnt do anything with them either) ---------------------- diff included ---------------------- Index: x2/source/accounting.c diff -u x2/source/accounting.c:1.9 x2/source/accounting.c:1.10 --- x2/source/accounting.c:1.9 Thu Mar 15 17:52:58 2001 +++ x2/source/accounting.c Sun Jul 4 13:42:18 2004 @@ -16,8 +16,9 @@ char* myrest; char* datestr; char *gmode; - // time_t mystart, myend; -// Debug(DBGINFO, "Examining: %s", LogLine); + /* time_t mystart, myend; + *Debug(DBGINFO, "Examining: %s", LogLine); + */ datestr = (char *) mysep(&LogLine, "]"); mychan = (char *) mysep(&LogLine, " "); @@ -28,7 +29,7 @@ if(!mycommand) { - //Debug(DBGINFO, "Invalid line in log input."); + /*Debug(DBGINFO, "Invalid line in log input."); */ return(0); } /* @@ -118,8 +119,9 @@ if(first) strcat(LogLine, PrevBuff); first = 0; - // Debug(DBGINFO, "LOGLINE: %s", LogLine); - // send_to_user(uptr, "LOGLINE: %s", LogLine); + /* Debug(DBGINFO, "LOGLINE: %s", LogLine); + * send_to_user(uptr, "LOGLINE: %s", LogLine); + */ searchline++; if(parselog(LogLine, uptr, cptr, chan, nuh, command, rest, start, end)) line++; Index: x2/source/chan.c diff -u x2/source/chan.c:1.89 x2/source/chan.c:1.90 --- x2/source/chan.c:1.89 Wed Jun 9 16:40:31 2004 +++ x2/source/chan.c Sun Jul 4 13:42:18 2004 @@ -367,6 +367,22 @@ return (false); } +boolean IsDehalfop(char *Modes) +{ + char Operator = '+'; + int Len, i; + + Len = strlen(Modes); + for (i = 0; i < Len; i++) + { + if (Modes[i] == '-') + Operator = '-'; + if ((Modes[i] == 'h') && (Operator == '-')) + return (true); + } + return (false); +} + boolean IsBan(char *Modes) { char Operator = '+'; @@ -385,6 +401,24 @@ return (false); } +boolean IsBanexamption(char *Modes) +{ + char Operator = '+'; + int Len, i; + + Len = strlen(Modes); + for (i = 0; i < Len; i++) + { + if (Modes[i] == '-') + Operator = '-'; + if (Modes[i] == '+') + Operator = '+'; + if ((Modes[i] == 'e') && (Operator == '+')) + return (true); + } + return (false); +} + void ProcessKick(ChannelListType cptr, UserListType uptr, char *Kicked) { UserListType kptr; @@ -504,6 +538,46 @@ } break; } + case 'h': + { + UserListType hptr; + numnick = (char *) strtok(params, " "); + params = (char *) strtok(NULL, "\0\n"); + if (!numnick) + break; + if (IsModeK(uptr)) + break; +/* server can do modes.. hmm. + if (GetServer(uptr)) + break; +*/ + hptr = FindNumnick(numnick, UsersU); + if (sign == '+') + { + /* Do checks if we should remove the o */ + if (!halfopok(cptr, uptr, hptr)) + { + strcat(unminmode, "h"); + strcat(unminparams, numnick); + strcat(unminparams, " "); + did_change = TRUE; + } + } + else + /* sign == '-' */ + { + /* Do checks if we should give back the o */ + if (!dehalfopok(cptr, uptr, hptr)) + { + strcat(unplusmode, "h"); + strcat(unplusparams, numnick); + strcat(unplusparams, " "); + did_change = TRUE; + punish(cptr, uptr, hptr, 'h'); + } + } + break; + } case 'b': banstring = (char *) strtok(params, " "); params = (char *) strtok(NULL, "\0\n"); @@ -518,7 +592,7 @@ strcat(unminparams, banstring); strcat(unminparams, " "); did_change = TRUE; -// punish(cptr, uptr, banstring, 'b'); +/* punish(cptr, uptr, banstring, 'b'); */ break; } add_ban(cptr, banstring); @@ -536,13 +610,14 @@ break; if (sign == '+') { -// if (!IsModeK(uptr)) /* If its not a service doing it */ -// add_exempt(cptr, exemptstring); +/* if (!IsModeK(uptr)) * If its not a service doing it + * add_exempt(cptr, exemptstring); + */ } else /* sign == '-' */ { - //delete_exempt(cptr, exemptstring); + /*delete_exempt(cptr, exemptstring); */ } break; case 'v': Index: x2/source/commands.c diff -u x2/source/commands.c:1.183 x2/source/commands.c:1.184 --- x2/source/commands.c:1.183 Sat Jun 26 14:02:15 2004 +++ x2/source/commands.c Sun Jul 4 13:42:18 2004 @@ -44,6 +44,7 @@ #include "parse.h" #include "accounting.h" #include "help.h" +#include "set.h" int FILTER = 0; char LISTTYPE = '\0'; @@ -842,6 +843,7 @@ Debug(DBGWARNING, "c_god(): null user"); return(FALSE); } + return(FALSE); } int c_whoami(C_PARAM) @@ -1241,7 +1243,6 @@ { char* handle; char* password; - char seed[14]; AuthHandleListType ahptr; if(!rest || !*rest) @@ -1305,7 +1306,6 @@ char* handle; char* password; char* channel; - char seed[14]; int OK; AuthHandleListType ahptr; @@ -1526,8 +1526,9 @@ return(FALSE); } rest = getscflags(rest, &secret, &nodelete, &noinchan, &suspended, &noowner, &total); -// send_to_user(uptr, "secret=%d, nodelete=%d, noinchan=%d, suspended=%d, total=%d :%s", -// secret, nodelete, noinchan, suspended, total, rest); +/* send_to_user(uptr, "secret=%d, nodelete=%d, noinchan=%d, suspended=%d, total=%d :%s", + * secret, nodelete, noinchan, suspended, total, rest); + */ count = 0; chansearch = (char *) strtok(rest, " "); if(!chansearch) @@ -1843,7 +1844,6 @@ int c_access(C_PARAM) { UserListType target; - char level[10] = ""; if (!strcmp(rest, "")) { target = uptr; @@ -2456,7 +2456,6 @@ char timestring[LINEBUFFSIZE]; time_t GoneTime; int OwnerNumber = 0, CoOwnerNumber = 0, ManagerNumber = 0, OpNumber = 0, PeonNumber = 0, LamerNumber = 0; - int k; if(cptr->Regged == FALSE) { @@ -3091,8 +3090,6 @@ int c_settings(C_PARAM) { - time_t UpTime; - ShowXSet(uptr); #ifdef NOTDEF UpTime = time(NULL) - StartTime; Index: x2/source/config.h diff -u x2/source/config.h:1.77 x2/source/config.h:1.78 --- x2/source/config.h:1.77 Wed Jun 9 16:40:31 2004 +++ x2/source/config.h Sun Jul 4 13:42:19 2004 @@ -17,7 +17,7 @@ #include <time.h> /* If your system doesnt have this, try commenting it out. */ -//#include <crypt.h> +/*#include <crypt.h>*/ /* If there are problems and you want all X2 output to go to x2.debug, define * this. Note that it gets very big, very fast... @@ -68,7 +68,7 @@ /* Uncomment the following for debugging. */ -/* #define debugon */ + #define debugon /* If you dont want the word warez in channel names, define this. * TODO : This is a hack, and would do better in a config file. Do it! Index: x2/source/help.c diff -u x2/source/help.c:1.2 x2/source/help.c:1.3 --- x2/source/help.c:1.2 Wed Jun 9 16:33:03 2004 +++ x2/source/help.c Sun Jul 4 13:42:19 2004 @@ -1,4 +1,5 @@ #include "config.h" +#include "send.h" int HelpSub(char *Target, char *Source) { Index: x2/source/main.c diff -u x2/source/main.c:1.61 x2/source/main.c:1.62 --- x2/source/main.c:1.61 Tue Mar 16 20:43:03 2004 +++ x2/source/main.c Sun Jul 4 13:42:19 2004 @@ -684,7 +684,7 @@ } fclose(OpFile); } -// fclose(OpFile); +/* fclose(OpFile); */ fclose(TheFile); Debug(DBGNOTICE, ":Finished reading channel data files\n"); return (1); @@ -897,8 +897,9 @@ #ifdef debugon perror("SELECT"); #endif - //Debug(DBGSEVERE, "select returned -1. Errno:%d", errno); - //exit(1); profiling causes "Interrupted System Call" here.. + /*Debug(DBGSEVERE, "select returned -1. Errno:%d", errno); + *exit(1); profiling causes "Interrupted System Call" here.. + */ } if(c > 0) /* Incomming data */ { Index: x2/source/misc.c diff -u x2/source/misc.c:1.50 x2/source/misc.c:1.51 --- x2/source/misc.c:1.50 Sat Jun 14 13:24:18 2003 +++ x2/source/misc.c Sun Jul 4 13:42:19 2004 @@ -327,7 +327,6 @@ void LogAccess(UserListType uptr, char* item, int size) { FILE* LOGFILE; - char buff[MAXLEN*4]; if(strcmp(AccessLog, "none")) { @@ -345,7 +344,6 @@ { FILE* LOGFILE; char buff[MAXLEN*4]; - int hidepass = 0; /* global nick!user@host command rest [time] */ /* #channel nick!user@host GOD command rest [time] */ if( ! (strcasecmp(command, "LOGIN") && @@ -518,6 +516,32 @@ } } +int halfopok(ChannelListType ChanPtr, UserListType uptr, UserListType optr) +{ + /* Check if its ok for user from to op user to given settings */ + if(uptr == NULL) + return(TRUE); /* No user.. must be a server */ + switch (ChanPtr->settings[STRICTOP]) + { + case 0: /* anyone */ + return (TRUE); + case 1: /* Ops Managers & (CO)Owners only */ + if (userlevel2(optr, FindBestUserMatch(ChanPtr, optr)) >= OP) + return (TRUE); + if (userlevel2(uptr, FindBestUserMatch(ChanPtr, uptr)) >= OP) + return (TRUE); + return (FALSE); + case 2: /* Managers & (co)owners */ + if (userlevel2(optr, FindBestUserMatch(ChanPtr, optr)) >= OP) + return (TRUE); + if (userlevel2(uptr, FindBestUserMatch(ChanPtr, uptr)) >= MA) + return (TRUE); + return (FALSE); + default: + return (TRUE); + } +} + int deopok(ChannelListType ChanPtr, UserListType from, UserListType to) { int fromlev, tolev; @@ -564,6 +588,52 @@ } } +int dehalfopok(ChannelListType ChanPtr, UserListType from, UserListType to) +{ + int fromlev, tolev; + + if(from == NULL) + return(TRUE); /* no from, must be server */ + if(from == to) /* Mode done to self. */ + { + return(TRUE); + } + fromlev = userlevel2(from, FindBestUserMatch(ChanPtr, from)); + tolev = userlevel2(to, FindBestUserMatch(ChanPtr, to)); + /* Check if its ok for user from to deop user to given settings */ + switch (ChanPtr->settings[PROTECT]) + { + case 0: /* Noone from anyone */ + return (TRUE); + case 1: /* Higher rank from lower rank */ + if (tolev < OP) + return (TRUE); + if (fromlev < tolev) + return (FALSE); + return (TRUE); + case 2: /* Equal or higher rank */ + if (tolev < OP) + return (TRUE); + if (fromlev <= tolev) + return (FALSE); + return (TRUE); + case 3: /* Managers & owners from everyone */ + if (tolev < MA) + return (TRUE); + if (fromlev <= tolev) + return (FALSE); + return (TRUE); + case 4: /* Owners from everyone */ + if (tolev < CO) + return (TRUE); + if (fromlev < tolev) + return (FALSE); + return (TRUE); + default: + return (TRUE); + } +} + int kickok(ChannelListType ChanPtr, UserListType from, UserListType to) { int fromlev, tolev; @@ -1382,8 +1452,9 @@ len = strlen(Address); -// if ((!isalpha(Address[0])) && (Address[0] != '*') && (Address[0] != '?')) -// return (0); +/* if ((!isalpha(Address[0])) && (Address[0] != '*') && (Address[0] != '?')) + * return (0); + */ if (Address[0] == '*') { gotstar = true; @@ -1401,9 +1472,10 @@ gotstar = true; else { -// Why are we not allowing * before @??? -// if (!gotat) -// return (false); +/* Why are we not allowing * before @??? + * if (!gotat) + * return (false); + */ } } else if (Address[i] == '!') Index: x2/source/misc.h diff -u x2/source/misc.h:1.19 x2/source/misc.h:1.20 --- x2/source/misc.h:1.19 Tue Dec 12 20:45:11 2000 +++ x2/source/misc.h Sun Jul 4 13:42:19 2004 @@ -22,6 +22,8 @@ int isinchan(ChannelListType cptr, UserListType uptr); int opok(ChannelListType ChanPtr, UserListType uptr, UserListType optr); int deopok(ChannelListType ChanPtr, UserListType from, UserListType to); +int halfopok(ChannelListType ChanPtr, UserListType uptr, UserListType optr); +int dehalfopok(ChannelListType ChanPtr, UserListType from, UserListType to); int kickok(ChannelListType ChanPtr, UserListType from, UserListType to); int modeok(ChannelListType ChanPtr, UserListType from); int banok(ChannelListType ChanPtr, UserListType from, char* mask); @@ -67,3 +69,5 @@ void do_math(char *buff, char *math); unsigned long Hash(char *str); unsigned int base64toint(const char *s); +const char* inttobase64(char* buf, unsigned int v, unsigned int count); +void LogAccess(UserListType uptr, char* item, int size); Index: x2/source/parse.c diff -u x2/source/parse.c:1.90 x2/source/parse.c:1.91 --- x2/source/parse.c:1.90 Mon Jun 28 14:46:22 2004 +++ x2/source/parse.c Sun Jul 4 13:42:19 2004 @@ -361,10 +361,10 @@ } case '%': /* burst ban list */ { -// ChannelListType ChanPtr; +/* ChannelListType ChanPtr; */ char* ban; -// if(!(ChanPtr = GetChannel(channel))) -// return(0); /* Not a channel we are in */ +/* if(!(ChanPtr = GetChannel(channel))) */ +/* return(0); * Not a channel we are in */ parm++; /* Ignore % */ for( ban = parm; /* ban = first ban */ ban; /* while ban != null */ @@ -405,7 +405,7 @@ int m_nick(M_PARAMS) { char* Arg[9]; - char* modes, *account, *sethost, *fakehost, *modef; + char* modes, *account, *sethost, *fakehost; UserListType UserPtr; unsigned int IP; Index: x2/source/parse.h diff -u x2/source/parse.h:1.14 x2/source/parse.h:1.15 --- x2/source/parse.h:1.14 Sat Jun 26 14:02:16 2004 +++ x2/source/parse.h Sun Jul 4 13:42:19 2004 @@ -1,5 +1,6 @@ int ProcessCommand(UserListType from, char *to, char *rest); int ProcessCTCP(UserListType from, char *to, char *rest); +int ProcessCTCPReply(UserListType from, char *to, char *rest); int ReadSocket(int TheSocket, char *Buffer); /* m_functions */ Index: x2/source/route.c diff -u x2/source/route.c:1.13 x2/source/route.c:1.14 --- x2/source/route.c:1.13 Sat Jun 14 13:48:56 2003 +++ x2/source/route.c Sun Jul 4 13:42:19 2004 @@ -97,7 +97,7 @@ ChangeRouteUplinks(Route); } } - //RankOutsideNess(Route); + /*RankOutsideNess(Route); */ } void WipeRouteList(RouteType Route) @@ -158,7 +158,7 @@ while(rptr) { strcpy(nextserver, rptr->uplink); /* next step in the trail */ - //strcpy(lastserver, rptr->server); + /*strcpy(lastserver, rptr->server); */ Debug(DBGINFO, "ChangeRouteUplinks(): Changing %s uplink to %s", rptr->server, lastserver); free(rptr->uplink); @@ -361,7 +361,7 @@ { if(rptr->outsideness == i) { - //send_to_user(uptr, "Inspecting server [%s]", rptr->server); + /*send_to_user(uptr, "Inspecting server [%s]", rptr->server); */ suptr = GetServer(rptr->uplink); if(!suptr) { Index: x2/source/set.c diff -u x2/source/set.c:1.7 x2/source/set.c:1.8 --- x2/source/set.c:1.7 Wed Jun 9 16:33:03 2004 +++ x2/source/set.c Sun Jul 4 13:42:19 2004 @@ -2,6 +2,10 @@ #include "commands.h" #include "set.h" #include "ctype.h" +#include "send.h" +#include "chan.h" +#include "user.h" +#include "misc.h" set_list set_commands[NUMOFCHANSETTINGS+1] = /* Command index level user num default description short set0 set1 set2 set3 set4 set5 */ @@ -383,7 +387,7 @@ { char ModeString[LINEBUFFSIZE]; char *option, *param; - int i, j, value; + int i, value; option = strtok(rest, " "); param = strtok(NULL, "\n"); @@ -535,6 +539,7 @@ } PINGOUTCONNECT = Val; send_wallops("PINGOUTCONNECT set to %s by %s.", GetSetting(PINGOUTCONNECT), uptr); + return(TRUE); } int xs_autorouting(UserListType uptr, char *param) @@ -552,6 +557,7 @@ } AUTOROUTING = Val; send_wallops("AUTOROUTING set to %s by %s.", GetSetting(AUTOROUTING), uptr->Nick); + return(TRUE); } int xs_autoconnect(UserListType uptr, char *param) @@ -569,6 +575,7 @@ } AUTOCONNECT = Val; send_wallops("AUTOCONNECT %s by %s.", GetSetting(AUTOCONNECT), uptr->Nick); + return(TRUE); } int xs_sub7scan(UserListType uptr, char *param) @@ -586,6 +593,7 @@ } SUB7SCAN = Val; send_wallops("SUB7SCAN set to %d by %s.", SUB7SCAN, uptr->Nick); + return(TRUE); } int xs_litmus(UserListType uptr, char *param) { @@ -602,6 +610,7 @@ } LITMUS = Val; send_wallops("LITMUS set to %d by %s.", LITMUS, uptr->Nick); + return(TRUE); } int xs_sdbot(UserListType uptr, char*param) @@ -619,6 +628,7 @@ } SDBOT = Val; send_wallops("SDBOT set to %d by %s.", SDBOT, uptr->Nick); + return(TRUE); } int xs_gatecheck(UserListType uptr, char *param) @@ -636,6 +646,7 @@ } GATECHECK = Val; send_wallops("GATECHECK set to %d by %s.", GATECHECK, uptr->Nick); + return(TRUE); } int xs_maxclones(UserListType uptr, char *param) @@ -653,6 +664,7 @@ } MAXCLONES = Val; send_wallops("MAXCLONES set to %d by %s.", MAXCLONES, uptr->Nick); + return(TRUE); } int xs_cloneres(UserListType uptr, char *param) @@ -670,6 +682,7 @@ } CLONERES = Val; send_wallops("CLONERES set to %s by %s.", GetCloneResMet(CLONERES), uptr->Nick); + return(TRUE); } int xs_debug(UserListType uptr, char *param) @@ -704,7 +717,6 @@ int do_xset(C_PARAM) { char *Option, *param; - int Val; int i; Option = strtok(rest, " "); Index: x2/source/set.h diff -u x2/source/set.h:1.3 x2/source/set.h:1.4 --- x2/source/set.h:1.3 Sun Sep 15 00:41:12 2002 +++ x2/source/set.h Sun Jul 4 13:42:19 2004 @@ -18,3 +18,4 @@ int do_set(C_PARAM); int do_xset(C_PARAM); +void ShowXSet(UserListType uptr); ----------------------- End of diff ----------------------- |
From: Alex S. <ru...@us...> - 2004-07-05 08:12:32
|
Committer : Alex Schumann <ru...@us...> CVSROOT : /cvsroot/x2serv Module : x2 Commit time: 2004-07-05 08:12:25 UTC Modified files: source/parse.c Log message: Fixed +e burst parsing ---------------------- diff included ---------------------- Index: x2/source/parse.c diff -u x2/source/parse.c:1.91 x2/source/parse.c:1.92 --- x2/source/parse.c:1.91 Sun Jul 4 13:42:19 2004 +++ x2/source/parse.c Mon Jul 5 01:12:14 2004 @@ -361,6 +361,7 @@ } case '%': /* burst ban list */ { + int bore = 0; /* 0=ban, 1=exempt */ /* ChannelListType ChanPtr; */ char* ban; /* if(!(ChanPtr = GetChannel(channel))) */ @@ -371,7 +372,19 @@ ban = (char *) mysep(&rest, " ") /* Get next ban from outside stack */ ) { - add_ban(ChanPtr, ban); + if(ban[0]=='~') /* If we encounter a ~ its sirvulcans exempt marker. rest are exempts */ + { /* and ignore this one as its just a ~ */ + bore = 1; + ban++; + } + if(ban[0]) /* If the aboe ~ check didnt end the string.. */ + { + if(bore == 0) /* ban */ + add_ban(ChanPtr, ban); + /* else ** TODO: Add exempt functions and uncomment this ** + add_exempt(ChanPtr, ban); + */ + } } break; } @@ -1501,7 +1514,10 @@ } for(i = 0; i < SERVNUMLEN - 1; i++) + { numnick[i] = Arg[6][i]; + } + numnick[i] = '\0'; Debug(DBGINFO, "Adding server %s %s %s", Arg[1], ServiceName, numnick); AddServer(Arg[1], ServiceName, numnick); NETBURSTING = TRUE; /* Ignore incomming users for a while*/ ----------------------- End of diff ----------------------- |
From: Alex S. <ru...@us...> - 2004-08-22 19:11:04
|
Committer : Alex Schumann <ru...@us...> CVSROOT : /cvsroot/x2serv Module : x2 Commit time: 2004-08-22 19:10:53 UTC Modified files: source/commands.c source/config.h Log message: Removed server from ircops ---------------------- diff included ---------------------- Index: x2/source/commands.c diff -u x2/source/commands.c:1.184 x2/source/commands.c:1.185 --- x2/source/commands.c:1.184 Sun Jul 4 13:42:18 2004 +++ x2/source/commands.c Sun Aug 22 12:10:42 2004 @@ -103,9 +103,11 @@ { "DISCONNECT",c_disconnect, NONE, 0, 0, 0, T, F }, { "NETSTAT", c_netstat, NONE, 0, 0, 0, F, T }, { "NETSTATS", c_netstat, NONE, 0, 0, 0, F, T }, +/* not safe to show this anymore :( { "SERVERS", c_servers, NONE, 0, 0, 0, F, T }, { "LINKS", c_servers, NONE, 0, 0, 0, F, T }, { "MAP", c_map, NONE, 0, 0, 0, F, T }, +*/ { "RMAP", c_rmap, NONE, 0, 0, 0, T, T }, { "RLIST", c_rlist, NONE, 0, 0, 0, T, T }, { "ADDR", c_addr, NONE, 0, 0, 0, T, T }, @@ -4167,11 +4169,11 @@ { count++; if(ListPtr->Modes & UMODEaway) - send_to_user(uptr, "%16s : %s \002(Away)\002", - ListPtr->Nick, ListPtr->Serv); + send_to_user(uptr, "%16s : \002(Away)\002", + ListPtr->Nick); else - send_to_user(uptr, "\002%16s : %s\002", - ListPtr->Nick, ListPtr->Serv); + send_to_user(uptr, "\002%16s\002", + ListPtr->Nick); } } ListPtr = ListPtr->NextN; Index: x2/source/config.h diff -u x2/source/config.h:1.78 x2/source/config.h:1.79 --- x2/source/config.h:1.78 Sun Jul 4 13:42:19 2004 +++ x2/source/config.h Sun Aug 22 12:10:42 2004 @@ -68,7 +68,7 @@ /* Uncomment the following for debugging. */ - #define debugon +/* #define debugon */ /* If you dont want the word warez in channel names, define this. * TODO : This is a hack, and would do better in a config file. Do it! ----------------------- End of diff ----------------------- |
From: Alex S. <ru...@us...> - 2004-08-23 15:26:09
|
Committer : Alex Schumann <ru...@us...> CVSROOT : /cvsroot/x2serv Module : x2 Commit time: 2004-08-23 15:25:59 UTC Modified files: Makefile.in source/chan.c source/commands.c source/config.h source/misc.c source/misc.h source/parse.c source/parse.h source/user.c source/user.h Log message: Added (proper) support for hidden hosts, fakehosts, and sethosts. They are considered in lamer, ban and access functions, and available in the WHOIS command. ---------------------- diff included ---------------------- Index: x2/Makefile.in diff -u x2/Makefile.in:1.9 x2/Makefile.in:1.10 --- x2/Makefile.in:1.9 Sun Sep 15 00:41:10 2002 +++ x2/Makefile.in Mon Aug 23 08:25:47 2004 @@ -49,11 +49,11 @@ else \ echo "keeping existing $(prefix)/x2.motd.example";\ fi - @if [ ! -f $(prefix)/x2.news ]; then \ - echo "Creating $(prefix)/x2.news"; \ - $(CP) $(srcdir)/conf/x2.news $(prefix)/x2.news;\ + @if [ ! -f $(prefix)/x2.news.example ]; then \ + echo "Creating $(prefix)/x2.news.example"; \ + $(CP) $(srcdir)/conf/x2.news.example $(prefix)/x2.news.example;\ else \ - echo "keeping existing $(prefix)/x2.news";\ + echo "keeping existing $(prefix)/x2.news.example";\ fi @if [ ! -f $(prefix)/illegalchans.dat ]; then \ echo "Creating $(prefix)/illegalchans.dat"; \ Index: x2/source/chan.c diff -u x2/source/chan.c:1.90 x2/source/chan.c:1.91 --- x2/source/chan.c:1.90 Sun Jul 4 13:42:18 2004 +++ x2/source/chan.c Mon Aug 23 08:25:48 2004 @@ -165,22 +165,27 @@ { LamerListType lptr; char *nuh; + char *nuh2; if(uptr == NULL || cptr == NULL) return(NULL); - nuh = (char *) malloc(strlen(uptr->Nick) + strlen(uptr->UserID) + strlen(uptr->Address) + 3); - sprintf(nuh, "%s!%s@%s", uptr->Nick, uptr->UserID, uptr->Address); + nuh = (char *) malloc(strlen(uptr->Nick) + strlen(ActiveUsername(uptr)) + strlen(ActiveHost(uptr)) + 3); + nuh2 = (char *) malloc(strlen(uptr->Nick) + strlen(uptr->UserID) + strlen(uptr->Address) + 3); + sprintf(nuh, "%s!%s@%s", uptr->Nick, ActiveUsername(uptr), ActiveHost(uptr)); + sprintf(nuh2, "%s!%s@%s", uptr->Nick, uptr->UserID, uptr->Address); for(lptr = cptr->Lamers;lptr;lptr = lptr->Next) { - if(!matches(lptr->Mask, nuh)) + if(!matches(lptr->Mask, nuh) || !matches(lptr->Mask, nuh2)) { free(nuh); + free(nuh2); return(lptr); } } free(nuh); + free(nuh2); return (NULL); } @@ -287,7 +292,7 @@ } } /* No login, so find a match here... */ - sprintf(Str, "%s!%s@%s", uptr->Nick, uptr->UserID, uptr->Address); + sprintf(Str, "%s!%s@%s", uptr->Nick, ActiveUsername(uptr), ActiveHost(uptr)); for(hptr = cptr->Handles;hptr;hptr = hptr->Next) { for(mptr = hptr->Masks;mptr;mptr = mptr->Next) Index: x2/source/commands.c diff -u x2/source/commands.c:1.185 x2/source/commands.c:1.186 --- x2/source/commands.c:1.185 Sun Aug 22 12:10:42 2004 +++ x2/source/commands.c Mon Aug 23 08:25:48 2004 @@ -414,7 +414,7 @@ send_to_user(uptr, "\002%s is a Service.\002", rest); return(FALSE); } - sprintf(nuh, "%s!%s@%s", UserNode->Nick, UserNode->UserID, UserNode->Address); + sprintf(nuh, "%s!%s@%s", UserNode->Nick, ActiveUsername(UserNode), ActiveHost(UserNode)); if (!banok(cptr, uptr, nuh)) { @@ -624,7 +624,7 @@ send_to_user(uptr, "\002Sorry, you cannot kick or deop channel services.\002"); return(FALSE); } - sprintf(nuh, "%s!%s@%s", target->Nick, target->UserID, target->Address); + sprintf(nuh, "%s!%s@%s", target->Nick, ActiveUsername(target), ActiveHost(target)); if ((!kickok(cptr, uptr, target)) || (!banok(cptr, uptr, nuh))) { @@ -650,7 +650,7 @@ Debug(DBGWARNING, "c_ubm(): Null uptr"); return(FALSE); } - sprintf(nuh, "%s!%s@%s", uptr->Nick, uptr->UserID, uptr->Address); + sprintf(nuh, "%s!%s@%s", uptr->Nick, ActiveUsername(uptr), ActiveHost(uptr)); sprintf(nuh2, "%s!%s@%d.%d.%d.%d", uptr->Nick, uptr->UserID, uptr->IP / 65536 / 256 % 256, uptr->IP / 65536 % 256, uptr->IP / 256 % 256, uptr->IP % 256); @@ -694,7 +694,7 @@ } if((target = FindNick(rest, UsersN))) { - sprintf(nuh, "%s!%s@%s", target->Nick, target->UserID, target->Address); + sprintf(nuh, "%s!%s@%s", target->Nick, ActiveUsername(target), ActiveHost(target)); if (channel_unban(cptr, nuh)) { send_to_user(uptr, "\002%s has been unbanned from %s.\002", nuh, cptr->Name); @@ -750,7 +750,7 @@ else { char str[MAXLEN]; - snprintf(str, MAXLEN, "%s!%s@%s", target->Nick, target->UserID, target->Address); + snprintf(str, MAXLEN, "%s!%s@%s", target->Nick, ActiveUsername(target), ActiveHost(target)); send_to_user(uptr, "That user (%s) clusters to: %s", str, cluster(str)); } } @@ -875,13 +875,17 @@ if((target = (FindNick(rest, UsersN)))) { send_to_user(uptr, "\002=------%s------=\002", rest); - send_to_user(uptr, "\002 Nick : %s\002", target->Nick); - send_to_user(uptr, "\002 NumNick: %s\002", target->Numnick); - send_to_user(uptr, "\002 UserID : %s\002", target->UserID); - send_to_user(uptr, "\002 Address: %s\002", target->Address); - send_to_user(uptr, "\002 IP Addr: %s\002", unsigned32ToDotQuad(target->IP)); - send_to_user(uptr, "\002 Server : %s\002", target->Serv); - send_to_user(uptr, "\002 Clones : %d\002", target->Clones); + send_to_user(uptr, "\002 NumNick : %s\002", target->Numnick); + send_to_user(uptr, "\002 Nick : %s\002", target->Nick); + send_to_user(uptr, "\002 UserID : %s\002", target->UserID); + send_to_user(uptr, "\002 Address : %s\002", target->Address); + send_to_user(uptr, "\002 Realname: %s\002", target->RealName); + send_to_user(uptr, "\002 Account : %s\002", target->Account); + send_to_user(uptr, "\002 fakehost: %s\002", target->Fakehost); + send_to_user(uptr, "\002 sethost : %s\002", target->Sethost); + send_to_user(uptr, "\002 IP Addr : %s\002", unsigned32ToDotQuad(target->IP)); + send_to_user(uptr, "\002 Server : %s\002", target->Serv); + send_to_user(uptr, "\002 Clones : %d\002", target->Clones); if (target->Modes & UMODEd) strcat(modetmp, "d"); if (target->Modes & UMODEi) @@ -902,6 +906,12 @@ strcat(modetmp, "B"); if (target->Modes & UMODER) strcat(modetmp, "R"); + if (target->Modes & UMODEr) + strcat(modetmp, "r"); + if (target->Modes & UMODEf) + strcat(modetmp, "f"); + if (target->Modes & UMODEh) + strcat(modetmp, "h"); if (target->Modes & UMODEgod) strcat(modetmp, "(GOD)"); send_to_user(uptr, "\002 Modes : +%s\002", modetmp); @@ -3968,7 +3978,7 @@ send_to_user(uptr, "\002You cannot kick/deop/lamer a channel service.\002"); return(FALSE); } - sprintf(nuh, "%s!%s@%s", target->Nick, target->UserID, target->Address); + sprintf(nuh, "%s!%s@%s", target->Nick, ActiveUsername(target), ActiveHost(target)); sprintf(buff, "%s", cluster(nuh)); Address = buff; } @@ -4073,7 +4083,7 @@ { /* if the address doesnt have address stuff in it (!@ etc) */ if((target = FindNick(Address, UsersN))) { /* if theres a user on with that nick */ - sprintf(buff, "%s!%s@%s", target->Nick, target->UserID, target->Address); + sprintf(buff, "%s!%s@%s", target->Nick, ActiveUsername(target), ActiveHost(target)); Address = buff; send_to_user(uptr, "\002Searching for a mask matching: %s\002", Address); for(lptr = cptr->Lamers;lptr;lptr = lptr->Next) Index: x2/source/config.h diff -u x2/source/config.h:1.79 x2/source/config.h:1.80 --- x2/source/config.h:1.79 Sun Aug 22 12:10:42 2004 +++ x2/source/config.h Mon Aug 23 08:25:48 2004 @@ -47,7 +47,9 @@ #define VERSION "X2 v5.2 - AfterNET Channel Services" /* This is used to refer to your network in various places. It should be one word, eg "AfterNET" */ -#define NETWORK "AfterNET" +#define NETWORK "AfterNET" +#define HIDDEN_HOST "Users.AfterNET.Org" +#define HIDDEN_HOST_STAFF "Staff.AfterNET.Org" #define HELPURL "http://www.afternet.org/support/" #define OPERHELPFILE "HELP/operhelp.txt" @@ -68,7 +70,7 @@ /* Uncomment the following for debugging. */ -/* #define debugon */ + #define debugon /* If you dont want the word warez in channel names, define this. * TODO : This is a hack, and would do better in a config file. Do it! @@ -488,6 +490,9 @@ char Numnick[NUMNICKLEN]; char UserID[12]; char *Address; + char *Account; /* ircu +r account */ + char *Sethost; /* ircu +h sethost (S: lines) */ + char *Fakehost; /* ircu +f fakehost */ unsigned int IP; struct AuthHandleStruct *AuthHandles; /* A list of channel and handles were logged in as */ char *RealName; Index: x2/source/misc.c diff -u x2/source/misc.c:1.51 x2/source/misc.c:1.52 --- x2/source/misc.c:1.51 Sun Jul 4 13:42:19 2004 +++ x2/source/misc.c Mon Aug 23 08:25:48 2004 @@ -889,7 +889,7 @@ { char buff[MAXLEN]; - sprintf(buff, "%s!%s@%s", uptr->Nick, uptr->UserID, uptr->Address); + sprintf(buff, "%s!%s@%s", uptr->Nick, ActiveUsername(uptr), ActiveHost(uptr)); send_chanmode(cptr, "-ov+b %s %s %s", uptr->Numnick, uptr->Numnick, cluster(buff)); add_ban(cptr, cluster(buff)); } @@ -971,26 +971,7 @@ /* This will have to be reworked when the new domains are deploid */ tptr = &temp[strlen(temp) - 4]; /* Try to guess how many dots we need (minus one) */ - if(!strcasecmp(tptr, ".psi.net")) - { - numofdots = 4; - } - else if(!strcasecmp(tptr, "home.com") || - !strcasecmp(tptr, ".ar") || - !strcasecmp(tptr, ".ibm.net") || - !strcasecmp(tptr, ".uu.net")) - { - numofdots = 3; - } - else if(!strcasecmp(tptr, ".level3.net") || - !strcasecmp(tptr, ".texas.net") || - !strcasecmp(tptr, ".execpc.com") || - !strcasecmp(tptr, ".freei.net") || - !strcasecmp(tptr, ".rr.com")) - { - numofdots = 2; - } - else if (!strcasecmp(tptr, ".com") || + if ( !strcasecmp(tptr, ".com") || !strcasecmp(tptr, ".edu") || !strcasecmp(tptr, ".org") || !strcasecmp(tptr, ".net") || @@ -1003,7 +984,8 @@ !strcasecmp(tptr, ".no") || !strcasecmp(tptr, ".ca") || !strcasecmp(tptr, ".nu") || - !strcasecmp(tptr, ".fr")) + !strcasecmp(tptr, ".fr") + ) { numofdots = 1; } @@ -1011,6 +993,8 @@ { numofdots = 2; } + if(!matches("*.AfterNET.Org", fullhost)) + numofdots = 4; temp = fullhost; for (x = 0; x <= (strlen(fullhost) - 1); x++) { @@ -1596,3 +1580,49 @@ else return (Name); } + +char *ActiveHost(UserListType uptr) +{ + static char buff[MAXLEN]; + char *buffptr = buff; + if(uptr->Modes & UMODEh) + { + char *uname; + char *host; + strcpy(buff, uptr->Sethost); + uname = mysep(&buffptr, "@"); + host = mysep(&buffptr, "@"); + + return(host); + } + else if(uptr->Modes & UMODEf) + return(uptr->Fakehost); + else if(uptr->Modes & UMODEr) + { + if(uptr->Modes & UMODEo) + sprintf(buff, "%s.%s", uptr->Account, HIDDEN_HOST_STAFF); + else + sprintf(buff, "%s.%s", uptr->Account, HIDDEN_HOST); + return(buff); + } + else + return(uptr->Address); +} + +char *ActiveUsername(UserListType uptr) +{ + static char buff[MAXLEN]; + char *buffptr = buff; + if(uptr->Modes & UMODEh) + { + char *uname; + strcpy(buff, uptr->Sethost); + uname = mysep(&buffptr, "@"); + return(uname); + } + else + return(uptr->UserID); +} + + + Index: x2/source/misc.h diff -u x2/source/misc.h:1.20 x2/source/misc.h:1.21 --- x2/source/misc.h:1.20 Sun Jul 4 13:42:19 2004 +++ x2/source/misc.h Mon Aug 23 08:25:48 2004 @@ -71,3 +71,5 @@ unsigned int base64toint(const char *s); const char* inttobase64(char* buf, unsigned int v, unsigned int count); void LogAccess(UserListType uptr, char* item, int size); +char *ActiveHost(UserListType uptr); +char *ActiveUsername(UserListType uptr); Index: x2/source/parse.c diff -u x2/source/parse.c:1.92 x2/source/parse.c:1.93 --- x2/source/parse.c:1.92 Mon Jul 5 01:12:14 2004 +++ x2/source/parse.c Mon Aug 23 08:25:48 2004 @@ -89,11 +89,13 @@ { "WA", m_noop, TRUE, TRUE }, { "R", m_noop, TRUE, TRUE }, { "SE", m_settime, TRUE, FALSE }, - { "AC", m_noop, TRUE, FALSE }, /* not used in X2 */ + { "AC", m_account, TRUE, FALSE }, { "PRIVS", m_noop, TRUE, FALSE }, { "WU", m_noop, TRUE, TRUE }, { "LL", m_noop, TRUE, FALSE }, +#ifdef notdef { "SH", m_sethost, TRUE, FALSE }, +#endif { "FA", m_fakehost, TRUE, FALSE }, { "OM", m_noop, TRUE, TRUE }, { "CM", m_noop, TRUE, TRUE }, @@ -125,16 +127,54 @@ return true; } +/* This dont even exist.. it uses usermode */ +#ifdef notdef int m_sethost(M_PARAMS) { /* TODO: Change the host part of the structure */ return(0); } +#endif int m_fakehost(M_PARAMS) { - /* TODO: Change the host part of the structure */ - return(0); + char *numnick; + char *fakehost; + + numnick = mysep(&rest, " "); + fakehost = mysep(&rest, " "); + uptr = FindNumnick(numnick, UsersU); + if(!uptr) + { + Debug(DBGERROR, "Failed to find numnick %s in m_fakehost", numnick); + return(0); + } + uptr->Modes = uptr->Modes | UMODEf; + free(uptr->Fakehost); + uptr->Fakehost = malloc(strlen(fakehost)+1); + strcpy(uptr->Fakehost, fakehost); + return(0); +} +/* This is set when someone auths with srvx */ +/* It should set UMODEr and uptr->Account */ +int m_account(M_PARAMS) +{ + char *numnick; + char *account; + + numnick = mysep(&rest, " "); + account = mysep(&rest, " "); + uptr = FindNumnick(numnick, UsersU); + if(!uptr) + { + Debug(DBGERROR, "Failed to find numnick '%s' for AC '%s' (in m_account()) ", numnick, account); + return(0); + } + uptr->Modes = uptr->Modes | UMODEr; + free(uptr->Account); + uptr->Account = malloc(strlen(account) + 1); + strcpy(uptr->Account, account); + return(0); } int m_notice(M_PARAMS) @@ -418,9 +458,10 @@ int m_nick(M_PARAMS) { char* Arg[9]; - char* modes, *account, *sethost, *fakehost; + char* modes, *account = "", *sethost = "", *fakehost = ""; UserListType UserPtr; unsigned int IP; + char modestr[MAXLEN]; /* Built from parsing to pass to UserMode() */ Arg[0] = (char *) strtok(rest, " "); /* nick */ Arg[1] = (char *) strtok(NULL, " "); /* 1 */ @@ -440,20 +481,27 @@ Arg[3] = (char *) strtok(NULL, " "); /* userID */ Arg[4] = (char *) strtok(NULL, " "); /* address */ modes = (char *) strtok(NULL, " "); /* modes */ + strcpy(modestr, modes); if(modes[0] == '+') { Arg[5] = modes; if(strchr(modes, 'r')) { account = (char *) strtok(NULL, " "); /* This user has an account set from another service */ + strcat(modestr, " "); + strcat(modestr, account); } if(strchr(modes, 'h')) { sethost = (char *) strtok(NULL, " "); /* This user has an hidden hostmask (asuka/Nefarious only) */ + strcat(modestr, " "); + strcat(modestr, sethost); } if(strchr(modes, 'f')) { fakehost = (char *) strtok(NULL, " "); /* This user has an hidden hostmask (GameSurge/Nefarious only) */ + strcat(modestr, " "); + strcat(modestr, fakehost); } Arg[6] = (char *) strtok(NULL, " "); /* Compressed IP */ } @@ -475,14 +523,16 @@ Debug(DBGWARNING, "Incorrect syntax in NICK line"); return(0); } - UserPtr = AddUser(Arg[7], Arg[0], Arg[3], Arg[4], Arg[8], IP, sptr->Name, NOMODES); + UserPtr = AddUser(Arg[7], Arg[0], Arg[3], Arg[4], Arg[8], IP, sptr->Name, NOMODES, account, sethost, fakehost); if(!UserPtr) { Debug(DBGWARNING, "AddUser returned NULL for %s", Arg[0]); return(0); } - if(modes[0] == '+') - ProcessUserMode(UserPtr, modes); + + if(modes[0] == '+') + ProcessUserMode(UserPtr, modestr); + if(!NETBURSTING) SendMOTD(UserPtr); if(UserPtr) @@ -808,10 +858,10 @@ char* Arg[4]; Arg[0] = (char *) strtok(rest, " "); /* nick/channel */ - Arg[1] = (char *) strtok(NULL, " "); /* +/- mode */ if (Arg[0][0] == '#') { char buff[MAXLEN]; + Arg[1] = (char *) strtok(NULL, " "); /* +/- mode */ Arg[2] = (char *) strtok(NULL, " "); Arg[3] = (char *) strtok(NULL, "\n\0"); snprintf(buff, MAXLEN, "%s %s %s", Arg[1], Arg[2]?Arg[2]:"", Arg[3]?Arg[3]:""); @@ -822,7 +872,10 @@ on_mode(GetChannel(Arg[0]), NULL, buff); } else - ProcessUserMode(uptr, &Arg[1][1]); + { + Arg[1] = strtok(NULL, "\0"); + ProcessUserMode(uptr, Arg[1]); + } return (0); } int m_pong(M_PARAMS) @@ -1537,7 +1590,7 @@ } } AddUser(NumNick, IrcNick, IrcNick, "X2", ServiceName, - LOCALIP, ServiceName, (UMODEk & UMODEo)); + LOCALIP, ServiceName, (UMODEk & UMODEo),"","",""); ProcessUserMode(FindNick(IrcNick, UsersN), "+kows"); return; Index: x2/source/parse.h diff -u x2/source/parse.h:1.15 x2/source/parse.h:1.16 --- x2/source/parse.h:1.15 Sun Jul 4 13:42:19 2004 +++ x2/source/parse.h Mon Aug 23 08:25:48 2004 @@ -28,6 +28,9 @@ int m_quit(M_PARAMS); int m_kill(M_PARAMS); int m_squit(M_PARAMS); +#ifdef notdef int m_sethost(M_PARAMS); +#endif int m_fakehost(M_PARAMS); +int m_account(M_PARAMS); int m_logerror(M_PARAMS); Index: x2/source/user.c diff -u x2/source/user.c:1.36 x2/source/user.c:1.37 --- x2/source/user.c:1.36 Wed Jun 9 16:33:03 2004 +++ x2/source/user.c Mon Aug 23 08:25:48 2004 @@ -180,7 +180,7 @@ return (false); } -UserListType AddUser(char *Numnick, char *Nick, char *UserID, char *Address, char *RealName, unsigned int IP, char *Serv, unsigned char Modes) +UserListType AddUser(char *Numnick, char *Nick, char *UserID, char *Address, char *RealName, unsigned int IP, char *Serv, unsigned char Modes, char *Account, char *Sethost, char *Fakehost) { static int UserSegWarning = 1; UserListType NewUser, UserNode; @@ -210,6 +210,12 @@ return(NULL); if (!(NewUser->Address = (char *) malloc(strlen(Address) + 1))) return(NULL); + if (!(NewUser->Account = (char *) malloc(strlen(Account) + 1))) + return(NULL); + if (!(NewUser->Sethost = (char *) malloc(strlen(Sethost) + 1))) + return(NULL); + if (!(NewUser->Fakehost = (char *) malloc(strlen(Fakehost) + 1))) + return(NULL); if (!(NewUser->Serv = (char *) malloc(strlen(Serv) + 1))) return(NULL); if (!(NewUser->RealName = (char *) malloc(strlen(RealName) + 1))) @@ -218,6 +224,9 @@ UpdateCloneCount(CleanUserID, Address, CloneCount, UsersA); strcpy(NewUser->UserID, CleanUserID); strcpy(NewUser->Address, Address); + strcpy(NewUser->Account, Account); + strcpy(NewUser->Fakehost, Fakehost); + strcpy(NewUser->Sethost, Sethost); strcpy(NewUser->Serv, Serv); strcpy(NewUser->RealName, RealName); NewUser->IP = IP; @@ -472,7 +481,11 @@ if (ServPtr) ServPtr->NumOfUsers--; free(CurrPtrN->Address); + free(CurrPtrN->Account); + free(CurrPtrN->Fakehost); + free(CurrPtrN->Sethost); free(CurrPtrN->Serv); + free(CurrPtrN->RealName); free(CurrPtrN); } @@ -516,21 +529,26 @@ void ProcessUserMode(UserListType uptr, char *Modes) { -/* i'm not realy satisfied with the way this works */ char ch; char Operator = '+'; int len, i; unsigned int UserMode; + char *modestr; + char *sethost; + char *fakehost; + char *account; if (uptr == NULL) return; + modestr = mysep(&Modes, " "); + UserMode = NOMODES; - len = strlen(Modes); + len = strlen(modestr); for (i = 0; i < len; i++) { - ch = Modes[i]; + ch = modestr[i]; switch (ch) { case 'o': @@ -550,6 +568,20 @@ break; case 'h': UserMode = UMODEh; + if(Operator == '+') + { + /* Need to store the sethost! */ + sethost = mysep(&Modes, " "); + free(uptr->Sethost); /* Free the old one */ + uptr->Sethost = malloc(strlen(sethost) + 1); /* Make room */ + strcpy(uptr->Sethost, sethost); /* Copy it over */ + } + else + { + free(uptr->Sethost); + uptr->Sethost = malloc(2); + strcpy(uptr->Sethost, ""); + } break; case 'g': UserMode = UMODEg; @@ -559,9 +591,29 @@ break; case 'x': UserMode = UMODEx; + /* Can only be +, error on - */ break; case 'r': + /* Important NOTE: This is used for bursting, but after + * that m_account() gets called, which does the following + * itself (so look there too). + * Also note that -r doesnt ever really happen + */ UserMode = UMODEr; + if(Operator == '+') + { + /* Need to store the account */ + account = mysep(&Modes, " "); + free(uptr->Account); /* Free the old one */ + uptr->Account = malloc(strlen(account) + 1); + strcpy(uptr->Account, account); + } + else /* NEVER gets used. you cant unregister */ + { + free(uptr->Account); + uptr->Account = malloc(2); + strcpy(uptr->Account, ""); + } break; case 'B': UserMode = UMODEB; @@ -571,6 +623,21 @@ break; case 'f': UserMode = UMODEf; + if(Operator == '+') + { + /* Need to store teh fakehost! */ + fakehost = mysep(&Modes, " "); + free(uptr->Fakehost); + uptr->Fakehost = malloc(strlen(fakehost) + 1); + strcpy(uptr->Fakehost, fakehost); + } + else + { + free(uptr->Fakehost); + uptr->Fakehost = malloc(2); + strcpy(uptr->Fakehost, ""); + } + break; case '-': Operator = ch; break; Index: x2/source/user.h diff -u x2/source/user.h:1.12 x2/source/user.h:1.13 --- x2/source/user.h:1.12 Tue Jan 2 02:11:33 2001 +++ x2/source/user.h Mon Aug 23 08:25:48 2004 @@ -11,7 +11,7 @@ boolean IsOper(UserListType uptr); boolean IsGodOper(UserListType uptr); boolean IsOperByAdd(char *UserID, char *Address); -UserListType AddUser(char *Numnick, char *Nick, char *UserID, char *Address, char *RealName, unsigned int IP, char *Serv, unsigned char Modes); +UserListType AddUser(char *Numnick, char *Nick, char *UserID, char *Address, char *RealName, unsigned int IP, char *Serv, unsigned char Modes, char *Account, char *Sethost, char *Fakehost); void DeleteAllUsersByServer(char *ServerName); void DeleteUser(UserListType uptr, boolean sendnotice); void KillUserList(); ----------------------- End of diff ----------------------- |
From: Alex S. <ru...@us...> - 2004-09-05 09:09:08
|
Committer : Alex Schumann <ru...@us...> CVSROOT : /cvsroot/x2serv Module : x2 Commit time: 2004-09-05 09:08:53 UTC Modified files: source/commands.c source/misc.c Log message: Fix ban nick not showing up in command log (was not returning TRUE) Fix fakehost not being used in command log ---------------------- diff included ---------------------- Index: x2/source/commands.c diff -u x2/source/commands.c:1.186 x2/source/commands.c:1.187 --- x2/source/commands.c:1.186 Mon Aug 23 08:25:48 2004 +++ x2/source/commands.c Sun Sep 5 02:08:42 2004 @@ -424,6 +424,7 @@ ban_user(cptr, UserNode); send_to_user(uptr, "\x2%s banned on %s.\x2", nuh, cptr->Name); send_wallchops(cptr, "\002This ban (%s) brought to you by %s/%s.\002", nuh, uptr->Nick, cptr->Name); + return(TRUE); } else { Index: x2/source/misc.c diff -u x2/source/misc.c:1.52 x2/source/misc.c:1.53 --- x2/source/misc.c:1.52 Mon Aug 23 08:25:48 2004 +++ x2/source/misc.c Sun Sep 5 02:08:42 2004 @@ -359,13 +359,13 @@ if(ChanSecurity) { sprintf(buff, "[%s] %s %s(%s!%s@%s) %s %s %s", time2str(time(NULL)), - cptr->Name, hptr?hptr->Handle:"*", uptr->Nick, uptr->UserID, uptr->Address, + cptr->Name, hptr?hptr->Handle:"*", uptr->Nick, ActiveUsername(uptr), ActiveHost(uptr), HelpOverride?"+h":"-h", command, rest); } else { sprintf(buff, "[%s] global %s!%s@%s - %s %s", time2str(time(NULL)), - uptr->Nick, uptr->UserID, uptr->Address, + uptr->Nick, ActiveUsername(uptr), ActiveHost(uptr), command, rest); } if((LOGFILE = fopen(AccountingLog, "a+")) != NULL) ----------------------- End of diff ----------------------- |
From: Alex S. <ru...@us...> - 2004-10-22 04:35:57
|
Committer : Alex Schumann <ru...@us...> CVSROOT : /cvsroot/x2serv Module : x2 Commit time: 2004-10-22 04:35:50 UTC Modified files: HELP/AUTH source/config.h source/parse.c Log message: Updated to use the new AC R account syntax. This makes x2 incompatable with ircd < u2.10.11.07+Nefarious(0.3.0)+[1.242] ---------------------- diff included ---------------------- Index: x2/HELP/AUTH diff -u x2/HELP/AUTH:1.3 x2/HELP/AUTH:1.4 --- x2/HELP/AUTH:1.3 Thu May 31 07:15:55 2001 +++ x2/HELP/AUTH Thu Oct 21 21:35:34 2004 @@ -1 +1 @@ -Please see ^BLOGIN^B. +Please see LOGIN. Index: x2/source/config.h diff -u x2/source/config.h:1.80 x2/source/config.h:1.81 --- x2/source/config.h:1.80 Mon Aug 23 08:25:48 2004 +++ x2/source/config.h Thu Oct 21 21:35:40 2004 @@ -70,7 +70,7 @@ /* Uncomment the following for debugging. */ - #define debugon +// #define debugon /* If you dont want the word warez in channel names, define this. * TODO : This is a hack, and would do better in a config file. Do it! Index: x2/source/parse.c diff -u x2/source/parse.c:1.93 x2/source/parse.c:1.94 --- x2/source/parse.c:1.93 Mon Aug 23 08:25:48 2004 +++ x2/source/parse.c Thu Oct 21 21:35:40 2004 @@ -161,19 +161,27 @@ { char *numnick; char *account; + char *type; + char *strtimestamp; + type = mysep(&rest, " "); numnick = mysep(&rest, " "); account = mysep(&rest, " "); - uptr = FindNumnick(numnick, UsersU); - if(!uptr) + strtimestamp = mysep(&rest, " "); + + if(type && strcmp(type, "R")==0) { - Debug(DBGERROR, "Failed to find numnick '%s' for AC '%s' (in m_account()) ", numnick, account); - return(0); + uptr = FindNumnick(numnick, UsersU); + if(!uptr) + { + Debug(DBGERROR, "Failed to find numnick '%s' for AC '%s' (in m_account()) ", numnick, account); + return(0); + } + uptr->Modes = uptr->Modes | UMODEr; + free(uptr->Account); + uptr->Account = malloc(strlen(account) + 1); + strcpy(uptr->Account, account); } - uptr->Modes = uptr->Modes | UMODEr; - free(uptr->Account); - uptr->Account = malloc(strlen(account) + 1); - strcpy(uptr->Account, account); return(0); } ----------------------- End of diff ----------------------- |
From: Alex S. <ru...@us...> - 2004-10-28 05:04:24
|
Committer : Alex Schumann <ru...@us...> CVSROOT : /cvsroot/x2serv Module : x2 Commit time: 2004-10-28 05:04:16 UTC Modified files: source/parse.c Log message: Fixed bug with AC R Author: Log message: ---------------------- diff included ---------------------- Index: x2/source/parse.c diff -u x2/source/parse.c:1.94 x2/source/parse.c:1.95 --- x2/source/parse.c:1.94 Thu Oct 21 21:35:40 2004 +++ x2/source/parse.c Wed Oct 27 22:04:06 2004 @@ -164,11 +164,13 @@ char *type; char *strtimestamp; - type = mysep(&rest, " "); numnick = mysep(&rest, " "); + type = mysep(&rest, " "); account = mysep(&rest, " "); strtimestamp = mysep(&rest, " "); + Debug(DBGINFO, "Type:%s numnick:%s account:%s timestamp:%s", type, numnick, account, strtimestamp); + if(type && strcmp(type, "R")==0) { uptr = FindNumnick(numnick, UsersU); ----------------------- End of diff ----------------------- |
From: Neil S. <sir...@us...> - 2004-10-31 14:00:11
|
Committer : Neil Spierling <sir...@us...> CVSROOT : /cvsroot/x2serv Module : x2 Commit time: 2004-10-31 13:59:46 UTC Modified files: HELP/MODE Log message: tiny spelling mistake pointed out by a person on afternet ---------------------- diff included ---------------------- Index: x2/HELP/MODE diff -u x2/HELP/MODE:1.1 x2/HELP/MODE:1.2 --- x2/HELP/MODE:1.1 Thu May 31 11:06:47 2001 +++ x2/HELP/MODE Sun Oct 31 05:59:35 2004 @@ -1,6 +1,6 @@ Usage: MODE ----------- -The MODE command will reset the channle mode to those stored +The MODE command will reset the channel mode to those stored in the channel database. You cannot modify the default mode with this command, instead you must use the SET MODE command to do this. ----------------------- End of diff ----------------------- |
From: Alex S. <ru...@us...> - 2004-11-21 08:22:46
|
Committer : Alex Schumann <ru...@us...> CVSROOT : /cvsroot/x2serv Module : x2 Commit time: 2004-11-21 08:21:54 UTC Modified files: source/parse.c Log message: Handles timestamped accounts now ---------------------- diff included ---------------------- Index: x2/source/parse.c diff -u x2/source/parse.c:1.95 x2/source/parse.c:1.96 --- x2/source/parse.c:1.95 Wed Oct 27 22:04:06 2004 +++ x2/source/parse.c Sun Nov 21 00:21:44 2004 @@ -497,7 +497,12 @@ Arg[5] = modes; if(strchr(modes, 'r')) { + char *actptr; account = (char *) strtok(NULL, " "); /* This user has an account set from another service */ + if((actptr = strchr(account, ':'))) + { + account = actptr+1; + } strcat(modestr, " "); strcat(modestr, account); } ----------------------- End of diff ----------------------- |
From: Alex S. <ru...@us...> - 2004-11-21 08:56:20
|
Committer : Alex Schumann <ru...@us...> CVSROOT : /cvsroot/x2serv Module : x2 Commit time: 2004-11-21 08:55:36 UTC Modified files: source/parse.c Log message: Oops. lets try this another way ;) ---------------------- diff included ---------------------- Index: x2/source/parse.c diff -u x2/source/parse.c:1.96 x2/source/parse.c:1.97 --- x2/source/parse.c:1.96 Sun Nov 21 00:21:44 2004 +++ x2/source/parse.c Sun Nov 21 00:55:26 2004 @@ -499,9 +499,9 @@ { char *actptr; account = (char *) strtok(NULL, " "); /* This user has an account set from another service */ - if((actptr = strchr(account, ':'))) + if((actptr = strchr(account, ':')) && actptr[1]) { - account = actptr+1; + *actptr = '\0'; } strcat(modestr, " "); strcat(modestr, account); ----------------------- End of diff ----------------------- |
From: Alex S. <ru...@us...> - 2004-12-02 07:01:43
|
Committer : Alex Schumann <ru...@us...> CVSROOT : /cvsroot/x2serv Module : x2 Commit time: 2004-12-02 07:01:22 UTC Modified files: source/misc.c Log message: Pipe (|) was not being treated as acceptable in hostmasks, but it is. Author: Log message: ---------------------- diff included ---------------------- Index: x2/source/misc.c diff -u x2/source/misc.c:1.53 x2/source/misc.c:1.54 --- x2/source/misc.c:1.53 Sun Sep 5 02:08:42 2004 +++ x2/source/misc.c Wed Dec 1 23:01:11 2004 @@ -1403,7 +1403,7 @@ switch (Address[i]) { case '*': case '?': case '+': case '-': case '.': case '\\': case '^': case '_': case '{': case '[': case '}': case ']': case '~': - case '\'': case '`': + case '\'': case '`': case '|': continue; case '!': { if (gotexcl || gotat) ----------------------- End of diff ----------------------- |
From: Alex S. <ru...@us...> - 2005-01-31 04:15:34
|
Committer : Alex Schumann <ru...@us...> CVSROOT : /cvsroot/x2serv Module : x2 Commit time: 2005-01-31 04:15:28 UTC Modified files: source/config.h source/user.c Log message: Handle umode +A ---------------------- diff included ---------------------- Index: x2/source/config.h diff -u x2/source/config.h:1.81 x2/source/config.h:1.82 --- x2/source/config.h:1.81 Thu Oct 21 21:35:40 2004 +++ x2/source/config.h Sun Jan 30 20:15:17 2005 @@ -236,6 +236,7 @@ #define CMODEm 1 /* These are for User mode parsing.. */ +#define UMODEA 32768 #define UMODEf 16384 #define UMODEh 8192 #define UMODEB 4096 Index: x2/source/user.c diff -u x2/source/user.c:1.37 x2/source/user.c:1.38 --- x2/source/user.c:1.37 Mon Aug 23 08:25:48 2004 +++ x2/source/user.c Sun Jan 30 20:15:18 2005 @@ -554,6 +554,9 @@ case 'o': UserMode = UMODEo; break; + case 'A': + UserMode = UMODEA; + break; case 'd': UserMode = UMODEd; break; ----------------------- End of diff ----------------------- |
From: Alex S. <ru...@us...> - 2005-02-19 03:42:57
|
Committer : Alex Schumann <ru...@us...> CVSROOT : /cvsroot/x2serv Module : x2 Commit time: 2005-02-19 03:42:47 UTC Modified files: source/commands.c Log message: Author: Log message: modified addop and scriptreg to add a default mask based on the users account name. added "die" command as an alias of "quit" ---------------------- diff included ---------------------- Index: x2/source/commands.c diff -u x2/source/commands.c:1.187 x2/source/commands.c:1.188 --- x2/source/commands.c:1.187 Sun Sep 5 02:08:42 2004 +++ x2/source/commands.c Fri Feb 18 19:42:22 2005 @@ -203,6 +203,7 @@ { "SETHANDLE", c_sethandle, REGED, MA, T, T, F, T }, { "SETINFO", c_setinfo, REGED, PE, T, F, F, T }, { "QUIT", c_quit, NONE, 0, 0, 0, T, F }, + { "DIE", c_quit, NONE, 0, 0, 0, T, F }, { "D", c_roll, NONE, 0, 0, 0, F, T }, { "DICE", c_roll, NONE, 0, 0, 0, F, T }, { "ROLL", c_roll, NONE, 0, 0, 0, F, T }, @@ -1308,6 +1309,19 @@ SetLastSeen(cptr, hptr, JOIN); } + + /* If they are (co)owner, make sure the (co)owner last seen time gets reset. */ + if(IsChanOwner(hptr) || IsChanCoOwner(hptr)) + { + /* cant do this because they may have been already counted from a mask. + * cptr->OwnersOnline++; */ + + /* If OwnersOnline is 0, there is currently an owner already counted in the channel, + * so expiring wont be a problem. Otherwise, lets update the timestamp. */ + if(cptr->LastAccess > 0) + cptr->LastAccess = (unsigned long) time(NULL); + WriteChanOpFile(cptr); + } return(TRUE); } @@ -2673,6 +2687,14 @@ genpass(Pass, GENPASSLEN); tmphptr = AddHandle(cptr, handle, crypt(Pass, "$1$92737837$"), "*", *level, 1, 0, 0); + if(uptr->Account) + { + /* Add a mask of *!*@account.users.afternet.org automagically! */ + char buf[MAXLEN]; + + sprintf(buf, "*!*@%s.Users.AfterNET.Org", uptr->Account); + AddMask(tmphptr, buf); + } WriteChanOpFile(cptr); send_to_user(uptr, "New user \"%s\" added to %s userlist, as %s.", handle, cptr->Name, levelnamefromchar(*level)); @@ -3704,6 +3726,8 @@ { char Str[MAXLEN]; ChannelListType cptr; + HandleListType LastHandle = NULL; + if(!(cptr = GetChannel(ChanName))) { send_to_user(uptr, "REGCHAN returned OK, however, I cant find %s in memory...", ChanName); @@ -3712,8 +3736,12 @@ } /* Add owner */ - if(AddHandle(cptr, OwnerHandle, crypt(OwnerPassword, "$1$92737837$"), "*", 'W', 1, 0, 0)) + if((LastHandle = AddHandle(cptr, OwnerHandle, crypt(OwnerPassword, "$1$92737837$"), "*", 'W', 1, 0, 0))) { + char buf[MAXLEN]; + + sprintf(buf, "*!*@%s.users.AfterNET.Org", LastHandle->Handle); + AddMask(LastHandle, buf); strcpy(Str, "Owner: \002SUCCESS\002"); } else ----------------------- End of diff ----------------------- |
From: Alex S. <ru...@us...> - 2005-02-19 21:04:35
|
Committer : Alex Schumann <ru...@us...> CVSROOT : /cvsroot/x2serv Module : x2 Commit time: 2005-02-19 21:04:24 UTC Modified files: source/commands.c Log message: Author: Log message: Applied a working variant of osiris' calc patch. Calc now supports things like: 3(3)3 = 3*3*3 2pi = 2*pi ---------------------- diff included ---------------------- Index: x2/source/commands.c diff -u x2/source/commands.c:1.188 x2/source/commands.c:1.189 --- x2/source/commands.c:1.188 Fri Feb 18 19:42:22 2005 +++ x2/source/commands.c Sat Feb 19 13:04:12 2005 @@ -1134,6 +1134,11 @@ int c_calc(C_PARAM) { char buff[MAXLEN]; + char newrest[MAXLEN]; + char *ptr; + boolean lastNumber = false; + boolean lastBracket = false; + boolean failed; if(!rest || !*rest) { @@ -1141,7 +1146,61 @@ send_to_user(uptr, "For example: CALC 5 + 3 / 6"); return(TRUE); } - do_math(buff, rest); + + /* This is a HACK to insert * before ( so multiplication takes place + * in things such as 3(3) instead of ignoring the first 3. Submitted + * by Osiris. + * I spent some time tlooking at calc.c and I didnt see an easy way + * to do this there... and that file gives me a headache.. so.. -Rubin + */ + ptr = newrest; + while(*rest && ptr < newrest+MAXLEN-1) { + switch(*rest) { + case '1': case '2': + case '3': case '4': + case '5': case '6': + case '7': case '8': + case '9': case '0': + lastNumber = true; + if(lastBracket == true) { + *ptr = '*'; + ptr++; + } + *ptr = *rest; + lastBracket = false; + break; + case ')': case ']': /* Support sin[12](3) also */ + lastNumber = true; + lastBracket = true; + *ptr = *rest; + break; + case '(': case '[': + if (lastNumber == true) { + *ptr = '*'; + ptr++; + } + *ptr = *rest; + lastNumber = false; + lastBracket = false; + break; + default: + if(isalpha(*rest)) + { + if(lastNumber == true) { + *ptr = '*'; + ptr++; + } + } + *ptr = *rest; + lastNumber = false; + lastBracket = false; + break; + } + rest++; + ptr++; + } + *ptr = '\0'; + do_math(buff, newrest); if(said_inptr && PublicReplyAllowed(hptr)) { send_to_channel(said_inptr, "\002%s:\002 %s", uptr->Nick, buff); ----------------------- End of diff ----------------------- |
From: Alex S. <ru...@us...> - 2005-02-20 03:19:40
|
Committer : Alex Schumann <ru...@us...> CVSROOT : /cvsroot/x2serv Module : x2 Commit time: 2005-02-20 03:19:30 UTC Modified files: source/commands.c Log message: Fixed a mistake with my addop mask creation code ---------------------- diff included ---------------------- Index: x2/source/commands.c diff -u x2/source/commands.c:1.189 x2/source/commands.c:1.190 --- x2/source/commands.c:1.189 Sat Feb 19 13:04:12 2005 +++ x2/source/commands.c Sat Feb 19 19:19:14 2005 @@ -2746,12 +2746,12 @@ genpass(Pass, GENPASSLEN); tmphptr = AddHandle(cptr, handle, crypt(Pass, "$1$92737837$"), "*", *level, 1, 0, 0); - if(uptr->Account) + if(target->Account) { /* Add a mask of *!*@account.users.afternet.org automagically! */ char buf[MAXLEN]; - sprintf(buf, "*!*@%s.Users.AfterNET.Org", uptr->Account); + sprintf(buf, "*!*@%s.Users.AfterNET.Org", target->Account); AddMask(tmphptr, buf); } WriteChanOpFile(cptr); ----------------------- End of diff ----------------------- |
From: Alex S. <ru...@us...> - 2005-02-20 03:43:30
|
Committer : Alex Schumann <ru...@us...> CVSROOT : /cvsroot/x2serv Module : x2 Commit time: 2005-02-20 03:43:18 UTC Modified files: source/chan.c source/user.c Log message: Applied untested ':' ignoring in mode parsing code. ---------------------- diff included ---------------------- Index: x2/source/chan.c diff -u x2/source/chan.c:1.91 x2/source/chan.c:1.92 --- x2/source/chan.c:1.91 Mon Aug 23 08:25:48 2004 +++ x2/source/chan.c Sat Feb 19 19:43:08 2005 @@ -495,6 +495,8 @@ { switch (*chanchars) { + case ':': + break; case '+': sign = '+'; globsign = '+'; Index: x2/source/user.c diff -u x2/source/user.c:1.38 x2/source/user.c:1.39 --- x2/source/user.c:1.38 Sun Jan 30 20:15:18 2005 +++ x2/source/user.c Sat Feb 19 19:43:08 2005 @@ -551,6 +551,8 @@ ch = modestr[i]; switch (ch) { + case ':': + break; case 'o': UserMode = UMODEo; break; ----------------------- End of diff ----------------------- |
From: Reed L. <r3...@us...> - 2005-03-13 22:24:37
|
Committer : Reed Loden <r3...@us...> CVSROOT : /cvsroot/x2serv Module : x2 Commit time: 2005-03-13 22:24:18 UTC Modified files: source/commands.c source/config.h source/parse.c source/parse.h source/send.c Log message: Various fixes to make X2 more P10-compatible and to actually use channel timestamps. ---------------------- diff included ---------------------- Index: x2/source/commands.c diff -u x2/source/commands.c:1.190 x2/source/commands.c:1.191 --- x2/source/commands.c:1.190 Sat Feb 19 19:19:14 2005 +++ x2/source/commands.c Sun Mar 13 14:24:06 2005 @@ -912,8 +912,6 @@ strcat(modetmp, "r"); if (target->Modes & UMODEf) strcat(modetmp, "f"); - if (target->Modes & UMODEh) - strcat(modetmp, "h"); if (target->Modes & UMODEgod) strcat(modetmp, "(GOD)"); send_to_user(uptr, "\002 Modes : +%s\002", modetmp); Index: x2/source/config.h diff -u x2/source/config.h:1.82 x2/source/config.h:1.83 --- x2/source/config.h:1.82 Sun Jan 30 20:15:17 2005 +++ x2/source/config.h Sun Mar 13 14:24:07 2005 @@ -199,12 +199,6 @@ /* Warning message */ #define CHANWARNMESSAGE "ATTENTION: This channel will expire soon due to inactivity! '/msg x2 help expire' for details." -/* This time stamp is used as the date registered channels were created in X2. - * It should be older then the oldest channel on the network, or X2 wont get - * ops. All channels registered on the net will have this timestamp displayed. - */ -#define BURSTCHANNELDATE 691085573 /* Mon Nov 25 08:12:53 1991 */ - /* These are the constants that determine how often a user can use * X2's invite. */ Index: x2/source/parse.c diff -u x2/source/parse.c:1.97 x2/source/parse.c:1.98 --- x2/source/parse.c:1.97 Sun Nov 21 00:55:26 2004 +++ x2/source/parse.c Sun Mar 13 14:24:07 2005 @@ -93,9 +93,6 @@ { "PRIVS", m_noop, TRUE, FALSE }, { "WU", m_noop, TRUE, TRUE }, { "LL", m_noop, TRUE, FALSE }, -#ifdef notdef - { "SH", m_sethost, TRUE, FALSE }, -#endif { "FA", m_fakehost, TRUE, FALSE }, { "OM", m_noop, TRUE, TRUE }, { "CM", m_noop, TRUE, TRUE }, @@ -127,15 +124,6 @@ return true; } -/* This dont even exist.. it uses usermode */ -#ifdef notdef -int m_sethost(M_PARAMS) -{ - /* TODO: Change the host part of the structure */ - return(0); -} -#endif - int m_fakehost(M_PARAMS) { char *numnick; Index: x2/source/parse.h diff -u x2/source/parse.h:1.16 x2/source/parse.h:1.17 --- x2/source/parse.h:1.16 Mon Aug 23 08:25:48 2004 +++ x2/source/parse.h Sun Mar 13 14:24:07 2005 @@ -28,9 +28,6 @@ int m_quit(M_PARAMS); int m_kill(M_PARAMS); int m_squit(M_PARAMS); -#ifdef notdef -int m_sethost(M_PARAMS); -#endif int m_fakehost(M_PARAMS); int m_account(M_PARAMS); int m_logerror(M_PARAMS); Index: x2/source/send.c diff -u x2/source/send.c:1.40 x2/source/send.c:1.41 --- x2/source/send.c:1.40 Sun Jul 4 10:03:09 2004 +++ x2/source/send.c Sun Mar 13 14:24:07 2005 @@ -247,7 +247,7 @@ void send_opchan(ChannelListType cptr) { - send_command_from_server("M %s +o %s 0", cptr->Name, NumNick); + send_command_from_server("M %s +o %s %lu", cptr->Name, NumNick, cptr->CreationDate); } void send_hackmode(ChannelListType cptr, char *format, ...) @@ -259,7 +259,7 @@ vsprintf(buff, format, args); va_end(args); - send_command_from_server("M %s %s %lu", cptr->Name, buff, 0); + send_command_from_server("M %s %s %lu", cptr->Name, buff, cptr->CreationDate); } void send_join(ChannelListType cptr) @@ -448,13 +448,13 @@ ServiceName, LinkTimeStamp, ServerTimeStamp, ServNum, "X2 Channel Service"); /* <server> NICK <nick> <hops> <timestamp> <user> <host> <compressed ip> <3 letter numeric> :<username> */ - sendtosock(Sock, "%s N %s 1 %lu %s %s +%s %s %s%s :\002%c\002) /MSG %s Help (\002%c\002", + sendtosock(Sock, "%s N %s 1 %lu %s %s +%s %s %s :\002%c\002) /MSG %s Help (\002%c\002", ServNum, IrcNick, LinkTimeStamp, IrcNick, /* user */ ServiceName, /* host */ - "ko", /* Modes */ + "iok", /* Modes */ "B]AAAB", /* compressed ip (127.0.0.1) */ - ServNum, "AAA", /* lets use the first available numeric :) */ + NumNick, /* lets use the first available numeric :) */ CommandMark, IrcNick, CommandMark); #ifdef pinging PingStamp = time(NULL); @@ -473,7 +473,6 @@ void ModeChans() { - char ModeString[LINEBUFFSIZE]; int i; ChannelListType TempChanPtr; @@ -484,15 +483,8 @@ { if(TempChanPtr->settings[INCHAN]) { - sendtosock(Sock, ":%s M %s %s", IrcNick, TempChanPtr->Name, - GetModeString(ModeString, TempChanPtr->PlusModes, - TempChanPtr->MinModes, TempChanPtr->Key, - TempChanPtr->Limit)); - } - if(TempChanPtr->settings[INCHAN]) - { if (strcmp(TempChanPtr->Topic, "*") && (TempChanPtr->settings[TOPICFREQ] > 0)) - sendtosock(Sock, ":%s T %s :%s", IrcNick, + sendtosock(Sock, "%s T %s :%s", NumNick, TempChanPtr->Name, TempChanPtr->Topic); } TempChanPtr = TempChanPtr->Next; @@ -516,9 +508,9 @@ if(TempChanPtr->settings[INCHAN]) { send_opchan(TempChanPtr); - sendtosock(Sock, ":%s M %s +o %s %lu", - ServiceName, TempChanPtr->Name, - IrcNick, BURSTCHANNELDATE); + sendtosock(Sock, "%s M %s +o %s %lu", + ServNum, TempChanPtr->Name, + NumNick, TempChanPtr->CreationDate); } TempChanPtr = TempChanPtr->Next; } @@ -527,6 +519,7 @@ void JoinChans() { + char ModeString[LINEBUFFSIZE]; int i; ChannelListType TempChanPtr; @@ -538,10 +531,13 @@ if(TempChanPtr->settings[INCHAN]) { TempChanPtr->NumOfNicks++; /* Note that we joined the channel */ - sendtosock(Sock, "%s B %s %lu %s:o", + sendtosock(Sock, "%s B %s %lu %s %s:o", ServNum, /* servers numnick */ TempChanPtr->Name, /* #channel */ TempChanPtr->CreationDate, /* Hopefully already set by other side BURST */ + GetModeString(ModeString, TempChanPtr->PlusModes, + TempChanPtr->MinModes, TempChanPtr->Key, + TempChanPtr->Limit), NumNick); /* My nick is joining, and had ops.. */ } TempChanPtr = TempChanPtr->Next; @@ -564,7 +560,7 @@ while (TempChanPtr) { if(TempChanPtr->settings[TOPICFREQ] && strcmp(TempChanPtr->Topic, "*")) - sendtosock(Sock, ":%s T %s :%s", IrcNick, TempChanPtr->Name, TempChanPtr->Topic); + sendtosock(Sock, "%s T %s :%s", NumNick, TempChanPtr->Name, TempChanPtr->Topic); TempChanPtr = TempChanPtr->Next; } ----------------------- End of diff ----------------------- |
From: Alex S. <ru...@us...> - 2005-03-21 20:15:46
|
Committer : Alex Schumann <ru...@us...> CVSROOT : /cvsroot/x2serv Module : x2 Commit time: 2005-03-21 20:15:37 UTC Modified files: source/config.h source/parse.c Log message: Make X2 ignore nefarious MK commands (mark as RBL positive) ---------------------- diff included ---------------------- Index: x2/source/config.h diff -u x2/source/config.h:1.83 x2/source/config.h:1.84 --- x2/source/config.h:1.83 Sun Mar 13 14:24:07 2005 +++ x2/source/config.h Mon Mar 21 12:15:11 2005 @@ -70,7 +70,7 @@ /* Uncomment the following for debugging. */ -// #define debugon +//#define debugon /* If you dont want the word warez in channel names, define this. * TODO : This is a hack, and would do better in a config file. Do it! Index: x2/source/parse.c diff -u x2/source/parse.c:1.98 x2/source/parse.c:1.99 --- x2/source/parse.c:1.98 Sun Mar 13 14:24:07 2005 +++ x2/source/parse.c Mon Mar 21 12:15:12 2005 @@ -96,6 +96,7 @@ { "FA", m_fakehost, TRUE, FALSE }, { "OM", m_noop, TRUE, TRUE }, { "CM", m_noop, TRUE, TRUE }, + { "MK", m_noop, TRUE, TRUE }, { NULL, NULL, FALSE, FALSE } }; /* *INDENT-ON* */ ----------------------- End of diff ----------------------- |
From: Alex S. <ru...@us...> - 2005-06-06 22:17:54
|
Committer : Alex Schumann <ru...@us...> CVSROOT : /cvsroot/x2serv Module : x2 Commit time: 2005-06-06 22:17:47 UTC Modified files: source/chan.c source/commands.c Log message: Adding the afternet mambo web based channel registration tool to tools/ ---------------------- diff included ---------------------- Index: x2/source/chan.c diff -u x2/source/chan.c:1.92 x2/source/chan.c:1.93 --- x2/source/chan.c:1.92 Sat Feb 19 19:43:08 2005 +++ x2/source/chan.c Mon Jun 6 15:17:35 2005 @@ -264,7 +264,8 @@ HandleListType FindBestUserMatch(ChannelListType cptr, UserListType uptr) { - char Str[LINEBUFFSIZE]; + char* Str; + char* Str2; int weight, prevweight = 0, lvl, prevlvl = 0; HandleListType hptr; MaskListType mptr; @@ -292,13 +293,17 @@ } } /* No login, so find a match here... */ + Str = (char *) malloc(strlen(uptr->Nick) + strlen(ActiveUsername(uptr)) + strlen(ActiveHost(uptr)) + 3); + Str2 = (char *) malloc(strlen(uptr->Nick) + strlen(uptr->UserID) + strlen(uptr->Address) + 3); + sprintf(Str, "%s!%s@%s", uptr->Nick, ActiveUsername(uptr), ActiveHost(uptr)); + sprintf(Str2, "%s!%s@%s", uptr->Nick, uptr->UserID, uptr->Address); for(hptr = cptr->Handles;hptr;hptr = hptr->Next) { for(mptr = hptr->Masks;mptr;mptr = mptr->Next) { - if (!matches(mptr->Mask, Str)) - { /* If mask matches our user, */ + if (!matches(mptr->Mask, Str) && !matches(mptr->Mask, Str2)) + { /* If mask matches our user by either 2 hosts above, */ weight=calcmaskweight(mptr->Mask); lvl=userlevelbychar(hptr->Level); if ( (!PrevHandlePtr || (lvl > prevlvl) || (weight > prevweight && lvl >= prevlvl))) @@ -311,6 +316,8 @@ } } return(PrevHandlePtr); + free(Str); + free(Str2); return(NULL); } Index: x2/source/commands.c diff -u x2/source/commands.c:1.191 x2/source/commands.c:1.192 --- x2/source/commands.c:1.191 Sun Mar 13 14:24:06 2005 +++ x2/source/commands.c Mon Jun 6 15:17:36 2005 @@ -1152,62 +1152,67 @@ * to do this there... and that file gives me a headache.. so.. -Rubin */ ptr = newrest; - while(*rest && ptr < newrest+MAXLEN-1) { - switch(*rest) { - case '1': case '2': - case '3': case '4': - case '5': case '6': - case '7': case '8': - case '9': case '0': - lastNumber = true; - if(lastBracket == true) { - *ptr = '*'; - ptr++; - } - *ptr = *rest; - lastBracket = false; - break; - case ')': case ']': /* Support sin[12](3) also */ - lastNumber = true; - lastBracket = true; - *ptr = *rest; - break; - case '(': case '[': - if (lastNumber == true) { - *ptr = '*'; - ptr++; - } - *ptr = *rest; - lastNumber = false; - lastBracket = false; - break; - default: - if(isalpha(*rest)) - { - if(lastNumber == true) { + while(*rest && ptr < newrest+MAXLEN-1) + { + switch(*rest) + { + case '1': case '2': + case '3': case '4': + case '5': case '6': + case '7': case '8': + case '9': case '0': + lastNumber = true; + if(lastBracket == true) + { + *ptr = '*'; + ptr++; + } + *ptr = *rest; + lastBracket = false; + break; + case ')': case ']': /* Support sin[12](3) also */ + lastNumber = true; + lastBracket = true; + *ptr = *rest; + break; + case '(': case '[': + if (lastNumber == true) + { *ptr = '*'; ptr++; } - } - *ptr = *rest; - lastNumber = false; - lastBracket = false; - break; + *ptr = *rest; + lastNumber = false; + lastBracket = false; + break; + default: + if(isalpha(*rest)) + { + if(lastNumber == true) + { + *ptr = '*'; + ptr++; + } + } + *ptr = *rest; + lastNumber = false; + lastBracket = false; + break; + } + rest++; + ptr++; } - rest++; - ptr++; - } - *ptr = '\0'; - do_math(buff, newrest); - if(said_inptr && PublicReplyAllowed(hptr)) - { - send_to_channel(said_inptr, "\002%s:\002 %s", uptr->Nick, buff); - } - else - { - send_to_user(uptr, "%s", buff); - } - return(TRUE); + *ptr = '\0'; + do_math(buff, newrest); + if(said_inptr && PublicReplyAllowed(hptr)) + { + send_to_channel(said_inptr, "\002%s:\002 %s", uptr->Nick, buff); + } + else + { + send_to_user(uptr, "%s", buff); + } + return(TRUE); } int c_inviteme(C_PARAM) ----------------------- End of diff ----------------------- |
From: Alex S. <ru...@us...> - 2005-06-06 22:29:11
|
Committer : Alex Schumann <ru...@us...> CVSROOT : /cvsroot/x2serv Module : x2 Commit time: 2005-06-06 22:28:44 UTC Added files: tools/com_cservice/README tools/com_cservice/config.php tools/com_cservice/cservice.php tools/com_cservice/mysqldump.sql tools/com_cservice/regex.php tools/com_cservice/classes/ircclient.php tools/com_cservice/classes/template.php tools/com_cservice/help/errInvalidChannelName.html tools/com_cservice/help/errInvalidEmailDomain.html tools/com_cservice/help/errInvalidOwnerEmail.html tools/com_cservice/help/errInvalidOwnerHandle.html tools/com_cservice/help/errInvalidOwnerPassword.html tools/com_cservice/help/helpdocs.js tools/com_cservice/lang/en.php tools/com_cservice/templates/aup.html tools/com_cservice/templates/dberror.html tools/com_cservice/templates/must_login.html tools/com_cservice/templates/regfailed.html tools/com_cservice/templates/regsuccess.html tools/com_cservice/templates/too_many.html Log message: adding mambo web registration module to tools/ ---------------------- diff included ---------------------- Index: x2/tools/com_cservice/README diff -u /dev/null x2/tools/com_cservice/README:1.1 --- /dev/null Mon Jun 6 15:28:44 2005 +++ x2/tools/com_cservice/README Mon Jun 6 15:28:33 2005 @@ -0,0 +1,5 @@ +This is a MAMBO OPENSOURCE module for registering channels on a mambo based website with X2. + +It works for us, and im providing it so you can see how we did it. If your not really good with mysql, irc, and php, dont bother trying to get this to go.. its really a manual process for experts. (sorry) + + Index: x2/tools/com_cservice/classes/ircclient.php diff -u /dev/null x2/tools/com_cservice/classes/ircclient.php:1.1 --- /dev/null Mon Jun 6 15:28:44 2005 +++ x2/tools/com_cservice/classes/ircclient.php Mon Jun 6 15:28:33 2005 @@ -0,0 +1,145 @@ +<?php +class IRCClient +{ + var $irc_nick; + var $irc_user; + var $irc_name; + var $irc_host; + var $irc_server; + var $irc_port; + var $irc_password; + + var $socket; + var $error; + var $errno; + var $callback_handlers; + var $fp; + + function IRCClient ($nick, $user, $name, $host) + { + $this->irc_nick = $nick; + $this->irc_user = $user; + $this->irc_name = $name; + $this->irc_host = $host; + $this->socket = NULL; + $this->error = NULL; + $this->errno = NULL; + $this->callback_handlers = array(); + } + + function irc_connect ($server, $pass=NULL) + { + $this->fp = fopen ('/tmp/irclog.log', 'a'); + + list ($server, $port) = explode(':', $server); + $this->irc_server = $server; + $this->irc_port = ($port)? $port: '6667'; + $this->irc_pass = ($pass)? $pass: NULL; + + fwrite($this->fp, sprintf( "[%s] Connecting to %s (%s) port %s\n", + date("YmdHis"), $this->irc_server, + gethostbyname($this->irc_server), $this->irc_port ) ); + + $this->socket = fsockopen ($this->irc_server, $this->irc_port, + $this->errno, $this->error, 10); + + set_socket_blocking($this->socket, FALSE); + if ( !empty ($this->irc_password) ) { + $this->irc_send_msg (sprintf ("PASS %s", $this->irc_password)); + } + + $this->irc_send_msg (sprintf ("USER %s %s %s :%s", $this->irc_user, $this->irc_user, $this->irc_user, $this->irc_name)); + $this->irc_send_msg (sprintf ("NICK %s", $this->irc_nick)); + + + $this->irc_do_loop(); + } + + function irc_disconnect () + { + $this->irc_send_msg (sprintf ("QUIT")); + fclose ($this->socket); + $this->socket = NULL; + + fwrite($this->fp, sprintf( "[%s] Disconnected from %s (%s) port %s\n", + date("YmdHis"), $this->irc_server, + gethostbyname($this->irc_server), $this->irc_port ) ); + fclose ($this->fp); + } + + function irc_do_loop () + { + $begin_time = time(); + $bigbuf = ''; + while (1) + { + $bufr = fgets ($this->socket, 1024); + /* If this big has a end of line feed in it, we want to process it. + * if not, its just a partial, save it and try again */ + if(preg_match('/[\n]$/', $bufr)) + { + $bufr = $bigbuf . $bufr; + $bigbuf = ''; + fwrite($this->fp, sprintf( "[%s] %s", date("YmdHis"), $bufr)); + + $data = explode (' ', rtrim ($bufr), 4); + for ($i = 0; $i < count ($data); $i++) + { + $data[$i] = ltrim ($data[$i], ':'); + } + + if ( $data[0] == 'PING' ) { + $this->irc_send_msg (sprintf ("PONG %s", $data[1]), FALSE); + continue; + } + + if ( array_key_exists ($data[1], $this->callback_handlers) ) + { + if($this->callback_handlers[$data[1]] ( $data, $this ) == FALSE) + { + break; + } + } + } + else + { + $bigbuf = $bufr; + fwrite($this->fp, sprintf( "[%s] %s\n", date("YmdHis"), "No data yet, sleeping..")); + fflush($this->fp); + sleep(2); + } + if(time() - $begin_time > 60) + { + if(array_key_exists('timeout', $this->callback_handlers)) + { + set_time_limit(30); // dont time out php + $begin_time = time(); + if($this->callback_handlers['timeout'] (null, $this) == FALSE) + { + break; + } + } + } + } + } + + function irc_register_callback ($event, $callback) + { + $this->callback_handlers[$event] = $callback; + } + + function irc_unregister_callback ($event) + { + $this->callback_handlers[$event] = NULL; + } + + function irc_send_msg ($msg) + { + set_socket_blocking($this->socket, TRUE); + fwrite($this->fp, sprintf( "[%s] %s\n", date("YmdHis"), $msg)); + fputs ($this->socket, sprintf ("%s\n", $msg)); + set_socket_blocking($this->socket, FALSE); + + } +} +?> Index: x2/tools/com_cservice/classes/template.php diff -u /dev/null x2/tools/com_cservice/classes/template.php:1.1 --- /dev/null Mon Jun 6 15:28:44 2005 +++ x2/tools/com_cservice/classes/template.php Mon Jun 6 15:28:33 2005 @@ -0,0 +1,967 @@ +<?php +/* + * Session Management for PHP3 + * + * (C) Copyright 1999-2000 NetUSE GmbH + * Kristian Koehntopp + * + * $Id: template.php,v 1.1 2005/06/06 22:28:33 rubin Exp $ + * + */ + +/* + * Change log since version 7.2c + * + * Bug fixes to version 7.2c compiled by Richard Archer <rh...@ju...>: + * (credits given to first person to post a diff to phplib mailing list) + * + * Normalised all comments and whitespace (rha) + * replaced "$handle" with "$varname" and "$h" with "$v" throughout (from phplib-devel) + * added braces around all one-line if statements in: get_undefined, loadfile and halt (rha) + * set_var was missing two sets of braces (rha) + * added a couple of "return true" statements (rha) + * set_unknowns had "keep" as default instead of "remove" (from phplib-devel) + * set_file failed to check for empty strings if passed an array of filenames (phplib-devel) + * remove @ from call to preg_replace in subst -- report errors if there are any (NickM) + * set_block unnecessarily required a newline in the template file (Marc Tardif) + * pparse now calls this->finish to replace undefined vars (Layne Weathers) + * get_var now checks for unset varnames (NickM & rha) + * get_var when passed an array used the array key instead of the value (rha) + * get_vars now uses a call to get_var rather than this->varvals to prevent undefined var warning (rha) + * in finish, the replacement string referenced an unset variable (rha) + * loadfile would try to load a file if the varval had been set to "" (rha) + * in get_undefined, only match non-whitespace in variable tags as in finish (Layne Weathers & rha) + * more elegant fix to the problem of subst stripping '$n', '\n' and '\\' strings (rha) + * + * + * Changes in functionality which go beyond bug fixes: + * + * changed debug handling so set, get and internals can be tracked separately (rha) + * added debug statements throughout to track most function calls (rha) + * debug output contained raw HTML -- is now escaped with htmlentities (rha) + * Alter regex in set_block to remove more whitespace around BEGIN/END tags to improve HTML layout (rha) + * Add "append" option to set_var, works just like append in parse (dale at linuxwebpro.com, rha) + * Altered parse so that append is honored if passed an array (Brian) + * Converted comments and documentation to phpdoc style (rha) + * Added clear_var to set the value of variables to "" (rha) + * Added unset_var to usset variables (rha) + * + */ + +/** + * The template class allows you to keep your HTML code in some external files + * which are completely free of PHP code, but contain replacement fields. + * The class provides you with functions which can fill in the replacement fields + * with arbitrary strings. These strings can become very large, e.g. entire tables. + * + * Note: If you think that this is like FastTemplates, read carefully. It isn't. + * + */ + +class Template +{ + /** + * Serialization helper, the name of this class. + * + * @var string + * @access public + */ + var $classname = "Template"; + + /** + * Determines how much debugging output Template will produce. + * This is a bitwise mask of available debug levels: + * 0 = no debugging + * 1 = debug variable assignments + * 2 = debug calls to get variable + * 4 = debug internals (outputs all function calls with parameters). + * + * Note: setting $this->debug = true will enable debugging of variable + * assignments only which is the same behaviour as versions up to release 7.2d. + * + * @var int + * @access public + */ + var $debug = false; + + /** + * The base directory from which template files are loaded. + * + * @var string + * @access private + * @see set_root + */ + var $root = "components/com_cservice"; + + /** + * A hash of strings forming a translation table which translates variable names + * into names of files containing the variable content. + * $file[varname] = "filename"; + * + * @var array + * @access private + * @see set_file + */ + var $file = array(); + + /** + * A hash of strings forming a translation table which translates variable names + * into regular expressions for themselves. + * $varkeys[varname] = "/varname/" + * + * @var array + * @access private + * @see set_var + */ + var $varkeys = array(); + + /** + * A hash of strings forming a translation table which translates variable names + * into values for their respective varkeys. + * $varvals[varname] = "value" + * + * @var array + * @access private + * @see set_var + */ + var $varvals = array(); + + /** + * Determines how to output variable tags with no assigned value in templates. + * + * @var string + * @access private + * @see set_unknowns + */ + var $unknowns = "remove"; + + /** + * Determines how Template handles error conditions. + * "yes" = the error is reported, then execution is halted + * "report" = the error is reported, then execution continues by returning "false" + * "no" = errors are silently ignored, and execution resumes reporting "false" + * + * @var string + * @access public + * @see halt + */ + var $halt_on_error = "yes"; + + /** + * The last error message is retained in this variable. + * + * @var string + * @access public + * @see halt + */ + var $last_error = ""; + + /****************************************************************************** + * Class constructor. May be called with two optional parameters. + * The first parameter sets the template directory the second parameter + * sets the policy regarding handling of unknown variables. + * + * usage: Template([string $root = "."], [string $unknowns = "remove"]) + * + * @param $root path to template directory + * @param $string what to do with undefined variables + * @see set_root + * @see set_unknowns + * @access public + * @return void + */ + function Template($root = null, $unknowns = "remove") { + if($root == null) + $root = $this->root; + if ($this->debug & 4) { + echo "<p><b>Template:</b> root = $root, unknowns = $unknowns</p>\n"; + } + $this->set_root($root); + $this->set_unknowns($unknowns); + } + + + /****************************************************************************** + * Checks that $root is a valid directory and if so sets this directory as the + * base directory from which templates are loaded by storing the value in + * $this->root. Relative filenames are prepended with the path in $this->root. + * + * Returns true on success, false on error. + * + * usage: set_root(string $root) + * + * @param $root string containing new template directory + * @see root + * @access public + * @return boolean + */ + function set_root($root) { + if ($this->debug & 4) { + echo "<p><b>set_root:</b> root = $root</p>\n"; + } + if (!is_dir($root)) { + $this->halt("set_root: $root is not a directory."); + return false; + } + + $this->root = $root; + return true; + } + + + /****************************************************************************** + * Sets the policy for dealing with unresolved variable names. + * + * unknowns defines what to do with undefined template variables + * "remove" = remove undefined variables + * "comment" = replace undefined variables with comments + * "keep" = keep undefined variables + * + * Note: "comment" can cause unexpected results when the variable tag is embedded + * inside an HTML tag, for example a tag which is expected to be replaced with a URL. + * + * usage: set_unknowns(string $unknowns) + * + * @param $unknowns new value for unknowns + * @see unknowns + * @access public + * @return void + */ + function set_unknowns($unknowns = "remove") { + if ($this->debug & 4) { + echo "<p><b>unknowns:</b> unknowns = $unknowns</p>\n"; + } + $this->unknowns = $unknowns; + } + + + /****************************************************************************** + * Defines a filename for the initial value of a variable. + * + * It may be passed either a varname and a file name as two strings or + * a hash of strings with the key being the varname and the value + * being the file name. + * + * The new mappings are stored in the array $this->file. + * The files are not loaded yet, but only when needed. + * + * Returns true on success, false on error. + * + * usage: set_file(array $filelist = (string $varname => string $filename)) + * or + * usage: set_file(string $varname, string $filename) + * + * @param $varname either a string containing a varname or a hash of varname/file name pairs. + * @param $filename if varname is a string this is the filename otherwise filename is not required + * @access public + * @return boolean + */ + function set_file($varname, $filename = "") { + if (!is_array($varname)) { + if ($this->debug & 4) { + echo "<p><b>set_file:</b> (with scalar) varname = $varname, filename = $filename</p>\n"; + } + if ($filename == "") { + $this->halt("set_file: For varname $varname filename is empty."); + return false; + } + $this->file[$varname] = $this->filename($filename); + } else { + reset($varname); + while(list($v, $f) = each($varname)) { + if ($this->debug & 4) { + echo "<p><b>set_file:</b> (with array) varname = $v, filename = $f</p>\n"; + } + if ($f == "") { + $this->halt("set_file: For varname $v filename is empty."); + return false; + } + $this->file[$v] = $this->filename($f); + } + } + return true; + } + + + /****************************************************************************** + * A variable $parent may contain a variable block defined by: + * <!-- BEGIN $varname --> content <!-- END $varname -->. This function removes + * that block from $parent and replaces it with a variable reference named $name. + * The block is inserted into the varkeys and varvals hashes. If $name is + * omitted, it is assumed to be the same as $varname. + * + * Blocks may be nested but care must be taken to extract the blocks in order + * from the innermost block to the outermost block. + * + * Returns true on success, false on error. + * + * usage: set_block(string $parent, string $varname, [string $name = ""]) + * + * @param $parent a string containing the name of the parent variable + * @param $varname a string containing the name of the block to be extracted + * @param $name the name of the variable in which to store the block + * @access public + * @return boolean + */ + function set_block($parent, $varname, $name = "") { + if ($this->debug & 4) { + echo "<p><b>set_block:</b> parent = $parent, varname = $varname, name = $name</p>\n"; + } + if (!$this->loadfile($parent)) { + $this->halt("set_block: unable to load $parent."); + return false; + } + if ($name == "") { + $name = $varname; + } + + $str = $this->get_var($parent); + $reg = "/[ \t]*<!--\s+BEGIN $varname\s+-->\s*?\n?(\s*.*?\n?)\s*<!--\s+END $varname\s+-->\s*?\n?/sm"; + preg_match_all($reg, $str, $m); + $str = preg_replace($reg, "{" . "$name}", $str); + $this->set_var($varname, $m[1][0]); + $this->set_var($parent, $str); + return true; + } + + + /****************************************************************************** + * This functions sets the value of a variable. + * + * It may be called with either a varname and a value as two strings or an + * an associative array with the key being the varname and the value being + * the new variable value. + * + * The function inserts the new value of the variable into the $varkeys and + * $varvals hashes. It is not necessary for a variable to exist in these hashes + * before calling this function. + * + * An optional third parameter allows the value for each varname to be appended + * to the existing variable instead of replacing it. The default is to replace. + * This feature was introduced after the 7.2d release. + * + * + * usage: set_var(string $varname, [string $value = ""], [boolean $append = false]) + * or + * usage: set_var(array $varname = (string $varname => string $value), [mixed $dummy_var], [boolean $append = false]) + * + * @param $varname either a string containing a varname or a hash of varname/value pairs. + * @param $value if $varname is a string this contains the new value for the variable otherwise this parameter is ignored + * @param $append if true, the value is appended to the variable's existing value + * @access public + * @return void + */ + function set_var($varname, $value = "", $append = false) { + if (!is_array($varname)) { + if (!empty($varname)) { + if ($this->debug & 1) { + printf("<b>set_var:</b> (with scalar) <b>%s</b> = '%s'<br>\n", $varname, htmlentities($value)); + } + $this->varkeys[$varname] = "/".$this->varname($varname)."/"; + if ($append && isset($this->varvals[$varname])) { + $this->varvals[$varname] .= $value; + } else { + $this->varvals[$varname] = $value; + } + } + } else { + reset($varname); + while(list($k, $v) = each($varname)) { + if (!empty($k)) { + if ($this->debug & 1) { + printf("<b>set_var:</b> (with array) <b>%s</b> = '%s'<br>\n", $k, htmlentities($v)); + } + $this->varkeys[$k] = "/".$this->varname($k)."/"; + if ($append && isset($this->varvals[$k])) { + $this->varvals[$k] .= $v; + } else { + $this->varvals[$k] = $v; + } + } + } + } + } + + + /****************************************************************************** + * This functions clears the value of a variable. + * + * It may be called with either a varname as a string or an array with the + * values being the varnames to be cleared. + * + * The function sets the value of the variable in the $varkeys and $varvals + * hashes to "". It is not necessary for a variable to exist in these hashes + * before calling this function. + * + * + * usage: clear_var(string $varname) + * or + * usage: clear_var(array $varname = (string $varname)) + * + * @param $varname either a string containing a varname or an array of varnames. + * @access public + * @return void + */ + function clear_var($varname) { + if (!is_array($varname)) { + if (!empty($varname)) { + if ($this->debug & 1) { + printf("<b>clear_var:</b> (with scalar) <b>%s</b><br>\n", $varname); + } + $this->set_var($varname, ""); + } + } else { + reset($varname); + while(list($k, $v) = each($varname)) { + if (!empty($v)) { + if ($this->debug & 1) { + printf("<b>clear_var:</b> (with array) <b>%s</b><br>\n", $v); + } + $this->set_var($v, ""); + } + } + } + } + + + /****************************************************************************** + * This functions unsets a variable completely. + * + * It may be called with either a varname as a string or an array with the + * values being the varnames to be cleared. + * + * The function removes the variable from the $varkeys and $varvals hashes. + * It is not necessary for a variable to exist in these hashes before calling + * this function. + * + * + * usage: unset_var(string $varname) + * or + * usage: unset_var(array $varname = (string $varname)) + * + * @param $varname either a string containing a varname or an array of varnames. + * @access public + * @return void + */ + function unset_var($varname) { + if (!is_array($varname)) { + if (!empty($varname)) { + if ($this->debug & 1) { + printf("<b>unset_var:</b> (with scalar) <b>%s</b><br>\n", $varname); + } + unset($this->varkeys[$varname]); + unset($this->varvals[$varname]); + } + } else { + reset($varname); + while(list($k, $v) = each($varname)) { + if (!empty($v)) { + if ($this->debug & 1) { + printf("<b>unset_var:</b> (with array) <b>%s</b><br>\n", $v); + } + unset($this->varkeys[$v]); + unset($this->varvals[$v]); + } + } + } + } + + + /****************************************************************************** + * This function fills in all the variables contained within the variable named + * $varname. The resulting value is returned as the function result and the + * original value of the variable varname is not changed. The resulting string + * is not "finished", that is, the unresolved variable name policy has not been + * applied yet. + * + * Returns: the value of the variable $varname with all variables substituted. + * + * usage: subst(string $varname) + * + * @param $varname the name of the variable within which variables are to be substituted + * @access public + * @return string + */ + function subst($varname) { + $varvals_quoted = array(); + if ($this->debug & 4) { + echo "<p><b>subst:</b> varname = $varname</p>\n"; + } + if (!$this->loadfile($varname)) { + $this->halt("subst: unable to load $varname."); + return false; + } + + // quote the replacement strings to prevent bogus stripping of special chars + reset($this->varvals); + while(list($k, $v) = each($this->varvals)) { + $varvals_quoted[$k] = preg_replace(array('/\\\\/', '/\$/'), array('\\\\\\\\', '\\\\$'), $v); + } + + $str = $this->get_var($varname); + $str = preg_replace($this->varkeys, $varvals_quoted, $str); + return $str; + } + + + /****************************************************************************** + * This is shorthand for print $this->subst($varname). See subst for further + * details. + * + * Returns: always returns false. + * + * usage: psubst(string $varname) + * + * @param $varname the name of the variable within which variables are to be substituted + * @access public + * @return false + * @see subst + */ + function psubst($varname) { + if ($this->debug & 4) { + echo "<p><b>psubst:</b> varname = $varname</p>\n"; + } + print $this->subst($varname); + + return false; + } + + + /****************************************************************************** + * The function substitutes the values of all defined variables in the variable + * named $varname and stores or appends the result in the variable named $target. + * + * It may be called with either a target and a varname as two strings or a + * target as a string and an array of variable names in varname. + * + * The function inserts the new value of the variable into the $varkeys and + * $varvals hashes. It is not necessary for a variable to exist in these hashes + * before calling this function. + * + * An optional third parameter allows the value for each varname to be appended + * to the existing target variable instead of replacing it. The default is to + * replace. + * + * If $target and $varname are both strings, the substituted value of the + * variable $varname is inserted into or appended to $target. + * + * If $handle is an array of variable names the variables named by $handle are + * sequentially substituted and the result of each substitution step is + * inserted into or appended to in $target. The resulting substitution is + * available in the variable named by $target, as is each intermediate step + * for the next $varname in sequence. Note that while it is possible, it + * is only rarely desirable to call this function with an array of varnames + * and with $append = true. This append feature was introduced after the 7.2d + * release. + * + * Returns: the last value assigned to $target. + * + * usage: parse(string $target, string $varname, [boolean $append]) + * or + * usage: parse(string $target, array $varname = (string $varname), [boolean $append]) + * + * @param $target a string containing the name of the variable into which substituted $varnames are to be stored + * @param $varname if a string, the name the name of the variable to substitute or if an array a list of variables to be substituted + * @param $append if true, the substituted variables are appended to $target otherwise the existing value of $target is replaced + * @access public + * @return string + * @see subst + */ + function parse($target, $varname, $append = false) { + if (!is_array($varname)) { + if ($this->debug & 4) { + echo "<p><b>parse:</b> (with scalar) target = $target, varname = $varname, append = $append</p>\n"; + } + $str = $this->subst($varname); + if ($append) { + $this->set_var($target, $this->get_var($target) . $str); + } else { + $this->set_var($target, $str); + } + } else { + reset($varname); + while(list($i, $v) = each($varname)) { + if ($this->debug & 4) { + echo "<p><b>parse:</b> (with array) target = $target, i = $i, varname = $v, append = $append</p>\n"; + } + $str = $this->subst($v); + if ($append) { + $this->set_var($target, $this->get_var($target) . $str); + } else { + $this->set_var($target, $str); + } + } + } + + if ($this->debug & 4) { + echo "<p><b>parse:</b> completed</p>\n"; + } + return $str; + } + + + /****************************************************************************** + * This is shorthand for print $this->parse(...) and is functionally identical. + * See parse for further details. + * + * Returns: always returns false. + * + * usage: pparse(string $target, string $varname, [boolean $append]) + * or + * usage: pparse(string $target, array $varname = (string $varname), [boolean $append]) + * + * @param $target a string containing the name of the variable into which substituted $varnames are to be stored + * @param $varname if a string, the name the name of the variable to substitute or if an array a list of variables to be substituted + * @param $append if true, the substituted variables are appended to $target otherwise the existing value of $target is replaced + * @access public + * @return false + * @see parse + */ + function pparse($target, $varname, $append = false) { + if ($this->debug & 4) { + echo "<p><b>pparse:</b> passing parameters to parse...</p>\n"; + } + print $this->finish($this->parse($target, $varname, $append)); + return false; + } + + + /****************************************************************************** + * This function returns an associative array of all defined variables with the + * name as the key and the value of the variable as the value. + * + * This is mostly useful for debugging. Also note that $this->debug can be used + * to echo all variable assignments as they occur and to trace execution. + * + * Returns: a hash of all defined variable values keyed by their names. + * + * usage: get_vars() + * + * @access public + * @return array + * @see $debug + */ + function get_vars() { + if ($this->debug & 4) { + echo "<p><b>get_vars:</b> constructing array of vars...</p>\n"; + } + reset($this->varkeys); + while(list($k, $v) = each($this->varkeys)) { + $result[$k] = $this->get_var($k); + } + return $result; + } + + + /****************************************************************************** + * This function returns the value of the variable named by $varname. + * If $varname references a file and that file has not been loaded yet, the + * variable will be reported as empty. + * + * When called with an array of variable names this function will return a a + * hash of variable values keyed by their names. + * + * Returns: a string or an array containing the value of $varname. + * + * usage: get_var(string $varname) + * or + * usage: get_var(array $varname) + * + * @param $varname if a string, the name the name of the variable to get the value of, or if an array a list of variables to return the value of + * @access public + * @return string or array + */ + function get_var($varname) { + if (!is_array($varname)) { + if (isset($this->varvals[$varname])) { + $str = $this->varvals[$varname]; + } else { + $str = ""; + } + if ($this->debug & 2) { + printf ("<b>get_var</b> (with scalar) <b>%s</b> = '%s'<br>\n", $varname, htmlentities($str)); + } + return $str; + } else { + reset($varname); + while(list($k, $v) = each($varname)) { + if (isset($this->varvals[$v])) { + $str = $this->varvals[$v]; + } else { + $str = ""; + } + if ($this->debug & 2) { + printf ("<b>get_var:</b> (with array) <b>%s</b> = '%s'<br>\n", $v, htmlentities($str)); + } + $result[$v] = $str; + } + return $result; + } + } + + + /****************************************************************************** + * This function returns a hash of unresolved variable names in $varname, keyed + * by their names (that is, the hash has the form $a[$name] = $name). + * + * Returns: a hash of varname/varname pairs or false on error. + * + * usage: get_undefined(string $varname) + * + * @param $varname a string containing the name the name of the variable to scan for unresolved variables + * @access public + * @return array + */ + function get_undefined($varname) { + if ($this->debug & 4) { + echo "<p><b>get_undefined:</b> varname = $varname</p>\n"; + } + if (!$this->loadfile($varname)) { + $this->halt("get_undefined: unable to load $varname."); + return false; + } + + preg_match_all("/{([^ \t\r\n}]+)}/", $this->get_var($varname), $m); + $m = $m[1]; + if (!is_array($m)) { + return false; + } + + reset($m); + while(list($k, $v) = each($m)) { + if (!isset($this->varkeys[$v])) { + if ($this->debug & 4) { + echo "<p><b>get_undefined:</b> undefined: $v</p>\n"; + } + $result[$v] = $v; + } + } + + if (count($result)) { + return $result; + } else { + return false; + } + } + + + /****************************************************************************** + * This function returns the finished version of $str. That is, the policy + * regarding unresolved variable names will be applied to $str. + * + * Returns: a finished string derived from $str and $this->unknowns. + * + * usage: finish(string $str) + * + * @param $str a string to which to apply the unresolved variable policy + * @access public + * @return string + * @see set_unknowns + */ + function finish($str) { + switch ($this->unknowns) { + case "keep": + break; + + case "remove": + $str = preg_replace('/{[^ \t\r\n}]+}/', "", $str); + break; + + case "comment": + $str = preg_replace('/{([^ \t\r\n}]+)}/', "<!-- Template variable \\1 undefined -->", $str); + break; + } + + return $str; + } + + + /****************************************************************************** + * This function prints the finished version of the value of the variable named + * by $varname. That is, the policy regarding unresolved variable names will be + * applied to the variable $varname then it will be printed. + * + * usage: p(string $varname) + * + * @param $varname a string containing the name of the variable to finish and print + * @access public + * @return void + * @see set_unknowns + * @see finish + */ + function p($varname) { + print $this->finish($this->get_var($varname)); + } + + + /****************************************************************************** + * This function returns the finished version of the value of the variable named + * by $varname. That is, the policy regarding unresolved variable names will be + * applied to the variable $varname and the result returned. + * + * Returns: a finished string derived from the variable $varname. + * + * usage: get(string $varname) + * + * @param $varname a string containing the name of the variable to finish + * @access public + * @return void + * @see set_unknowns + * @see finish + */ + function get($varname) { + return $this->finish($this->get_var($varname)); + } + + + /****************************************************************************** + * When called with a relative pathname, this function will return the pathname + * with $this->root prepended. Absolute pathnames are returned unchanged. + * + * Returns: a string containing an absolute pathname. + * + * usage: filename(string $filename) + * + * @param $filename a string containing a filename + * @access private + * @return string + * @see set_root + */ + function filename($filename) { + if ($this->debug & 4) { + echo "<p><b>filename:</b> filename = $filename</p>\n"; + } + if (substr($filename, 0, 1) != "/") { + $filename = $this->root."/".$filename; + } + + if (!file_exists($filename)) { + $this->halt("filename: file $filename does not exist."); + } + return $filename; + } + + + /****************************************************************************** + * This function will construct a regexp for a given variable name with any + * special chars quoted. + * + * Returns: a string containing an escaped variable name. + * + * usage: varname(string $varname) + * + * @param $varname a string containing a variable name + * @access private + * @return string + */ + function varname($varname) { + return preg_quote("{".$varname."}"); + } + + + /****************************************************************************** + * If a variable's value is undefined and the variable has a filename stored in + * $this->file[$varname] then the backing file will be loaded and the file's + * contents will be assigned as the variable's value. + * + * Note that the behaviour of this function changed slightly after the 7.2d + * release. Where previously a variable was reloaded from file if the value + * was empty, now this is not done. This allows a variable to be loaded then + * set to "", and also prevents attempts to load empty variables. Files are + * now only loaded if $this->varvals[$varname] is unset. + * + * Returns: true on success, false on error. + * + * usage: loadfile(string $varname) + * + * @param $varname a string containing the name of a variable to load + * @access private + * @return boolean + * @see set_file + */ + function loadfile($varname) { + if ($this->debug & 4) { + echo "<p><b>loadfile:</b> varname = $varname</p>\n"; + } + + if (!isset($this->file[$varname])) { + // $varname does not reference a file so return + if ($this->debug & 4) { + echo "<p><b>loadfile:</b> varname $varname does not reference a file</p>\n"; + } + return true; + } + + if (isset($this->varvals[$varname])) { + // will only be unset if varname was created with set_file and has never been loaded + // $varname has already been loaded so return + if ($this->debug & 4) { + echo "<p><b>loadfile:</b> varname $varname is already loaded</p>\n"; + } + return true; + } + $filename = $this->file[$varname]; + + /* use @file here to avoid leaking filesystem information if there is an error */ + $str = implode("", @file($filename)); + if (empty($str)) { + $this->halt("loadfile: While loading $varname, $filename does not exist or is empty."); + return false; + } + + if ($this->debug & 4) { + printf("<b>loadfile:</b> loaded $filename into $varname<br>\n"); + } + $this->set_var($varname, $str); + + return true; + } + + + /****************************************************************************** + * This function is called whenever an error occurs and will handle the error + * according to the policy defined in $this->halt_on_error. Additionally the + * error message will be saved in $this->last_error. + * + * Returns: always returns false. + * + * usage: halt(string $msg) + * + * @param $msg a string containing an error message + * @access private + * @return void + * @see $halt_on_error + */ + function halt($msg) { + $this->last_error = $msg; + + if ($this->halt_on_error != "no") { + $this->haltmsg($msg); + } + + if ($this->halt_on_error == "yes") { + die("<b>Halted.</b>"); + } + + return false; + } + + + /****************************************************************************** + * This function prints an error message. + * It can be overridden by your subclass of Template. It will be called with an + * error message to display. + * + * usage: haltmsg(string $msg) + * + * @param $msg a string containing the error message to display + * @access public + * @return void + * @see halt + */ + function haltmsg($msg) { + printf("<b>Template Error:</b> %s<br>\n", $msg); + } + +} +?> Index: x2/tools/com_cservice/config.php diff -u /dev/null x2/tools/com_cservice/config.php:1.1 --- /dev/null Mon Jun 6 15:28:44 2005 +++ x2/tools/com_cservice/config.php Mon Jun 6 15:28:33 2005 @@ -0,0 +1,35 @@ +<?php +$irc_nick = 'regbot'; +$irc_user = 'regbot'; +$irc_name = 'X2 Web Link'; +// your webservers host. is ignored by irc server anyway.. +$irc_host = '127.0.0.1'; +// Your irc server and port +$irc_server = '127.0.0.1:6667'; +// Nick of your x2 service +$irc_botnick = 'X2'; +// NOTE. If you are another customer on this machine reading +// this file with php or cgi scripts please know that +// if you use this password to oper without autorization +// I will hunt you down and kill you. +// this is not an idle threat. Keep out of here, i mean it. +$irc_oper = 'oper oname opassword'; + +// Mysql info (used to store rate info and log signups) +$db_server = 'localhost'; +$db_port = ''; +$db_user = 'dbuser'; +$db_pass = 'dbpass'; +$db_database = 'dbname'; +$db_table = 'chanreg'; + +/* $my comes from mambo.. */ +$channel_name = ''; +$channel_owner_handle = $my->userid; +$channel_owner_email = $my->email; +$channel_owner_password = ''; +$channel_default_modes = ''; +$channel_default_topic = ''; + +//$debug = 1; +?> Index: x2/tools/com_cservice/cservice.php diff -u /dev/null x2/tools/com_cservice/cservice.php:1.1 --- /dev/null Mon Jun 6 15:28:44 2005 +++ x2/tools/com_cservice/cservice.php Mon Jun 6 15:28:33 2005 @@ -0,0 +1,426 @@ +<?php +require_once ('classes/ircclient.php'); +require_once ('classes/template.php'); +require_once ('config.php'); +require_once ('regex.php'); + +define ('IRC_LOG_COMMUNICATIONS', TRUE); + +function do_step_one ( ) +{ + global $tpl, $channel_name, $channel_owner_handle, + $channel_owner_email, $channel_owner_password, + $irc, $irc_nick, $irc_user, $irc_name, $irc_host, + $irc_server, $irc_botnick, $dbx, $db_server, + $db_port, $db_user, $db_pass, $db_database, + $db_table; + + $tpl->set_file ('main', 'templates/aup.html'); + $tpl->set_block ('main', 'ErrorBlock', 'error_used_block'); + $tpl->set_var ( array ( + 'txtChannelName', + 'txtOwnerHandle', + 'txtOwnerPassword', + 'txtOwnerEmail' + ) ); + include ("lang/en.php"); + $tpl->pparse ('out', 'main'); +} + +function makePass() { + $makepass=""; + $syllables="er,in,tia,wol,fe,pre,vet,jo,nes,al,len,son,cha,ir,ler,bo,ok,tio,nar,sim,ple,bla,ten,toe,cho,co,lat,spe,ak,er,po,co,lor,pen,cil,li,ght,wh,at,the,he,ck,is,mam,bo,no,fi,ve,any,way,pol,iti,cs,ra,dio,sou,rce,sea,rch,pa,per,com,bo,sp,eak,st,fi,rst,gr,oup,boy,ea,gle,tr,ail,bi,ble,brb,pri,dee,kay,en,be,se"; + $syllable_array=explode(",", $syllables); + srand((double)microtime()*1000000); + for ($count=1;$count<=4;$count++) { + if (rand()%10 == 1) { + $makepass .= sprintf("%0.0f",(rand()%50)+1); + } else { + $makepass .= sprintf("%s",$syllable_array[rand()%62]); + } + } + return($makepass); +} + +function do_step_two() +{ + global $my, $tpl, $channel_name, $channel_owner_handle, + $channel_owner_email, $channel_owner_password, + $irc, $irc_nick, $irc_user, $irc_name, $irc_host, + $irc_server, $irc_botnick, $dbx, $db_server, + $db_port, $db_user, $db_pass, $db_database, + $db_table; + + $errors = array(); + $i = 0; + + $channel_name = post_clean ($_REQUEST['channel_name']); + + $channel_owner_handle = $my->username; + + $sql = "SELECT email FROM mos_users WHERE id=$my->id"; + $res = db_query($sql); + if(mysql_num_rows($res) < 1) + { + $errors[] = '{errYourIDWasNotFound}'; + } + else + { + $channel_owner_email = mysql_result($res, 0); + } + + $channel_owner_password = makePass(); + if ( !isset($_POST['iagree']) || $_POST['iagree'] <> 'true' ) + { + $errors[] = '{errAupNotAccepted}'; + } + if ( !validate_channel ($channel_name, 1, 49) ) { + $errors[] = '{errInvalidChannelName}'; + } + + else if ( channel_registered ($channel_name) ) { + $errors[] = '{errChannelIsRegisterd}'; + } + + + if ( count ($errors) > 0 ) + { + $tpl->set_file ('main', 'templates/aup.html'); + $tpl->set_var ( array ( + 'txtChannelName' => $channel_name, + ) ); + $tpl->set_block ('main', 'ErrorBlock', 'error_blk'); + + for ($i = 0; $i < count ($errors); $i++) + { + $tpl->set_var ('error', $errors[$i]); + $tpl->parse ('error_blk', 'ErrorBlock', true); + } + + include ("lang/en.php"); + $tpl->pparse ('out', 'main'); + } + + else + { + + $irc = new IRCClient ($irc_nick, $irc_user, $irc_name, $irc_host); + $irc->irc_register_callback ('001', 'irc_on_connect'); + $irc->irc_register_callback ('433', 'irc_on_nicknameinuse'); + $irc->irc_register_callback ('PRIVMSG', 'irc_on_privmsg'); + $irc->irc_register_callback ('NOTICE', 'irc_on_privmsg'); + $irc->irc_register_callback ('timeout', 'irc_on_timeout'); + $irc->irc_connect($irc_server); + return; + + } +} + +/* The purpose of this is.. ??? */ +function post_clean ( $key ) +{ + return trim ($key); +} + +function validate_channel ( $channel, $min=1, $max=200 ) +{ + global $_channel; + + // if ( preg_match ("/^{$_channel}{{$min},{$max}}$/", $channel) ) { + + if ( preg_match ('/^[#][A-Za-z0-9][A-Za-z0-9_.{}-]*$/', $channel) ) { + return true; + } + return false; +} + +function channel_registered ( $channel ) +{ + // DEBUG: Temp disabling due to + // lack of x2 on this server + return false; + global $chandatpath; + + $cf = fopen($chandatpath, "r"); + if($cf) + { + while($chans = fscanf($cf, "%s")) + { + list($chan) = $chans; + if(!strcasecmp($chan,$channel) or !strcasecmp($channel, "#afternet") or + !strcasecmp($channel, "#help") or + !strcasecmp($channel, "#Operations") ) + $conflict = 1; + } + } + if($conflict) + { + return true; + } + + return false; +} + +function db_connect () +{ + global $dbx; + global $db_server, $db_port, $db_user, $db_pass, $db_database; + + $dbx = @mysql_connect ("{$db_server}:{$db_port}", $db_user, $db_pass); + @mysql_select_db ($db_database); + + return $dbx; +} + +function db_query ( $query ) +{ + $dbx = db_connect(); + $res = @mysql_query ($query, $dbx); + + if (!$res) { + global $tpl; + $tpl->set_file ('main', 'templates/dberror.html'); + $tpl->set_var ('query', $query); + $tpl->set_var ('error', @mysql_error()); + $tpl->set_var ('errno', @mysql_errno()); + $tpl->pparse ('out', 'main'); + exit; + } + + return $res; +} + +function irc_on_connect ( $data, $object ) +{ + global $tpl, $channel_name, $channel_owner_handle, + $channel_owner_password, $channel_owner_email, + $irc, $irc_nick, $irc_user, $irc_name, $irc_host, + $irc_server, $irc_botnick, $irc_oper, $dbx, $db_server, + $db_port, $db_user, $db_pass, $db_database, + $db_table; + + /* We connected successfully. Send oper and scriptreg */ + $object->irc_send_msg("$irc_oper"); + $object->irc_send_msg ( + preg_replace('/[\n]/','', // no hacking me!! + sprintf ("PRIVMSG %s :SCRIPTREG %s %s %s %s %s", + $irc_botnick, $channel_name, $channel_owner_handle, + $channel_owner_password, $channel_owner_email, '+nt' ) + ) + ); + return(TRUE); +} + +function irc_on_privmsg ( $data, $object ) +{ + global $tpl, $channel_name, $channel_owner_handle, + $channel_owner_email, $channel_owner_password, + $irc, $irc_nick, $irc_user, $irc_name, $irc_host, + $irc_server, $irc_botnick, $dbx, $db_server, + $db_port, $db_user, $db_pass, $db_database, + $db_table; + + $nick = substr ($data[0], 0, strpos ($data[0], '!')); + + $data[3] = str_replace("\002", "", $data[3]); + if ( (strtoupper($data[2]) == strtoupper($object->irc_nick)) && ($nick == $irc_botnick) ) { + if ( preg_match ("/Owner\:\ SUCCESS/", $data[3]) ) { + $object->irc_disconnect(); + $query = sprintf ("insert into chanreg set channel_name='%s', + owner_handle='%s', owner_email='%s', owner_pass='%s', + status='OK', result='%s', timestamp=NULL, ip='%s'", + mysql_escape_string($channel_name), + mysql_escape_string($channel_owner_handle), + mysql_escape_string($channel_owner_email), + md5($channel_owner_password), + mysql_escape_string($data[3]), + $_SERVER['REMOTE_ADDR'] ); + $res = db_query ($query); + $tpl->set_file ('main', 'templates/regsuccess.html'); + $tpl->set_var ('owner_handle', $channel_owner_handle); + $tpl->set_var ('channel_name', $channel_name); + $tpl->set_var ('channel_owner_password', $channel_owner_password); + include ("lang/en.php"); + $tpl->pparse ('out', 'main'); + mail($channel_owner_email, "AfterNET channel registration for $channel_name", + "Just a reminder,\n". + "The channel registration for $channel_name has been\n". + "processed.\n\n". + "X2 is now in your channel. You can login by doing:\n". + "/msg x2 $channel_name login $channel_owner_handle $channel_owner_password\n\n ". + "Once logged in, please change your password by doing:\n". + "/msg x2 $channel_name pass $channel_owner_password yournewpassword\n\n". + "For more help with using x2, do /msg x2 help\n". + "Thanks,\n". + " AfterNET Support team\n". + "", + "From: su...@af...\nReply-To: su...@af...\n"); + + return(FALSE); + } + + elseif ( preg_match ("/(Registration Aborted|Error\:)/", $data[3]) ) { + $object->irc_disconnect(); + $query = sprintf ("insert into chanreg set channel_name='%s', + owner_handle='%s', owner_email='%s', owner_pass='%s', + status='ERR', result='%s', timestamp=NULL, ip='%s'", + mysql_escape_string($channel_name), + mysql_escape_string($channel_owner_handle), + mysql_escape_string($channel_owner_email), + md5($channel_owner_password), + mysql_escape_string($data[3]), + $_SERVER['REMOTE_ADDR'] ); + $res = db_query ($query); + $tpl->set_file ('main', 'templates/regfailed.html'); + $tpl->set_var ('owner_handle', $channel_owner_handle); + $tpl->set_var ('channel_name', $channel_name); + $tpl->set_var ('fail_reason', $data[3]); + include ("lang/en.php"); + $tpl->pparse ('out', 'main'); + return(FALSE); + } + } + return(TRUE); +} + +function irc_on_nicknameinuse ( $data, $object ) +{ + global $irc; + $irc->irc_nick = "{$irc->irc_nick}_"; + $irc->irc_send_msg (sprintf ("NICK %s", $irc->irc_nick)); + return(TRUE); +} + +function irc_on_timeout($data, $object) +{ + echo "Sorry, the registration process timed out. Please try again later."; + return(FALSE); +} + +function do_login_first() +{ + global $tpl, $channel_name, $channel_owner_handle, + $channel_owner_email, $channel_owner_password, + $irc, $irc_nick, $irc_user, $irc_name, $irc_host, + $irc_server, $irc_botnick, $dbx, $db_server, + $db_port, $db_user, $db_pass, $db_database, + $db_table; + + $tpl->set_file ('main', 'templates/must_login.html'); + include ("lang/en.php"); + $tpl->pparse ('out', 'main'); +} + +function do_show_too_many($reason) +{ + global $tpl, $channel_name, $channel_owner_handle, + $channel_owner_email, $channel_owner_password, + $irc, $irc_nick, $irc_user, $irc_name, $irc_host, + $irc_server, $irc_botnick, $dbx, $db_server, + $db_port, $db_user, $db_pass, $db_database, + $db_table; + + $tpl->set_file ('main', 'templates/too_many.html'); + $tpl->set_var ('Error', $reason); + include("lang/en.php"); + $tpl->pparse('out', 'main'); +} + + +function rate_limit() +{ + global $my; + global $tpl, $channel_name, $channel_owner_handle, + $channel_owner_email, $channel_owner_password, + $irc, $irc_nick, $irc_user, $irc_name, $irc_host, + $irc_server, $irc_botnick, $dbx, $db_server, + $db_port, $db_user, $db_pass, $db_database, + $db_table; + + /* 1 channel per day check */ + $yesterday = time() - (24 * 60 * 60); + $strSQL = " + select count(channel_name) + FROM chanreg + WHERE owner_handle='$my->username' + AND status='OK' + AND unix_timestamp(timestamp) > $yesterday + "; + $res = db_query($strSQL); + if(mysql_result($res, 0) > 0) + { + return("You may register only one channel per day"); + } + + /* 3 channels per month check */ + $lastmonth = time() - (24 * 60 * 60 * 30); + $strSQL = " + SELECT count(channel_name) + FROM chanreg + WHERE owner_handle='$my->username' + AND status='OK' + AND unix_timestamp(timestamp) > $lastmonth + "; + $res = db_query($strSQL); + if(mysql_result($res, 0) >= 3) + { + return("You may register only one channel per month"); + } + + /* max 100 channels per day for all users */ + $yesterday = time() - (24 * 60 * 60); + $strSQL = " + select count(channel_name) + FROM chanreg + WHERE status='OK' + AND unix_timestamp(timestamp) > $yesterday + "; + $res = db_query($strSQL); + if(mysql_result($res, 0) > 50) + { + return("Our registration system is currently overloaded. Please check back tomorrow."); + } + /* max 3 channels per day for same IP address */ + $yesterday = time() - (24 * 60 * 60); + $strSQL = " + select count(channel_name) + FROM chanreg + WHERE status='OK' + AND unix_timestamp(timestamp) > $yesterday + AND ip='$_SERVER[REMOTE_ADDR]' + "; + $res = db_query($strSQL); + if(mysql_result($res, 0) >= 3) + { + return("Too many registrations from your IP. Please contact us."); + } + return FALSE; +} + +$dbx = db_connect(); +$tpl = new Template(); +$irc = new IRCClient ($irc_nick, $irc_user, $irc_name, $irc_host); + +if(!$my->id) +{ + do_login_first(); +} +else +{ + switch ($_REQUEST['step']) + { + default: + case '1': + do_step_one(); + break; + + case '2': + $reason = rate_limit(); + if($reason) + do_show_too_many($reason); + else + do_step_two(); + break; + } +} +?> Index: x2/tools/com_cservice/help/errInvalidChannelName.html diff -u /dev/null x2/tools/com_cservice/help/errInvalidChannelName.html:1.1 --- /dev/null Mon Jun 6 15:28:44 2005 +++ x2/tools/com_cservice/help/errInvalidChannelName.html Mon Jun 6 15:28:33 2005 @@ -0,0 +1,16 @@ +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> +<html xmlns="http://www.w3.org/1999/xhtml"> +<head> +<title>Invalid Channel Name</title> +<script type="text/javascript" src="helpdocs.js"></script> +<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> +</head> +<body> +<h2>Invalid Channel Name</h2> +<p>Your channel name must be bewteen 1 and 49 characters in length and may contain only alpha-numeric characters (a-Z, 0-9).</p> +<p><code>Ex. #AfterNet</code></p> +<p align="center"> + <button onclick="close_help()">close</button> +</p> +</body> +</html> Index: x2/tools/com_cservice/help/errInvalidEmailDomain.html diff -u /dev/null x2/tools/com_cservice/help/errInvalidEmailDomain.html:1.1 --- /dev/null Mon Jun 6 15:28:44 2005 +++ x2/tools/com_cservice/help/errInvalidEmailDomain.html Mon Jun 6 15:28:33 2005 @@ -0,0 +1,15 @@ +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> +<html xmlns="http://www.w3.org/1999/xhtml"> +<head> +<title>Invalid E-Mail Domain Detected</title> +<script type="text/javascript" src="helpdocs.js"></script> +<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> +</head> +<body> +<h2>Invalid E-Mail Domain Detected</h2> +<p>We do not accept public or anonymous email accounts! DO NOT enter public free accounts such as hotmail, yahoo, or mail.com. Please use your real ISP email account. It will never be givin to anyone or used in any way other than to verify your identity and for us to contact you.</p> +<p align="center"> + <button onclick="close_help()">close</button> +</p> +</body> +</html> Index: x2/tools/com_cservice/help/errInvalidOwnerEmail.html diff -u /dev/null x2/tools/com_cservice/help/errInvalidOwnerEmail.html:1.1 --- /dev/null Mon Jun 6 15:28:44 2005 +++ x2/tools/com_cservice/help/errInvalidOwnerEmail.html Mon Jun 6 15:28:33 2005 @@ -0,0 +1,16 @@ +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> +<html xmlns="http://www.w3.org/1999/xhtml"> +<head> +<title>Invalid Owner E-mail Address</title> +<script type="text/javascript" src="helpdocs.js"></script> +<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> +</head> +<body> +<h2>Invalid Owner E-mail Address</h2> +<p>Your email address should be in the form of <user>@<host>.[com|net|org]. Please verify you enter the correct address, important information regarding channel registration will be sent to this address.</p> +<p><code>Ex. jo...@af...</code></p> +<p align="center"> + <button onclick="close_help()">close</button> +</p> +</body> +</html> Index: x2/tools/com_cservice/help/errInvalidOwnerHandle.html diff -u /dev/null x2/tools/com_cservice/help/errInvalidOwnerHandle.html:1.1 --- /dev/null Mon Jun 6 15:28:44 2005 +++ x2/tools/com_cservice/help/errInvalidOwnerHandle.html Mon Jun 6 15:28:33 2005 @@ -0,0 +1,16 @@ +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> +<html xmlns="http://www.w3.org/1999/xhtml"> +<head> +<title>Invalid Owner Handle</title> +<script type="text/javascript" src="helpdocs.js"></script> +<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> +</head> +<body> +<h2>Invalid Owner Handle</h2> +<p>Your handle (nickname) must be bewteen 1 and 30 characters in length and may contain only alpha-numeric characters (a-Z, 0-9).</p> +<p><code>Ex. john37m</code></p> +<p align="center"> + <button onclick="close_help()">close</button> +</p> +</body> +</html> Index: x2/tools/com_cservice/help/errInvalidOwnerPassword.html diff -u /dev/null x2/tools/com_cservice/help/errInvalidOwnerPassword.html:1.1 --- /dev/null Mon Jun 6 15:28:44 2005 +++ x2/tools/com_cservice/help/errInvalidOwnerPassword.html Mon Jun 6 15:28:33 2005 @@ -0,0 +1,16 @@ +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> +<html xmlns="http://www.w3.org/1999/xhtml"> +<head> +<title>Invalid Owner Password</title> +<script type="text/javascript" src="helpdocs.js"></script> +<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> +</head> +<body> +<h... [truncated message content] |