#include "modcmd.h"
#include "opserv.h" /* for opserv_bad_channel() */
#include "saxdb.h"
+#include "spamserv.h"
#include "timeq.h"
#define CHANSERV_CONF_NAME "services/chanserv"
{ "CSMSG_SET_CTCPREACTION", "$bCTCPReaction$b %d - %s" },
{ "CSMSG_SET_TOPICREFRESH", "$bTopicRefresh$b %d - %s" },
{ "CSMSG_SET_RESYNC", "$bResync $b %d - %s" },
- { "CSMSG_SET_BANTYPE", "$bBanType $b %d - %s" },
{ "CSMSG_SET_BANTIMEOUT", "$bBanTimeout $b %d - %s" },
{ "CSMSG_USET_AUTOOP", "$bAutoOp $b %s" },
{ "CSMSG_BANTIMEOUT_1D", "Bans will be removed after 24 hours."},
{ "CSMSG_BANTIMEOUT_1W", "Bans will be removed after 1 week."},
- { "CSMSG_BANTYPE_A", "*!user@host" },
- { "CSMSG_BANTYPE_B", "*!*user@host" },
- { "CSMSG_BANTYPE_C", "*!*@host" },
- { "CSMSG_BANTYPE_D", "*!*user@*.host" },
- { "CSMSG_BANTYPE_E", "*!*@*.host" },
- { "CSMSG_BANTYPE_F", "nick!user@host" },
- { "CSMSG_BANTYPE_G", "nick!*@host" },
- { "CSMSG_BANTYPE_H", "nick!*user@*.host" },
- { "CSMSG_BANTYPE_I", "nick!*@*.host" },
-
{ "CSMSG_INVITED_USER", "Invited $b%s$b to join %s." },
{ "CSMSG_INVITING_YOU_REASON", "$b%s$b invites you to join %s: %s" },
{ "CSMSG_INVITING_YOU", "$b%s$b invites you to join %s." },
static dict_t plain_dnrs, mask_dnrs, handle_dnrs;
static struct log_type *CS_LOG;
struct adduserPending* adduser_pendings = NULL;
-extern const char *hidden_host_suffix;
unsigned int adduser_pendings_count = 0;
unsigned long god_timeout;
{ '3', "CSMSG_BANTIMEOUT_4H" },
{ '4', "CSMSG_BANTIMEOUT_1D" },
{ '5', "CSMSG_BANTIMEOUT_1W" }
-}, resyncValues[] = {
+},
+resyncValues[] = {
{ 'n', "CSMSG_RESYNC_NEVER" },
{ '1', "CSMSG_RESYNC_3_HOURS" },
{ '2', "CSMSG_RESYNC_6_HOURS" },
{ '3', "CSMSG_RESYNC_12_HOURS" },
{ '4', "CSMSG_RESYNC_24_HOURS" }
-}, banTypeValues[] = {
- { '1', "CSMSG_BANTYPE_A" },
- { '2', "CSMSG_BANTYPE_B" },
- { '3', "CSMSG_BANTYPE_C" },
- { '4', "CSMSG_BANTYPE_D" },
- { '5', "CSMSG_BANTYPE_E" },
- { '6', "CSMSG_BANTYPE_F" },
- { '7', "CSMSG_BANTYPE_G" },
- { '8', "CSMSG_BANTYPE_H" },
- { '9', "CSMSG_BANTYPE_I" }
};
static const struct {
{ "CSMSG_SET_CTCPREACTION", "ctcpreaction", 'n', 10, ArrayLength(ctcpReactionValues), ctcpReactionValues },
{ "CSMSG_SET_BANTIMEOUT", "bantimeout", '0', 11, ArrayLength(banTimeoutValues), banTimeoutValues },
{ "CSMSG_SET_RESYNC", "resync", 'n', 12, ArrayLength(resyncValues), resyncValues },
- { "CSMSG_SET_BANTYPE", "bantype", '4', 13, ArrayLength(banTypeValues), banTypeValues },
};
struct userData *helperList;
#define CHANSERV_DB_VERSION 2
-#define GetChannelUser(channel, handle) _GetChannelUser(channel, handle, 1, 0)
#define GetChannelAccess(channel, handle) _GetChannelUser(channel, handle, 0, 0)
#define GetTrueChannelAccess(channel, handle) _GetChannelUser(channel, handle, 0, 1)
free(user->info);
free(user);
- if(do_gc && !channel->users && !IsProtected(channel))
+ if(do_gc && !channel->users && !IsProtected(channel)) {
+ spamserv_cs_unregister(NULL, channel->channel, lost_all_users, NULL);
unregister_channel(channel, "lost all users.");
+ }
}
static struct adduserPending*
static void expire_ban(void *data);
-static struct banData*
+struct banData*
add_channel_ban(struct chanData *channel, const char *mask, char *owner, time_t set, time_t triggered, time_t expires, char *reason)
{
struct banData *bd;
/* Unregister the channel */
log_module(CS_LOG, LOG_INFO, "(%s) Channel registration expired.", channel->channel->name);
+ spamserv_cs_unregister(NULL, channel->channel, expire, NULL);
unregister_channel(channel, "registration expired.");
}
sprintf(reason, "unregistered by %s.", user->handle_info->handle);
name = strdup(channel->name);
unregister_channel(cData, reason);
+ spamserv_cs_unregister(user, channel, manually, "unregistered");
reply("CSMSG_UNREG_SUCCESS", name);
free(name);
return 1;
}
+static void
+ss_cs_join_channel(struct chanNode *channel, int spamserv_join)
+{
+ extern struct userNode *spamserv;
+ struct mod_chanmode *change;
+
+ if(spamserv && spamserv_join && get_chanInfo(channel->name))
+ {
+ change = mod_chanmode_alloc(2);
+ change->argc = 2;
+ change->args[0].mode = MODE_CHANOP;
+ change->args[0].u.member = AddChannelUser(chanserv, channel);
+ change->args[1].mode = MODE_CHANOP;
+ change->args[1].u.member = AddChannelUser(spamserv, channel);
+ }
+ else
+ {
+ change = mod_chanmode_alloc(1);
+ change->argc = 1;
+ change->args[0].mode = MODE_CHANOP;
+ change->args[0].u.member = AddChannelUser(chanserv, channel);
+ }
+
+ mod_chanmode_announce(chanserv, channel, change);
+ mod_chanmode_free(change);
+}
+
static CHANSERV_FUNC(cmd_move)
{
struct mod_chanmode change;
struct userData *uData;
char reason[MAXLEN];
struct do_not_register *dnr;
+ int chanserv_join = 0, spamserv_join;
REQUIRE_PARAMS(2);
{
target = AddChannel(argv[1], now, NULL, NULL, NULL);
if(!IsSuspended(channel->channel_info))
- AddChannelUser(chanserv, target);
+ chanserv_join = 1;
}
else if(target->channel_info)
{
return 0;
}
else if(!IsSuspended(channel->channel_info))
- {
- change.argc = 1;
- change.args[0].mode = MODE_CHANOP;
- change.args[0].u.member = AddChannelUser(chanserv, target);
- mod_chanmode_announce(chanserv, target, &change);
- }
+ chanserv_join = 1;
if(off_channel > 0)
{
target->channel_info->channel = target;
channel->channel_info = NULL;
- reply("CSMSG_MOVE_SUCCESS", target->name);
+ spamserv_join = spamserv_cs_move_merge(user, channel, target, 1);
+
+ if (chanserv_join)
+ ss_cs_join_channel(target, spamserv_join);
sprintf(reason, "%s moved to %s by %s.", channel->name, target->name, user->handle_info->handle);
if(!IsSuspended(target->channel_info))
UnlockChannel(channel);
LockChannel(target);
global_message(MESSAGE_RECIPIENT_OPERS | MESSAGE_RECIPIENT_HELPERS, reason);
+ reply("CSMSG_MOVE_SUCCESS", target->name);
return 1;
}
/* Merge the channel structures and associated data. */
merge_channel(channel->channel_info, target->channel_info);
+ spamserv_cs_move_merge(user, channel, target, 0);
sprintf(reason, "merged into %s by %s.", target->name, user->handle_info->handle);
unregister_channel(channel->channel_info, reason);
reply("CSMSG_MERGE_SUCCESS", target->name);
return 0;
}
-#define i_isdigit(x) isdigit((int) (unsigned char) (x))
-
-int is_ipv4_address(const char *host)
-{
- while (*host != '\0') {
- if (*host != '.' && !i_isdigit(*host))
- return 0;
- host++;
- }
- return 1;
-}
-
-static char *get_domain_mask(char *host)
-{
- char *ptr;
-
- if (strchr(host, '.') == NULL) {
- /* no dots - toplevel domain or IPv6 address */
- ptr = strrchr(host, ':');
- if (ptr != NULL) {
- /* IPv6 address, ban the last 64k addresses */
- if (ptr[1] != '\0') strcpy(ptr+1, "*");
- }
- return host;
- }
-
- if (is_ipv4_address(host)) {
- /* it's an IP address, change last digit to * */
- ptr = strrchr(host, '.');
- if (ptr != NULL && i_isdigit(ptr[1]))
- strcpy(ptr+1, "*");
- } else {
- /* if more than one dot, skip the first
- (dyn123.blah.net -> *.blah.net) */
- ptr = strchr(host, '.');
- if (ptr != NULL && strchr(ptr+1, '.') != NULL) {
- host = ptr-1;
- host[0] = '*';
- }
- }
- return host;
-}
-
-char *generate_ban_hostmask(struct userNode *user, const char banopt)
-{
- char *nickname = NULL;
- char *ident = "*";
- char *hostname = NULL;
- char *mask = NULL;
- char *usemask = NULL;
- int len;
-
- usemask = user->hostname;
- if (IsFakeHost(user) && IsHiddenHost(user))
- usemask = user->fakehost;
- else if (IsSetHost(user))
- usemask = strchr(user->sethost, '@') + 1;
- else if (IsHiddenHost(user) && user->handle_info && hidden_host_suffix) {
- usemask = alloca(strlen(user->handle_info->handle) + strlen(hidden_host_suffix) + 2);
- sprintf(usemask, "%s.%s", user->handle_info->handle, hidden_host_suffix);
- }
-
- if((banopt == '6') || (banopt == '7') || (banopt == '8') || (banopt == '9'))
- nickname = user->nick;
- else
- nickname = "*";
-
- if((banopt == '4') || (banopt == '5') || (banopt == '8') || (banopt == '9'))
- hostname = get_domain_mask(usemask);
- else
- hostname = usemask;
-
- if((banopt == '1') || (banopt == '6')) {
- if (IsSetHost(user)) {
- ident = alloca(strcspn(user->sethost, "@")+2);
- safestrncpy(ident, user->sethost, strcspn(user->sethost, "@")+1);
- } else
- ident = user->ident;
- }
- else if((banopt == '2') || (banopt == '4') || (banopt == '8')) {
- if (IsSetHost(user)) {
- ident = alloca(strcspn(user->sethost, "@")+3);
- ident[0] = '*';
- safestrncpy(ident+1, user->sethost, strcspn(user->sethost, "@")+1);
- } else {
- ident = malloc(strlen(user->ident)+1);
- sprintf(ident, "*%s", user->ident);
- }
- } else
- ident = "*";
-
- /* Put it all together. */
- len = strlen(ident) + strlen(hostname) + strlen(nickname) + 3;
- mask = malloc(len);
- sprintf(mask, "%s!%s@%s", nickname, ident, hostname);
-
- return mask;
-}
-
static int
eject_user(struct userNode *user, struct chanNode *channel, unsigned int argc, char *argv[], struct svccmd *cmd, int action)
{
struct userNode *victim;
struct modeNode **victims;
- struct chanData *cData;
unsigned int offset, n, victimCount, duration = 0;
- char *reason = "Bye.", *ban, *name, banopt;
+ char *reason = "Bye.", *ban, *name;
char interval[INTERVALLEN];
offset = (action & ACTION_ADD_TIMED_LAMER) ? 3 : 2;
return 0;
}
- if(!(cData = channel->channel_info)) {
- banopt = '4';
- }
-
- if (!(cData->chOpts[chBanType])) {
- banopt = '4';
- } else {
- banopt = cData->chOpts[chBanType];
- }
-
- ban = generate_ban_hostmask(victim, banopt);
+ ban = generate_hostmask(victim, GENMASK_STRICT_HOST|GENMASK_ANY_IDENT);
name = victim->nick;
}
else
suspended->cData->flags &= ~CHANNEL_SUSPENDED;
if(!IsOffChannel(suspended->cData))
{
- struct mod_chanmode change;
- mod_chanmode_init(&change);
- change.argc = 1;
- change.args[0].mode = MODE_CHANOP;
- change.args[0].u.member = AddChannelUser(chanserv, channel);
- mod_chanmode_announce(chanserv, channel, &change);
+ spamserv_cs_suspend(channel, 0, 0, NULL);
+ ss_cs_join_channel(channel, 1);
}
}
/* Mark the channel as suspended, then part. */
channel->channel_info->flags |= CHANNEL_SUSPENDED;
+ spamserv_cs_suspend(channel, expiry, 1, suspended->reason);
DelChannelUser(chanserv, channel, suspended->reason, 0);
reply("CSMSG_SUSPENDED", channel->name);
sprintf(reason, "%s suspended by %s.", channel->name, suspended->suspender);
return channel_multiple_option(chResync, CSFUNC_ARGS);
}
-static MODCMD_FUNC(chan_opt_bantype)
-{
- return channel_multiple_option(chBanType, CSFUNC_ARGS);
-}
-
static struct svccmd_list set_shows_list;
static void
"PubCmd", "InviteMe", "UserInfo","EnfOps",
"EnfHalfOps", "EnfModes", "EnfTopic", "TopicSnarf", "Setters",
/* multiple choice options */
- "AutoMode", "CtcpReaction", "Protect", "Toys", "TopicRefresh",
- "Resync", "BanType"
+ "AutoMode", "CtcpReaction", "Protect", "Toys", "TopicRefresh", "Resync",
/* binary options */
"DynLimit", "NoDelete", "BanTimeout",
/* delimiter */
DEFINE_CHANNEL_OPTION(setters);
DEFINE_CHANNEL_OPTION(topicrefresh);
DEFINE_CHANNEL_OPTION(resync);
- DEFINE_CHANNEL_OPTION(bantype);
DEFINE_CHANNEL_OPTION(ctcpreaction);
DEFINE_CHANNEL_OPTION(bantimeout);
DEFINE_CHANNEL_OPTION(inviteme);