mirror of
https://github.com/unrealircd/unrealircd.git
synced 2026-07-08 13:23:12 +02:00
Add TextAnalysis on spamfilter hit in the JSON logs.
This commit is contained in:
@@ -1393,6 +1393,7 @@ extern LogData *log_data_source(const char *file, int line, const char *function
|
||||
extern LogData *log_data_socket_error(int fd);
|
||||
extern LogData *log_data_link_block(ConfigItem_link *link);
|
||||
extern LogData *log_data_tkl(const char *key, TKL *tkl);
|
||||
extern LogData *log_data_textanalysis(const char *key, TextAnalysis *ta);
|
||||
extern LogData *log_data_tls_error(void);
|
||||
extern void log_data_free(LogData *d);
|
||||
extern void log_pre_rehash(void);
|
||||
|
||||
@@ -728,6 +728,21 @@ LogData *log_data_tkl(const char *key, TKL *tkl)
|
||||
return d;
|
||||
}
|
||||
|
||||
LogData *log_data_textanalysis(const char *key, TextAnalysis *ta)
|
||||
{
|
||||
char buf[BUFSIZE];
|
||||
LogData *d = safe_alloc(sizeof(LogData));
|
||||
json_t *j;
|
||||
|
||||
d->type = LOG_FIELD_OBJECT;
|
||||
safe_strdup(d->key, key);
|
||||
d->value.object = j = json_object();
|
||||
|
||||
json_expand_textanalysis(j, NULL, ta, 1);
|
||||
|
||||
return d;
|
||||
}
|
||||
|
||||
void log_data_free(LogData *d)
|
||||
{
|
||||
if (d->type == LOG_FIELD_STRING)
|
||||
|
||||
+6
-1
@@ -5416,13 +5416,18 @@ static void match_spamfilter_hit(Client *client, const char *str_in, const char
|
||||
log_data_string("_space", destination ? " " : ""),
|
||||
log_data_string("destination", destination ? destination : ""));
|
||||
} else {
|
||||
// Yeah we are re-running the text analysis.
|
||||
TextAnalysis textanalysis;
|
||||
memset(&textanalysis, 0, sizeof(textanalysis));
|
||||
RunHook(HOOKTYPE_ANALYZE_TEXT, client, str, &textanalysis);
|
||||
unreal_log(ULOG_INFO, "tkl", "SPAMFILTER_MATCH", client,
|
||||
"[Spamfilter] $client.details matches filter '$tkl': [cmd: $command$_space$destination: '$str'] [reason: $tkl.reason] [action: $tkl.ban_action]",
|
||||
log_data_tkl("tkl", tkl),
|
||||
log_data_string("command", cmd),
|
||||
log_data_string("_space", destination ? " " : ""),
|
||||
log_data_string("destination", destination ? destination : ""),
|
||||
log_data_string("str", str));
|
||||
log_data_string("str", str),
|
||||
log_data_textanalysis("textanalysis", &textanalysis));
|
||||
*content_revealed = 1;
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -561,7 +561,7 @@ static void parse2(Client *cptr, Client **fromptr, MessageTag *mtags, int mtags_
|
||||
{
|
||||
memset(&text_analysis_storage, 0, sizeof(text_analysis_storage));
|
||||
clictx.textanalysis = &text_analysis_storage;
|
||||
RunHook(HOOKTYPE_ANALYZE_TEXT, from, para[i-1], clictx.textanalysis); // is para[i] correct? probably not? -1 ? safety check?
|
||||
RunHook(HOOKTYPE_ANALYZE_TEXT, from, para[i-1], clictx.textanalysis);
|
||||
}
|
||||
|
||||
/* Now ready to execute the command */
|
||||
|
||||
Reference in New Issue
Block a user