forked from allinurl/goaccess
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommons.c
289 lines (269 loc) · 11 KB
/
commons.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
/**
* commons.c -- holds different data types
* Copyright (C) 2010 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.
*/
#include <curses.h>
#include <time.h>
#include <glib.h>
#include "commons.h"
#define COL_WHITE 0
#define COL_BLUE 1
#define COL_GREEN 11
#define COL_RED 3
#define COL_BLACK 4
#define COL_CYAN 5
#define COL_YELLOW 6
#define BLUE_GREEN 7
#define BLACK_GREEN 8
#define BLACK_CYAN 9
#define WHITE_RED 10
/* Definitions checked against declarations */
GHashTable *ht_unique_visitors = NULL;
GHashTable *ht_requests = NULL;
GHashTable *ht_referrers = NULL;
GHashTable *ht_unique_vis = NULL;
GHashTable *ht_requests_static = NULL;
GHashTable *ht_not_found_requests = NULL;
GHashTable *ht_os = NULL;
GHashTable *ht_browsers = NULL;
GHashTable *ht_hosts = NULL;
GHashTable *ht_status_code = NULL;
GHashTable *ht_referring_sites = NULL;
GHashTable *ht_keyphrases = NULL;
GHashTable *ht_file_bw = NULL;
enum MODULES modules;
/* enable flags */
int ignore_flag = 0;
int stripped_flag = 0;
int bandwidth_flag = 0;
long long req_size = 0;
int http_status_code_flag = 0;
/* string processing */
char *req;
char *status_code;
char *ignore_host;
/* Processing time */
time_t now;
time_t end_proc;
time_t start_proc;
/* resizing */
size_t term_h = 0;
size_t term_w = 0;
size_t real_size_y = 0;
/* file */
char *ifile = NULL;
char *module_names[] = {
" Visitors - ^s^ sort by date - ^S^ sort by hits",
" Requests sorted by hits",
" Static Requests sorted by hits",
" Referrers sorted by hits",
" 404 - Not Found sorted by hits",
" Operating Systems sorted by unique visitors",
" Browsers sorted by unique visitors",
" Hosts sorted by hits",
" HTTP Status Codes sorted by hits",
" Top Referring Sites sorted by hits",
" Top Search Keyphrases (Google, Cache, Translate)"
};
/* {"search string", "belongs to"} */
char *os[][2] = {
/* WINDOWS PLATFORM TOKENS */
{"Windows NT 5.1", "Windows"}, {"Windows NT 6.0", "Windows"},
{"Windows NT 6.1", "Windows"}, {"Windows NT 5.01", "Windows"},
{"Windows NT 5.0", "Windows"}, {"Windows NT 4.0", "Windows"},
{"Win 9x 4.90", "Windows"}, {"Windows 98", "Windows"},
{"Windows 95", "Windows"}, {"Windows CE", "Windows"},
/* LINUX, MAC & OTHERS */
{"Debian", "Linux"}, {"Ubuntu", "Linux"}, {"Fedora", "Linux"},
{"Mint", "Linux"}, {"SUSE", "Linux"}, {"Mandriva", "Linux"},
{"Red Hat", "Linux"}, {"Gentoo", "Linux"}, {"CentOS", "Linux"},
{"Android", "Linux"}, {"PCLinuxOS", "Linux"}, {"Linux", "Linux"},
{"iPad", "Macintosh"}, {"iPhone", "Macintosh"}, {"iPod", "Macintosh"},
{"iTunes", "Macintosh"}, {"Mac OS X", "Macintosh"},
{"Mac OS", "Macintosh"}, {"FreeBSD", "BSD"}, {"NetBSD", "BSD"},
{"OpenBSD", "BSD"}, {"SunOS", "Others"}, {"AmigaOS", "Others"},
{"BlackBerry", "Others"}, {"Symbian OS", "Others"}, {"Xbox", "Others"},
{"Nokia", "Others"}, {"PlayStation", "Others"}
};
/* {"search string", "belongs to"} */
char *browsers[][2] = {
/* BROWSERS & OFFLINE BROWSERS */
{"Avant Browser", "Others"},
{"America Online Browser", "Others"},
{"MSIE 6.", "MSIE"}, {"MSIE 7.", "MSIE"}, {"MSIE 8.", "MSIE"},
{"MSIE 5.", "MSIE"}, {"MSIE 4.", "MSIE"},
{"Flock", "Others"}, {"Epiphany", "Others"},
{"SeaMonkey", "Others"}, {"Iceweasel", "Others"},
{"Minefield", "Others"}, {"GranParadiso", "Others"},
{"Firefox", "Firefox"}, {"Chrome", "Chrome"}, {"Safari", "Safari"},
{"Opera Mini", "Opera"}, {"Opera", "Opera"}, {"Netscape", "Others"},
{"Konqueror", "Others"}, {"Wget", "Others"}, {"w3m", "Others"},
{"Links", "Others"}, {"Lynx", "Others"},
{"Camino", "Others"}, {"Dillo", "Others"}, {"Kazehakase", "Others"},
{"Iceape", "Others"}, {"K-Meleon", "Others"}, {"Galeon", "Others"},
{"BrowserX", "Others"}, {"ELinks", "Others"}, {"IBrowse", "Others"},
{"Mosaic", "Others"}, {"midori", "Others"}, {"Midori", "Others"},
{"Firebird", "Others"},
/* CRAWLERS & VALIDATORS */
{"W3C_Validator", "Crawlers"},
{"W3C_CSS_Validator", "Crawlers"}, {"facebook", "Crawlers"},
{"msnbot-media", "Crawlers"}, {"msnbot", "Crawlers"},
{"ia_archiver", "Crawlers"}, {"Mediapartners-Google", "Crawlers"},
{"Googlebot-Image", "Crawlers"}, {"Googlebot", "Crawlers"},
{"slurp", "Crawlers"}, {"Baiduspider", "Crawlers"},
{"YandexBot", "Crawlers"}, {"FeedFetcher-Google", "Crawlers"},
{"Speedy Spider", "Crawlers"}, {"Java", "Crawlers"},
{"Gigabot", "Crawlers"}, {"Twiceler", "Crawlers"},
{"YoudaoBot", "Crawlers"}, {"Turnitin", "Crawlers"},
{"Ask Jeeves", "Crawlers"}, {"Exabot", "Crawlers"},
{"archive.org_bot", "Crawlers"}, {"Google-Sitemaps", "Crawlers"},
{"PostRank", "Crawlers"}, {"KaloogaBot", "Crawlers"},
{"Twitter", "Crawlers"}, {"yacy", "Crawlers"}, {"Nutch", "Crawlers"},
{"ichiro", "Crawlers"}, {"Sogou", "Crawlers"},
{"KaloogaBot", "Crawlers"}, {"Mozilla", "Others"}
};
char *codes[][2] = {
{"100", "Continue - Server has received the request headers"},
{"101", "Switching Protocols - Client asked to switch protocols"},
{"200", "OK - The request sent by the client was successful"},
{"201", "Created - The request has been fulfilled and created"},
{"202", "Accepted - The request has been accepted for processing"},
{"203", "Non-Authoritative Information"},
{"204", "No Content - Request is not returning any content"},
{"205", "Reset Content - User-Agent should reset the document"},
{"206", "Partial Content - The partial GET has been successful"},
{"300", "Multiple Choices - Multiple options for the resource"},
{"301", "Moved Permanently - Resource has permanently moved"},
{"302", "Moved Temporarily"},
{"303", "See Other - The response is at a different URI"},
{"304", "Not Modified - Resource has not been modified"},
{"305", "Use Proxy - Can only be accessed through the proxy"},
{"307", "Temporary Redirect - Resource temporarily moved"},
{"400", "Bad Request - The syntax of the request is invalid"},
{"401", "Unauthorized - Request needs user authentication"},
{"402", "Payment Required"},
{"403", "Forbidden - Server is refusing to respond to it"},
{"404", "Document Not Found - Requested resource could not be found"},
{"405", "Method Not Allowed - Request method not supported"},
{"406", "Not Acceptable"},
{"407", "Proxy Authentication Required"},
{"408", "Request Timeout - The server timed out waiting for the request"},
{"409", "Conflict - Conflict in the request"},
{"410", "Gone - Resource requested is no longer available"},
{"411", "Length Required - Invalid Content-Length"},
{"412", "Precondition Failed - Server does not meet preconditions"},
{"413", "Request entity Too Long"},
{"414", "Request-URI Too Long"},
{"415", "Unsupported Media Type - Media type is not supported"},
{"416", "Requested Range Not Satisfiable - Cannot supply that portion"},
{"417", "Expectation Failed"},
{"500", "Internal Server Error"},
{"501", "Not Implemented"},
{"502", "Bad Gateway - Received an invalid response from the upstream"},
{"503", "Service Unavailable - The server is currently unavailable"},
{"504", "Gateway Timeout - The upstream server failed to send request"},
{"505", "HTTP Version Not Supported"}
};
char *help_main[] = {
"Copyright (C) 2010",
"by Gerardo Orellana <[email protected]>",
"http://goaccess.prosoftcorp.com",
"Released under the GNU GPL. See `man` page for",
"more details.",
"",
"GoAccess is an open source and real-time Apache",
"web log analyzer that provides fast and valuable",
"HTTP statistics for system administrators that ",
"require a visual and interactive report on the fly.",
"",
"The data collected based on the parsing of the log",
"is divided into different modules. Modules are",
"automatically generated and presented to the user.",
"",
"The main window displays general statistics, top ",
"visitors, requests, browsers, operating systems,",
"hosts, etc.",
"",
"The user can make use of the following keys:",
" ^F1^ or ^CTRL^ + ^h^ [main help]",
" ^F5^ redraw [main window]",
" ^q^ quit the program/current window",
" ^o^ open detail view for selected module",
" ^RIGHT ARROW^ open detail view for selected",
" module",
" ^TAB^ iterate modules (forward)",
" ^SHIFT^ + ^TAB^ iterate modules (backward)",
" ^0-9^ select module so the user can open a",
" [detail view] with either ^o^ or",
" ^RIGHT ARROW^",
" ^SHIFT^ + ^0-9^ select module above 10",
" ^s^ [detail view] sort unique visitors by date",
" ^S^ [detail view] sort unique visitors by hits",
" ^/^ [detail view] search forward for the ",
" occurrence of pattern",
" ^n^ detail view - find the position of the next",
" occurrence",
" ^t^ [detail view] move to the first item",
" ^b^ [detail view] move to the last item",
"",
"If you believe you have found a bug, please drop me",
"an email with details.",
"",
"If you have a medium or high traffic website, it",
"would be interesting to hear your experience with",
"GoAccess, such as generating time, visitors or hits.",
"",
"Feedback? Just shoot me an email to:",
};
void
init_colors (void)
{
use_default_colors ();
init_pair (COL_BLUE, COLOR_BLUE, -1);
init_pair (COL_GREEN, COLOR_GREEN, -1);
init_pair (COL_RED, COLOR_RED, -1);
init_pair (COL_BLACK, COLOR_BLACK, -1);
init_pair (COL_CYAN, COLOR_CYAN, -1);
init_pair (COL_YELLOW, COLOR_YELLOW, -1);
init_pair (BLUE_GREEN, COLOR_BLUE, COLOR_GREEN);
init_pair (BLACK_GREEN, COLOR_BLACK, COLOR_GREEN);
init_pair (BLACK_CYAN, COLOR_BLACK, COLOR_CYAN);
init_pair (WHITE_RED, COLOR_WHITE, COLOR_RED);
}
size_t
os_size ()
{
return sizeof (os) / sizeof (os[0]);
}
size_t
browsers_size ()
{
return sizeof (browsers) / sizeof (browsers[0]);
}
size_t
codes_size ()
{
return sizeof (codes) / sizeof (codes[0]);
}
size_t
help_main_size ()
{
return sizeof (help_main) / sizeof (help_main[0]);
}