| 1 | /************************************************* |
| 2 | * Exim Monitor * |
| 3 | *************************************************/ |
| 4 | |
| 5 | /* Copyright (c) University of Cambridge 1995 - 2009 */ |
| 6 | /* See the file NOTICE for conditions of use and distribution. */ |
| 7 | |
| 8 | |
| 9 | /* This is the general header file for all the modules that comprise |
| 10 | the exim monitor program. */ |
| 11 | |
| 12 | /* If this macro is defined, Eximon will anonymize all email addresses. This |
| 13 | feature is just so that screen shots can be obtained for documentation |
| 14 | purposes! */ |
| 15 | |
| 16 | /* #define ANONYMIZE */ |
| 17 | |
| 18 | /* System compilation parameters */ |
| 19 | |
| 20 | #define queue_index_size 10 /* Size of index into queue */ |
| 21 | |
| 22 | /* Assume most systems have statfs() unless os.h undefines this macro */ |
| 23 | |
| 24 | #define HAVE_STATFS |
| 25 | |
| 26 | /* Bring in the system-dependent stuff */ |
| 27 | |
| 28 | #include "os.h" |
| 29 | |
| 30 | |
| 31 | /* ANSI C includes */ |
| 32 | |
| 33 | #include <ctype.h> |
| 34 | #include <setjmp.h> |
| 35 | #include <signal.h> |
| 36 | #include <stdarg.h> |
| 37 | #include <stdio.h> |
| 38 | #include <stdlib.h> |
| 39 | #include <string.h> |
| 40 | #include <time.h> |
| 41 | |
| 42 | /* Not-fully-ANSI systems (e.g. SunOS4 are missing some things) */ |
| 43 | |
| 44 | #ifndef SEEK_SET |
| 45 | #define SEEK_SET 0 |
| 46 | #define SEEK_CUR 1 |
| 47 | #define SEEK_END 2 |
| 48 | #endif |
| 49 | |
| 50 | /* Unix includes */ |
| 51 | |
| 52 | #include <sys/types.h> |
| 53 | #include <errno.h> |
| 54 | #include <dirent.h> |
| 55 | #include <fcntl.h> |
| 56 | #include <pwd.h> |
| 57 | #include <grp.h> |
| 58 | #include <sys/param.h> |
| 59 | #include <sys/stat.h> |
| 60 | #include <unistd.h> |
| 61 | |
| 62 | /* The new standard is statvfs; some OS have statfs. Also arrange |
| 63 | to be able to cut it out altogether for way-out OS that don't have |
| 64 | anything. */ |
| 65 | |
| 66 | #ifdef HAVE_STATFS |
| 67 | #ifdef HAVE_SYS_STATVFS_H |
| 68 | #include <sys/statvfs.h> |
| 69 | |
| 70 | #else |
| 71 | #define statvfs statfs |
| 72 | #ifdef HAVE_SYS_VFS_H |
| 73 | #include <sys/vfs.h> |
| 74 | #ifdef HAVE_SYS_STATFS_H |
| 75 | #include <sys/statfs.h> |
| 76 | #endif |
| 77 | #endif |
| 78 | #ifdef HAVE_SYS_MOUNT_H |
| 79 | #include <sys/mount.h> |
| 80 | #endif |
| 81 | #endif |
| 82 | #endif |
| 83 | |
| 84 | #include <sys/wait.h> |
| 85 | |
| 86 | /* Regular expression include */ |
| 87 | |
| 88 | #include <pcre.h> |
| 89 | |
| 90 | /* Includes from the main source of Exim. One of these days I should tidy up |
| 91 | this interface so that this kind of kludge isn't needed. */ |
| 92 | |
| 93 | #ifndef NS_MAXMSG |
| 94 | # define NS_MAXMSG 65535 |
| 95 | #endif |
| 96 | typedef void hctx; |
| 97 | |
| 98 | #include "local_scan.h" |
| 99 | #include "macros.h" |
| 100 | #include "structs.h" |
| 101 | #include "blob.h" |
| 102 | #include "globals.h" |
| 103 | #include "dbstuff.h" |
| 104 | #include "functions.h" |
| 105 | #include "osfunctions.h" |
| 106 | |
| 107 | /* The sys/resource.h header on SunOS 4 causes trouble with the gcc |
| 108 | compiler. Just stuff the bit we want in here; pragmatic easy way out. */ |
| 109 | |
| 110 | #ifdef NO_SYS_RESOURCE_H |
| 111 | #define RLIMIT_NOFILE 6 /* maximum descriptor index + 1 */ |
| 112 | struct rlimit { |
| 113 | int rlim_cur; /* current (soft) limit */ |
| 114 | int rlim_max; /* maximum value for rlim_cur */ |
| 115 | }; |
| 116 | #else |
| 117 | #include <sys/time.h> |
| 118 | #include <sys/resource.h> |
| 119 | #endif |
| 120 | |
| 121 | /* X11 includes */ |
| 122 | |
| 123 | #include <X11/Xlib.h> |
| 124 | #include <X11/Intrinsic.h> |
| 125 | #include <X11/StringDefs.h> |
| 126 | #include <X11/cursorfont.h> |
| 127 | #include <X11/keysym.h> |
| 128 | #include <X11/Shell.h> |
| 129 | #include <X11/Xaw/AsciiText.h> |
| 130 | #include <X11/Xaw/Command.h> |
| 131 | #include <X11/Xaw/Form.h> |
| 132 | #include <X11/Xaw/Dialog.h> |
| 133 | #include <X11/Xaw/Label.h> |
| 134 | #include <X11/Xaw/SimpleMenu.h> |
| 135 | #include <X11/Xaw/SmeBSB.h> |
| 136 | #include <X11/Xaw/SmeLine.h> |
| 137 | #include <X11/Xaw/TextSrc.h> |
| 138 | #include <X11/Xaw/TextSink.h> |
| 139 | |
| 140 | /* These are required because exim monitor has its own munged |
| 141 | version of the stripchart widget. */ |
| 142 | |
| 143 | #include <X11/IntrinsicP.h> |
| 144 | #include <X11/StringDefs.h> |
| 145 | #include <X11/Xaw/XawInit.h> |
| 146 | #include <X11/Xaw/StripCharP.h> |
| 147 | |
| 148 | extern WidgetClass mystripChartWidgetClass; |
| 149 | |
| 150 | |
| 151 | |
| 152 | /************************************************* |
| 153 | * Enumerations * |
| 154 | *************************************************/ |
| 155 | |
| 156 | /* Operations on the in-store message queue */ |
| 157 | |
| 158 | enum { queue_noop, queue_add }; |
| 159 | |
| 160 | /* Operations on the destinations queue */ |
| 161 | |
| 162 | enum { dest_noop, dest_add, dest_remove }; |
| 163 | |
| 164 | |
| 165 | /************************************************* |
| 166 | * Structure for destinations * |
| 167 | *************************************************/ |
| 168 | |
| 169 | typedef struct dest_item { |
| 170 | struct dest_item *next; |
| 171 | struct dest_item *parent; |
| 172 | uschar address[1]; |
| 173 | } dest_item; |
| 174 | |
| 175 | |
| 176 | |
| 177 | /************************************************* |
| 178 | * Structure for queue items * |
| 179 | *************************************************/ |
| 180 | |
| 181 | typedef struct queue_item { |
| 182 | struct queue_item *next; |
| 183 | struct queue_item *prev; |
| 184 | struct dest_item *destinations; |
| 185 | int input_time; |
| 186 | int update_time; |
| 187 | int size; |
| 188 | uschar *sender; |
| 189 | uschar name[17]; |
| 190 | uschar seen; |
| 191 | uschar frozen; |
| 192 | uschar dir_char; |
| 193 | } queue_item; |
| 194 | |
| 195 | |
| 196 | /************************************************* |
| 197 | * Structure for queue skip items * |
| 198 | *************************************************/ |
| 199 | |
| 200 | typedef struct skip_item { |
| 201 | struct skip_item *next; |
| 202 | time_t reveal; |
| 203 | uschar text[1]; |
| 204 | } skip_item; |
| 205 | |
| 206 | |
| 207 | /************************************************* |
| 208 | * Structure for delivery displays * |
| 209 | *************************************************/ |
| 210 | |
| 211 | typedef struct pipe_item { |
| 212 | struct pipe_item *next; |
| 213 | int fd; |
| 214 | Widget widget; |
| 215 | } pipe_item; |
| 216 | |
| 217 | |
| 218 | |
| 219 | /************************************************* |
| 220 | * Global variables * |
| 221 | *************************************************/ |
| 222 | |
| 223 | extern Display *X_display; /* Current display */ |
| 224 | extern XtAppContext X_appcon; /* Application context */ |
| 225 | extern XtActionsRec actionTable[]; /* Actions table */ |
| 226 | |
| 227 | extern XtTranslations queue_trans; /* translation table for queue text widget */ |
| 228 | extern XtTranslations text_trans; /* translation table for other text widgets */ |
| 229 | |
| 230 | extern Widget dialog_ref_widget; /* for positioning dialog box */ |
| 231 | extern Widget toplevel_widget; |
| 232 | extern Widget log_widget; /* widget for tail display */ |
| 233 | extern Widget queue_widget; /* widget for queue display */ |
| 234 | extern Widget unhide_widget; /* widget for unhide button */ |
| 235 | |
| 236 | extern FILE *LOG; |
| 237 | |
| 238 | extern int action_output; /* TRUE when wanting action command output */ |
| 239 | extern int action_queue_update; /* controls auto updates */ |
| 240 | extern int actionTableSize; /* # entries in actionTable */ |
| 241 | extern uschar actioned_message[]; /* For menu handling */ |
| 242 | extern uschar *action_required; |
| 243 | extern uschar *alternate_config; /* Alternate Exim configuration file */ |
| 244 | |
| 245 | extern int body_max; /* Max size of body to display */ |
| 246 | |
| 247 | extern int eximon_initialized; /* TRUE when initialized */ |
| 248 | |
| 249 | extern int log_buffer_size; /* size of log buffer */ |
| 250 | extern BOOL log_datestamping; /* TRUE if logs are datestamped */ |
| 251 | extern int log_depth; /* depth of log tail window */ |
| 252 | extern uschar *log_display_buffer; /* to hold display text */ |
| 253 | extern uschar *log_file; /* supplied name of exim log file */ |
| 254 | extern uschar log_file_open[256]; /* actual open file */ |
| 255 | extern uschar *log_font; /* font for log display */ |
| 256 | extern ino_t log_inode; /* the inode of the log file */ |
| 257 | extern long int log_position; /* position in log file */ |
| 258 | extern int log_width; /* width of log tail window */ |
| 259 | |
| 260 | extern uschar *menu_event; /* name of menu event */ |
| 261 | extern int menu_is_up; /* TRUE when menu displayed */ |
| 262 | extern int min_height; /* min window height */ |
| 263 | extern int min_width; /* min window width */ |
| 264 | |
| 265 | extern pipe_item *pipe_chain; /* for delivery displays */ |
| 266 | |
| 267 | extern uschar *qualify_domain; |
| 268 | extern int queue_depth; /* depth of queue window */ |
| 269 | extern uschar *queue_font; /* font for queue display */ |
| 270 | extern int queue_max_addresses; /* limit on per-message list */ |
| 271 | extern skip_item *queue_skip; /* for hiding bits of queue */ |
| 272 | extern uschar *queue_stripchart_name; /* sic */ |
| 273 | extern int queue_update; /* update interval */ |
| 274 | extern int queue_width; /* width of queue window */ |
| 275 | |
| 276 | extern pcre *yyyymmdd_regex; /* for matching yyyy-mm-dd */ |
| 277 | |
| 278 | extern uschar *size_stripchart; /* path for size monitoring */ |
| 279 | extern uschar *size_stripchart_name; /* name for size stripchart */ |
| 280 | extern uschar *spool_directory; /* Name of exim spool directory */ |
| 281 | extern int spool_is_split; /* True if detected split spool */ |
| 282 | extern int start_small; /* True to start with small window */ |
| 283 | extern int stripchart_height; /* height of stripcharts */ |
| 284 | extern int stripchart_number; /* number of stripcharts */ |
| 285 | extern pcre **stripchart_regex; /* vector of regexps */ |
| 286 | extern uschar **stripchart_title; /* vector of titles */ |
| 287 | extern int *stripchart_total; /* vector of accumulating values */ |
| 288 | extern int stripchart_update; /* update interval */ |
| 289 | extern int stripchart_width; /* width of stripcharts */ |
| 290 | extern int stripchart_varstart; /* starting number for variable charts */ |
| 291 | |
| 292 | extern int text_depth; /* depth of text windows */ |
| 293 | extern int tick_queue_accumulator; /* For timing next auto update */ |
| 294 | |
| 295 | extern uschar *window_title; /* title of the exim monitor window */ |
| 296 | |
| 297 | |
| 298 | /************************************************* |
| 299 | * Global functions * |
| 300 | *************************************************/ |
| 301 | |
| 302 | extern XtActionProc dialogAction(Widget, XEvent *, String *, Cardinal *); |
| 303 | |
| 304 | extern uschar *copystring(uschar *); |
| 305 | extern void create_dialog(uschar *, uschar *); |
| 306 | extern void create_stripchart(Widget, uschar *); |
| 307 | extern void debug(char *, ...); |
| 308 | extern dest_item *find_dest(queue_item *, uschar *, int, BOOL); |
| 309 | extern queue_item *find_queue(uschar *, int, int); |
| 310 | extern void init(int, uschar **); |
| 311 | extern void menu_create(Widget, XEvent *, String *, Cardinal *); |
| 312 | extern void NonMessageDialogue(uschar *); |
| 313 | extern void queue_display(void); |
| 314 | extern void read_log(void); |
| 315 | extern int read_spool(uschar *); |
| 316 | extern int read_spool_init(uschar *); |
| 317 | extern void read_spool_tidy(void); |
| 318 | extern int repaint_window(StripChartWidget, int, int); |
| 319 | extern void scan_spool_input(int); |
| 320 | extern void stripchart_init(void); |
| 321 | extern void text_empty(Widget); |
| 322 | extern void text_show(Widget, uschar *); |
| 323 | extern void text_showf(Widget, char *, ...); |
| 324 | extern void xs_SetValues(Widget, Cardinal, ...); |
| 325 | |
| 326 | /* End of em_hdr.h */ |