X-Git-Url: https://jfr.im/git/irc/quakenet/newserv.git/blobdiff_plain/25b7d0faff482c03a21571f968297c7f4c4a7737..2af7cf5058dcf0f326292e32c52e04ff52bc1252:/request/request.c diff --git a/request/request.c b/request/request.c index 30d9a965..7c192909 100644 --- a/request/request.c +++ b/request/request.c @@ -1,17 +1,23 @@ /* shroud's service request */ +#include #include #include "../localuser/localuser.h" #include "../localuser/localuserchannel.h" #include "../core/schedule.h" #include "../lib/irc_string.h" #include "../lib/splitline.h" +#include "../lib/version.h" #include "../control/control.h" +#include "../splitlist/splitlist.h" #include "request.h" #include "request_block.h" +#include "request_fasttrack.h" #include "lrequest.h" #include "sqrequest.h" +MODULE_VERSION(""); + nick *rqnick; CommandTree *rqcommands; @@ -25,7 +31,7 @@ int rqcmd_addblock(void *user, int cargc, char **cargv); int rqcmd_delblock(void *user, int cargc, char **cargv); int rqcmd_listblocks(void *user, int cargc, char **cargv); int rqcmd_stats(void *user, int cargc, char **cargv); -int rqcmd_legacyrequest(void *user, int cargc, char **cargv); +int rqcmd_requestop(void *user, int cargc, char **cargv); #define min(a,b) ((a > b) ? b : a) @@ -35,53 +41,72 @@ int rq_failed = 0; int rq_success = 0; int rq_blocked = 0; +/* log fd */ +FILE *rq_logfd; + +static int extloaded = 0; + void _init(void) { + if(!rq_initblocks()) + return; + + if(!rq_initfasttrack()) + return; + + extloaded = 1; + rqcommands = newcommandtree(); addcommandtotree(rqcommands, "showcommands", RQU_ANY, 1, &rqcmd_showcommands); addcommandtotree(rqcommands, "requestbot", RQU_ANY, 1, &rqcmd_request); addcommandtotree(rqcommands, "requestspamscan", RQU_ANY, 1, &rqcmd_requestspamscan); + addcommandtotree(rqcommands, "requestop", RQU_ANY, 2, &rqcmd_requestop); + addcommandtotree(rqcommands, "addblock", RQU_OPER, 3, &rqcmd_addblock); addcommandtotree(rqcommands, "delblock", RQU_OPER, 1, &rqcmd_delblock); addcommandtotree(rqcommands, "listblocks", RQU_OPER, 1, &rqcmd_listblocks); addcommandtotree(rqcommands, "stats", RQU_OPER, 1, &rqcmd_stats); - - /* old legacy stuff */ - addcommandtotree(rqcommands, "requestq", RQU_ANY, 1, &rqcmd_legacyrequest); - - rq_initblocks(); + qr_initrequest(); + rq_logfd = fopen(RQ_LOGFILE, "a"); + scheduleoneshot(time(NULL) + 1, (ScheduleCallback)&rq_registeruser, NULL); } void _fini(void) { + if(!extloaded) + return; + deregisterlocaluser(rqnick, NULL); deletecommandfromtree(rqcommands, "showcommands", &rqcmd_showcommands); deletecommandfromtree(rqcommands, "requestbot", &rqcmd_request); deletecommandfromtree(rqcommands, "requestspamscan", &rqcmd_requestspamscan); + deletecommandfromtree(rqcommands, "requestop", &rqcmd_requestop); + deletecommandfromtree(rqcommands, "addblock", &rqcmd_addblock); deletecommandfromtree(rqcommands, "delblock", &rqcmd_delblock); deletecommandfromtree(rqcommands, "listblocks", &rqcmd_listblocks); deletecommandfromtree(rqcommands, "stats", &rqcmd_stats); - /* old legacy stuff */ - deletecommandfromtree(rqcommands, "requestq", &rqcmd_legacyrequest); - destroycommandtree(rqcommands); rq_finiblocks(); + rq_finifasttrack(); qr_finirequest(); + if (rq_logfd != NULL) + fclose(rq_logfd); + deleteallschedules((ScheduleCallback)&rq_registeruser); } void rq_registeruser(void) { channel *cp; - rqnick = registerlocaluser(RQ_REQUEST_NICK, RQ_REQUEST_USER, RQ_REQUEST_HOST, - RQ_REQUEST_REAL, RQ_REQUEST_AUTH, + rqnick = registerlocaluserflags(RQ_REQUEST_NICK, RQ_REQUEST_USER, RQ_REQUEST_HOST, + RQ_REQUEST_REAL, RQ_REQUEST_AUTH, RQ_REQUEST_AUTHID, 0, UMODE_ACCOUNT | UMODE_SERVICE | UMODE_OPER, rq_handler); @@ -130,7 +155,7 @@ void rq_handler(nick *target, int type, void **params) { return; } - if (cmd->level & RQU_OPER && !IsOper(user)) { + if ((cmd->level & RQU_OPER) && !IsOper(user)) { sendnoticetouser(rqnick, user, "Sorry, this command is not " "available to you."); @@ -149,37 +174,40 @@ void rq_handler(nick *target, int type, void **params) { break; case LU_PRIVNOTICE: - qr_handlenotice(params[0], params[1]); + qr_handle_notice(params[0], params[1]); break; } } int rqcmd_showcommands(void *user, int cargc, char **cargv) { + nick* np = (nick*)user; int n, i; Command* cmdlist[50]; n = getcommandlist(rqcommands, cmdlist, 50); - sendnoticetouser(rqnick, (nick*)user, "Available commands:"); - sendnoticetouser(rqnick, (nick*)user, "-------------------"); + sendnoticetouser(rqnick, np, "Available commands:"); + sendnoticetouser(rqnick, np, "-------------------"); for (i = 0; i < n; i++) { - if ((cmdlist[i]->level & RQU_OPER) == 0 || IsOper((nick*)user)) - sendnoticetouser(rqnick, (nick*)user, "%s", cmdlist[i]->command->content); + if ((cmdlist[i]->level & RQU_OPER) && !IsOper(np)) + continue; + + sendnoticetouser(rqnick, np, "%s", cmdlist[i]->command->content); } - sendnoticetouser(rqnick, (nick*)user, "End of SHOWCOMMANDS"); + sendnoticetouser(rqnick, np, "End of SHOWCOMMANDS"); return 0; } -int rq_genericrequestcheck(nick *np, char *channelname, channel **cp, nick **lnick, nick **qnick) { +int rq_genericrequestcheck(nick *np, char *channelname, channel **cp, nick **qnick) { unsigned long *userhand; rq_block *block; if (!IsAccount(np)) { - sendnoticetouser(rqnick, np, "Error: You must be authed."); + sendnoticetouser(rqnick, np, "Error: You must be authed to perform a service request."); return RQ_ERROR; } @@ -187,26 +215,17 @@ int rq_genericrequestcheck(nick *np, char *channelname, channel **cp, nick **lni *cp = findchannel(channelname); if (*cp == NULL) { - sendnoticetouser(rqnick, np, "Error: Channel %s does not exist.", + sendnoticetouser(rqnick, np, "Error: Channel '%s' does not exist on the network.", channelname); return RQ_ERROR; } - *lnick = getnickbynick(RQ_LNICK); - - if (*lnick == NULL || findserver(RQ_LSERVER) < 0) { - sendnoticetouser(rqnick, np, "Error: %s does not seem to be online. " - "Try again later.", RQ_LNICK); - - return RQ_ERROR; - } - *qnick = getnickbynick(RQ_QNICK); if (*qnick == NULL || findserver(RQ_QSERVER) < 0) { sendnoticetouser(rqnick, np, "Error: %s does not seem to be online. " - "Try again later.", RQ_QNICK); + "Please try again later.", RQ_QNICK); return RQ_ERROR; } @@ -229,8 +248,18 @@ int rq_genericrequestcheck(nick *np, char *channelname, channel **cp, nick **lni block = rq_findblock(channelname); if (block != NULL) { - sendnoticetouser(rqnick, np, "Error: You are not allowed to request a " - "service to this channel."); + /* only say when block expires if <7 days */ + if ( block->expires < getnettime() + 3600 * 24 * 7) { + sendnoticetouser(rqnick, np, "Error: You are not allowed to request a " + "service to '%s'. Keep waiting for at least %s before you try again.", + channelname, rq_longtoduration(block->expires - getnettime())); + /* give them another 5 minutes to think about it */ + block->expires += 300; + rq_saveblocks(); + } else { + sendnoticetouser(rqnick, np, "Error: You are not allowed to request a " + "service to '%s'.", channelname); + } sendnoticetouser(rqnick, np, "Reason: %s", block->reason->content); rq_blocked++; @@ -264,10 +293,12 @@ int rq_genericrequestcheck(nick *np, char *channelname, channel **cp, nick **lni int rqcmd_request(void *user, int cargc, char **cargv) { nick *np = (nick*)user; - nick *lnick, *qnick; - unsigned long *lhand, *qhand; + nick *qnick; + unsigned long *qhand; channel *cp; int retval; + time_t now_ts; + char now[50]; if (cargc < 1) { sendnoticetouser(rqnick, np, "Syntax: requestbot <#channel>"); @@ -277,14 +308,12 @@ int rqcmd_request(void *user, int cargc, char **cargv) { rq_count++; - if (rq_genericrequestcheck(np, cargv[0], &cp, &lnick, &qnick) == RQ_ERROR) { + if (rq_genericrequestcheck(np, cargv[0], &cp, &qnick) == RQ_ERROR) { rq_failed++; return RQ_ERROR; } - lhand = getnumerichandlefromchanhash(cp->users, lnick->numeric); - qhand = getnumerichandlefromchanhash(cp->users, qnick->numeric); if (qhand != NULL) { @@ -295,23 +324,18 @@ int rqcmd_request(void *user, int cargc, char **cargv) { return RQ_ERROR; } - retval = RQ_ERROR; - - if (lhand == NULL && qhand == NULL) { - /* try 'instant' Q request */ - retval = qr_instantrequestq(np, cp); - } - - if (retval == RQ_ERROR) { - if (lhand == NULL) { - /* user 'wants' L */ + retval = lr_requestl(rqnick, np, cp, qnick); - retval = lr_requestl(rqnick, np, cp, lnick); - } else { - /* user 'wants' Q */ + if (rq_logfd != NULL) { + now[0] = '\0'; + now_ts = time(NULL); + strftime(now, sizeof(now), "%c", localtime(&now_ts)); - retval = qr_requestq(rqnick, np, cp, lnick, qnick); - } + fprintf(rq_logfd, "%s: request (%s) for %s from %s!%s@%s%s%s: Request was %s.\n", + now, RQ_QNICK, cp->index->name->content, + np->nick, np->ident, np->host->name->content, IsAccount(np)?"/":"", IsAccount(np)?np->authname:"", + (retval == RQ_OK) ? "accepted" : "denied"); + fflush(rq_logfd); } if (retval == RQ_ERROR) @@ -325,8 +349,8 @@ int rqcmd_request(void *user, int cargc, char **cargv) { int rqcmd_requestspamscan(void *user, int cargc, char **cargv) { nick *np = (nick*)user; channel *cp; - nick *lnick, *qnick, *snick; - unsigned long *lhand, *qhand, *shand; + nick *qnick, *snick; + unsigned long *qhand, *shand; int retval; if (cargc < 1) { @@ -337,7 +361,7 @@ int rqcmd_requestspamscan(void *user, int cargc, char **cargv) { rq_count++; - if (rq_genericrequestcheck(np, cargv[0], &cp, &lnick, &qnick) == RQ_ERROR) { + if (rq_genericrequestcheck(np, cargv[0], &cp, &qnick) == RQ_ERROR) { rq_failed++; return RQ_ERROR; @@ -347,7 +371,7 @@ int rqcmd_requestspamscan(void *user, int cargc, char **cargv) { if (snick == NULL || findserver(RQ_SSERVER) < 0) { sendnoticetouser(rqnick, np, "Error: %s does not seem to be online. " - "Try again later.", RQ_SNICK); + "Please try again later.", RQ_SNICK); rq_failed++; @@ -365,13 +389,12 @@ int rqcmd_requestspamscan(void *user, int cargc, char **cargv) { return RQ_ERROR; } - /* we need either L or Q */ - lhand = getnumerichandlefromchanhash(cp->users, lnick->numeric); + /* we need Q */ qhand = getnumerichandlefromchanhash(cp->users, qnick->numeric); - if (lhand || qhand) { + if (qhand) { /* great, now try to request */ - retval = qr_requests(rqnick, np, cp, lnick, qnick); + retval = qr_requests(rqnick, np, cp, qnick); if (retval == RQ_OK) rq_success++; @@ -380,10 +403,10 @@ int rqcmd_requestspamscan(void *user, int cargc, char **cargv) { return retval; } else { - /* channel apparently doesn't have L or Q */ + /* channel apparently doesn't have Q */ - sendnoticetouser(rqnick, np, "Error: You need %s or %s in order to be " - "able to request %s.", RQ_LNICK, RQ_QNICK, RQ_SNICK); + sendnoticetouser(rqnick, np, "Error: You need %s in order to be " + "able to request %s.", RQ_QNICK, RQ_SNICK); rq_failed++; @@ -391,12 +414,141 @@ int rqcmd_requestspamscan(void *user, int cargc, char **cargv) { } } +int rqcmd_requestop(void *source, int cargc, char **cargv) { + nick *np2, *np = (nick *)source; + nick *user = np; + channel *cp; + int ret, a, count; + unsigned long *hand; + modechanges changes; + + if (cargc < 1) { + sendnoticetouser(rqnick, np, "Syntax: requestop <#channel> [nick]"); + + return CMD_ERROR; + } + + cp = findchannel(cargv[0]); + + if (cp == NULL) { + sendnoticetouser(rqnick, np, "Error: Channel '%s' does not exist on the network.", + cargv[0]); + + return CMD_ERROR; + } + + if (cargc > 1) { + user = getnickbynick(cargv[1]); + + if (!user) { + sendnoticetouser(rqnick, np, "Error: No such user."); + + return CMD_ERROR; + } + } + + if (getnettime() - np->timestamp < 300) { + sendnoticetouser(rqnick, np, "Error: You connected %s ago. To" + " request ops you must have been on the network for" + " at least 5 minutes.", + rq_longtoduration(getnettime() - np->timestamp)); + + return CMD_ERROR; + } + + if (getnettime() - user->timestamp < 300) { + sendnoticetouser(rqnick, np, "Error: The nick you requested op for" + " connected %s ago. To request op, it must have" + "been on the network for at least 5 minutes.", + rq_longtoduration(getnettime() - user->timestamp)); + + return CMD_ERROR; + } + + hand = getnumerichandlefromchanhash(cp->users, user->numeric); + + if (!hand) { + sendnoticetouser(rqnick, np, "Error: User %s is not on channel '%s'.", user->nick, cargv[0]); + + return CMD_ERROR; + } + + + count = 0; + + localsetmodeinit(&changes, cp, rqnick); + + /* reop any services first */ + for(a=0;ausers->hashsize;a++) { + if(cp->users->content[a] != nouser) { + np2 = getnickbynumeric(cp->users->content[a]); + + if (IsService(np2) && (np2->nick[1] == '\0') && !(cp->users->content[a] & CUMODE_OP)) { + localdosetmode_nick(&changes, np2, MC_OP); + count++; + } + } + } + + localsetmodeflush(&changes, 1); + + if (count > 0) { + if (count == 1) + sendnoticetouser(rqnick, np, "1 service was reopped."); + else + sendnoticetouser(rqnick, np, "%d services were reopped.", count); + + return CMD_ERROR; + } + + for (a=0;ausers->hashsize;a++) { + if ((cp->users->content[a] != nouser) && (cp->users->content[a] & CUMODE_OP)) { + sendnoticetouser(rqnick, np, "There are ops on channel '%s'. This command can only be" + " used if there are no ops.", cargv[0]); + + return CMD_ERROR; + } + } + + if (sp_countsplitservers(SERVERTYPEFLAG_USER_STATE) > 0) { + sendnoticetouser(rqnick, np, "One or more servers are currently split. Wait until the" + " netsplit is over and try again."); + + return CMD_ERROR; + } + + if (cf_wouldreop(user, cp)) { + localsetmodeinit(&changes, cp, rqnick); + localdosetmode_nick(&changes, user, MC_OP); + localsetmodeflush(&changes, 1); + + sendnoticetouser(rqnick, np, "Chanfix opped you on the specified channel."); + } else { + ret = cf_fixchannel(cp); + + if (ret == CFX_NOUSERSAVAILABLE) + sendnoticetouser(rqnick, np, "Chanfix knows regular ops for that channel. They will" + " be opped when they return."); + else + sendnoticetouser(rqnick, np, "Chanfix has opped known ops for that channel."); + } + + return CMD_OK; + +} + int rqcmd_addblock(void *user, int cargc, char **cargv) { nick *np = (nick*)user; rq_block *block; time_t expires; char *account; + if (!IsOper(np)) { + sendnoticetouser(rqnick, np, "You do not have access to this command."); + + return RQ_ERROR; + } + if (cargc < 3) { sendnoticetouser(rqnick, np, "Syntax: addblock "); @@ -431,8 +583,14 @@ int rqcmd_delblock(void *user, int cargc, char **cargv) { nick *np = (nick*)user; int result; + if (!IsOper(np)) { + sendnoticetouser(rqnick, np, "You do not have access to this command."); + + return RQ_ERROR; + } + if (cargc < 1) { - controlreply(np, "Syntax: delblock "); + sendnoticetouser(rqnick, np, "Syntax: delblock "); return RQ_ERROR; } @@ -455,6 +613,12 @@ int rqcmd_listblocks(void *user, int cargc, char **cargv) { rq_block block; int i; + if (!IsOper(np)) { + sendnoticetouser(rqnick, np, "You do not have access to this command."); + + return RQ_ERROR; + } + sendnoticetouser(rqnick, np, "Mask By Expires" " Reason"); @@ -480,6 +644,12 @@ int rqcmd_listblocks(void *user, int cargc, char **cargv) { int rqcmd_stats(void *user, int cargc, char **cargv) { nick *np = (nick*)user; + if (!IsOper(np)) { + sendnoticetouser(rqnick, np, "You do not have access to this command."); + + return RQ_ERROR; + } + sendnoticetouser(rqnick, np, "Total requests: %d", rq_count); sendnoticetouser(rqnick, np, "Successful requests: %d", rq_success); sendnoticetouser(rqnick, np, "Failed requests: %d", rq_failed); @@ -491,11 +661,3 @@ int rqcmd_stats(void *user, int cargc, char **cargv) { return RQ_OK; } -int rqcmd_legacyrequest(void *user, int cargc, char **cargv) { - nick *np = (nick*)user; - - sendnoticetouser(rqnick, np, "This command is no longer valid. Please use " - "/msg %s REQUESTBOT #channel instead.", RQ_REQUEST_NICK); - - return RQ_OK; -}