34 #define STATE_FILE "ze-state" 44 0, PTHREAD_MUTEX_INITIALIZER};
47 #define SCORE_LOCK() MUTEX_LOCK(&msg_score.mutex) 48 #define SCORE_UNLOCK() MUTEX_UNLOCK(&msg_score.mutex) 65 bay_sc = scores->
bayes;
66 msg_sc = reg_sc + ora_sc;
70 if (msg_score.nb == 0) {
71 memset(msg_score.ora, 0, sizeof (msg_score.ora));
72 memset(msg_score.reg, 0, sizeof (msg_score.reg));
73 memset(msg_score.msg, 0, sizeof (msg_score.msg));
74 memset(msg_score.bay, 0, sizeof (msg_score.bay));
77 if (msg_sc >= 0 || bay_sc >= 0.75) {
86 if (bay_sc <= MAX_SCORE)
89 msg_score.bay[MAX_SCORE + 1]++;
91 if (msg_sc <= MAX_SCORE)
92 msg_score.msg[msg_sc]++;
94 msg_score.msg[MAX_SCORE + 1]++;
96 if (ora_sc <= MAX_SCORE)
97 msg_score.ora[ora_sc]++;
99 msg_score.ora[MAX_SCORE + 1]++;
101 if (reg_sc <= MAX_SCORE)
102 msg_score.reg[reg_sc]++;
104 msg_score.reg[MAX_SCORE + 1]++;
136 v = msg_score.msg[i];
139 v = msg_score.reg[i];
142 v = msg_score.ora[i];
145 v = msg_score.bay[i];
154 FD_PRINTF(fd,
"\nMESSAGES : %7d\n", cnt);
158 for (i = 0; i < MAX_SCORE + 2; i++) {
162 v = msg_score.msg[i];
165 v = msg_score.reg[i];
168 v = msg_score.ora[i];
171 v = msg_score.bay[i];
179 memset(sout, 0,
sizeof (sout));
180 memset(sout,
' ', 51);
182 memset(sout,
'.', (50 * sum) / cnt);
183 for (j = 0; j < 51; j += 10)
186 sout[(50 * sum) / cnt] =
'X';
187 FD_PRINTF(fd,
" %4d : %7d %s\n", i, v, sout);
202 static pthread_mutex_t st_mutex = PTHREAD_MUTEX_INITIALIZER;
204 #define STATS_LOCK() MUTEX_LOCK(&st_mutex) 205 #define STATS_UNLOCK() MUTEX_UNLOCK(&st_mutex) 212 fill_counters_buffer(buf, bufsz)
217 time_t now = time(NULL);
222 memset(str, 0,
sizeof (str));
224 snprintf(str,
sizeof (str),
"%12lld ", (
long long) now);
226 snprintf(str,
sizeof (str),
"RESTART=(%lld) ",
229 snprintf(str,
sizeof (str),
"CONN=(%lld) ",
232 snprintf(str,
sizeof (str),
"ABRT=(%lld) ",
235 snprintf(str,
sizeof (str),
"MSGS=(%lld) ",
238 snprintf(str,
sizeof (str),
"KBYTES=(%lld) ",
241 snprintf(str,
sizeof (str),
"RCPT=(%lld) ",
244 snprintf(str,
sizeof (str),
"FILES=(%lld) ",
247 snprintf(str,
sizeof (str),
"XFILES=(%lld) ",
250 snprintf(str,
sizeof (str),
"RCPTRATE=(%lld) ",
253 snprintf(str,
sizeof (str),
"THROTTLE=(%lld) ",
256 snprintf(str,
sizeof (str),
"OPENCONN=(%lld) ",
259 snprintf(str,
sizeof (str),
"BADRCPT=(%lld) ",
262 snprintf(str,
sizeof (str),
"SPAMTRAP=(%lld) ",
265 snprintf(str,
sizeof (str),
"LOCALUSER=(%lld) ",
268 snprintf(str,
sizeof (str),
"RESFAIL=(%lld) ",
271 snprintf(str,
sizeof (str),
"RESFORG=(%lld) ",
274 snprintf(str,
sizeof (str),
"MATCHING=(%lld) ",
277 snprintf(str,
sizeof (str),
"ORACLE=(%lld) ",
280 snprintf(str,
sizeof (str),
"URLBL=(%lld) ",
283 snprintf(str,
sizeof (str),
"BAYESSPAM=(%lld) ",
286 snprintf(str,
sizeof (str),
"BAYESHAM=(%lld) ",
290 snprintf(str,
sizeof (str),
"VIRUS=(%lld) ",
293 snprintf(str,
sizeof (str),
"POLICY=(%lld) ",
298 snprintf(str,
sizeof (str),
"BADMX=(%lld) ",
303 snprintf(str,
sizeof (str),
"GREYMSGS=(%lld) ",
308 snprintf(str,
sizeof (str),
"GREYRCPT=(%lld) ",
334 time_t now = time(NULL);
343 memset(buf, 0,
sizeof (buf));
344 snprintf(buf,
sizeof (buf),
"DATA ");
345 if (fill_counters_buffer(buf,
sizeof (buf)))
353 if (wkdir == NULL || strlen(wkdir) == 0)
360 if (strlen(path) == 0) {
368 memset(buf, 0,
sizeof (buf));
369 if (fill_counters_buffer(buf,
sizeof (buf)))
383 time_t now = time(NULL);
387 memset(&m_stats, 0,
sizeof (m_stats));
433 time_t now = time(NULL);
440 if (wkdir == NULL || strlen(wkdir) == 0)
445 if (strlen(path) == 0) {
450 if ((fd = open(path, O_WRONLY | O_CREAT, 00644)) >= 0) {
455 if (write(fd, &m_stats,
sizeof (m_stats)) !=
sizeof (m_stats))
477 if (wkdir == NULL || strlen(wkdir) == 0)
482 if (strlen(path) == 0) {
487 if ((fd = open(path, O_RDONLY)) >= 0) {
489 if (read(fd, &m_stats,
sizeof (m_stats)) !=
sizeof (m_stats))
504 time_t now = time(NULL);
513 memset(&m_stats.
proc, 0, sizeof (m_stats.
proc));
530 time_t now = time(NULL);
534 memset(&m_stats, 0,
sizeof (m_stats));
560 if (wkdir == NULL || strlen(wkdir) == 0)
565 if (strlen(path) == 0) {
573 if ((fd = open(path, O_RDONLY)) >= 0) {
574 if (read(fd, &st,
sizeof (st)) ==
sizeof (st)) {
584 FD_PRINTF(ofd,
"%-30s : %s\n",
"Start", out);
585 FD_PRINTF(ofd,
"%-30s : %ld\n",
"# Start-up",
592 FD_PRINTF(ofd,
"%-30s : %ld\n",
"# Attached files",
596 FD_PRINTF(ofd,
"%-30s : %ld\n",
"# Reject Local Users",
598 FD_PRINTF(ofd,
"%-30s : %ld\n",
"# Reject No RCPT Headers",
600 FD_PRINTF(ofd,
"%-30s : %ld\n",
"# Reject No Senders ",
602 FD_PRINTF(ofd,
"%-30s : %ld\n",
"# Reject Exceed Max RCPT",
609 FD_PRINTF(ofd,
"%-30s : %s\n",
"Start", out);
610 FD_PRINTF(ofd,
"%-30s : %ld\n",
"# Start-up",
617 FD_PRINTF(ofd,
"%-30s : %ld\n",
"# Attached files",
621 FD_PRINTF(ofd,
"%-30s : %ld\n",
"# Reject Local Users",
623 FD_PRINTF(ofd,
"%-30s : %ld\n",
"# Reject No RCPT Headers",
625 FD_PRINTF(ofd,
"%-30s : %ld\n",
"# Reject No Senders ",
627 FD_PRINTF(ofd,
"%-30s : %ld\n",
"# Reject Exceed Max RCPT",
631 FD_PRINTF(ofd,
"Error reading %s file : %s\n", path, strerror(errno));
635 FD_PRINTF(ofd,
"Error opening %s file : %s\n", path, strerror(errno));
652 static CODE stat_names[] = {
660 "KBytes transfered"},
680 "Cumulative # RCPT"},
688 "Attached unsafe files"},
696 "Msgs sent to intranet users"},
700 "No To or CC headers"},
708 "No headers at all"},
712 "Gateways without DNS resolution"},
716 "Gateways with forged DNS names"},
720 "Msgs exceeding allowed # of recipients"},
724 "Hosts exceeding allowed recipient rate"},
728 "Hosts exceeding allowed connection rate"},
732 "Hosts exceeding allowed open connections"},
736 "Hosts doing too much empty connections"},
744 "Forbidden subject contents (regex)"},
748 "Forbiden body contents (regex)"},
752 "Binary encoded message body"},
756 "BASE 64 encoded message body"},
760 "Quoted-printable message body"},
764 "Message violating site policy"},
768 "Sender address has BAD MX"},
772 "Recipient delayed by greylisting"},
776 "Message delayed by greylisting"},
785 CODE *p = stat_names;
791 if (code == p->
c_val)
820 if ((p =
strchr(out,
'\n')) != NULL)
822 FD_PRINTF(ofd,
"%c %-30s : %s\n", c,
"Start", out);
827 FD_PRINTF(ofd,
"%c %-30s : %10lu\n", c,
"# KBytes",
833 FD_PRINTF(ofd,
"%c %-30s : %10ld\n", c,
"# ENV RCPT",
836 FD_PRINTF(ofd,
"%c %-30s : %10ld\n", c,
"# Attached files",
839 FD_PRINTF(ofd,
"%c %-30s : %10ld\n", c,
"# X-Files",
844 FD_PRINTF(ofd,
"%c %-30s : %10ld\n", c,
"# Reject Local Users",
847 FD_PRINTF(ofd,
"%c %-30s : %10ld\n", c,
"# Reject No RCPT Headers",
850 FD_PRINTF(ofd,
"%c %-30s : %10ld\n", c,
"# Reject No Senders ",
853 FD_PRINTF(ofd,
"%c %-30s : %10ld\n", c,
"# Reject Exceed Max RCPT",
856 FD_PRINTF(ofd,
"%c %-30s : %10ld\n", c,
"# Reject Exceed rcpt rate",
859 FD_PRINTF(ofd,
"%c %-30s : %10ld\n", c,
"# Reject Exceed conn rate",
862 FD_PRINTF(ofd,
"%c %-30s : %10ld\n", c,
"# Resolve FAIL",
865 FD_PRINTF(ofd,
"%c %-30s : %10ld\n", c,
"# Resolve FORGED",
868 FD_PRINTF(ofd,
"%c %-30s : %10ld\n", c,
"# Sender with bad MX",
892 if ((p =
strchr(out,
'\n')) != NULL)
894 FD_PRINTF(ofd,
"\n%-30s %s\n", titlea, out);
897 if ((p =
strchr(out,
'\n')) != NULL)
899 FD_PRINTF(ofd,
"%-30s %s\n", titleb, out);
923 FD_PRINTF(ofd,
"# %-40s : %10ld %10ld\n",
925 FD_PRINTF(ofd,
"# %-40s : %10ld %10ld\n",
929 FD_PRINTF(ofd,
"# %-40s : %10ld %10ld\n",
933 FD_PRINTF(ofd,
"# %-40s : %10ld %10ld\n",
937 FD_PRINTF(ofd,
"# %-40s : %10ld %10ld\n",
940 FD_PRINTF(ofd,
"# %-40s : %10ld %10ld\n",
943 FD_PRINTF(ofd,
"# %-40s : %10ld %10ld\n",
947 FD_PRINTF(ofd,
"# %-40s : %10ld %10ld\n",
948 "Reject Exceed Max RCPT",
951 FD_PRINTF(ofd,
"# %-40s : %10ld %10ld\n",
952 "Reject Exceed Throttle",
955 FD_PRINTF(ofd,
"# %-40s : %10ld %10ld\n",
956 "Reject Exceed Conn Rate",
959 FD_PRINTF(ofd,
"# %-40s : %10ld %10ld\n",
964 FD_PRINTF(ofd,
"# %-40s : %10ld %10ld\n",
"Message per connection limit",
970 FD_PRINTF(ofd,
"# %-40s : %10ld %10ld\n",
"Recipient - - REJECT",
975 FD_PRINTF(ofd,
"# %-40s : %10ld %10ld\n",
"Recipient - ACCESS DENIED",
980 FD_PRINTF(ofd,
"# %-40s : %10ld %10ld\n",
981 "Recipient - BAD_NETWORK",
987 FD_PRINTF(ofd,
"# %-40s : %10ld %10ld\n",
"Recipient - USER UNKNOWN",
992 FD_PRINTF(ofd,
"# %-40s : %10ld %10ld\n",
"Recipient - SPAMTRAP",
996 FD_PRINTF(ofd,
"# %-40s : %10ld %10ld\n",
997 "Connections from harvesters",
1001 FD_PRINTF(ofd,
"# %-40s : %10ld %10ld\n",
1002 "Recipients delayed by greylisting",
1005 FD_PRINTF(ofd,
"# %-40s : %10ld %10ld\n",
1006 "Messages delayed by greylisting",
1010 FD_PRINTF(ofd,
"# %-40s : %10ld %10ld\n",
"Resolve FAIL",
1014 FD_PRINTF(ofd,
"# %-40s : %10ld %10ld\n",
"Resolve FORGED",
1019 FD_PRINTF(ofd,
"# %-40s : %10ld %10ld\n",
"Reject No RCPT Headers",
1023 FD_PRINTF(ofd,
"# %-40s : %10ld %10ld\n",
"Reject No Senders ",
1028 FD_PRINTF(ofd,
"# %-40s : %10ld %10ld\n",
"Reject pattern matching",
1032 FD_PRINTF(ofd,
"# %-40s : %10ld %10ld\n",
"Reject URL BL",
1035 FD_PRINTF(ofd,
"# %-40s : %10ld %10ld\n",
"Detected by heuristic filter",
1039 FD_PRINTF(ofd,
"# %-40s : %10ld %10ld\n",
"Detected by bayes filter",
1043 FD_PRINTF(ofd,
"# %-40s : %10ld %10ld\n",
"Reject subject contents",
1048 FD_PRINTF(ofd,
"# %-40s : %10ld %10ld\n",
"Reject headers contents",
1052 FD_PRINTF(ofd,
"# %-40s : %10ld %10ld\n",
1053 "Reject binary encoded body",
1056 FD_PRINTF(ofd,
"# %-40s : %10ld %10ld\n",
1057 "Reject base 64 encoded body",
1061 FD_PRINTF(ofd,
"# %-40s : %10ld %10ld\n",
1062 "Reject quoted printable encoded body",
1090 if (wkdir == NULL || strlen(wkdir) == 0)
1095 if (strlen(path) == 0) {
1101 ofd = STDOUT_FILENO;
1103 if ((fd = open(path, O_RDONLY)) >= 0) {
1104 if (read(fd, &st,
sizeof (st)) ==
sizeof (st)) {
1112 if ((p =
strchr(out,
'\n')) != NULL)
1114 FD_PRINTF(ofd,
"%-30s : %s\n",
"Last counters dump", out);
1127 "*** PROCESSUS DATA ***",
1128 &st.
glob,
"*** GLOBAL DATA ***", all, nf);
1155 char *title =
"*** PROCESSUS DATA ***";
1164 if ((p =
strchr(out,
'\n')) != NULL)
1192 ZE_MessageInfo(9,
"%c %-30s : %10ld", c,
"# Reject No RCPT Headers",
1198 ZE_MessageInfo(9,
"%c %-30s : %10ld", c,
"# Reject Exceed Max RCPT",
1201 ZE_MessageInfo(9,
"%c %-30s : %10ld", c,
"# Reject Exceed rcpt rate",
1204 ZE_MessageInfo(9,
"%c %-30s : %10ld", c,
"# Reject Exceed conn rate",
void print_filter_stats_summary()
bool log_write(LOG_T *, char *)
bool log_counters_reopen()
#define STAT_NO_FROM_HEADERS
#define STAT_SINGLE_MESSAGE
void print_p_stats_all(int ofd, p_stats_T *sta, char *titlea, p_stats_T *stb, char *titleb, int all, bool nf)
void msg_score_stats_print(int fd, int which)
#define ZE_LogMsgError(level,...)
#define ADJUST_FILENAME(path, fname, cfdir, defval)
#define STAT_NO_TO_HEADERS
#define FD_PRINTF(fdp,...)
void log_counters(int fd, bool dump)
#define STAT_PATTERN_MATCHING
int dump_state(int ofd, int jp, int jg, int all, bool nf)
#define CF_SCANNER_ACTION
void stats_inc(int which, long n)
#define STAT_QUOTED_PRINTABLE
#define ZE_MessageInfo(level,...)
#define log_check_and_open(log, name)
#define STAT_RCPT_UNKNOWN
#define STAT_RESOLVE_FAIL
#define ZE_LogSysError(...)
void print_p_stats(int ofd, p_stats_T *st, char *title, int c, int all)
char * cf_get_str(int id)
void msg_score_stats_update(msg_scores_T *scores)
#define STAT_SUBJECT_CONTENTS
#define STAT_RCPT_BAD_NETWORK
#define STAT_HEADERS_CONTENTS
#define STAT_RESOLVE_FORGED
#define STAT_RCPT_SPAMTRAP
#define ADJUST_LOG_NAME(path, fname, dir, defval)
char * stats_title(int code)