#define KEY_EXPIRY "expiry"
#define KEY_DEBUG_CHANNEL "debug_channel"
+#define KEY_OPER_CHANNEL "oper_channel"
#define KEY_GLOBAL_EXCEPTIONS "global_exceptions"
#define KEY_NETWORK_RULES "network_rules"
#define KEY_TRIGGER "trigger"
dict_t killed_users_dict;
#define spamserv_notice(target, format...) send_message(target , spamserv , ## format)
-#define spamserv_debug(format...) do { if(spamserv_conf.debug_channel) send_channel_notice(spamserv_conf.debug_channel , spamserv , ## format); } while(0)
+#define spamserv_debug(format...) do { if(spamserv_conf.debug_channel) send_channel_message(spamserv_conf.debug_channel , spamserv , ## format); } while(0)
+#define spamserv_oper_message(format...) do { if(spamserv_conf.oper_channel) send_channel_message(spamserv_conf.oper_channel , spamserv , ## format); } while(0)
#define ss_reply(format...) send_message(user , spamserv , ## format)
#define SET_SUBCMDS_SIZE 10
{ "SSMSG_STATUS_MEMORY", "$bMemory Information:$b" },
{ "SSMSG_STATUS_CHANNEL_LIST", "$bRegistered Channels:$b" },
{ "SSMSG_STATUS_NO_CHANNEL", "No channels registered." },
+
+ { "SSMSG_BADWORD_ALREADY_ADDED", "$b%s$b is already added. (ID: %s)" },
+ { "SSMSG_BADWORD_ADDED", "added '$b%s$b' to the badword list with ID %s." },
+ { "SSMSG_BADWORD_SET_DONE", "Done." },
+ { "SSMSG_BADWORD_SET_INVALID", "Invalid Option for setting %s" },
+ { "SSMSG_BADWORD_SET", "Settings for BadWord entry $b%s$b" },
+ { "SSMSG_BADWORD_SET_MASK", "$bMASK$b: %s" },
+ { "SSMSG_BADWORD_SET_ACTION", "$bACTION$b: %s" },
+ { "SSMSG_BADWORD_NOT_FOUND", "badword with ID %s does not exist." },
+ { "SSMSG_BADWORD_REMOVED", "badword ID $b%s$b has been removed (mask: '%s')" },
{ NULL, NULL }
};
#define SSMSG_WARNING_2 "You are violating the network rules"
#define SSMSG_WARNING_RULES "%s is against the network rules. Read the network rules at %s"
#define SSMSG_WARNING_RULES_2 "You are violating the network rules. Read the network rules at %s"
+#define SSMSG_BADWORD_DETECTED "Your message contained a forbidden word."
+#define SSMSG_CHANNEL_REGISTERED "%s (channel %s) registered by %s."
+#define SSMSG_CHANNEL_UNREGISTERED "%s (channel %s) unregistered by %s."
static struct
{
struct chanNode *debug_channel;
+ struct chanNode *oper_channel;
struct string_list *global_exceptions;
const char *network_rules;
unsigned char trigger;
}
}
+static struct badword*
+add_badword(struct chanInfo *cInfo, const char *badword_mask, unsigned int triggered, unsigned int action, const char *id)
+{
+ struct badword *badword;
+
+ badword = calloc(1, sizeof(*badword));
+ if (!badword)
+ return NULL;
+
+ if(!id) {
+ cInfo->last_badword_id++;
+ badword->id = strtab(cInfo->last_badword_id);
+ } else
+ badword->id = strdup(id);
+ badword->badword_mask = strdup(badword_mask);
+ badword->triggered = triggered;
+ badword->action = action;
+ dict_insert(cInfo->badwords, badword->id, badword);
+ return badword;
+}
+
/***********************************************/
/* Other Stuff */
/***********************************************/
spamserv_join_channel(cInfo->channel);
- snprintf(reason, sizeof(reason), "%s (channel %s) registered by %s.", spamserv->nick, channel->name, user->handle_info->handle);
- global_message(MESSAGE_RECIPIENT_OPERS | MESSAGE_RECIPIENT_HELPERS, reason);
+ spamserv_oper_message(SSMSG_CHANNEL_REGISTERED, spamserv->nick, channel->name, user->handle_info->handle);
ss_reply("SSMSG_REG_SUCCESS", channel->name);
return 1;
spamserv_unregister_channel(cInfo);
- snprintf(reason, sizeof(reason), "%s (channel %s) unregistered by %s.", spamserv->nick, channel->name, user->handle_info->handle);
- global_message(MESSAGE_RECIPIENT_OPERS | MESSAGE_RECIPIENT_HELPERS, reason);
+ spamserv_oper_message(SSMSG_CHANNEL_UNREGISTERED, channel->name, user->handle_info->handle);
ss_reply("SSMSG_UNREG_SUCCESS", channel->name);
return 1;
return 1;
}
+static SPAMSERV_FUNC(cmd_addbad)
+{
+ struct chanInfo *cInfo = get_chanInfo(channel->name);
+ struct userData *uData;
+
+ if(!cInfo)
+ {
+ ss_reply("SSMSG_NOT_REGISTERED", channel->name);
+ return 0;
+ }
+
+ if(CHECK_SUSPENDED(cInfo))
+ {
+ ss_reply("SSMSG_SUSPENDED", channel->name);
+ return 0;
+ }
+
+ if(!check_user_level(channel,user,lvlSetters,1,0))
+ {
+ ss_reply("SSMSG_NO_ACCESS");
+ return 0;
+ }
+
+ dict_iterator_t it;
+ char *mask = unsplit_string(argv + 1, argc - 1, NULL);
+ for (it = dict_first(cInfo->badwords); it; it = iter_next(it)) {
+ struct badword *badword = iter_data(it);
+ if(match_ircglob(mask,badword->badword_mask)) {
+ reply("SSMSG_BADWORD_ALREADY_ADDED", mask, badword->id);
+ return 1;
+ }
+ }
+
+ struct badword *new_badword = add_badword(cInfo, mask, 0, BADACTION_KICK, NULL);
+ for (it = dict_first(cInfo->badwords); it; it = iter_next(it)) {
+ struct badword *badword = iter_data(it);
+ if(match_ircglob(badword->badword_mask, new_badword->badword_mask) && badword != new_badword) {
+ dict_remove(cInfo->badwords, badword->id);
+ }
+ }
+
+ reply("SSMSG_BADWORD_ADDED", new_badword->badword_mask, new_badword->id);
+ return 1;
+}
+
+static SPAMSERV_FUNC(cmd_delbad)
+{
+ struct chanInfo *cInfo = get_chanInfo(channel->name);
+ struct userData *uData;
+ unsigned int n;
+
+ if(!cInfo)
+ {
+ ss_reply("SSMSG_NOT_REGISTERED", channel->name);
+ return 0;
+ }
+
+ if(CHECK_SUSPENDED(cInfo))
+ {
+ ss_reply("SSMSG_SUSPENDED", channel->name);
+ return 0;
+ }
+
+ if(!check_user_level(channel,user,lvlSetters,1,0))
+ {
+ ss_reply("SSMSG_NO_ACCESS");
+ return 0;
+ }
+
+ for (n=1; n<argc; n++) {
+ struct badword *badword = dict_find(cInfo->badwords, argv[n], NULL);
+ if (!badword) {
+ reply("SSMSG_BADWORD_NOT_FOUND", argv[n]);
+ continue;
+ }
+ reply("SSMSG_BADWORD_REMOVED", argv[n], badword->badword_mask);
+ dict_remove(cInfo->badwords, argv[n]);
+ }
+ return 1;
+}
+
+static SPAMSERV_FUNC(cmd_setbad)
+{
+ struct chanInfo *cInfo = get_chanInfo(channel->name);
+ struct userData *uData;
+ struct badword *badword;
+
+ if(!cInfo)
+ {
+ ss_reply("SSMSG_NOT_REGISTERED", channel->name);
+ return 0;
+ }
+
+ if(CHECK_SUSPENDED(cInfo))
+ {
+ ss_reply("SSMSG_SUSPENDED", channel->name);
+ return 0;
+ }
+
+ if(!check_user_level(channel,user,lvlSetters,1,0))
+ {
+ ss_reply("SSMSG_NO_ACCESS");
+ return 0;
+ }
+
+ if ((badword = dict_find(cInfo->badwords, argv[1], NULL))) {
+ if (argc > 3) {
+ unsigned int ii;
+ char *setting = argv[2];
+ char *value = argv[3];
+ for( ii = 0; setting[ ii ]; ii++)
+ setting[ ii ] = toupper( setting[ ii ] );
+ for( ii = 0; value[ ii ]; ii++)
+ value[ ii ] = toupper( value[ ii ] );
+ if(!strcmp("MASK",setting)) {
+ free(badword->badword_mask);
+ badword->badword_mask = strdup(argv[3]);
+ badword->triggered = 0;
+ reply("SSMSG_BADWORD_SET_DONE");
+ }
+ else if(!strcmp("ACTION",setting)) {
+ if (!strcmp("1",value) || !strcmp("KICK",value)) {
+ badword->action = BADACTION_KICK;
+ reply("SSMSG_BADWORD_SET_DONE");
+ } else if (!strcmp("2",value) || !strcmp("BAN",value)) {
+ badword->action = BADACTION_BAN;
+ reply("SSMSG_BADWORD_SET_DONE");
+ } else if (!strcmp("3",value) || !strcmp("KILL",value)) {
+ badword->action = BADACTION_KILL;
+ reply("SSMSG_BADWORD_SET_DONE");
+ } else if (!strcmp("4",value) || !strcmp("GLINE",value)) {
+ badword->action = BADACTION_GLINE;
+ reply("SSMSG_BADWORD_SET_DONE");
+ } else {
+ reply("SSMSG_BADWORD_SET_INVALID", setting);
+ }
+ } else {
+ reply("SSMSG_BADWORD_SETTING_INVALID", setting);
+ }
+
+ } else {
+ reply("SSMSG_BADWORD_SET", badword->id);
+ reply("SSMSG_BADWORD_SET_MASK", badword->badword_mask);
+ switch(badword->action) {
+ case BADACTION_KICK:
+ reply("SSMSG_BADWORD_SET_ACTION", "KICK");
+ break;
+ case BADACTION_BAN:
+ reply("SSMSG_BADWORD_SET_ACTION", "BAN");
+ break;
+ case BADACTION_KILL:
+ reply("SSMSG_BADWORD_SET_ACTION", "KILL");
+ break;
+ case BADACTION_GLINE:
+ reply("SSMSG_BADWORD_SET_ACTION", "GLINE");
+ break;
+ default:
+ reply("SSMSG_BADWORD_SET_ACTION", "*undef*");
+ }
+ }
+ } else {
+ reply("SSMSG_BADWORD_NOT_FOUND", argv[1]);
+ return 0;
+ }
+ return 1;
+}
+
+int
+ss_badwords_sort(const void *pa, const void *pb)
+{
+ struct badword *a = *(struct badword**)pa;
+ struct badword *b = *(struct badword**)pb;
+
+ return strtoul(a->id, NULL, 0) - strtoul(b->id, NULL, 0);
+}
+
+static SPAMSERV_FUNC(cmd_listbad)
+{
+ struct helpfile_table tbl;
+ struct chanInfo *cInfo = get_chanInfo(channel->name);
+ struct userData *uData;
+ struct badword **badwords;
+ unsigned int count = 0, ii = 0;
+
+ if(!cInfo)
+ {
+ ss_reply("SSMSG_NOT_REGISTERED", channel->name);
+ return 0;
+ }
+
+ if(CHECK_SUSPENDED(cInfo))
+ {
+ ss_reply("SSMSG_SUSPENDED", channel->name);
+ return 0;
+ }
+
+ if(!check_user_level(channel,user,lvlSetters,1,0))
+ {
+ ss_reply("SSMSG_NO_ACCESS");
+ return 0;
+ }
+
+ dict_iterator_t it;
+ for (it = dict_first(cInfo->badwords); it; it = iter_next(it)) {
+ count++;
+ }
+
+ tbl.length = count+1;
+ tbl.width = 4;
+ tbl.flags = 0;
+ tbl.flags = TABLE_NO_FREE;
+ tbl.contents = malloc(tbl.length * sizeof(tbl.contents[0]));
+ tbl.contents[0] = malloc(tbl.width * sizeof(tbl.contents[0][0]));
+ tbl.contents[0][0] = "#";
+ tbl.contents[0][1] = "Badword";
+ tbl.contents[0][2] = "Action";
+ tbl.contents[0][3] = "(Triggered)";
+ if(!count)
+ {
+ table_send(cmd->parent->bot, user->nick, 0, NULL, tbl);
+ reply("MSG_NONE");
+ free(tbl.contents[0]);
+ free(tbl.contents);
+ return 0;
+ }
+ badwords = alloca(count * sizeof(badwords[0]));
+ for (it = dict_first(cInfo->badwords); it; it = iter_next(it)) {
+ struct badword *bw = iter_data(it);
+ badwords[ii++] = bw;
+ }
+
+ qsort(badwords, count, sizeof(badwords[0]), ss_badwords_sort);
+ for (ii = 1; ii <= count; ii++) {
+ struct badword *bw = badwords[ii-1];
+ tbl.contents[ii] = malloc(tbl.width * sizeof(tbl.contents[0][0]));
+ tbl.contents[ii][0] = strdup(bw->id);
+ tbl.contents[ii][1] = strdup(bw->badword_mask);
+ switch(bw->action) {
+ case BADACTION_KICK:
+ tbl.contents[ii][2] = "KICK";
+ break;
+ case BADACTION_BAN:
+ tbl.contents[ii][2] = "BAN";
+ break;
+ case BADACTION_KILL:
+ tbl.contents[ii][2] = "KILL";
+ break;
+ case BADACTION_GLINE:
+ tbl.contents[ii][2] = "GLINE";
+ break;
+ default:
+ tbl.contents[ii][2] = "*undef*";
+ }
+ tbl.contents[ii][3] = strtab(bw->triggered);
+ }
+
+ table_send(cmd->parent->bot, user->nick, 0, NULL, tbl);
+ for(ii = 1; ii < tbl.length; ++ii)
+ {
+ free(tbl.contents[ii]);
+ }
+ free(tbl.contents[0]);
+ free(tbl.contents);
+ return 1;
+}
+
static void
to_lower(char *message)
{
}
}
}
+
+ dict_iterator_t it;
+
+ for (it = dict_first(cInfo->badwords); it; it = iter_next(it)) {
+ struct badword *badword = iter_data(it);
+ if(match_ircglob(text, badword->badword_mask)) {
+ spamserv_detected_badword(user, channel, badword);
+ }
+ }
if(CHECK_ADV(cInfo) && check_advertising(cInfo, text))
{
}
}
+static int
+spamserv_saxdb_read_shitlist(const char *name, void *data, void *extra)
+{
+ struct record_data *rd = data;
+ struct chanInfo *chan = extra;
+ char *badword;
+ char *triggered, *action;
+
+ if (rd->type == RECDB_OBJECT) {
+ dict_t obj = GET_RECORD_OBJECT(rd);
+ /* new style structure */
+ badword = database_get_data(obj, KEY_BADWORD_MASK, RECDB_QSTRING);
+ triggered = database_get_data(obj, KEY_BADWORD_TRIGGERED, RECDB_QSTRING);
+ action = database_get_data(obj, KEY_BADWORD_ACTION, RECDB_QSTRING);
+
+ add_badword(chan, badword, strtoul(triggered, NULL, 0), strtoul(action, NULL, 0), name);
+ }
+ return 0;
+}
+
static int
spamserv_saxdb_read(struct dict *database)
{
dict_iterator_t it;
+ struct dict *badwords;
struct record_data *hir;
struct chanNode *channel;
struct chanInfo *cInfo;
struct string_list *strlist;
- unsigned int flags,exceptlevel;
- char *str, *info;
+ unsigned int flags,exceptlevel,badwordid;
+ char *str, *info;
unsigned long expiry;
for(it = dict_first(database); it; it = iter_next(it))
else
cInfo->suspend_expiry = expiry;
cInfo->exceptlevel=exceptlevel;
+ cInfo->badwords = dict_new();
+ str = database_get_data(hir->d.object, KEY_LASTBADWORDID, RECDB_QSTRING);
+ badwordid = str ? atoi(str) : 0;
+ cInfo->last_badword_id = badwordid;
+ if ((badwords = database_get_data(hir->d.object, KEY_BADWORDS, RECDB_OBJECT)))
+ dict_foreach(badwords, spamserv_saxdb_read_shitlist, cInfo);
}
}
else
saxdb_write_int(ctx, KEY_EXCEPTLEVEL, cInfo->exceptlevel);
if(cInfo->suspend_expiry)
- saxdb_write_int(ctx, KEY_EXPIRY, cInfo->suspend_expiry);
-
+ saxdb_write_int(ctx, KEY_EXPIRY, cInfo->suspend_expiry);
+
+ saxdb_write_int(ctx, KEY_LASTBADWORDID, cInfo->last_badword_id);
+ saxdb_start_record(ctx, KEY_BADWORDS, 1);
+ dict_iterator_t itbad;
+ for (itbad = dict_first(cInfo->badwords); itbad; itbad = iter_next(itbad)) {
+ struct badword *badword = iter_data(itbad);
+ saxdb_start_record(ctx, badword->id, 1);
+ saxdb_write_string(ctx, KEY_BADWORDID, badword->id);
+ saxdb_write_string(ctx, KEY_BADWORD_MASK, badword->badword_mask);
+ saxdb_write_int(ctx, KEY_BADWORD_ACTION, badword->action);
+ saxdb_write_int(ctx, KEY_BADWORD_TRIGGERED, badword->triggered);
+ saxdb_end_record(ctx);
+ }
+ saxdb_end_record(ctx);
saxdb_end_record(ctx);
}
return 0;
}
str = database_get_data(conf_node, KEY_DEBUG_CHANNEL, RECDB_QSTRING);
-
if(str)
{
spamserv_conf.debug_channel = AddChannel(str, now, "+tinms", NULL);
spamserv_conf.debug_channel = NULL;
}
+ str = database_get_data(conf_node, KEY_OPER_CHANNEL, RECDB_QSTRING);
+ if(str)
+ {
+ spamserv_conf.oper_channel = AddChannel(str, now, "+tinms", NULL);
+ }
+ else
+ {
+ spamserv_conf.oper_channel = NULL;
+ }
+
spamserv_conf.global_exceptions = database_get_data(conf_node, KEY_GLOBAL_EXCEPTIONS, RECDB_STRING_LIST);
str = database_get_data(conf_node, KEY_NETWORK_RULES, RECDB_QSTRING);