]>
Commit | Line | Data |
---|---|---|
97390b65 CP |
1 | /* Automatically generated by refactor.pl. |
2 | * | |
3 | * | |
4 | * CMDNAME: maillock | |
5 | * CMDLEVEL: QCMD_OPER | |
6 | * CMDARGS: 3 | |
7 | * CMDDESC: Set/unset/list mail lock patterns | |
8 | * CMDFUNC: csu_domaillock | |
9 | * CMDPROTO: int csu_domaillock(void *source, int cargc, char **cargv); | |
10 | * CMDHELP: Usage: maillock <-list|-add|-del> <pattern> [<reason>] | |
11 | * CMDHELP: Manipulates the list of mail lock patterns. | |
12 | * CMDHELP: Any email address matching the pattern will be refused in HELLO/EMAIL. | |
13 | * CMDHELP: A reason is optional for -list, but recommended. | |
14 | */ | |
15 | ||
16 | #include "../chanserv.h" | |
17 | #include "../../lib/irc_string.h" | |
18 | #include <stdio.h> | |
19 | #include <string.h> | |
20 | ||
21 | int csu_domaillock(void *source, int cargc, char **cargv) { | |
22 | nick *sender=source; | |
23 | char *pattern; | |
24 | maillock *mlp; | |
25 | ||
26 | if (cargc<2) { | |
27 | chanservstdmessage(sender,QM_NOTENOUGHPARAMS,"maillock"); | |
28 | return CMD_ERROR; | |
29 | } | |
30 | ||
31 | pattern = cargv[1]; | |
32 | ||
33 | if(!strcasecmp(cargv[0], "-list")) { | |
34 | char timebuf[100]; | |
35 | reguser *rup; | |
36 | ||
37 | chanservstdmessage(sender, QM_MAILLOCKHEADER); | |
38 | for(mlp=maillocks;mlp;mlp=mlp->next) { | |
39 | if(!match(mlp->pattern->content, pattern)) | |
40 | continue; | |
41 | ||
42 | rup=findreguserbyID(mlp->createdby); | |
43 | strftime(timebuf,15,"%d/%m/%y %H:%M",gmtime(&mlp->created)); | |
44 | ||
b7ed259b | 45 | chanservsendmessage(sender, "%-50s %-15s %-25s %s", mlp->pattern->content, rup?rup->username:"??", mlp->reason?mlp->reason->content:"(none)", timebuf); |
97390b65 CP |
46 | } |
47 | } else if(!strcasecmp(cargv[0], "-del")) { | |
48 | maillock *pmlp = NULL; | |
49 | ||
50 | for(mlp=maillocks;mlp;pmlp=mlp,mlp=mlp->next) | |
51 | if(!strcasecmp(pattern, mlp->pattern->content)) | |
52 | break; | |
53 | ||
54 | if(!mlp) { | |
55 | chanservstdmessage(sender, QM_MAILLOCKDOESNTEXIST); | |
56 | return CMD_ERROR; | |
57 | } | |
58 | ||
59 | csdb_deletemaillock(mlp); | |
60 | if(!pmlp) { | |
61 | maillocks=mlp->next; | |
62 | } else { | |
63 | pmlp->next=mlp->next; | |
64 | } | |
65 | freemaillock(mlp); | |
66 | ||
67 | } else if(!strcasecmp(cargv[0], "-add")) { | |
68 | char *reason; | |
69 | reguser *rup = getreguserfromnick(sender);; | |
70 | ||
71 | if(cargc<3) { | |
72 | reason = NULL; | |
73 | } else { | |
74 | reason = cargv[2]; | |
75 | } | |
76 | ||
77 | for(mlp=maillocks;mlp;mlp=mlp->next) { | |
78 | if(!strcasecmp(pattern, mlp->pattern->content)) { | |
79 | chanservstdmessage(sender, QM_MAILLOCKALREADYEXISTS); | |
80 | return CMD_ERROR; | |
81 | } | |
82 | } | |
83 | ||
84 | mlp=getmaillock(); | |
85 | mlp->pattern=getsstring(pattern, 300); | |
86 | if(reason) { | |
87 | mlp->reason=getsstring(reason, 300); | |
88 | } else { | |
89 | mlp->reason=NULL; | |
90 | } | |
91 | mlp->createdby=rup->ID; | |
92 | mlp->created=time(NULL); | |
93 | mlp->id=++lastmaillockID; | |
94 | mlp->next=maillocks; | |
95 | maillocks=mlp; | |
96 | csdb_createmaillock(mlp); | |
97 | ||
98 | } else { | |
99 | chanservsendmessage(sender, "Invalid option, see HELP."); | |
100 | return CMD_ERROR; | |
101 | } | |
102 | ||
103 | chanservstdmessage(sender, QM_DONE); | |
104 | return CMD_OK; | |
105 | } |