static void do_killclones(User * u) { char killreason[NICKMAX + 32]; char akillreason[] = "Temporary KILLCLONES akill."; int count; char *clonenick, *clonemask, *akillmask; User *cloneuser, *user, *tempuser; clonenick = strtok(NULL, " "); count = 0; if (!clonenick) { notice_lang(s_OperServ, u, OPER_KILLCLONES_SYNTAX); } else if (!(cloneuser = finduser(clonenick))) { notice_lang(s_OperServ, u, OPER_KILLCLONES_UNKNOWN_NICK, clonenick); } else { clonemask = smalloc(strlen(cloneuser->host) + 5); sprintf(clonemask, "*!*@%s", cloneuser->host); akillmask = smalloc(strlen(cloneuser->host) + 3); sprintf(akillmask, "*@%s", strlower(cloneuser->host)); user = firstuser(); while (user) { if (match_usermask(clonemask, user) != 0) { tempuser = nextuser(); count++; snprintf(killreason, sizeof(killreason), "Cloning [%d]", count); kill_user(NULL, user->nick, killreason); user = tempuser; } else { user = nextuser(); } } add_akill(akillmask, akillreason, u->nick, time(NULL) + (60 * 60 * 6)); wallops(s_OperServ, "\2%s\2 used KILLCLONES for \2%s\2 " "killing \2%d\2 clones. A temporary AKILL has been " "added for \2%s\2.", u->nick, clonemask, count, akillmask); log("%s: KILLCLONES: %d clone(s) matching %s killed.", s_OperServ, count, clonemask); free(akillmask); free(clonemask); } }
int add_sgline(User * u, char *mask, const char *by, const time_t expires, const char *reason) { int deleted = 0, i; SXLine *entry; User *u2, *next; char buf[BUFSIZE]; *buf = '\0'; /* Checks whether there is an SGLINE that already covers * the one we want to add, and whether there are SGLINEs * that would be covered by this one. * If so, warn the user in the first case and cleanup * the useless SGLINEs in the second. */ if (!mask) { return -1; } if (sglines.count > 0) { for (i = sglines.count - 1; i >= 0; i--) { entry = sglines.list[i]; if (!entry) continue; if (!stricmp(entry->mask, mask)) { if (entry->expires >= expires || entry->expires == 0) { if (u) notice_lang(s_OperServ, u, OPER_SGLINE_EXISTS, mask); return -1; } else { entry->expires = expires; if (u) notice_lang(s_OperServ, u, OPER_SGLINE_CHANGED, entry->mask); return -2; } } if (match_wild_nocase(entry->mask, mask) && (entry->expires >= expires || entry->expires == 0)) { if (u) notice_lang(s_OperServ, u, OPER_SGLINE_ALREADY_COVERED, mask, entry->mask); return -1; } if (match_wild_nocase(mask, entry->mask) && (entry->expires <= expires || expires == 0)) { slist_delete(&sglines, i); deleted++; } } } /* We can now check whether the list is full or not. */ if (slist_full(&sglines)) { if (u) notice_lang(s_OperServ, u, OPER_SGLINE_REACHED_LIMIT, sglines.limit); return -1; } /* We can now (really) add the SGLINE. */ entry = scalloc(sizeof(SXLine), 1); if (!entry) return -1; entry->mask = sstrdup(mask); entry->by = sstrdup(by); entry->reason = sstrdup(reason); entry->seton = time(NULL); entry->expires = expires; slist_add(&sglines, entry); xanadu_cmd_sgline(entry->mask, entry->reason); if (KillonSGline && !ircd->sglineenforce) { snprintf(buf, (BUFSIZE - 1), "G-Lined: %s", entry->reason); u2 = firstuser(); while (u2) { next = nextuser(); if (!is_oper(u2)) { if (match_wild_nocase(entry->mask, u2->realname)) { kill_user(ServerName, u2->nick, buf); } } u2 = next; } } return deleted; }
/** * Export all stats to xml file * * @param file is the name that will be used * @return void - no returend value * */ void xml_export_all(char *file) { FILE *ptr; User *u, *next; Server *s, *snext; TLD *t; lnode_t *tn; Channel *c, *cnext; int i, count; char buf[BUFSIZE]; struct u_chanlist *uc; struct c_userlist *cu; char **bans; int ping = 0; int counttoping = 1; char *temp; ptr = new_xml(file); SET_SEGV_LOCATION(); if (ptr) { xml_write_header(ptr); xml_write_block_top(ptr, "stats"); xml_write_tag_int(ptr, "users_max", stats->users_max); xml_write_tag_int(ptr, "users", stats->users); xml_write_tag_int(ptr, "chans_max", stats->chans_max); xml_write_tag_int(ptr, "chans", stats->chans); xml_write_tag_int(ptr, "servs_max", stats->servers_max); xml_write_tag_int(ptr, "servs", stats->servers); xml_write_block_bottom(ptr, "stats"); denora_cmd_pong(ServerName, ServerName); xml_write_block_top(ptr, "users"); u = firstuser(); SET_SEGV_LOCATION(); while (u) { next = nextuser(); if (ping) { denora_cmd_pong(ServerName, ServerName); ping = 0; } SET_SEGV_LOCATION(); xml_write_block_top(ptr, "user"); xml_write_tag(ptr, "name", u->nick); xml_write_tag(ptr, "username", u->username); xml_write_tag(ptr, "host", u->host); if (ircd->vhost) { xml_write_tag(ptr, "vhost", u->vhost); } if (ircd->vident && u->vident) { xml_write_tag(ptr, "vident", u->vident); } xml_write_tag(ptr, "realname", u->realname); xml_write_tag(ptr, "server", u->server->name); if (u->ip) { xml_write_tag(ptr, "ip", u->ip); } xml_write_tag(ptr, "country_code", u->country_code); xml_write_tag(ptr, "country_name", u->country_name); xml_write_tag_int(ptr, "timestamp", (long int) u->timestamp); xml_write_tag_int(ptr, "my_signon", (long int) u->my_signon); xml_write_tag_int(ptr, "svid", u->svid); xml_write_tag_int(ptr, "mode", u->mode); xml_write_tag_int(ptr, "language", u->language); xml_write_tag_int(ptr, "isaway", (long int) u->isaway); if (u->isaway && u->awaymsg) { xml_write_tag(ptr, "awaymsg", u->awaymsg); } xml_write_tag_int(ptr, "admin", u->admin); for (i = 0; i < 128; i++) { if (u->mode & umodes[i]) { ircsnprintf(buf, BUFSIZE - 1, "mode_%c", (int) i); xml_write_tag_int(ptr, buf, 1); *buf = '\0'; } } xml_write_block_top(ptr, "inchannels"); for (uc = u->chans; uc; uc = uc->next) { xml_write_tag(ptr, "channel", uc->chan->name); } xml_write_block_bottom(ptr, "inchannels"); xml_moduleData(ptr, &u->moduleData); xml_write_block_bottom(ptr, "user"); u = next; if (counttoping == 10) { ping = 1; counttoping = 1; } else { counttoping++; } } xml_write_block_bottom(ptr, "users"); xml_write_block_top(ptr, "servers"); s = servlist->links; while (s) { snext = s->next; if (HideUline && s->uline) { continue; } if (ping) { denora_cmd_pong(ServerName, ServerName); ping = 0; } xml_write_block_top(ptr, "server"); xml_write_tag(ptr, "name", s->name); xml_write_tag_int(ptr, "hops", s->hops); xml_write_tag(ptr, "desc", s->desc); xml_write_tag_int(ptr, "flags", s->flags); xml_write_tag_int(ptr, "synced", s->sync); if (s->suid) { xml_write_tag(ptr, "suid", s->suid); } if (s->version) { xml_write_tag(ptr, "version", s->version); } if (s->uptime) { xml_write_tag_int(ptr, "uptime", s->uptime); } if (s->uplink) { xml_write_tag(ptr, "uplink", s->uplink->name); } xml_write_block_top(ptr, "serverstats"); if (s->ss->currentusers) { xml_write_tag_int(ptr, "currentusers", s->ss->currentusers); } xml_write_tag_int(ptr, "maxusers", s->ss->maxusers); xml_write_block_bottom(ptr, "serverstats"); xml_write_block_bottom(ptr, "server"); s = snext; if (counttoping == 10) { ping = 1; counttoping = 1; } else { counttoping++; } } xml_write_block_bottom(ptr, "servers"); xml_write_block_top(ptr, "tld"); list_sort(Thead, sortusers); tn = list_first(Thead); while (tn) { t = lnode_get(tn); if (ping) { denora_cmd_pong(ServerName, ServerName); ping = 0; } xml_write_block_top(ptr, "domain"); xml_write_tag(ptr, "countrycode", t->countrycode); xml_write_tag(ptr, "country", t->country); xml_write_tag_int(ptr, "current", t->count); xml_write_tag_int(ptr, "overall", t->overall); xml_write_block_bottom(ptr, "domain"); tn = list_next(Thead, tn); if (counttoping == 10) { ping = 1; counttoping = 1; } else { counttoping++; } } xml_write_block_bottom(ptr, "tld"); xml_write_block_top(ptr, "channels"); c = firstchan(); while (c) { cnext = nextchan(); if (ping) { denora_cmd_pong(ServerName, ServerName); ping = 0; } xml_write_block_top(ptr, "chans"); xml_write_tag(ptr, "name", c->name); xml_write_tag(ptr, "topic", c->topic); xml_write_tag(ptr, "topicsetter", c->topic_setter); xml_write_tag_int(ptr, "creation_time", (long int) c->creation_time); xml_write_tag_int(ptr, "topic_time", (long int) c->topic_time); xml_write_tag_int(ptr, "topic_count", c->stats->topic_count); xml_write_tag_int(ptr, "limit", c->limit); xml_write_tag_int(ptr, "usercount", (long int) c->stats->usercount); xml_write_tag_int(ptr, "maxusercount", (long int) c->stats->maxusercount); xml_write_tag_int(ptr, "kickcount", (long int) c->stats->kickcount); xml_write_tag_int(ptr, "joincounter", (long int) c->stats->joincounter); temp = chan_get_modes(c, 1); xml_write_tag(ptr, "mode", temp); free(temp); if (c->limit) { xml_write_tag_int(ptr, "limit", 1); } if (c->key) { xml_write_tag_int(ptr, "key", 1); } if (ircd->Lmode && c->redirect) { xml_write_tag(ptr, "redirect", c->redirect); } if (ircd->fmode && c->flood) { xml_write_tag(ptr, "flood", c->flood); } xml_write_block_top(ptr, "inchannel"); for (cu = c->users; cu; cu = cu->next) { xml_write_tag(ptr, "user", cu->user->nick); } xml_write_block_bottom(ptr, "inchannel"); if (c->bancount) { xml_write_tag_int(ptr, "bancount", c->bancount); xml_write_block_top(ptr, "bans"); count = c->bancount; bans = calloc(sizeof(char *) * count, 1); for (i = 0; i < count; i++) { bans[i] = sstrdup(c->bans[i]); xml_write_tag(ptr, "ban", bans[i]); } free(bans); xml_write_block_bottom(ptr, "bans"); } if (ircd->except && c->exceptcount) { xml_write_tag_int(ptr, "exceptcount", c->exceptcount); xml_write_block_top(ptr, "exceptions"); count = c->exceptcount; bans = calloc(sizeof(char *) * count, 1); for (i = 0; i < count; i++) { bans[i] = sstrdup(c->excepts[i]); xml_write_tag(ptr, "except", bans[i]); } free(bans); xml_write_block_bottom(ptr, "exceptions"); } if (ircd->invitemode && c->invitecount) { xml_write_tag_int(ptr, "invitecount", c->invitecount); xml_write_block_top(ptr, "invites"); count = c->invitecount; bans = calloc(sizeof(char *) * count, 1); for (i = 0; i < count; i++) { bans[i] = sstrdup(c->invite[i]); xml_write_tag(ptr, "invite", bans[i]); } free(bans); xml_write_block_bottom(ptr, "invites"); } xml_write_block_bottom(ptr, "chans"); c = cnext; if (counttoping == 10) { ping = 1; counttoping = 1; } else { counttoping++; } } xml_write_block_bottom(ptr, "channels"); xml_write_footer(ptr); } }
/** * Export user struct to xml file * * @param file is the name that will be used * @return void - no returend value * */ void xml_export_users(char *file) { FILE *ptr; User *u, *next; int i; char buf[BUFSIZE]; struct u_chanlist *uc; *buf = '\0'; ptr = new_xml(file); SET_SEGV_LOCATION(); if (ptr) { xml_write_header(ptr); xml_write_block_top(ptr, "users"); u = firstuser(); SET_SEGV_LOCATION(); while (u) { next = nextuser(); denora_cmd_pong(ServerName, ServerName); SET_SEGV_LOCATION(); xml_write_block_top(ptr, "user"); xml_write_tag(ptr, "name", u->nick); xml_write_tag(ptr, "username", u->username); xml_write_tag(ptr, "host", u->host); if (ircd->vhost) { xml_write_tag(ptr, "vhost", u->vhost); } if (ircd->vident && u->vident) { xml_write_tag(ptr, "vident", u->vident); } xml_write_tag(ptr, "realname", u->realname); xml_write_tag(ptr, "server", u->server->name); if (u->ip) { xml_write_tag(ptr, "ip", u->ip); } xml_write_tag(ptr, "country_code", u->country_code); xml_write_tag(ptr, "country_name", u->country_name); xml_write_tag_int(ptr, "timestamp", (long int) u->timestamp); xml_write_tag_int(ptr, "my_signon", (long int) u->my_signon); xml_write_tag_int(ptr, "svid", u->svid); xml_write_tag_int(ptr, "mode", u->mode); xml_write_tag_int(ptr, "language", u->language); xml_write_tag_int(ptr, "isaway", (long int) u->isaway); if (u->isaway && u->awaymsg) { xml_write_tag(ptr, "awaymsg", u->awaymsg); } xml_write_tag_int(ptr, "admin", u->admin); for (i = 0; i < 128; i++) { if (u->mode & umodes[i]) { ircsnprintf(buf, BUFSIZE - 1, "mode_%c", (int) i); xml_write_tag_int(ptr, buf, 1); *buf = '\0'; } } xml_write_block_top(ptr, "inchannels"); for (uc = u->chans; uc; uc = uc->next) { xml_write_tag(ptr, "channel", uc->chan->name); } xml_write_block_bottom(ptr, "inchannels"); xml_moduleData(ptr, &u->moduleData); xml_write_block_bottom(ptr, "user"); u = next; } xml_write_block_bottom(ptr, "users"); xml_write_footer(ptr); } }