ze-filter  (ze-filter-0.8.0-develop-180218)
ze-ndc-help.c
Go to the documentation of this file.
1 
2 /*
3  *
4  * ze-filter - Mail Server Filter for sendmail
5  *
6  * Copyright (c) 2001-2018 - Jose-Marcio Martins da Cruz
7  *
8  * Auteur : Jose Marcio Martins da Cruz
9  * jose.marcio.mc@gmail.org
10  *
11  * Historique :
12  * Creation : Sun Mar 2 11:51:21 CET 2008
13  *
14  * This program is free software, but with restricted license :
15  *
16  *
17  * This program is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
20  *
21  * More details about ze-filter license can be found at ze-filter
22  * web site : http://foss.jose-marcio.org
23  */
24 
25 
26 #include <ze-sys.h>
27 #include <ze-filter.h>
28 #include <ze-ndc-help.h>
29 
30 /* ****************************************************************************
31  * *
32  * *
33  ******************************************************************************/
34 static bool show_help(int fd, char *hdr, char *str);
35 
36 typedef struct {
37  char *cmd;
38  char *desc;
39  char *str;
40 } ndc_help_T;
41 
42 static ndc_help_T helps[] = {
43  {
44  "help",
45  NULL,
46  " HELP\r\n" " * We can help you\r\n" " * Commands :\r\n"},
47 
48  {
49  "version",
50  NULL,
51  " VERSION\r\n"
52  " * Show filter version\r\n" " * Syntax :\r\n"
53  " ze-ndc VERSION\r\n"},
54 
55  {
56  "setcf",
57  NULL,
58  " SETCF\r\n"
59  " * Modify running configuration (overrides ze-filter values)\r\n"
60  " * Syntax :\r\n" " ze-ndc SETCF option value\r\n"},
61 
62  {
63  "dumpcf",
64  NULL,
65  " DUMPCF\r\n"
66  " * Dumps running configuration\r\n"
67  " * Syntax :\r\n" " ze-ndc DUMPCF option\r\n"
68  " option is one of :\r\n"
69  " default\r\n" " running\r\n" " short\r\n"},
70 
71  {
72  "setoracle",
73  NULL,
74  " SETORACLE\r\n"
75  " * Set heuristic filter (oracle) checks scores\r\n"
76  " * Syntax :\r\n"
77  " ze-ndc SETORACLE Tnn value\r\n"
78  " Where T is one of :\r\n"
79  " R : RBL Check\r\n"
80  " C : Connection check\r\n"
81  " M : Message check\r\n"
82  " H : HTML mime part check\r\n"
83  " P : Plain text mime part check\r\n"},
84 
85  {
86  "set",
87  NULL,
88  " SET\r\n"
89  " * Set the value of some internal variables\r\n"
90  " * Syntax :\r\n"
91  " ze-ndc SET variable value\r\n"
92  " Where variable can be one of :\r\n"
93  " LOGLEVEL\r\n"
94  " LOG_SM_MACROS\r\n" " MXCHECKLEVEL\r\n"
95 #if 0
96  " TLONGCONN\r\n"
97  " URLBLTIME\r\n"
98  " GREYDELAYS\r\n"
99  " GREYLIFETIME\r\n"
100  " GREYPENDING\r\n"
101  " GREYTUPLE\r\n"
102  " GREYCLEANUP\r\n" " GREY_DEWHITE_THRESHOLD\r\n"
103 #endif
104  },
105 
106  {
107  "bayes",
108  NULL,
109  " BAYES\r\n"
110  " * Reopen bayes filter database\r\n"
111  " * Syntax :\r\n"
112  " ze-ndc BAYES command parameter\r\n"
113  " Where command can be one of :\r\n" " REOPEN\r\n"},
114 
115 #if 0
116  {
117  "greydelete",
118  NULL,
119  " *" " * Syntax :\r\n" " ze-ndc \r\n"},
120 #endif
121 
122  {
123  "show",
124  NULL,
125  " SHOW\r\n"
126  " * Show internals\r\n"
127  " * Syntax :\r\n"
128  " ze-ndc SHOW select\r\n"
129  " Where select can be one of :\r\n"
130  " RUN : Running configuration\r\n"},
131 
132  {
133  "stats",
134  NULL,
135  " STATS\r\n"
136  " * Show internal statistics for this filter instance\r\n"
137  " * Syntax :\r\n"
138  " ze-ndc STATS select\r\n"
139  " Where select can be one of :\r\n"
140  " ORACLE : heuristic filter counters for this process\r\n"
141  " THROTTLE : show global server rates\r\n"
142  " SMTPRATE : show rates data for each client\r\n"
143  " CONNOPEN : show open connections\r\n"
144  " HTIMES : callback handling times\r\n"
145  " COUNTERS : show internal counters\r\n"
146  " SCORES : histogram of scores (regex + oracle)\r\n"
147  " ORASCORE : histogram of scores (oracle)\r\n"
148  " REGSCORE : histogram of scores (regex)\r\n"
149  " LIVEHISTORY : show short history blacklist\r\n"
150  " LIVEHISTORY_R : same as before with address resolution (slower)\r\n"},
151 
152  {
153  "reconfig",
154  NULL,
155  " RECONFIG\r\n"
156  " * Reload configuration files (ze-filter.cf)\r\n"
157  " * Syntax :\r\n" " ze-ndc RECONFIG\r\n"},
158 
159  {
160  "reload",
161  NULL,
162  " RELOAD\r\n"
163  " * Reload / Reopen tables databases or logfiles\r\n"
164  " * Syntax :\r\n"
165  " ze-ndc RELOAD select\r\n"
166  " Where select can be one of :\r\n"
167  " TABLES : \r\n"
168  " ze-regex\r\n"
169  " ze-oracle\r\n"
170  " ze-tables\r\n"
171  " ze-xfiles\r\n"
172  " DATABASES : \r\n"
173  " ze-rcpt.db\r\n"
174  " ze-policy.db\r\n"
175  " ze-urlbl.db\r\n"
176  " ze-bayes.db\r\n"
177  " LOGFILES : \r\n"
178  " ze-regex\r\n"
179  " ze-files\r\n"
180  " ze-virus\r\n"
181  " ze-quarantine\r\n"
182  " ze-stats\r\n"},
183 
184  {
185  "reopen",
186  NULL,
187  " REOPEN\r\n"
188  " * Reload / Reopen tables databases or logfiles\r\n"
189  " * Syntax :\r\n"
190  " ze-ndc REOPEN select\r\n"
191  " Where select can be one of :\r\n"
192  " TABLES : \r\n"
193  " ze-regex\r\n"
194  " ze-oracle\r\n"
195  " ze-tables\r\n"
196  " ze-xfiles\r\n"
197  " DATABASES : \r\n"
198  " ze-rcpt.db\r\n"
199  " ze-policy.db\r\n"
200  " ze-urlbl.db\r\n"
201  " ze-bayes.db\r\n"
202  " LOGFILES : \r\n"
203  " ze-regex_r\n"
204  " ze-files\r\n"
205  " ze-virus\r\n"
206  " ze-quarantine\r\n"
207  " ze-stats\r\n"},
208 
209  {
210  "reset",
211  NULL,
212  " RESET\r\n"
213  " * Reinitialize internal values\r\n"
214  " * Syntax :\r\n"
215  " ze-ndc RESET select\r\n"
216  " Where select can be one of :\r\n"
217  " STATS\r\n" " GREYERRORS\r\n"},
218 
219  {
220  "restart",
221  NULL,
222  " RESTART\r\n"
223  " * Restart the filter (soft restart)\r\n"
224  " * Syntax :\r\n" " ze-ndc RESTART\r\n"},
225 
226  {
227  NULL, NULL, NULL}
228 };
229 
230 static ndc_help_T *
231 get_help_rec(cmd, buf, sz)
232  char *cmd;
233  char *buf;
234  size_t sz;
235 {
236  ndc_help_T *p = NULL;
237  char s[32];
238 
239  for (p = helps; p->cmd != NULL; p++) {
240  if (p->cmd != NULL && STRCASEEQUAL(p->cmd, cmd)) {
241  snprintf(buf, sz, "%s", p->str);
242  if (!STRCASEEQUAL(p->cmd, "help"))
243  return p;
244  }
245  }
246 
247  for (p = helps; p->cmd != NULL; p++) {
248  snprintf(s, sizeof (s), " %s\r\n", p->cmd);
249  zeStr2Upper(s);
250  strlcat(buf, s, sz);
251  }
252 
253  return NULL;
254 }
255 
256 
257 /* ****************************************************************************
258  * *
259  * *
260  ******************************************************************************/
261 bool
262 ndc_help(fd, hdr, help, argc, argv)
263  int fd;
264  char *hdr;
265  bool help;
266  int argc;
267  char **argv;
268 {
269  char *str = NULL;
270  ndc_help_T *p = NULL;
271  char *cmd = "help";
272 
273  char buf[1024];
274 
275  if (argc > 0 && argv[0] != NULL)
276  cmd = argv[0];
277 
278  memset(buf, 0, sizeof (buf));
279  p = get_help_rec(cmd, buf, sizeof (buf));
280 
281  return show_help(fd, hdr, buf);
282 }
283 
284 /* ****************************************************************************
285  * *
286  * *
287  ******************************************************************************/
288 static bool
289 show_help(fd, hdr, str)
290  int fd;
291  char *hdr;
292  char *str;
293 {
294  if (!sd_printf(fd, "200 %s\r\n", PACKAGE))
295  goto ioerror;
296  if (hdr != NULL)
297  if (!sd_printf(fd, "%s\r\n", hdr))
298  goto ioerror;
299  if (!sd_printf(fd, "%s\r\n", str))
300  goto ioerror;
301  if (!sd_printf(fd, "200 OK !!\r\n"))
302  goto ioerror;
303 
304  return TRUE;
305 
306 ioerror:
307  return FALSE;
308 }
bool sd_printf(int sd, char *format,...)
Definition: ze-inet.c:629
#define FALSE
Definition: macros.h:160
char * str
Definition: ze-ndc-help.c:39
#define strlcat
Definition: zeString.h:28
char * desc
Definition: ze-ndc-help.c:38
#define TRUE
Definition: macros.h:157
char * cmd
Definition: ze-ndc-help.c:37
char * zeStr2Upper(char *)
Definition: zeStrings.c:312
#define PACKAGE
Definition: version.h:28
bool ndc_help(int fd, char *hdr, bool help, int argc, char **argv)
Definition: ze-ndc-help.c:262
#define STRCASEEQUAL(a, b)
Definition: macros.h:72