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