Imported Upstream version 2.23.05
[hcoop/zz_old/debian/webalizer.git] / output.c
CommitLineData
e015f748
CE
1/*
2 webalizer - a web server log analysis program
3
4 Copyright (C) 1997-2011 Bradford L. Barrett
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version, and provided that the above
10 copyright and permission notice is included with all distributed
11 copies of this or derived software.
12
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
21
22*/
23
24/*********************************************/
25/* STANDARD INCLUDES */
26/*********************************************/
27
28#include <time.h>
29#include <stdio.h>
30#include <stdlib.h>
31#include <string.h>
32#include <unistd.h> /* normal stuff */
33#include <ctype.h>
34#include <errno.h>
35#include <sys/stat.h>
36#include <sys/utsname.h>
37#ifdef USE_DNS
38#include <db.h>
39#endif
40
41/* ensure sys/types */
42#ifndef _SYS_TYPES_H
43#include <sys/types.h>
44#endif
45
46/* need socket header? */
47#ifdef HAVE_SYS_SOCKET_H
48#include <sys/socket.h>
49#endif
50
51/* some systems need this */
52#ifdef HAVE_MATH_H
53#include <math.h>
54#endif
55
56#ifdef USE_GEOIP
57#include <GeoIP.h>
58#endif
59
60#include "webalizer.h" /* main header */
61#include "lang.h"
62#include "hashtab.h"
63#include "preserve.h"
64#include "linklist.h"
65#include "graphs.h"
66#include "output.h"
67
68/* internal function prototypes */
69void write_html_head(char *, FILE *); /* head of html page */
70void write_html_tail(FILE *); /* tail of html page */
71void month_links(); /* Page links */
72void month_total_table(); /* monthly total table */
73void daily_total_table(); /* daily total table */
74void hourly_total_table(); /* hourly total table */
75void top_sites_table(int); /* top n sites table */
76void top_urls_table(int); /* top n URLs table */
77void top_entry_table(int); /* top n entry/exits */
78void top_refs_table(); /* top n referrers "" */
79void top_agents_table(); /* top n u-agents "" */
80void top_ctry_table(); /* top n countries "" */
81void top_search_table(); /* top n search strs */
82void top_users_table(); /* top n ident table */
83u_int64_t load_url_array( UNODEPTR *); /* load URL array */
84u_int64_t load_site_array( HNODEPTR *); /* load Site array */
85u_int64_t load_ref_array( RNODEPTR *); /* load Refs array */
86u_int64_t load_agent_array(ANODEPTR *); /* load Agents array */
87u_int64_t load_srch_array( SNODEPTR *); /* load srch str array */
88u_int64_t load_ident_array(INODEPTR *); /* load ident array */
89int qs_url_cmph( const void*, const void*); /* compare by hits */
90int qs_url_cmpk( const void*, const void*); /* compare by kbytes */
91int qs_url_cmpn( const void*, const void*); /* compare by entrys */
92int qs_url_cmpx( const void*, const void*); /* compare by exits */
93int qs_site_cmph(const void*, const void*); /* compare by hits */
94int qs_site_cmpk(const void*, const void*); /* compare by kbytes */
95int qs_ref_cmph( const void*, const void*); /* compare by hits */
96int qs_agnt_cmph(const void*, const void*); /* compare by hits */
97int qs_srch_cmph(const void*, const void*); /* compare by hits */
98int qs_ident_cmph(const void*, const void*); /* compare by hits */
99int qs_ident_cmpk(const void*, const void*); /* compare by kbytes */
100
101int all_sites_page(u_int64_t, u_int64_t); /* output site page */
102int all_urls_page(u_int64_t, u_int64_t); /* output urls page */
103int all_refs_page(u_int64_t, u_int64_t); /* output refs page */
104int all_agents_page(u_int64_t, u_int64_t); /* output agents page */
105int all_search_page(u_int64_t, u_int64_t); /* output search page */
106int all_users_page(u_int64_t, u_int64_t); /* output ident page */
107void dump_all_sites(); /* dump sites tab file */
108void dump_all_urls(); /* dump urls tab file */
109void dump_all_refs(); /* dump refs tab file */
110void dump_all_agents(); /* dump agents file */
111void dump_all_users(); /* dump usernames file */
112void dump_all_search(); /* dump search file */
113
114/* define some colors for HTML */
115#define WHITE "#FFFFFF"
116#define BLACK "#000000"
117#define RED "#FF0000"
118#define ORANGE "#FF8000"
119#define LTBLUE "#0080FF"
120#define BLUE "#0000FF"
121#define GREEN "#00FF00"
122#define DKGREEN "#008040"
123#define GREY "#C0C0C0"
124#define LTGREY "#E8E8E8"
125#define YELLOW "#FFFF00"
126#define PURPLE "#FF00FF"
127#define CYAN "#00E0FF"
128#define GRPCOLOR "#D0D0E0"
129
130/* configurable html colors */
131#define HITCOLOR hit_color
132#define FILECOLOR file_color
133#define SITECOLOR site_color
134#define KBYTECOLOR kbyte_color
135#define PAGECOLOR page_color
136#define VISITCOLOR visit_color
137#define MISCCOLOR misc_color
138
139/* sort arrays */
140UNODEPTR *u_array = NULL; /* Sort array for URLs */
141HNODEPTR *h_array = NULL; /* hostnames (sites) */
142RNODEPTR *r_array = NULL; /* referrers */
143ANODEPTR *a_array = NULL; /* user agents */
144SNODEPTR *s_array = NULL; /* search strings */
145INODEPTR *i_array = NULL; /* ident strings (username) */
146u_int64_t a_ctr = 0; /* counter for sort array */
147
148FILE *out_fp;
149
150/*********************************************/
151/* WRITE_HTML_HEAD - output top of HTML page */
152/*********************************************/
153
154void write_html_head(char *period, FILE *out_fp)
155{
156 NLISTPTR lptr; /* used for HTMLhead processing */
157
158 /* HTMLPre code goes before all else */
159 lptr = html_pre;
160 if (lptr==NULL)
161 {
162 /* Default 'DOCTYPE' header record if none specified */
163 fprintf(out_fp,
164 "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\">\n\n");
165 }
166 else
167 {
168 while (lptr!=NULL)
169 {
170 fprintf(out_fp,"%s\n",lptr->string);
171 lptr=lptr->next;
172 }
173 }
174 /* Standard header comments */
175 fprintf(out_fp,"<!-- Generated by The Webalizer Ver. %s-%s -->\n",
176 version,editlvl);
177 fprintf(out_fp,"<!-- -->\n");
178 fprintf(out_fp,"<!-- Copyright 1997-2011 Bradford L. Barrett -->\n");
179 fprintf(out_fp,"<!-- -->\n");
180 fprintf(out_fp,"<!-- Distributed under the GNU GPL Version 2 -->\n");
181 fprintf(out_fp,"<!-- Full text may be found at: -->\n");
182 fprintf(out_fp,"<!-- http://www.webalizer.org -->\n");
183 fprintf(out_fp,"<!-- -->\n");
184 fprintf(out_fp,"<!-- Give the power back to the programmers -->\n");
185 fprintf(out_fp,"<!-- Support the Free Software Foundation -->\n");
186 fprintf(out_fp,"<!-- (http://www.fsf.org) -->\n");
187 fprintf(out_fp,"<!-- -->\n");
188 fprintf(out_fp,"<!-- *** Generated: %s *** -->\n\n",cur_time());
189
190 fprintf(out_fp,"<HTML lang=\"%s\">\n<HEAD>\n",langcode);
191 fprintf(out_fp," <TITLE>%s %s - %s</TITLE>\n",
192 msg_title, hname, (period)?period:msg_main_per);
193 lptr=html_head;
194 while (lptr!=NULL)
195 {
196 fprintf(out_fp,"%s\n",lptr->string);
197 lptr=lptr->next;
198 }
199 fprintf(out_fp,"</HEAD>\n\n");
200
201 lptr = html_body;
202 if (lptr==NULL)
203 fprintf(out_fp,"<BODY BGCOLOR=\"%s\" TEXT=\"%s\" " \
204 "LINK=\"%s\" VLINK=\"%s\">\n",
205 LTGREY, BLACK, BLUE, RED);
206 else
207 {
208 while (lptr!=NULL)
209 {
210 fprintf(out_fp,"%s\n",lptr->string);
211 lptr=lptr->next;
212 }
213 }
214 fprintf(out_fp,"<H2>%s %s</H2>\n",msg_title, hname);
215 if (period)
216 fprintf(out_fp,"<SMALL><STRONG>\n%s: %s<BR>\n",msg_hhdr_sp,period);
217 else
218 fprintf(out_fp,"<SMALL><STRONG>\n%s<BR>\n",msg_main_per);
219 fprintf(out_fp,"%s %s<BR>\n</STRONG></SMALL>\n",msg_hhdr_gt,cur_time());
220 lptr=html_post;
221 while (lptr!=NULL)
222 {
223 fprintf(out_fp,"%s\n",lptr->string);
224 lptr=lptr->next;
225 }
226 fprintf(out_fp,"<CENTER>\n<HR>\n<P>\n");
227}
228
229/*********************************************/
230/* WRITE_HTML_TAIL - output HTML page tail */
231/*********************************************/
232
233void write_html_tail(FILE *out_fp)
234{
235 NLISTPTR lptr;
236
237 fprintf(out_fp,"</CENTER>\n");
238 fprintf(out_fp,"<P>\n<HR>\n");
239 fprintf(out_fp,"<TABLE WIDTH=\"100%%\" CELLPADDING=0 " \
240 "CELLSPACING=0 BORDER=0>\n");
241 fprintf(out_fp,"<TR>\n");
242 fprintf(out_fp,"<TD ALIGN=left VALIGN=top>\n");
243 fprintf(out_fp,"<SMALL>Generated by\n");
244 fprintf(out_fp,"<A HREF=\"http://www.webalizer.org/\">");
245 fprintf(out_fp,"<STRONG>Webalizer Version %s</STRONG></A>\n",version);
246 fprintf(out_fp,"</SMALL>\n</TD>\n");
247 lptr=html_tail;
248 if (lptr)
249 {
250 fprintf(out_fp,"<TD ALIGN=\"right\" VALIGN=\"top\">\n");
251 while (lptr!=NULL)
252 {
253 fprintf(out_fp,"%s\n",lptr->string);
254 lptr=lptr->next;
255 }
256 fprintf(out_fp,"</TD>\n");
257 }
258 fprintf(out_fp,"</TR>\n</TABLE>\n");
259
260 /* wind up, this is the end of the file */
261 fprintf(out_fp,"\n<!-- Webalizer Version %s-%s (Mod: %s) -->\n",
262 version,editlvl,moddate);
263 lptr = html_end;
264 if (lptr)
265 {
266 while (lptr!=NULL)
267 {
268 fprintf(out_fp,"%s\n",lptr->string);
269 lptr=lptr->next;
270 }
271 }
272 else fprintf(out_fp,"\n</BODY>\n</HTML>\n");
273}
274
275/*********************************************/
276/* WRITE_MONTH_HTML - does what it says... */
277/*********************************************/
278
279int write_month_html()
280{
281 char html_fname[256]; /* filename storage areas... */
282 char png1_fname[32];
283 char png2_fname[32];
284
285 char buffer[BUFSIZE]; /* scratch buffer */
286 char dtitle[256];
287 char htitle[256];
288
289 if (verbose>1)
290 printf("%s %s %d\n",msg_gen_rpt, l_month[cur_month-1], cur_year);
291
292 /* fill in filenames */
293 snprintf(html_fname,sizeof(html_fname),"usage_%04d%02d.%s",
294 cur_year,cur_month,html_ext);
295 sprintf(png1_fname,"daily_usage_%04d%02d.png",cur_year,cur_month);
296 sprintf(png2_fname,"hourly_usage_%04d%02d.png",cur_year,cur_month);
297
298 /* create PNG images for web page */
299 if (daily_graph)
300 {
301 snprintf(dtitle,sizeof(dtitle),"%s %s %d",
302 msg_hmth_du,l_month[cur_month-1],cur_year);
303 month_graph6 ( png1_fname, /* filename */
304 dtitle, /* graph title */
305 cur_month, /* graph month */
306 cur_year, /* graph year */
307 tm_hit, /* data 1 (hits) */
308 tm_file, /* data 2 (files) */
309 tm_site, /* data 3 (sites) */
310 tm_xfer, /* data 4 (kbytes) */
311 tm_page, /* data 5 (pages) */
312 tm_visit); /* data 6 (visits) */
313 }
314
315 if (hourly_graph)
316 {
317 snprintf(htitle,sizeof(htitle),"%s %s %d",
318 msg_hmth_hu,l_month[cur_month-1],cur_year);
319 day_graph3( png2_fname,
320 htitle,
321 th_hit,
322 th_file,
323 th_page );
324 }
325
326 /* now do html stuff... */
327 /* first, open the file */
328 if ( (out_fp=open_out_file(html_fname))==NULL ) return 1;
329
330 snprintf(buffer,sizeof(buffer),"%s %d",l_month[cur_month-1],cur_year);
331 write_html_head(buffer, out_fp);
332 month_links();
333 month_total_table();
334 if (daily_graph || daily_stats) /* Daily stuff */
335 {
336 fprintf(out_fp,"<A NAME=\"DAYSTATS\"></A>\n");
337 if (daily_graph) fprintf(out_fp,"<IMG SRC=\"%s\" ALT=\"%s\" " \
338 "HEIGHT=400 WIDTH=512><P>\n",png1_fname,dtitle);
339 if (daily_stats) daily_total_table();
340 }
341
342 if (hourly_graph || hourly_stats) /* Hourly stuff */
343 {
344 fprintf(out_fp,"<A NAME=\"HOURSTATS\"></A>\n");
345 if (hourly_graph) fprintf(out_fp,"<IMG SRC=\"%s\" ALT=\"%s\" " \
346 "HEIGHT=256 WIDTH=512><P>\n",png2_fname,htitle);
347 if (hourly_stats) hourly_total_table();
348 }
349
350 /* Do URL related stuff here, sorting appropriately */
351 if ( (a_ctr=load_url_array(NULL)) )
352 {
353 if ( (u_array=malloc(sizeof(UNODEPTR)*(a_ctr))) !=NULL )
354 {
355 a_ctr=load_url_array(u_array); /* load up our sort array */
356 if (ntop_urls || dump_urls)
357 {
358 qsort(u_array,a_ctr,sizeof(UNODEPTR),qs_url_cmph);
359 if (ntop_urls) top_urls_table(0); /* Top URLs (by hits) */
360 if (dump_urls) dump_all_urls(); /* Dump URLs tab file */
361 }
362 if (ntop_urlsK) /* Top URLs (by kbytes) */
363 {qsort(u_array,a_ctr,sizeof(UNODEPTR),qs_url_cmpk); top_urls_table(1); }
364 if (ntop_entry) /* Top Entry Pages */
365 {qsort(u_array,a_ctr,sizeof(UNODEPTR),qs_url_cmpn); top_entry_table(0);}
366 if (ntop_exit) /* Top Exit Pages */
367 {qsort(u_array,a_ctr,sizeof(UNODEPTR),qs_url_cmpx); top_entry_table(1);}
368 free(u_array);
369 }
370 else if (verbose) fprintf(stderr,"%s [u_array]\n",msg_nomem_tu); /* err */
371 }
372
373 /* do hostname (sites) related stuff here, sorting appropriately... */
374 if ( (a_ctr=load_site_array(NULL)) )
375 {
376 if ( (h_array=malloc(sizeof(HNODEPTR)*(a_ctr))) !=NULL )
377 {
378 a_ctr=load_site_array(h_array); /* load up our sort array */
379 if (ntop_sites || dump_sites)
380 {
381 qsort(h_array,a_ctr,sizeof(HNODEPTR),qs_site_cmph);
382 if (ntop_sites) top_sites_table(0); /* Top sites table (by hits) */
383 if (dump_sites) dump_all_sites(); /* Dump sites tab file */
384 }
385 if (ntop_sitesK) /* Top Sites table (by kbytes) */
386 {
387 qsort(h_array,a_ctr,sizeof(HNODEPTR),qs_site_cmpk);
388 top_sites_table(1);
389 }
390 free(h_array);
391 }
392 else if (verbose) fprintf(stderr,"%s [h_array]\n",msg_nomem_ts); /* err */
393 }
394
395 /* do referrer related stuff here, sorting appropriately... */
396 if ( (a_ctr=load_ref_array(NULL)) )
397 {
398 if ( (r_array=malloc(sizeof(RNODEPTR)*(a_ctr))) != NULL)
399 {
400 a_ctr=load_ref_array(r_array);
401 if (ntop_refs || dump_refs)
402 {
403 qsort(r_array,a_ctr,sizeof(RNODEPTR),qs_ref_cmph);
404 if (ntop_refs) top_refs_table(); /* Top referrers table */
405 if (dump_refs) dump_all_refs(); /* Dump referrers tab file */
406 }
407 free(r_array);
408 }
409 else if (verbose) fprintf(stderr,"%s [r_array]\n",msg_nomem_tr); /* err */
410 }
411
412 /* do search string related stuff, sorting appropriately... */
413 if ( (a_ctr=load_srch_array(NULL)) )
414 {
415 if ( (s_array=malloc(sizeof(SNODEPTR)*(a_ctr))) != NULL)
416 {
417 a_ctr=load_srch_array(s_array);
418 if (ntop_search || dump_search)
419 {
420 qsort(s_array,a_ctr,sizeof(SNODEPTR),qs_srch_cmph);
421 if (ntop_search) top_search_table(); /* top search strings table */
422 if (dump_search) dump_all_search(); /* dump search string tab file */
423 }
424 free(s_array);
425 }
426 else if (verbose) fprintf(stderr,"%s [s_array]\n",msg_nomem_tsr);/* err */
427 }
428
429 /* do ident (username) related stuff here, sorting appropriately... */
430 if ( (a_ctr=load_ident_array(NULL)) )
431 {
432 if ( (i_array=malloc(sizeof(INODEPTR)*(a_ctr))) != NULL)
433 {
434 a_ctr=load_ident_array(i_array);
435 if (ntop_users || dump_users)
436 {
437 qsort(i_array,a_ctr,sizeof(INODEPTR),qs_ident_cmph);
438 if (ntop_users) top_users_table(); /* top usernames table */
439 if (dump_users) dump_all_users(); /* dump usernames tab file */
440 }
441 free(i_array);
442 }
443 else if (verbose) fprintf(stderr,"%s [i_array]\n",msg_nomem_ti); /* err */
444 }
445
446 /* do user agent related stuff here, sorting appropriately... */
447 if ( (a_ctr=load_agent_array(NULL)) )
448 {
449 if ( (a_array=malloc(sizeof(ANODEPTR)*(a_ctr))) != NULL)
450 {
451 a_ctr=load_agent_array(a_array);
452 if (ntop_agents || dump_agents)
453 {
454 qsort(a_array,a_ctr,sizeof(ANODEPTR),qs_agnt_cmph);
455 if (ntop_agents) top_agents_table(); /* top user agents table */
456 if (dump_agents) dump_all_agents(); /* dump user agents tab file */
457 }
458 free(a_array);
459 }
460 else if (verbose) fprintf(stderr,"%s [a_array]\n",msg_nomem_ta); /* err */
461 }
462
463 if (ntop_ctrys ) top_ctry_table(); /* top countries table */
464
465 write_html_tail(out_fp); /* finish up the HTML document */
466 fclose(out_fp); /* close the file */
467 return (0); /* done... */
468}
469
470/*********************************************/
471/* MONTH_LINKS - links to other page parts */
472/*********************************************/
473
474void month_links()
475{
476 fprintf(out_fp,"<SMALL>\n");
477 if (daily_stats || daily_graph)
478 fprintf(out_fp,"<A HREF=\"#DAYSTATS\">[%s]</A>\n",msg_hlnk_ds);
479 if (hourly_stats || hourly_graph)
480 fprintf(out_fp,"<A HREF=\"#HOURSTATS\">[%s]</A>\n",msg_hlnk_hs);
481 if (ntop_urls || ntop_urlsK)
482 fprintf(out_fp,"<A HREF=\"#TOPURLS\">[%s]</A>\n",msg_hlnk_u);
483 if (ntop_entry)
484 fprintf(out_fp,"<A HREF=\"#TOPENTRY\">[%s]</A>\n",msg_hlnk_en);
485 if (ntop_exit)
486 fprintf(out_fp,"<A HREF=\"#TOPEXIT\">[%s]</A>\n",msg_hlnk_ex);
487 if (ntop_sites || ntop_sitesK)
488 fprintf(out_fp,"<A HREF=\"#TOPSITES\">[%s]</A>\n",msg_hlnk_s);
489 if (ntop_refs && t_ref)
490 fprintf(out_fp,"<A HREF=\"#TOPREFS\">[%s]</A>\n",msg_hlnk_r);
491 if (ntop_search)
492 fprintf(out_fp,"<A HREF=\"#TOPSEARCH\">[%s]</A>\n",msg_hlnk_sr);
493 if (ntop_users && t_user)
494 fprintf(out_fp,"<A HREF=\"#TOPUSERS\">[%s]</A>\n",msg_hlnk_i);
495 if (ntop_agents && t_agent)
496 fprintf(out_fp,"<A HREF=\"#TOPAGENTS\">[%s]</A>\n",msg_hlnk_a);
497 if (ntop_ctrys)
498 fprintf(out_fp,"<A HREF=\"#TOPCTRYS\">[%s]</A>\n",msg_hlnk_c);
499 fprintf(out_fp,"</SMALL>\n<P>\n");
500}
501
502/*********************************************/
503/* MONTH_TOTAL_TABLE - monthly totals table */
504/*********************************************/
505
506void month_total_table()
507{
508 int i,days_in_month;
509 u_int64_t max_files=0,max_hits=0,max_visits=0,max_pages=0,max_sites=0;
510 double max_xfer=0.0;
511
512 days_in_month=(l_day-f_day)+1;
513 for (i=0;i<31;i++)
514 { /* Get max/day values */
515 if (tm_hit[i]>max_hits) max_hits = tm_hit[i];
516 if (tm_file[i]>max_files) max_files = tm_file[i];
517 if (tm_page[i]>max_pages) max_pages = tm_page[i];
518 if (tm_visit[i]>max_visits) max_visits= tm_visit[i];
519 if (tm_site[i]>max_sites) max_sites = tm_site[i];
520 if (tm_xfer[i]>max_xfer) max_xfer = tm_xfer[i];
521 }
522
523 fprintf(out_fp,"<TABLE WIDTH=510 BORDER=2 CELLSPACING=1 CELLPADDING=1>\n");
524 fprintf(out_fp,"<TR><TH HEIGHT=4></TH></TR>\n");
525 fprintf(out_fp,"<TR><TH COLSPAN=3 ALIGN=center BGCOLOR=\"%s\">" \
526 "%s %s %d</TH></TR>\n",GREY,msg_mtot_ms,l_month[cur_month-1],cur_year);
527 fprintf(out_fp,"<TR><TH HEIGHT=4></TH></TR>\n");
528 /* Total Hits */
529 fprintf(out_fp,"<TR><TD WIDTH=380><FONT SIZE=\"-1\">%s</FONT></TD>\n" \
530 "<TD ALIGN=right COLSPAN=2><FONT SIZE=\"-1\"><B>%llu</B>" \
531 "</FONT></TD></TR>\n",msg_mtot_th,t_hit);
532 /* Total Files */
533 fprintf(out_fp,"<TR><TD WIDTH=380><FONT SIZE=\"-1\">%s</FONT></TD>\n" \
534 "<TD ALIGN=right COLSPAN=2><FONT SIZE=\"-1\"><B>%llu</B>" \
535 "</FONT></TD></TR>\n",msg_mtot_tf,t_file);
536 /* Total Pages */
537 fprintf(out_fp,"<TR><TD WIDTH=380><FONT SIZE=\"-1\">%s %s</FONT></TD>\n" \
538 "<TD ALIGN=right COLSPAN=2><FONT SIZE=\"-1\"><B>%llu</B>" \
539 "</FONT></TD></TR>\n",msg_h_total, msg_h_pages, t_page);
540 /* Total Visits */
541 fprintf(out_fp,"<TR><TD WIDTH=380><FONT SIZE=\"-1\">%s %s</FONT></TD>\n" \
542 "<TD ALIGN=right COLSPAN=2><FONT SIZE=\"-1\"><B>%llu</B>" \
543 "</FONT></TD></TR>\n",msg_h_total, msg_h_visits, t_visit);
544 /* Total XFer */
545 fprintf(out_fp,"<TR><TD WIDTH=380><FONT SIZE=\"-1\">%s</FONT></TD>\n" \
546 "<TD ALIGN=right COLSPAN=2><FONT SIZE=\"-1\"><B>%.0f</B>" \
547 "</FONT></TD></TR>\n",msg_mtot_tx,t_xfer/1024);
548 fprintf(out_fp,"<TR><TH HEIGHT=4></TH></TR>\n");
549 /**********************************************/
550 /* Unique Sites */
551 fprintf(out_fp,"<TR>" \
552 "<TD WIDTH=380><FONT SIZE=\"-1\">%s</FONT></TD>\n" \
553 "<TD ALIGN=right COLSPAN=2><FONT SIZE=\"-1\"><B>%llu</B>" \
554 "</FONT></TD></TR>\n",msg_mtot_us,t_site);
555 /* Unique URLs */
556 fprintf(out_fp,"<TR>" \
557 "<TD WIDTH=380><FONT SIZE=\"-1\">%s</FONT></TD>\n" \
558 "<TD ALIGN=right COLSPAN=2><FONT SIZE=\"-1\"><B>%llu</B>" \
559 "</FONT></TD></TR>\n",msg_mtot_uu,t_url);
560 /* Unique Referrers */
561 if (t_ref != 0)
562 fprintf(out_fp,"<TR>" \
563 "<TD WIDTH=380><FONT SIZE=\"-1\">%s</FONT></TD>\n" \
564 "<TD ALIGN=right COLSPAN=2><FONT SIZE=\"-1\"><B>%llu</B>" \
565 "</FONT></TD></TR>\n",msg_mtot_ur,t_ref);
566 /* Unique Usernames */
567 if (t_user != 0)
568 fprintf(out_fp,"<TR>" \
569 "<TD WIDTH=380><FONT SIZE=\"-1\">%s</FONT></TD>\n" \
570 "<TD ALIGN=right COLSPAN=2><FONT SIZE=\"-1\"><B>%llu</B>" \
571 "</FONT></TD></TR>\n",msg_mtot_ui,t_user);
572 /* Unique Agents */
573 if (t_agent != 0)
574 fprintf(out_fp,"<TR>" \
575 "<TD WIDTH=380><FONT SIZE=\"-1\">%s</FONT></TD>\n" \
576 "<TD ALIGN=right COLSPAN=2><FONT SIZE=\"-1\"><B>%llu</B>" \
577 "</FONT></TD></TR>\n",msg_mtot_ua,t_agent);
578 fprintf(out_fp,"<TR><TH HEIGHT=4></TH></TR>\n");
579 /**********************************************/
580 /* Hourly/Daily avg/max totals */
581 fprintf(out_fp,"<TR>" \
582 "<TH WIDTH=380 BGCOLOR=\"%s\"><FONT SIZE=-1 COLOR=\"%s\">.</FONT></TH>\n"\
583 "<TH WIDTH=65 BGCOLOR=\"%s\" ALIGN=right>" \
584 "<FONT SIZE=-1>%s </FONT></TH>\n" \
585 "<TH WIDTH=65 BGCOLOR=\"%s\" ALIGN=right>" \
586 "<FONT SIZE=-1>%s </FONT></TH></TR>\n",
587 GREY,GREY,GREY,msg_h_avg,GREY,msg_h_max);
588 fprintf(out_fp,"<TR><TH HEIGHT=4></TH></TR>\n");
589 /* Max/Avg Hits per Hour */
590 fprintf(out_fp,"<TR>" \
591 "<TD><FONT SIZE=\"-1\">%s</FONT></TD>\n" \
592 "<TD ALIGN=right WIDTH=65><FONT SIZE=\"-1\"><B>%llu</B></FONT></TD>\n" \
593 "<TD WIDTH=65 ALIGN=right><FONT SIZE=-1><B>%llu</B>" \
594 "</FONT></TD></TR>\n",msg_mtot_mhh, t_hit/(24*days_in_month),mh_hit);
595 /* Max/Avg Hits per Day */
596 fprintf(out_fp,"<TR>" \
597 "<TD><FONT SIZE=\"-1\">%s</FONT></TD>\n" \
598 "<TD ALIGN=right WIDTH=65><FONT SIZE=\"-1\"><B>%llu</B></FONT></TD>\n" \
599 "<TD WIDTH=65 ALIGN=right><FONT SIZE=-1><B>%llu</B>" \
600 "</FONT></TD></TR>\n",msg_mtot_mhd, t_hit/days_in_month, max_hits);
601 /* Max/Avg Files per Day */
602 fprintf(out_fp,"<TR>" \
603 "<TD><FONT SIZE=\"-1\">%s</FONT></TD>\n" \
604 "<TD ALIGN=right WIDTH=65><FONT SIZE=\"-1\"><B>%llu</B></FONT></TD>\n" \
605 "<TD WIDTH=65 ALIGN=right><FONT SIZE=-1><B>%llu</B>" \
606 "</FONT></TD></TR>\n",msg_mtot_mfd, t_file/days_in_month,max_files);
607 /* Max/Avg Pages per Day */
608 fprintf(out_fp,"<TR>" \
609 "<TD><FONT SIZE=\"-1\">%s</FONT></TD>\n" \
610 "<TD ALIGN=right WIDTH=65><FONT SIZE=\"-1\"><B>%llu</B></FONT></TD>\n" \
611 "<TD WIDTH=65 ALIGN=right><FONT SIZE=-1><B>%llu</B>" \
612 "</FONT></TD></TR>\n",msg_mtot_mpd, t_page/days_in_month,max_pages);
613 /* Max/Avg Sites per Day */
614 fprintf(out_fp,"<TR>" \
615 "<TD><FONT SIZE=\"-1\">%s</FONT></TD>\n" \
616 "<TD ALIGN=right WIDTH=65><FONT SIZE=\"-1\"><B>%llu</B></FONT></TD>\n" \
617 "<TD WIDTH=65 ALIGN=right><FONT SIZE=-1><B>%llu</B>" \
618 "</FONT></TD></TR>\n",msg_mtot_msd, t_site/days_in_month,max_sites);
619 /* Max/Avg Visits per Day */
620 fprintf(out_fp,"<TR>" \
621 "<TD><FONT SIZE=\"-1\">%s</FONT></TD>\n" \
622 "<TD ALIGN=right WIDTH=65><FONT SIZE=\"-1\"><B>%llu</B></FONT></TD>\n" \
623 "<TD WIDTH=65 ALIGN=right><FONT SIZE=-1><B>%llu</B>" \
624 "</FONT></TD></TR>\n",msg_mtot_mvd, t_visit/days_in_month,max_visits);
625 /* Max/Avg KBytes per Day */
626 fprintf(out_fp,"<TR>" \
627 "<TD><FONT SIZE=\"-1\">%s</FONT></TD>\n" \
628 "<TD ALIGN=right WIDTH=65><FONT SIZE=\"-1\"><B>%.0f</B></FONT></TD>\n" \
629 "<TD WIDTH=65 ALIGN=right><FONT SIZE=-1><B>%.0f</B>" \
630 "</FONT></TD></TR>\n",msg_mtot_mkd,
631 (t_xfer/1024)/days_in_month,max_xfer/1024);
632 fprintf(out_fp,"<TR><TH HEIGHT=4></TH></TR>\n");
633 /**********************************************/
634 /* response code totals */
635 fprintf(out_fp,"<TR><TH COLSPAN=3 ALIGN=center BGCOLOR=\"%s\">\n" \
636 "<FONT SIZE=\"-1\">%s</FONT></TH></TR>\n",GREY,msg_mtot_rc);
637 fprintf(out_fp,"<TR><TH HEIGHT=4></TH></TR>\n");
638 for (i=0;i<TOTAL_RC;i++)
639 {
640 if (response[i].count != 0)
641 fprintf(out_fp,"<TR><TD><FONT SIZE=\"-1\">%s</FONT></TD>\n" \
642 "<TD ALIGN=right><FONT SIZE=\"-2\">%3.02f%%</FONT></TD>\n" \
643 "<TD ALIGN=right><FONT SIZE=\"-1\"><B>%llu</B></FONT></TD></TR>\n",
644 response[i].desc,PCENT(response[i].count,t_hit),response[i].count);
645 }
646 fprintf(out_fp,"<TR><TH HEIGHT=4></TH></TR>\n");
647 /**********************************************/
648
649 fprintf(out_fp,"</TABLE>\n");
650 fprintf(out_fp,"<P>\n");
651}
652
653/*********************************************/
654/* DAILY_TOTAL_TABLE - daily totals */
655/*********************************************/
656
657void daily_total_table()
658{
659 int i,j;
660
661 /* Daily stats */
662 fprintf(out_fp,"<TABLE WIDTH=510 BORDER=2 CELLSPACING=1 CELLPADDING=1>\n");
663 fprintf(out_fp,"<TR><TH HEIGHT=4></TH></TR>\n");
664 /* Daily statistics for ... */
665 fprintf(out_fp,"<TR><TH BGCOLOR=\"%s\" COLSPAN=13 ALIGN=center>" \
666 "%s %s %d</TH></TR>\n",
667 GREY,msg_dtot_ds,l_month[cur_month-1], cur_year);
668 fprintf(out_fp,"<TR><TH HEIGHT=4></TH></TR>\n");
669 fprintf(out_fp,"<TR><TH ALIGN=center BGCOLOR=\"%s\">" \
670 "<FONT SIZE=\"-1\">%s</FONT></TH>\n" \
671 "<TH ALIGN=center BGCOLOR=\"%s\" COLSPAN=2>" \
672 "<FONT SIZE=\"-1\">%s</FONT></TH>\n" \
673 "<TH ALIGN=center BGCOLOR=\"%s\" COLSPAN=2>" \
674 "<FONT SIZE=\"-1\">%s</FONT></TH>\n" \
675 "<TH ALIGN=center BGCOLOR=\"%s\" COLSPAN=2>" \
676 "<FONT SIZE=\"-1\">%s</FONT></TH>\n" \
677 "<TH ALIGN=center BGCOLOR=\"%s\" COLSPAN=2>" \
678 "<FONT SIZE=\"-1\">%s</FONT></TH>\n" \
679 "<TH ALIGN=center BGCOLOR=\"%s\" COLSPAN=2>" \
680 "<FONT SIZE=\"-1\">%s</FONT></TH>\n" \
681 "<TH ALIGN=center BGCOLOR=\"%s\" COLSPAN=2>" \
682 "<FONT SIZE=\"-1\">%s</FONT></TH></TR>\n",
683 GREY, msg_h_day,
684 HITCOLOR, msg_h_hits,
685 FILECOLOR, msg_h_files,
686 PAGECOLOR, msg_h_pages,
687 VISITCOLOR, msg_h_visits,
688 SITECOLOR, msg_h_sites,
689 KBYTECOLOR, msg_h_xfer);
690 fprintf(out_fp,"<TR><TH HEIGHT=4></TH></TR>\n");
691
692 /* skip beginning blank days in a month */
693 for (i=0;i<l_day;i++) if (tm_hit[i]!=0) break;
694 if (i==l_day) i=0;
695
696 for (;i<l_day;i++)
697 {
698 j = jdate(i+1,cur_month,cur_year);
699 if ( (j%7==6) || (j%7==0) )
700 fprintf(out_fp,"<TR BGCOLOR=\"%s\"><TD ALIGN=center>",GRPCOLOR);
701 else fprintf(out_fp,"<TR><TD ALIGN=center>");
702 fprintf(out_fp,"<FONT SIZE=\"-1\"><B>%d</B></FONT></TD>\n", i+1);
703 fprintf(out_fp,"<TD ALIGN=right>" \
704 "<FONT SIZE=\"-1\"><B>%llu</B></FONT></TD>\n" \
705 "<TD ALIGN=right><FONT SIZE=\"-2\">%3.02f%%</FONT></TD>\n",
706 tm_hit[i],PCENT(tm_hit[i],t_hit));
707 fprintf(out_fp,"<TD ALIGN=right>" \
708 "<FONT SIZE=\"-1\"><B>%llu</B></FONT></TD>\n" \
709 "<TD ALIGN=right><FONT SIZE=\"-2\">%3.02f%%</FONT></TD>\n",
710 tm_file[i],PCENT(tm_file[i],t_file));
711 fprintf(out_fp,"<TD ALIGN=right>" \
712 "<FONT SIZE=\"-1\"><B>%llu</B></FONT></TD>\n" \
713 "<TD ALIGN=right><FONT SIZE=\"-2\">%3.02f%%</FONT></TD>\n",
714 tm_page[i],PCENT(tm_page[i],t_page));
715 fprintf(out_fp,"<TD ALIGN=right>" \
716 "<FONT SIZE=\"-1\"><B>%llu</B></FONT></TD>\n" \
717 "<TD ALIGN=right><FONT SIZE=\"-2\">%3.02f%%</FONT></TD>\n",
718 tm_visit[i],PCENT(tm_visit[i],t_visit));
719 fprintf(out_fp,"<TD ALIGN=right>" \
720 "<FONT SIZE=\"-1\"><B>%llu</B></FONT></TD>\n" \
721 "<TD ALIGN=right><FONT SIZE=\"-2\">%3.02f%%</FONT></TD>\n",
722 tm_site[i],PCENT(tm_site[i],t_site));
723 fprintf(out_fp,"<TD ALIGN=right>" \
724 "<FONT SIZE=\"-1\"><B>%.0f</B></FONT></TD>\n" \
725 "<TD ALIGN=right><FONT SIZE=\"-2\">%3.02f%%</FONT></TD></TR>\n",
726 tm_xfer[i]/1024,PCENT(tm_xfer[i],t_xfer));
727 }
728 fprintf(out_fp,"<TR><TH HEIGHT=4></TH></TR>\n");
729 fprintf(out_fp,"</TABLE>\n");
730 fprintf(out_fp,"<P>\n");
731}
732
733/*********************************************/
734/* HOURLY_TOTAL_TABLE - hourly table */
735/*********************************************/
736
737void hourly_total_table()
738{
739 int i,days_in_month;
740 u_int64_t avg_file=0;
741 double avg_xfer=0.0;
742
743 days_in_month=(l_day-f_day)+1;
744
745 /* Hourly stats */
746 fprintf(out_fp,"<TABLE WIDTH=510 BORDER=2 CELLSPACING=1 CELLPADDING=1>\n");
747 fprintf(out_fp,"<TR><TH HEIGHT=4></TH></TR>\n");
748 fprintf(out_fp,"<TR><TH BGCOLOR=\"%s\" COLSPAN=13 ALIGN=center>"\
749 "%s %s %d</TH></TR>\n",
750 GREY,msg_htot_hs,l_month[cur_month-1], cur_year);
751 fprintf(out_fp,"<TR><TH HEIGHT=4></TH></TR>\n");
752 fprintf(out_fp,"<TR><TH ALIGN=center ROWSPAN=2 BGCOLOR=\"%s\">" \
753 "<FONT SIZE=\"-1\">%s</FONT></TH>\n" \
754 "<TH ALIGN=center BGCOLOR=\"%s\" COLSPAN=3>" \
755 "<FONT SIZE=\"-1\">%s</FONT></TH>\n" \
756 "<TH ALIGN=center BGCOLOR=\"%s\" COLSPAN=3>" \
757 "<FONT SIZE=\"-1\">%s</FONT></TH>\n" \
758 "<TH ALIGN=center BGCOLOR=\"%s\" COLSPAN=3>" \
759 "<FONT SIZE=\"-1\">%s</FONT></TH>\n" \
760 "<TH ALIGN=center BGCOLOR=\"%s\" COLSPAN=3>" \
761 "<FONT SIZE=\"-1\">%s</FONT></TH></TR>\n",
762 GREY, msg_h_hour,
763 HITCOLOR, msg_h_hits,
764 FILECOLOR, msg_h_files,
765 PAGECOLOR, msg_h_pages,
766 KBYTECOLOR, msg_h_xfer);
767 fprintf(out_fp,"<TR><TH ALIGN=center BGCOLOR=\"%s\">" \
768 "<FONT SIZE=\"-2\">%s</FONT></TH>\n" \
769 "<TH ALIGN=center BGCOLOR=\"%s\" COLSPAN=2>" \
770 "<FONT SIZE=\"-2\">%s</FONT></TH>\n",
771 HITCOLOR, msg_h_avg, HITCOLOR, msg_h_total);
772 fprintf(out_fp,"<TH ALIGN=center BGCOLOR=\"%s\">" \
773 "<FONT SIZE=\"-2\">%s</FONT></TH>\n" \
774 "<TH ALIGN=center BGCOLOR=\"%s\" COLSPAN=2>" \
775 "<FONT SIZE=\"-2\">%s</FONT></TH>\n",
776 FILECOLOR, msg_h_avg, FILECOLOR, msg_h_total);
777 fprintf(out_fp,"<TH ALIGN=center BGCOLOR=\"%s\">" \
778 "<FONT SIZE=\"-2\">%s</FONT></TH>\n" \
779 "<TH ALIGN=center BGCOLOR=\"%s\" COLSPAN=2>" \
780 "<FONT SIZE=\"-2\">%s</FONT></TH>\n",
781 PAGECOLOR, msg_h_avg, PAGECOLOR, msg_h_total);
782 fprintf(out_fp,"<TH ALIGN=center BGCOLOR=\"%s\">" \
783 "<FONT SIZE=\"-2\">%s</FONT></TH>\n" \
784 "<TH ALIGN=center BGCOLOR=\"%s\" COLSPAN=2>" \
785 "<FONT SIZE=\"-2\">%s</FONT></TH></TR>\n",
786 KBYTECOLOR, msg_h_avg, KBYTECOLOR, msg_h_total);
787
788 fprintf(out_fp,"<TR><TH HEIGHT=4></TH></TR>\n");
789 for (i=0;i<24;i++)
790 {
791 fprintf(out_fp,"<TR><TD ALIGN=center>" \
792 "<FONT SIZE=\"-1\"><B>%d</B></FONT></TD>\n",i);
793 fprintf(out_fp,
794 "<TD ALIGN=right><FONT SIZE=\"-1\"><B>%llu</B></FONT></TD>\n"\
795 "<TD ALIGN=right><FONT SIZE=\"-1\"><B>%llu</B></FONT></TD>\n"\
796 "<TD ALIGN=right><FONT SIZE=\"-2\">%3.02f%%</FONT></TD>\n",
797 th_hit[i]/days_in_month,th_hit[i],
798 PCENT(th_hit[i],t_hit));
799 fprintf(out_fp,
800 "<TD ALIGN=right><FONT SIZE=\"-1\"><B>%llu</B></FONT></TD>\n"\
801 "<TD ALIGN=right><FONT SIZE=\"-1\"><B>%llu</B></FONT></TD>\n"\
802 "<TD ALIGN=right><FONT SIZE=\"-2\">%3.02f%%</FONT></TD>\n",
803 th_file[i]/days_in_month,th_file[i],
804 PCENT(th_file[i],t_file));
805 fprintf(out_fp,
806 "<TD ALIGN=right><FONT SIZE=\"-1\"><B>%llu</B></FONT></TD>\n"\
807 "<TD ALIGN=right><FONT SIZE=\"-1\"><B>%llu</B></FONT></TD>\n"\
808 "<TD ALIGN=right><FONT SIZE=\"-2\">%3.02f%%</FONT></TD>\n",
809 th_page[i]/days_in_month,th_page[i],
810 PCENT(th_page[i],t_page));
811 fprintf(out_fp,
812 "<TD ALIGN=right><FONT SIZE=\"-1\"><B>%.0f</B></FONT></TD>\n" \
813 "<TD ALIGN=right><FONT SIZE=\"-1\"><B>%.0f</B></FONT></TD>\n" \
814 "<TD ALIGN=right><FONT SIZE=\"-2\">%3.02f%%</FONT></TD></TR>\n",
815 (th_xfer[i]/days_in_month)/1024,th_xfer[i]/1024,
816 PCENT(th_xfer[i],t_xfer));
817 avg_file += th_file[i]/days_in_month;
818 avg_xfer+= (th_xfer[i]/days_in_month)/1024;
819 }
820 fprintf(out_fp,"<TR><TH HEIGHT=4></TH></TR>\n");
821 fprintf(out_fp,"</TABLE>\n<P>\n");
822}
823
824/*********************************************/
825/* TOP_SITES_TABLE - generate top n table */
826/*********************************************/
827
828void top_sites_table(int flag)
829{
830 u_int64_t cnt=0, h_reg=0, h_grp=0, h_hid=0, tot_num;
831 int i;
832 HNODEPTR hptr, *pointer;
833
834 cnt=a_ctr; pointer=h_array;
835 while(cnt--)
836 {
837 /* calculate totals */
838 switch ( (int)((HNODEPTR)(*pointer)->flag) )
839 {
840 case OBJ_REG: h_reg++; break;
841 case OBJ_GRP: h_grp++; break;
842 case OBJ_HIDE: h_hid++; break;
843 }
844 pointer++;
845 }
846
847 if ( (tot_num=h_reg+h_grp)==0 ) return; /* split if none */
848 i=(flag)?ntop_sitesK:ntop_sites; /* Hits or KBytes?? */
849 if (tot_num > i) tot_num = i; /* get max to do... */
850
851 if ((!flag) || (flag&&!ntop_sites)) /* now do <A> tag */
852 fprintf(out_fp,"<A NAME=\"TOPSITES\"></A>\n");
853
854 fprintf(out_fp,"<TABLE WIDTH=510 BORDER=2 CELLSPACING=1 CELLPADDING=1>\n");
855 fprintf(out_fp,"<TR><TH HEIGHT=4></TH></TR>\n");
856 if (flag) fprintf(out_fp,"<TR><TH BGCOLOR=\"%s\" ALIGN=CENTER COLSPAN=10>" \
857 "%s %llu %s %llu %s %s %s</TH></TR>\n",
858 GREY, msg_top_top,tot_num,msg_top_of,
859 t_site,msg_top_s,msg_h_by,msg_h_xfer);
860 else fprintf(out_fp,"<TR><TH BGCOLOR=\"%s\" ALIGN=CENTER COLSPAN=10>" \
861 "%s %llu %s %llu %s</TH></TR>\n",
862 GREY,msg_top_top, tot_num, msg_top_of, t_site, msg_top_s);
863 fprintf(out_fp,"<TR><TH HEIGHT=4></TH></TR>\n");
864 fprintf(out_fp,"<TR><TH BGCOLOR=\"%s\" ALIGN=center>" \
865 "<FONT SIZE=\"-1\">#</FONT></TH>\n",GREY);
866 fprintf(out_fp,"<TH BGCOLOR=\"%s\" ALIGN=center COLSPAN=2>" \
867 "<FONT SIZE=\"-1\">%s</FONT></TH>\n",HITCOLOR,msg_h_hits);
868 fprintf(out_fp,"<TH BGCOLOR=\"%s\" ALIGN=center COLSPAN=2>" \
869 "<FONT SIZE=\"-1\">%s</FONT></TH>\n",FILECOLOR,msg_h_files);
870 fprintf(out_fp,"<TH BGCOLOR=\"%s\" ALIGN=center COLSPAN=2>" \
871 "<FONT SIZE=\"-1\">%s</FONT></TH>\n",KBYTECOLOR,msg_h_xfer);
872 fprintf(out_fp,"<TH BGCOLOR=\"%s\" ALIGN=center COLSPAN=2>" \
873 "<FONT SIZE=\"-1\">%s</FONT></TH>\n",VISITCOLOR,msg_h_visits);
874 fprintf(out_fp,"<TH BGCOLOR=\"%s\" ALIGN=center>" \
875 "<FONT SIZE=\"-1\">%s</FONT></TH></TR>\n",MISCCOLOR,msg_h_hname);
876 fprintf(out_fp,"<TR><TH HEIGHT=4></TH></TR>\n");
877
878 pointer=h_array; i=0;
879 while(tot_num)
880 {
881 hptr=*pointer++;
882 if (hptr->flag != OBJ_HIDE)
883 {
884 /* shade grouping? */
885 if (shade_groups && (hptr->flag==OBJ_GRP))
886 fprintf(out_fp,"<TR BGCOLOR=\"%s\">\n", GRPCOLOR);
887 else fprintf(out_fp,"<TR>\n");
888
889 fprintf(out_fp,
890 "<TD ALIGN=center><FONT SIZE=\"-1\"><B>%d</B></FONT></TD>\n" \
891 "<TD ALIGN=right><FONT SIZE=\"-1\"><B>%llu</B></FONT></TD>\n" \
892 "<TD ALIGN=right><FONT SIZE=\"-2\">%3.02f%%</FONT></TD>\n" \
893 "<TD ALIGN=right><FONT SIZE=\"-1\"><B>%llu</B></FONT></TD>\n" \
894 "<TD ALIGN=right><FONT SIZE=\"-2\">%3.02f%%</FONT></TD>\n" \
895 "<TD ALIGN=right><FONT SIZE=\"-1\"><B>%.0f</B></FONT></TD>\n" \
896 "<TD ALIGN=right><FONT SIZE=\"-2\">%3.02f%%</FONT></TD>\n" \
897 "<TD ALIGN=right><FONT SIZE=\"-1\"><B>%llu</B></FONT></TD>\n" \
898 "<TD ALIGN=right><FONT SIZE=\"-2\">%3.02f%%</FONT></TD>\n" \
899 "<TD ALIGN=left NOWRAP><FONT SIZE=\"-1\">",
900 i+1,hptr->count,
901 (t_hit==0)?0:((float)hptr->count/t_hit)*100.0,hptr->files,
902 (t_file==0)?0:((float)hptr->files/t_file)*100.0,hptr->xfer/1024,
903 (t_xfer==0)?0:((float)hptr->xfer/t_xfer)*100.0,hptr->visit,
904 (t_visit==0)?0:((float)hptr->visit/t_visit)*100.0);
905
906 if ((hptr->flag==OBJ_GRP)&&hlite_groups)
907 fprintf(out_fp,"<STRONG>%s</STRONG></FONT></TD></TR>\n",
908 hptr->string);
909 else fprintf(out_fp,"%s</FONT></TD></TR>\n",
910 hptr->string);
911 tot_num--;
912 i++;
913 }
914 }
915
916 fprintf(out_fp,"<TR><TH HEIGHT=4></TH></TR>\n");
917 if ((!flag) || (flag&&!ntop_sites))
918 {
919 if ( (all_sites) && ((h_reg+h_grp)>ntop_sites) )
920 {
921 if (all_sites_page(h_reg, h_grp))
922 {
923 fprintf(out_fp,"<TR BGCOLOR=\"%s\">",GRPCOLOR);
924 fprintf(out_fp,"<TD COLSPAN=10 ALIGN=\"center\">\n");
925 fprintf(out_fp,"<FONT SIZE=\"-1\">");
926 fprintf(out_fp,"<A HREF=\"./site_%04d%02d.%s\">",
927 cur_year,cur_month,html_ext);
928 fprintf(out_fp,"%s</A></TD></TR>\n",msg_v_sites);
929 if (flag) /* do we need to sort? */
930 qsort(h_array,a_ctr,sizeof(HNODEPTR),qs_site_cmph);
931 }
932 }
933 }
934 fprintf(out_fp,"</TABLE>\n<P>\n");
935}
936
937/*********************************************/
938/* ALL_SITES_PAGE - HTML page of all sites */
939/*********************************************/
940
941int all_sites_page(u_int64_t h_reg, u_int64_t h_grp)
942{
943 HNODEPTR hptr, *pointer;
944 char site_fname[256], buffer[256];
945 FILE *out_fp;
946 int i=(h_grp)?1:0;
947
948 /* generate file name */
949 snprintf(site_fname,sizeof(site_fname),"site_%04d%02d.%s",
950 cur_year,cur_month,html_ext);
951
952 /* open file */
953 if ( (out_fp=open_out_file(site_fname))==NULL ) return 0;
954
955 snprintf(buffer,sizeof(buffer),"%s %d - %s",
956 l_month[cur_month-1],cur_year,msg_h_sites);
957 write_html_head(buffer, out_fp);
958
959 fprintf(out_fp,"<FONT SIZE=\"-1\"></CENTER><PRE>\n");
960
961 fprintf(out_fp," %12s %12s %12s %12s %s\n",
962 msg_h_hits, msg_h_files, msg_h_xfer, msg_h_visits, msg_h_hname);
963 fprintf(out_fp,"---------------- ---------------- ---------------- " \
964 "---------------- --------------------\n\n");
965
966 /* Do groups first (if any) */
967 pointer=h_array;
968 while(h_grp)
969 {
970 hptr=*pointer++;
971 if (hptr->flag == OBJ_GRP)
972 {
973 fprintf(out_fp,
974 "%-8llu %6.02f%% %8llu %6.02f%% %8.0f %6.02f%% " \
975 "%8llu %6.02f%% %s\n",
976 hptr->count,
977 (t_hit==0)?0:((float)hptr->count/t_hit)*100.0,hptr->files,
978 (t_file==0)?0:((float)hptr->files/t_file)*100.0,hptr->xfer/1024,
979 (t_xfer==0)?0:((float)hptr->xfer/t_xfer)*100.0,hptr->visit,
980 (t_visit==0)?0:((float)hptr->visit/t_visit)*100.0,
981 hptr->string);
982 h_grp--;
983 }
984 }
985
986 if (i) fprintf(out_fp,"\n");
987
988 /* Now do individual sites (if any) */
989 pointer=h_array;
990 if (!hide_sites) while(h_reg)
991 {
992 hptr=*pointer++;
993 if (hptr->flag == OBJ_REG)
994 {
995 fprintf(out_fp,
996 "%-8llu %6.02f%% %8llu %6.02f%% %8.0f %6.02f%% " \
997 "%8llu %6.02f%% %s\n",
998 hptr->count,
999 (t_hit==0)?0:((float)hptr->count/t_hit)*100.0,hptr->files,
1000 (t_file==0)?0:((float)hptr->files/t_file)*100.0,hptr->xfer/1024,
1001 (t_xfer==0)?0:((float)hptr->xfer/t_xfer)*100.0,hptr->visit,
1002 (t_visit==0)?0:((float)hptr->visit/t_visit)*100.0,
1003 hptr->string);
1004 h_reg--;
1005 }
1006 }
1007
1008 fprintf(out_fp,"</PRE></FONT>\n");
1009 write_html_tail(out_fp);
1010 fclose(out_fp);
1011 return 1;
1012}
1013
1014/*********************************************/
1015/* TOP_URLS_TABLE - generate top n table */
1016/*********************************************/
1017
1018void top_urls_table(int flag)
1019{
1020 u_int64_t cnt=0,u_reg=0,u_grp=0,u_hid=0, tot_num;
1021 int i;
1022 UNODEPTR uptr, *pointer;
1023
1024 cnt=a_ctr; pointer=u_array;
1025 while (cnt--)
1026 {
1027 /* calculate totals */
1028 switch ( (int)((UNODEPTR)(*pointer)->flag) )
1029 {
1030 case OBJ_REG: u_reg++; break;
1031 case OBJ_GRP: u_grp++; break;
1032 case OBJ_HIDE: u_hid++; break;
1033 }
1034 pointer++;
1035 }
1036
1037 if ( (tot_num=u_reg+u_grp)==0 ) return; /* split if none */
1038 i=(flag)?ntop_urlsK:ntop_urls; /* Hits or KBytes?? */
1039 if (tot_num > i) tot_num = i; /* get max to do... */
1040 if ((!flag) || (flag&&!ntop_urls)) /* now do <A> tag */
1041 fprintf(out_fp,"<A NAME=\"TOPURLS\"></A>\n");
1042
1043 fprintf(out_fp,"<TABLE WIDTH=510 BORDER=2 CELLSPACING=1 CELLPADDING=1>\n");
1044 fprintf(out_fp,"<TR><TH HEIGHT=4></TH></TR>\n");
1045 if (flag) fprintf(out_fp,"<TR><TH BGCOLOR=\"%s\" ALIGN=CENTER COLSPAN=6>" \
1046 "%s %llu %s %llu %s %s %s</TH></TR>\n",
1047 GREY,msg_top_top,tot_num,msg_top_of,
1048 t_url,msg_top_u,msg_h_by,msg_h_xfer);
1049 else fprintf(out_fp,"<TR><TH BGCOLOR=\"%s\" ALIGN=CENTER COLSPAN=6>" \
1050 "%s %llu %s %llu %s</TH></TR>\n",
1051 GREY,msg_top_top,tot_num,msg_top_of,t_url,msg_top_u);
1052 fprintf(out_fp,"<TR><TH HEIGHT=4></TH></TR>\n");
1053 fprintf(out_fp,"<TR><TH BGCOLOR=\"%s\" ALIGN=center>" \
1054 "<FONT SIZE=\"-1\">#</FONT></TH>\n",GREY);
1055 fprintf(out_fp,"<TH BGCOLOR=\"%s\" ALIGN=center COLSPAN=2>" \
1056 "<FONT SIZE=\"-1\">%s</FONT></TH>\n",
1057 HITCOLOR,msg_h_hits);
1058 fprintf(out_fp,"<TH BGCOLOR=\"%s\" ALIGN=center COLSPAN=2>" \
1059 "<FONT SIZE=\"-1\">%s</FONT></TH>\n",
1060 KBYTECOLOR,msg_h_xfer);
1061 fprintf(out_fp,"<TH BGCOLOR=\"%s\" ALIGN=center>" \
1062 "<FONT SIZE=\"-1\">%s</FONT></TH></TR>\n",
1063 MISCCOLOR,msg_h_url);
1064 fprintf(out_fp,"<TR><TH HEIGHT=4></TH></TR>\n");
1065
1066 pointer=u_array; i=0;
1067 while (tot_num)
1068 {
1069 uptr=*pointer++; /* point to the URL node */
1070 if (uptr->flag != OBJ_HIDE)
1071 {
1072 /* shade grouping? */
1073 if (shade_groups && (uptr->flag==OBJ_GRP))
1074 fprintf(out_fp,"<TR BGCOLOR=\"%s\">\n", GRPCOLOR);
1075 else fprintf(out_fp,"<TR>\n");
1076
1077 fprintf(out_fp,
1078 "<TD ALIGN=center><FONT SIZE=\"-1\"><B>%d</B></FONT></TD>\n" \
1079 "<TD ALIGN=right><FONT SIZE=\"-1\"><B>%llu</B></FONT></TD>\n"\
1080 "<TD ALIGN=right><FONT SIZE=\"-2\">%3.02f%%</FONT></TD>\n" \
1081 "<TD ALIGN=right><FONT SIZE=\"-1\"><B>%.0f</B></FONT></TD>\n"\
1082 "<TD ALIGN=right><FONT SIZE=\"-2\">%3.02f%%</FONT></TD>\n" \
1083 "<TD ALIGN=left NOWRAP><FONT SIZE=\"-1\">",
1084 i+1,uptr->count,
1085 (t_hit==0)?0:((float)uptr->count/t_hit)*100.0,
1086 uptr->xfer/1024,
1087 (t_xfer==0)?0:((float)uptr->xfer/t_xfer)*100.0);
1088
1089 if (uptr->flag==OBJ_GRP)
1090 {
1091 if (hlite_groups)
1092 fprintf(out_fp,"<STRONG>%s</STRONG></FONT></TD></TR>\n",
1093 uptr->string);
1094 else fprintf(out_fp,"%s</FONT></TD></TR>\n",uptr->string);
1095 }
1096 else
1097 {
1098 /* check for a service prefix (ie: http://) */
1099 if (strstr(uptr->string,"://")!=NULL)
1100 fprintf(out_fp,"<A HREF=\"%s\">%s</A></FONT></TD></TR>\n",
1101 uptr->string,uptr->string);
1102 else
1103 {
1104 if (log_type == LOG_FTP) /* FTP log? */
1105 fprintf(out_fp,"%s</FONT></TD></TR>\n",uptr->string);
1106 else
1107 { /* Web log */
1108 if (use_https)
1109 /* secure server mode, use https:// */
1110 fprintf(out_fp,
1111 "<A HREF=\"https://%s%s\">%s</A></FONT></TD></TR>\n",
1112 hname,uptr->string,uptr->string);
1113 else
1114 /* otherwise use standard 'http://' */
1115 fprintf(out_fp,
1116 "<A HREF=\"http://%s%s\">%s</A></FONT></TD></TR>\n",
1117 hname,uptr->string,uptr->string);
1118 }
1119 }
1120 }
1121 tot_num--;
1122 i++;
1123 }
1124 }
1125 fprintf(out_fp,"<TR><TH HEIGHT=4></TH></TR>\n");
1126 if ((!flag) || (flag&&!ntop_urls))
1127 {
1128 if ( (all_urls) && ((u_reg+u_grp)>ntop_urls) )
1129 {
1130 if (all_urls_page(u_reg, u_grp))
1131 {
1132 fprintf(out_fp,"<TR BGCOLOR=\"%s\">",GRPCOLOR);
1133 fprintf(out_fp,"<TD COLSPAN=6 ALIGN=\"center\">\n");
1134 fprintf(out_fp,"<FONT SIZE=\"-1\">");
1135 fprintf(out_fp,"<A HREF=\"./url_%04d%02d.%s\">",
1136 cur_year,cur_month,html_ext);
1137 fprintf(out_fp,"%s</A></TD></TR>\n",msg_v_urls);
1138 if (flag) /* do we need to sort first? */
1139 qsort(u_array,a_ctr,sizeof(UNODEPTR),qs_url_cmph);
1140 }
1141 }
1142 }
1143 fprintf(out_fp,"</TABLE>\n<P>\n");
1144}
1145
1146/*********************************************/
1147/* ALL_URLS_PAGE - HTML page of all urls */
1148/*********************************************/
1149
1150int all_urls_page(u_int64_t u_reg, u_int64_t u_grp)
1151{
1152 UNODEPTR uptr, *pointer;
1153 char url_fname[256], buffer[256];
1154 FILE *out_fp;
1155 int i=(u_grp)?1:0;
1156
1157 /* generate file name */
1158 snprintf(url_fname,sizeof(url_fname),"url_%04d%02d.%s",
1159 cur_year,cur_month,html_ext);
1160
1161 /* open file */
1162 if ( (out_fp=open_out_file(url_fname))==NULL ) return 0;
1163
1164 snprintf(buffer,sizeof(buffer),"%s %d - %s",
1165 l_month[cur_month-1],cur_year,msg_h_url);
1166 write_html_head(buffer, out_fp);
1167
1168 fprintf(out_fp,"<FONT SIZE=\"-1\"></CENTER><PRE>\n");
1169
1170 fprintf(out_fp," %12s %12s %s\n",
1171 msg_h_hits,msg_h_xfer,msg_h_url);
1172 fprintf(out_fp,"---------------- ---------------- " \
1173 "--------------------\n\n");
1174
1175 /* do groups first (if any) */
1176 pointer=u_array;
1177 while (u_grp)
1178 {
1179 uptr=*pointer++;
1180 if (uptr->flag == OBJ_GRP)
1181 {
1182 fprintf(out_fp,"%-8llu %6.02f%% %8.0f %6.02f%% %s\n",
1183 uptr->count,
1184 (t_hit==0)?0:((float)uptr->count/t_hit)*100.0,
1185 uptr->xfer/1024,
1186 (t_xfer==0)?0:((float)uptr->xfer/t_xfer)*100.0,
1187 uptr->string);
1188 u_grp--;
1189 }
1190 }
1191
1192 if (i) fprintf(out_fp,"\n");
1193
1194 /* now do invididual sites (if any) */
1195 pointer=u_array;
1196 while (u_reg)
1197 {
1198 uptr=*pointer++;
1199 if (uptr->flag == OBJ_REG)
1200 {
1201 fprintf(out_fp,"%-8llu %6.02f%% %8.0f %6.02f%% %s\n",
1202 uptr->count,
1203 (t_hit==0)?0:((float)uptr->count/t_hit)*100.0,
1204 uptr->xfer/1024,
1205 (t_xfer==0)?0:((float)uptr->xfer/t_xfer)*100.0,
1206 uptr->string);
1207 u_reg--;
1208 }
1209 }
1210
1211 fprintf(out_fp,"</PRE></FONT>\n");
1212 write_html_tail(out_fp);
1213 fclose(out_fp);
1214 return 1;
1215}
1216
1217/*********************************************/
1218/* TOP_ENTRY_TABLE - top n entry/exit urls */
1219/*********************************************/
1220
1221void top_entry_table(int flag)
1222{
1223 u_int64_t cnt=0, u_entry=0, u_exit=0, tot_num;
1224 u_int64_t t_entry=0, t_exit=0;
1225 int i;
1226 UNODEPTR uptr, *pointer;
1227
1228 cnt=a_ctr; pointer=u_array;
1229 while (cnt--)
1230 {
1231 if ( (int)((UNODEPTR)(*pointer)->flag) == OBJ_REG )
1232 {
1233 if ( (u_int64_t)(((UNODEPTR)(*pointer))->entry) )
1234 { u_entry++; t_entry+=(u_int64_t)(((UNODEPTR)(*pointer))->entry); }
1235 if ( (u_int64_t)(((UNODEPTR)(*pointer))->exit) )
1236 { u_exit++; t_exit +=(u_int64_t)(((UNODEPTR)(*pointer))->exit); }
1237 }
1238 pointer++;
1239 }
1240
1241 /* calculate how many we have */
1242 tot_num=(flag)?u_exit:u_entry;
1243 if (flag) { if (tot_num > ntop_exit ) tot_num=ntop_exit; }
1244 else { if (tot_num > ntop_entry) tot_num=ntop_entry; }
1245
1246 /* return if none to do */
1247 if (!tot_num) return;
1248
1249 if (flag) fprintf(out_fp,"<A NAME=\"TOPEXIT\"></A>\n"); /* do anchor tag */
1250 else fprintf(out_fp,"<A NAME=\"TOPENTRY\"></A>\n");
1251
1252 fprintf(out_fp,"<TABLE WIDTH=510 BORDER=2 CELLSPACING=1 CELLPADDING=1>\n");
1253 fprintf(out_fp,"<TR><TH HEIGHT=4></TH></TR>\n");
1254 fprintf(out_fp,"<TR><TH BGCOLOR=\"%s\" ALIGN=CENTER COLSPAN=6>" \
1255 "%s %llu %s %llu %s</TH></TR>\n",
1256 GREY,msg_top_top,tot_num,msg_top_of,
1257 (flag)?u_exit:u_entry,(flag)?msg_top_ex:msg_top_en);
1258 fprintf(out_fp,"<TR><TH HEIGHT=4></TH></TR>\n");
1259 fprintf(out_fp,"<TR><TH BGCOLOR=\"%s\" ALIGN=center>" \
1260 "<FONT SIZE=\"-1\">#</FONT></TH>\n",
1261 GREY);
1262 fprintf(out_fp,"<TH BGCOLOR=\"%s\" ALIGN=center COLSPAN=2>" \
1263 "<FONT SIZE=\"-1\">%s</FONT></TH>\n",
1264 HITCOLOR,msg_h_hits);
1265 fprintf(out_fp,"<TH BGCOLOR=\"%s\" ALIGN=center COLSPAN=2>" \
1266 "<FONT SIZE=\"-1\">%s</FONT></TH>\n",
1267 VISITCOLOR,msg_h_visits);
1268 fprintf(out_fp,"<TH BGCOLOR=\"%s\" ALIGN=center>" \
1269 "<FONT SIZE=\"-1\">%s</FONT></TH></TR>\n",
1270 MISCCOLOR,msg_h_url);
1271 fprintf(out_fp,"<TR><TH HEIGHT=4></TH></TR>\n");
1272
1273 pointer=u_array; i=0;
1274 while (tot_num)
1275 {
1276 uptr=*pointer++;
1277 if (uptr->flag != OBJ_HIDE)
1278 {
1279 fprintf(out_fp,"<TR>\n");
1280 fprintf(out_fp,
1281 "<TD ALIGN=center><FONT SIZE=\"-1\"><B>%d</B></FONT></TD>\n" \
1282 "<TD ALIGN=right><FONT SIZE=\"-1\"><B>%llu</B></FONT></TD>\n"\
1283 "<TD ALIGN=right><FONT SIZE=\"-2\">%3.02f%%</FONT></TD>\n" \
1284 "<TD ALIGN=right><FONT SIZE=\"-1\"><B>%llu</B></FONT></TD>\n"\
1285 "<TD ALIGN=right><FONT SIZE=\"-2\">%3.02f%%</FONT></TD>\n" \
1286 "<TD ALIGN=left NOWRAP><FONT SIZE=\"-1\">",
1287 i+1,uptr->count,
1288 (t_hit==0)?0:((float)uptr->count/t_hit)*100.0,
1289 (flag)?uptr->exit:uptr->entry,
1290 (flag)?((t_exit==0)?0:((float)uptr->exit/t_exit)*100.0)
1291 :((t_entry==0)?0:((float)uptr->entry/t_entry)*100.0));
1292
1293 /* check for a service prefix (ie: http://) */
1294 if (strstr(uptr->string,"://")!=NULL)
1295 fprintf(out_fp,
1296 "<A HREF=\"%s\">%s</A></FONT></TD></TR>\n",
1297 uptr->string,uptr->string);
1298 else
1299 {
1300 if (use_https)
1301 /* secure server mode, use https:// */
1302 fprintf(out_fp,
1303 "<A HREF=\"https://%s%s\">%s</A></FONT></TD></TR>\n",
1304 hname,uptr->string,uptr->string);
1305 else
1306 /* otherwise use standard 'http://' */
1307 fprintf(out_fp,
1308 "<A HREF=\"http://%s%s\">%s</A></FONT></TD></TR>\n",
1309 hname,uptr->string,uptr->string);
1310 }
1311 tot_num--;
1312 i++;
1313 }
1314 }
1315 fprintf(out_fp,"<TR><TH HEIGHT=4></TH></TR>\n");
1316 fprintf(out_fp,"</TABLE>\n<P>\n");
1317}
1318
1319/*********************************************/
1320/* TOP_REFS_TABLE - generate top n table */
1321/*********************************************/
1322
1323void top_refs_table()
1324{
1325 u_int64_t cnt=0, r_reg=0, r_grp=0, r_hid=0, tot_num;
1326 int i;
1327 RNODEPTR rptr, *pointer;
1328
1329 if (t_ref==0) return; /* return if none to process */
1330
1331 cnt=a_ctr; pointer=r_array;
1332 while(cnt--)
1333 {
1334 /* calculate totals */
1335 switch ( (int)((RNODEPTR)(*pointer)->flag) )
1336 {
1337 case OBJ_REG: r_reg++; break;
1338 case OBJ_HIDE: r_hid++; break;
1339 case OBJ_GRP: r_grp++; break;
1340 }
1341 pointer++;
1342 }
1343
1344 if ( (tot_num=r_reg+r_grp)==0 ) return; /* split if none */
1345 if (tot_num > ntop_refs) tot_num=ntop_refs; /* get max to do... */
1346
1347 fprintf(out_fp,"<A NAME=\"TOPREFS\"></A>\n");
1348 fprintf(out_fp,"<TABLE WIDTH=510 BORDER=2 CELLSPACING=1 CELLPADDING=1>\n");
1349 fprintf(out_fp,"<TR><TH HEIGHT=4></TH></TR>\n");
1350 fprintf(out_fp,"<TR><TH BGCOLOR=\"%s\" ALIGN=CENTER COLSPAN=4>" \
1351 "%s %llu %s %llu %s</TH></TR>\n",
1352 GREY, msg_top_top, tot_num, msg_top_of, t_ref, msg_top_r);
1353 fprintf(out_fp,"<TR><TH HEIGHT=4></TH></TR>\n");
1354 fprintf(out_fp,"<TR><TH BGCOLOR=\"%s\" ALIGN=center>" \
1355 "<FONT SIZE=\"-1\">#</FONT></TH>\n",
1356 GREY);
1357 fprintf(out_fp,"<TH BGCOLOR=\"%s\" ALIGN=center COLSPAN=2>" \
1358 "<FONT SIZE=\"-1\">%s</FONT></TH>\n",
1359 HITCOLOR,msg_h_hits);
1360 fprintf(out_fp,"<TH BGCOLOR=\"%s\" ALIGN=center>" \
1361 "<FONT SIZE=\"-1\">%s</FONT></TH></TR>\n",
1362 MISCCOLOR,msg_h_ref);
1363 fprintf(out_fp,"<TR><TH HEIGHT=4></TH></TR>\n");
1364
1365 pointer=r_array; i=0;
1366 while(tot_num)
1367 {
1368 rptr=*pointer++;
1369 if (rptr->flag != OBJ_HIDE)
1370 {
1371 /* shade grouping? */
1372 if (shade_groups && (rptr->flag==OBJ_GRP))
1373 fprintf(out_fp,"<TR BGCOLOR=\"%s\">\n", GRPCOLOR);
1374 else fprintf(out_fp,"<TR>\n");
1375
1376 fprintf(out_fp,
1377 "<TD ALIGN=center><FONT SIZE=\"-1\"><B>%d</B></FONT></TD>\n" \
1378 "<TD ALIGN=right><FONT SIZE=\"-1\"><B>%llu</B></FONT></TD>\n" \
1379 "<TD ALIGN=right><FONT SIZE=\"-2\">%3.02f%%</FONT></TD>\n" \
1380 "<TD ALIGN=left NOWRAP><FONT SIZE=\"-1\">",
1381 i+1,rptr->count,
1382 (t_hit==0)?0:((float)rptr->count/t_hit)*100.0);
1383
1384 if (rptr->flag==OBJ_GRP)
1385 {
1386 if (hlite_groups)
1387 fprintf(out_fp,"<STRONG>%s</STRONG>",rptr->string);
1388 else fprintf(out_fp,"%s",rptr->string);
1389 }
1390 else
1391 {
1392 /* only link if enabled and has a service prefix */
1393 if ( (strstr(rptr->string,"://")!=NULL) && link_referrer )
1394 fprintf(out_fp,"<A HREF=\"%s\" rel=\"nofollow\">%s</A>",
1395 rptr->string, rptr->string);
1396 else
1397 fprintf(out_fp,"%s", rptr->string);
1398 }
1399 fprintf(out_fp,"</FONT></TD></TR>\n");
1400 tot_num--;
1401 i++;
1402 }
1403 }
1404 fprintf(out_fp,"<TR><TH HEIGHT=4></TH></TR>\n");
1405 if ( (all_refs) && ((r_reg+r_grp)>ntop_refs) )
1406 {
1407 if (all_refs_page(r_reg, r_grp))
1408 {
1409 fprintf(out_fp,"<TR BGCOLOR=\"%s\">",GRPCOLOR);
1410 fprintf(out_fp,"<TD COLSPAN=4 ALIGN=\"center\">\n");
1411 fprintf(out_fp,"<FONT SIZE=\"-1\">");
1412 fprintf(out_fp,"<A HREF=\"./ref_%04d%02d.%s\">",
1413 cur_year,cur_month,html_ext);
1414 fprintf(out_fp,"%s</A></TD></TR>\n",msg_v_refs);
1415 }
1416 }
1417 fprintf(out_fp,"</TABLE>\n<P>\n");
1418}
1419
1420/*********************************************/
1421/* ALL_REFS_PAGE - HTML page of all refs */
1422/*********************************************/
1423
1424int all_refs_page(u_int64_t r_reg, u_int64_t r_grp)
1425{
1426 RNODEPTR rptr, *pointer;
1427 char ref_fname[256], buffer[256];
1428 FILE *out_fp;
1429 int i=(r_grp)?1:0;
1430
1431 /* generate file name */
1432 snprintf(ref_fname,sizeof(ref_fname),"ref_%04d%02d.%s",
1433 cur_year,cur_month,html_ext);
1434
1435 /* open file */
1436 if ( (out_fp=open_out_file(ref_fname))==NULL ) return 0;
1437
1438 snprintf(buffer,sizeof(buffer),"%s %d - %s",
1439 l_month[cur_month-1],cur_year,msg_h_ref);
1440 write_html_head(buffer, out_fp);
1441
1442 fprintf(out_fp,"<FONT SIZE=\"-1\"></CENTER><PRE>\n");
1443
1444 fprintf(out_fp," %12s %s\n",msg_h_hits,msg_h_ref);
1445 fprintf(out_fp,"---------------- --------------------\n\n");
1446
1447 /* do groups first (if any) */
1448 pointer=r_array;
1449 while(r_grp)
1450 {
1451 rptr=*pointer++;
1452 if (rptr->flag == OBJ_GRP)
1453 {
1454 fprintf(out_fp,"%-8llu %6.02f%% %s\n",
1455 rptr->count,
1456 (t_hit==0)?0:((float)rptr->count/t_hit)*100.0,
1457 rptr->string);
1458 r_grp--;
1459 }
1460 }
1461
1462 if (i) fprintf(out_fp,"\n");
1463
1464 pointer=r_array;
1465 while(r_reg)
1466 {
1467 rptr=*pointer++;
1468 if (rptr->flag == OBJ_REG)
1469 {
1470 fprintf(out_fp,"%-8llu %6.02f%% %s\n",
1471 rptr->count,
1472 (t_hit==0)?0:((float)rptr->count/t_hit)*100.0,
1473 rptr->string);
1474 r_reg--;
1475 }
1476 }
1477
1478 fprintf(out_fp,"</PRE></FONT>\n");
1479 write_html_tail(out_fp);
1480 fclose(out_fp);
1481 return 1;
1482}
1483
1484/*********************************************/
1485/* TOP_AGENTS_TABLE - generate top n table */
1486/*********************************************/
1487
1488void top_agents_table()
1489{
1490 u_int64_t cnt, a_reg=0, a_grp=0, a_hid=0, tot_num;
1491 int i;
1492 ANODEPTR aptr, *pointer;
1493
1494 if (t_agent == 0) return; /* don't bother if we don't have any */
1495
1496 cnt=a_ctr; pointer=a_array;
1497 while(cnt--)
1498 {
1499 /* calculate totals */
1500 switch ( (int)((ANODEPTR)(*pointer)->flag) )
1501 {
1502 case OBJ_REG: a_reg++; break;
1503 case OBJ_GRP: a_grp++; break;
1504 case OBJ_HIDE: a_hid++; break;
1505 }
1506 pointer++;
1507 }
1508
1509 if ( (tot_num=a_reg+a_grp)==0 ) return; /* split if none */
1510 if (tot_num > ntop_agents) tot_num=ntop_agents; /* get max to do... */
1511
1512 fprintf(out_fp,"<A NAME=\"TOPAGENTS\"></A>\n");
1513 fprintf(out_fp,"<TABLE WIDTH=510 BORDER=2 CELLSPACING=1 CELLPADDING=1>\n");
1514 fprintf(out_fp,"<TR><TH HEIGHT=4></TH></TR>\n");
1515 fprintf(out_fp,"<TR><TH BGCOLOR=\"%s\" ALIGN=CENTER COLSPAN=4>" \
1516 "%s %llu %s %llu %s</TH></TR>\n",
1517 GREY, msg_top_top, tot_num, msg_top_of, t_agent, msg_top_a);
1518 fprintf(out_fp,"<TR><TH HEIGHT=4></TH></TR>\n");
1519 fprintf(out_fp,"<TR><TH BGCOLOR=\"%s\" ALIGN=center>" \
1520 "<FONT SIZE=\"-1\">#</FONT></TH>\n",
1521 GREY);
1522 fprintf(out_fp,"<TH BGCOLOR=\"%s\" ALIGN=center COLSPAN=2>" \
1523 "<FONT SIZE=\"-1\">%s</FONT></TH>\n",
1524 HITCOLOR,msg_h_hits);
1525 fprintf(out_fp,"<TH BGCOLOR=\"%s\" ALIGN=center>" \
1526 "<FONT SIZE=\"-1\">%s</FONT></TH></TR>\n",
1527 MISCCOLOR,msg_h_agent);
1528 fprintf(out_fp,"<TR><TH HEIGHT=4></TH></TR>\n");
1529
1530 pointer=a_array; i=0;
1531 while(tot_num)
1532 {
1533 aptr=*pointer++;
1534 if (aptr->flag != OBJ_HIDE)
1535 {
1536 /* shade grouping? */
1537 if (shade_groups && (aptr->flag==OBJ_GRP))
1538 fprintf(out_fp,"<TR BGCOLOR=\"%s\">\n", GRPCOLOR);
1539 else fprintf(out_fp,"<TR>\n");
1540
1541 fprintf(out_fp,
1542 "<TD ALIGN=center><FONT SIZE=\"-1\"><B>%d</B></FONT></TD>\n" \
1543 "<TD ALIGN=right><FONT SIZE=\"-1\"><B>%llu</B></FONT></TD>\n"\
1544 "<TD ALIGN=right><FONT SIZE=\"-2\">%3.02f%%</FONT></TD>\n" \
1545 "<TD ALIGN=left NOWRAP><FONT SIZE=\"-1\">",
1546 i+1,aptr->count,
1547 (t_hit==0)?0:((float)aptr->count/t_hit)*100.0);
1548
1549 if ((aptr->flag==OBJ_GRP)&&hlite_groups)
1550 fprintf(out_fp,"<STRONG>%s</STRONG></FONT></TD></TR>\n",
1551 aptr->string);
1552 else fprintf(out_fp,"%s</FONT></TD></TR>\n",
1553 aptr->string);
1554 tot_num--;
1555 i++;
1556 }
1557 }
1558 fprintf(out_fp,"<TR><TH HEIGHT=4></TH></TR>\n");
1559 if ( (all_agents) && ((a_reg+a_grp)>ntop_agents) )
1560 {
1561 if (all_agents_page(a_reg, a_grp))
1562 {
1563 fprintf(out_fp,"<TR BGCOLOR=\"%s\">",GRPCOLOR);
1564 fprintf(out_fp,"<TD COLSPAN=4 ALIGN=\"center\">\n");
1565 fprintf(out_fp,"<FONT SIZE=\"-1\">");
1566 fprintf(out_fp,"<A HREF=\"./agent_%04d%02d.%s\">",
1567 cur_year,cur_month,html_ext);
1568 fprintf(out_fp,"%s</A></TD></TR>\n",msg_v_agents);
1569 }
1570 }
1571 fprintf(out_fp,"</TABLE>\n<P>\n");
1572}
1573
1574/*********************************************/
1575/* ALL_AGENTS_PAGE - HTML user agent page */
1576/*********************************************/
1577
1578int all_agents_page(u_int64_t a_reg, u_int64_t a_grp)
1579{
1580 ANODEPTR aptr, *pointer;
1581 char agent_fname[256], buffer[256];
1582 FILE *out_fp;
1583 int i=(a_grp)?1:0;
1584
1585 /* generate file name */
1586 snprintf(agent_fname,sizeof(agent_fname),"agent_%04d%02d.%s",
1587 cur_year,cur_month,html_ext);
1588
1589 /* open file */
1590 if ( (out_fp=open_out_file(agent_fname))==NULL ) return 0;
1591
1592 snprintf(buffer,sizeof(buffer),"%s %d - %s",
1593 l_month[cur_month-1],cur_year,msg_h_agent);
1594 write_html_head(buffer, out_fp);
1595
1596 fprintf(out_fp,"<FONT SIZE=\"-1\"></CENTER><PRE>\n");
1597
1598 fprintf(out_fp," %12s %s\n",msg_h_hits,msg_h_agent);
1599 fprintf(out_fp,"---------------- ----------------------\n\n");
1600
1601 /* do groups first (if any) */
1602 pointer=a_array;
1603 while(a_grp)
1604 {
1605 aptr=*pointer++;
1606 if (aptr->flag == OBJ_GRP)
1607 {
1608 fprintf(out_fp,"%-8llu %6.02f%% %s\n",
1609 aptr->count,
1610 (t_hit==0)?0:((float)aptr->count/t_hit)*100.0,
1611 aptr->string);
1612 a_grp--;
1613 }
1614 }
1615
1616 if (i) fprintf(out_fp,"\n");
1617
1618 pointer=a_array;
1619 while(a_reg)
1620 {
1621 aptr=*pointer++;
1622 if (aptr->flag == OBJ_REG)
1623 {
1624 fprintf(out_fp,"%-8llu %6.02f%% %s\n",
1625 aptr->count,
1626 (t_hit==0)?0:((float)aptr->count/t_hit)*100.0,
1627 aptr->string);
1628 a_reg--;
1629 }
1630 }
1631
1632 fprintf(out_fp,"</PRE></FONT>\n");
1633 write_html_tail(out_fp);
1634 fclose(out_fp);
1635 return 1;
1636}
1637
1638/*********************************************/
1639/* TOP_SEARCH_TABLE - generate top n table */
1640/*********************************************/
1641
1642void top_search_table()
1643{
1644 u_int64_t cnt,t_val=0, tot_num;
1645 int i;
1646 SNODEPTR sptr, *pointer;
1647
1648 if (a_ctr==0) return; /* don't bother if none to do */
1649
1650 cnt=tot_num=a_ctr; pointer=s_array;
1651 while(cnt--)
1652 {
1653 t_val+=(u_int64_t)(((SNODEPTR)(*pointer))->count);
1654 pointer++;
1655 }
1656
1657 if ( tot_num > ntop_search) tot_num=ntop_search;
1658
1659 fprintf(out_fp,"<A NAME=\"TOPSEARCH\"></A>\n");
1660 fprintf(out_fp,"<TABLE WIDTH=510 BORDER=2 CELLSPACING=1 CELLPADDING=1>\n");
1661 fprintf(out_fp,"<TR><TH HEIGHT=4></TH></TR>\n");
1662 fprintf(out_fp,"<TR><TH BGCOLOR=\"%s\" ALIGN=CENTER COLSPAN=4>" \
1663 "%s %llu %s %llu %s</TH></TR>\n",
1664 GREY, msg_top_top, tot_num, msg_top_of, a_ctr, msg_top_sr);
1665 fprintf(out_fp,"<TR><TH HEIGHT=4></TH></TR>\n");
1666 fprintf(out_fp,"<TR><TH BGCOLOR=\"%s\" ALIGN=center>" \
1667 "<FONT SIZE=\"-1\">#</FONT></TH>\n",
1668 GREY);
1669 fprintf(out_fp,"<TH BGCOLOR=\"%s\" ALIGN=center COLSPAN=2>" \
1670 "<FONT SIZE=\"-1\">%s</FONT></TH>\n",
1671 HITCOLOR,msg_h_hits);
1672 fprintf(out_fp,"<TH BGCOLOR=\"%s\" ALIGN=center>" \
1673 "<FONT SIZE=\"-1\">%s</FONT></TH></TR>\n",
1674 MISCCOLOR,msg_h_search);
1675 fprintf(out_fp,"<TR><TH HEIGHT=4></TH></TR>\n");
1676
1677 pointer=s_array; i=0;
1678 while(tot_num)
1679 {
1680 sptr=*pointer++;
1681 fprintf(out_fp,
1682 "<TR>\n" \
1683 "<TD ALIGN=center><FONT SIZE=\"-1\"><B>%d</B></FONT></TD>\n" \
1684 "<TD ALIGN=right><FONT SIZE=\"-1\"><B>%llu</B></FONT></TD>\n"\
1685 "<TD ALIGN=right><FONT SIZE=\"-2\">%3.02f%%</FONT></TD>\n" \
1686 "<TD ALIGN=left NOWRAP><FONT SIZE=\"-1\">",
1687 i+1,sptr->count,
1688 (t_val==0)?0:((float)sptr->count/t_val)*100.0);
1689 fprintf(out_fp,"%s</FONT></TD></TR>\n",sptr->string);
1690 tot_num--;
1691 i++;
1692 }
1693 fprintf(out_fp,"<TR><TH HEIGHT=4></TH></TR>\n");
1694 if ( (all_search) && (a_ctr>ntop_search) )
1695 {
1696 if (all_search_page(a_ctr, t_val))
1697 {
1698 fprintf(out_fp,"<TR BGCOLOR=\"%s\">",GRPCOLOR);
1699 fprintf(out_fp,"<TD COLSPAN=4 ALIGN=\"center\">\n");
1700 fprintf(out_fp,"<FONT SIZE=\"-1\">");
1701 fprintf(out_fp,"<A HREF=\"./search_%04d%02d.%s\">",
1702 cur_year,cur_month,html_ext);
1703 fprintf(out_fp,"%s</A></TD></TR>\n",msg_v_search);
1704 }
1705 }
1706 fprintf(out_fp,"</TABLE>\n<P>\n");
1707}
1708
1709/*********************************************/
1710/* ALL_SEARCH_PAGE - HTML for search strings */
1711/*********************************************/
1712
1713int all_search_page(u_int64_t tot_num, u_int64_t t_val)
1714{
1715 SNODEPTR sptr, *pointer;
1716 char search_fname[256], buffer[256];
1717 FILE *out_fp;
1718
1719 if (!tot_num) return 0;
1720
1721 /* generate file name */
1722 snprintf(search_fname,sizeof(search_fname),"search_%04d%02d.%s",
1723 cur_year,cur_month,html_ext);
1724
1725 /* open file */
1726 if ( (out_fp=open_out_file(search_fname))==NULL ) return 0;
1727
1728 snprintf(buffer,sizeof(buffer),"%s %d - %s",
1729 l_month[cur_month-1],cur_year,msg_h_search);
1730 write_html_head(buffer, out_fp);
1731
1732 fprintf(out_fp,"<FONT SIZE=\"-1\"></CENTER><PRE>\n");
1733
1734 fprintf(out_fp," %12s %s\n",msg_h_hits,msg_h_search);
1735 fprintf(out_fp,"---------------- ----------------------\n\n");
1736
1737 pointer=s_array;
1738 while(tot_num)
1739 {
1740 sptr=*pointer++;
1741 fprintf(out_fp,"%-8llu %6.02f%% %s\n",
1742 sptr->count,
1743 (t_val==0)?0:((float)sptr->count/t_val)*100.0,
1744 sptr->string);
1745 tot_num--;
1746 }
1747 fprintf(out_fp,"</PRE></FONT>\n");
1748 write_html_tail(out_fp);
1749 fclose(out_fp);
1750 return 1;
1751}
1752
1753/*********************************************/
1754/* TOP_USERS_TABLE - generate top n table */
1755/*********************************************/
1756
1757void top_users_table()
1758{
1759 u_int64_t cnt=0, i_reg=0, i_grp=0, i_hid=0, tot_num;
1760 int i;
1761 INODEPTR iptr, *pointer;
1762
1763 cnt=a_ctr; pointer=i_array;
1764 while(cnt--)
1765 {
1766 /* calculate totals */
1767 switch ( (int)((INODEPTR)(*pointer)->flag) )
1768 {
1769 case OBJ_REG: i_reg++; break;
1770 case OBJ_GRP: i_grp++; break;
1771 case OBJ_HIDE: i_hid++; break;
1772 }
1773 pointer++;
1774 }
1775
1776 if ( (tot_num=i_reg+i_grp)==0 ) return; /* split if none */
1777 if (tot_num > ntop_users) tot_num = ntop_users;
1778
1779 fprintf(out_fp,"<A NAME=\"TOPUSERS\"></A>\n"); /* now do <A> tag */
1780
1781 fprintf(out_fp,"<TABLE WIDTH=510 BORDER=2 CELLSPACING=1 CELLPADDING=1>\n");
1782 fprintf(out_fp,"<TR><TH HEIGHT=4></TH></TR>\n");
1783 fprintf(out_fp,"<TR><TH BGCOLOR=\"%s\" ALIGN=CENTER COLSPAN=10>" \
1784 "%s %llu %s %llu %s</TH></TR>\n",
1785 GREY,msg_top_top, tot_num, msg_top_of, t_user, msg_top_i);
1786 fprintf(out_fp,"<TR><TH HEIGHT=4></TH></TR>\n");
1787 fprintf(out_fp,"<TR><TH BGCOLOR=\"%s\" ALIGN=center>" \
1788 "<FONT SIZE=\"-1\">#</FONT></TH>\n",GREY);
1789 fprintf(out_fp,"<TH BGCOLOR=\"%s\" ALIGN=center COLSPAN=2>" \
1790 "<FONT SIZE=\"-1\">%s</FONT></TH>\n",HITCOLOR,msg_h_hits);
1791 fprintf(out_fp,"<TH BGCOLOR=\"%s\" ALIGN=center COLSPAN=2>" \
1792 "<FONT SIZE=\"-1\">%s</FONT></TH>\n",FILECOLOR,msg_h_files);
1793 fprintf(out_fp,"<TH BGCOLOR=\"%s\" ALIGN=center COLSPAN=2>" \
1794 "<FONT SIZE=\"-1\">%s</FONT></TH>\n",KBYTECOLOR,msg_h_xfer);
1795 fprintf(out_fp,"<TH BGCOLOR=\"%s\" ALIGN=center COLSPAN=2>" \
1796 "<FONT SIZE=\"-1\">%s</FONT></TH>\n",VISITCOLOR,msg_h_visits);
1797 fprintf(out_fp,"<TH BGCOLOR=\"%s\" ALIGN=center>" \
1798 "<FONT SIZE=\"-1\">%s</FONT></TH></TR>\n",MISCCOLOR,msg_h_uname);
1799 fprintf(out_fp,"<TR><TH HEIGHT=4></TH></TR>\n");
1800
1801 pointer=i_array; i=0;
1802 while(tot_num)
1803 {
1804 iptr=*pointer++;
1805 if (iptr->flag != OBJ_HIDE)
1806 {
1807 /* shade grouping? */
1808 if (shade_groups && (iptr->flag==OBJ_GRP))
1809 fprintf(out_fp,"<TR BGCOLOR=\"%s\">\n", GRPCOLOR);
1810 else fprintf(out_fp,"<TR>\n");
1811
1812 fprintf(out_fp,
1813 "<TD ALIGN=center><FONT SIZE=\"-1\"><B>%d</B></FONT></TD>\n" \
1814 "<TD ALIGN=right><FONT SIZE=\"-1\"><B>%llu</B></FONT></TD>\n" \
1815 "<TD ALIGN=right><FONT SIZE=\"-2\">%3.02f%%</FONT></TD>\n" \
1816 "<TD ALIGN=right><FONT SIZE=\"-1\"><B>%llu</B></FONT></TD>\n" \
1817 "<TD ALIGN=right><FONT SIZE=\"-2\">%3.02f%%</FONT></TD>\n" \
1818 "<TD ALIGN=right><FONT SIZE=\"-1\"><B>%.0f</B></FONT></TD>\n" \
1819 "<TD ALIGN=right><FONT SIZE=\"-2\">%3.02f%%</FONT></TD>\n" \
1820 "<TD ALIGN=right><FONT SIZE=\"-1\"><B>%llu</B></FONT></TD>\n" \
1821 "<TD ALIGN=right><FONT SIZE=\"-2\">%3.02f%%</FONT></TD>\n" \
1822 "<TD ALIGN=left NOWRAP><FONT SIZE=\"-1\">",
1823 i+1,iptr->count,
1824 (t_hit==0)?0:((float)iptr->count/t_hit)*100.0,iptr->files,
1825 (t_file==0)?0:((float)iptr->files/t_file)*100.0,iptr->xfer/1024,
1826 (t_xfer==0)?0:((float)iptr->xfer/t_xfer)*100.0,iptr->visit,
1827 (t_visit==0)?0:((float)iptr->visit/t_visit)*100.0);
1828
1829 if ((iptr->flag==OBJ_GRP)&&hlite_groups)
1830 fprintf(out_fp,"<STRONG>%s</STRONG></FONT></TD></TR>\n",
1831 iptr->string);
1832 else fprintf(out_fp,"%s</FONT></TD></TR>\n",
1833 iptr->string);
1834 tot_num--;
1835 i++;
1836 }
1837 }
1838
1839 fprintf(out_fp,"<TR><TH HEIGHT=4></TH></TR>\n");
1840 if ( (all_users) && ((i_reg+i_grp)>ntop_users) )
1841 {
1842 if (all_users_page(i_reg, i_grp))
1843 {
1844 fprintf(out_fp,"<TR BGCOLOR=\"%s\">",GRPCOLOR);
1845 fprintf(out_fp,"<TD COLSPAN=10 ALIGN=\"center\">\n");
1846 fprintf(out_fp,"<FONT SIZE=\"-1\">");
1847 fprintf(out_fp,"<A HREF=\"./user_%04d%02d.%s\">",
1848 cur_year,cur_month,html_ext);
1849 fprintf(out_fp,"%s</A></TD></TR>\n",msg_v_users);
1850 }
1851 }
1852 fprintf(out_fp,"</TABLE>\n<P>\n");
1853}
1854
1855/*********************************************/
1856/* ALL_USERS_PAGE - HTML of all usernames */
1857/*********************************************/
1858
1859int all_users_page(u_int64_t i_reg, u_int64_t i_grp)
1860{
1861 INODEPTR iptr, *pointer;
1862 char user_fname[256], buffer[256];
1863 FILE *out_fp;
1864 int i=(i_grp)?1:0;
1865
1866 /* generate file name */
1867 snprintf(user_fname,sizeof(user_fname),"user_%04d%02d.%s",
1868 cur_year,cur_month,html_ext);
1869
1870 /* open file */
1871 if ( (out_fp=open_out_file(user_fname))==NULL ) return 0;
1872
1873 snprintf(buffer,sizeof(buffer),"%s %d - %s",
1874 l_month[cur_month-1],cur_year,msg_h_uname);
1875 write_html_head(buffer, out_fp);
1876
1877 fprintf(out_fp,"<FONT SIZE=\"-1\"></CENTER><PRE>\n");
1878
1879 fprintf(out_fp," %12s %12s %12s %12s %s\n",
1880 msg_h_hits, msg_h_files, msg_h_xfer, msg_h_visits, msg_h_uname);
1881 fprintf(out_fp,"---------------- ---------------- ---------------- " \
1882 "---------------- --------------------\n\n");
1883
1884 /* Do groups first (if any) */
1885 pointer=i_array;
1886 while(i_grp)
1887 {
1888 iptr=*pointer++;
1889 if (iptr->flag == OBJ_GRP)
1890 {
1891 fprintf(out_fp,
1892 "%-8llu %6.02f%% %8llu %6.02f%% %8.0f %6.02f%% %8llu %6.02f%% %s\n",
1893 iptr->count,
1894 (t_hit==0)?0:((float)iptr->count/t_hit)*100.0,iptr->files,
1895 (t_file==0)?0:((float)iptr->files/t_file)*100.0,iptr->xfer/1024,
1896 (t_xfer==0)?0:((float)iptr->xfer/t_xfer)*100.0,iptr->visit,
1897 (t_visit==0)?0:((float)iptr->visit/t_visit)*100.0,
1898 iptr->string);
1899 i_grp--;
1900 }
1901 }
1902
1903 if (i) fprintf(out_fp,"\n");
1904
1905 /* Now do individual users (if any) */
1906 pointer=i_array;
1907 while(i_reg)
1908 {
1909 iptr=*pointer++;
1910 if (iptr->flag == OBJ_REG)
1911 {
1912 fprintf(out_fp,
1913 "%-8llu %6.02f%% %8llu %6.02f%% %8.0f %6.02f%% %8llu %6.02f%% %s\n",
1914 iptr->count,
1915 (t_hit==0)?0:((float)iptr->count/t_hit)*100.0,iptr->files,
1916 (t_file==0)?0:((float)iptr->files/t_file)*100.0,iptr->xfer/1024,
1917 (t_xfer==0)?0:((float)iptr->xfer/t_xfer)*100.0,iptr->visit,
1918 (t_visit==0)?0:((float)iptr->visit/t_visit)*100.0,
1919 iptr->string);
1920 i_reg--;
1921 }
1922 }
1923
1924 fprintf(out_fp,"</PRE></FONT>\n");
1925 write_html_tail(out_fp);
1926 fclose(out_fp);
1927 return 1;
1928}
1929
1930/*********************************************/
1931/* TOP_CTRY_TABLE - top countries table */
1932/*********************************************/
1933
1934void top_ctry_table()
1935{
1936 int i,j,x,tot_num=0,tot_ctry=0;
1937 int ctry_fnd=0;
1938 u_int64_t idx;
1939 HNODEPTR hptr;
1940 char *domain;
1941 u_int64_t pie_data[10];
1942 char *pie_legend[10];
1943 char pie_title[48];
1944 char pie_fname[48];
1945 char flag_buf[256];
1946
1947 extern int ctry_graph; /* include external flag */
1948
1949#ifdef USE_GEOIP
1950 extern int geoip;
1951 extern GeoIP *geo_fp;
1952 const char *geo_rc=NULL;
1953#endif
1954 char geo_ctry[3]="--";
1955
1956 /* scan hash table adding up domain totals */
1957 for (i=0;i<MAXHASH;i++)
1958 {
1959 hptr=sm_htab[i];
1960 while (hptr!=NULL)
1961 {
1962 if (hptr->flag != OBJ_GRP) /* ignore group totals */
1963 {
1964 if (isipaddr(hptr->string)>0)
1965 {
1966 idx=0; /* unresolved/unknown */
1967#ifdef USE_DNS
1968 if (geodb)
1969 {
1970 /* Lookup IP address here, turn into idx */
1971 geodb_get_cc(geo_db, hptr->string, geo_ctry);
1972 if (geo_ctry[0]=='-')
1973 {
1974 if (debug_mode)
1975 fprintf(stderr,"GeoDB: %s unknown!\n",hptr->string);
1976 }
1977 else idx=ctry_idx(geo_ctry);
1978 }
1979#endif
1980#ifdef USE_GEOIP
1981 if (geoip)
1982 {
1983 /* Lookup IP address here, turn into idx */
1984 geo_rc=GeoIP_country_code_by_addr(geo_fp, hptr->string);
1985 if (geo_rc==NULL||geo_rc[0]=='\0'||geo_rc[0]=='-')
1986 {
1987 if (debug_mode)
1988 fprintf(stderr,"GeoIP: %s unknown (returns '%s')\n",
1989 hptr->string,(geo_rc==NULL)?"null":geo_rc);
1990 }
1991 else
1992 {
1993 /* index returned geo_ctry */
1994 geo_ctry[0]=tolower(geo_rc[0]);
1995 geo_ctry[1]=tolower(geo_rc[1]);
1996 idx=ctry_idx(geo_ctry);
1997 }
1998 }
1999#endif /* USE_GEOIP */
2000 }
2001 else
2002 {
2003 /* resolved hostname.. try to get TLD */
2004 domain = hptr->string+strlen(hptr->string)-1;
2005 while ( (*domain!='.')&&(domain!=hptr->string)) domain--;
2006 if (domain++==hptr->string) idx=0;
2007 else idx=ctry_idx(domain);
2008 }
2009 if (idx!=0)
2010 {
2011 ctry_fnd=0;
2012 for (j=0;ctry[j].desc;j++)
2013 {
2014 if (idx==ctry[j].idx)
2015 {
2016 ctry[j].count+=hptr->count;
2017 ctry[j].files+=hptr->files;
2018 ctry[j].xfer +=hptr->xfer;
2019 ctry_fnd=1;
2020 break;
2021 }
2022 }
2023 }
2024 if (!ctry_fnd || idx==0)
2025 {
2026 ctry[0].count+=hptr->count;
2027 ctry[0].files+=hptr->files;
2028 ctry[0].xfer +=hptr->xfer;
2029 }
2030 }
2031 hptr=hptr->next;
2032 }
2033 }
2034
2035 for (i=0;ctry[i].desc;i++)
2036 {
2037 if (ctry[i].count!=0) tot_ctry++;
2038 for (j=0;j<ntop_ctrys;j++)
2039 {
2040 if (top_ctrys[j]==NULL) { top_ctrys[j]=&ctry[i]; break; }
2041 else
2042 {
2043 if (ctry[i].count > top_ctrys[j]->count)
2044 {
2045 for (x=ntop_ctrys-1;x>j;x--)
2046 top_ctrys[x]=top_ctrys[x-1];
2047 top_ctrys[x]=&ctry[i];
2048 break;
2049 }
2050 }
2051 }
2052 }
2053
2054 /* put our anchor tag first... */
2055 fprintf(out_fp,"<A NAME=\"TOPCTRYS\"></A>\n");
2056
2057 /* generate pie chart if needed */
2058 if (ctry_graph)
2059 {
2060 for (i=0;i<10;i++) pie_data[i]=0; /* init data array */
2061 if (ntop_ctrys<10) j=ntop_ctrys; else j=10; /* ensure data size */
2062
2063 for (i=0;i<j;i++)
2064 {
2065 pie_data[i]=top_ctrys[i]->count; /* load the array */
2066 pie_legend[i]=top_ctrys[i]->desc;
2067 }
2068 snprintf(pie_title,sizeof(pie_title),"%s %s %d",
2069 msg_ctry_use,l_month[cur_month-1],cur_year);
2070 sprintf(pie_fname,"ctry_usage_%04d%02d.png",cur_year,cur_month);
2071
2072 pie_chart(pie_fname,pie_title,t_hit,pie_data,pie_legend); /* do it */
2073
2074 /* put the image tag in the page */
2075 fprintf(out_fp,"<IMG SRC=\"%s\" ALT=\"%s\" " \
2076 "HEIGHT=300 WIDTH=512><P>\n",pie_fname,pie_title);
2077 }
2078
2079 /* Now do the table */
2080
2081 for (i=0;i<ntop_ctrys;i++) if (top_ctrys[i]->count!=0) tot_num++;
2082 fprintf(out_fp,"<TABLE WIDTH=510 BORDER=2 CELLSPACING=1 CELLPADDING=1>\n");
2083 fprintf(out_fp,"<TR><TH HEIGHT=4></TH></TR>\n");
2084 fprintf(out_fp,"<TR><TH BGCOLOR=\"%s\" ALIGN=CENTER COLSPAN=8>" \
2085 "%s %d %s %d %s</TH></TR>\n",
2086 GREY,msg_top_top,tot_num,msg_top_of,tot_ctry,msg_top_c);
2087 fprintf(out_fp,"<TR><TH HEIGHT=4></TH></TR>\n");
2088 fprintf(out_fp,"<TR><TH BGCOLOR=\"%s\" ALIGN=center>" \
2089 "<FONT SIZE=\"-1\">#</FONT></TH>\n",GREY);
2090 fprintf(out_fp,"<TH BGCOLOR=\"%s\" ALIGN=center COLSPAN=2>" \
2091 "<FONT SIZE=\"-1\">%s</FONT></TH>\n",HITCOLOR,msg_h_hits);
2092 fprintf(out_fp,"<TH BGCOLOR=\"%s\" ALIGN=center COLSPAN=2>" \
2093 "<FONT SIZE=\"-1\">%s</FONT></TH>\n",FILECOLOR,msg_h_files);
2094 fprintf(out_fp,"<TH BGCOLOR=\"%s\" ALIGN=center COLSPAN=2>" \
2095 "<FONT SIZE=\"-1\">%s</FONT></TH>\n",KBYTECOLOR,msg_h_xfer);
2096 fprintf(out_fp,"<TH BGCOLOR=\"%s\" ALIGN=center>" \
2097 "<FONT SIZE=\"-1\">%s</FONT></TH></TR>\n",MISCCOLOR,msg_h_ctry);
2098 fprintf(out_fp,"<TR><TH HEIGHT=4></TH></TR>\n");
2099 for (i=0;i<ntop_ctrys;i++)
2100 {
2101 flag_buf[0]=0;
2102 if (use_flags)
2103 {
2104 domain=un_idx((idx=top_ctrys[i]->idx));
2105 if (strlen(domain)<3 && idx!=0) /* only to ccTLDs */
2106 {
2107 if ( domain[0]!='a'||domain[1]!='p' ) /* all but 'ap' */
2108 snprintf(flag_buf,sizeof(flag_buf),
2109 "<IMG SRC=\"%s/%s.png\" ALT=\"%s\" WIDTH=18 HEIGHT=12> ",
2110 flag_dir,domain,top_ctrys[i]->desc);
2111 }
2112 }
2113
2114 if (top_ctrys[i]->count!=0)
2115 fprintf(out_fp,"<TR>" \
2116 "<TD ALIGN=center><FONT SIZE=\"-1\"><B>%d</B></FONT></TD>\n" \
2117 "<TD ALIGN=right><FONT SIZE=\"-1\"><B>%llu</B></FONT></TD>\n"\
2118 "<TD ALIGN=right><FONT SIZE=\"-2\">%3.02f%%</FONT></TD>\n" \
2119 "<TD ALIGN=right><FONT SIZE=\"-1\"><B>%llu</B></FONT></TD>\n"\
2120 "<TD ALIGN=right><FONT SIZE=\"-2\">%3.02f%%</FONT></TD>\n" \
2121 "<TD ALIGN=right><FONT SIZE=\"-1\"><B>%.0f</B></FONT></TD>\n"\
2122 "<TD ALIGN=right><FONT SIZE=\"-2\">%3.02f%%</FONT></TD>\n" \
2123 "<TD ALIGN=left NOWRAP>%s<FONT SIZE=\"-1\">%s</FONT>" \
2124 "</TD></TR>\n",
2125 i+1,top_ctrys[i]->count,
2126 (t_hit==0)?0:((float)top_ctrys[i]->count/t_hit)*100.0,
2127 top_ctrys[i]->files,
2128 (t_file==0)?0:((float)top_ctrys[i]->files/t_file)*100.0,
2129 top_ctrys[i]->xfer/1024,
2130 (t_xfer==0)?0:((float)top_ctrys[i]->xfer/t_xfer)*100.0,
2131 flag_buf,top_ctrys[i]->desc);
2132 }
2133 fprintf(out_fp,"<TR><TH HEIGHT=4></TH></TR>\n");
2134 fprintf(out_fp,"</TABLE>\n<P>\n");
2135}
2136
2137/*********************************************/
2138/* DUMP_ALL_SITES - dump sites to tab file */
2139/*********************************************/
2140
2141void dump_all_sites()
2142{
2143 HNODEPTR hptr, *pointer;
2144 FILE *out_fp;
2145 char filename[256];
2146 u_int64_t cnt=a_ctr;
2147
2148 /* generate file name */
2149 snprintf(filename,sizeof(filename),"%s/site_%04d%02d.%s",
2150 (dump_path)?dump_path:".",cur_year,cur_month,dump_ext);
2151
2152 /* open file */
2153 if ( (out_fp=open_out_file(filename))==NULL ) return;
2154
2155 /* need a header? */
2156 if (dump_header)
2157 {
2158 fprintf(out_fp,"%s\t%s\t%s\t%s\t%s\n",
2159 msg_h_hits,msg_h_files,msg_h_xfer,msg_h_visits,msg_h_hname);
2160 }
2161
2162 /* dump 'em */
2163 pointer=h_array;
2164 while (cnt)
2165 {
2166 hptr=*pointer++;
2167 if (hptr->flag != OBJ_GRP)
2168 {
2169 fprintf(out_fp,
2170 "%llu\t%llu\t%.0f\t%llu\t%s\n",
2171 hptr->count,hptr->files,hptr->xfer/1024,
2172 hptr->visit,hptr->string);
2173 }
2174 cnt--;
2175 }
2176 fclose(out_fp);
2177 return;
2178}
2179
2180/*********************************************/
2181/* DUMP_ALL_URLS - dump all urls to tab file */
2182/*********************************************/
2183
2184void dump_all_urls()
2185{
2186 UNODEPTR uptr, *pointer;
2187 FILE *out_fp;
2188 char filename[256];
2189 u_int64_t cnt=a_ctr;
2190
2191 /* generate file name */
2192 snprintf(filename,sizeof(filename),"%s/url_%04d%02d.%s",
2193 (dump_path)?dump_path:".",cur_year,cur_month,dump_ext);
2194
2195 /* open file */
2196 if ( (out_fp=open_out_file(filename))==NULL ) return;
2197
2198 /* need a header? */
2199 if (dump_header)
2200 {
2201 fprintf(out_fp,"%s\t%s\t%s\n",msg_h_hits,msg_h_xfer,msg_h_url);
2202 }
2203
2204 /* dump 'em */
2205 pointer=u_array;
2206 while (cnt)
2207 {
2208 uptr=*pointer++;
2209 if (uptr->flag != OBJ_GRP)
2210 {
2211 fprintf(out_fp,"%llu\t%.0f\t%s\n",
2212 uptr->count,uptr->xfer/1024,uptr->string);
2213 }
2214 cnt--;
2215 }
2216 fclose(out_fp);
2217 return;
2218}
2219
2220/*********************************************/
2221/* DUMP_ALL_REFS - dump all refs to tab file */
2222/*********************************************/
2223
2224void dump_all_refs()
2225{
2226 RNODEPTR rptr, *pointer;
2227 FILE *out_fp;
2228 char filename[256];
2229 u_int64_t cnt=a_ctr;
2230
2231 /* generate file name */
2232 snprintf(filename,sizeof(filename),"%s/ref_%04d%02d.%s",
2233 (dump_path)?dump_path:".",cur_year,cur_month,dump_ext);
2234
2235 /* open file */
2236 if ( (out_fp=open_out_file(filename))==NULL ) return;
2237
2238 /* need a header? */
2239 if (dump_header)
2240 {
2241 fprintf(out_fp,"%s\t%s\n",msg_h_hits,msg_h_ref);
2242 }
2243
2244 /* dump 'em */
2245 pointer=r_array;
2246 while(cnt)
2247 {
2248 rptr=*pointer++;
2249 if (rptr->flag != OBJ_GRP)
2250 {
2251 fprintf(out_fp,"%llu\t%s\n",rptr->count, rptr->string);
2252 }
2253 cnt--;
2254 }
2255 fclose(out_fp);
2256 return;
2257}
2258
2259/*********************************************/
2260/* DUMP_ALL_AGENTS - dump agents htab file */
2261/*********************************************/
2262
2263void dump_all_agents()
2264{
2265 ANODEPTR aptr, *pointer;
2266 FILE *out_fp;
2267 char filename[256];
2268 u_int64_t cnt=a_ctr;
2269
2270 /* generate file name */
2271 snprintf(filename,sizeof(filename),"%s/agent_%04d%02d.%s",
2272 (dump_path)?dump_path:".",cur_year,cur_month,dump_ext);
2273
2274 /* open file */
2275 if ( (out_fp=open_out_file(filename))==NULL ) return;
2276
2277 /* need a header? */
2278 if (dump_header)
2279 {
2280 fprintf(out_fp,"%s\t%s\n",msg_h_hits,msg_h_agent);
2281 }
2282
2283 /* dump 'em */
2284 pointer=a_array;
2285 while(cnt)
2286 {
2287 aptr=*pointer++;
2288 if (aptr->flag != OBJ_GRP)
2289 {
2290 fprintf(out_fp,"%llu\t%s\n",aptr->count,aptr->string);
2291 }
2292 cnt--;
2293 }
2294 fclose(out_fp);
2295 return;
2296}
2297
2298/*********************************************/
2299/* DUMP_ALL_USERS - dump username tab file */
2300/*********************************************/
2301
2302void dump_all_users()
2303{
2304 INODEPTR iptr, *pointer;
2305 FILE *out_fp;
2306 char filename[256];
2307 u_int64_t cnt=a_ctr;
2308
2309 /* generate file name */
2310 snprintf(filename,sizeof(filename),"%s/user_%04d%02d.%s",
2311 (dump_path)?dump_path:".",cur_year,cur_month,dump_ext);
2312
2313 /* open file */
2314 if ( (out_fp=open_out_file(filename))==NULL ) return;
2315
2316 /* need a header? */
2317 if (dump_header)
2318 {
2319 fprintf(out_fp,"%s\t%s\t%s\t%s\t%s\n",
2320 msg_h_hits,msg_h_files,msg_h_xfer,msg_h_visits,msg_h_uname);
2321 }
2322
2323 /* dump 'em */
2324 pointer=i_array;
2325 while(cnt)
2326 {
2327 iptr=*pointer++;
2328 if (iptr->flag != OBJ_GRP)
2329 {
2330 fprintf(out_fp,
2331 "%llu\t%llu\t%.0f\t%llu\t%s\n",
2332 iptr->count,iptr->files,iptr->xfer/1024,
2333 iptr->visit,iptr->string);
2334 }
2335 cnt--;
2336 }
2337 fclose(out_fp);
2338 return;
2339}
2340
2341/*********************************************/
2342/* DUMP_ALL_SEARCH - dump search htab file */
2343/*********************************************/
2344
2345void dump_all_search()
2346{
2347 SNODEPTR sptr, *pointer;
2348 FILE *out_fp;
2349 char filename[256];
2350 u_int64_t cnt=a_ctr;
2351
2352 /* generate file name */
2353 snprintf(filename,sizeof(filename),"%s/search_%04d%02d.%s",
2354 (dump_path)?dump_path:".",cur_year,cur_month,dump_ext);
2355
2356 /* open file */
2357 if ( (out_fp=open_out_file(filename))==NULL ) return;
2358
2359 /* need a header? */
2360 if (dump_header)
2361 {
2362 fprintf(out_fp,"%s\t%s\n",msg_h_hits,msg_h_search);
2363 }
2364
2365 /* dump 'em */
2366 pointer=s_array;
2367 while(cnt)
2368 {
2369 sptr=*pointer++;
2370 fprintf(out_fp,"%llu\t%s\n",sptr->count,sptr->string);
2371 cnt--;
2372 }
2373 fclose(out_fp);
2374 return;
2375}
2376
2377/*********************************************/
2378/* WRITE_MAIN_INDEX - main index.html file */
2379/*********************************************/
2380
2381int write_main_index()
2382{
2383 /* create main index file */
2384
2385 int i,j,days_in_month;
2386 int s_year=hist[HISTSIZE-1].year;
2387 char index_fname[256];
2388 char buffer[BUFSIZE];
2389 u_int64_t m_hit=0;
2390 u_int64_t m_files=0;
2391 u_int64_t m_pages=0;
2392 u_int64_t m_visits=0;
2393 double m_xfer=0.0;
2394 double gt_hit=0.0;
2395 double gt_files=0.0;
2396 double gt_pages=0.0;
2397 double gt_xfer=0.0;
2398 double gt_visits=0.0;
2399
2400 if (verbose>1) printf("%s\n",msg_gen_sum);
2401
2402 snprintf(buffer,sizeof(buffer),"%s %s",msg_main_us,hname);
2403 year_graph6x("usage.png", buffer, hist);
2404
2405 /* now do html stuff... */
2406 snprintf(index_fname,sizeof(index_fname),"index.%s",html_ext);
2407
2408 /* .htaccess file needed? */
2409 if (htaccess)
2410 {
2411 if ((out_fp=fopen(".htaccess","wx")) != NULL)
2412 {
2413 fprintf(out_fp,"DirectoryIndex %s\n",index_fname);
2414 fclose(out_fp);
2415 }
2416 else
2417 {
2418 if (errno!=EEXIST && verbose)
2419 fprintf(stderr,"Error: Failed to create .htaccess file: %s\n",
2420 strerror(errno));
2421 }
2422 }
2423
2424 if ( (out_fp=open_out_file(index_fname)) == NULL)
2425 {
2426 if (verbose)
2427 fprintf(stderr,"%s %s!\n",msg_no_open,index_fname);
2428 return 1;
2429 }
2430 write_html_head(NULL, out_fp);
2431
2432 /* year graph */
2433 fprintf(out_fp,"<IMG SRC=\"usage.png\" ALT=\"%s\" " \
2434 "HEIGHT=256 WIDTH=512><P>\n",buffer);
2435 /* month table */
2436 fprintf(out_fp,"<TABLE WIDTH=600 BORDER=2 CELLSPACING=1 CELLPADDING=1>\n");
2437 fprintf(out_fp,"<TR><TH HEIGHT=4></TH></TR>\n");
2438 fprintf(out_fp,"<TR><TH COLSPAN=11 BGCOLOR=\"%s\" ALIGN=center>",GREY);
2439 fprintf(out_fp,"%s</TH></TR>\n",msg_main_sum);
2440 fprintf(out_fp,"<TR><TH HEIGHT=4></TH></TR>\n");
2441 fprintf(out_fp,"<TR><TH ALIGN=left ROWSPAN=2 BGCOLOR=\"%s\">" \
2442 "<FONT SIZE=\"-1\">%s</FONT></TH>\n",GREY,msg_h_mth);
2443 fprintf(out_fp,"<TH ALIGN=center COLSPAN=4 BGCOLOR=\"%s\">" \
2444 "<FONT SIZE=\"-1\">%s</FONT></TH>\n",GREY,msg_main_da);
2445 fprintf(out_fp,"<TH ALIGN=center COLSPAN=6 BGCOLOR=\"%s\">" \
2446 "<FONT SIZE=\"-1\">%s</FONT></TH></TR>\n",GREY,msg_main_mt);
2447 fprintf(out_fp,"<TR><TH ALIGN=center BGCOLOR=\"%s\">" \
2448 "<FONT SIZE=\"-1\">%s</FONT></TH>\n",HITCOLOR,msg_h_hits);
2449 fprintf(out_fp,"<TH ALIGN=center BGCOLOR=\"%s\">" \
2450 "<FONT SIZE=\"-1\">%s</FONT></TH>\n",FILECOLOR,msg_h_files);
2451 fprintf(out_fp,"<TH ALIGN=center BGCOLOR=\"%s\">" \
2452 "<FONT SIZE=\"-1\">%s</FONT></TH>\n",PAGECOLOR,msg_h_pages);
2453 fprintf(out_fp,"<TH ALIGN=center BGCOLOR=\"%s\">" \
2454 "<FONT SIZE=\"-1\">%s</FONT></TH>\n",VISITCOLOR,msg_h_visits);
2455 fprintf(out_fp,"<TH ALIGN=center BGCOLOR=\"%s\">" \
2456 "<FONT SIZE=\"-1\">%s</FONT></TH>\n",SITECOLOR,msg_h_sites);
2457 fprintf(out_fp,"<TH ALIGN=center BGCOLOR=\"%s\">" \
2458 "<FONT SIZE=\"-1\">%s</FONT></TH>\n",KBYTECOLOR,msg_h_xfer);
2459 fprintf(out_fp,"<TH ALIGN=center BGCOLOR=\"%s\">" \
2460 "<FONT SIZE=\"-1\">%s</FONT></TH>\n",VISITCOLOR,msg_h_visits);
2461 fprintf(out_fp,"<TH ALIGN=center BGCOLOR=\"%s\">" \
2462 "<FONT SIZE=\"-1\">%s</FONT></TH>\n",PAGECOLOR,msg_h_pages);
2463 fprintf(out_fp,"<TH ALIGN=center BGCOLOR=\"%s\">" \
2464 "<FONT SIZE=\"-1\">%s</FONT></TH>\n",FILECOLOR,msg_h_files);
2465 fprintf(out_fp,"<TH ALIGN=center BGCOLOR=\"%s\">" \
2466 "<FONT SIZE=\"-1\">%s</FONT></TH></TR>\n",HITCOLOR,msg_h_hits);
2467 fprintf(out_fp,"<TR><TH HEIGHT=4></TH></TR>\n");
2468 for (i=HISTSIZE-1;i>=HISTSIZE-index_mths;i--)
2469 {
2470 if (hist[i].hit==0)
2471 {
2472 days_in_month=1;
2473 for (j=i;j>=0;j--) if (hist[j].hit!=0) break;
2474 if (j<0) break;
2475 }
2476 else days_in_month=(hist[i].lday-hist[i].fday)+1;
2477
2478 /* Check for year change */
2479 if (s_year!=hist[i].year)
2480 {
2481 /* Year Totals */
2482 if (index_mths>16 && year_totals)
2483 {
2484 fprintf(out_fp,"<TR><TH COLSPAN=6 BGCOLOR=\"%s\" " \
2485 "ALIGN=left><FONT SIZE=\"-1\"><STRONG>%04d</TH>\n",
2486 GRPCOLOR,s_year);
2487 fprintf(out_fp,"<TH ALIGN=\"right\" BGCOLOR=\"%s\">" \
2488 "<FONT SIZE=\"-1\">%.0f</TH>", GRPCOLOR, m_xfer);
2489 fprintf(out_fp,"<TH ALIGN=\"right\" BGCOLOR=\"%s\">" \
2490 "<FONT SIZE=\"-1\">%0llu</TH>", GRPCOLOR, m_visits);
2491 fprintf(out_fp,"<TH ALIGN=\"right\" BGCOLOR=\"%s\">" \
2492 "<FONT SIZE=\"-1\">%0llu</TH>", GRPCOLOR, m_pages);
2493 fprintf(out_fp,"<TH ALIGN=\"right\" BGCOLOR=\"%s\">" \
2494 "<FONT SIZE=\"-1\">%0llu</TH>", GRPCOLOR, m_files);
2495 fprintf(out_fp,"<TH ALIGN=\"right\" BGCOLOR=\"%s\">" \
2496 "<FONT SIZE=\"-1\">%0llu</TH>", GRPCOLOR, m_hit);
2497 m_xfer=0; m_visits=0; m_pages=0; m_files=0; m_hit=0;
2498 }
2499
2500 /* Year Header */
2501 s_year=hist[i].year;
2502 if (index_mths>16 && year_hdrs)
2503 fprintf(out_fp,"<TR><TH COLSPAN=11 BGCOLOR=\"%s\" " \
2504 "ALIGN=center>%04d</TH></TR>\n", GREY, s_year);
2505 }
2506
2507 fprintf(out_fp,"<TR><TD NOWRAP>");
2508 if (hist[i].hit!=0)
2509 fprintf(out_fp,"<A HREF=\"usage_%04d%02d.%s\">" \
2510 "<FONT SIZE=\"-1\">%s %d</FONT></A></TD>\n",
2511 hist[i].year, hist[i].month, html_ext,
2512 s_month[hist[i].month-1], hist[i].year);
2513 else
2514 fprintf(out_fp,"<FONT SIZE=\"-1\">%s %d</FONT></A></TD>\n", \
2515 s_month[hist[i].month-1], hist[i].year);
2516
2517 fprintf(out_fp,"<TD ALIGN=right><FONT SIZE=\"-1\">%llu</FONT></TD>\n",
2518 hist[i].hit/days_in_month);
2519 fprintf(out_fp,"<TD ALIGN=right><FONT SIZE=\"-1\">%llu</FONT></TD>\n",
2520 hist[i].files/days_in_month);
2521 fprintf(out_fp,"<TD ALIGN=right><FONT SIZE=\"-1\">%llu</FONT></TD>\n",
2522 hist[i].page/days_in_month);
2523 fprintf(out_fp,"<TD ALIGN=right><FONT SIZE=\"-1\">%llu</FONT></TD>\n",
2524 hist[i].visit/days_in_month);
2525 fprintf(out_fp,"<TD ALIGN=right><FONT SIZE=\"-1\">%llu</FONT></TD>\n",
2526 hist[i].site);
2527 fprintf(out_fp,"<TD ALIGN=right><FONT SIZE=\"-1\">%.0f</FONT></TD>\n",
2528 hist[i].xfer);
2529 fprintf(out_fp,"<TD ALIGN=right><FONT SIZE=\"-1\">%llu</FONT></TD>\n",
2530 hist[i].visit);
2531 fprintf(out_fp,"<TD ALIGN=right><FONT SIZE=\"-1\">%llu</FONT></TD>\n",
2532 hist[i].page);
2533 fprintf(out_fp,"<TD ALIGN=right><FONT SIZE=\"-1\">%llu</FONT></TD>\n",
2534 hist[i].files);
2535 fprintf(out_fp,"<TD ALIGN=right><FONT SIZE=\"-1\">%llu</FONT></TD>",
2536 hist[i].hit);
2537 fprintf(out_fp,"</TR>\n");
2538 gt_hit += hist[i].hit;
2539 gt_files += hist[i].files;
2540 gt_pages += hist[i].page;
2541 gt_xfer += hist[i].xfer;
2542 gt_visits+= hist[i].visit;
2543 m_hit += hist[i].hit;
2544 m_files += hist[i].files;
2545 m_pages += hist[i].page;
2546 m_visits+= hist[i].visit;
2547 m_xfer += hist[i].xfer;
2548 }
2549
2550 if (index_mths>16 && year_totals)
2551 {
2552 fprintf(out_fp,"<TR><TH COLSPAN=6 BGCOLOR=\"%s\" " \
2553 "ALIGN=left><FONT SIZE=\"-1\"><STRONG>%04d</TH>\n",
2554 GRPCOLOR,s_year);
2555 fprintf(out_fp,"<TH ALIGN=\"right\" BGCOLOR=\"%s\">" \
2556 "<FONT SIZE=\"-1\">%.0f</TH>", GRPCOLOR, m_xfer);
2557 fprintf(out_fp,"<TH ALIGN=\"right\" BGCOLOR=\"%s\">" \
2558 "<FONT SIZE=\"-1\">%0llu</TH>", GRPCOLOR, m_visits);
2559 fprintf(out_fp,"<TH ALIGN=\"right\" BGCOLOR=\"%s\">" \
2560 "<FONT SIZE=\"-1\">%0llu</TH>", GRPCOLOR, m_pages);
2561 fprintf(out_fp,"<TH ALIGN=\"right\" BGCOLOR=\"%s\">" \
2562 "<FONT SIZE=\"-1\">%0llu</TH>", GRPCOLOR, m_files);
2563 fprintf(out_fp,"<TH ALIGN=\"right\" BGCOLOR=\"%s\">" \
2564 "<FONT SIZE=\"-1\">%0llu</TH>", GRPCOLOR, m_hit);
2565 }
2566 fprintf(out_fp,"<TR><TH HEIGHT=4></TH></TR>\n");
2567 fprintf(out_fp,"<TR><TH BGCOLOR=\"%s\" COLSPAN=6 ALIGN=left>" \
2568 "<FONT SIZE=\"-1\">%s</FONT></TH>\n",GREY,msg_h_totals);
2569 fprintf(out_fp,"<TH BGCOLOR=\"%s\" ALIGN=right>" \
2570 "<FONT SIZE=\"-1\">%.0f</FONT></TH>\n",GREY,gt_xfer);
2571 fprintf(out_fp,"<TH BGCOLOR=\"%s\" ALIGN=right>" \
2572 "<FONT SIZE=\"-1\">%.0f</FONT></TH>\n",GREY,gt_visits);
2573 fprintf(out_fp,"<TH BGCOLOR=\"%s\" ALIGN=right>" \
2574 "<FONT SIZE=\"-1\">%.0f</FONT></TH>\n",GREY,gt_pages);
2575 fprintf(out_fp,"<TH BGCOLOR=\"%s\" ALIGN=right>" \
2576 "<FONT SIZE=\"-1\">%.0f</FONT></TH>\n",GREY,gt_files);
2577 fprintf(out_fp,"<TH BGCOLOR=\"%s\" ALIGN=right>" \
2578 "<FONT SIZE=\"-1\">%.0f</FONT></TH></TR>\n",GREY,gt_hit);
2579 fprintf(out_fp,"<TR><TH HEIGHT=4></TH></TR>\n");
2580 fprintf(out_fp,"</TABLE>\n");
2581 write_html_tail(out_fp);
2582 fclose(out_fp);
2583 return 0;
2584}
2585
2586/*********************************************/
2587/* QS_SITE_CMPH - QSort compare site by hits */
2588/*********************************************/
2589
2590int qs_site_cmph(const void *cp1, const void *cp2)
2591{
2592 u_int64_t t1, t2;
2593 t1=(*(HNODEPTR *)cp1)->count;
2594 t2=(*(HNODEPTR *)cp2)->count;
2595 if (t1!=t2) return (t2<t1)?-1:1;
2596 /* if hits are the same, we sort by hostname instead */
2597 return strcmp( (*(HNODEPTR *)cp1)->string,
2598 (*(HNODEPTR *)cp2)->string );
2599}
2600
2601/*********************************************/
2602/* QS_SITE_CMPK - QSort cmp site by bytes */
2603/*********************************************/
2604
2605int qs_site_cmpk(const void *cp1, const void *cp2)
2606{
2607 double t1, t2;
2608 t1=(*(HNODEPTR *)cp1)->xfer;
2609 t2=(*(HNODEPTR *)cp2)->xfer;
2610 if (t1!=t2) return (t2<t1)?-1:1;
2611 /* if xfer bytes are the same, we sort by hostname instead */
2612 return strcmp( (*(HNODEPTR *)cp1)->string,
2613 (*(HNODEPTR *)cp2)->string );
2614}
2615
2616/*********************************************/
2617/* QS_URL_CMPH - QSort compare URL by hits */
2618/*********************************************/
2619
2620int qs_url_cmph(const void *cp1, const void *cp2)
2621{
2622 u_int64_t t1, t2;
2623 t1=(*(UNODEPTR *)cp1)->count;
2624 t2=(*(UNODEPTR *)cp2)->count;
2625 if (t1!=t2) return (t2<t1)?-1:1;
2626 /* if hits are the same, we sort by url instead */
2627 return strcmp( (*(UNODEPTR *)cp1)->string,
2628 (*(UNODEPTR *)cp2)->string );
2629}
2630
2631/*********************************************/
2632/* QS_URL_CMPK - QSort compare URL by bytes */
2633/*********************************************/
2634
2635int qs_url_cmpk(const void *cp1, const void *cp2)
2636{
2637 double t1, t2;
2638 t1=(*(UNODEPTR *)cp1)->xfer;
2639 t2=(*(UNODEPTR *)cp2)->xfer;
2640 if (t1!=t2) return (t2<t1)?-1:1;
2641 /* if xfer bytes are the same, we sort by url instead */
2642 return strcmp( (*(UNODEPTR *)cp1)->string,
2643 (*(UNODEPTR *)cp2)->string );
2644}
2645
2646/*********************************************/
2647/* QS_URL_CMPN - QSort compare URL by entry */
2648/*********************************************/
2649
2650int qs_url_cmpn(const void *cp1, const void *cp2)
2651{
2652 double t1, t2;
2653 t1=(*(UNODEPTR *)cp1)->entry;
2654 t2=(*(UNODEPTR *)cp2)->entry;
2655 if (t1!=t2) return (t2<t1)?-1:1;
2656 /* if xfer bytes are the same, we sort by url instead */
2657 return strcmp( (*(UNODEPTR *)cp1)->string,
2658 (*(UNODEPTR *)cp2)->string );
2659}
2660
2661/*********************************************/
2662/* QS_URL_CMPX - QSort compare URL by exit */
2663/*********************************************/
2664
2665int qs_url_cmpx(const void *cp1, const void *cp2)
2666{
2667 double t1, t2;
2668 t1=(*(UNODEPTR *)cp1)->exit;
2669 t2=(*(UNODEPTR *)cp2)->exit;
2670 if (t1!=t2) return (t2<t1)?-1:1;
2671 /* if xfer bytes are the same, we sort by url instead */
2672 return strcmp( (*(UNODEPTR *)cp1)->string,
2673 (*(UNODEPTR *)cp2)->string );
2674}
2675
2676/*********************************************/
2677/* QS_REF_CMPH - QSort compare Refs by hits */
2678/*********************************************/
2679
2680int qs_ref_cmph(const void *cp1, const void *cp2)
2681{
2682 u_int64_t t1, t2;
2683 t1=(*(RNODEPTR *)cp1)->count;
2684 t2=(*(RNODEPTR *)cp2)->count;
2685 if (t1!=t2) return (t2<t1)?-1:1;
2686 /* if hits are the same, we sort by referrer URL instead */
2687 return strcmp( (*(RNODEPTR *)cp1)->string,
2688 (*(RNODEPTR *)cp2)->string );
2689}
2690
2691/*********************************************/
2692/* QS_AGNT_CMPH - QSort cmp Agents by hits */
2693/*********************************************/
2694
2695int qs_agnt_cmph(const void *cp1, const void *cp2)
2696{
2697 u_int64_t t1, t2;
2698 t1=(*(ANODEPTR *)cp1)->count;
2699 t2=(*(ANODEPTR *)cp2)->count;
2700 if (t1!=t2) return (t2<t1)?-1:1;
2701 /* if hits are the same, we sort by agent string instead */
2702 return strcmp( (*(ANODEPTR *)cp1)->string,
2703 (*(ANODEPTR *)cp2)->string );
2704}
2705
2706/*********************************************/
2707/* QS_SRCH_CMPH - QSort cmp srch str by hits */
2708/*********************************************/
2709
2710int qs_srch_cmph(const void *cp1, const void *cp2)
2711{
2712 u_int64_t t1, t2;
2713 t1=(*(SNODEPTR *)cp1)->count;
2714 t2=(*(SNODEPTR *)cp2)->count;
2715 if (t1!=t2) return (t2<t1)?-1:1;
2716 /* if hits are the same, we sort by search string instead */
2717 return strcmp( (*(SNODEPTR *)cp1)->string,
2718 (*(SNODEPTR *)cp2)->string );
2719}
2720
2721/*********************************************/
2722/* QS_IDENT_CMPH - QSort cmp ident by hits */
2723/*********************************************/
2724
2725int qs_ident_cmph(const void *cp1, const void *cp2)
2726{
2727 u_int64_t t1, t2;
2728 t1=(*(INODEPTR *)cp1)->count;
2729 t2=(*(INODEPTR *)cp2)->count;
2730 if (t1!=t2) return (t2<t1)?-1:1;
2731 /* if hits are the same, sort by ident (username) string instead */
2732 return strcmp( (*(INODEPTR *)cp1)->string,
2733 (*(INODEPTR *)cp2)->string );
2734}
2735
2736/*********************************************/
2737/* LOAD_SITE_ARRAY - load up the sort array */
2738/*********************************************/
2739
2740u_int64_t load_site_array(HNODEPTR *pointer)
2741{
2742 HNODEPTR hptr;
2743 int i;
2744 u_int64_t ctr = 0;
2745
2746 /* load the array */
2747 for (i=0;i<MAXHASH;i++)
2748 {
2749 hptr=sm_htab[i];
2750 while (hptr!=NULL)
2751 {
2752 if (pointer==NULL) ctr++; /* fancy way to just count 'em */
2753 else *(pointer+ctr++)=hptr; /* otherwise, really do the load */
2754 hptr=hptr->next;
2755 }
2756 }
2757 return ctr; /* return number loaded */
2758}
2759
2760/*********************************************/
2761/* LOAD_URL_ARRAY - load up the sort array */
2762/*********************************************/
2763
2764u_int64_t load_url_array(UNODEPTR *pointer)
2765{
2766 UNODEPTR uptr;
2767 int i;
2768 u_int64_t ctr = 0;
2769
2770 /* load the array */
2771 for (i=0;i<MAXHASH;i++)
2772 {
2773 uptr=um_htab[i];
2774 while (uptr!=NULL)
2775 {
2776 if (pointer==NULL) ctr++; /* fancy way to just count 'em */
2777 else *(pointer+ctr++)=uptr; /* otherwise, really do the load */
2778 uptr=uptr->next;
2779 }
2780 }
2781 return ctr; /* return number loaded */
2782}
2783
2784/*********************************************/
2785/* LOAD_REF_ARRAY - load up the sort array */
2786/*********************************************/
2787
2788u_int64_t load_ref_array(RNODEPTR *pointer)
2789{
2790 RNODEPTR rptr;
2791 int i;
2792 u_int64_t ctr = 0;
2793
2794 /* load the array */
2795 for (i=0;i<MAXHASH;i++)
2796 {
2797 rptr=rm_htab[i];
2798 while (rptr!=NULL)
2799 {
2800 if (pointer==NULL) ctr++; /* fancy way to just count 'em */
2801 else *(pointer+ctr++)=rptr; /* otherwise, really do the load */
2802 rptr=rptr->next;
2803 }
2804 }
2805 return ctr; /* return number loaded */
2806}
2807
2808/*********************************************/
2809/* LOAD_AGENT_ARRAY - load up the sort array */
2810/*********************************************/
2811
2812u_int64_t load_agent_array(ANODEPTR *pointer)
2813{
2814 ANODEPTR aptr;
2815 int i;
2816 u_int64_t ctr = 0;
2817
2818 /* load the array */
2819 for (i=0;i<MAXHASH;i++)
2820 {
2821 aptr=am_htab[i];
2822 while (aptr!=NULL)
2823 {
2824 if (pointer==NULL) ctr++; /* fancy way to just count 'em */
2825 else *(pointer+ctr++)=aptr; /* otherwise, really do the load */
2826 aptr=aptr->next;
2827 }
2828 }
2829 return ctr; /* return number loaded */
2830}
2831
2832/*********************************************/
2833/* LOAD_SRCH_ARRAY - load up the sort array */
2834/*********************************************/
2835
2836u_int64_t load_srch_array(SNODEPTR *pointer)
2837{
2838 SNODEPTR sptr;
2839 int i;
2840 u_int64_t ctr = 0;
2841
2842 /* load the array */
2843 for (i=0;i<MAXHASH;i++)
2844 {
2845 sptr=sr_htab[i];
2846 while (sptr!=NULL)
2847 {
2848 if (pointer==NULL) ctr++; /* fancy way to just count 'em */
2849 else *(pointer+ctr++)=sptr; /* otherwise, really do the load */
2850 sptr=sptr->next;
2851 }
2852 }
2853 return ctr; /* return number loaded */
2854}
2855
2856/*********************************************/
2857/* LOAD_IDENT_ARRAY - load up the sort array */
2858/*********************************************/
2859
2860u_int64_t load_ident_array(INODEPTR *pointer)
2861{
2862 INODEPTR iptr;
2863 int i;
2864 u_int64_t ctr = 0;
2865
2866 /* load the array */
2867 for (i=0;i<MAXHASH;i++)
2868 {
2869 iptr=im_htab[i];
2870 while (iptr!=NULL)
2871 {
2872 if (pointer==NULL) ctr++; /* fancy way to just count 'em */
2873 else *(pointer+ctr++)=iptr; /* otherwise, really do the load */
2874 iptr=iptr->next;
2875 }
2876 }
2877 return ctr; /* return number loaded */
2878}
2879
2880/*********************************************/
2881/* OPEN_OUT_FILE - Open file for output */
2882/*********************************************/
2883
2884FILE *open_out_file(char *filename)
2885{
2886 struct stat out_stat;
2887 FILE *out_fp;
2888
2889 /* stat the file */
2890 if ( !(lstat(filename, &out_stat)) )
2891 {
2892 /* check if the file a symlink */
2893 if ( S_ISLNK(out_stat.st_mode) )
2894 {
2895 if (verbose)
2896 fprintf(stderr,"%s %s (symlink)\n",msg_no_open,filename);
2897 return NULL;
2898 }
2899 }
2900
2901 /* open the file... */
2902 if ( (out_fp=fopen(filename,"w")) == NULL)
2903 {
2904 if (verbose)
2905 fprintf(stderr,"%s %s!\n",msg_no_open,filename);
2906 return NULL;
2907 }
2908 return out_fp;
2909}
2910