/* shroud's service request */
+#include <stdio.h>
#include <string.h>
#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 "lrequest.h"
#include "sqrequest.h"
#include "user.h"
+MODULE_VERSION("");
+
nick *rqnick;
CommandTree *rqcommands;
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);
int rqcmd_adduser(void *user, int cargc, char **cargv);
int rqcmd_deluser(void *user, int cargc, char **cargv);
int rq_success = 0;
int rq_blocked = 0;
+/* log fd */
+FILE *rq_logfd;
+
+static int extloaded = 0;
+
void _init(void) {
+ if(!rq_initblocks())
+ 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_ACCOUNT, 3, &rqcmd_addblock);
addcommandtotree(rqcommands, "delblock", RQU_ACCOUNT, 1, &rqcmd_delblock);
addcommandtotree(rqcommands, "listblocks", RQU_ACCOUNT, 1, &rqcmd_listblocks);
addcommandtotree(rqcommands, "changelev", RQU_OPER, 2, &rqcmd_changelev);
addcommandtotree(rqcommands, "userlist", RQU_OPER, 1, &rqcmd_userlist);
- /* old legacy stuff */
- addcommandtotree(rqcommands, "requestq", RQU_ANY, 1, &rqcmd_legacyrequest);
-
- rq_initblocks();
qr_initrequest();
ru_load();
+ 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, "changelev", &rqcmd_changelev);
deletecommandfromtree(rqcommands, "userlist", &rqcmd_userlist);
-
- /* old legacy stuff */
- deletecommandfromtree(rqcommands, "requestq", &rqcmd_legacyrequest);
-
destroycommandtree(rqcommands);
rq_finiblocks();
qr_finirequest();
ru_persist();
+ 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, 1780711, 0,
UMODE_ACCOUNT | UMODE_SERVICE | UMODE_OPER,
rq_handler);
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)) &&
- (((cmdlist[i]->level & RQU_ACCOUNT) == 0 || (IsOper((nick*)user) || (IsAccount((nick*)user)) && ru_getlevel((nick*)user) > 0))))
- sendnoticetouser(rqnick, (nick*)user, "%s", cmdlist[i]->command->content);
+ if ((cmdlist[i]->level & RQU_OPER) && !IsOper(np))
+ continue;
+
+ if ((cmdlist[i]->level & RQU_ACCOUNT) && !(IsOper(np) || (IsAccount(np) && ru_getlevel(np) > 0)))
+ 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;
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) {
block = rq_findblock(channelname);
if (block != NULL) {
- sendnoticetouser(rqnick, np, "Error: You are not allowed to request a "
+ /* 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 this channel. Keep waiting for at least %s before you try again.",
+ 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 this channel.");
+ }
sendnoticetouser(rqnick, np, "Reason: %s", block->reason->content);
rq_blocked++;
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>");
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) {
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: Request was %s.\n", now, RQ_QNICK, cp->index->name->content, np->nick, (retval == RQ_OK) ? "accepted" : "denied");
+ fflush(rq_logfd);
}
if (retval == RQ_ERROR)
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) {
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;
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++;
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++;
}
}
+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: No such channel.");
+
+ 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;a<cp->users->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;a<cp->users->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() > 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;
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;
-}
-
int rqcmd_adduser(void *user, int cargc, char **cargv) {
nick *np = (nick*)user;
int result, level;