1 /* 2 AWFFull - A Webalizer Fork, Full o' features 3 4 awffull.h 5 The primary definitions file 6 7 Copyright (C) 1997-2001 Bradford L. Barrett (brad@mrunix.net) 8 Copyright 2002, 2004 by Stanislaw Yurievich Pusep 9 Copyright (C) 2004-2008 by Stephen McInerney (spm@stedee.id.au) 10 11 This file is part of AWFFull. 12 13 AWFFull is free software: you can redistribute it and/or modify 14 it under the terms of the GNU General Public License as published by 15 the Free Software Foundation, either version 3 of the License, or 16 (at your option) any later version. 17 18 AWFFull is distributed in the hope that it will be useful, 19 but WITHOUT ANY WARRANTY; without even the implied warranty of 20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 21 GNU General Public License for more details. 22 23 You should have received a copy of the GNU General Public License 24 along with AWFFull. If not, see <http://www.gnu.org/licenses/>. 25 26 This software uses the gd graphics library, which is copyright by 27 Quest Protein Database Center, Cold Spring Harbor Labs. Please 28 see the documentation supplied with the library for additional 29 information and license terms, or visit www.boutell.com/gd/ for the 30 most recent version of the library and supporting documentation. 31 */ 32 33 #ifndef AWFFULL_AWFFULL_H 34 #define AWFFULL_AWFFULL_H 35 36 37 #include "common.h" 38 39 #define FILENAME_CONFIG "awffull.conf" 40 #define FILENAME_HISTORY "awffull.hist" 41 #define FILENAME_CURRENT "awffull.current" 42 #define FILENAME_CSS "awffull.css" 43 44 #define SITE_ADDRESS "http://www.stedee.id.au/awffull/" 45 46 #define GEOIP_DATABASE "/usr/local/share/GeoIP/GeoIP.dat" 47 48 #define DATE_TIME_FORMAT "%d/%b/%Y:%H:%M:%S" /* Default DATE_TIME format for input to strptime */ 49 #define DATE_TIME_XFERLOG_FORMAT "%a %b %d %H:%M:%S %Y" 50 51 #define MAXHASH 5381 /* Size of our hash tables */ 52 #define BUFSIZE (1024 * 64) /* Max buffer size for log record */ 53 /* NB! BUFSIZE *must* be > any of the MAX... #defines */ 54 #define MAXHOST 256 /* Max hostname buffer size */ 55 #define MAXURL 4096 /* Max HTTP request/URL field size */ 56 #define MAXREF 4096 /* Max referrer field size */ 57 #define MAXAGENT 1024 /* Max user agent field size */ 58 #define MAXCTRY 48 /* Max country name size */ 59 #define MAXSRCH 1024 /* Max size of search string buffer */ 60 #define MAXSRCHH MAXSRCH /* Max size of search str in htab */ 61 #define MAXIDENT 64 /* Max size of ident string (user) */ 62 #define MAXHISTLEN (20 * 12) /* Maximum length of the history - 20 years */ 63 #define MAXDATETIME 30 /* Max size of any Date/Time String */ 64 65 66 #define MAXPATHNAMELENGTH 4096 67 #define MAXFILENAMELENGTH 1024 68 #define MAXTITLELENGTH 1024 69 #define MAXCSSLENGTH 1024 70 71 #define SLOP_VAL 3600 /* out of sequence slop (seconds) */ 72 73 #define VOLUMEBASE 1000 /* Move to SI Units. Kb = 1000 vs 1024. 74 If change to 1024, modify hr_size() in output.c */ 75 76 /* Default Graph Sizes */ 77 #define GRAPH_INDEX_X 512 /* px. Default X size (512) */ 78 #define GRAPH_INDEX_Y 256 /* px. Default Y size (256) */ 79 #define GRAPH_DAILY_X 512 /* px. Daily X size (512) */ 80 #define GRAPH_DAILY_Y 400 /* px. Daily Y size (400) */ 81 #define GRAPH_HOURLY_X 512 /* px. Daily X size (512) */ 82 #define GRAPH_HOURLY_Y 400 /* px. Daily Y size (400) */ 83 #define GRAPH_PIE_X 512 /* px. Pie X size (512) */ 84 #define GRAPH_PIE_Y 300 /* px. Pie Y size (300) */ 85 86 /* Log types */ 87 #define LOG_UNRECOGNISED -1 /* Unrecognised log format */ 88 #define LOG_AUTO 0 /* Try and discover the log format */ 89 #define LOG_CLF 1 /* CLF log type */ 90 #define LOG_FTP 2 /* wu-ftpd xferlog type */ 91 #define LOG_SQUID 3 /* squid proxy log */ 92 #define LOG_COMBINED 4 /* Apache Combined log type */ 93 #define LOG_DOMINO 5 /* Lotus Domino, quoted user name else == #3 */ 94 95 /* Response code defines as per draft ietf HTTP/1.1 rev 6 */ 96 #define RC_CONTINUE 100 97 #define RC_SWITCHPROTO 101 98 #define RC_OK 200 99 #define RC_CREATED 201 100 #define RC_ACCEPTED 202 101 #define RC_NONAUTHINFO 203 102 #define RC_NOCONTENT 204 103 #define RC_RESETCONTENT 205 104 #define RC_PARTIALCONTENT 206 105 #define RC_MULTIPLECHOICES 300 106 #define RC_MOVEDPERM 301 107 #define RC_MOVEDTEMP 302 108 #define RC_SEEOTHER 303 109 #define RC_NOMOD 304 110 #define RC_USEPROXY 305 111 #define RC_MOVEDTEMPORARILY 307 112 #define RC_BAD 400 113 #define RC_UNAUTH 401 114 #define RC_PAYMENTREQ 402 115 #define RC_FORBIDDEN 403 116 #define RC_NOTFOUND 404 117 #define RC_METHODNOTALLOWED 405 118 #define RC_NOTACCEPTABLE 406 119 #define RC_PROXYAUTHREQ 407 120 #define RC_TIMEOUT 408 121 #define RC_CONFLICT 409 122 #define RC_GONE 410 123 #define RC_LENGTHREQ 411 124 #define RC_PREFAILED 412 125 #define RC_REQENTTOOLARGE 413 126 #define RC_REQURITOOLARGE 414 127 #define RC_UNSUPMEDIATYPE 415 128 #define RC_RNGNOTSATISFIABLE 416 129 #define RC_EXPECTATIONFAILED 417 130 #define RC_SERVERERR 500 131 #define RC_NOTIMPLEMENTED 501 132 #define RC_BADGATEWAY 502 133 #define RC_UNAVAIL 503 134 #define RC_GATEWAYTIMEOUT 504 135 #define RC_BADHTTPVER 505 136 137 /* Index defines for RC codes */ 138 #define IDX_UNDEFINED 0 139 #define IDX_CONTINUE 1 140 #define IDX_SWITCHPROTO 2 141 #define IDX_OK 3 142 #define IDX_CREATED 4 143 #define IDX_ACCEPTED 5 144 #define IDX_NONAUTHINFO 6 145 #define IDX_NOCONTENT 7 146 #define IDX_RESETCONTENT 8 147 #define IDX_PARTIALCONTENT 9 148 #define IDX_MULTIPLECHOICES 10 149 #define IDX_MOVEDPERM 11 150 #define IDX_MOVEDTEMP 12 151 #define IDX_SEEOTHER 13 152 #define IDX_NOMOD 14 153 #define IDX_USEPROXY 15 154 #define IDX_MOVEDTEMPORARILY 16 155 #define IDX_BAD 17 156 #define IDX_UNAUTH 18 157 #define IDX_PAYMENTREQ 19 158 #define IDX_FORBIDDEN 20 159 #define IDX_NOTFOUND 21 160 #define IDX_METHODNOTALLOWED 22 161 #define IDX_NOTACCEPTABLE 23 162 #define IDX_PROXYAUTHREQ 24 163 #define IDX_TIMEOUT 25 164 #define IDX_CONFLICT 26 165 #define IDX_GONE 27 166 #define IDX_LENGTHREQ 28 167 #define IDX_PREFAILED 29 168 #define IDX_REQENTTOOLARGE 30 169 #define IDX_REQURITOOLARGE 31 170 #define IDX_UNSUPMEDIATYPE 32 171 #define IDX_RNGNOTSATISFIABLE 33 172 #define IDX_EXPECTATIONFAILED 34 173 #define IDX_SERVERERR 35 174 #define IDX_NOTIMPLEMENTED 36 175 #define IDX_BADGATEWAY 37 176 #define IDX_UNAVAIL 38 177 #define IDX_GATEWAYTIMEOUT 39 178 #define IDX_BADHTTPVER 40 179 #define TOTAL_RC 41 180 181 #define VERBOSE0 0 182 #define VERBOSE1 1 183 #define VERBOSE2 2 184 #define VERBOSE3 3 185 #define VERBOSE4 4 186 #define VERBOSE5 5 187 #define VERBOSE_MAX VERBOSE5 188 189 #define USESPACE true 190 #define IGNORESPACE false 191 192 /************************************************************************ 193 * MACROS * 194 ************************************************************************/ 195 /* Where verbosity is a global, set once ONLY, defining what level of verboseness we are at */ 196 #define VPRINT(level, ...) if (g_settings.settings.verbosity >= (level)) { printf(__VA_ARGS__); } 197 #define ERRVPRINT(level, ...) fflush (stdout); if (g_settings.settings.verbosity >= (level)) { fprintf(stderr, __VA_ARGS__); } 198 199 #define IDX_2C(c1,c2) ((((c1) -'a'+1)<<5)+((c2) -'a'+1) ) 200 #define IDX_3C(c1,c2,c3) ((((c1) -'a'+1)<<10)+(((c2) -'a'+1)<<5)+((c3) -'a'+1) ) 201 #define IDX_4C(c1,c2,c3,c4) ((((c1) -'a'+1)<<15)+(((c2) -'a'+1)<<10)+(((c3) -'a'+1)<<5)+((c4) -'a'+1) ) 202 203 #define INIT_CTRY(index, dom, descr) j = (index) ; ctry[j].idx = ctry_idx(dom); ctry[j].domain = dom; ctry[j].desc = descr; 204 #define INIT_RESPCODE(index, descr) response[(index)].desc = descr; 205 206 #ifndef MAX 207 #define MAX(a,b) ((a) > (b) ? (a) : (b)) 208 #endif /* not MAX */ 209 210 211 /************************************************************************ 212 * GLOBALS * 213 ************************************************************************/ 214 struct amount_so_far { 215 unsigned long hit; 216 unsigned long partial_hit; 217 unsigned long file; 218 unsigned long page; 219 unsigned long visit; 220 unsigned long site; 221 unsigned long long vol; 222 unsigned long long partial_vol; 223 unsigned long url; 224 unsigned long ref; 225 unsigned long agent; 226 unsigned long user; 227 unsigned long entry; 228 unsigned long exit; 229 unsigned long single_access; 230 }; 231 232 /* Response code structure */ 233 struct response_code { 234 const char *desc; /* response code struct */ 235 unsigned long count; 236 }; 237 238 /* Country code structure */ 239 struct country_code { 240 unsigned long idx; 241 const char *desc; 242 const char *domain; 243 unsigned long long pages; 244 unsigned long count; 245 unsigned long files; 246 unsigned long long xfer; 247 }; 248 249 typedef struct country_code *CLISTPTR; 250 251 /* log record structure */ 252 struct log_struct { 253 bool force_include; /* If TRUE, this record *MUST* be included */ 254 bool is_page; /* If TRUE, this record IS a page */ 255 char hostname[MAXHOST + 1]; /* hostname */ 256 char ident[MAXIDENT + 1]; /* ident string (user) */ 257 char datetime[MAXDATETIME + 1]; /* raw timestamp */ 258 char url[MAXURL + 1]; /* raw request field */ 259 int resp_code; /* response code */ 260 unsigned long xfer_size; /* xfer size in bytes */ 261 char refer[MAXREF + 1]; /* referrer */ 262 char agent[MAXAGENT + 1]; /* user agent (browser) */ 263 char srchstr[MAXSRCH + 1]; /* search string */ 264 }; 265 266 /* These structures are used to put all global flags into a single unit. 267 * For ease of code readability */ 268 269 /************************************************************ 270 * When adding new Configuration Globals, add them to 271 * options.c/display_options 272 ************************************************************/ 273 struct display_graphs { 274 bool hourly; /* hourly graph display */ 275 bool daily; /* daily graph display */ 276 bool country; /* country graph display */ 277 bool url_by_hits; /* TOP URL's by Hits graph display */ 278 bool url_by_vol; /* TOP URL's by Volume graph display */ 279 bool sites_by_pages; /* TOP Sites Pages Graph - 0 no, 1 yes */ 280 bool sites_by_vol; /* TOP Sites Volume Graph - 0 no, 1 yes */ 281 bool agents; /* TOP User Agents Graph - 0 no, 1 yes */ 282 int exit_pages; /* TOP Exit Pages Graph Display - 0 no, 1 hits, 2 visits */ 283 int entry_pages; /* TOP Entry Pgaes Graph Display - 0 no, 1 hits, 2 visits */ 284 285 bool legend; /* graph legend (1=yes) */ 286 bool lines; /* display graph lines */ 287 bool use_kanji; /* Do special offsets in graphs for Japanese Character Set */ 288 289 int index_x; /* Size of Main Graph X */ 290 int index_y; /* Size of Main Graph Y */ 291 int daily_x; /* Size of Monthly Graph X */ 292 int daily_y; /* Size of Monthly Graph Y */ 293 int hourly_x; /* Size of Daily Graph X */ 294 int hourly_y; /* Size of Daily Graph Y */ 295 int pie_x; /* Size of Pie Graph X */ 296 int pie_y; /* Size of Pie Graph Y */ 297 }; 298 299 struct display_stats { 300 bool hourly; /* hourly stats table */ 301 bool daily; /* daily stats table */ 302 }; 303 304 /* Unless otherwise stated, false == no, true == yes */ 305 struct generic_flags { 306 bool time_me; /* timing display flag */ 307 bool local_time; /* 1=localtime 0=GMT (UTC) */ 308 bool ignore_history; /* history flag (1=skip) */ 309 bool shade_groups; /* Group shading 0=no 1=yes */ 310 bool highlight_groups; /* Group hlite 0=no 1=yes */ 311 bool incremental; /* incremental mode 1=yes */ 312 bool incremental_duplicate_check; /* Set to true when in incremental mode; 313 false when not in incremental mode, or already found all duplicates */ 314 bool use_https; /* use 'https://' on URL's */ 315 bool fold_seq_err; /* fold seq err (0=no) */ 316 bool hide_sites; /* Hide ind. sites (0=no) */ 317 bool track_206_reqs; /* Track 206 Requests */ 318 bool display_match_counts; /* Display the match counts vs Groups, Ignore's etc */ 319 bool display_yearly_subtotals; /* Display Yearly Subtotals on main page */ 320 bool force_log_type; /* Set to true if log_type set by Command line or Config File */ 321 bool use_geoip; /* If able, use GeoIP capability */ 322 bool have_geoip; /* If GeoIP is compiled in */ 323 bool cumulative_percentages; /* Display Cumulative percentages instead of by share */ 324 bool segmenting; /* True if we are doing any Segmenting */ 325 bool segcountry; /* True if we are Segmenting by Country */ 326 bool segreferer; /* True if we are Segmenting by Referer */ 327 bool disable_report_file_checks; /* True if we are NOT doing any checks for CSS files and links to old reports */ 328 bool ignore_index_alias; /* True if we ignore index.* checks in the URL */ 329 bool is_first_run; 330 }; 331 332 /* General Settings, not otherwise categorised */ 333 struct generic_settings { 334 unsigned int index_months; /* Number of Months to display */ 335 unsigned int mangle_agent; /* mangle user agents */ 336 unsigned int visit_timeout; /* visit timeout - units in seconds */ 337 unsigned int log_type; /* Log Type. See #define LOG_* above */ 338 unsigned int group_domains; /* Group domains 0=none */ 339 unsigned int verbosity; /* How many extra stuff to show. If 0: none. Bigger numbers, show more. */ 340 const char *hostname; /* hostname for reports */ 341 const char *title_message; /* Title Message for Reports */ 342 const char *state_filename; /* run state file name */ 343 const char *history_filename; /* name of history file */ 344 const char *css_filename; /* CSS file name */ 345 char *config_filename; /* name of config file */ 346 const char *html_ext; /* HTML file extension */ 347 const char *out_dir; /* output directory */ 348 const char *flags_location; /* Display Country Flags if not null */ 349 const char *geoip_database; /* location of the GeoIP Database file */ 350 unsigned history_index; /* Current place in the history - more of a counter, but counters are reset monthly */ 351 }; 352 353 /* The flags for displaying ALL_XXX results */ 354 struct all_flags { 355 bool sites; /* List All sites (0=no) */ 356 bool urls; /* List All URL's (0=no) */ 357 bool refs; /* List All Referrers */ 358 bool agents; /* List All User Agents */ 359 bool search; /* List All Search Strings */ 360 bool users; /* List All Usernames */ 361 bool errors; /* List All ErrorPages */ 362 bool entry; /* List All EntryPages */ 363 bool exit; /* List All ExitPages */ 364 }; 365 366 /* The flags for dumping various results */ 367 struct dump_flags { 368 bool sites; /* Dump tab delimited sites */ 369 bool urls; /* URL's */ 370 bool refs; /* Referrers */ 371 bool agents; /* User Agents */ 372 bool users; /* Usernames */ 373 bool search; /* Search strings */ 374 bool countries; /* Countries */ 375 bool entry_pages; /* Entry Pages */ 376 bool exit_pages; /* Exit Pages */ 377 bool header; /* Dump header as first rec */ 378 const char *dump_path; /* Path for dump files */ 379 const char *dump_ext; /* Dump file extension */ 380 }; 381 382 struct ntop { 383 unsigned int sites; /* top n sites to display */ 384 unsigned int sites_by_vol; /* top n sites (by kbytes) */ 385 unsigned int urls; /* top n url's to display */ 386 unsigned int urls_by_vol; /* top n url's (by kbytes) */ 387 unsigned int entry; /* top n entry url's */ 388 unsigned int exit; /* top n exit url's */ 389 unsigned int refs; /* top n referrers "" */ 390 unsigned int agents; /* top n user agents "" */ 391 unsigned int countries; /* top n countries "" */ 392 unsigned int search; /* top n search strings */ 393 unsigned int users; /* top n users to display */ 394 unsigned int error; /* top n 404 to display */ 395 }; 396 397 /* Structure for all Settings & Flags - used globally */ 398 struct global_settings { 399 struct generic_flags flags; /* General Flags */ 400 struct generic_settings settings; /* General Settings */ 401 struct ntop top; /* Top Nbr Settings */ 402 struct display_graphs graphs; /* Graphing Flags and Settings */ 403 struct display_stats stats; /* HTML Table Flags and Settings */ 404 struct all_flags all; /* Flags for the various ALL_XXX settings */ 405 struct dump_flags dump; /* Flags for the various DUMP_XXX settings */ 406 }; 407 408 /* The actual Global Variable */ 409 extern struct global_settings g_settings; 410 411 412 /************************************************************************* 413 * Counter Structures 414 * 415 * All that can be counted.... 416 *************************************************************************/ 417 struct generic_counters { 418 unsigned long bad_month; /* total bad records */ 419 unsigned long error_month; /* total error pages */ 420 unsigned long ignored_month; /* total ignored records */ 421 }; 422 423 struct hourly_counters { 424 unsigned long hit[24]; 425 unsigned long partial_hit[24]; 426 unsigned long file[24]; 427 unsigned long page[24]; 428 unsigned long visit[24]; 429 unsigned long site[24]; 430 unsigned long long vol[24]; 431 unsigned long long partial_vol[24]; 432 unsigned long url[24]; 433 unsigned long ref[24]; 434 unsigned long agent[24]; 435 unsigned long user[24]; 436 }; 437 438 struct daily_counters { 439 unsigned long hit[31]; 440 unsigned long partial_hit[31]; 441 unsigned long file[31]; 442 unsigned long page[31]; 443 unsigned long visit[31]; 444 unsigned long site[31]; 445 unsigned long long vol[31]; 446 unsigned long long partial_vol[31]; 447 unsigned long url[31]; 448 unsigned long ref[31]; 449 unsigned long agent[31]; 450 unsigned long user[31]; 451 }; 452 453 struct monthly_counters { 454 unsigned int first_day; 455 unsigned int last_day; 456 unsigned long hit; 457 unsigned long partial_hit; 458 unsigned long file; 459 unsigned long page; 460 unsigned long visit; 461 unsigned long site; 462 unsigned long long vol; 463 unsigned long long partial_vol; 464 unsigned long url; 465 unsigned long ref; 466 unsigned long agent; 467 unsigned long user; 468 unsigned long entry; 469 unsigned long exit; 470 unsigned long single_access; 471 // unsigned long search_strings; 472 }; 473 474 struct global_counters { 475 struct generic_counters generic; 476 struct hourly_counters hour; 477 struct daily_counters day; 478 struct monthly_counters month; 479 }; 480 481 struct global_run_counters { 482 unsigned long total_run; /* Total Records Processed */ 483 unsigned long bad_run; /* total bad records */ 484 unsigned long error_run; /* total error pages */ 485 unsigned long ignored_run; /* total ignored records */ 486 487 }; 488 489 extern struct global_counters g_counters; /* All monthly/daily/hourly counters */ 490 extern struct global_run_counters g_run_counters; /* All permanent for the entire run counters */ 491 492 493 extern char *log_fname; /* log file pointer */ 494 extern char *blank_str; /* blank string */ 495 496 #if HAVE_GEOIP_H 497 extern GeoIP *gi; /* GeoIP access */ 498 #endif 499 500 extern unsigned long cur_tstamp; /* Current timestamp */ 501 extern unsigned long epoch; /* used for timestamp adj. */ 502 503 extern const char *version; /* program version */ 504 extern const char *copyright; 505 506 507 extern int g_cur_year, g_cur_month, /* year/month/day/hour */ 508 g_cur_day, g_cur_hour, /* tracking variables */ 509 g_cur_min, g_cur_sec; 510 511 512 extern unsigned long dt_site; /* daily 'sites' total */ 513 extern unsigned long ht_hit, mh_hit; /* hourly hits totals */ 514 515 extern int gz_log; /* flag for zipped log */ 516 517 extern CLISTPTR *top_ctrys; /* Top countries table */ 518 519 extern char hit_color[]; /* graph hit color */ 520 extern char file_color[]; /* graph file color */ 521 extern char site_color[]; /* graph site color */ 522 extern char kbyte_color[]; /* graph kbyte color */ 523 extern char page_color[]; /* graph page color */ 524 extern char visit_color[]; /* graph visit color */ 525 extern char pie_color1[]; /* pie additionnal color 1 */ 526 extern char pie_color2[]; /* pie additionnal color 2 */ 527 extern char pie_color3[]; /* pie additionnal color 3 */ 528 extern char pie_color4[]; /* pie additionnal color 4 */ 529 530 /* define our externally visable functions */ 531 extern char *current_time(void); 532 extern unsigned long ctry_idx(char *); 533 extern void init_counters(void); 534 extern void process_options(int, char *[]); 535 extern void display_options(void); 536 extern void get_config(const char *); /* Read a config file */ 537 extern void generate_css_file(void); /* Generate the CSS file */ 538 extern void set_defaults(void); /* Use the default-global structures to set the default settings */ 539 extern char *get_domain(char *); /* return domain name */ 540 extern char *strtoupper(char *); /* Convert a string to Upper Case */ 541 extern char *strtolower(char *); /* Convert a string to Lower Case */ 542 543 extern unsigned long jdate(int, int, int); 544 extern void assign_messages(void); 545 546 #include "graphs.h" 547 #include "hashtab.h" 548 #include "messages.h" 549 #include "linklist.h" 550 #include "output.h" 551 #include "parser.h" 552 #include "preserve.h" 553 #include "xmalloc.h" 554 #include "segment.h" 555 556 557 #endif /* AWFFULL_AWFFULL_H */ 558