X-Git-Url: https://jfr.im/git/irc/evilnet/x3.git/blobdiff_plain/0e08a8e0da1204f414c27c5352a590244c7a0e9a..cbfd323c3191336a3c07c24725019cdaf87f0dd6:/src/opserv.c diff --git a/src/opserv.c b/src/opserv.c index e28b4d2..197610a 100644 --- a/src/opserv.c +++ b/src/opserv.c @@ -5,7 +5,7 @@ * * x3 is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or + * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, @@ -18,6 +18,8 @@ * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ +#include "config.h" +#include "chanserv.h" #include "conf.h" #include "common.h" #include "gline.h" @@ -43,7 +45,6 @@ #include #endif - #define OPSERV_CONF_NAME "services/opserv" #define KEY_ALERT_CHANNEL "alert_channel" @@ -75,6 +76,7 @@ #define KEY_WARN "chanwarn" #define KEY_MAX "max" #define KEY_TIME "time" +#define KEY_LAST "last" #define KEY_MAX_CLIENTS "max_clients" #define KEY_LIMIT "limit" #define KEY_EXPIRES "expires" @@ -163,17 +165,24 @@ static const struct message_entry msgtab[] = { { "OSMSG_NO_DEBUG_CHANNEL", "No debug channel has been configured." }, { "OSMSG_INVITE_DONE", "Invited $b%s$b to $b%s$b." }, { "OSMSG_ALREADY_THERE", "You are already in $b%s$b." }, + { "OSMSG_USER_ALREADY_THERE", "%s is already in $b%s$b." }, + { "OSMSG_NOT_THERE", "You not in $b%s$b." }, { "OSMSG_JOIN_DONE", "I have joined $b%s$b." }, + { "OSMSG_MARK_SET", "Set the MARK." }, { "OSMSG_SVSJOIN_SENT", "Sent the SVSJOIN." }, + { "OSMSG_SVSPART_SENT", "Sent the SVSPART." }, { "OSMSG_ALREADY_JOINED", "I am already in $b%s$b." }, { "OSMSG_NOT_ON_CHANNEL", "$b%s$b does not seem to be on $b%s$b." }, { "OSMSG_KICKALL_DONE", "I have cleared out %s." }, { "OSMSG_LEAVING", "Leaving $b%s$b." }, + { "OSMSG_MARK_INVALID", "Sorry, marks must contain only letters, numbers, and dashes ('-')." }, { "OSMSG_MODE_SET", "I have set the modes for $b%s$b." }, { "OSMSG_OP_DONE", "Opped the requested lusers." }, { "OSMSG_OPALL_DONE", "Opped everyone on $b%s$b." }, { "OSMSG_HOP_DONE", "Halfopped the requested lusers." }, { "OSMSG_HOPALL_DONE", "Halfopped everyone on $b%s$b." }, + { "OMSG_BAD_SVSNICK", "$b%s$b is an invalid nickname." }, + { "OSMSG_WHOIS_IDENT", "%s (%s@%s) from %d.%d.%d.%d" }, { "OSMSG_WHOIS_NICK", "Nick : %s" }, { "OSMSG_WHOIS_HOST", "Host : %s@%s" }, @@ -201,6 +210,8 @@ static const struct message_entry msgtab[] = { { "OSMSG_WHOIS_CHANNELS", "Channels : %s" }, { "OSMSG_WHOIS_HIDECHANS", "Channel list omitted for your sanity." }, { "OSMSG_WHOIS_VERSION", "Version : %s" }, + { "OSMSG_WHOIS_MARK", "Mark : %s" }, + { "OSMSG_WHOIS_NO_NOTICE", "No_notices : %s" }, { "OSMSG_UNBAN_DONE", "Ban(s) removed from channel %s." }, { "OSMSG_CHANNEL_VOICED", "All users on %s voiced." }, { "OSMSG_CHANNEL_DEVOICED", "All voiced users on %s de-voiced." }, @@ -277,6 +288,9 @@ static const struct message_entry msgtab[] = { { "OSMSG_USER_SEARCH_BAR", "-------------------------------------------" }, { "OSMSG_USER_SEARCH_COUNT", "There were %4u matches" }, { "OSMSG_USER_SEARCH_COUNT_BAR", "------------ Found %4u matches -----------" }, + { "OSMSG_MARK_NO_MARK", "MARK action requires mark criteria (what do you want to mark them as?)" }, + { "OSMSG_SVSJOIN_NO_TARGET", "SVSJOIN action requires chantarget criteria (where should they join?)" }, + { "OSMSG_SVSPART_NO_TARGET", "SVSPART action requires chantarget criteria (where should they join?)" }, { "OSMSG_CHANNEL_SEARCH_RESULTS", "The following channels were found:" }, { "OSMSG_GLINE_SEARCH_RESULTS", "The following glines were found:" }, { "OSMSG_SHUN_SEARCH_RESULTS", "The following shun were found:" }, @@ -296,24 +310,28 @@ static const struct message_entry msgtab[] = { { "OSMSG_ALERT_EXISTS", "An alert named $b%s$b already exists." }, { "OSMSG_UNKNOWN_REACTION", "Unknown alert reaction $b%s$b." }, { "OSMSG_ADDED_ALERT", "Added alert named $b%s$b." }, + { "OSMSG_ALERT_ADD_FAILED", "Unable to add alert. Check syntax, required parts, and access" }, { "OSMSG_REMOVED_ALERT", "Removed alert named $b%s$b." }, { "OSMSG_NO_SUCH_ALERT", "No alert named $b%s$b could be found." }, - { "OSMSG_ALERTS_LIST", "$bCurrent $O alerts$b" }, + { "OSMSG_ALERTS_LIST", "$bCurrent $O alerts matching '$b%s$b'$b" }, { "OSMSG_ALERTS_BAR", "----------------------------------------------" }, { "OSMSG_ALERTS_HEADER", "Name Action (by Oper)" }, - { "OSMSG_ALERTS_DESC", " Criteria: %s" }, + { "OSMSG_ALERTS_DESC", " $uCriteria$u: %s" }, + { "OSMSG_ALERTS_LAST", " $uTriggered$u: %s" }, { "OSMSG_ALERT_IS", "$b%-20s$b %-6s (by %s)" }, { "OSMSG_ALERT_END", "----------------End of Alerts-----------------" }, /* routing messages */ - { "OSMSG_ROUTINGPLAN_LIST", "$bRouting Plans$b" }, + { "OSMSG_ROUTINGPLAN", "$bRouting Plan(s)$b" }, + { "OSMSG_ROUTINGPLAN_LIST_HEAD", "$bRouting Plans$b" }, { "OSMSG_ROUTINGPLAN_BAR", "----------------------------------------------" }, - { "OSMSG_ROUTINGPLAN_END", "-------------End of Routing Plans-------------" }, + { "OSMSG_ROUTINGPLAN_END", "------------End of Routing Plan(s)------------" }, { "OSMSG_ROUTINGPLAN_OPTION", "%s is set to %s" }, { "OSMSG_ROUTINGPLAN_ACTIVE", "Auto routing is active, using plan '%s'." }, { "OSMSG_ROUTING_ACTIVATION_ERROR", "There was an error activating the routing plan. Check for loops, and make sure the map includes my own uplink." }, { "OSMSG_ROUTINGPLAN_OPTION_NOT_FOUND", "There is no routing plan option '%s'." }, { "OSMSG_ROUTINGPLAN_OPTION_NOT_SET", "Option '%s' is not currently set." }, { "OSMSG_ROUTINGPLAN_NAME", "$b%s:$b" }, + { "OSMSG_ROUTINGPLAN_LIST", "$b%s$b" }, { "OSMSG_ROUTINGPLAN_SERVER"," %s:%d <-- %s[%d/%s] (%s)" }, { "OSMSG_ADDPLAN_SUCCESS", "Added new routing plan '%s'." }, { "OSMSG_ADDPLAN_FAILED", "Could not add new plan '%s' (does it already exist?)." }, @@ -512,7 +530,7 @@ opserv_free_waiting_connection(void *data) typedef struct opservDiscrim { struct chanNode *channel; - char *mask_nick, *mask_ident, *mask_host, *mask_info, *mask_version, *server, *reason, *accountmask, *chantarget; + char *mask_nick, *mask_ident, *mask_host, *mask_info, *mask_version, *server, *reason, *accountmask, *chantarget, *mark, *mask_mark, *modes; irc_in_addr_t ip_mask; unsigned long limit; time_t min_ts, max_ts; @@ -526,6 +544,7 @@ typedef struct opservDiscrim { unsigned int intra_scmp : 2, intra_dcmp : 2; unsigned int use_regex : 1; unsigned int silent : 1; + unsigned int checkrestrictions : 2; } *discrim_t; struct discrim_and_source { @@ -548,7 +567,9 @@ typedef enum { REACT_TRACK, REACT_SHUN, REACT_SVSJOIN, - REACT_VERSION + REACT_SVSPART, + REACT_VERSION, + REACT_MARK } opserv_alert_reaction; struct opserv_user_alert { @@ -556,6 +577,7 @@ struct opserv_user_alert { char *text_discrim, *split_discrim; discrim_t discrim; opserv_alert_reaction reaction; + int last; }; /* funny type to make it acceptible to dict_set_free_data, far below */ @@ -736,7 +758,7 @@ static MODCMD_FUNC(cmd_defcon) showDefConSettings(user, cmd); if (DefConTimeOut > 0) { - timeq_del(0, defcon_timeout, NULL, TIMEQ_IGNORE_DATA & TIMEQ_IGNORE_WHEN); + timeq_del(0, defcon_timeout, NULL, TIMEQ_IGNORE_DATA | TIMEQ_IGNORE_WHEN); timeq_add(now + DefConTimeOut, defcon_timeout, NULL); } @@ -1349,7 +1371,15 @@ opserv_version(struct userNode *target) } static void -opserv_svsjoin(struct userNode *target, UNUSED_ARG(char *src_handle), UNUSED_ARG(char *reason), char *channame) +opserv_mark(struct userNode *target, UNUSED_ARG(char *src_handle), UNUSED_ARG(char *reason), char *mark) +{ + if(!mark) + return; + irc_mark(target, mark); +} + +static void +opserv_svsjoin(struct userNode *target, UNUSED_ARG(char *src_handle), UNUSED_ARG(char *reason), char *channame, unsigned int checkrestrictions) { struct chanNode *channel; @@ -1366,10 +1396,53 @@ opserv_svsjoin(struct userNode *target, UNUSED_ARG(char *src_handle), UNUSED_ARG return; } + if (checkrestrictions) { + if (trace_check_bans(target, channel) == 1) { + return; /* found on lamer list */ + } + + if (channel->modes & MODE_INVITEONLY) { + return; /* channel is invite only */ + } + + if (channel->limit > 0) { + if (channel->members.used >= channel->limit) { + return; /* channel is invite on */ + } + } + + if (*channel->key) { + return; /* channel is password protected */ + } + } + irc_svsjoin(opserv, target, channel); /* Should we tell the user they got joined? -Rubin*/ } +static void +opserv_svspart(struct userNode *target, UNUSED_ARG(char *src_handle), UNUSED_ARG(char *reason), char *channame) +{ + struct chanNode *channel; + + if(!channame || !IsChannelName(channame)) { + /* Not a valid channel name. We shouldnt ever get this if we check properly in addalert */ + return; + } + + if (!(channel = GetChannel(channame))) { + /* channel doesnt exist */ + return; + } + + if (!GetUserMode(channel, target)) { + /* not in it */ + return; + } + + irc_svspart(opserv, target, channel); +} + static struct shun * opserv_shun(struct userNode *target, char *src_handle, char *reason, unsigned long duration) { @@ -1466,7 +1539,7 @@ static MODCMD_FUNC(cmd_refreshs) } static void -opserv_ison(struct userNode *tell, struct userNode *target, const char *message) +opserv_ison(struct userNode *bot, struct userNode *tell, struct userNode *target, const char *message) { struct modeNode *mn; unsigned int count, here_len, n, maxlen; @@ -1480,7 +1553,7 @@ opserv_ison(struct userNode *tell, struct userNode *target, const char *message) here_len = strlen(mn->channel->name); if ((count + here_len + 4) > maxlen) { buff[count] = 0; - send_message(tell, opserv, message, buff); + send_message(tell, bot, message, buff); count = 0; } if (mn->modes & MODE_CHANOP) @@ -1495,7 +1568,7 @@ opserv_ison(struct userNode *tell, struct userNode *target, const char *message) } if (count) { buff[count] = 0; - send_message(tell, opserv, message, buff); + send_message(tell, bot, message, buff); } } @@ -1555,7 +1628,7 @@ static MODCMD_FUNC(cmd_svsjoin) channel = AddChannel(argv[2], now, NULL, NULL, NULL); } if (GetUserMode(channel, target)) { - reply("OSMSG_ALREADY_THERE", channel->name); + reply("OSMSG_USER_ALREADY_THERE", target->nick, channel->name); return 0; } irc_svsjoin(opserv, target, channel); @@ -1563,6 +1636,23 @@ static MODCMD_FUNC(cmd_svsjoin) return 1; } +static MODCMD_FUNC(cmd_svsnick) +{ + struct userNode *target; + + target = GetUserH(argv[1]); + if (!target) { + reply("MSG_NICK_UNKNOWN", argv[1]); + return 0; + } + if(!is_valid_nick(argv[2])) { + reply("OMSG_BAD_SVSNICK", argv[2]); + return 0; + } + irc_svsnick(opserv, target, argv[2]); + return 1; +} + static MODCMD_FUNC(cmd_join) { struct userNode *bot = cmd->parent->bot; @@ -1729,6 +1819,36 @@ static MODCMD_FUNC(cmd_kickbanall) return 1; } +static MODCMD_FUNC(cmd_svspart) +{ + struct userNode *target; + struct chanNode *target_channel; + + if(!IsChannelName(argv[2])) { + reply("MSG_NOT_CHANNEL_NAME"); + return 0; + } + if(!(target_channel = GetChannel(argv[2]))) + { + reply("MSG_INVALID_CHANNEL"); + return 0; + } + target = GetUserH(argv[1]); + if (!target) { + reply("MSG_NICK_UNKNOWN", argv[1]); + return 0; + } + + if (!GetUserMode(target_channel, target)) { + reply("OSMSG_NOT_ON_CHANNEL", cmd->parent->bot->nick, target_channel->name); + return 0; + } + + irc_svspart(opserv, target, target_channel); + reply("OSMSG_SVSPART_SENT"); + return 1; +} + static MODCMD_FUNC(cmd_part) { char *reason; @@ -1759,6 +1879,40 @@ static MODCMD_FUNC(cmd_mode) return 1; } +int is_valid_mark(char *mark) +{ + char *ptr; + + if(!mark || !*mark) + return 0; + if(strlen(mark) > MARKLEN) + return 0; + + for(ptr = mark; *ptr; ptr++) { + if(! (isalnum(*ptr) || *ptr == '-')) + return 0; + } + + return 1; +} + +static MODCMD_FUNC(cmd_mark) +{ + char *mark = argv[2]; + struct userNode *victim = GetUserH(argv[1]); + + if(!victim) + reply("MSG_NICK_UNKNOWN", argv[1]); + else if(!is_valid_mark(mark)) + reply("OSMSG_MARK_INVALID"); + else { + irc_mark(victim, mark); + reply("OSMSG_MARK_SET"); + return 1; + } + return 0; +} + static MODCMD_FUNC(cmd_op) { struct mod_chanmode *change; @@ -1908,6 +2062,10 @@ static MODCMD_FUNC(cmd_whois) if(target->version_reply) { reply("OSMSG_WHOIS_VERSION", target->version_reply); } + if(target->mark) { + reply("OSMSG_WHOIS_MARK", target->mark); + } + reply("OSMSG_WHOIS_NO_NOTICE", target->no_notice ? "YES":"NO"); if (target->modes) { bpos = 0; @@ -1926,6 +2084,10 @@ static MODCMD_FUNC(cmd_whois) if (IsDeaf(target)) buffer[bpos++] = 'd'; if (target->handle_info) buffer[bpos++] = 'r'; if (IsHiddenHost(target)) buffer[bpos++] = 'x'; + if (IsBotM(target)) buffer[bpos++] = 'B'; + if (IsHideChans(target)) buffer[bpos++] = 'n'; + if (IsHideIdle(target)) buffer[bpos++] = 'I'; + if (IsXtraOp(target)) buffer[bpos++] = 'X'; if (IsGagged(target)) buffer_cat(" (gagged)"); if (IsRegistering(target)) buffer_cat(" (registered account)"); buffer[bpos] = 0; @@ -1944,7 +2106,7 @@ static MODCMD_FUNC(cmd_whois) intervalString(buffer, now - target->timestamp, user->handle_info); reply("OSMSG_WHOIS_NICK_AGE", buffer); if (target->channels.used <= MAX_CHANNELS_WHOIS) - opserv_ison(user, target, "OSMSG_WHOIS_CHANNELS"); + opserv_ison(cmd->parent->bot, user, target, "OSMSG_WHOIS_CHANNELS"); else reply("OSMSG_WHOIS_HIDECHANS"); return 1; @@ -2264,13 +2426,19 @@ static MODCMD_FUNC(cmd_stats_alerts) { dict_iterator_t it; struct opserv_user_alert *alert; const char *reaction; + char t_buffer[INTERVALLEN]; + char *m = NULL; - reply("OSMSG_ALERTS_LIST"); + if(argc > 1) + m = unsplit_string(argv + 1, argc - 1, NULL); + reply("OSMSG_ALERTS_LIST", m ? m : "*"); 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); + if(m && (!match_ircglob(alert->text_discrim, m) && strcasecmp(alert->owner, m) && strcasecmp(iter_key(it), m))) + continue; /* not a match to requested filter */ switch (alert->reaction) { case REACT_NOTICE: reaction = "notice"; break; case REACT_KILL: reaction = "kill"; break; @@ -2279,11 +2447,17 @@ static MODCMD_FUNC(cmd_stats_alerts) { case REACT_TRACK: reaction = "track"; break; case REACT_SHUN: reaction = "shun"; break; case REACT_SVSJOIN: reaction = "svsjoin"; break; + case REACT_SVSPART: reaction = "svspart"; break; case REACT_VERSION: reaction = "version"; break; + case REACT_MARK: reaction = "mark"; break; default: reaction = ""; break; } reply("OSMSG_ALERT_IS", iter_key(it), reaction, alert->owner); reply("OSMSG_ALERTS_DESC", alert->text_discrim); + if (alert->last > 0) + reply("OSMSG_ALERTS_LAST", intervalString(t_buffer, now - alert->last, user->handle_info)); + else + reply("OSMSG_ALERTS_LAST", "Never"); } reply("OSMSG_ALERT_END"); return 1; @@ -2529,7 +2703,7 @@ opserv_new_user_check(struct userNode *user) } if (checkDefCon(DEFCON_NO_NEW_CLIENTS)) { - irc_kill(opserv, user, DefConGlineReason); + DelUser(user, opserv, 1, DefConGlineReason); return 0; } @@ -2669,12 +2843,12 @@ opserv_notice_handler(struct userNode *user, struct userNode *bot, char *text, U if(text[0] == '\001') { text++; cmd = mysep(&text, " "); - if(!irccasecmp(cmd, "VERSION")) { + if(cmd && !irccasecmp(cmd, "VERSION")) { char *version = mysep(&text, "\n"); if(!version) version = ""; /* opserv_debug("Opserv got CTCP VERSION Notice from %s: %s", user->nick, version); */ - user->version_reply = strdup(version); + /* user->version_reply = strdup(version); done in parse-p10.c now */ dict_foreach(opserv_user_alerts, alert_check_user, user); } } @@ -2897,7 +3071,7 @@ rank_outside_rec(struct route *route, char *server, int count) return(max + 1); } else { - log_module(MAIN_LOG, LOG_ERROR, "routing struct rank_outsideness() couldnt find %s", server); + log_module(MAIN_LOG, LOG_WARNING, "routing struct rank_outsideness() couldnt find %s", server); return 0; } } @@ -2970,7 +3144,7 @@ change_route_uplinks(struct route *route) strcpy(lastserver, servicename); rptr = find_routeList_server(route, self->uplink->name); if(!rptr) { - log_module(MAIN_LOG, LOG_ERROR, "Cannot convert routing map to center: My uplink is not on the map! Marking map as uncentered."); + log_module(MAIN_LOG, LOG_WARNING, "Cannot convert routing map to center: My uplink is not on the map! Marking map as uncentered."); route->centered = false; return false; } @@ -3017,7 +3191,7 @@ activate_routing(struct svccmd *cmd, struct userNode *user, char *plan_name) /* since it doesnt exist, remove the active setting */ dict_remove(opserv_routing_plan_options, plan_name); } - log_module(MAIN_LOG, LOG_ERROR, "activate_routing() couldnt find active routing plan!"); + log_module(MAIN_LOG, LOG_WARNING, "activate_routing() couldnt find active routing plan!"); return 0; } } @@ -3042,6 +3216,8 @@ activate_routing(struct svccmd *cmd, struct userNode *user, char *plan_name) /* Delete the existing active route */ wipe_route_list(opserv_route); + if(!rp || !rp->servers) + return 1; for(it = dict_first(rp->servers); it; it = iter_next(it)) { const char* servername = iter_key(it); struct routingPlanServer *rps = iter_data(it), @@ -3076,15 +3252,27 @@ activate_routing(struct svccmd *cmd, struct userNode *user, char *plan_name) add_routestruct_server(opserv_route, servername, rps->port, uplink, NULL); } if(change_route_uplinks(opserv_route)) + { return 1; + } else if(user) { reply("OSMSG_ROUTING_ACTIVATION_ERROR"); activate_routing(cmd, user, "*"); return 0; } + /* routing activation failed but we dont do anything? */ return 1; } + +void routing_init() +{ + activate_routing(NULL, NULL, NULL); + + /* start auto-routing system */ + reroute_timer_reset(0); +} + /******************************************************* * Functions to handle online route configuration via opserv */ @@ -3314,6 +3502,9 @@ static MODCMD_FUNC(cmd_reroute) { * and setup timer. */ void reroute_timer(void *data) { + /* Delete any other timers such as this one.. */ + timeq_del(0, reroute_timer, NULL, TIMEQ_IGNORE_DATA | TIMEQ_IGNORE_WHEN); + if(!opserv_route || !opserv_route->servers) return; /* no active route */ char *retry_period = dict_find(opserv_routing_plan_options, "RETRY_PERIOD", NULL); @@ -3323,6 +3514,9 @@ void reroute_timer(void *data) { if(freq < 1) return; /* retry_period set to 0, disable */ + /* opserv_debug("Reroute timer checking reroute"); */ + log_module(MAIN_LOG, LOG_DEBUG, "Reroute timer checking reroute()"); + /* Do the reroute C attempt */ if(data) reroute(opserv_route, NULL, NULL, "C"); @@ -3496,7 +3690,7 @@ routing_handle_connect_failure(struct server *source, char *server, char *messag char *active; struct routingPlan *rp; struct routingPlanServer *rps; - log_module(MAIN_LOG, LOG_ERROR, "Failed to connect %s to %s: %s", server, source->name, message); + log_module(MAIN_LOG, LOG_WARNING, "Failed to connect %s to %s: %s", server, source->name, message); /* remove the waiting connection n timeq */ routing_delete_connect_timer(server); /* check if routing is active.. */ @@ -3528,10 +3722,23 @@ routing_handle_connect_failure(struct server *source, char *server, char *messag /* Delete any existing timers, and start the timer again * using the passed time for the first run. * - this is called during a retry_period change - * before it has saved the new value. */ + * before it has saved the new value. + * + * If time is 0, lookup the interval. */ void reroute_timer_reset(unsigned int time) { - timeq_del(0, reroute_timer, NULL, TIMEQ_IGNORE_DATA & TIMEQ_IGNORE_WHEN); + timeq_del(0, reroute_timer, NULL, TIMEQ_IGNORE_DATA | TIMEQ_IGNORE_WHEN); + if(time == 0) { + if(!opserv_route || !opserv_route->servers) + return; /* no active route */ + char *retry_period = dict_find(opserv_routing_plan_options, "RETRY_PERIOD", NULL); + if(!retry_period) + return; /* retry_period invalid */ + time = atoi(retry_period); + if(time < 1) + return; /* retry_period set to 0, disable */ + + } timeq_add(now + time, reroute_timer, "run"); } @@ -3604,21 +3811,34 @@ static MODCMD_FUNC(cmd_stats_routing_plans) { dict_iterator_t rpit; dict_iterator_t it; struct routingPlan *rp; - reply("OSMSG_ROUTINGPLAN_LIST"); - reply("OSMSG_ROUTINGPLAN_BAR"); - for(rpit = dict_first(opserv_routing_plans); rpit; rpit = iter_next(rpit)) { - const char* name = iter_key(rpit); - rp = iter_data(rpit); - reply("OSMSG_ROUTINGPLAN_NAME", name); - for(it = dict_first(rp->servers); it; it = iter_next(it)) { - const char* servername = iter_key(it); - struct routingPlanServer *rps = iter_data(it); - reply("OSMSG_ROUTINGPLAN_SERVER", servername, rps->port, rps->uplink, rps->karma, rps->offline? "offline" : "online", rps->secondaryuplink ? rps->secondaryuplink : "None"); - } + if(argc > 1) { + reply("OSMSG_ROUTINGPLAN"); + reply("OSMSG_ROUTINGPLAN_BAR"); + for(rpit = dict_first(opserv_routing_plans); rpit; rpit = iter_next(rpit)) { + const char* name = iter_key(rpit); + rp = iter_data(rpit); + if(match_ircglob(name, argv[1])) { + reply("OSMSG_ROUTINGPLAN_NAME", name); + for(it = dict_first(rp->servers); it; it = iter_next(it)) { + const char* servername = iter_key(it); + struct routingPlanServer *rps = iter_data(it); + reply("OSMSG_ROUTINGPLAN_SERVER", servername, rps->port, rps->uplink, rps->karma, rps->offline? "offline" : "online", rps->secondaryuplink ? rps->secondaryuplink : "None"); + } + } + } + reply("OSMSG_ROUTINGPLAN_END"); + } + else { + reply("OSMSG_ROUTINGPLAN_LIST_HEAD"); + reply("OSMSG_ROUTINGPLAN_BAR"); + for(rpit = dict_first(opserv_routing_plans); rpit; rpit = iter_next(rpit)) { + const char* name = iter_key(rpit); + reply("OSMSG_ROUTINGPLAN_LIST", name); + } + reply("OSMSG_ROUTINGPLAN_END"); + route_show_options(cmd, user); } - reply("OSMSG_ROUTINGPLAN_END"); - route_show_options(cmd, user); return 1; } @@ -4442,7 +4662,7 @@ add_gag_helper(const char *key, void *data, UNUSED_ARG(void *extra)) } static struct opserv_user_alert * -opserv_add_user_alert(struct userNode *req, const char *name, opserv_alert_reaction reaction, const char *text_discrim) +opserv_add_user_alert(struct userNode *req, const char *name, opserv_alert_reaction reaction, const char *text_discrim, int last) { unsigned int wordc; char *wordv[MAXNUMPARAMS], *discrim_copy; @@ -4456,10 +4676,14 @@ opserv_add_user_alert(struct userNode *req, const char *name, opserv_alert_react alert = malloc(sizeof(*alert)); alert->owner = strdup(req->handle_info ? req->handle_info->handle : req->nick); alert->text_discrim = strdup(text_discrim); + alert->last = last; discrim_copy = strdup(text_discrim); /* save a copy of the discrim */ wordc = split_line(discrim_copy, false, ArrayLength(wordv), wordv); alert->discrim = opserv_discrim_create(req, opserv, wordc, wordv, 0); - if (!alert->discrim) { + /* Check for missing required criteria or broken records */ + if (!alert->discrim || (reaction==REACT_SVSJOIN && !alert->discrim->chantarget) || + (reaction==REACT_SVSPART && !alert->discrim->chantarget) || + (reaction==REACT_MARK && !alert->discrim->mark)) { free(alert->text_discrim); free(discrim_copy); free(alert); @@ -4504,6 +4728,8 @@ static int add_user_alert(const char *key, void *data, UNUSED_ARG(void *extra)) { dict_t alert_dict; + char *str; + int last = 0; const char *discrim, *react, *owner; opserv_alert_reaction reaction; struct opserv_user_alert *alert; @@ -4514,6 +4740,10 @@ add_user_alert(const char *key, void *data, UNUSED_ARG(void *extra)) } discrim = database_get_data(alert_dict, KEY_DISCRIM, RECDB_QSTRING); react = database_get_data(alert_dict, KEY_REACTION, RECDB_QSTRING); + str = database_get_data(alert_dict, KEY_LAST, RECDB_QSTRING); + if (str) + last = atoi(str); + if (!react || !irccasecmp(react, "notice")) reaction = REACT_NOTICE; else if (!irccasecmp(react, "kill")) @@ -4530,13 +4760,17 @@ add_user_alert(const char *key, void *data, UNUSED_ARG(void *extra)) reaction = REACT_SHUN; else if (!irccasecmp(react, "svsjoin")) reaction = REACT_SVSJOIN; + else if (!irccasecmp(react, "svspart")) + reaction = REACT_SVSPART; else if (!irccasecmp(react, "version")) reaction = REACT_VERSION; + else if (!irccasecmp(react, "mark")) + reaction = REACT_MARK; else { log_module(OS_LOG, LOG_ERROR, "Invalid reaction %s for alert %s.", react, key); return 0; } - alert = opserv_add_user_alert(opserv, key, reaction, discrim); + alert = opserv_add_user_alert(opserv, key, reaction, discrim, last); if (!alert) { log_module(OS_LOG, LOG_ERROR, "Unable to create alert %s from database.", key); return 0; @@ -4806,6 +5040,7 @@ opserv_saxdb_write(struct saxdb_context *ctx) saxdb_start_record(ctx, iter_key(it), 0); saxdb_write_string(ctx, KEY_DISCRIM, alert->text_discrim); saxdb_write_string(ctx, KEY_OWNER, alert->owner); + saxdb_write_int(ctx, KEY_LAST, alert->last); switch (alert->reaction) { case REACT_NOTICE: reaction = "notice"; break; case REACT_KILL: reaction = "kill"; break; @@ -4814,7 +5049,9 @@ opserv_saxdb_write(struct saxdb_context *ctx) case REACT_TRACK: reaction = "track"; break; case REACT_SHUN: reaction = "shun"; break; case REACT_SVSJOIN: reaction = "svsjoin"; break; + case REACT_SVSPART: reaction = "svspart"; break; case REACT_VERSION: reaction = "version"; break; + case REACT_MARK: reaction = "mark"; break; default: reaction = NULL; log_module(OS_LOG, LOG_ERROR, "Invalid reaction type %d for alert %s (while writing database).", alert->reaction, iter_key(it)); @@ -5005,12 +5242,30 @@ opserv_discrim_create(struct userNode *user, struct userNode *bot, unsigned int } discrim->accountmask = argv[++i]; discrim->authed = 1; + } else if (irccasecmp(argv[i], "marked") == 0) { + discrim->mask_mark = argv[++i]; } else if (irccasecmp(argv[i], "chantarget") == 0) { if(!IsChannelName(argv[i+1])) { send_message(user, bot, "MSG_NOT_CHANNEL_NAME"); goto fail; } discrim->chantarget = argv[++i]; + } else if (irccasecmp(argv[i], "checkrestrictions") == 0) { + i++; + if (true_string(argv[i])) { + discrim->checkrestrictions = 1; + } else if (false_string(argv[i])) { + discrim->checkrestrictions = 0; + } else { + send_message(user, bot, "MSG_INVALID_BINARY", argv[i]); + goto fail; + } + } else if (irccasecmp(argv[i], "mark") == 0) { + if(!is_valid_mark(argv[i+1])) { + send_message(user, bot, "OSMSG_MARK_INVALID"); + goto fail; + } + discrim->mark = argv[++i]; } else if (irccasecmp(argv[i], "authed") == 0) { i++; /* true_string and false_string are macros! */ if (true_string(argv[i])) { @@ -5154,6 +5409,8 @@ opserv_discrim_create(struct userNode *user, struct userNode *bot, unsigned int discrim->domain_depth = strtoul(argv[++i], NULL, 0); } else if (irccasecmp(argv[i], "clones") == 0) { discrim->min_clones = strtoul(argv[++i], NULL, 0); + } else if (irccasecmp(argv[i], "modes") == 0) { + discrim->modes = argv[++i]; } else { send_message(user, bot, "MSG_INVALID_CRITERIA", argv[i]); goto fail; @@ -5180,7 +5437,7 @@ opserv_discrim_create(struct userNode *user, struct userNode *bot, unsigned int { if(discrim->mask_nick) { - int err = regcomp(&discrim->regex_nick, discrim->mask_nick, REG_EXTENDED|REG_ICASE|REG_NOSUB); + int err = regcomp(&discrim->regex_nick, discrim->mask_nick, REG_EXTENDED|REG_NOSUB); discrim->has_regex_nick = !err; if(err) { @@ -5194,7 +5451,7 @@ opserv_discrim_create(struct userNode *user, struct userNode *bot, unsigned int if(discrim->mask_ident) { - int err = regcomp(&discrim->regex_ident, discrim->mask_ident, REG_EXTENDED|REG_ICASE|REG_NOSUB); + int err = regcomp(&discrim->regex_ident, discrim->mask_ident, REG_EXTENDED|REG_NOSUB); discrim->has_regex_ident = !err; if(err) { @@ -5208,7 +5465,7 @@ opserv_discrim_create(struct userNode *user, struct userNode *bot, unsigned int if(discrim->mask_host) { - int err = regcomp(&discrim->regex_host, discrim->mask_host, REG_EXTENDED|REG_ICASE|REG_NOSUB); + int err = regcomp(&discrim->regex_host, discrim->mask_host, REG_EXTENDED|REG_NOSUB); discrim->has_regex_host = !err; if(err) { @@ -5222,7 +5479,7 @@ opserv_discrim_create(struct userNode *user, struct userNode *bot, unsigned int if(discrim->mask_info) { - int err = regcomp(&discrim->regex_info, discrim->mask_info, REG_EXTENDED|REG_ICASE|REG_NOSUB); + int err = regcomp(&discrim->regex_info, discrim->mask_info, REG_EXTENDED|REG_NOSUB); discrim->has_regex_info = !err; if(err) { @@ -5236,7 +5493,7 @@ opserv_discrim_create(struct userNode *user, struct userNode *bot, unsigned int if(discrim->mask_version) { - int err = regcomp(&discrim->regex_version, discrim->mask_version, REG_EXTENDED|REG_ICASE|REG_NOSUB); + int err = regcomp(&discrim->regex_version, discrim->mask_version, REG_EXTENDED|REG_NOSUB); discrim->has_regex_version = !err; if(err) { @@ -5284,6 +5541,7 @@ discrim_match(discrim_t discrim, struct userNode *user) || (discrim->info_space == 0 && user->info[0] == ' ') || (discrim->info_space == 1 && user->info[0] != ' ') || (discrim->server && !match_ircglob(user->uplink->name, discrim->server)) + || (discrim->mask_mark && (!user->mark || !match_ircglob(user->mark, discrim->mask_mark))) || (discrim->accountmask && (!user->handle_info || !match_ircglob(user->handle_info->handle, discrim->accountmask))) || (discrim->ip_mask_bits && !irc_check_mask(&user->ip, &discrim->ip_mask, discrim->ip_mask_bits)) ) @@ -5338,6 +5596,57 @@ discrim_match(discrim_t discrim, struct userNode *user) return 0; } + if (discrim->modes) { + unsigned int ii, matches = 0; + for (ii = 0; ii < strlen(discrim->modes); ii++) { + switch(discrim->modes[ii]) { + case 'O': + if(IsOper(user)) matches++; + break; + case 'o': + if(IsOper(user)) matches++; + break; + case 'i': + if(IsInvisible(user)) matches++; + break; + case 'w': + if(IsWallOp(user)) matches++; + break; + case 's': + if(IsServNotice(user)) matches++; + break; + case 'd': + if(IsDeaf(user)) matches++; + break; + case 'k': + if(IsService(user)) matches++; + break; + case 'g': + if(IsGlobal(user)) matches++; + break; + case 'h': + if(IsSetHost(user)) matches++; + break; + case 'B': + if(IsBotM(user)) matches++; + break; + case 'n': + if(IsHideChans(user)) matches++; + break; + case 'I': + if(IsHideIdle(user)) matches++; + break; + case 'X': + if(IsXtraOp(user)) matches++; + break; + case 'x': + if(IsHiddenHost(user)) matches++; + break; + } + } + if (matches != strlen(discrim->modes)) return 0; + } + access = user->handle_info ? user->handle_info->opserv_level : 0; if ((access < discrim->min_level) || (access > discrim->max_level)) { @@ -5490,15 +5799,28 @@ trace_kill_func(struct userNode *match, void *extra) return 0; } +static int +trace_mark_func(struct userNode *match, void *extra) +{ + struct discrim_and_source *das = extra; + char *mark = das->discrim->mark; + + if(!mark) + return 1; + irc_mark(match, mark); + return 0; +} + static int trace_svsjoin_func(struct userNode *match, void *extra) { struct discrim_and_source *das = extra; char *channame = das->discrim->chantarget; + int checkrestrictions = das->discrim->checkrestrictions; struct chanNode *channel; - if(!IsChannelName(channame)) { + if(!channame || !IsChannelName(channame)) { //reply("MSG_NOT_CHANNEL_NAME"); return 1; } @@ -5506,6 +5828,27 @@ trace_svsjoin_func(struct userNode *match, void *extra) if (!(channel = GetChannel(channame))) { channel = AddChannel(channame, now, NULL, NULL, NULL); } + + if (checkrestrictions) { + if (trace_check_bans(match, channel) == 1) { + return 1; /* found on lamer list */ + } + + if (channel->modes & MODE_INVITEONLY) { + return 1; /* channel is invite only */ + } + + if (channel->limit > 0) { + if (channel->members.used >= channel->limit) { + return 1; /* channel is invite on */ + } + } + + if (*channel->key) { + return 1; /* channel is password protected */ + } + } + if (GetUserMode(channel, match)) { // reply("OSMSG_ALREADY_THERE", channel->name); return 1; @@ -5515,6 +5858,26 @@ trace_svsjoin_func(struct userNode *match, void *extra) return 0; } +static int +trace_svspart_func(struct userNode *match, void *extra) +{ + struct discrim_and_source *das = extra; + char *channame = das->discrim->chantarget; + struct chanNode *channel; + + if(!channame || !IsChannelName(channame)) + return 1; + + if (!(channel = GetChannel(channame))) + return 1; + + if (!GetUserMode(channel, match)) + return 1; + + irc_svspart(opserv, match, channel); + return 0; +} + static int trace_version_func(struct userNode *match, UNUSED_ARG(void *extra)) { @@ -5631,6 +5994,7 @@ static MODCMD_FUNC(cmd_trace) unsigned int matches; struct svccmd *subcmd; char buf[MAXLEN]; + int ret = 1; sprintf(buf, "trace %s", argv[1]); if (!(subcmd = dict_find(opserv_service->commands, buf, NULL))) { @@ -5655,8 +6019,12 @@ static MODCMD_FUNC(cmd_trace) action = trace_gag_func; else if (!irccasecmp(argv[1], "svsjoin")) action = trace_svsjoin_func; + else if (!irccasecmp(argv[1], "svspart")) + action = trace_svspart_func; else if (!irccasecmp(argv[1], "version")) action = trace_version_func; + else if (!irccasecmp(argv[1], "mark")) + action = trace_mark_func; else { reply("OSMSG_BAD_ACTION", argv[1]); return 0; @@ -5694,20 +6062,35 @@ static MODCMD_FUNC(cmd_trace) das.disp_limit = das.discrim->limit; das.discrim->limit = INT_MAX; } - matches = opserv_discrim_search(das.discrim, action, &das); - if (action == trace_domains_func) - dict_foreach(das.dict, opserv_show_hostinfo, &das); + if (action == trace_svsjoin_func && !das.discrim->chantarget) { + reply("OSMSG_SVSJOIN_NO_TARGET"); + ret = 0; + } + else if (action == trace_svspart_func && !das.discrim->chantarget) { + reply("OSMSG_SVSPART_NO_TARGET"); + ret = 0; + } + else if (action == trace_mark_func && !das.discrim->mark) { + reply("OSMSG_MARK_NO_MARK"); + ret = 0; + } + else { + matches = opserv_discrim_search(das.discrim, action, &das); + + if (action == trace_domains_func) + dict_foreach(das.dict, opserv_show_hostinfo, &das); - if (matches) - { - if(action == trace_print_func) - reply("OSMSG_USER_SEARCH_COUNT_BAR", matches); + if (matches) + { + if(action == trace_print_func) + reply("OSMSG_USER_SEARCH_COUNT_BAR", matches); + else + reply("OSMSG_USER_SEARCH_COUNT", matches); + } else - reply("OSMSG_USER_SEARCH_COUNT", matches); + reply("MSG_NO_MATCHES"); } - else - reply("MSG_NO_MATCHES"); if (das.discrim->channel) UnlockChannel(das.discrim->channel); @@ -5726,7 +6109,7 @@ static MODCMD_FUNC(cmd_trace) free(das.discrim); dict_delete(das.dict); - return 1; + return ret; } typedef void (*cdiscrim_search_func)(struct chanNode *match, void *data, struct userNode *bot); @@ -6127,6 +6510,8 @@ alert_check_user(const char *key, void *data, void *extra) if (alert->discrim->option_log) log_module(OS_LOG, LOG_INFO, "Alert %s triggered by user %s!%s@%s (%s).", key, user->nick, user->ident, user->hostname, alert->discrim->reason); + alert->last = now; + /* Return 1 to halt alert matching, such as when killing the user that triggered the alert. */ switch (alert->reaction) { @@ -6140,7 +6525,10 @@ alert_check_user(const char *key, void *data, void *extra) opserv_shun(user, alert->owner, alert->discrim->reason, alert->discrim->duration); return 1; case REACT_SVSJOIN: - opserv_svsjoin(user, alert->owner, alert->discrim->reason, alert->discrim->chantarget); + opserv_svsjoin(user, alert->owner, alert->discrim->reason, alert->discrim->chantarget, alert->discrim->checkrestrictions); + break; + case REACT_SVSPART: + opserv_svspart(user, alert->owner, alert->discrim->reason, alert->discrim->chantarget); break; case REACT_VERSION: /* Don't auto-version a user who we already have a version on, because the version reply itself @@ -6151,6 +6539,9 @@ alert_check_user(const char *key, void *data, void *extra) if(!user->version_reply) opserv_version(user); break; + case REACT_MARK: + opserv_mark(user, alert->owner, alert->discrim->reason, alert->discrim->mark); + break; default: log_module(OS_LOG, LOG_ERROR, "Invalid reaction type %d for alert %s.", alert->reaction, key); /* fall through to REACT_NOTICE case */ @@ -6320,10 +6711,6 @@ static MODCMD_FUNC(cmd_addalert) reaction = REACT_NOTICE; else if (!irccasecmp(argv[2], "kill")) reaction = REACT_KILL; -/* - else if (!irccasecmp(argv[2], "silent")) - reaction = REACT_SILENT; -*/ else if (!irccasecmp(argv[2], "gline")) reaction = REACT_GLINE; else if (!irccasecmp(argv[2], "track")) { @@ -6337,15 +6724,21 @@ static MODCMD_FUNC(cmd_addalert) reaction = REACT_SHUN; else if(!irccasecmp(argv[2], "svsjoin")) reaction = REACT_SVSJOIN; + else if(!irccasecmp(argv[2], "svspart")) + reaction = REACT_SVSPART; else if(!irccasecmp(argv[2], "version")) reaction = REACT_VERSION; + else if(!irccasecmp(argv[2], "mark")) + reaction = REACT_MARK; else { reply("OSMSG_UNKNOWN_REACTION", argv[2]); return 0; } if (!svccmd_can_invoke(user, opserv_service->bot, subcmd, channel, SVCCMD_NOISY) - || !opserv_add_user_alert(user, name, reaction, unsplit_string(argv + 3, argc - 3, NULL))) + || !opserv_add_user_alert(user, name, reaction, unsplit_string(argv + 3, argc - 3, NULL), 0)) { + reply("OSMSG_ALERT_ADD_FAILED"); return 0; + } reply("OSMSG_ADDED_ALERT", name); return 1; } @@ -6603,7 +6996,9 @@ init_opserv(const char *nick) opserv_define_func("ADDALERT TRACK", NULL, 900, 0, 0); opserv_define_func("ADDALERT KILL", NULL, 900, 0, 0); opserv_define_func("ADDALERT SVSJOIN", NULL, 999, 0, 0); + opserv_define_func("ADDALERT SVSPART", NULL, 999, 0, 0); opserv_define_func("ADDALERT VERSION", NULL, 999, 0, 0); + opserv_define_func("ADDALERT MARK", NULL, 999, 0, 0); opserv_define_func("ADDBAD", cmd_addbad, 800, 0, 2); opserv_define_func("ADDEXEMPT", cmd_addexempt, 800, 0, 2); opserv_define_func("ADDTRUST", cmd_addtrust, 800, 0, 5); @@ -6645,7 +7040,9 @@ init_opserv(const char *nick) opserv_define_func("INVITE", cmd_invite, 100, 2, 0); opserv_define_func("INVITEME", cmd_inviteme, 100, 0, 0); opserv_define_func("JOIN", cmd_join, 601, 0, 2); + opserv_define_func("SVSNICK", cmd_svsnick, 999, 0, 3); opserv_define_func("SVSJOIN", cmd_svsjoin, 999, 0, 3); + opserv_define_func("SVSPART", cmd_svspart, 999, 0, 3); opserv_define_func("JUMP", cmd_jump, 900, 0, 2); opserv_define_func("JUPE", cmd_jupe, 900, 0, 4); opserv_define_func("KICK", cmd_kick, 100, 2, 2); @@ -6654,6 +7051,7 @@ init_opserv(const char *nick) opserv_define_func("KICKBANALL", cmd_kickbanall, 450, 2, 0); opserv_define_func("LOG", cmd_log, 900, 0, 2); opserv_define_func("MODE", cmd_mode, 100, 2, 2); + opserv_define_func("MARK", cmd_mark, 900, 0, 3); opserv_define_func("OP", cmd_op, 100, 2, 2); opserv_define_func("OPALL", cmd_opall, 400, 2, 0); opserv_define_func("HOP", cmd_hop, 100, 2, 2); @@ -6709,6 +7107,8 @@ init_opserv(const char *nick) opserv_define_func("TRACE KILL", NULL, 600, 0, 0); opserv_define_func("TRACE VERSION", NULL, 999, 0, 0); opserv_define_func("TRACE SVSJOIN", NULL, 999, 0, 0); + opserv_define_func("TRACE SVSPART", NULL, 999, 0, 0); + opserv_define_func("TRACE MARK", NULL, 999, 0, 0); opserv_define_func("UNBAN", cmd_unban, 100, 2, 2); opserv_define_func("UNGAG", cmd_ungag, 600, 0, 2); opserv_define_func("UNGLINE", cmd_ungline, 600, 0, 2); @@ -6749,7 +7149,9 @@ init_opserv(const char *nick) } /* start auto-routing system */ - reroute_timer(NULL); + /* this cant be done here, because the routing system isnt marked active yet. */ + /* reroute_timer(NULL); */ + /* start the karma timer, using the saved one if available */ routing_karma_timer(dict_find(opserv_routing_plan_options, "KARMA_TIMER", NULL));