2 webalizer - a web server log analysis program
4 Copyright (C) 1997-2011 Bradford L. Barrett
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.
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.
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
24 /*********************************************/
25 /* STANDARD INCLUDES */
26 /*********************************************/
32 #include <unistd.h> /* normal stuff */
36 #include <sys/utsname.h>
41 /* ensure sys/types */
43 #include <sys/types.h>
46 /* need socket header? */
47 #ifdef HAVE_SYS_SOCKET_H
48 #include <sys/socket.h>
51 /* some systems need this */
60 #include "webalizer.h" /* main header */
68 /* internal function prototypes */
69 void write_html_head(char *, FILE *); /* head of html page */
70 void write_html_tail(FILE *); /* tail of html page */
71 void month_links(); /* Page links */
72 void month_total_table(); /* monthly total table */
73 void daily_total_table(); /* daily total table */
74 void hourly_total_table(); /* hourly total table */
75 void top_sites_table(int); /* top n sites table */
76 void top_urls_table(int); /* top n URLs table */
77 void top_entry_table(int); /* top n entry/exits */
78 void top_refs_table(); /* top n referrers "" */
79 void top_agents_table(); /* top n u-agents "" */
80 void top_ctry_table(); /* top n countries "" */
81 void top_search_table(); /* top n search strs */
82 void top_users_table(); /* top n ident table */
83 u_int64_t
load_url_array( UNODEPTR
*); /* load URL array */
84 u_int64_t
load_site_array( HNODEPTR
*); /* load Site array */
85 u_int64_t
load_ref_array( RNODEPTR
*); /* load Refs array */
86 u_int64_t
load_agent_array(ANODEPTR
*); /* load Agents array */
87 u_int64_t
load_srch_array( SNODEPTR
*); /* load srch str array */
88 u_int64_t
load_ident_array(INODEPTR
*); /* load ident array */
89 int qs_url_cmph( const void*, const void*); /* compare by hits */
90 int qs_url_cmpk( const void*, const void*); /* compare by kbytes */
91 int qs_url_cmpn( const void*, const void*); /* compare by entrys */
92 int qs_url_cmpx( const void*, const void*); /* compare by exits */
93 int qs_site_cmph(const void*, const void*); /* compare by hits */
94 int qs_site_cmpk(const void*, const void*); /* compare by kbytes */
95 int qs_ref_cmph( const void*, const void*); /* compare by hits */
96 int qs_agnt_cmph(const void*, const void*); /* compare by hits */
97 int qs_srch_cmph(const void*, const void*); /* compare by hits */
98 int qs_ident_cmph(const void*, const void*); /* compare by hits */
99 int qs_ident_cmpk(const void*, const void*); /* compare by kbytes */
101 int all_sites_page(u_int64_t
, u_int64_t
); /* output site page */
102 int all_urls_page(u_int64_t
, u_int64_t
); /* output urls page */
103 int all_refs_page(u_int64_t
, u_int64_t
); /* output refs page */
104 int all_agents_page(u_int64_t
, u_int64_t
); /* output agents page */
105 int all_search_page(u_int64_t
, u_int64_t
); /* output search page */
106 int all_users_page(u_int64_t
, u_int64_t
); /* output ident page */
107 void dump_all_sites(); /* dump sites tab file */
108 void dump_all_urls(); /* dump urls tab file */
109 void dump_all_refs(); /* dump refs tab file */
110 void dump_all_agents(); /* dump agents file */
111 void dump_all_users(); /* dump usernames file */
112 void dump_all_search(); /* dump search file */
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"
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
140 UNODEPTR
*u_array
= NULL
; /* Sort array for URLs */
141 HNODEPTR
*h_array
= NULL
; /* hostnames (sites) */
142 RNODEPTR
*r_array
= NULL
; /* referrers */
143 ANODEPTR
*a_array
= NULL
; /* user agents */
144 SNODEPTR
*s_array
= NULL
; /* search strings */
145 INODEPTR
*i_array
= NULL
; /* ident strings (username) */
146 u_int64_t a_ctr
= 0; /* counter for sort array */
150 /*********************************************/
151 /* WRITE_HTML_HEAD - output top of HTML page */
152 /*********************************************/
154 void write_html_head(char *period
, FILE *out_fp
)
156 NLISTPTR lptr
; /* used for HTMLhead processing */
158 /* HTMLPre code goes before all else */
162 /* Default 'DOCTYPE' header record if none specified */
164 "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\">\n\n");
170 fprintf(out_fp
,"%s\n",lptr
->string
);
174 /* Standard header comments */
175 fprintf(out_fp
,"<!-- Generated by The Webalizer Ver. %s-%s -->\n",
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());
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
);
196 fprintf(out_fp
,"%s\n",lptr
->string
);
199 fprintf(out_fp
,"</HEAD>\n\n");
203 fprintf(out_fp
,"<BODY BGCOLOR=\"%s\" TEXT=\"%s\" " \
204 "LINK=\"%s\" VLINK=\"%s\">\n",
205 LTGREY
, BLACK
, BLUE
, RED
);
210 fprintf(out_fp
,"%s\n",lptr
->string
);
214 fprintf(out_fp
,"<H2>%s %s</H2>\n",msg_title
, hname
);
216 fprintf(out_fp
,"<SMALL><STRONG>\n%s: %s<BR>\n",msg_hhdr_sp
,period
);
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());
223 fprintf(out_fp
,"%s\n",lptr
->string
);
226 fprintf(out_fp
,"<CENTER>\n<HR>\n<P>\n");
229 /*********************************************/
230 /* WRITE_HTML_TAIL - output HTML page tail */
231 /*********************************************/
233 void write_html_tail(FILE *out_fp
)
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");
250 fprintf(out_fp
,"<TD ALIGN=\"right\" VALIGN=\"top\">\n");
253 fprintf(out_fp
,"%s\n",lptr
->string
);
256 fprintf(out_fp
,"</TD>\n");
258 fprintf(out_fp
,"</TR>\n</TABLE>\n");
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
);
268 fprintf(out_fp
,"%s\n",lptr
->string
);
272 else fprintf(out_fp
,"\n</BODY>\n</HTML>\n");
275 /*********************************************/
276 /* WRITE_MONTH_HTML - does what it says... */
277 /*********************************************/
279 int write_month_html()
281 char html_fname
[256]; /* filename storage areas... */
285 char buffer
[BUFSIZE
]; /* scratch buffer */
290 printf("%s %s %d\n",msg_gen_rpt
, l_month
[cur_month
-1], cur_year
);
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
);
298 /* create PNG images for web page */
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) */
317 snprintf(htitle
,sizeof(htitle
),"%s %s %d",
318 msg_hmth_hu
,l_month
[cur_month
-1],cur_year
);
319 day_graph3( png2_fname
,
326 /* now do html stuff... */
327 /* first, open the file */
328 if ( (out_fp
=open_out_file(html_fname
))==NULL
) return 1;
330 snprintf(buffer
,sizeof(buffer
),"%s %d",l_month
[cur_month
-1],cur_year
);
331 write_html_head(buffer
, out_fp
);
334 if (daily_graph
|| daily_stats
) /* Daily stuff */
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();
342 if (hourly_graph
|| hourly_stats
) /* Hourly stuff */
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();
350 /* Do URL related stuff here, sorting appropriately */
351 if ( (a_ctr
=load_url_array(NULL
)) )
353 if ( (u_array
=malloc(sizeof(UNODEPTR
)*(a_ctr
))) !=NULL
)
355 a_ctr
=load_url_array(u_array
); /* load up our sort array */
356 if (ntop_urls
|| dump_urls
)
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 */
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);}
370 else if (verbose
) fprintf(stderr
,"%s [u_array]\n",msg_nomem_tu
); /* err */
373 /* do hostname (sites) related stuff here, sorting appropriately... */
374 if ( (a_ctr
=load_site_array(NULL
)) )
376 if ( (h_array
=malloc(sizeof(HNODEPTR
)*(a_ctr
))) !=NULL
)
378 a_ctr
=load_site_array(h_array
); /* load up our sort array */
379 if (ntop_sites
|| dump_sites
)
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 */
385 if (ntop_sitesK
) /* Top Sites table (by kbytes) */
387 qsort(h_array
,a_ctr
,sizeof(HNODEPTR
),qs_site_cmpk
);
392 else if (verbose
) fprintf(stderr
,"%s [h_array]\n",msg_nomem_ts
); /* err */
395 /* do referrer related stuff here, sorting appropriately... */
396 if ( (a_ctr
=load_ref_array(NULL
)) )
398 if ( (r_array
=malloc(sizeof(RNODEPTR
)*(a_ctr
))) != NULL
)
400 a_ctr
=load_ref_array(r_array
);
401 if (ntop_refs
|| dump_refs
)
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 */
409 else if (verbose
) fprintf(stderr
,"%s [r_array]\n",msg_nomem_tr
); /* err */
412 /* do search string related stuff, sorting appropriately... */
413 if ( (a_ctr
=load_srch_array(NULL
)) )
415 if ( (s_array
=malloc(sizeof(SNODEPTR
)*(a_ctr
))) != NULL
)
417 a_ctr
=load_srch_array(s_array
);
418 if (ntop_search
|| dump_search
)
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 */
426 else if (verbose
) fprintf(stderr
,"%s [s_array]\n",msg_nomem_tsr
);/* err */
429 /* do ident (username) related stuff here, sorting appropriately... */
430 if ( (a_ctr
=load_ident_array(NULL
)) )
432 if ( (i_array
=malloc(sizeof(INODEPTR
)*(a_ctr
))) != NULL
)
434 a_ctr
=load_ident_array(i_array
);
435 if (ntop_users
|| dump_users
)
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 */
443 else if (verbose
) fprintf(stderr
,"%s [i_array]\n",msg_nomem_ti
); /* err */
446 /* do user agent related stuff here, sorting appropriately... */
447 if ( (a_ctr
=load_agent_array(NULL
)) )
449 if ( (a_array
=malloc(sizeof(ANODEPTR
)*(a_ctr
))) != NULL
)
451 a_ctr
=load_agent_array(a_array
);
452 if (ntop_agents
|| dump_agents
)
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 */
460 else if (verbose
) fprintf(stderr
,"%s [a_array]\n",msg_nomem_ta
); /* err */
463 if (ntop_ctrys
) top_ctry_table(); /* top countries table */
465 write_html_tail(out_fp
); /* finish up the HTML document */
466 fclose(out_fp
); /* close the file */
467 return (0); /* done... */
470 /*********************************************/
471 /* MONTH_LINKS - links to other page parts */
472 /*********************************************/
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
);
484 fprintf(out_fp
,"<A HREF=\"#TOPENTRY\">[%s]</A>\n",msg_hlnk_en
);
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
);
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
);
498 fprintf(out_fp
,"<A HREF=\"#TOPCTRYS\">[%s]</A>\n",msg_hlnk_c
);
499 fprintf(out_fp
,"</SMALL>\n<P>\n");
502 /*********************************************/
503 /* MONTH_TOTAL_TABLE - monthly totals table */
504 /*********************************************/
506 void month_total_table()
509 u_int64_t max_files
=0,max_hits
=0,max_visits
=0,max_pages
=0,max_sites
=0;
512 days_in_month
=(l_day
-f_day
)+1;
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
];
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");
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
);
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
);
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
);
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
);
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 /**********************************************/
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
);
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 */
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 */
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
);
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
++)
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
);
646 fprintf(out_fp
,"<TR><TH HEIGHT=4></TH></TR>\n");
647 /**********************************************/
649 fprintf(out_fp
,"</TABLE>\n");
650 fprintf(out_fp
,"<P>\n");
653 /*********************************************/
654 /* DAILY_TOTAL_TABLE - daily totals */
655 /*********************************************/
657 void daily_total_table()
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",
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");
692 /* skip beginning blank days in a month */
693 for (i
=0;i
<l_day
;i
++) if (tm_hit
[i
]!=0) break;
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
));
728 fprintf(out_fp
,"<TR><TH HEIGHT=4></TH></TR>\n");
729 fprintf(out_fp
,"</TABLE>\n");
730 fprintf(out_fp
,"<P>\n");
733 /*********************************************/
734 /* HOURLY_TOTAL_TABLE - hourly table */
735 /*********************************************/
737 void hourly_total_table()
740 u_int64_t avg_file
=0;
743 days_in_month
=(l_day
-f_day
)+1;
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",
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
);
788 fprintf(out_fp
,"<TR><TH HEIGHT=4></TH></TR>\n");
791 fprintf(out_fp
,"<TR><TD ALIGN=center>" \
792 "<FONT SIZE=\"-1\"><B>%d</B></FONT></TD>\n",i
);
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
));
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
));
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
));
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;
820 fprintf(out_fp
,"<TR><TH HEIGHT=4></TH></TR>\n");
821 fprintf(out_fp
,"</TABLE>\n<P>\n");
824 /*********************************************/
825 /* TOP_SITES_TABLE - generate top n table */
826 /*********************************************/
828 void top_sites_table(int flag
)
830 u_int64_t cnt
=0, h_reg
=0, h_grp
=0, h_hid
=0, tot_num
;
832 HNODEPTR hptr
, *pointer
;
834 cnt
=a_ctr
; pointer
=h_array
;
837 /* calculate totals */
838 switch ( (int)((HNODEPTR
)(*pointer
)->flag
) )
840 case OBJ_REG
: h_reg
++; break;
841 case OBJ_GRP
: h_grp
++; break;
842 case OBJ_HIDE
: h_hid
++; break;
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... */
851 if ((!flag
) || (flag
&&!ntop_sites
)) /* now do <A> tag */
852 fprintf(out_fp
,"<A NAME=\"TOPSITES\"></A>\n");
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");
878 pointer
=h_array
; i
=0;
882 if (hptr
->flag
!= OBJ_HIDE
)
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");
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\">",
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);
906 if ((hptr
->flag
==OBJ_GRP
)&&hlite_groups
)
907 fprintf(out_fp
,"<STRONG>%s</STRONG></FONT></TD></TR>\n",
909 else fprintf(out_fp
,"%s</FONT></TD></TR>\n",
916 fprintf(out_fp
,"<TR><TH HEIGHT=4></TH></TR>\n");
917 if ((!flag
) || (flag
&&!ntop_sites
))
919 if ( (all_sites
) && ((h_reg
+h_grp
)>ntop_sites
) )
921 if (all_sites_page(h_reg
, h_grp
))
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
);
934 fprintf(out_fp
,"</TABLE>\n<P>\n");
937 /*********************************************/
938 /* ALL_SITES_PAGE - HTML page of all sites */
939 /*********************************************/
941 int all_sites_page(u_int64_t h_reg
, u_int64_t h_grp
)
943 HNODEPTR hptr
, *pointer
;
944 char site_fname
[256], buffer
[256];
948 /* generate file name */
949 snprintf(site_fname
,sizeof(site_fname
),"site_%04d%02d.%s",
950 cur_year
,cur_month
,html_ext
);
953 if ( (out_fp
=open_out_file(site_fname
))==NULL
) return 0;
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
);
959 fprintf(out_fp
,"<FONT SIZE=\"-1\"></CENTER><PRE>\n");
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");
966 /* Do groups first (if any) */
971 if (hptr
->flag
== OBJ_GRP
)
974 "%-8llu %6.02f%% %8llu %6.02f%% %8.0f %6.02f%% " \
975 "%8llu %6.02f%% %s\n",
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,
986 if (i
) fprintf(out_fp
,"\n");
988 /* Now do individual sites (if any) */
990 if (!hide_sites
) while(h_reg
)
993 if (hptr
->flag
== OBJ_REG
)
996 "%-8llu %6.02f%% %8llu %6.02f%% %8.0f %6.02f%% " \
997 "%8llu %6.02f%% %s\n",
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,
1008 fprintf(out_fp
,"</PRE></FONT>\n");
1009 write_html_tail(out_fp
);
1014 /*********************************************/
1015 /* TOP_URLS_TABLE - generate top n table */
1016 /*********************************************/
1018 void top_urls_table(int flag
)
1020 u_int64_t cnt
=0,u_reg
=0,u_grp
=0,u_hid
=0, tot_num
;
1022 UNODEPTR uptr
, *pointer
;
1024 cnt
=a_ctr
; pointer
=u_array
;
1027 /* calculate totals */
1028 switch ( (int)((UNODEPTR
)(*pointer
)->flag
) )
1030 case OBJ_REG
: u_reg
++; break;
1031 case OBJ_GRP
: u_grp
++; break;
1032 case OBJ_HIDE
: u_hid
++; break;
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");
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");
1066 pointer
=u_array
; i
=0;
1069 uptr
=*pointer
++; /* point to the URL node */
1070 if (uptr
->flag
!= OBJ_HIDE
)
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");
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\">",
1085 (t_hit
==0)?0:((float)uptr
->count
/t_hit
)*100.0,
1087 (t_xfer
==0)?0:((float)uptr
->xfer
/t_xfer
)*100.0);
1089 if (uptr
->flag
==OBJ_GRP
)
1092 fprintf(out_fp
,"<STRONG>%s</STRONG></FONT></TD></TR>\n",
1094 else fprintf(out_fp
,"%s</FONT></TD></TR>\n",uptr
->string
);
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
);
1104 if (log_type
== LOG_FTP
) /* FTP log? */
1105 fprintf(out_fp
,"%s</FONT></TD></TR>\n",uptr
->string
);
1109 /* secure server mode, use https:// */
1111 "<A HREF=\"https://%s%s\">%s</A></FONT></TD></TR>\n",
1112 hname
,uptr
->string
,uptr
->string
);
1114 /* otherwise use standard 'http://' */
1116 "<A HREF=\"http://%s%s\">%s</A></FONT></TD></TR>\n",
1117 hname
,uptr
->string
,uptr
->string
);
1125 fprintf(out_fp
,"<TR><TH HEIGHT=4></TH></TR>\n");
1126 if ((!flag
) || (flag
&&!ntop_urls
))
1128 if ( (all_urls
) && ((u_reg
+u_grp
)>ntop_urls
) )
1130 if (all_urls_page(u_reg
, u_grp
))
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
);
1143 fprintf(out_fp
,"</TABLE>\n<P>\n");
1146 /*********************************************/
1147 /* ALL_URLS_PAGE - HTML page of all urls */
1148 /*********************************************/
1150 int all_urls_page(u_int64_t u_reg
, u_int64_t u_grp
)
1152 UNODEPTR uptr
, *pointer
;
1153 char url_fname
[256], buffer
[256];
1157 /* generate file name */
1158 snprintf(url_fname
,sizeof(url_fname
),"url_%04d%02d.%s",
1159 cur_year
,cur_month
,html_ext
);
1162 if ( (out_fp
=open_out_file(url_fname
))==NULL
) return 0;
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
);
1168 fprintf(out_fp
,"<FONT SIZE=\"-1\"></CENTER><PRE>\n");
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");
1175 /* do groups first (if any) */
1180 if (uptr
->flag
== OBJ_GRP
)
1182 fprintf(out_fp
,"%-8llu %6.02f%% %8.0f %6.02f%% %s\n",
1184 (t_hit
==0)?0:((float)uptr
->count
/t_hit
)*100.0,
1186 (t_xfer
==0)?0:((float)uptr
->xfer
/t_xfer
)*100.0,
1192 if (i
) fprintf(out_fp
,"\n");
1194 /* now do invididual sites (if any) */
1199 if (uptr
->flag
== OBJ_REG
)
1201 fprintf(out_fp
,"%-8llu %6.02f%% %8.0f %6.02f%% %s\n",
1203 (t_hit
==0)?0:((float)uptr
->count
/t_hit
)*100.0,
1205 (t_xfer
==0)?0:((float)uptr
->xfer
/t_xfer
)*100.0,
1211 fprintf(out_fp
,"</PRE></FONT>\n");
1212 write_html_tail(out_fp
);
1217 /*********************************************/
1218 /* TOP_ENTRY_TABLE - top n entry/exit urls */
1219 /*********************************************/
1221 void top_entry_table(int flag
)
1223 u_int64_t cnt
=0, u_entry
=0, u_exit
=0, tot_num
;
1224 u_int64_t t_entry
=0, t_exit
=0;
1226 UNODEPTR uptr
, *pointer
;
1228 cnt
=a_ctr
; pointer
=u_array
;
1231 if ( (int)((UNODEPTR
)(*pointer
)->flag
) == OBJ_REG
)
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
); }
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
; }
1246 /* return if none to do */
1247 if (!tot_num
) return;
1249 if (flag
) fprintf(out_fp
,"<A NAME=\"TOPEXIT\"></A>\n"); /* do anchor tag */
1250 else fprintf(out_fp
,"<A NAME=\"TOPENTRY\"></A>\n");
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",
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");
1273 pointer
=u_array
; i
=0;
1277 if (uptr
->flag
!= OBJ_HIDE
)
1279 fprintf(out_fp
,"<TR>\n");
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\">",
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));
1293 /* check for a service prefix (ie: http://) */
1294 if (strstr(uptr
->string
,"://")!=NULL
)
1296 "<A HREF=\"%s\">%s</A></FONT></TD></TR>\n",
1297 uptr
->string
,uptr
->string
);
1301 /* secure server mode, use https:// */
1303 "<A HREF=\"https://%s%s\">%s</A></FONT></TD></TR>\n",
1304 hname
,uptr
->string
,uptr
->string
);
1306 /* otherwise use standard 'http://' */
1308 "<A HREF=\"http://%s%s\">%s</A></FONT></TD></TR>\n",
1309 hname
,uptr
->string
,uptr
->string
);
1315 fprintf(out_fp
,"<TR><TH HEIGHT=4></TH></TR>\n");
1316 fprintf(out_fp
,"</TABLE>\n<P>\n");
1319 /*********************************************/
1320 /* TOP_REFS_TABLE - generate top n table */
1321 /*********************************************/
1323 void top_refs_table()
1325 u_int64_t cnt
=0, r_reg
=0, r_grp
=0, r_hid
=0, tot_num
;
1327 RNODEPTR rptr
, *pointer
;
1329 if (t_ref
==0) return; /* return if none to process */
1331 cnt
=a_ctr
; pointer
=r_array
;
1334 /* calculate totals */
1335 switch ( (int)((RNODEPTR
)(*pointer
)->flag
) )
1337 case OBJ_REG
: r_reg
++; break;
1338 case OBJ_HIDE
: r_hid
++; break;
1339 case OBJ_GRP
: r_grp
++; break;
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... */
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",
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");
1365 pointer
=r_array
; i
=0;
1369 if (rptr
->flag
!= OBJ_HIDE
)
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");
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\">",
1382 (t_hit
==0)?0:((float)rptr
->count
/t_hit
)*100.0);
1384 if (rptr
->flag
==OBJ_GRP
)
1387 fprintf(out_fp
,"<STRONG>%s</STRONG>",rptr
->string
);
1388 else fprintf(out_fp
,"%s",rptr
->string
);
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
);
1397 fprintf(out_fp
,"%s", rptr
->string
);
1399 fprintf(out_fp
,"</FONT></TD></TR>\n");
1404 fprintf(out_fp
,"<TR><TH HEIGHT=4></TH></TR>\n");
1405 if ( (all_refs
) && ((r_reg
+r_grp
)>ntop_refs
) )
1407 if (all_refs_page(r_reg
, r_grp
))
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
);
1417 fprintf(out_fp
,"</TABLE>\n<P>\n");
1420 /*********************************************/
1421 /* ALL_REFS_PAGE - HTML page of all refs */
1422 /*********************************************/
1424 int all_refs_page(u_int64_t r_reg
, u_int64_t r_grp
)
1426 RNODEPTR rptr
, *pointer
;
1427 char ref_fname
[256], buffer
[256];
1431 /* generate file name */
1432 snprintf(ref_fname
,sizeof(ref_fname
),"ref_%04d%02d.%s",
1433 cur_year
,cur_month
,html_ext
);
1436 if ( (out_fp
=open_out_file(ref_fname
))==NULL
) return 0;
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
);
1442 fprintf(out_fp
,"<FONT SIZE=\"-1\"></CENTER><PRE>\n");
1444 fprintf(out_fp
," %12s %s\n",msg_h_hits
,msg_h_ref
);
1445 fprintf(out_fp
,"---------------- --------------------\n\n");
1447 /* do groups first (if any) */
1452 if (rptr
->flag
== OBJ_GRP
)
1454 fprintf(out_fp
,"%-8llu %6.02f%% %s\n",
1456 (t_hit
==0)?0:((float)rptr
->count
/t_hit
)*100.0,
1462 if (i
) fprintf(out_fp
,"\n");
1468 if (rptr
->flag
== OBJ_REG
)
1470 fprintf(out_fp
,"%-8llu %6.02f%% %s\n",
1472 (t_hit
==0)?0:((float)rptr
->count
/t_hit
)*100.0,
1478 fprintf(out_fp
,"</PRE></FONT>\n");
1479 write_html_tail(out_fp
);
1484 /*********************************************/
1485 /* TOP_AGENTS_TABLE - generate top n table */
1486 /*********************************************/
1488 void top_agents_table()
1490 u_int64_t cnt
, a_reg
=0, a_grp
=0, a_hid
=0, tot_num
;
1492 ANODEPTR aptr
, *pointer
;
1494 if (t_agent
== 0) return; /* don't bother if we don't have any */
1496 cnt
=a_ctr
; pointer
=a_array
;
1499 /* calculate totals */
1500 switch ( (int)((ANODEPTR
)(*pointer
)->flag
) )
1502 case OBJ_REG
: a_reg
++; break;
1503 case OBJ_GRP
: a_grp
++; break;
1504 case OBJ_HIDE
: a_hid
++; break;
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... */
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",
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");
1530 pointer
=a_array
; i
=0;
1534 if (aptr
->flag
!= OBJ_HIDE
)
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");
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\">",
1547 (t_hit
==0)?0:((float)aptr
->count
/t_hit
)*100.0);
1549 if ((aptr
->flag
==OBJ_GRP
)&&hlite_groups
)
1550 fprintf(out_fp
,"<STRONG>%s</STRONG></FONT></TD></TR>\n",
1552 else fprintf(out_fp
,"%s</FONT></TD></TR>\n",
1558 fprintf(out_fp
,"<TR><TH HEIGHT=4></TH></TR>\n");
1559 if ( (all_agents
) && ((a_reg
+a_grp
)>ntop_agents
) )
1561 if (all_agents_page(a_reg
, a_grp
))
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
);
1571 fprintf(out_fp
,"</TABLE>\n<P>\n");
1574 /*********************************************/
1575 /* ALL_AGENTS_PAGE - HTML user agent page */
1576 /*********************************************/
1578 int all_agents_page(u_int64_t a_reg
, u_int64_t a_grp
)
1580 ANODEPTR aptr
, *pointer
;
1581 char agent_fname
[256], buffer
[256];
1585 /* generate file name */
1586 snprintf(agent_fname
,sizeof(agent_fname
),"agent_%04d%02d.%s",
1587 cur_year
,cur_month
,html_ext
);
1590 if ( (out_fp
=open_out_file(agent_fname
))==NULL
) return 0;
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
);
1596 fprintf(out_fp
,"<FONT SIZE=\"-1\"></CENTER><PRE>\n");
1598 fprintf(out_fp
," %12s %s\n",msg_h_hits
,msg_h_agent
);
1599 fprintf(out_fp
,"---------------- ----------------------\n\n");
1601 /* do groups first (if any) */
1606 if (aptr
->flag
== OBJ_GRP
)
1608 fprintf(out_fp
,"%-8llu %6.02f%% %s\n",
1610 (t_hit
==0)?0:((float)aptr
->count
/t_hit
)*100.0,
1616 if (i
) fprintf(out_fp
,"\n");
1622 if (aptr
->flag
== OBJ_REG
)
1624 fprintf(out_fp
,"%-8llu %6.02f%% %s\n",
1626 (t_hit
==0)?0:((float)aptr
->count
/t_hit
)*100.0,
1632 fprintf(out_fp
,"</PRE></FONT>\n");
1633 write_html_tail(out_fp
);
1638 /*********************************************/
1639 /* TOP_SEARCH_TABLE - generate top n table */
1640 /*********************************************/
1642 void top_search_table()
1644 u_int64_t cnt
,t_val
=0, tot_num
;
1646 SNODEPTR sptr
, *pointer
;
1648 if (a_ctr
==0) return; /* don't bother if none to do */
1650 cnt
=tot_num
=a_ctr
; pointer
=s_array
;
1653 t_val
+=(u_int64_t
)(((SNODEPTR
)(*pointer
))->count
);
1657 if ( tot_num
> ntop_search
) tot_num
=ntop_search
;
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",
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");
1677 pointer
=s_array
; i
=0;
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\">",
1688 (t_val
==0)?0:((float)sptr
->count
/t_val
)*100.0);
1689 fprintf(out_fp
,"%s</FONT></TD></TR>\n",sptr
->string
);
1693 fprintf(out_fp
,"<TR><TH HEIGHT=4></TH></TR>\n");
1694 if ( (all_search
) && (a_ctr
>ntop_search
) )
1696 if (all_search_page(a_ctr
, t_val
))
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
);
1706 fprintf(out_fp
,"</TABLE>\n<P>\n");
1709 /*********************************************/
1710 /* ALL_SEARCH_PAGE - HTML for search strings */
1711 /*********************************************/
1713 int all_search_page(u_int64_t tot_num
, u_int64_t t_val
)
1715 SNODEPTR sptr
, *pointer
;
1716 char search_fname
[256], buffer
[256];
1719 if (!tot_num
) return 0;
1721 /* generate file name */
1722 snprintf(search_fname
,sizeof(search_fname
),"search_%04d%02d.%s",
1723 cur_year
,cur_month
,html_ext
);
1726 if ( (out_fp
=open_out_file(search_fname
))==NULL
) return 0;
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
);
1732 fprintf(out_fp
,"<FONT SIZE=\"-1\"></CENTER><PRE>\n");
1734 fprintf(out_fp
," %12s %s\n",msg_h_hits
,msg_h_search
);
1735 fprintf(out_fp
,"---------------- ----------------------\n\n");
1741 fprintf(out_fp
,"%-8llu %6.02f%% %s\n",
1743 (t_val
==0)?0:((float)sptr
->count
/t_val
)*100.0,
1747 fprintf(out_fp
,"</PRE></FONT>\n");
1748 write_html_tail(out_fp
);
1753 /*********************************************/
1754 /* TOP_USERS_TABLE - generate top n table */
1755 /*********************************************/
1757 void top_users_table()
1759 u_int64_t cnt
=0, i_reg
=0, i_grp
=0, i_hid
=0, tot_num
;
1761 INODEPTR iptr
, *pointer
;
1763 cnt
=a_ctr
; pointer
=i_array
;
1766 /* calculate totals */
1767 switch ( (int)((INODEPTR
)(*pointer
)->flag
) )
1769 case OBJ_REG
: i_reg
++; break;
1770 case OBJ_GRP
: i_grp
++; break;
1771 case OBJ_HIDE
: i_hid
++; break;
1776 if ( (tot_num
=i_reg
+i_grp
)==0 ) return; /* split if none */
1777 if (tot_num
> ntop_users
) tot_num
= ntop_users
;
1779 fprintf(out_fp
,"<A NAME=\"TOPUSERS\"></A>\n"); /* now do <A> tag */
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");
1801 pointer
=i_array
; i
=0;
1805 if (iptr
->flag
!= OBJ_HIDE
)
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");
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\">",
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);
1829 if ((iptr
->flag
==OBJ_GRP
)&&hlite_groups
)
1830 fprintf(out_fp
,"<STRONG>%s</STRONG></FONT></TD></TR>\n",
1832 else fprintf(out_fp
,"%s</FONT></TD></TR>\n",
1839 fprintf(out_fp
,"<TR><TH HEIGHT=4></TH></TR>\n");
1840 if ( (all_users
) && ((i_reg
+i_grp
)>ntop_users
) )
1842 if (all_users_page(i_reg
, i_grp
))
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
);
1852 fprintf(out_fp
,"</TABLE>\n<P>\n");
1855 /*********************************************/
1856 /* ALL_USERS_PAGE - HTML of all usernames */
1857 /*********************************************/
1859 int all_users_page(u_int64_t i_reg
, u_int64_t i_grp
)
1861 INODEPTR iptr
, *pointer
;
1862 char user_fname
[256], buffer
[256];
1866 /* generate file name */
1867 snprintf(user_fname
,sizeof(user_fname
),"user_%04d%02d.%s",
1868 cur_year
,cur_month
,html_ext
);
1871 if ( (out_fp
=open_out_file(user_fname
))==NULL
) return 0;
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
);
1877 fprintf(out_fp
,"<FONT SIZE=\"-1\"></CENTER><PRE>\n");
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");
1884 /* Do groups first (if any) */
1889 if (iptr
->flag
== OBJ_GRP
)
1892 "%-8llu %6.02f%% %8llu %6.02f%% %8.0f %6.02f%% %8llu %6.02f%% %s\n",
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,
1903 if (i
) fprintf(out_fp
,"\n");
1905 /* Now do individual users (if any) */
1910 if (iptr
->flag
== OBJ_REG
)
1913 "%-8llu %6.02f%% %8llu %6.02f%% %8.0f %6.02f%% %8llu %6.02f%% %s\n",
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,
1924 fprintf(out_fp
,"</PRE></FONT>\n");
1925 write_html_tail(out_fp
);
1930 /*********************************************/
1931 /* TOP_CTRY_TABLE - top countries table */
1932 /*********************************************/
1934 void top_ctry_table()
1936 int i
,j
,x
,tot_num
=0,tot_ctry
=0;
1941 u_int64_t pie_data
[10];
1942 char *pie_legend
[10];
1947 extern int ctry_graph
; /* include external flag */
1951 extern GeoIP
*geo_fp
;
1952 const char *geo_rc
=NULL
;
1954 char geo_ctry
[3]="--";
1956 /* scan hash table adding up domain totals */
1957 for (i
=0;i
<MAXHASH
;i
++)
1962 if (hptr
->flag
!= OBJ_GRP
) /* ignore group totals */
1964 if (isipaddr(hptr
->string
)>0)
1966 idx
=0; /* unresolved/unknown */
1970 /* Lookup IP address here, turn into idx */
1971 geodb_get_cc(geo_db
, hptr
->string
, geo_ctry
);
1972 if (geo_ctry
[0]=='-')
1975 fprintf(stderr
,"GeoDB: %s unknown!\n",hptr
->string
);
1977 else idx
=ctry_idx(geo_ctry
);
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]=='-')
1988 fprintf(stderr
,"GeoIP: %s unknown (returns '%s')\n",
1989 hptr
->string
,(geo_rc
==NULL
)?"null":geo_rc
);
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
);
1999 #endif /* USE_GEOIP */
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
);
2012 for (j
=0;ctry
[j
].desc
;j
++)
2014 if (idx
==ctry
[j
].idx
)
2016 ctry
[j
].count
+=hptr
->count
;
2017 ctry
[j
].files
+=hptr
->files
;
2018 ctry
[j
].xfer
+=hptr
->xfer
;
2024 if (!ctry_fnd
|| idx
==0)
2026 ctry
[0].count
+=hptr
->count
;
2027 ctry
[0].files
+=hptr
->files
;
2028 ctry
[0].xfer
+=hptr
->xfer
;
2035 for (i
=0;ctry
[i
].desc
;i
++)
2037 if (ctry
[i
].count
!=0) tot_ctry
++;
2038 for (j
=0;j
<ntop_ctrys
;j
++)
2040 if (top_ctrys
[j
]==NULL
) { top_ctrys
[j
]=&ctry
[i
]; break; }
2043 if (ctry
[i
].count
> top_ctrys
[j
]->count
)
2045 for (x
=ntop_ctrys
-1;x
>j
;x
--)
2046 top_ctrys
[x
]=top_ctrys
[x
-1];
2047 top_ctrys
[x
]=&ctry
[i
];
2054 /* put our anchor tag first... */
2055 fprintf(out_fp
,"<A NAME=\"TOPCTRYS\"></A>\n");
2057 /* generate pie chart if needed */
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 */
2065 pie_data
[i
]=top_ctrys
[i
]->count
; /* load the array */
2066 pie_legend
[i
]=top_ctrys
[i
]->desc
;
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
);
2072 pie_chart(pie_fname
,pie_title
,t_hit
,pie_data
,pie_legend
); /* do it */
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
);
2079 /* Now do the table */
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
++)
2104 domain
=un_idx((idx
=top_ctrys
[i
]->idx
));
2105 if (strlen(domain
)<3 && idx
!=0) /* only to ccTLDs */
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
);
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>" \
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
);
2133 fprintf(out_fp
,"<TR><TH HEIGHT=4></TH></TR>\n");
2134 fprintf(out_fp
,"</TABLE>\n<P>\n");
2137 /*********************************************/
2138 /* DUMP_ALL_SITES - dump sites to tab file */
2139 /*********************************************/
2141 void dump_all_sites()
2143 HNODEPTR hptr
, *pointer
;
2146 u_int64_t cnt
=a_ctr
;
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
);
2153 if ( (out_fp
=open_out_file(filename
))==NULL
) return;
2155 /* need a header? */
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
);
2167 if (hptr
->flag
!= OBJ_GRP
)
2170 "%llu\t%llu\t%.0f\t%llu\t%s\n",
2171 hptr
->count
,hptr
->files
,hptr
->xfer
/1024,
2172 hptr
->visit
,hptr
->string
);
2180 /*********************************************/
2181 /* DUMP_ALL_URLS - dump all urls to tab file */
2182 /*********************************************/
2184 void dump_all_urls()
2186 UNODEPTR uptr
, *pointer
;
2189 u_int64_t cnt
=a_ctr
;
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
);
2196 if ( (out_fp
=open_out_file(filename
))==NULL
) return;
2198 /* need a header? */
2201 fprintf(out_fp
,"%s\t%s\t%s\n",msg_h_hits
,msg_h_xfer
,msg_h_url
);
2209 if (uptr
->flag
!= OBJ_GRP
)
2211 fprintf(out_fp
,"%llu\t%.0f\t%s\n",
2212 uptr
->count
,uptr
->xfer
/1024,uptr
->string
);
2220 /*********************************************/
2221 /* DUMP_ALL_REFS - dump all refs to tab file */
2222 /*********************************************/
2224 void dump_all_refs()
2226 RNODEPTR rptr
, *pointer
;
2229 u_int64_t cnt
=a_ctr
;
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
);
2236 if ( (out_fp
=open_out_file(filename
))==NULL
) return;
2238 /* need a header? */
2241 fprintf(out_fp
,"%s\t%s\n",msg_h_hits
,msg_h_ref
);
2249 if (rptr
->flag
!= OBJ_GRP
)
2251 fprintf(out_fp
,"%llu\t%s\n",rptr
->count
, rptr
->string
);
2259 /*********************************************/
2260 /* DUMP_ALL_AGENTS - dump agents htab file */
2261 /*********************************************/
2263 void dump_all_agents()
2265 ANODEPTR aptr
, *pointer
;
2268 u_int64_t cnt
=a_ctr
;
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
);
2275 if ( (out_fp
=open_out_file(filename
))==NULL
) return;
2277 /* need a header? */
2280 fprintf(out_fp
,"%s\t%s\n",msg_h_hits
,msg_h_agent
);
2288 if (aptr
->flag
!= OBJ_GRP
)
2290 fprintf(out_fp
,"%llu\t%s\n",aptr
->count
,aptr
->string
);
2298 /*********************************************/
2299 /* DUMP_ALL_USERS - dump username tab file */
2300 /*********************************************/
2302 void dump_all_users()
2304 INODEPTR iptr
, *pointer
;
2307 u_int64_t cnt
=a_ctr
;
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
);
2314 if ( (out_fp
=open_out_file(filename
))==NULL
) return;
2316 /* need a header? */
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
);
2328 if (iptr
->flag
!= OBJ_GRP
)
2331 "%llu\t%llu\t%.0f\t%llu\t%s\n",
2332 iptr
->count
,iptr
->files
,iptr
->xfer
/1024,
2333 iptr
->visit
,iptr
->string
);
2341 /*********************************************/
2342 /* DUMP_ALL_SEARCH - dump search htab file */
2343 /*********************************************/
2345 void dump_all_search()
2347 SNODEPTR sptr
, *pointer
;
2350 u_int64_t cnt
=a_ctr
;
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
);
2357 if ( (out_fp
=open_out_file(filename
))==NULL
) return;
2359 /* need a header? */
2362 fprintf(out_fp
,"%s\t%s\n",msg_h_hits
,msg_h_search
);
2370 fprintf(out_fp
,"%llu\t%s\n",sptr
->count
,sptr
->string
);
2377 /*********************************************/
2378 /* WRITE_MAIN_INDEX - main index.html file */
2379 /*********************************************/
2381 int write_main_index()
2383 /* create main index file */
2385 int i
,j
,days_in_month
;
2386 int s_year
=hist
[HISTSIZE
-1].year
;
2387 char index_fname
[256];
2388 char buffer
[BUFSIZE
];
2390 u_int64_t m_files
=0;
2391 u_int64_t m_pages
=0;
2392 u_int64_t m_visits
=0;
2395 double gt_files
=0.0;
2396 double gt_pages
=0.0;
2398 double gt_visits
=0.0;
2400 if (verbose
>1) printf("%s\n",msg_gen_sum
);
2402 snprintf(buffer
,sizeof(buffer
),"%s %s",msg_main_us
,hname
);
2403 year_graph6x("usage.png", buffer
, hist
);
2405 /* now do html stuff... */
2406 snprintf(index_fname
,sizeof(index_fname
),"index.%s",html_ext
);
2408 /* .htaccess file needed? */
2411 if ((out_fp
=fopen(".htaccess","wx")) != NULL
)
2413 fprintf(out_fp
,"DirectoryIndex %s\n",index_fname
);
2418 if (errno
!=EEXIST
&& verbose
)
2419 fprintf(stderr
,"Error: Failed to create .htaccess file: %s\n",
2424 if ( (out_fp
=open_out_file(index_fname
)) == NULL
)
2427 fprintf(stderr
,"%s %s!\n",msg_no_open
,index_fname
);
2430 write_html_head(NULL
, out_fp
);
2433 fprintf(out_fp
,"<IMG SRC=\"usage.png\" ALT=\"%s\" " \
2434 "HEIGHT=256 WIDTH=512><P>\n",buffer
);
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
--)
2473 for (j
=i
;j
>=0;j
--) if (hist
[j
].hit
!=0) break;
2476 else days_in_month
=(hist
[i
].lday
-hist
[i
].fday
)+1;
2478 /* Check for year change */
2479 if (s_year
!=hist
[i
].year
)
2482 if (index_mths
>16 && year_totals
)
2484 fprintf(out_fp
,"<TR><TH COLSPAN=6 BGCOLOR=\"%s\" " \
2485 "ALIGN=left><FONT SIZE=\"-1\"><STRONG>%04d</TH>\n",
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;
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
);
2507 fprintf(out_fp
,"<TR><TD NOWRAP>");
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
);
2514 fprintf(out_fp
,"<FONT SIZE=\"-1\">%s %d</FONT></A></TD>\n", \
2515 s_month
[hist
[i
].month
-1], hist
[i
].year
);
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",
2527 fprintf(out_fp
,"<TD ALIGN=right><FONT SIZE=\"-1\">%.0f</FONT></TD>\n",
2529 fprintf(out_fp
,"<TD ALIGN=right><FONT SIZE=\"-1\">%llu</FONT></TD>\n",
2531 fprintf(out_fp
,"<TD ALIGN=right><FONT SIZE=\"-1\">%llu</FONT></TD>\n",
2533 fprintf(out_fp
,"<TD ALIGN=right><FONT SIZE=\"-1\">%llu</FONT></TD>\n",
2535 fprintf(out_fp
,"<TD ALIGN=right><FONT SIZE=\"-1\">%llu</FONT></TD>",
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
;
2550 if (index_mths
>16 && year_totals
)
2552 fprintf(out_fp
,"<TR><TH COLSPAN=6 BGCOLOR=\"%s\" " \
2553 "ALIGN=left><FONT SIZE=\"-1\"><STRONG>%04d</TH>\n",
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
);
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
);
2586 /*********************************************/
2587 /* QS_SITE_CMPH - QSort compare site by hits */
2588 /*********************************************/
2590 int qs_site_cmph(const void *cp1
, const void *cp2
)
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
);
2601 /*********************************************/
2602 /* QS_SITE_CMPK - QSort cmp site by bytes */
2603 /*********************************************/
2605 int qs_site_cmpk(const void *cp1
, const void *cp2
)
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
);
2616 /*********************************************/
2617 /* QS_URL_CMPH - QSort compare URL by hits */
2618 /*********************************************/
2620 int qs_url_cmph(const void *cp1
, const void *cp2
)
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
);
2631 /*********************************************/
2632 /* QS_URL_CMPK - QSort compare URL by bytes */
2633 /*********************************************/
2635 int qs_url_cmpk(const void *cp1
, const void *cp2
)
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
);
2646 /*********************************************/
2647 /* QS_URL_CMPN - QSort compare URL by entry */
2648 /*********************************************/
2650 int qs_url_cmpn(const void *cp1
, const void *cp2
)
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
);
2661 /*********************************************/
2662 /* QS_URL_CMPX - QSort compare URL by exit */
2663 /*********************************************/
2665 int qs_url_cmpx(const void *cp1
, const void *cp2
)
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
);
2676 /*********************************************/
2677 /* QS_REF_CMPH - QSort compare Refs by hits */
2678 /*********************************************/
2680 int qs_ref_cmph(const void *cp1
, const void *cp2
)
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
);
2691 /*********************************************/
2692 /* QS_AGNT_CMPH - QSort cmp Agents by hits */
2693 /*********************************************/
2695 int qs_agnt_cmph(const void *cp1
, const void *cp2
)
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
);
2706 /*********************************************/
2707 /* QS_SRCH_CMPH - QSort cmp srch str by hits */
2708 /*********************************************/
2710 int qs_srch_cmph(const void *cp1
, const void *cp2
)
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
);
2721 /*********************************************/
2722 /* QS_IDENT_CMPH - QSort cmp ident by hits */
2723 /*********************************************/
2725 int qs_ident_cmph(const void *cp1
, const void *cp2
)
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
);
2736 /*********************************************/
2737 /* LOAD_SITE_ARRAY - load up the sort array */
2738 /*********************************************/
2740 u_int64_t
load_site_array(HNODEPTR
*pointer
)
2746 /* load the array */
2747 for (i
=0;i
<MAXHASH
;i
++)
2752 if (pointer
==NULL
) ctr
++; /* fancy way to just count 'em */
2753 else *(pointer
+ctr
++)=hptr
; /* otherwise, really do the load */
2757 return ctr
; /* return number loaded */
2760 /*********************************************/
2761 /* LOAD_URL_ARRAY - load up the sort array */
2762 /*********************************************/
2764 u_int64_t
load_url_array(UNODEPTR
*pointer
)
2770 /* load the array */
2771 for (i
=0;i
<MAXHASH
;i
++)
2776 if (pointer
==NULL
) ctr
++; /* fancy way to just count 'em */
2777 else *(pointer
+ctr
++)=uptr
; /* otherwise, really do the load */
2781 return ctr
; /* return number loaded */
2784 /*********************************************/
2785 /* LOAD_REF_ARRAY - load up the sort array */
2786 /*********************************************/
2788 u_int64_t
load_ref_array(RNODEPTR
*pointer
)
2794 /* load the array */
2795 for (i
=0;i
<MAXHASH
;i
++)
2800 if (pointer
==NULL
) ctr
++; /* fancy way to just count 'em */
2801 else *(pointer
+ctr
++)=rptr
; /* otherwise, really do the load */
2805 return ctr
; /* return number loaded */
2808 /*********************************************/
2809 /* LOAD_AGENT_ARRAY - load up the sort array */
2810 /*********************************************/
2812 u_int64_t
load_agent_array(ANODEPTR
*pointer
)
2818 /* load the array */
2819 for (i
=0;i
<MAXHASH
;i
++)
2824 if (pointer
==NULL
) ctr
++; /* fancy way to just count 'em */
2825 else *(pointer
+ctr
++)=aptr
; /* otherwise, really do the load */
2829 return ctr
; /* return number loaded */
2832 /*********************************************/
2833 /* LOAD_SRCH_ARRAY - load up the sort array */
2834 /*********************************************/
2836 u_int64_t
load_srch_array(SNODEPTR
*pointer
)
2842 /* load the array */
2843 for (i
=0;i
<MAXHASH
;i
++)
2848 if (pointer
==NULL
) ctr
++; /* fancy way to just count 'em */
2849 else *(pointer
+ctr
++)=sptr
; /* otherwise, really do the load */
2853 return ctr
; /* return number loaded */
2856 /*********************************************/
2857 /* LOAD_IDENT_ARRAY - load up the sort array */
2858 /*********************************************/
2860 u_int64_t
load_ident_array(INODEPTR
*pointer
)
2866 /* load the array */
2867 for (i
=0;i
<MAXHASH
;i
++)
2872 if (pointer
==NULL
) ctr
++; /* fancy way to just count 'em */
2873 else *(pointer
+ctr
++)=iptr
; /* otherwise, really do the load */
2877 return ctr
; /* return number loaded */
2880 /*********************************************/
2881 /* OPEN_OUT_FILE - Open file for output */
2882 /*********************************************/
2884 FILE *open_out_file(char *filename
)
2886 struct stat out_stat
;
2890 if ( !(lstat(filename
, &out_stat
)) )
2892 /* check if the file a symlink */
2893 if ( S_ISLNK(out_stat
.st_mode
) )
2896 fprintf(stderr
,"%s %s (symlink)\n",msg_no_open
,filename
);
2901 /* open the file... */
2902 if ( (out_fp
=fopen(filename
,"w")) == NULL
)
2905 fprintf(stderr
,"%s %s!\n",msg_no_open
,filename
);