X-Git-Url: https://jfr.im/git/irc/evilnet/x3.git/blobdiff_plain/bf93ca8d63e94ecbc72ee4fb54bcc15c5f5f6f1b..283cfa834c5e05d55462ffe643f0c301ef21ed4a:/src/opserv.c diff --git a/src/opserv.c b/src/opserv.c index 3481b48..5e0a7cd 100644 --- a/src/opserv.c +++ b/src/opserv.c @@ -25,12 +25,13 @@ #include "nickserv.h" #include "modcmd.h" #include "modules.h" +#include "proto.h" #include "opserv.h" #include "timeq.h" #include "saxdb.h" #include "shun.h" -#include +#include #ifdef HAVE_SYS_TIMES_H #include @@ -93,6 +94,20 @@ #define KEY_OFFLINE "offline" #define KEY_ROUTINGPLAN "routingplan" #define KEY_ROUTINGPLAN_OPTIONS "routingplan_options" +#define KEY_DEFCON1 "DefCon1" +#define KEY_DEFCON2 "DefCon2" +#define KEY_DEFCON3 "DefCon3" +#define KEY_DEFCON4 "DefCon4" +#define KEY_DEFCON_LEVEL "DefConLevel" +#define KEY_DEFCON_CHANMODES "DefConChanModes" +#define KEY_DEFCON_SESSION_LIMIT "DefConSessionLimit" +#define KEY_DEFCON_TIMEOUT "DefConTimeOut" +#define KEY_DEFCON_GLOBAL "GlobalOnDefcon" +#define KEY_DEFCON_GLOBAL_MORE "GlobalOnDefconMore" +#define KEY_DEFCON_MESSAGE "DefconMessage" +#define KEY_DEFCON_OFF_MESSAGE "DefConOffMessage" +#define KEY_DEFCON_GLINE_DURATION "DefConGlineExpire" +#define KEY_DEFCON_GLINE_REASON "DefConGlineReason" /* Routing karma values: */ /* What value we start out with when new servers are added: */ @@ -148,7 +163,10 @@ 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_NOT_THERE", "You not in $b%s$b." }, { "OSMSG_JOIN_DONE", "I have joined $b%s$b." }, + { "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." }, @@ -159,20 +177,33 @@ static const struct message_entry msgtab[] = { { "OSMSG_HOP_DONE", "Halfopped the requested lusers." }, { "OSMSG_HOPALL_DONE", "Halfopped everyone on $b%s$b." }, { "OSMSG_WHOIS_IDENT", "%s (%s@%s) from %d.%d.%d.%d" }, - { "OSMSG_WHOIS_NICK", "Nick : %s" }, - { "OSMSG_WHOIS_HOST", "Host : %s@%s" }, - { "OSMSG_WHOIS_FAKEHOST", "Fakehost : %s" }, - { "OSMSG_WHOIS_CRYPT_HOST", "Crypt Host : %s" }, - { "OSMSG_WHOIS_CRYPT_IP", "Crypt IP : %s" }, - { "OSMSG_WHOIS_IP", "Real IP : %s" }, - { "OSMSG_WHOIS_MODES", "Modes : +%s " }, - { "OSMSG_WHOIS_INFO", "Info : %s" }, - { "OSMSG_WHOIS_NUMERIC", "Numnick : %s" }, - { "OSMSG_WHOIS_SERVER", "Server : %s" }, - { "OSMSG_WHOIS_NICK_AGE", "Nick Age : %s" }, - { "OSMSG_WHOIS_ACCOUNT", "Account : %s" }, - { "OSMSG_WHOIS_CHANNELS", "Channels : %s" }, + { "OSMSG_WHOIS_NICK", "Nick : %s" }, + { "OSMSG_WHOIS_HOST", "Host : %s@%s" }, + { "OSMSG_WHOIS_FAKEHOST", "Fakehost : %s" }, + { "OSMSG_WHOIS_CRYPT_HOST", "Crypt Host : %s" }, + { "OSMSG_WHOIS_CRYPT_IP", "Crypt IP : %s" }, + { "OSMSG_WHOIS_IP", "Real IP : %s" }, + { "OSMSG_WHOIS_COUNTRY", "Country : %s" }, + { "OSMSG_WHOIS_COUNTRY_CODE","Country Code : %s" }, + { "OSMSG_WHOIS_CITY", "City : %s" }, + { "OSMSG_WHOIS_REGION", "Region/State : %s" }, + { "OSMSG_WHOIS_POSTAL_CODE","Postal Code : %s" }, + { "OSMSG_WHOIS_LATITUDE", "Latitude : %f" }, + { "OSMSG_WHOIS_LONGITUDE", "Longitude : %f" }, + { "OSMSG_WHOIS_MAP", "Map : %s" }, + { "OSMSG_WHOIS_DMA_CODE", "DMA Code : %d" }, + { "OSMSG_WHOIS_AREA_CODE", "Area Code : %d" }, + { "OSMSG_WHOIS_MODES", "Modes : +%s " }, + { "OSMSG_WHOIS_INFO", "Info : %s" }, + { "OSMSG_WHOIS_NUMERIC", "Numnick : %s" }, + { "OSMSG_WHOIS_SERVER", "Server : %s" }, + { "OSMSG_WHOIS_NICK_AGE", "Nick Age : %s" }, + { "OSMSG_WHOIS_ACCOUNT", "Account : %s" }, + { "OSMSG_WHOIS_PRIVS", "IRCd Privs : %s" }, + { "OSMSG_WHOIS_CHANNELS", "Channels : %s" }, { "OSMSG_WHOIS_HIDECHANS", "Channel list omitted for your sanity." }, + { "OSMSG_WHOIS_VERSION", "Version : %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." }, @@ -249,6 +280,8 @@ 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_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:" }, @@ -268,27 +301,30 @@ 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_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_FAILURE", "Could not add new plan '%s' (does it already exist?)." }, + { "OSMSG_ADDPLAN_FAILED", "Could not add new plan '%s' (does it already exist?)." }, { "OSMSG_INVALID_PLAN", "That routing plan name is not valid." }, { "OSMSG_PLAN_DELETED", "The routing plan was sucessfully deleted." }, { "OSMSG_PLAN_NOT_FOUND", "There is no routing plan called '%s'." }, @@ -308,6 +344,7 @@ static const struct message_entry msgtab[] = { { "OSMSG_COULDNT_FIND_SERVER", "Couldnt find %s, so using %s to link %s" }, { "OSMSG_INSPECTING_SERVER", "Inspecting server [%s]" }, { "OSMSG_REROUTING_ACC_MAP", "Rerouting network according to loaded map.." }, + { "OSMSG_REROUTING_NOTCONFIGURED", "You have not configured routing. See $/msg $O help routing$b." }, { "OSMSG_CONNECTING_MISSING_ONLY", "Connecting missing servers only.." }, { "OSMSG_NO_ROUTING_NECESSARY", "No rerouting appears necessary." }, { "OSMSG_TESTING_REROUTE", "Testing Reroute(): Commands not sent to socket.." }, @@ -361,11 +398,43 @@ static const struct message_entry msgtab[] = { { "OSMSG_INVALID_REGEX", "Invalid regex: %s: %s (%d)" }, { "OSMSG_TRACK_DISABLED", "Tracking is not currently compiled into X3" }, { "OSMSG_MAXUSERS_RESET", "Max clients has been reset to $b%d$b" }, + + { "OSMSG_DEFCON_INVALID", "DefCon level %d is invalid, please choose a value between 1 and 5" }, + { "OSMSG_DEFCON_ALLOWING_ALL", "DefCon is at level 5 and allowing everything" }, + { "OSMSG_DEFCON_DISALLOWING", "DefCon is at level %d and enforcing:" }, + { "OSMSG_DEFCON_NO_NEW_CHANNELS", "No Channel Registrations" }, + { "OSMSG_DEFCON_NO_NEW_NICKS", "No Nickname/Account Registrations" }, + { "OSMSG_DEFCON_NO_MODE_CHANGE", "No Channel Mode Changes" }, + { "OSMSG_DEFCON_NO_NEW_CLIENTS", "No New Clients" }, + { "OSMSG_DEFCON_FORCE_CHANMODES", "Forcing Channel Mode(s): %s" }, + { "OSMSG_DEFCON_REDUCE_SESSION", "Forcing Reduced Session: %d" }, + { "OSMSG_DEFCON_OPER_ONLY", "Allowing Services Communication With Opers Only" }, + { "OSMSG_DEFCON_SILENT_OPER_ONLY", "Allowing Services Communication With Opers Only AND Silently Ignoring Regular Users" }, + { "OSMSG_DEFCON_GLINE_NEW_CLIENTS", "Glining New Clients" }, + { "OSMSG_DEFCON_SHUN_NEW_CLIENTS", "Shunning New Clients" }, + { "OSMSG_DEFCON_NO_NEW_MEMOS", "Disallowing New Memos" }, + + { "OSMSG_PRIV_UNKNOWN", "Unknown privilege flag %s, see /msg $O HELP PRIVFLAGS for a flag list" }, + { "OSMSG_PRIV_SET", "Privilege flag %s has been %sset" }, + { NULL, NULL } }; #define OPSERV_SYNTAX() svccmd_send_help_brief(user, opserv, cmd) +int DefConLevel = 5; +int DefCon[6]; +int DefConTimeOut; +int GlobalOnDefcon = 0; +int GlobalOnDefconMore = 0; +int DefConGlineExpire; +int DefConModesSet = 0; +unsigned int DefConSessionLimit; +char *DefConChanModes; +char *DefConGlineReason; +char *DefConMessage; +char *DefConOffMessage; + extern void add_track_user(struct userNode *user); typedef int (*discrim_search_func)(struct userNode *match, void *extra); @@ -451,12 +520,12 @@ opserv_free_waiting_connection(void *data) typedef struct opservDiscrim { struct chanNode *channel; - char *mask_nick, *mask_ident, *mask_host, *mask_info, *server, *reason, *accountmask; + char *mask_nick, *mask_ident, *mask_host, *mask_info, *mask_version, *server, *reason, *accountmask, *chantarget; irc_in_addr_t ip_mask; unsigned long limit; time_t min_ts, max_ts; - regex_t regex_nick, regex_ident, regex_host, regex_info; - unsigned int has_regex_nick : 1, has_regex_ident : 1, has_regex_host : 1, has_regex_info : 1; + regex_t regex_nick, regex_ident, regex_host, regex_info, regex_version; + unsigned int has_regex_nick : 1, has_regex_ident : 1, has_regex_host : 1, has_regex_info : 1, has_regex_version : 1; unsigned int min_level, max_level, domain_depth, duration, min_clones, min_channels, max_channels; unsigned char ip_mask_bits; unsigned int match_opers : 1, option_log : 1; @@ -483,10 +552,12 @@ static int ungag_helper_func(struct userNode *match, void *extra); typedef enum { REACT_NOTICE, REACT_KILL, -// REACT_SILENT, REACT_GLINE, REACT_TRACK, - REACT_SHUN + REACT_SHUN, + REACT_SVSJOIN, + REACT_SVSPART, + REACT_VERSION } opserv_alert_reaction; struct opserv_user_alert { @@ -514,6 +585,8 @@ opserv_free_user_alert(void *data) regfree(&alert->discrim->regex_host); if(alert->discrim->has_regex_info) regfree(&alert->discrim->regex_info); + if(alert->discrim->has_regex_version) + regfree(&alert->discrim->regex_version); free(alert->discrim->reason); free(alert->discrim); free(alert); @@ -523,6 +596,212 @@ opserv_free_user_alert(void *data) #define opserv_alert(format...) do { if (opserv_conf.alert_channel) send_channel_notice(opserv_conf.alert_channel , opserv , ## format); } while (0) +char *defconReverseModes(const char *modes) +{ + char *newmodes = NULL; + unsigned int i = 0; + if (!modes) { + return NULL; + } + if (!(newmodes = malloc(sizeof(char) * strlen(modes) + 1))) { + return NULL; + } + for (i = 0; i < strlen(modes); i++) { + if (modes[i] == '+') + newmodes[i] = '-'; + else if (modes[i] == '-') + newmodes[i] = '+'; + else + newmodes[i] = modes[i]; + } + newmodes[i] = '\0'; + return newmodes; +} + +int checkDefCon(int level) +{ + return DefCon[DefConLevel] & level; +} + +void showDefConSettings(struct userNode *user, struct svccmd *cmd) +{ + if (DefConLevel == 5) { + reply("OSMSG_DEFCON_ALLOWING_ALL"); + return; + } else + reply("OSMSG_DEFCON_DISALLOWING", DefConLevel); + + if (checkDefCon(DEFCON_NO_NEW_CHANNELS)) + reply("OSMSG_DEFCON_NO_NEW_CHANNELS"); + + if (checkDefCon(DEFCON_NO_NEW_NICKS)) + reply("OSMSG_DEFCON_NO_NEW_NICKS"); + + if (checkDefCon(DEFCON_NO_MODE_CHANGE)) + reply("OSMSG_DEFCON_NO_MODE_CHANGE"); + + if (checkDefCon(DEFCON_FORCE_CHAN_MODES) && (DefConChanModes)) + reply("OSMSG_DEFCON_FORCE_CHANMODES", DefConChanModes); + + if (checkDefCon(DEFCON_REDUCE_SESSION)) + reply("OSMSG_DEFCON_REDUCE_SESSION", DefConSessionLimit); + + if (checkDefCon(DEFCON_NO_NEW_CLIENTS)) + reply("OSMSG_DEFCON_NO_NEW_CLIENTS"); + + if (checkDefCon(DEFCON_OPER_ONLY)) + reply("OSMSG_DEFCON_OPER_ONLY"); + + if (checkDefCon(DEFCON_SILENT_OPER_ONLY)) + reply("OSMSG_DEFCON_SILENT_OPER_ONLY"); + + if (checkDefCon(DEFCON_GLINE_NEW_CLIENTS)) + reply("OSMSG_DEFCON_GLINE_NEW_CLIENTS"); + + if (checkDefCon(DEFCON_SHUN_NEW_CLIENTS)) + reply("OSMSG_DEFCON_SHUN_NEW_CLIENTS"); + + if (checkDefCon(DEFCON_NO_NEW_MEMOS)) + reply("OSMSG_DEFCON_NO_NEW_MEMOS"); + + return; +} + +void do_mass_mode(char *modes) +{ + dict_iterator_t it; + + if (!modes) + return; + + for (it = dict_first(channels); it; it = iter_next(it)) { + struct chanNode *chan = iter_data(it); + + irc_mode(opserv, chan, modes); + } + +} + +void DefConProcess(struct userNode *user) +{ + char *newmodes; + + if (GlobalOnDefcon) + global_message_args(MESSAGE_RECIPIENT_LUSERS, "DEFCON_NETWORK_CHANGED", DefConLevel); + + if (GlobalOnDefconMore && GlobalOnDefcon) + global_message(MESSAGE_RECIPIENT_LUSERS, DefConMessage); + + if ((DefConLevel == 5) && !GlobalOnDefconMore && !GlobalOnDefcon) + global_message(MESSAGE_RECIPIENT_LUSERS, DefConOffMessage); + + if (user) + global_message_args(MESSAGE_RECIPIENT_OPERS, "DEFCON_OPER_LEVEL_CHANGE", user->nick, DefConLevel); + else + global_message_args(MESSAGE_RECIPIENT_OPERS, "DEFCON_TIMEOUT_LEVEL_CHANGE", DefConLevel); + + if (checkDefCon(DEFCON_FORCE_CHAN_MODES)) { + if (DefConChanModes && !DefConModesSet) { + if (DefConChanModes[0] == '+' || DefConChanModes[0] == '-') { + do_mass_mode(DefConChanModes); + DefConModesSet = 1; + } + } + } else { + if (DefConChanModes && (DefConModesSet != 0)) { + if (DefConChanModes[0] == '+' || DefConChanModes[0] == '-') { + if ((newmodes = defconReverseModes(DefConChanModes))) { + do_mass_mode(newmodes); + free(newmodes); + } + DefConModesSet = 0; + } + } + } + + return; +} + +void +defcon_timeout(UNUSED_ARG(void *data)) +{ + DefConLevel = 5; + DefConProcess(NULL); +} + +static MODCMD_FUNC(cmd_defcon) +{ + if ((argc < 2) || (atoi(argv[1]) == DefConLevel)) { + showDefConSettings(user, cmd); + return 1; + } + + if ((atoi(argv[1]) < 1) || (atoi(argv[1]) > 5)) { + reply("OSMSG_DEFCON_INVALID", atoi(argv[1])); + return 0; + } + + DefConLevel = atoi(argv[1]); + showDefConSettings(user, cmd); + + if (DefConTimeOut > 0) { + timeq_del(0, defcon_timeout, NULL, TIMEQ_IGNORE_DATA | TIMEQ_IGNORE_WHEN); + timeq_add(now + DefConTimeOut, defcon_timeout, NULL); + } + + DefConProcess(user); + return 1; +} + +/* TODO +static MODCMD_FUNC(cmd_privallow) +{ +//privallow servername/username +/-flag (global is set in conf) +} + +static MODCMD_FUNC(cmd_privdissallow) +{ +//privdisallow servername/username +/-flag (global is set in conf) +} + +static MODCMD_FUNC(cmd_privlist) +{ +//privlist servername/user (global with none) +} +*/ + +static MODCMD_FUNC(cmd_privset) +{ + struct userNode *target; + char *flag; + int add = PRIV_ADD; + + flag = argv[2]; + if (*flag == '-') { + add = PRIV_DEL; + flag++; + } else if (*flag == '+') { + add = PRIV_ADD; + flag++; + } + + target = GetUserH(argv[1]); + if (!target) { + reply("MSG_NICK_UNKNOWN", argv[1]); + return 0; + } + + if (check_priv(flag)) { + irc_privs(target, flag, add); + reply("OSMSG_PRIV_SET", argv[2], (add == 1) ? "" : "un"); + } else { + reply("OSMSG_PRIV_UNKNOWN", argv[2]); + return 0; + } + + return 1; +} + /* A lot of these commands are very similar to what ChanServ can do, * but OpServ can do them even on channels that aren't registered. */ @@ -666,9 +945,7 @@ static MODCMD_FUNC(cmd_warn) dict_insert(opserv_chan_warn, strdup(argv[1]), reason); reply("OSMSG_WARN_ADDED", argv[1], reason); if (dict_find(channels, argv[1], NULL)) { - message = alloca(strlen(reason) + strlen(argv[1]) + 55); - sprintf(message, "Channel activity warning for channel %s: %s", argv[1], reason); - global_message(MESSAGE_RECIPIENT_OPERS, message); + global_message_args(MESSAGE_RECIPIENT_OPERS, "OSMSG_CHANNEL_ACTIVITY_WARN" argv[1], reason); } return 1; } @@ -1074,6 +1351,57 @@ static MODCMD_FUNC(cmd_refreshg) return 1; } +static void +opserv_version(struct userNode *target) +{ + irc_version_user(opserv, target); +} + +static void +opserv_svsjoin(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 = AddChannel(channame, now, NULL, NULL, NULL); + } + if (GetUserMode(channel, target)) { + /* already in it */ + return; + } + + 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) { @@ -1170,7 +1498,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; @@ -1184,7 +1512,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) @@ -1199,7 +1527,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); } } @@ -1240,6 +1568,33 @@ static MODCMD_FUNC(cmd_invite) return 1; } +static MODCMD_FUNC(cmd_svsjoin) +{ + struct userNode *target; + + + if(!IsChannelName(argv[2])) { + reply("MSG_NOT_CHANNEL_NAME"); + return 0; + } + target = GetUserH(argv[1]); + if (!target) { + reply("MSG_NICK_UNKNOWN", argv[1]); + return 0; + } + + if (!(channel = GetChannel(argv[2]))) { + channel = AddChannel(argv[2], now, NULL, NULL, NULL); + } + if (GetUserMode(channel, target)) { + reply("OSMSG_ALREADY_THERE", channel->name); + return 0; + } + irc_svsjoin(opserv, target, channel); + reply("OSMSG_SVSJOIN_SENT"); + return 1; +} + static MODCMD_FUNC(cmd_join) { struct userNode *bot = cmd->parent->bot; @@ -1406,6 +1761,35 @@ static MODCMD_FUNC(cmd_kickbanall) return 1; } +static MODCMD_FUNC(cmd_svspart) +{ + struct userNode *target; + + if(!IsChannelName(argv[2])) { + reply("MSG_NOT_CHANNEL_NAME"); + return 0; + } + target = GetUserH(argv[1]); + if (!target) { + reply("MSG_NICK_UNKNOWN", argv[1]); + return 0; + } + + if (!(channel = GetChannel(argv[2]))) { + reply("OSMSG_NOT_ON_CHANNEL", cmd->parent->bot->nick, channel->name); + return 0; + } + + if (!GetUserMode(channel, target)) { + reply("OSMSG_NOT_ON_CHANNEL", cmd->parent->bot->nick, channel->name); + return 0; + } + + irc_svspart(opserv, target, channel); + reply("OSMSG_SVSPART_SENT"); + return 1; +} + static MODCMD_FUNC(cmd_part) { char *reason; @@ -1557,6 +1941,36 @@ static MODCMD_FUNC(cmd_whois) reply("OSMSG_WHOIS_CRYPT_HOST", target->crypthost); reply("OSMSG_WHOIS_CRYPT_IP", target->cryptip); reply("OSMSG_WHOIS_IP", irc_ntoa(&target->ip)); + + if (target->city) { + reply("OSMSG_WHOIS_COUNTRY", target->country_name); + reply("OSMSG_WHOIS_COUNTRY_CODE", target->country_code); + reply("OSMSG_WHOIS_CITY", target->city); + reply("OSMSG_WHOIS_REGION", target->region); + + reply("OSMSG_WHOIS_POSTAL_CODE", target->postal_code); + reply("OSMSG_WHOIS_LATITUDE", target->latitude); + reply("OSMSG_WHOIS_LONGITUDE", target->longitude); + /* Only show a map url if we have a city, latitude and longitude. + * Theres not much point of latitude and longitude coordinates are + * returned but no city, the coordinates are useless. + */ + if (target->latitude && target->longitude && target->city) { + char map_url[MAXLEN]; + snprintf(map_url, sizeof(map_url), "http://www.mapquest.com/maps/map.adp?searchtype=address&formtype=address&latlongtype=decimal&latitude=%f&longitude=%f", + target->latitude, target->longitude); + reply("OSMSG_WHOIS_MAP", map_url); + } + reply("OSMSG_WHOIS_DMA_CODE", target->dma_code); + reply("OSMSG_WHOIS_AREA_CODE", target->area_code); + } else if (target->country_name) { + reply("OSMSG_WHOIS_COUNTRY", target->country_name); + } + if(target->version_reply) { + reply("OSMSG_WHOIS_VERSION", target->version_reply); + } + reply("OSMSG_WHOIS_NO_NOTICE", target->no_notice ? "YES":"NO"); + if (target->modes) { bpos = 0; #define buffer_cat(str) (herelen = strlen(str), memcpy(buffer+bpos, str, herelen), bpos += herelen) @@ -1586,10 +2000,13 @@ static MODCMD_FUNC(cmd_whois) #endif reply("OSMSG_WHOIS_SERVER", target->uplink->name); reply("OSMSG_WHOIS_ACCOUNT", (target->handle_info ? target->handle_info->handle : "Not authenticated")); + + reply("OSMSG_WHOIS_PRIVS", client_report_privs(target)); + 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; @@ -1909,13 +2326,18 @@ static MODCMD_FUNC(cmd_stats_alerts) { dict_iterator_t it; struct opserv_user_alert *alert; const char *reaction; + 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)) ) + continue; /* not a match to requested filter */ switch (alert->reaction) { case REACT_NOTICE: reaction = "notice"; break; case REACT_KILL: reaction = "kill"; break; @@ -1923,6 +2345,9 @@ static MODCMD_FUNC(cmd_stats_alerts) { case REACT_GLINE: reaction = "gline"; break; 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; default: reaction = ""; break; } reply("OSMSG_ALERT_IS", iter_key(it), reaction, alert->owner); @@ -2171,12 +2596,33 @@ opserv_new_user_check(struct userNode *user) } } + if (checkDefCon(DEFCON_NO_NEW_CLIENTS)) { + irc_kill(opserv, user, DefConGlineReason); + return 0; + } + + if ( (checkDefCon(DEFCON_GLINE_NEW_CLIENTS) || checkDefCon(DEFCON_SHUN_NEW_CLIENTS)) && !IsOper(user)) { + char target[IRC_NTOP_MAX_SIZE + 3] = { '*', '@', '\0' }; + + strcpy(target + 2, user->hostname); + if (checkDefCon(DEFCON_GLINE_NEW_CLIENTS)) + gline_add(opserv->nick, target, DefConGlineExpire, DefConGlineReason, now, 1, 0); + else if (checkDefCon(DEFCON_SHUN_NEW_CLIENTS)) + shun_add(opserv->nick, target, DefConGlineExpire, DefConGlineReason, now, 1); + + return 0; + } + /* Only warn or G-line if there's an untrusted max and their IP is sane. */ if (opserv_conf.untrusted_max && irc_in_addr_is_valid(user->ip) && !irc_in_addr_is_loopback(user->ip)) { struct trusted_host *th = dict_find(opserv_trusted_hosts, addr, NULL); unsigned int limit = th ? th->limit : opserv_conf.untrusted_max; + + if (checkDefCon(DEFCON_REDUCE_SESSION) && !th) + limit = DefConSessionLimit; + if (!limit) { /* 0 means unlimited hosts */ } else if (ohi->clients.used == limit) { @@ -2268,9 +2714,7 @@ opserv_channel_check(struct chanNode *newchan) } /* 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); + global_message_args(MESSAGE_RECIPIENT_OPERS, "OSMSG_CHANNEL_ACTIVITY_WARN", newchan->name, warning); } */ @@ -2284,6 +2728,27 @@ opserv_channel_delete(struct chanNode *chan) timeq_del(0, opserv_part_channel, chan, TIMEQ_IGNORE_WHEN); } +static void +opserv_notice_handler(struct userNode *user, struct userNode *bot, char *text, UNUSED_ARG(int server_qualified)) +{ + char *cmd; + /* if its a version reply, do an alert check (only alerts with version=something) */ + if(bot == opserv) { + if(text[0] == '\001') { + text++; + cmd = mysep(&text, " "); + if(!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); done in parse-p10.c now */ + dict_foreach(opserv_user_alerts, alert_check_user, user); + } + } + } +} + static int opserv_join_check(struct modeNode *mNode) { @@ -2679,15 +3144,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 */ @@ -2754,6 +3231,10 @@ routing_connect_server(char *server, int port, struct server *to) wc->server = strdup(server); wc->target = strdup(to->name); + /* Just to make sure there isn't one left hanging + * if 2 connections are attempted at once.. + * */ + routing_delete_connect_timer(server); dict_insert(opserv_waiting_connections, strdup(server), wc); timeq_add(now + ROUTING_CONNECT_TIMEOUT, routing_connect_timeout, wc); @@ -2811,6 +3292,10 @@ int reroute(struct route *route, struct userNode *user, struct svccmd *cmd, char int connect = 0, move = 0, missing = 0, i; char d = toupper(*directive); + if(!route || !route->servers) { + reply("OSMSG_REROUTING_NOTCONFIGURED"); + return 0; + } if(user) { if(d == 'N') { /* normal */ irc_wallops("%s", "Attempting a reroute of the network according to loaded map..."); @@ -2909,6 +3394,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); @@ -2918,6 +3406,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"); @@ -3123,10 +3614,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"); } @@ -3199,21 +3703,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; } @@ -4054,7 +4571,8 @@ opserv_add_user_alert(struct userNode *req, const char *name, opserv_alert_react 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) { + if (!alert->discrim || (reaction==REACT_SVSJOIN && !alert->discrim->chantarget) || + (reaction==REACT_SVSPART && !alert->discrim->chantarget)) { free(alert->text_discrim); free(discrim_copy); free(alert); @@ -4123,6 +4641,12 @@ add_user_alert(const char *key, void *data, UNUSED_ARG(void *extra)) reaction = REACT_TRACK; else if (!irccasecmp(react, "shun")) 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 { log_module(OS_LOG, LOG_ERROR, "Invalid reaction %s for alert %s.", react, key); return 0; @@ -4404,6 +4928,9 @@ opserv_saxdb_write(struct saxdb_context *ctx) case REACT_GLINE: reaction = "gline"; break; 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; default: reaction = NULL; log_module(OS_LOG, LOG_ERROR, "Invalid reaction type %d for alert %s (while writing database).", alert->reaction, iter_key(it)); @@ -4577,6 +5104,8 @@ opserv_discrim_create(struct userNode *user, struct userNode *bot, unsigned int discrim->intra_scmp = 3; else discrim->mask_info = argv[i]; + } else if (irccasecmp(argv[i], "version") == 0) { + discrim->mask_version = argv[++i]; } else if (irccasecmp(argv[i], "server") == 0) { discrim->server = argv[++i]; } else if (irccasecmp(argv[i], "ip") == 0) { @@ -4592,6 +5121,12 @@ opserv_discrim_create(struct userNode *user, struct userNode *bot, unsigned int } discrim->accountmask = argv[++i]; discrim->authed = 1; + } 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], "authed") == 0) { i++; /* true_string and false_string are macros! */ if (true_string(argv[i])) { @@ -4750,6 +5285,9 @@ opserv_discrim_create(struct userNode *user, struct userNode *bot, unsigned int if (discrim->mask_info && !strcmp(discrim->mask_info, "*")) { discrim->mask_info = 0; } + if (discrim->mask_version && !strcmp(discrim->mask_version, "*")) { + discrim->mask_version = 0; + } if (discrim->mask_host && !discrim->mask_host[strspn(discrim->mask_host, "*.")]) { discrim->mask_host = 0; } @@ -4811,6 +5349,20 @@ opserv_discrim_create(struct userNode *user, struct userNode *bot, unsigned int goto regfail; } } + + if(discrim->mask_version) + { + int err = regcomp(&discrim->regex_version, discrim->mask_version, REG_EXTENDED|REG_ICASE|REG_NOSUB); + discrim->has_regex_version = !err; + if(err) + { + char buff[256]; + buff[regerror(err, &discrim->regex_version, buff, sizeof(buff))] = 0; + + send_message(user, bot, "OSMSG_INVALID_REGEX", discrim->mask_version, buff, err); + goto regfail; + } + } } return discrim; @@ -4861,7 +5413,8 @@ discrim_match(discrim_t discrim, struct userNode *user) if((discrim->has_regex_nick && regexec(&discrim->regex_nick, user->nick, 0, 0, 0)) || (discrim->has_regex_ident && regexec(&discrim->regex_ident, user->ident, 0, 0, 0)) || (discrim->has_regex_host && regexec(&discrim->regex_host, user->hostname, 0, 0, 0)) - || (discrim->has_regex_info && regexec(&discrim->regex_info, user->info, 0, 0, 0))) { + || (discrim->has_regex_info && regexec(&discrim->regex_info, user->info, 0, 0, 0)) + || (discrim->has_regex_version && (!user->version_reply || regexec(&discrim->regex_version, user->version_reply, 0, 0, 0)))) { return 0; } } @@ -4870,7 +5423,8 @@ discrim_match(discrim_t discrim, struct userNode *user) if ((discrim->mask_nick && !match_ircglob(user->nick, discrim->mask_nick)) || (discrim->mask_ident && !match_ircglob(user->ident, discrim->mask_ident)) || (discrim->mask_host && !match_ircglob(user->hostname, discrim->mask_host)) - || (discrim->mask_info && !match_ircglob(user->info, discrim->mask_info))) { + || (discrim->mask_info && !match_ircglob(user->info, discrim->mask_info)) + || (discrim->mask_version && (!user->version_reply || !match_ircglob(user->version_reply, discrim->mask_version))) ) { return 0; } } @@ -5052,6 +5606,58 @@ trace_kill_func(struct userNode *match, void *extra) return 0; } +static int +trace_svsjoin_func(struct userNode *match, void *extra) +{ + struct discrim_and_source *das = extra; + + char *channame = das->discrim->chantarget; + struct chanNode *channel; + + if(!channame || !IsChannelName(channame)) { + //reply("MSG_NOT_CHANNEL_NAME"); + return 1; + } + + if (!(channel = GetChannel(channame))) { + channel = AddChannel(channame, now, NULL, NULL, NULL); + } + if (GetUserMode(channel, match)) { +// reply("OSMSG_ALREADY_THERE", channel->name); + return 1; + } + irc_svsjoin(opserv, match, channel); + // reply("OSMSG_SVSJOIN_SENT"); + 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)) +{ + irc_version_user(opserv, match); + return 0; +} + static int is_gagged(char *mask) { @@ -5161,6 +5767,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))) { @@ -5183,6 +5790,12 @@ static MODCMD_FUNC(cmd_trace) action = trace_kill_func; else if (!irccasecmp(argv[1], "gag")) 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 { reply("OSMSG_BAD_ACTION", argv[1]); return 0; @@ -5220,20 +5833,31 @@ 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 { + 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); @@ -5247,10 +5871,12 @@ static MODCMD_FUNC(cmd_trace) regfree(&das.discrim->regex_host); if(das.discrim->has_regex_info) regfree(&das.discrim->regex_info); + if(das.discrim->has_regex_version) + regfree(&das.discrim->regex_version); free(das.discrim); dict_delete(das.dict); - return 1; + return ret; } typedef void (*cdiscrim_search_func)(struct chanNode *match, void *data, struct userNode *bot); @@ -5657,17 +6283,27 @@ alert_check_user(const char *key, void *data, void *extra) case REACT_KILL: DelUser(user, opserv, 1, alert->discrim->reason); return 1; -/* - case REACT_SILENT: - opserv_block(user, alert->owner, alert->discrim->reason, alert->discrim->duration, 1); - return 1; -*/ case REACT_GLINE: opserv_block(user, alert->owner, alert->discrim->reason, alert->discrim->duration, alert->discrim->silent); return 1; case REACT_SHUN: 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); + 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 + * re-triggers this check... + * TODO: maybe safer if we didn't even check react_version type alerts for the 2nd check? + * sort of like we only look at channel alerts on join. -Rubin + */ + if(!user->version_reply) + opserv_version(user); + break; default: log_module(OS_LOG, LOG_ERROR, "Invalid reaction type %d for alert %s.", alert->reaction, key); /* fall through to REACT_NOTICE case */ @@ -5837,10 +6473,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")) { @@ -5852,13 +6484,21 @@ static MODCMD_FUNC(cmd_addalert) #endif } else if (!irccasecmp(argv[2], "shun")) 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 { 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))) { + reply("OSMSG_ALERT_ADD_FAILED"); return 0; + } reply("OSMSG_ADDED_ALERT", name); return 1; } @@ -5984,6 +6624,48 @@ opserv_conf_read(void) policer_params_set(pp, "drain-rate", "3"); if ((child = database_get_data(conf_node, KEY_NEW_USER_POLICER, RECDB_OBJECT))) dict_foreach(child, set_policer_param, pp); + + /* Defcon configuration */ + DefCon[0] = 0; + str = database_get_data(conf_node, KEY_DEFCON1, RECDB_QSTRING); + DefCon[1] = str ? atoi(str) : 415; + str = database_get_data(conf_node, KEY_DEFCON2, RECDB_QSTRING); + DefCon[2] = str ? atoi(str) : 159; + str = database_get_data(conf_node, KEY_DEFCON3, RECDB_QSTRING); + DefCon[3] = str ? atoi(str) : 31; + str = database_get_data(conf_node, KEY_DEFCON4, RECDB_QSTRING); + DefCon[4] = str? atoi(str) : 23; + DefCon[5] = 0; + + str = database_get_data(conf_node, KEY_DEFCON_LEVEL, RECDB_QSTRING); + DefConLevel = str ? atoi(str) : 5; + + str = database_get_data(conf_node, KEY_DEFCON_CHANMODES, RECDB_QSTRING); + DefConChanModes = str ? strdup(str) : "+r"; + + str = database_get_data(conf_node, KEY_DEFCON_SESSION_LIMIT, RECDB_QSTRING); + DefConSessionLimit = str ? atoi(str) : 2; + + str = database_get_data(conf_node, KEY_DEFCON_TIMEOUT, RECDB_QSTRING); + DefConTimeOut = str ? ParseInterval(str) : 900; + + str = database_get_data(conf_node, KEY_DEFCON_GLINE_DURATION, RECDB_QSTRING); + DefConGlineExpire = str ? ParseInterval(str) : 300; + + str = database_get_data(conf_node, KEY_DEFCON_GLOBAL, RECDB_QSTRING); + GlobalOnDefcon = str ? atoi(str) : 0; + + str = database_get_data(conf_node, KEY_DEFCON_GLOBAL_MORE, RECDB_QSTRING); + GlobalOnDefconMore = str ? atoi(str) : 0; + + str = database_get_data(conf_node, KEY_DEFCON_MESSAGE, RECDB_QSTRING); + DefConMessage = str ? strdup(str) : "Put your message to send your users here. Dont forget to uncomment GlobalOnDefconMore"; + + str = database_get_data(conf_node, KEY_DEFCON_OFF_MESSAGE, RECDB_QSTRING); + DefConOffMessage = str? strdup(str) : "Services are now back to normal, sorry for any inconvenience"; + + str = database_get_data(conf_node, KEY_DEFCON_GLINE_REASON, RECDB_QSTRING); + DefConGlineReason = str ? strdup(str) : "This network is currently not accepting connections, please try again later"; } /* lame way to export opserv_conf value to nickserv.c ... */ @@ -6073,6 +6755,9 @@ init_opserv(const char *nick) opserv_define_func("ADDALERT SHUN", NULL, 900, 0, 0); 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("ADDBAD", cmd_addbad, 800, 0, 2); opserv_define_func("ADDEXEMPT", cmd_addexempt, 800, 0, 2); opserv_define_func("ADDTRUST", cmd_addtrust, 800, 0, 5); @@ -6092,6 +6777,7 @@ init_opserv(const char *nick) opserv_define_func("DELTRUST", cmd_deltrust, 800, 0, 2); opserv_define_func("DEOP", cmd_deop, 100, 2, 2); opserv_define_func("DEOPALL", cmd_deopall, 400, 2, 0); + opserv_define_func("DEFCON", cmd_defcon, 900, 0, 0); opserv_define_func("DEHOP", cmd_dehop, 100, 2, 2); opserv_define_func("DEHOPALL", cmd_dehopall, 400, 2, 0); opserv_define_func("DEVOICEALL", cmd_devoiceall, 300, 2, 0); @@ -6113,6 +6799,8 @@ 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("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); @@ -6126,6 +6814,7 @@ init_opserv(const char *nick) opserv_define_func("HOP", cmd_hop, 100, 2, 2); opserv_define_func("HOPALL", cmd_hopall, 400, 2, 0); opserv_define_func("MAP", cmd_stats_links, 0, 0, 0); + opserv_define_func("PRIVSET", cmd_privset, 900, 0, 3); opserv_define_func("PART", cmd_part, 601, 0, 2); opserv_define_func("QUERY", cmd_query, 0, 0, 0); opserv_define_func("RAW", cmd_raw, 999, 0, 2); @@ -6173,6 +6862,9 @@ init_opserv(const char *nick) opserv_define_func("TRACE SHUN", NULL, 600, 0, 0); opserv_define_func("TRACE GAG", NULL, 600, 0, 0); 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("UNBAN", cmd_unban, 100, 2, 2); opserv_define_func("UNGAG", cmd_ungag, 600, 0, 2); opserv_define_func("UNGLINE", cmd_ungline, 600, 0, 2); @@ -6202,6 +6894,7 @@ init_opserv(const char *nick) reg_del_channel_func(opserv_channel_delete); reg_join_func(opserv_join_check); reg_auth_func(opserv_staff_alert); + reg_notice_func(opserv, opserv_notice_handler); opserv_db_init(); saxdb_register("OpServ", opserv_saxdb_read, opserv_saxdb_write); @@ -6212,7 +6905,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));