forked from allinurl/goaccess
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoptions.c
378 lines (346 loc) · 13 KB
/
options.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
/**
* options.c -- functions related to parsing program options
* Copyright (C) 2009-2014 by Gerardo Orellana <[email protected]>
* GoAccess - An Ncurses apache weblog analyzer & interactive viewer
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* A copy of the GNU General Public License is attached to this
* source distribution for its full text.
*
* Visit http://goaccess.prosoftcorp.com for new releases.
*/
#if HAVE_CONFIG_H
#include <config.h>
#endif
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <getopt.h>
#include <errno.h>
#ifdef HAVE_LIBTOKYOCABINET
#include "tcabinet.h"
#endif
#include "options.h"
#include "error.h"
#include "settings.h"
#include "util.h"
static char short_options[] = "f:e:p:o:"
#ifdef DEBUG
"l:"
#endif
#ifdef HAVE_LIBGEOIP
"g"
#endif
"acrmMhHqdsV";
/* *INDENT-OFF* */
struct option long_opts[] = {
{"agent-list" , no_argument , 0 , 'a' } ,
{"config-dialog" , no_argument , 0 , 'c' } ,
{"config-file" , required_argument , 0 , 'p' } ,
{"exclude-ip" , required_argument , 0 , 'e' } ,
{"help" , no_argument , 0 , 'h' } ,
{"http-method" , no_argument , 0 , 'M' } ,
{"http-protocol" , no_argument , 0 , 'H' } ,
{"log-file" , required_argument , 0 , 'f' } ,
{"version" , no_argument , 0 , 'V' } ,
#ifdef DEBUG
{"debug-file" , required_argument , 0 , 'l' } ,
#endif
{"color-scheme" , required_argument , 0 , 0 } ,
{"date-format" , required_argument , 0 , 0 } ,
{"ignore-crawlers" , no_argument , 0 , 0 } ,
{"log-format" , required_argument , 0 , 0 } ,
{"no-color" , no_argument , 0 , 0 } ,
{"no-global-config" , no_argument , 0 , 0 } ,
{"no-progress" , no_argument , 0 , 0 } ,
{"no-query-string" , no_argument , 0 , 'q' } ,
{"no-term-resolver" , no_argument , 0 , 'r' } ,
{"output-format" , required_argument , 0 , 'o' } ,
{"real-os" , no_argument , 0 , 0 } ,
{"static-file" , required_argument , 0 , 0 } ,
{"storage" , no_argument , 0 , 's' } ,
{"with-mouse" , no_argument , 0 , 'm' } ,
{"with-output-resolver" , no_argument , 0 , 'd' } ,
#ifdef HAVE_LIBGEOIP
{"std-geoip" , no_argument , 0 , 'g' } ,
{"geoip-city-data" , required_argument , 0 , 0 } ,
#endif
#ifdef TCB_BTREE
{"keep-db-files" , no_argument , 0 , 0 } ,
{"load-from-disk" , no_argument , 0 , 0 } ,
{"db-path" , required_argument , 0 , 0 } ,
{"compression" , required_argument , 0 , 0 } ,
{"xmmap" , required_argument , 0 , 0 } ,
{"cache-lcnum" , required_argument , 0 , 0 } ,
{"cache-ncnum" , required_argument , 0 , 0 } ,
{"tune-lmemb" , required_argument , 0 , 0 } ,
{"tune-nmemb" , required_argument , 0 , 0 } ,
{"tune-bnum" , required_argument , 0 , 0 } ,
#endif
{0, 0, 0, 0}
};
void
cmd_help (void)
{
printf ("\nGoAccess - %s\n\n", GO_VERSION);
printf (
"Usage: "
"goaccess [ options ... ] -f log_file [-c][-M][-H][-q][-d][...]\n"
"The following options can also be supplied to the command:\n\n"
/* Log & Date Format Options */
"Log & Date Format Options\n\n"
" --date-format=<dateformat> - Specify log date format.\n"
" --log-format=<logformat> - Specify log format. Inner quotes need\n"
" to be escaped.\n\n"
/* User Interface Options */
"User Interface Options\n\n"
" -c --config-dialog - Prompt log/date configuration window.\n"
" --color-scheme=<1|2> - Color schemes: 1 => Grey, 2 => Green.\n"
" --no-color - Disable colored output.\n\n"
/* File Options */
"File Options\n\n"
" -f --log-file=<filename> - Path to input log file.\n"
" -p --config-file=<filename> - Custom configuration file.\n"
#ifdef DEBUG
" -l --debug-file=<filename> - Send all debug messages to the\n"
" specified file.\n"
#endif
" --no-global-config - Don't load global configuration file.\n\n"
/* Parse Options */
"Parse Options\n\n"
" -a --agent-list - Enable a list of user-agents by host.\n"
" -d --with-output-resolver - Enable IP resolver on HTML|JSON output.\n"
" -H --http-protocol - Include HTTP request protocol if found.\n"
" -M --http-method - Include HTTP request method if found.\n"
" -m --with-mouse - Enable mouse support on main dashboard.\n"
" -o --output-format=csv|json - Output either a JSON or a CSV file.\n"
" -q --no-query-string - Ignore request's query string.\n"
" -r --no-term-resolver - Disable IP resolver on terminal output.\n"
" -e --exclude-ip=<IP> - Exclude one or multiple IPv4/6, includes\n"
" IP ranges. i.e., 192.168.0.1-192.168.0.10\n"
" --real-os - Display real OS names. e.g, Windows XP,\n"
" Snow Leopard.\n"
" --static-file=<extension> - Add static file extension. e.g.: .mp3\n"
" Extensions are case sensitive.\n"
" --ignore-crawlers - Ignore crawlers.\n"
" --no-progress - Disable progress metrics.\n\n"
/* GeoIP Options */
#ifdef HAVE_LIBGEOIP
"GeoIP Options\n\n"
" -g --std-geoip - Standard GeoIP database for less memory\n"
" usage.\n"
" --geoip-city-data=<path> - Specify path to GeoIP City database\n"
" file. i.e., GeoLiteCity.dat\n\n"
#endif
/* On-Disk Database Options */
#ifdef TCB_BTREE
"On-Disk Database Options\n\n"
" --keep-db-files - Persist parsed data into disk.\n"
" --load-from-disk - Load previously stored data from disk.\n"
" --db-path=<path> - Path of the database file. Default [%s]\n"
" --xmmap=<number> - Set the size in bytes of the extra\n"
" mapped memory. Default [%d]\n"
" --cache-lcnum=<number> - Max number of leaf nodes to be cached.\n"
" Default [%d]\n"
" --cache-ncnum=<number> - Max number of non-leaf nodes to be cached.\n"
" Default [%d]\n"
" --tune-lmemb=<number> - Number of members in each leaf page.\n"
" Default [%d]\n"
" --tune-nmemb=<number> - Number of members in each non-leaf page.\n"
" Default [%d]\n"
" --tune-bnum=<number> - Number of elements of the bucket array.\n"
" Default [%d]\n"
#if defined(HAVE_ZLIB) || defined(HAVE_BZ2)
" --compression=<zlib|bz2> - Specifies that each page is compressed\n"
" with ZLIB|BZ2 encoding.\n\n"
#endif
#endif
/* Other Options */
"Other Options\n\n"
" -h --help - This help.\n"
" -V --version - Display version information and exit.\n"
" -s --storage - Display current storage method.\n"
" i.e., B+ Tree, Hash.\n\n"
"Examples can be found by running `man goaccess`.\n\n"
"For more details visit: http://goaccess.io\n"
"GoAccess Copyright (C) 2009-2014 GNU GPL'd, by Gerardo Orellana"
"\n\n"
#ifdef TCB_BTREE
, TC_DBPATH, TC_MMAP, TC_LCNUM, TC_NCNUM, TC_LMEMB, TC_NMEMB, TC_BNUM
#endif
);
exit (EXIT_FAILURE);
}
/* *INDENT-ON* */
void
verify_global_config (int argc, char **argv)
{
int o, idx = 0;
conf.load_global_config = 1;
while ((o = getopt_long (argc, argv, short_options, long_opts, &idx)) >= 0) {
if (-1 == o || EOF == o)
break;
switch (o) {
case 'p':
conf.iconfigfile = optarg;
break;
case 0:
if (!strcmp ("no-global-config", long_opts[idx].name))
conf.load_global_config = 0;
break;
case '?':
exit (EXIT_FAILURE);
}
}
for (idx = optind; idx < argc; idx++)
cmd_help ();
/* reset it to 1 */
optind = 1;
}
void
read_option_args (int argc, char **argv)
{
int o, idx = 0;
#ifdef HAVE_LIBGEOIP
conf.geo_db = GEOIP_MEMORY_CACHE;
#endif
while ((o = getopt_long (argc, argv, short_options, long_opts, &idx)) >= 0) {
if (-1 == o || EOF == o)
break;
switch (o) {
case 'f':
conf.ifile = optarg;
break;
case 'p':
/* ignore it */
break;
#ifdef HAVE_LIBGEOIP
case 'g':
conf.geo_db = GEOIP_STANDARD;
break;
#endif
case 'e':
conf.ignore_ips[conf.ignore_ip_idx++] = optarg;
break;
case 'a':
conf.list_agents = 1;
break;
case 'c':
conf.load_conf_dlg = 1;
break;
case 'q':
conf.ignore_qstr = 1;
break;
case 'o':
conf.output_format = optarg;
case 'l':
conf.debug_log = optarg;
dbg_log_open (conf.debug_log);
break;
case 'r':
conf.skip_term_resolver = 1;
break;
case 'd':
conf.enable_html_resolver = 1;
break;
case 'm':
conf.mouse_support = 1;
break;
case 'M':
conf.append_method = 1;
break;
case 'h':
cmd_help ();
break;
case 'H':
conf.append_protocol = 1;
break;
case 'V':
display_version ();
exit (EXIT_SUCCESS);
break;
case 0:
if (!strcmp ("no-global-config", long_opts[idx].name))
break; /* ignore it */
if (!strcmp ("color-scheme", long_opts[idx].name))
conf.color_scheme = atoi (optarg);
if (!strcmp ("log-format", long_opts[idx].name))
conf.log_format = unescape_str (optarg);
if (!strcmp ("date-format", long_opts[idx].name))
conf.date_format = unescape_str (optarg);
if (!strcmp ("static-file", long_opts[idx].name)) {
if (conf.static_file_max_len < strlen (optarg))
conf.static_file_max_len = strlen (optarg);
conf.static_files[conf.static_file_idx++] = optarg;
}
if (!strcmp ("ignore-crawlers", long_opts[idx].name))
conf.ignore_crawlers = 1;
if (!strcmp ("real-os", long_opts[idx].name))
conf.real_os = 1;
if (!strcmp ("no-color", long_opts[idx].name))
conf.no_color = 1;
if (!strcmp ("no-progress", long_opts[idx].name))
conf.no_progress = 1;
/* specifies the path of the GeoIP City database file */
if (!strcmp ("geoip-city-data", long_opts[idx].name))
conf.geoip_city_data = optarg;
/* load data from disk */
if (!strcmp ("load-from-disk", long_opts[idx].name))
conf.load_from_disk = 1;
/* keep database files */
if (!strcmp ("keep-db-files", long_opts[idx].name))
conf.keep_db_files = 1;
/* specifies the path of the database file */
if (!strcmp ("db-path", long_opts[idx].name))
conf.db_path = optarg;
/* set the size in bytes of the extra mapped memory */
if (!strcmp ("xmmap", long_opts[idx].name))
conf.xmmap = atoi (optarg);
/* specifies the maximum number of leaf nodes to be cached */
if (!strcmp ("cache-lcnum", long_opts[idx].name))
conf.cache_lcnum = atoi (optarg);
/* specifies the maximum number of non-leaf nodes to be cached */
if (!strcmp ("cache-ncnum", long_opts[idx].name))
conf.cache_ncnum = atoi (optarg);
/* number of members in each leaf page */
if (!strcmp ("tune-lmemb", long_opts[idx].name))
conf.tune_lmemb = atoi (optarg);
/* number of members in each non-leaf page */
if (!strcmp ("tune-nmemb", long_opts[idx].name))
conf.tune_nmemb = atoi (optarg);
/* number of elements of the bucket array */
if (!strcmp ("tune-bnum", long_opts[idx].name))
conf.tune_bnum = atoi (optarg);
/* specifies that each page is compressed with X encoding */
if (!strcmp ("compression", long_opts[idx].name)) {
#ifdef HAVE_ZLIB
if (!strcmp ("zlib", optarg))
conf.compression = TC_ZLIB;
#endif
#ifdef HAVE_BZ2
if (!strcmp ("bz2", optarg))
conf.compression = TC_BZ2;
#endif
}
break;
case 's':
display_storage ();
exit (EXIT_SUCCESS);
case '?':
exit (EXIT_FAILURE);
default:
exit (EXIT_FAILURE);
}
}
for (idx = optind; idx < argc; idx++)
cmd_help ();
}