mirror of
https://github.com/pissnet/pissircd.git
synced 2025-08-06 10:15:24 +01:00
Add spamfilter::action report (work in progress)
This commit is contained in:
parent
bee2853ded
commit
64f57ae243
7 changed files with 34 additions and 5 deletions
|
@ -921,6 +921,7 @@ extern MODVAR int (*websocket_create_packet_simple)(int opcode, const char **buf
|
|||
extern MODVAR const char *(*check_deny_link)(ConfigItem_link *link, int auto_connect);
|
||||
extern MODVAR void (*mtag_add_issued_by)(MessageTag **mtags, Client *client, MessageTag *recv_mtags);
|
||||
extern MODVAR void (*cancel_ident_lookup)(Client *client);
|
||||
extern MODVAR int (*spamreport)(Client *client, const char *ip, NameValuePrioList *details, const char *spamreport_block);
|
||||
/* /Efuncs */
|
||||
|
||||
/* TLS functions */
|
||||
|
@ -973,6 +974,7 @@ extern int websocket_create_packet_ex_default_handler(int opcode, char **buf, in
|
|||
extern int websocket_create_packet_simple_default_handler(int opcode, const char **buf, int *len);
|
||||
extern void mtag_add_issued_by_default_handler(MessageTag **mtags, Client *client, MessageTag *recv_mtags);
|
||||
extern void cancel_ident_lookup_default_handler(Client *client);
|
||||
extern int spamreport_default_handler(Client *client, const char *ip, NameValuePrioList *details, const char *spamreport_block);
|
||||
/* End of default handlers for efunctions */
|
||||
|
||||
extern MODVAR MOTDFile opermotd, svsmotd, motd, botmotd, smotd, rules;
|
||||
|
|
|
@ -2605,6 +2605,7 @@ enum EfunctionType {
|
|||
EFUNC_CHECK_DENY_LINK,
|
||||
EFUNC_MTAG_GENERATE_ISSUED_BY_IRC,
|
||||
EFUNC_CANCEL_IDENT_LOOKUP,
|
||||
EFUNC_SPAMREPORT,
|
||||
};
|
||||
|
||||
/* Module flags */
|
||||
|
|
|
@ -1172,7 +1172,8 @@ typedef enum BanActionValue {
|
|||
BAN_ACT_SOFT_BLOCK = 150,
|
||||
BAN_ACT_WARN = 100,
|
||||
BAN_ACT_SOFT_WARN = 50,
|
||||
BAN_ACT_SET = 40,
|
||||
BAN_ACT_REPORT = 40,
|
||||
BAN_ACT_SET = 30,
|
||||
} BanActionValue;
|
||||
|
||||
typedef enum VarActionValue {
|
||||
|
|
|
@ -161,6 +161,7 @@ int (*websocket_create_packet_simple)(int opcode, const char **buf, int *len);
|
|||
const char *(*check_deny_link)(ConfigItem_link *link, int auto_connect);
|
||||
void (*mtag_add_issued_by)(MessageTag **mtags, Client *client, MessageTag *recv_mtags);
|
||||
void (*cancel_ident_lookup)(Client *client);
|
||||
int (*spamreport)(Client *client, const char *ip, NameValuePrioList *details, const char *spamreport_block);
|
||||
|
||||
Efunction *EfunctionAddMain(Module *module, EfunctionType eftype, int (*func)(), void (*vfunc)(), void *(*pvfunc)(), char *(*stringfunc)(), const char *(*conststringfunc)())
|
||||
{
|
||||
|
@ -455,4 +456,5 @@ void efunctions_init(void)
|
|||
efunc_init_function(EFUNC_CHECK_DENY_LINK, check_deny_link, NULL);
|
||||
efunc_init_function(EFUNC_MTAG_GENERATE_ISSUED_BY_IRC, mtag_add_issued_by, mtag_add_issued_by_default_handler);
|
||||
efunc_init_function(EFUNC_CANCEL_IDENT_LOOKUP, cancel_ident_lookup, cancel_ident_lookup_default_handler);
|
||||
efunc_init_function(EFUNC_SPAMREPORT, spamreport, spamreport_default_handler);
|
||||
}
|
||||
|
|
12
src/misc.c
12
src/misc.c
|
@ -80,6 +80,7 @@ static BanActTable banacttable[] = {
|
|||
{ BAN_ACT_WARN, 'w', "warn" },
|
||||
{ BAN_ACT_SOFT_WARN, 'W', "soft-warn" },
|
||||
{ BAN_ACT_SET, '1', "set" },
|
||||
{ BAN_ACT_REPORT, 'r', "report" },
|
||||
{ 0, 0, 0 }
|
||||
};
|
||||
|
||||
|
@ -894,6 +895,8 @@ int test_ban_action_config_helper(ConfigEntry *ce, const char *name, const char
|
|||
errors++;
|
||||
}
|
||||
}
|
||||
} else if (action == BAN_ACT_REPORT)
|
||||
{
|
||||
}
|
||||
|
||||
return errors;
|
||||
|
@ -947,6 +950,10 @@ BanAction *parse_ban_action_config_helper(const char *name, const char *value)
|
|||
safe_strdup(action->var, var);
|
||||
action->value = varvalue;
|
||||
action->var_action = op;
|
||||
} else
|
||||
if (action->action == BAN_ACT_REPORT)
|
||||
{
|
||||
safe_strdup(action->var, value); // can be NULL, means all
|
||||
}
|
||||
|
||||
return action;
|
||||
|
@ -1681,6 +1688,11 @@ int is_silenced_default_handler(Client *client, Client *acptr)
|
|||
return 0;
|
||||
}
|
||||
|
||||
int spamreport_default_handler(Client *client, const char *ip, NameValuePrioList *details, const char *spamreport_block)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
/** Generate a BATCH id.
|
||||
* This can be used in a :serv BATCH +%s ... message
|
||||
*/
|
||||
|
|
|
@ -39,6 +39,7 @@ CMD_FUNC(cmd_spamreport);
|
|||
int tkl_config_test_spamreport(ConfigFile *, ConfigEntry *, int, int *);
|
||||
int tkl_config_run_spamreport(ConfigFile *, ConfigEntry *, int);
|
||||
void free_spamreport_blocks(void);
|
||||
int _spamreport(Client *client, const char *ip, NameValuePrioList *details, const char *spamreport_block);
|
||||
|
||||
/* Variables */
|
||||
Spamreport *spamreports = NULL;
|
||||
|
@ -46,6 +47,7 @@ Spamreport *spamreports = NULL;
|
|||
MOD_TEST()
|
||||
{
|
||||
MARK_AS_OFFICIAL_MODULE(modinfo);
|
||||
EfunctionAdd(modinfo->handle, EFUNC_SPAMREPORT, _spamreport);
|
||||
HookAdd(modinfo->handle, HOOKTYPE_CONFIGTEST, 0, tkl_config_test_spamreport);
|
||||
return MOD_SUCCESS;
|
||||
}
|
||||
|
@ -223,6 +225,7 @@ int tkl_config_run_spamreport(ConfigFile *cf, ConfigEntry *ce, int type)
|
|||
return 0;
|
||||
|
||||
s = safe_alloc(sizeof(Spamreport));
|
||||
safe_strdup(s->name, ce->value);
|
||||
|
||||
for (cep = ce->items; cep; cep = cep->next)
|
||||
{
|
||||
|
@ -300,21 +303,26 @@ Spamreport *find_spamreport_block(const char *name)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
int report_spam(Client *client, const char *ip, NameValuePrioList *details, Spamreport *s)
|
||||
int _spamreport(Client *client, const char *ip, NameValuePrioList *details, const char *spamreport_block)
|
||||
{
|
||||
Spamreport *s;
|
||||
char urlbuf[512];
|
||||
char bodybuf[512];
|
||||
char *url = NULL;
|
||||
char *body = NULL;
|
||||
|
||||
if (s == NULL)
|
||||
if (!spamreport_block)
|
||||
{
|
||||
int ret = 0;
|
||||
for (s = spamreports; s; s = s->next)
|
||||
ret += report_spam(client, ip, details, s);
|
||||
ret += spamreport(client, ip, details, s->name);
|
||||
return ret;
|
||||
}
|
||||
|
||||
s = find_spamreport_block(spamreport_block);
|
||||
if (!s)
|
||||
return -1; /* NOTFOUND */
|
||||
|
||||
if (s->except && client && user_allowed_by_security_group(client, s->except))
|
||||
return 0;
|
||||
// NOTE: 'except' is bypassed for manual SPAMREPORT with an ip and no client.
|
||||
|
@ -398,7 +406,7 @@ CMD_FUNC(cmd_spamreport)
|
|||
return;
|
||||
}
|
||||
|
||||
if (!((n = report_spam(target, ip, NULL, to))))
|
||||
if (!((n = spamreport(target, ip, NULL, to ? to->name : NULL))))
|
||||
sendnotice(client, "Could not report spam. No spamreport { } blocks configured, or all filtered out/exempt.");
|
||||
else
|
||||
sendnotice(client, "Sending spam report to %d target(s)", n);
|
||||
|
|
|
@ -4797,6 +4797,9 @@ int _place_host_ban(Client *client, BanAction *actions, char *reason, long durat
|
|||
if (!skip_set)
|
||||
ban_act_set(client, action);
|
||||
break;
|
||||
case BAN_ACT_REPORT:
|
||||
spamreport(client, client->ip, NULL, action->var);
|
||||
break;
|
||||
case BAN_ACT_WARN:
|
||||
/* No action taken by us */
|
||||
break;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue