gchar *debug_ip_map; /**< turn on debugging for specified ip addresses */
gboolean log_urls; /**< whether we should log URLs */
GList *debug_symbols; /**< symbols to debug */
+ gboolean log_color; /**< output colors for console output */
gsize max_statfile_size; /**< maximum size for statfile */
G_STRUCT_OFFSET (struct config_file, debug_symbols),
NULL
},
+ {
+ "log_color",
+ xml_handle_boolean,
+ G_STRUCT_OFFSET (struct config_file, log_color),
+ NULL
+ },
NULL_ATTR
},
NULL_DEF_ATTR
gchar tmpbuf[256], timebuf[32];
time_t now;
struct tm *tms;
- struct iovec iov[3];
+ struct iovec iov[4];
gint r;
guint32 cksum;
size_t mlen;
strftime (timebuf, sizeof (timebuf), "%F %H:%M:%S", tms);
cptype = process_to_str (rspamd_log->process_type);
+ if (rspamd_log->cfg->log_color) {
+ if (log_level >= G_LOG_LEVEL_INFO) {
+ /* White */
+ r = rspamd_snprintf (tmpbuf, sizeof (tmpbuf), "\033[1;37m");
+ }
+ else if (log_level >= G_LOG_LEVEL_WARNING) {
+ /* Magenta */
+ r = rspamd_snprintf (tmpbuf, sizeof (tmpbuf), "\033[2;32m");
+ }
+ else if (log_level >= G_LOG_LEVEL_CRITICAL) {
+ /* Red */
+ r = rspamd_snprintf (tmpbuf, sizeof (tmpbuf), "\033[1;31m");
+ }
+ }
+ else {
+ r = 0;
+ }
if (function == NULL) {
- r = rspamd_snprintf (tmpbuf, sizeof (tmpbuf), "%s #%P(%s) ", timebuf, rspamd_log->pid, cptype);
+ r += rspamd_snprintf (tmpbuf + r, sizeof (tmpbuf) - r, "%s #%P(%s) ", timebuf, rspamd_log->pid, cptype);
}
else {
- r = rspamd_snprintf (tmpbuf, sizeof (tmpbuf), "%s #%P(%s) %s: ", timebuf, rspamd_log->pid, cptype, function);
+ r += rspamd_snprintf (tmpbuf + r, sizeof (tmpbuf) -r, "%s #%P(%s) %s: ", timebuf, rspamd_log->pid, cptype, function);
}
/* Construct IOV for log line */
iov[0].iov_base = tmpbuf;
iov[1].iov_len = mlen;
iov[2].iov_base = (void *)&lf_chr;
iov[2].iov_len = 1;
+ if (rspamd_log->cfg->log_color) {
+ iov[3].iov_base = "\033[0m";
+ iov[3].iov_len = sizeof ("\033[0m") - 1;
+ /* Call helper (for buffering) */
+ file_log_helper (iov, 4);
+ }
+ else {
+ /* Call helper (for buffering) */
+ file_log_helper (iov, 3);
+ }
- /* Call helper (for buffering) */
- file_log_helper (iov, 3);
}
}
#include "../radix.h"
#include "../trie.h"
#include "../classifiers/classifiers.h"
+#include "../cfg_xml.h"
/* Config file methods */
LUA_FUNCTION_DEF (config, get_module_opt);
LUA_FUNCTION_DEF (config, get_classifier);
LUA_FUNCTION_DEF (config, register_symbol);
LUA_FUNCTION_DEF (config, register_post_filter);
+LUA_FUNCTION_DEF (config, register_module_option);
static const struct luaL_reg configlib_m[] = {
LUA_INTERFACE_DEF (config, get_module_opt),
LUA_INTERFACE_DEF (config, add_hash_map),
LUA_INTERFACE_DEF (config, get_classifier),
LUA_INTERFACE_DEF (config, register_symbol),
+ LUA_INTERFACE_DEF (config, register_module_option),
LUA_INTERFACE_DEF (config, register_post_filter),
{"__tostring", lua_class_tostring},
{NULL, NULL}
return 1;
}
+static gint
+lua_config_register_module_option (lua_State *L)
+{
+ struct config_file *cfg = lua_check_config (L);
+ const gchar *mname, *optname, *stype;
+ enum module_opt_type type;
+
+ if (cfg) {
+ mname = memory_pool_strdup (cfg->cfg_pool, luaL_checkstring (L, 2));
+ optname = memory_pool_strdup (cfg->cfg_pool, luaL_checkstring (L, 3));
+ stype = memory_pool_strdup (cfg->cfg_pool, luaL_checkstring (L, 4));
+ if (mname && optname) {
+ if (stype == NULL) {
+ stype = "string";
+ }
+ if (g_ascii_strcasecmp (stype, "string") == 0) {
+ type = MODULE_OPT_TYPE_STRING;
+ }
+ else if (g_ascii_strcasecmp (stype, "int") == 0) {
+ type = MODULE_OPT_TYPE_INT;
+ }
+ else if (g_ascii_strcasecmp (stype, "uint") == 0) {
+ type = MODULE_OPT_TYPE_UINT;
+ }
+ else if (g_ascii_strcasecmp (stype, "time") == 0) {
+ type = MODULE_OPT_TYPE_TIME;
+ }
+ else if (g_ascii_strcasecmp (stype, "size") == 0) {
+ type = MODULE_OPT_TYPE_SIZE;
+ }
+ else if (g_ascii_strcasecmp (stype, "map") == 0) {
+ type = MODULE_OPT_TYPE_MAP;
+ }
+ else if (g_ascii_strcasecmp (stype, "double") == 0) {
+ type = MODULE_OPT_TYPE_DOUBLE;
+ }
+ else {
+ msg_err ("unknown type '%s' for option: %s, for module: %s", stype, optname, mname);
+ luaL_error (L, "unknown type '%s' for option: %s, for module: %s", stype, optname, mname);
+ return 0;
+ }
+ register_module_opt (mname, optname, type);
+ return 1;
+ }
+ luaL_error (L, "bad arguments for register module option, must be: register_module_option(modulename, optionname, optiontype)");
+ }
+
+ return 0;
+}
+
void
lua_call_post_filters (struct worker_task *task)
{
/* Init events to test modules */
event_init ();
res = TRUE;
+ if (! init_lua_filters (rspamd->cfg)) {
+ res = FALSE;
+ }
if (!check_modules_config (rspamd->cfg)) {
res = FALSE;
}
}
l = g_list_next (l);
}
- if (! init_lua_filters (rspamd->cfg)) {
- res = FALSE;
- }
if (dump_vars) {
dump_cfg_vars (rspamd->cfg);
}
msg_info ("rspamd " RVERSION " is starting, build id: " RID);
rspamd->cfg->cfg_name = memory_pool_strdup (rspamd->cfg->cfg_pool, rspamd->cfg->cfg_name);
- (void)check_modules_config (rspamd->cfg);
+ /* Daemonize */
if (!rspamd->cfg->no_fork && daemon (0, 0) == -1) {
fprintf (stderr, "Cannot daemonize\n");
exit (-errno);
}
+ /* Write info */
rspamd->pid = getpid ();
rspamd->type = TYPE_MAIN;
event_init ();
g_mime_init (0);
+ /* Init lua filters */
+ if (! init_lua_filters (rspamd->cfg)) {
+ msg_err ("error loading lua plugins");
+ exit (EXIT_FAILURE);
+ }
+
+ /* Check configuration for modules */
+ (void)check_modules_config (rspamd->cfg);
+
/* Perform modules configuring */
l = g_list_first (rspamd->cfg->filters);
l = g_list_next (l);
}
- if (! init_lua_filters (rspamd->cfg)) {
- msg_err ("error loading lua plugins");
- exit (EXIT_FAILURE);
- }
-
+ /* Init config cache */
init_cfg_cache (rspamd->cfg);
+ /* Flush log */
flush_log_buf ();
+ /* Spawn workers */
rspamd->workers = g_hash_table_new (g_direct_hash, g_direct_equal);
spawn_workers (rspamd);
end
end
+-- Registration
+rspamd_config:register_module_option('forged_recipients', 'symbol_rcpt', 'string')
+rspamd_config:register_module_option('forged_recipients', 'symbol_sender', 'string')
+
-- Configuration
local opts = rspamd_config:get_all_opt('forged_recipients')
if opts then
task:insert_result(symbol, 1, 'subscribe.ru')
end
end
-
+-- Registration
+rspamd_config:register_module_option('maillist', 'symbol', 'string')
-- Configuration
local opts = rspamd_config:get_all_opt('maillist')
if opts then
return 1
end
+-- Registration
+rspamd_config:register_module_option('multimap', 'rule', 'string')
+
local opts = rspamd_config:get_all_opt('multimap')
if opts then
local strrules = opts['rule']
end
end
+-- Registration
+rspamd_config:register_module_option('once_received', 'symbol', 'string')
+rspamd_config:register_module_option('once_received', 'symbol_strict', 'string')
+rspamd_config:register_module_option('once_received', 'bad_host', 'string')
+rspamd_config:register_module_option('once_received', 'good_host', 'string')
+
-- Configuration
local opts = rspamd_config:get_all_opt('once_received')
if opts then
end
end
+-- Registration
+rspamd_config:register_module_option('phishing', 'symbol', 'string')
+rspamd_config:register_module_option('phishing', 'domains', 'map')
-local opts = rspamd_config:get_all_opt('phishing')
+local opts = rspamd_config:get_all_opt('phishing')
if opts then
if opts['symbol'] then
symbol = opts['symbol']
end
end
+-- Registration
+rspamd_config:register_module_option('received_rbl', 'symbol', 'string')
+rspamd_config:register_module_option('received_rbl', 'rbl', 'string')
+
-- Configuration
local opts = rspamd_config:get_all_opt('received_rbl')
if opts then
end
+-- Registration
+rspamd_config:register_module_option('whitelist', 'symbol_ip', 'string')
+rspamd_config:register_module_option('whitelist', 'symbol_from', 'string')
+rspamd_config:register_module_option('whitelist', 'ip_whitelist', 'map')
+rspamd_config:register_module_option('whitelist', 'from_whitelist', 'map')
-- Configuration
local opts = rspamd_config:get_all_opt('whitelist')