* 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"
#include <arpa/inet.h>
#endif
-
#define OPSERV_CONF_NAME "services/opserv"
#define KEY_ALERT_CHANNEL "alert_channel"
{ "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_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_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_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_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?)." },
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;
irc_in_addr_t ip_mask;
unsigned long limit;
time_t min_ts, max_ts;
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 {
REACT_SHUN,
REACT_SVSJOIN,
REACT_SVSPART,
- REACT_VERSION
+ REACT_VERSION,
+ REACT_MARK
} opserv_alert_reaction;
struct opserv_user_alert {
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);
}
}
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;
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*/
}
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;
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) {
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)) )
+ 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_SVSJOIN: reaction = "svsjoin"; break;
case REACT_SVSPART: reaction = "svspart"; break;
case REACT_VERSION: reaction = "version"; break;
+ case REACT_MARK: reaction = "mark"; break;
default: reaction = "<unknown>"; break;
}
reply("OSMSG_ALERT_IS", iter_key(it), reaction, alert->owner);
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 = "";
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
*/
* 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);
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");
/* 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");
}
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;
}
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);
+ /* 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_SVSPART && !alert->discrim->chantarget) ||
+ (reaction==REACT_MARK && !alert->discrim->mark)) {
free(alert->text_discrim);
free(discrim_copy);
free(alert);
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;
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));
}
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])) {
|| (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))
)
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(!channame || !IsChannelName(channame)) {
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;
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;
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);
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);
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 */
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;
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);
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);
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);
}
/* 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));