X-Git-Url: https://jfr.im/git/irc/evilnet/x3.git/blobdiff_plain/a32da4c70ca85b879f8162469ae37ffeca500b99..b1bf690d5e16c7f79d3ec308ffdc705e007ce6e5:/src/opserv.c diff --git a/src/opserv.c b/src/opserv.c index 49c2819..9951f3b 100644 --- a/src/opserv.c +++ b/src/opserv.c @@ -1,7 +1,7 @@ /* opserv.c - IRC Operator assistance service * Copyright 2000-2004 srvx Development Team * - * This file is part of srvx. + * This file is part of x3. * * srvx is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -86,6 +86,7 @@ #define OSMSG_GAG_REQUESTED "Gag requested by %s." static const struct message_entry msgtab[] = { + { "OSMSG_BAR", "----------------------------------------" }, { "OSMSG_USER_ACCESS_IS", "$b%s$b (account $b%s$b) has %d access." }, { "OSMSG_LEVEL_TOO_LOW", "You lack sufficient access to use this command." }, { "OSMSG_NEED_CHANNEL", "You must specify a channel for $b%s$b." }, @@ -159,8 +160,12 @@ static const struct message_entry msgtab[] = { { "OSMSG_MAX_CLIENTS", "Max clients: %d at %s" }, { "OSMSG_NETWORK_INFO", "Total users: %d (%d invisible, %d opers)" }, { "OSMSG_RESERVED_LIST", "List of reserved nicks:" }, - { "OSMSG_TRUSTED_LIST", "List of trusted hosts:" }, - { "OSMSG_HOST_IS_TRUSTED", "%s (%s; set %s ago by %s; expires %s: %s)" }, + { "OSMSG_TRUSTED_LIST", "$bTrusted Hosts$b" }, + { "OSMSG_TRUSTED_LIST_HEADER", "IP Address Limit By Time" }, + { "OSMSG_HOST_IS_TRUSTED", "%-15s %-5s %-10s set %s ago, expires %s" }, + { "OSMSG_HOST_IS_TRUSTED_DESC", " Reason: %s" }, + { "OSMSG_TRUSTED_LIST_BAR", "----------------------------------------" }, + { "OSMSG_TRUSTED_LIST_END", "----------End of Trusted Hosts----------" }, { "OSMSG_HOST_NOT_TRUSTED", "%s does not have a special trust." }, { "OSMSG_UPTIME_STATS", "Uptime: %s (%u lines processed, CPU time %.2fu/%.2fs)" }, { "OSMSG_LINE_DUMPED", "Raw line sent." }, @@ -196,6 +201,9 @@ static const struct message_entry msgtab[] = { { "OSMSG_SETTIME_SUCCESS", "Set time for servers named like $b%s$b." }, { "OSMSG_BAD_ACTION", "Unrecognized trace action $b%s$b." }, { "OSMSG_USER_SEARCH_RESULTS", "The following users were found:" }, + { "OSMSG_USER_SEARCH_HEADER", "Nick User@Host (Account)" }, + { "OSMSG_USER_SEARCH_BAR", "-------------------------------------------" }, + { "OSMSG_USER_SEARCH_COUNT", "------------ Found %4u matches -----------" }, { "OSMSG_CHANNEL_SEARCH_RESULTS", "The following channels were found:" }, { "OSMSG_GLINE_SEARCH_RESULTS", "The following glines were found:" }, { "OSMSG_LOG_SEARCH_RESULTS", "The following log entries were found:" }, @@ -214,8 +222,12 @@ static const struct message_entry msgtab[] = { { "OSMSG_ADDED_ALERT", "Added alert named $b%s$b." }, { "OSMSG_REMOVED_ALERT", "Removed alert named $b%s$b." }, { "OSMSG_NO_SUCH_ALERT", "No alert named $b%s$b could be found." }, - { "OSMSG_ALERT_IS", "%s (by %s, reaction %s): %s" }, - { "OSMSG_ALERTS_LIST", "Current $O alerts:" }, + { "OSMSG_ALERTS_LIST", "$bCurrent $O alerts$b" }, + { "OSMSG_ALERTS_BAR", "----------------------------------------------" }, + { "OSMSG_ALERTS_HEADER", "Name Action (by Oper)" }, + { "OSMSG_ALERTS_DESC", " Criteria: %s" }, + { "OSMSG_ALERT_IS", "$b%-20s$b %-6s (by %s)" }, + { "OSMSG_ALERT_END", "----------------End of Alerts-----------------" }, { "OSMSG_REHASH_COMPLETE", "Completed rehash of configuration database." }, { "OSMSG_REHASH_FAILED", "Rehash of configuration database failed, previous configuration is intact." }, { "OSMSG_REOPEN_COMPLETE", "Closed and reopened all log files." }, @@ -226,6 +238,7 @@ static const struct message_entry msgtab[] = { { "OSMSG_SERVER_JUPED", "Added new jupe server %s." }, { "OSMSG_SERVER_NOT_JUPE", "That server is not a juped server." }, { "OSMSG_SERVER_UNJUPED", "Server jupe removed." }, + /* { "OSMSG_WARN_ADDED", "Added channel activity warning for $b%s$b (%s)" }, { "OSMSG_WARN_EXISTS", "Channel activity warning for $b%s$b already exists." }, { "OSMSG_WARN_DELETED", "Removed channel activity warning for $b%s$b" }, @@ -233,6 +246,7 @@ static const struct message_entry msgtab[] = { { "OSMSG_WARN_LISTSTART", "Channel activity warnings:" }, { "OSMSG_WARN_LISTENTRY", "%s (%s)" }, { "OSMSG_WARN_LISTEND", "End of activity warning list." }, + */ { "OSMSG_UPLINK_CONNECTING", "Establishing connection with %s (%s:%d)." }, { "OSMSG_CURRENT_UPLINK", "$b%s$b is already the current uplink." }, { "OSMSG_INVALID_UPLINK", "$b%s$b is not a valid uplink name." }, @@ -257,13 +271,13 @@ static const struct message_entry msgtab[] = { { NULL, NULL } }; -#define OPSERV_SYNTAX() svccmd_send_help(user, opserv, cmd) +#define OPSERV_SYNTAX() svccmd_send_help_brief(user, opserv, cmd) typedef int (*discrim_search_func)(struct userNode *match, void *extra); struct userNode *opserv; -static dict_t opserv_chan_warn; /* data is char* */ +/*static dict_t opserv_chan_warn; */ /* data is char* */ static dict_t opserv_reserved_nick_dict; /* data is struct userNode* */ static struct string_list *opserv_bad_words; static dict_t opserv_exempt_channels; /* data is not used */ @@ -495,6 +509,8 @@ static MODCMD_FUNC(cmd_chaninfo) return 1; } +/* This command has been replaced by 'alert notice channel #foo' */ +/* static MODCMD_FUNC(cmd_warn) { char *reason, *message; @@ -535,6 +551,7 @@ static MODCMD_FUNC(cmd_unwarn) reply("OSMSG_WARN_DELETED", argv[1]); return 1; } +*/ static MODCMD_FUNC(cmd_clearbans) { @@ -544,9 +561,11 @@ static MODCMD_FUNC(cmd_clearbans) change = mod_chanmode_alloc(channel->banlist.used); for (ii=0; iibanlist.used; ii++) { change->args[ii].mode = MODE_REMOVE | MODE_BAN; - change->args[ii].u.hostmask = channel->banlist.list[ii]->ban; + change->args[ii].u.hostmask = strdup(channel->banlist.list[ii]->ban); } modcmd_chanmode_announce(change); + for (ii=0; iiargc; ++ii) + free((char*)change->args[ii].u.hostmask); mod_chanmode_free(change); reply("OSMSG_CLEARBANS_DONE", channel->name); return 1; @@ -606,7 +625,7 @@ static MODCMD_FUNC(cmd_dehop) || !(mn->modes & MODE_HALFOP)) continue; change->args[count].mode = MODE_REMOVE | MODE_HALFOP; - change->args[count++].member = mn; + change->args[count++].u.member = mn; } if (count) { change->argc = count; @@ -650,7 +669,7 @@ static MODCMD_FUNC(cmd_dehopall) if (IsService(mn->user) || !(mn->modes & MODE_HALFOP)) continue; change->args[count].mode = MODE_REMOVE | MODE_HALFOP; - change->args[count++].member = mn; + change->args[count++].u.member = mn; } if (count) { change->argc = count; @@ -1215,7 +1234,7 @@ static MODCMD_FUNC(cmd_hop) if (mn->modes & MODE_HALFOP) continue; change->args[count].mode = MODE_HALFOP; - change->args[count++].member = mn; + change->args[count++].u.member = mn; } if (count) { change->argc = count; @@ -1259,7 +1278,7 @@ static MODCMD_FUNC(cmd_hopall) if (mn->modes & MODE_HALFOP) continue; change->args[count].mode = MODE_HALFOP; - change->args[count++].member = mn; + change->args[count++].u.member = mn; } if (count) { change->argc = count; @@ -1280,10 +1299,8 @@ static MODCMD_FUNC(cmd_whois) if (argv[1][0] == '*') target = GetUserN(argv[1]+1); else - target = GetUserH(argv[1]); -#else - target = GetUserH(argv[1]); #endif + target = GetUserH(argv[1]); if (!target) { reply("MSG_NICK_UNKNOWN", argv[1]); return 0; @@ -1308,6 +1325,7 @@ static MODCMD_FUNC(cmd_whois) if (IsService(target)) buffer[bpos++] = 'k'; if (IsDeaf(target)) buffer[bpos++] = 'd'; + if (target->handle_info) buffer[bpos++] = 'r'; if (IsHiddenHost(target)) buffer[bpos++] = 'x'; if (IsGagged(target)) buffer_cat(" (gagged)"); if (IsRegistering(target)) buffer_cat(" (registered account)"); @@ -1392,8 +1410,10 @@ static MODCMD_FUNC(cmd_stats_bad) { char buffer[400]; /* Show the bad word list.. */ + /* TODO: convert nonprinting chars like bold to $b etc in a usable way */ for (ii=end=0; iiused; ii++) { here_len = strlen(opserv_bad_words->list[ii]); + /* If the line is full output it & start again */ if ((end + here_len + 2) > sizeof(buffer)) { buffer[end] = 0; reply("OSMSG_BADWORD_LIST", buffer); @@ -1553,6 +1573,10 @@ static MODCMD_FUNC(cmd_stats_trusted) { struct trusted_host *th; char length[INTERVALLEN], issued[INTERVALLEN], limit[32]; + reply("OSMSG_TRUSTED_LIST"); + reply("OSMSG_TRUSTED_LIST_BAR"); + reply("OSMSG_TRUSTED_LIST_HEADER"); + reply("OSMSG_TRUSTED_LIST_BAR"); if (argc > 1) { th = dict_find(opserv_trusted_hosts, argv[1], NULL); if (th) { @@ -1561,19 +1585,18 @@ static MODCMD_FUNC(cmd_stats_trusted) { if (th->expires) intervalString(length, th->expires - now, user->handle_info); if (th->limit) - sprintf(limit, "limit %lu", th->limit); + sprintf(limit, "%lu", th->limit); reply("OSMSG_HOST_IS_TRUSTED", th->ipaddr, - (th->limit ? limit : "no limit"), - (th->issued ? issued : "some time"), + (th->limit ? limit : "none"), (th->issuer ? th->issuer : ""), - (th->expires ? length : "never"), - (th->reason ? th->reason : "")); + (th->issued ? issued : "some time"), + (th->expires ? length : "never")); + reply("OSMSG_HOST_IS_TRUSTED_DESC", (th->reason ? th->reason : "")); } else { reply("OSMSG_HOST_NOT_TRUSTED", argv[1]); } } else { - reply("OSMSG_TRUSTED_LIST"); for (it = dict_first(opserv_trusted_hosts); it; it = iter_next(it)) { th = iter_data(it); if (th->issued) @@ -1581,15 +1604,16 @@ static MODCMD_FUNC(cmd_stats_trusted) { if (th->expires) intervalString(length, th->expires - now, user->handle_info); if (th->limit) - sprintf(limit, "limit %lu", th->limit); + sprintf(limit, "%lu", th->limit); reply("OSMSG_HOST_IS_TRUSTED", iter_key(it), - (th->limit ? limit : "no limit"), - (th->issued ? issued : "some time"), + (th->limit ? limit : "none"), (th->issuer ? th->issuer : ""), - (th->expires ? length : "never"), - (th->reason ? th->reason : "")); + (th->issued ? issued : "some time"), + (th->expires ? length : "never")); + reply("OSMSG_HOST_IS_TRUSTED_DESC", (th->reason ? th->reason : "")); } } + reply("OSMSG_TRUSTED_LIST_END"); return 1; } @@ -1635,6 +1659,9 @@ static MODCMD_FUNC(cmd_stats_alerts) { const char *reaction; reply("OSMSG_ALERTS_LIST"); + reply("OSMSG_ALERTS_BAR"); + reply("OSMSG_ALERTS_HEADER"); + reply("OSMSG_ALERTS_BAR"); for (it = dict_first(opserv_user_alerts); it; it = iter_next(it)) { alert = iter_data(it); switch (alert->reaction) { @@ -1643,8 +1670,10 @@ static MODCMD_FUNC(cmd_stats_alerts) { case REACT_GLINE: reaction = "gline"; break; default: reaction = ""; break; } - reply("OSMSG_ALERT_IS", iter_key(it), alert->owner, reaction, alert->text_discrim); + reply("OSMSG_ALERT_IS", iter_key(it), reaction, alert->owner); + reply("OSMSG_ALERTS_DESC", alert->text_discrim); } + reply("OSMSG_ALERT_END"); return 1; } @@ -1694,6 +1723,7 @@ static MODCMD_FUNC(cmd_stats_timeq) { return 1; } +/* static MODCMD_FUNC(cmd_stats_warn) { dict_iterator_t it; @@ -1703,12 +1733,35 @@ static MODCMD_FUNC(cmd_stats_warn) { reply("OSMSG_WARN_LISTEND"); return 1; } +*/ + +#if defined(WITH_MALLOC_X3) +static MODCMD_FUNC(cmd_stats_memory) { + extern unsigned long alloc_count, alloc_size; + send_message_type(MSG_TYPE_NOXLATE, user, cmd->parent->bot, + "%u allocations totalling %u bytes.", + alloc_count, alloc_size); + return 1; +} +#elif defined(WITH_MALLOC_SLAB) +static MODCMD_FUNC(cmd_stats_memory) { + extern unsigned long slab_alloc_count, slab_count, slab_alloc_size; + extern unsigned long big_alloc_count, big_alloc_size; + send_message_type(MSG_TYPE_NOXLATE, user, cmd->parent->bot, + "%u allocations in %u slabs totalling %u bytes.", + slab_alloc_count, slab_count, slab_alloc_size); +/* send_message_type(MSG_TYPE_NOXLATE, user, cmd->parent->bot, + "%u big allocations totalling %u bytes.", + */ + return 1; +} +#endif static MODCMD_FUNC(cmd_dump) { - char linedup[MAXLEN], *original; + char linedup[MAXLEN], original[MAXLEN]; - original = unsplit_string(argv+1, argc-1, NULL); + unsplit_string(argv+1, argc-1, original); safestrncpy(linedup, original, sizeof(linedup)); /* assume it's only valid IRC if we can parse it */ if (parse_line(linedup, 1)) { @@ -1721,9 +1774,9 @@ static MODCMD_FUNC(cmd_dump) static MODCMD_FUNC(cmd_raw) { - char linedup[MAXLEN], *original; + char linedup[MAXLEN], original[MAXLEN]; - original = unsplit_string(argv+1, argc-1, NULL); + unsplit_string(argv+1, argc-1, original); safestrncpy(linedup, original, sizeof(linedup)); /* Try to parse the line before sending it; if it's too wrong, * maybe it will core us instead of our uplink. */ @@ -1944,17 +1997,19 @@ opserv_shutdown_channel(struct chanNode *channel, const char *reason) static void opserv_channel_check(struct chanNode *newchan) { - char *warning; + /*char *warning; */ if (!newchan->join_policer.params) { newchan->join_policer.last_req = now; newchan->join_policer.params = opserv_conf.join_policer_params; } + /* if ((warning = dict_find(opserv_chan_warn, newchan->name, NULL))) { char message[MAXLEN]; snprintf(message, sizeof(message), "Channel activity warning for channel %s: %s", newchan->name, warning); global_message(MESSAGE_RECIPIENT_OPERS, message); } + */ /* Wait until the join check to shut channels down. */ newchan->bad_channel = opserv_bad_channel(newchan->name); @@ -2428,8 +2483,8 @@ static MODCMD_FUNC(cmd_clone) mod_chanmode_init(&change); change.argc = 1; change.args[0].mode = MODE_HALFOP; - change.args[0].member = GetUserMode(channel, clone); - if (!change.args[0].member) { + change.args[0].u.member = GetUserMode(channel, clone); + if (!change.args[0].u.member) { reply("OSMSG_NOT_ON_CHANNEL", clone->nick, channel->name); return 0; } @@ -2689,19 +2744,21 @@ opserv_add_user_alert(struct userNode *req, const char *name, opserv_alert_react return alert; } +/* static int add_chan_warn(const char *key, void *data, UNUSED_ARG(void *extra)) { struct record_data *rd = data; char *reason = GET_RECORD_QSTRING(rd); - /* i hope this can't happen */ + * i hope this can't happen * if (!reason) reason = "No Reason"; dict_insert(opserv_chan_warn, strdup(key), strdup(reason)); return 0; } +*/ static int add_user_alert(const char *key, void *data, UNUSED_ARG(void *extra)) @@ -2819,8 +2876,10 @@ opserv_saxdb_read(struct dict *conf_db) dict_foreach(object, add_gag_helper, NULL); if ((object = database_get_data(conf_db, KEY_ALERTS, RECDB_OBJECT))) dict_foreach(object, add_user_alert, NULL); +/* if ((object = database_get_data(conf_db, KEY_WARN, RECDB_OBJECT))) dict_foreach(object, add_chan_warn, NULL); +*/ return 0; } @@ -2886,6 +2945,7 @@ opserv_saxdb_write(struct saxdb_context *ctx) saxdb_end_record(ctx); } /* channel warnings */ + /* if (dict_size(opserv_chan_warn)) { saxdb_start_record(ctx, KEY_WARN, 0); for (it = dict_first(opserv_chan_warn); it; it = iter_next(it)) { @@ -2893,6 +2953,7 @@ opserv_saxdb_write(struct saxdb_context *ctx) } saxdb_end_record(ctx); } + */ /* alerts */ if (dict_size(opserv_user_alerts)) { saxdb_start_record(ctx, KEY_ALERTS, 1); @@ -3320,9 +3381,9 @@ trace_print_func(struct userNode *match, void *extra) { struct discrim_and_source *das = extra; if (match->handle_info) { - send_message_type(4, das->source, opserv, "%s!%s@%s %s", match->nick, match->ident, match->hostname, match->handle_info->handle); + send_message_type(4, das->source, opserv, "%-15s\002 \002%10s\002@\002%s (%s)", match->nick, match->ident, match->hostname, match->handle_info->handle); } else { - send_message_type(4, das->source, opserv, "%s!%s@%s", match->nick, match->ident, match->hostname); + send_message_type(4, das->source, opserv, "%-15s\002 \002%10s\002@\002%s", match->nick, match->ident, match->hostname); } return 0; } @@ -3506,7 +3567,12 @@ static MODCMD_FUNC(cmd_trace) return 0; if (action == trace_print_func) + { reply("OSMSG_USER_SEARCH_RESULTS"); + reply("OSMSG_USER_SEARCH_BAR"); + reply("OSMSG_USER_SEARCH_HEADER"); + reply("OSMSG_USER_SEARCH_BAR"); + } else if (action == trace_count_func) das.discrim->limit = INT_MAX; else if ((action == trace_gline_func) && !das.discrim->duration) @@ -3524,7 +3590,7 @@ static MODCMD_FUNC(cmd_trace) dict_foreach(das.dict, opserv_show_hostinfo, &das); if (matches) - reply("MSG_MATCH_COUNT", matches); + reply("OSMSG_USER_SEARCH_COUNT", matches); else reply("MSG_NO_MATCHES"); @@ -4122,10 +4188,13 @@ opserv_db_init(void) { opserv_trusted_hosts = dict_new(); dict_set_free_data(opserv_trusted_hosts, free_trusted_host); /* set up opserv_chan_warn dict */ + +/* alert trace notice channel #x replaces warnings dict_delete(opserv_chan_warn); opserv_chan_warn = dict_new(); dict_set_free_keys(opserv_chan_warn, free); dict_set_free_data(opserv_chan_warn, free); +*/ /* set up opserv_user_alerts */ dict_delete(opserv_channel_alerts); opserv_channel_alerts = dict_new(); @@ -4149,7 +4218,7 @@ opserv_db_cleanup(void) { unsigned int nn; - dict_delete(opserv_chan_warn); +/* dict_delete(opserv_chan_warn); */ dict_delete(opserv_reserved_nick_dict); free_string_list(opserv_bad_words); dict_delete(opserv_exempt_channels); @@ -4254,7 +4323,10 @@ init_opserv(const char *nick) opserv_define_func("STATS TRUSTED", cmd_stats_trusted, 0, 0, 0); opserv_define_func("STATS UPLINK", cmd_stats_uplink, 0, 0, 0); opserv_define_func("STATS UPTIME", cmd_stats_uptime, 0, 0, 0); - opserv_define_func("STATS WARN", cmd_stats_warn, 0, 0, 0); +/* opserv_define_func("STATS WARN", cmd_stats_warn, 0, 0, 0); */ +#if defined(WITH_MALLOC_X3) || defined(WITH_MALLOC_SLAB) + opserv_define_func("STATS MEMORY", cmd_stats_memory, 0, 0, 0); +#endif opserv_define_func("TRACE", cmd_trace, 100, 0, 3); opserv_define_func("TRACE PRINT", NULL, 0, 0, 0); opserv_define_func("TRACE COUNT", NULL, 0, 0, 0); @@ -4268,9 +4340,9 @@ init_opserv(const char *nick) modcmd_register(opserv_module, "GTRACE UNGLINE", NULL, 0, 0, "template", "ungline", NULL); opserv_define_func("UNJUPE", cmd_unjupe, 900, 0, 2); opserv_define_func("UNRESERVE", cmd_unreserve, 800, 0, 2); - opserv_define_func("UNWARN", cmd_unwarn, 800, 0, 0); +/* opserv_define_func("UNWARN", cmd_unwarn, 800, 0, 0); */ opserv_define_func("VOICEALL", cmd_voiceall, 300, 2, 0); - opserv_define_func("WARN", cmd_warn, 800, 0, 2); +/* opserv_define_func("WARN", cmd_warn, 800, 0, 2); */ opserv_define_func("WHOIS", cmd_whois, 0, 0, 2); opserv_reserved_nick_dict = dict_new(); @@ -4281,7 +4353,7 @@ init_opserv(const char *nick) reg_new_user_func(opserv_new_user_check); reg_nick_change_func(opserv_alert_check_nick); reg_del_user_func(opserv_user_cleanup); - reg_new_channel_func(opserv_channel_check); + reg_new_channel_func(opserv_channel_check); reg_del_channel_func(opserv_channel_delete); reg_join_func(opserv_join_check); reg_auth_func(opserv_staff_alert);