00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #include "module.h"
00017
00018 int do_szline(User * u);
00019 void myOperServHelp(User * u);
00020 int szline_view_callback(SList * slist, int number, void *item,
00021 va_list args);
00022 int szline_list_callback(SList * slist, int number, void *item,
00023 va_list args);
00024 int szline_view(int number, SXLine * sx, User * u, int *sent_header);
00025 int szline_list(int number, SXLine * sx, User * u, int *sent_header);
00026
00033 int AnopeInit(int argc, char **argv)
00034 {
00035 Command *c;
00036
00037 moduleAddAuthor("Anope");
00038 moduleAddVersion("$Id: os_szline.c 1345 2008-01-13 12:54:14Z geniusdex $");
00039 moduleSetType(CORE);
00040
00041 c = createCommand("SZLINE", do_szline, is_services_oper,
00042 OPER_HELP_SZLINE, -1, -1, -1, -1);
00043 moduleAddCommand(OPERSERV, c, MOD_UNIQUE);
00044
00045 moduleSetOperHelp(myOperServHelp);
00046 if (!ircd->szline) {
00047 return MOD_STOP;
00048 }
00049 return MOD_CONT;
00050 }
00051
00055 void AnopeFini(void)
00056 {
00057
00058 }
00059
00060
00065 void myOperServHelp(User * u)
00066 {
00067 if (is_services_oper(u)) {
00068 notice_lang(s_OperServ, u, OPER_HELP_CMD_SZLINE);
00069 }
00070 }
00071
00077 int do_szline(User * u)
00078 {
00079 char *cmd = strtok(NULL, " ");
00080
00081 if (!cmd)
00082 cmd = "";
00083
00084 if (!stricmp(cmd, "ADD")) {
00085 int deleted = 0;
00086 char *expiry, *mask, *reason;
00087 time_t expires;
00088
00089 mask = strtok(NULL, " ");
00090 if (mask && *mask == '+') {
00091 expiry = mask;
00092 mask = strtok(NULL, " ");
00093 } else {
00094 expiry = NULL;
00095 }
00096
00097 expires = expiry ? dotime(expiry) : SZLineExpiry;
00098
00099
00100
00101 if (expiry && isdigit(expiry[strlen(expiry) - 1]))
00102 expires *= 86400;
00103
00104 if (expires != 0 && expires < 60) {
00105 notice_lang(s_OperServ, u, BAD_EXPIRY_TIME);
00106 return MOD_CONT;
00107 } else if (expires > 0) {
00108 expires += time(NULL);
00109 }
00110
00111 if (mask && (reason = strtok(NULL, ""))) {
00112
00113
00114 if (strchr(mask, '!') || strchr(mask, '@')) {
00115 notice_lang(s_OperServ, u, OPER_SZLINE_ONLY_IPS);
00116 return MOD_CONT;
00117 }
00118
00119 if (strspn(mask, "*?") == strlen(mask)) {
00120 notice_lang(s_OperServ, u, USERHOST_MASK_TOO_WIDE, mask);
00121 return MOD_CONT;
00122 }
00123
00124 deleted = add_szline(u, mask, u->nick, expires, reason);
00125 if (deleted < 0)
00126 return MOD_CONT;
00127 else if (deleted)
00128 notice_lang(s_OperServ, u, OPER_SZLINE_DELETED_SEVERAL,
00129 deleted);
00130 notice_lang(s_OperServ, u, OPER_SZLINE_ADDED, mask);
00131
00132 if (WallOSSZLine) {
00133 char buf[128];
00134
00135 if (!expires) {
00136 strcpy(buf, "does not expire");
00137 } else {
00138 int wall_expiry = expires - time(NULL);
00139 char *s = NULL;
00140
00141 if (wall_expiry >= 86400) {
00142 wall_expiry /= 86400;
00143 s = "day";
00144 } else if (wall_expiry >= 3600) {
00145 wall_expiry /= 3600;
00146 s = "hour";
00147 } else if (wall_expiry >= 60) {
00148 wall_expiry /= 60;
00149 s = "minute";
00150 }
00151
00152 snprintf(buf, sizeof(buf), "expires in %d %s%s",
00153 wall_expiry, s,
00154 (wall_expiry == 1) ? "" : "s");
00155 }
00156
00157 anope_cmd_global(s_OperServ,
00158 "%s added an SZLINE for %s (%s)", u->nick,
00159 mask, buf);
00160 }
00161
00162 if (readonly)
00163 notice_lang(s_OperServ, u, READ_ONLY_MODE);
00164
00165 } else {
00166 syntax_error(s_OperServ, u, "SZLINE", OPER_SZLINE_SYNTAX);
00167 }
00168
00169 } else if (!stricmp(cmd, "DEL")) {
00170
00171 char *mask;
00172 int res = 0;
00173
00174 mask = strtok(NULL, " ");
00175
00176 if (!mask) {
00177 syntax_error(s_OperServ, u, "SZLINE", OPER_SZLINE_SYNTAX);
00178 return MOD_CONT;
00179 }
00180
00181 if (szlines.count == 0) {
00182 notice_lang(s_OperServ, u, OPER_SZLINE_LIST_EMPTY);
00183 return MOD_CONT;
00184 }
00185
00186 if (isdigit(*mask) && strspn(mask, "1234567890,-") == strlen(mask)) {
00187
00188 res = slist_delete_range(&szlines, mask, NULL);
00189 if (res == 0) {
00190 notice_lang(s_OperServ, u, OPER_SZLINE_NO_MATCH);
00191 return MOD_CONT;
00192 } else if (res == 1) {
00193 notice_lang(s_OperServ, u, OPER_SZLINE_DELETED_ONE);
00194 } else {
00195 notice_lang(s_OperServ, u, OPER_SZLINE_DELETED_SEVERAL,
00196 res);
00197 }
00198 } else {
00199 if ((res = slist_indexof(&szlines, mask)) == -1) {
00200 notice_lang(s_OperServ, u, OPER_SZLINE_NOT_FOUND, mask);
00201 return MOD_CONT;
00202 }
00203
00204 slist_delete(&szlines, res);
00205 notice_lang(s_OperServ, u, OPER_SZLINE_DELETED, mask);
00206 }
00207
00208 if (readonly)
00209 notice_lang(s_OperServ, u, READ_ONLY_MODE);
00210
00211 } else if (!stricmp(cmd, "LIST")) {
00212 char *mask;
00213 int res, sent_header = 0;
00214
00215 if (szlines.count == 0) {
00216 notice_lang(s_OperServ, u, OPER_SZLINE_LIST_EMPTY);
00217 return MOD_CONT;
00218 }
00219
00220 mask = strtok(NULL, " ");
00221
00222 if (!mask || (isdigit(*mask)
00223 && strspn(mask, "1234567890,-") == strlen(mask))) {
00224 res =
00225 slist_enum(&szlines, mask, &szline_list_callback, u,
00226 &sent_header);
00227 if (res == 0) {
00228 notice_lang(s_OperServ, u, OPER_SZLINE_NO_MATCH);
00229 return MOD_CONT;
00230 }
00231 } else {
00232 int i;
00233 char *amask;
00234
00235 for (i = 0; i < szlines.count; i++) {
00236 amask = ((SXLine *) szlines.list[i])->mask;
00237 if (!stricmp(mask, amask)
00238 || match_wild_nocase(mask, amask))
00239 szline_list(i + 1, szlines.list[i], u, &sent_header);
00240 }
00241
00242 if (!sent_header)
00243 notice_lang(s_OperServ, u, OPER_SZLINE_NO_MATCH);
00244 }
00245 } else if (!stricmp(cmd, "VIEW")) {
00246 char *mask;
00247 int res, sent_header = 0;
00248
00249 if (szlines.count == 0) {
00250 notice_lang(s_OperServ, u, OPER_SZLINE_LIST_EMPTY);
00251 return MOD_CONT;
00252 }
00253
00254 mask = strtok(NULL, " ");
00255
00256 if (!mask || (isdigit(*mask)
00257 && strspn(mask, "1234567890,-") == strlen(mask))) {
00258 res =
00259 slist_enum(&szlines, mask, &szline_view_callback, u,
00260 &sent_header);
00261 if (res == 0) {
00262 notice_lang(s_OperServ, u, OPER_SZLINE_NO_MATCH);
00263 return MOD_CONT;
00264 }
00265 } else {
00266 int i;
00267 char *amask;
00268
00269 for (i = 0; i < szlines.count; i++) {
00270 amask = ((SXLine *) szlines.list[i])->mask;
00271 if (!stricmp(mask, amask)
00272 || match_wild_nocase(mask, amask))
00273 szline_view(i + 1, szlines.list[i], u, &sent_header);
00274 }
00275
00276 if (!sent_header)
00277 notice_lang(s_OperServ, u, OPER_SZLINE_NO_MATCH);
00278 }
00279 } else if (!stricmp(cmd, "CLEAR")) {
00280 slist_clear(&szlines, 1);
00281 notice_lang(s_OperServ, u, OPER_SZLINE_CLEAR);
00282 } else {
00283 syntax_error(s_OperServ, u, "SZLINE", OPER_SZLINE_SYNTAX);
00284 }
00285 return MOD_CONT;
00286 }
00287
00288
00289 int szline_view(int number, SXLine * sx, User * u, int *sent_header)
00290 {
00291 char timebuf[32], expirebuf[256];
00292 struct tm tm;
00293
00294 if (!sx)
00295 return 0;
00296
00297 if (!*sent_header) {
00298 notice_lang(s_OperServ, u, OPER_SZLINE_VIEW_HEADER);
00299 *sent_header = 1;
00300 }
00301
00302 tm = *localtime(&sx->seton);
00303 strftime_lang(timebuf, sizeof(timebuf), u, STRFTIME_SHORT_DATE_FORMAT,
00304 &tm);
00305 expire_left(u->na, expirebuf, sizeof(expirebuf), sx->expires);
00306 notice_lang(s_OperServ, u, OPER_SZLINE_VIEW_FORMAT, number, sx->mask,
00307 sx->by, timebuf, expirebuf, sx->reason);
00308
00309 return 1;
00310 }
00311
00312
00313
00314 int szline_view_callback(SList * slist, int number, void *item,
00315 va_list args)
00316 {
00317 User *u = va_arg(args, User *);
00318 int *sent_header = va_arg(args, int *);
00319
00320 return szline_view(number, item, u, sent_header);
00321 }
00322
00323
00324
00325 int szline_list_callback(SList * slist, int number, void *item,
00326 va_list args)
00327 {
00328 User *u = va_arg(args, User *);
00329 int *sent_header = va_arg(args, int *);
00330
00331 return szline_list(number, item, u, sent_header);
00332 }
00333
00334
00335
00336 int szline_list(int number, SXLine * sx, User * u, int *sent_header)
00337 {
00338 if (!sx)
00339 return 0;
00340
00341 if (!*sent_header) {
00342 notice_lang(s_OperServ, u, OPER_SZLINE_LIST_HEADER);
00343 *sent_header = 1;
00344 }
00345
00346 notice_lang(s_OperServ, u, OPER_SZLINE_LIST_FORMAT, number, sx->mask,
00347 sx->reason);
00348
00349 return 1;
00350 }