📄 m_tkl.c
字号:
return matches;}aTKline *_find_qline(aClient *cptr, char *nick, int *ishold){ aTKline *lp; char *chost, *cname, *cip; char host[NICKLEN+USERLEN+HOSTLEN+6], hostbuf2[NICKLEN+USERLEN+HOSTLEN+6], *host2 = NULL; int points = 0; ConfigItem_except *excepts; *ishold = 0; if (IsServer(cptr) || IsMe(cptr)) return NULL; for (lp = tklines[tkl_hash('q')]; lp; lp = lp->next) { points = 0; if (!(lp->type & TKL_NICK)) continue; if (!match(lp->hostmask, nick)) { points = 1; break; } } if (points != 1) return NULL; /* It's a services hold */ if (*lp->usermask == 'H') { *ishold = 1; return lp; } chost = cptr->user ? cptr->user->realhost : (MyConnect(cptr) ? cptr->sockhost : "unknown"); cname = cptr->user ? cptr->user->username : "unknown"; strcpy(host, make_user_host(cname, chost)); cip = GetIP(cptr); if (cip) { strcpy(hostbuf2, make_user_host(cname, cip)); host2 = hostbuf2; } for (excepts = conf_except; excepts; excepts = (ConfigItem_except *)excepts->next) { if (excepts->flag.type != CONF_EXCEPT_TKL || excepts->type != TKL_NICK) continue; if (excepts->netmask) { if (MyConnect(cptr) && match_ip(cptr->ip, NULL, NULL, excepts->netmask)) return NULL; } else if (!match(excepts->mask, host) || (host2 && !match(excepts->mask, host2))) return NULL; } return lp;}int _find_tkline_match_zap_ex(aClient *cptr, aTKline **rettk){ aTKline *lp; char *cip; TS nowtime; char msge[1024]; ConfigItem_except *excepts; Hook *tmphook; if (rettk) *rettk = NULL; if (IsServer(cptr) || IsMe(cptr)) return -1; nowtime = TStime(); cip = GetIP(cptr); for (lp = tklines[tkl_hash('z')]; lp; lp = lp->next) { if (lp->type & TKL_ZAP) { if ((lp->ptr.netmask && match_ip(cptr->ip, NULL, NULL, lp->ptr.netmask)) || !match(lp->hostmask, cip)) { for (excepts = conf_except; excepts; excepts = (ConfigItem_except *)excepts->next) { if (excepts->flag.type != CONF_EXCEPT_TKL || excepts->type != lp->type) continue; if (excepts->netmask) { if (match_ip(cptr->ip, NULL, NULL, excepts->netmask)) return -1; } else if (!match(excepts->mask, cip)) return -1; } for (tmphook = Hooks[HOOKTYPE_TKL_EXCEPT]; tmphook; tmphook = tmphook->next) if (tmphook->func.intfunc(cptr, lp) > 0) return -1; ircstp->is_ref++; ircsprintf(msge, "ERROR :Closing Link: [%s] Z:Lined (%s)\r\n",#ifndef INET6 inetntoa((char *)&cptr->ip), lp->reason);#else inet_ntop(AF_INET6, (char *)&cptr->ip, mydummy, MYDUMMY_SIZE), lp->reason);#endif strlcpy(zlinebuf, msge, sizeof zlinebuf); if (rettk) *rettk = lp; return (1); } } } return -1;}int _find_tkline_match_zap(aClient *cptr){ return _find_tkline_match_zap_ex(cptr, NULL);}#define BY_MASK 0x1#define BY_REASON 0x2#define NOT_BY_MASK 0x4#define NOT_BY_REASON 0x8#define BY_SETBY 0x10#define NOT_BY_SETBY 0x20typedef struct { int flags; char *mask; char *reason; char *setby;} TKLFlag;static void parse_tkl_para(char *para, TKLFlag *flag){ static char paratmp[512]; /* <- copy of para, because it gets fragged by strtok() */ char *flags, *tmp; char what = '+'; strncpyzt(paratmp, para, sizeof(paratmp)); flags = strtok(paratmp, " "); bzero(flag, sizeof(TKLFlag)); for (; *flags; flags++) { switch (*flags) { case '+': what = '+'; break; case '-': what = '-'; break; case 'm': if (flag->mask || !(tmp = strtok(NULL, " "))) continue; if (what == '+') flag->flags |= BY_MASK; else flag->flags |= NOT_BY_MASK; flag->mask = tmp; break; case 'r': if (flag->reason || !(tmp = strtok(NULL, " "))) continue; if (what == '+') flag->flags |= BY_REASON; else flag->flags |= NOT_BY_REASON; flag->reason = tmp; break; case 's': if (flag->setby || !(tmp = strtok(NULL, " "))) continue; if (what == '+') flag->flags |= BY_SETBY; else flag->flags |= NOT_BY_SETBY; flag->setby = tmp; break; } }} void _tkl_stats(aClient *cptr, int type, char *para){ aTKline *tk; TS curtime; TKLFlag tklflags; int index; /* We output in this row: Glines,GZlines,KLine, ZLIne Character: G, Z, K, z */ if (!BadPtr(para)) parse_tkl_para(para, &tklflags); tkl_check_expire(NULL); curtime = TStime(); for (index = 0; index < TKLISTLEN; index++) for (tk = tklines[index]; tk; tk = tk->next) { if (type && tk->type != type) continue; if (!BadPtr(para)) { if (tklflags.flags & BY_MASK) { if (tk->type & TKL_NICK) { if (match(tklflags.mask, tk->hostmask)) continue; } else if (match(tklflags.mask, make_user_host(tk->usermask, tk->hostmask))) continue; } if (tklflags.flags & NOT_BY_MASK) { if (tk->type & TKL_NICK) { if (!match(tklflags.mask, tk->hostmask)) continue; } else if (!match(tklflags.mask, make_user_host(tk->usermask, tk->hostmask))) continue; } if (tklflags.flags & BY_REASON) if (match(tklflags.reason, tk->reason)) continue; if (tklflags.flags & NOT_BY_REASON) if (!match(tklflags.reason, tk->reason)) continue; if (tklflags.flags & BY_SETBY) if (match(tklflags.setby, tk->setby)) continue; if (tklflags.flags & NOT_BY_SETBY) if (!match(tklflags.setby, tk->setby)) continue; } if (tk->type == (TKL_KILL | TKL_GLOBAL)) { sendto_one(cptr, rpl_str(RPL_STATSGLINE), me.name, cptr->name, 'G', tk->usermask, tk->hostmask, (tk->expire_at != 0) ? (tk->expire_at - curtime) : 0, (curtime - tk->set_at), tk->setby, tk->reason); } if (tk->type == (TKL_ZAP | TKL_GLOBAL)) { sendto_one(cptr, rpl_str(RPL_STATSGLINE), me.name, cptr->name, 'Z', tk->usermask, tk->hostmask, (tk->expire_at != 0) ? (tk->expire_at - curtime) : 0, (curtime - tk->set_at), tk->setby, tk->reason); } if (tk->type == (TKL_SHUN | TKL_GLOBAL)) { sendto_one(cptr, rpl_str(RPL_STATSGLINE), me.name, cptr->name, 's', tk->usermask, tk->hostmask, (tk->expire_at != 0) ? (tk->expire_at - curtime) : 0, (curtime - tk->set_at), tk->setby, tk->reason); } if (tk->type == (TKL_KILL)) { sendto_one(cptr, rpl_str(RPL_STATSGLINE), me.name, cptr->name, 'K', tk->usermask, tk->hostmask, (tk->expire_at != 0) ? (tk->expire_at - curtime) : 0, (curtime - tk->set_at), tk->setby, tk->reason); } if (tk->type == (TKL_ZAP)) { sendto_one(cptr, rpl_str(RPL_STATSGLINE), me.name, cptr->name, 'z', tk->usermask, tk->hostmask, (tk->expire_at != 0) ? (tk->expire_at - curtime) : 0, (curtime - tk->set_at), tk->setby, tk->reason); } if (tk->type & TKL_SPAMF) { sendto_one(cptr, rpl_str(RPL_STATSSPAMF), me.name, cptr->name, (tk->type & TKL_GLOBAL) ? 'F' : 'f', spamfilter_target_inttostring(tk->subtype), banact_valtostring(tk->ptr.spamf->action), (tk->expire_at != 0) ? (tk->expire_at - curtime) : 0, curtime - tk->set_at, tk->ptr.spamf->tkl_duration, tk->ptr.spamf->tkl_reason, tk->setby, tk->reason); } if (tk->type & TKL_NICK) sendto_one(cptr, rpl_str(RPL_STATSQLINE), me.name, cptr->name, (tk->type & TKL_GLOBAL) ? 'Q' : 'q', tk->hostmask, (tk->expire_at != 0) ? (tk->expire_at - curtime) : 0, curtime - tk->set_at, tk->setby, tk->reason); }}void _tkl_synch(aClient *sptr){ aTKline *tk; char typ = 0; int index; for (index = 0; index < TKLISTLEN; index++) for (tk = tklines[index]; tk; tk = tk->next) { if (tk->type & TKL_GLOBAL) { if (tk->type & TKL_KILL) typ = 'G'; if (tk->type & TKL_ZAP) typ = 'Z'; if (tk->type & TKL_SHUN) typ = 's'; if (tk->type & TKL_SPAMF) typ = 'F'; if (tk->type & TKL_NICK) typ = 'Q'; if ((tk->type & TKL_SPAMF) && (sptr->proto & PROTO_TKLEXT)) { sendto_one(sptr, ":%s %s + %c %s %s %s %li %li %li %s :%s", me.name, IsToken(sptr) ? TOK_TKL : MSG_TKL, typ, tk->usermask, tk->hostmask, tk->setby, tk->expire_at, tk->set_at, tk->ptr.spamf->tkl_duration, tk->ptr.spamf->tkl_reason, tk->reason); } else sendto_one(sptr, ":%s %s + %c %s %s %s %li %li :%s", me.name, IsToken(sptr) ? TOK_TKL : MSG_TKL, typ, tk->usermask ? tk->usermask : "*", tk->hostmask, tk->setby, tk->expire_at, tk->set_at, tk->reason); } }}/* * m_tkl: * HISTORY: * This was originall called Timed KLines, but today it's * used by various *line types eg: zline, gline, gzline, shun, * but also by spamfilter etc... * USAGE: * This routine is used both internally by the ircd (to * for example add local klines, zlines, etc) and over the * network (glines, gzlines, spamfilter, etc). * add: remove: spamfilter: spamfilter+TKLEXT sqline: * parv[ 1]: + - +/- + +/- * parv[ 2]: type type type type type * parv[ 3]: user user target target hold * parv[ 4]: host host action action host * parv[ 5]: setby removedby (un)setby setby setby * parv[ 6]: expire_at expire_at (0) expire_at (0) expire_at * parv[ 7]: set_at set_at set_at set_at * parv[ 8]: reason regex tkl duration reason * parv[ 9]: tkl reason [A] * parv[10]: regex * * [A] tkl reason field must be escaped by caller [eg: use unreal_encodespace() * if m_tkl is called internally]. * */int _m_tkl(aClient *cptr, aClient *sptr, int parc, char *parv[]){ aTKline *tk; int type; int found = 0; char gmt[256], gmt2[256]; char txt[256]; TS expiry_1, setat_1, spamf_tklduration = 0; char *reason = NULL; if (!IsServer(sptr) && !IsOper(sptr) && !IsMe(sptr)) return 0; if (parc < 2) return 0; tkl_check_expire(NULL); switch (*parv[1]) { case '+': { /* we relay on servers to be failsafe.. */ if (!IsServer(sptr) && !IsMe(sptr)) return 0; if (parc < 9) return 0; if (parv[2][0] == 'G') type = TKL_KILL | TKL_GLOBAL; else if (parv[2][0] == 'Z') type = TKL_ZAP | TKL_GLOBAL; else if (parv[2][0] == 'z') type = TKL_ZAP; else if (parv[2][0] == 'k') type = TKL_KILL; else if (parv[2][0] == 's') type = TKL_SHUN | TKL_GLOBAL; else if (parv[2][0] == 'f') type = TKL_SPAMF; else if (parv[2][0] == 'F') type = TKL_SPAMF | TKL_GLOBAL; else if (parv[2][0] == 'Q') type = TKL_NICK | TKL_GLOBAL; else if (parv[2][0] == 'q') type = TKL_NICK; else return 0; expiry_1 = atol(parv[6]); setat_1 = atol(parv[7]); reason = parv[8]; if (expiry_1 < 0) { sendto_realops("Invalid TKL entry from %s, negative expire time (%ld) -- not added. Clock on other server incorrect?", sptr->name, (long)expiry_1); return 0; } if (setat_1 < 0) { sendto_realops("Invalid TKL entry from %s, negative set-at time (%ld) -- not added. Clock on other server incorrect?", sptr->name, (long)setat_1); return 0; } found = 0; if ((type & TKL_SPAMF) && (parc >= 11)) { reason = parv[10]; spamf_tklduration = config_checkval(parv[8], CFG_TIME); /* was: atol(parv[8]); */ } for (tk = tklines[tkl_hash(parv[2][0])]; tk; tk = tk->next) { if (tk->type == type) { if ((tk->type & TKL_NICK) && !stricmp(tk->hostmask, parv[4])) { found = 1; break; } else if (!strcmp(tk->hostmask, parv[4]) && !strcmp(tk->usermask, parv[3]) && (!(type & TKL_SPAMF) || !stricmp(tk->reason, reason))) { found = 1; break; } } } /* *:Line already exists! */ if (found == 1) { /* SYZTAG: TODO: check for tklreason/tklduration differnces */ /* do they differ in ANY way? */ if (type & TKL_NICK) { /* for sqline: usermask = H overrides */ if (*parv[3] == 'H') *tk->usermask = 'H'; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -