-
Notifications
You must be signed in to change notification settings - Fork 1
/
output.c
2914 lines (2620 loc) · 107 KB
/
output.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
webalizer - a web server log analysis program
Copyright (C) 1997-2013 Bradford L. Barrett
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version, and provided that the above
copyright and permission notice is included with all distributed
copies of this or derived software.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
/*********************************************/
/* STANDARD INCLUDES */
/*********************************************/
#include <time.h>
#include <stdio.h>
#include <stdlib.h>
#include <inttypes.h>
#include <string.h>
#include <unistd.h> /* normal stuff */
#include <ctype.h>
#include <errno.h>
#include <sys/stat.h>
#include <sys/utsname.h>
#ifdef USE_DNS
#include <db.h>
#endif
/* ensure sys/types */
#ifndef _SYS_TYPES_H
#include <sys/types.h>
#endif
/* need socket header? */
#ifdef HAVE_SYS_SOCKET_H
#include <sys/socket.h>
#endif
/* some systems need this */
#ifdef HAVE_MATH_H
#include <math.h>
#endif
#ifdef USE_GEOIP
#include <maxminddb.h>
#endif
#include "webalizer.h" /* main header */
#include "lang.h"
#include "hashtab.h"
#include "preserve.h"
#include "linklist.h"
#include "graphs.h"
#include "output.h"
/* internal function prototypes */
void write_html_head(char *, FILE *); /* head of html page */
void write_html_tail(FILE *); /* tail of html page */
void month_links(); /* Page links */
void month_total_table(); /* monthly total table */
void daily_total_table(); /* daily total table */
void hourly_total_table(); /* hourly total table */
void top_sites_table(int); /* top n sites table */
void top_urls_table(int); /* top n URLs table */
void top_entry_table(int); /* top n entry/exits */
void top_refs_table(); /* top n referrers "" */
void top_agents_table(); /* top n u-agents "" */
void top_ctry_table(); /* top n countries "" */
void top_search_table(); /* top n search strs */
void top_users_table(); /* top n ident table */
u_int64_t load_url_array( UNODEPTR *); /* load URL array */
u_int64_t load_site_array( HNODEPTR *); /* load Site array */
u_int64_t load_ref_array( RNODEPTR *); /* load Refs array */
u_int64_t load_agent_array(ANODEPTR *); /* load Agents array */
u_int64_t load_srch_array( SNODEPTR *); /* load srch str array */
u_int64_t load_ident_array(INODEPTR *); /* load ident array */
int qs_url_cmph( const void*, const void*); /* compare by hits */
int qs_url_cmpk( const void*, const void*); /* compare by kbytes */
int qs_url_cmpn( const void*, const void*); /* compare by entrys */
int qs_url_cmpx( const void*, const void*); /* compare by exits */
int qs_site_cmph(const void*, const void*); /* compare by hits */
int qs_site_cmpk(const void*, const void*); /* compare by kbytes */
int qs_ref_cmph( const void*, const void*); /* compare by hits */
int qs_agnt_cmph(const void*, const void*); /* compare by hits */
int qs_srch_cmph(const void*, const void*); /* compare by hits */
int qs_ident_cmph(const void*, const void*); /* compare by hits */
int qs_ident_cmpk(const void*, const void*); /* compare by kbytes */
int all_sites_page(u_int64_t, u_int64_t); /* output site page */
int all_urls_page(u_int64_t, u_int64_t); /* output urls page */
int all_refs_page(u_int64_t, u_int64_t); /* output refs page */
int all_agents_page(u_int64_t, u_int64_t); /* output agents page */
int all_search_page(u_int64_t, u_int64_t); /* output search page */
int all_users_page(u_int64_t, u_int64_t); /* output ident page */
void dump_all_sites(); /* dump sites tab file */
void dump_all_urls(); /* dump urls tab file */
void dump_all_refs(); /* dump refs tab file */
void dump_all_agents(); /* dump agents file */
void dump_all_users(); /* dump usernames file */
void dump_all_search(); /* dump search file */
/* define some colors for HTML */
#define WHITE "#FFFFFF"
#define BLACK "#000000"
#define RED "#FF0000"
#define ORANGE "#FF8000"
#define LTBLUE "#0080FF"
#define BLUE "#0000FF"
#define GREEN "#00FF00"
#define DKGREEN "#008040"
#define GREY "#C0C0C0"
#define LTGREY "#E8E8E8"
#define YELLOW "#FFFF00"
#define PURPLE "#FF00FF"
#define CYAN "#00E0FF"
#define GRPCOLOR "#D0D0E0"
/* configurable html colors */
#define HITCOLOR hit_color
#define FILECOLOR file_color
#define SITECOLOR site_color
#define KBYTECOLOR kbyte_color
#define PAGECOLOR page_color
#define VISITCOLOR visit_color
#define MISCCOLOR misc_color
/* sort arrays */
UNODEPTR *u_array = NULL; /* Sort array for URLs */
HNODEPTR *h_array = NULL; /* hostnames (sites) */
RNODEPTR *r_array = NULL; /* referrers */
ANODEPTR *a_array = NULL; /* user agents */
SNODEPTR *s_array = NULL; /* search strings */
INODEPTR *i_array = NULL; /* ident strings (username) */
u_int64_t a_ctr = 0; /* counter for sort array */
FILE *out_fp;
/*********************************************/
/* WRITE_HTML_HEAD - output top of HTML page */
/*********************************************/
void write_html_head(char *period, FILE *out_fp)
{
NLISTPTR lptr; /* used for HTMLhead processing */
/* HTMLPre code goes before all else */
lptr = html_pre;
if (lptr==NULL)
{
/* Default 'DOCTYPE' header record if none specified */
fprintf(out_fp,
"<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\">\n\n");
}
else
{
while (lptr!=NULL)
{
fprintf(out_fp,"%s\n",lptr->string);
lptr=lptr->next;
}
}
/* Standard header comments */
fprintf(out_fp,"<!-- Generated by The Webalizer Ver. %s-%s -->\n",
version,editlvl);
fprintf(out_fp,"<!-- -->\n");
fprintf(out_fp,"<!-- Copyright 1997-2013 Bradford L. Barrett -->\n");
fprintf(out_fp,"<!-- -->\n");
fprintf(out_fp,"<!-- Distributed under the GNU GPL Version 2 -->\n");
fprintf(out_fp,"<!-- Full text may be found at: -->\n");
fprintf(out_fp,"<!-- http://www.webalizer.org -->\n");
fprintf(out_fp,"<!-- -->\n");
fprintf(out_fp,"<!-- Give the power back to the programmers -->\n");
fprintf(out_fp,"<!-- Support the Free Software Foundation -->\n");
fprintf(out_fp,"<!-- (http://www.fsf.org) -->\n");
fprintf(out_fp,"<!-- -->\n");
fprintf(out_fp,"<!-- *** Generated: %s *** -->\n\n",cur_time());
fprintf(out_fp,"<HTML lang=\"%s\">\n<HEAD>\n",langcode);
fprintf(out_fp," <TITLE>%s %s - %s</TITLE>\n",
msg_title, hname, (period)?period:msg_main_per);
lptr=html_head;
while (lptr!=NULL)
{
fprintf(out_fp,"%s\n",lptr->string);
lptr=lptr->next;
}
fprintf(out_fp,"</HEAD>\n\n");
lptr = html_body;
if (lptr==NULL)
fprintf(out_fp,"<BODY BGCOLOR=\"%s\" TEXT=\"%s\" " \
"LINK=\"%s\" VLINK=\"%s\">\n",
LTGREY, BLACK, BLUE, RED);
else
{
while (lptr!=NULL)
{
fprintf(out_fp,"%s\n",lptr->string);
lptr=lptr->next;
}
}
fprintf(out_fp,"<H2>%s %s</H2>\n",msg_title, hname);
if (period)
fprintf(out_fp,"<SMALL><STRONG>\n%s: %s<BR>\n",msg_hhdr_sp,period);
else
fprintf(out_fp,"<SMALL><STRONG>\n%s<BR>\n",msg_main_per);
fprintf(out_fp,"%s %s<BR>\n</STRONG></SMALL>\n",msg_hhdr_gt,cur_time());
lptr=html_post;
while (lptr!=NULL)
{
fprintf(out_fp,"%s\n",lptr->string);
lptr=lptr->next;
}
fprintf(out_fp,"<CENTER>\n<HR>\n<P>\n");
}
/*********************************************/
/* WRITE_HTML_TAIL - output HTML page tail */
/*********************************************/
void write_html_tail(FILE *out_fp)
{
NLISTPTR lptr;
fprintf(out_fp,"</CENTER>\n");
fprintf(out_fp,"<P>\n<HR>\n");
fprintf(out_fp,"<TABLE WIDTH=\"100%%\" CELLPADDING=0 " \
"CELLSPACING=0 BORDER=0>\n");
fprintf(out_fp,"<TR>\n");
fprintf(out_fp,"<TD ALIGN=left VALIGN=top>\n");
fprintf(out_fp,"<SMALL>Generated by\n");
fprintf(out_fp,"<A HREF=\"http://www.webalizer.org/\">");
fprintf(out_fp,"<STRONG>Webalizer Version %s</STRONG></A>\n",version);
fprintf(out_fp,"</SMALL>\n</TD>\n");
lptr=html_tail;
if (lptr)
{
fprintf(out_fp,"<TD ALIGN=\"right\" VALIGN=\"top\">\n");
while (lptr!=NULL)
{
fprintf(out_fp,"%s\n",lptr->string);
lptr=lptr->next;
}
fprintf(out_fp,"</TD>\n");
}
fprintf(out_fp,"</TR>\n</TABLE>\n");
/* wind up, this is the end of the file */
fprintf(out_fp,"\n<!-- Webalizer Version %s-%s (Mod: %s) -->\n",
version,editlvl,moddate);
lptr = html_end;
if (lptr)
{
while (lptr!=NULL)
{
fprintf(out_fp,"%s\n",lptr->string);
lptr=lptr->next;
}
}
else fprintf(out_fp,"\n</BODY>\n</HTML>\n");
}
/*********************************************/
/* WRITE_MONTH_HTML - does what it says... */
/*********************************************/
int write_month_html()
{
char html_fname[256]; /* filename storage areas... */
char png1_fname[32];
char png2_fname[32];
char buffer[BUFSIZE]; /* scratch buffer */
char dtitle[256];
char htitle[256];
if (verbose>1)
printf("%s %s %d\n",msg_gen_rpt, l_month[cur_month-1], cur_year);
/* fill in filenames */
snprintf(html_fname,sizeof(html_fname),"usage_%04d%02d.%s",
cur_year,cur_month,html_ext);
sprintf(png1_fname,"daily_usage_%04d%02d.png",cur_year,cur_month);
sprintf(png2_fname,"hourly_usage_%04d%02d.png",cur_year,cur_month);
/* create PNG images for web page */
if (daily_graph)
{
snprintf(dtitle,sizeof(dtitle),"%s %s %d",
msg_hmth_du,l_month[cur_month-1],cur_year);
month_graph6 ( png1_fname, /* filename */
dtitle, /* graph title */
cur_month, /* graph month */
cur_year, /* graph year */
tm_hit, /* data 1 (hits) */
tm_file, /* data 2 (files) */
tm_site, /* data 3 (sites) */
tm_xfer, /* data 4 (kbytes) */
tm_page, /* data 5 (pages) */
tm_visit); /* data 6 (visits) */
}
if (hourly_graph)
{
snprintf(htitle,sizeof(htitle),"%s %s %d",
msg_hmth_hu,l_month[cur_month-1],cur_year);
day_graph3( png2_fname,
htitle,
th_hit,
th_file,
th_page );
}
/* now do html stuff... */
/* first, open the file */
if ( (out_fp=open_out_file(html_fname))==NULL ) return 1;
snprintf(buffer,sizeof(buffer),"%s %d",l_month[cur_month-1],cur_year);
write_html_head(buffer, out_fp);
month_links();
month_total_table();
if (daily_graph || daily_stats) /* Daily stuff */
{
fprintf(out_fp,"<A NAME=\"DAYSTATS\"></A>\n");
if (daily_graph) fprintf(out_fp,"<IMG SRC=\"%s\" ALT=\"%s\" " \
"HEIGHT=400 WIDTH=512><P>\n",png1_fname,dtitle);
if (daily_stats) daily_total_table();
}
if (hourly_graph || hourly_stats) /* Hourly stuff */
{
fprintf(out_fp,"<A NAME=\"HOURSTATS\"></A>\n");
if (hourly_graph) fprintf(out_fp,"<IMG SRC=\"%s\" ALT=\"%s\" " \
"HEIGHT=256 WIDTH=512><P>\n",png2_fname,htitle);
if (hourly_stats) hourly_total_table();
}
/* Do URL related stuff here, sorting appropriately */
if ( (a_ctr=load_url_array(NULL)) )
{
if ( (u_array=malloc(sizeof(UNODEPTR)*(a_ctr))) !=NULL )
{
a_ctr=load_url_array(u_array); /* load up our sort array */
if (ntop_urls || dump_urls)
{
qsort(u_array,a_ctr,sizeof(UNODEPTR),qs_url_cmph);
if (ntop_urls) top_urls_table(0); /* Top URLs (by hits) */
if (dump_urls) dump_all_urls(); /* Dump URLs tab file */
}
if (ntop_urlsK) /* Top URLs (by kbytes) */
{qsort(u_array,a_ctr,sizeof(UNODEPTR),qs_url_cmpk); top_urls_table(1); }
if (ntop_entry) /* Top Entry Pages */
{qsort(u_array,a_ctr,sizeof(UNODEPTR),qs_url_cmpn); top_entry_table(0);}
if (ntop_exit) /* Top Exit Pages */
{qsort(u_array,a_ctr,sizeof(UNODEPTR),qs_url_cmpx); top_entry_table(1);}
free(u_array);
}
else if (verbose) fprintf(stderr,"%s [u_array]\n",msg_nomem_tu); /* err */
}
/* do hostname (sites) related stuff here, sorting appropriately... */
if ( (a_ctr=load_site_array(NULL)) )
{
if ( (h_array=malloc(sizeof(HNODEPTR)*(a_ctr))) !=NULL )
{
a_ctr=load_site_array(h_array); /* load up our sort array */
if (ntop_sites || dump_sites)
{
qsort(h_array,a_ctr,sizeof(HNODEPTR),qs_site_cmph);
if (ntop_sites) top_sites_table(0); /* Top sites table (by hits) */
if (dump_sites) dump_all_sites(); /* Dump sites tab file */
}
if (ntop_sitesK) /* Top Sites table (by kbytes) */
{
qsort(h_array,a_ctr,sizeof(HNODEPTR),qs_site_cmpk);
top_sites_table(1);
}
free(h_array);
}
else if (verbose) fprintf(stderr,"%s [h_array]\n",msg_nomem_ts); /* err */
}
/* do referrer related stuff here, sorting appropriately... */
if ( (a_ctr=load_ref_array(NULL)) )
{
if ( (r_array=malloc(sizeof(RNODEPTR)*(a_ctr))) != NULL)
{
a_ctr=load_ref_array(r_array);
if (ntop_refs || dump_refs)
{
qsort(r_array,a_ctr,sizeof(RNODEPTR),qs_ref_cmph);
if (ntop_refs) top_refs_table(); /* Top referrers table */
if (dump_refs) dump_all_refs(); /* Dump referrers tab file */
}
free(r_array);
}
else if (verbose) fprintf(stderr,"%s [r_array]\n",msg_nomem_tr); /* err */
}
/* do search string related stuff, sorting appropriately... */
if ( (a_ctr=load_srch_array(NULL)) )
{
if ( (s_array=malloc(sizeof(SNODEPTR)*(a_ctr))) != NULL)
{
a_ctr=load_srch_array(s_array);
if (ntop_search || dump_search)
{
qsort(s_array,a_ctr,sizeof(SNODEPTR),qs_srch_cmph);
if (ntop_search) top_search_table(); /* top search strings table */
if (dump_search) dump_all_search(); /* dump search string tab file */
}
free(s_array);
}
else if (verbose) fprintf(stderr,"%s [s_array]\n",msg_nomem_tsr);/* err */
}
/* do ident (username) related stuff here, sorting appropriately... */
if ( (a_ctr=load_ident_array(NULL)) )
{
if ( (i_array=malloc(sizeof(INODEPTR)*(a_ctr))) != NULL)
{
a_ctr=load_ident_array(i_array);
if (ntop_users || dump_users)
{
qsort(i_array,a_ctr,sizeof(INODEPTR),qs_ident_cmph);
if (ntop_users) top_users_table(); /* top usernames table */
if (dump_users) dump_all_users(); /* dump usernames tab file */
}
free(i_array);
}
else if (verbose) fprintf(stderr,"%s [i_array]\n",msg_nomem_ti); /* err */
}
/* do user agent related stuff here, sorting appropriately... */
if ( (a_ctr=load_agent_array(NULL)) )
{
if ( (a_array=malloc(sizeof(ANODEPTR)*(a_ctr))) != NULL)
{
a_ctr=load_agent_array(a_array);
if (ntop_agents || dump_agents)
{
qsort(a_array,a_ctr,sizeof(ANODEPTR),qs_agnt_cmph);
if (ntop_agents) top_agents_table(); /* top user agents table */
if (dump_agents) dump_all_agents(); /* dump user agents tab file */
}
free(a_array);
}
else if (verbose) fprintf(stderr,"%s [a_array]\n",msg_nomem_ta); /* err */
}
if (ntop_ctrys ) top_ctry_table(); /* top countries table */
write_html_tail(out_fp); /* finish up the HTML document */
fclose(out_fp); /* close the file */
return (0); /* done... */
}
/*********************************************/
/* MONTH_LINKS - links to other page parts */
/*********************************************/
void month_links()
{
fprintf(out_fp,"<SMALL>\n");
if (daily_stats || daily_graph)
fprintf(out_fp,"<A HREF=\"#DAYSTATS\">[%s]</A>\n",msg_hlnk_ds);
if (hourly_stats || hourly_graph)
fprintf(out_fp,"<A HREF=\"#HOURSTATS\">[%s]</A>\n",msg_hlnk_hs);
if (ntop_urls || ntop_urlsK)
fprintf(out_fp,"<A HREF=\"#TOPURLS\">[%s]</A>\n",msg_hlnk_u);
if (ntop_entry)
fprintf(out_fp,"<A HREF=\"#TOPENTRY\">[%s]</A>\n",msg_hlnk_en);
if (ntop_exit)
fprintf(out_fp,"<A HREF=\"#TOPEXIT\">[%s]</A>\n",msg_hlnk_ex);
if (ntop_sites || ntop_sitesK)
fprintf(out_fp,"<A HREF=\"#TOPSITES\">[%s]</A>\n",msg_hlnk_s);
if (ntop_refs && t_ref)
fprintf(out_fp,"<A HREF=\"#TOPREFS\">[%s]</A>\n",msg_hlnk_r);
if (ntop_search)
fprintf(out_fp,"<A HREF=\"#TOPSEARCH\">[%s]</A>\n",msg_hlnk_sr);
if (ntop_users && t_user)
fprintf(out_fp,"<A HREF=\"#TOPUSERS\">[%s]</A>\n",msg_hlnk_i);
if (ntop_agents && t_agent)
fprintf(out_fp,"<A HREF=\"#TOPAGENTS\">[%s]</A>\n",msg_hlnk_a);
if (ntop_ctrys)
fprintf(out_fp,"<A HREF=\"#TOPCTRYS\">[%s]</A>\n",msg_hlnk_c);
fprintf(out_fp,"</SMALL>\n<P>\n");
}
/*********************************************/
/* MONTH_TOTAL_TABLE - monthly totals table */
/*********************************************/
void month_total_table()
{
int i,days_in_month;
u_int64_t max_files=0,max_hits=0,max_visits=0,max_pages=0,max_sites=0;
double max_xfer=0.0;
days_in_month=(l_day-f_day)+1;
for (i=0;i<31;i++)
{ /* Get max/day values */
if (tm_hit[i]>max_hits) max_hits = tm_hit[i];
if (tm_file[i]>max_files) max_files = tm_file[i];
if (tm_page[i]>max_pages) max_pages = tm_page[i];
if (tm_visit[i]>max_visits) max_visits= tm_visit[i];
if (tm_site[i]>max_sites) max_sites = tm_site[i];
if (tm_xfer[i]>max_xfer) max_xfer = tm_xfer[i];
}
fprintf(out_fp,"<TABLE WIDTH=510 BORDER=2 CELLSPACING=1 CELLPADDING=1>\n");
fprintf(out_fp,"<TR><TH HEIGHT=4 COLSPAN=3></TH></TR>\n");
fprintf(out_fp,"<TR><TH COLSPAN=3 ALIGN=center BGCOLOR=\"%s\">" \
"%s %s %d</TH></TR>\n",GREY,msg_mtot_ms,l_month[cur_month-1],cur_year);
fprintf(out_fp,"<TR><TH HEIGHT=4 COLSPAN=3></TH></TR>\n");
/* Total Hits */
fprintf(out_fp,"<TR><TD WIDTH=380><FONT SIZE=\"-1\">%s</FONT></TD>\n" \
"<TD ALIGN=right COLSPAN=2><FONT SIZE=\"-1\"><B>%"PRIu64"</B>" \
"</FONT></TD></TR>\n",msg_mtot_th,t_hit);
/* Total Files */
fprintf(out_fp,"<TR><TD WIDTH=380><FONT SIZE=\"-1\">%s</FONT></TD>\n" \
"<TD ALIGN=right COLSPAN=2><FONT SIZE=\"-1\"><B>%"PRIu64"</B>" \
"</FONT></TD></TR>\n",msg_mtot_tf,t_file);
/* Total Pages */
fprintf(out_fp,"<TR><TD WIDTH=380><FONT SIZE=\"-1\">%s %s</FONT></TD>\n" \
"<TD ALIGN=right COLSPAN=2><FONT SIZE=\"-1\"><B>%"PRIu64"</B>" \
"</FONT></TD></TR>\n",msg_h_total, msg_h_pages, t_page);
/* Total Visits */
fprintf(out_fp,"<TR><TD WIDTH=380><FONT SIZE=\"-1\">%s %s</FONT></TD>\n" \
"<TD ALIGN=right COLSPAN=2><FONT SIZE=\"-1\"><B>%"PRIu64"</B>" \
"</FONT></TD></TR>\n",msg_h_total, msg_h_visits, t_visit);
/* Total XFer */
fprintf(out_fp,"<TR><TD WIDTH=380><FONT SIZE=\"-1\">%s</FONT></TD>\n" \
"<TD ALIGN=right COLSPAN=2><FONT SIZE=\"-1\"><B>%.0f</B>" \
"</FONT></TD></TR>\n",msg_mtot_tx,t_xfer/1024);
fprintf(out_fp,"<TR><TH HEIGHT=4 COLSPAN=3></TH></TR>\n");
/**********************************************/
/* Unique Sites */
fprintf(out_fp,"<TR>" \
"<TD WIDTH=380><FONT SIZE=\"-1\">%s</FONT></TD>\n" \
"<TD ALIGN=right COLSPAN=2><FONT SIZE=\"-1\"><B>%"PRIu64"</B>" \
"</FONT></TD></TR>\n",msg_mtot_us,t_site);
/* Unique URLs */
fprintf(out_fp,"<TR>" \
"<TD WIDTH=380><FONT SIZE=\"-1\">%s</FONT></TD>\n" \
"<TD ALIGN=right COLSPAN=2><FONT SIZE=\"-1\"><B>%"PRIu64"</B>" \
"</FONT></TD></TR>\n",msg_mtot_uu,t_url);
/* Unique Referrers */
if (t_ref != 0)
fprintf(out_fp,"<TR>" \
"<TD WIDTH=380><FONT SIZE=\"-1\">%s</FONT></TD>\n" \
"<TD ALIGN=right COLSPAN=2><FONT SIZE=\"-1\"><B>%"PRIu64"</B>" \
"</FONT></TD></TR>\n",msg_mtot_ur,t_ref);
/* Unique Usernames */
if (t_user != 0)
fprintf(out_fp,"<TR>" \
"<TD WIDTH=380><FONT SIZE=\"-1\">%s</FONT></TD>\n" \
"<TD ALIGN=right COLSPAN=2><FONT SIZE=\"-1\"><B>%"PRIu64"</B>" \
"</FONT></TD></TR>\n",msg_mtot_ui,t_user);
/* Unique Agents */
if (t_agent != 0)
fprintf(out_fp,"<TR>" \
"<TD WIDTH=380><FONT SIZE=\"-1\">%s</FONT></TD>\n" \
"<TD ALIGN=right COLSPAN=2><FONT SIZE=\"-1\"><B>%"PRIu64"</B>" \
"</FONT></TD></TR>\n",msg_mtot_ua,t_agent);
fprintf(out_fp,"<TR><TH HEIGHT=4 COLSPAN=3></TH></TR>\n");
/**********************************************/
/* Hourly/Daily avg/max totals */
fprintf(out_fp,"<TR>" \
"<TH WIDTH=380 BGCOLOR=\"%s\"><FONT SIZE=-1 COLOR=\"%s\">.</FONT></TH>\n"\
"<TH WIDTH=65 BGCOLOR=\"%s\" ALIGN=right>" \
"<FONT SIZE=-1>%s </FONT></TH>\n" \
"<TH WIDTH=65 BGCOLOR=\"%s\" ALIGN=right>" \
"<FONT SIZE=-1>%s </FONT></TH></TR>\n",
GREY,GREY,GREY,msg_h_avg,GREY,msg_h_max);
fprintf(out_fp,"<TR><TH HEIGHT=4 COLSPAN=3></TH></TR>\n");
/* Max/Avg Hits per Hour */
fprintf(out_fp,"<TR>" \
"<TD><FONT SIZE=\"-1\">%s</FONT></TD>\n" \
"<TD ALIGN=right WIDTH=65><FONT SIZE=\"-1\"><B>%"PRIu64"</B></FONT></TD>\n" \
"<TD WIDTH=65 ALIGN=right><FONT SIZE=-1><B>%"PRIu64"</B>" \
"</FONT></TD></TR>\n",msg_mtot_mhh, t_hit/(24*days_in_month),mh_hit);
/* Max/Avg Hits per Day */
fprintf(out_fp,"<TR>" \
"<TD><FONT SIZE=\"-1\">%s</FONT></TD>\n" \
"<TD ALIGN=right WIDTH=65><FONT SIZE=\"-1\"><B>%"PRIu64"</B></FONT></TD>\n" \
"<TD WIDTH=65 ALIGN=right><FONT SIZE=-1><B>%"PRIu64"</B>" \
"</FONT></TD></TR>\n",msg_mtot_mhd, t_hit/days_in_month, max_hits);
/* Max/Avg Files per Day */
fprintf(out_fp,"<TR>" \
"<TD><FONT SIZE=\"-1\">%s</FONT></TD>\n" \
"<TD ALIGN=right WIDTH=65><FONT SIZE=\"-1\"><B>%"PRIu64"</B></FONT></TD>\n" \
"<TD WIDTH=65 ALIGN=right><FONT SIZE=-1><B>%"PRIu64"</B>" \
"</FONT></TD></TR>\n",msg_mtot_mfd, t_file/days_in_month,max_files);
/* Max/Avg Pages per Day */
fprintf(out_fp,"<TR>" \
"<TD><FONT SIZE=\"-1\">%s</FONT></TD>\n" \
"<TD ALIGN=right WIDTH=65><FONT SIZE=\"-1\"><B>%"PRIu64"</B></FONT></TD>\n" \
"<TD WIDTH=65 ALIGN=right><FONT SIZE=-1><B>%"PRIu64"</B>" \
"</FONT></TD></TR>\n",msg_mtot_mpd, t_page/days_in_month,max_pages);
/* Max/Avg Sites per Day */
fprintf(out_fp,"<TR>" \
"<TD><FONT SIZE=\"-1\">%s</FONT></TD>\n" \
"<TD ALIGN=right WIDTH=65><FONT SIZE=\"-1\"><B>%"PRIu64"</B></FONT></TD>\n" \
"<TD WIDTH=65 ALIGN=right><FONT SIZE=-1><B>%"PRIu64"</B>" \
"</FONT></TD></TR>\n",msg_mtot_msd, t_site/days_in_month,max_sites);
/* Max/Avg Visits per Day */
fprintf(out_fp,"<TR>" \
"<TD><FONT SIZE=\"-1\">%s</FONT></TD>\n" \
"<TD ALIGN=right WIDTH=65><FONT SIZE=\"-1\"><B>%"PRIu64"</B></FONT></TD>\n" \
"<TD WIDTH=65 ALIGN=right><FONT SIZE=-1><B>%"PRIu64"</B>" \
"</FONT></TD></TR>\n",msg_mtot_mvd, t_visit/days_in_month,max_visits);
/* Max/Avg KBytes per Day */
fprintf(out_fp,"<TR>" \
"<TD><FONT SIZE=\"-1\">%s</FONT></TD>\n" \
"<TD ALIGN=right WIDTH=65><FONT SIZE=\"-1\"><B>%.0f</B></FONT></TD>\n" \
"<TD WIDTH=65 ALIGN=right><FONT SIZE=-1><B>%.0f</B>" \
"</FONT></TD></TR>\n",msg_mtot_mkd,
(t_xfer/1024)/days_in_month,max_xfer/1024);
fprintf(out_fp,"<TR><TH HEIGHT=4></TH></TR>\n");
/**********************************************/
/* response code totals */
fprintf(out_fp,"<TR><TH COLSPAN=3 ALIGN=center BGCOLOR=\"%s\">\n" \
"<FONT SIZE=\"-1\">%s</FONT></TH></TR>\n",GREY,msg_mtot_rc);
fprintf(out_fp,"<TR><TH HEIGHT=4 COLSPAN=3></TH></TR>\n");
for (i=0;i<TOTAL_RC;i++)
{
if (response[i].count != 0)
fprintf(out_fp,"<TR><TD><FONT SIZE=\"-1\">%s</FONT></TD>\n" \
"<TD ALIGN=right><FONT SIZE=\"-2\">%3.02f%%</FONT></TD>\n" \
"<TD ALIGN=right><FONT SIZE=\"-1\"><B>%"PRIu64"</B></FONT></TD></TR>\n",
response[i].desc,PCENT(response[i].count,t_hit),response[i].count);
}
fprintf(out_fp,"<TR><TH HEIGHT=4 COLSPAN=3></TH></TR>\n");
/**********************************************/
fprintf(out_fp,"</TABLE>\n");
fprintf(out_fp,"<P>\n");
}
/*********************************************/
/* DAILY_TOTAL_TABLE - daily totals */
/*********************************************/
void daily_total_table()
{
int i,j;
/* Daily stats */
fprintf(out_fp,"<TABLE WIDTH=510 BORDER=2 CELLSPACING=1 CELLPADDING=1>\n");
fprintf(out_fp,"<TR><TH HEIGHT=4 COLSPAN=13></TH></TR>\n");
/* Daily statistics for ... */
fprintf(out_fp,"<TR><TH BGCOLOR=\"%s\" COLSPAN=13 ALIGN=center>" \
"%s %s %d</TH></TR>\n",
GREY,msg_dtot_ds,l_month[cur_month-1], cur_year);
fprintf(out_fp,"<TR><TH HEIGHT=4 COLSPAN=13></TH></TR>\n");
fprintf(out_fp,"<TR><TH ALIGN=center BGCOLOR=\"%s\">" \
"<FONT SIZE=\"-1\">%s</FONT></TH>\n" \
"<TH ALIGN=center BGCOLOR=\"%s\" COLSPAN=2>" \
"<FONT SIZE=\"-1\">%s</FONT></TH>\n" \
"<TH ALIGN=center BGCOLOR=\"%s\" COLSPAN=2>" \
"<FONT SIZE=\"-1\">%s</FONT></TH>\n" \
"<TH ALIGN=center BGCOLOR=\"%s\" COLSPAN=2>" \
"<FONT SIZE=\"-1\">%s</FONT></TH>\n" \
"<TH ALIGN=center BGCOLOR=\"%s\" COLSPAN=2>" \
"<FONT SIZE=\"-1\">%s</FONT></TH>\n" \
"<TH ALIGN=center BGCOLOR=\"%s\" COLSPAN=2>" \
"<FONT SIZE=\"-1\">%s</FONT></TH>\n" \
"<TH ALIGN=center BGCOLOR=\"%s\" COLSPAN=2>" \
"<FONT SIZE=\"-1\">%s</FONT></TH></TR>\n",
GREY, msg_h_day,
HITCOLOR, msg_h_hits,
FILECOLOR, msg_h_files,
PAGECOLOR, msg_h_pages,
VISITCOLOR, msg_h_visits,
SITECOLOR, msg_h_sites,
KBYTECOLOR, msg_h_xfer);
fprintf(out_fp,"<TR><TH HEIGHT=4 COLSPAN=13></TH></TR>\n");
/* skip beginning blank days in a month */
for (i=0;i<l_day;i++) if (tm_hit[i]!=0) break;
if (i==l_day) i=0;
for (;i<l_day;i++)
{
j = jdate(i+1,cur_month,cur_year);
if ( (j%7==6) || (j%7==0) )
fprintf(out_fp,"<TR BGCOLOR=\"%s\"><TD ALIGN=center>",GRPCOLOR);
else fprintf(out_fp,"<TR><TD ALIGN=center>");
fprintf(out_fp,"<FONT SIZE=\"-1\"><B>%d</B></FONT></TD>\n", i+1);
fprintf(out_fp,"<TD ALIGN=right>" \
"<FONT SIZE=\"-1\"><B>%"PRIu64"</B></FONT></TD>\n" \
"<TD ALIGN=right><FONT SIZE=\"-2\">%3.02f%%</FONT></TD>\n",
tm_hit[i],PCENT(tm_hit[i],t_hit));
fprintf(out_fp,"<TD ALIGN=right>" \
"<FONT SIZE=\"-1\"><B>%"PRIu64"</B></FONT></TD>\n" \
"<TD ALIGN=right><FONT SIZE=\"-2\">%3.02f%%</FONT></TD>\n",
tm_file[i],PCENT(tm_file[i],t_file));
fprintf(out_fp,"<TD ALIGN=right>" \
"<FONT SIZE=\"-1\"><B>%"PRIu64"</B></FONT></TD>\n" \
"<TD ALIGN=right><FONT SIZE=\"-2\">%3.02f%%</FONT></TD>\n",
tm_page[i],PCENT(tm_page[i],t_page));
fprintf(out_fp,"<TD ALIGN=right>" \
"<FONT SIZE=\"-1\"><B>%"PRIu64"</B></FONT></TD>\n" \
"<TD ALIGN=right><FONT SIZE=\"-2\">%3.02f%%</FONT></TD>\n",
tm_visit[i],PCENT(tm_visit[i],t_visit));
fprintf(out_fp,"<TD ALIGN=right>" \
"<FONT SIZE=\"-1\"><B>%"PRIu64"</B></FONT></TD>\n" \
"<TD ALIGN=right><FONT SIZE=\"-2\">%3.02f%%</FONT></TD>\n",
tm_site[i],PCENT(tm_site[i],t_site));
fprintf(out_fp,"<TD ALIGN=right>" \
"<FONT SIZE=\"-1\"><B>%.0f</B></FONT></TD>\n" \
"<TD ALIGN=right><FONT SIZE=\"-2\">%3.02f%%</FONT></TD></TR>\n",
tm_xfer[i]/1024,PCENT(tm_xfer[i],t_xfer));
}
fprintf(out_fp,"<TR><TH HEIGHT=4 COLSPAN=13></TH></TR>\n");
fprintf(out_fp,"</TABLE>\n");
fprintf(out_fp,"<P>\n");
}
/*********************************************/
/* HOURLY_TOTAL_TABLE - hourly table */
/*********************************************/
void hourly_total_table()
{
int i,days_in_month;
u_int64_t avg_file=0;
double avg_xfer=0.0;
days_in_month=(l_day-f_day)+1;
/* Hourly stats */
fprintf(out_fp,"<TABLE WIDTH=510 BORDER=2 CELLSPACING=1 CELLPADDING=1>\n");
fprintf(out_fp,"<TR><TH HEIGHT=4 COLSPAN=13></TH></TR>\n");
fprintf(out_fp,"<TR><TH BGCOLOR=\"%s\" COLSPAN=13 ALIGN=center>"\
"%s %s %d</TH></TR>\n",
GREY,msg_htot_hs,l_month[cur_month-1], cur_year);
fprintf(out_fp,"<TR><TH HEIGHT=4 COLSPAN=13></TH></TR>\n");
fprintf(out_fp,"<TR><TH ALIGN=center ROWSPAN=2 BGCOLOR=\"%s\">" \
"<FONT SIZE=\"-1\">%s</FONT></TH>\n" \
"<TH ALIGN=center BGCOLOR=\"%s\" COLSPAN=3>" \
"<FONT SIZE=\"-1\">%s</FONT></TH>\n" \
"<TH ALIGN=center BGCOLOR=\"%s\" COLSPAN=3>" \
"<FONT SIZE=\"-1\">%s</FONT></TH>\n" \
"<TH ALIGN=center BGCOLOR=\"%s\" COLSPAN=3>" \
"<FONT SIZE=\"-1\">%s</FONT></TH>\n" \
"<TH ALIGN=center BGCOLOR=\"%s\" COLSPAN=3>" \
"<FONT SIZE=\"-1\">%s</FONT></TH></TR>\n",
GREY, msg_h_hour,
HITCOLOR, msg_h_hits,
FILECOLOR, msg_h_files,
PAGECOLOR, msg_h_pages,
KBYTECOLOR, msg_h_xfer);
fprintf(out_fp,"<TR><TH ALIGN=center BGCOLOR=\"%s\">" \
"<FONT SIZE=\"-2\">%s</FONT></TH>\n" \
"<TH ALIGN=center BGCOLOR=\"%s\" COLSPAN=2>" \
"<FONT SIZE=\"-2\">%s</FONT></TH>\n",
HITCOLOR, msg_h_avg, HITCOLOR, msg_h_total);
fprintf(out_fp,"<TH ALIGN=center BGCOLOR=\"%s\">" \
"<FONT SIZE=\"-2\">%s</FONT></TH>\n" \
"<TH ALIGN=center BGCOLOR=\"%s\" COLSPAN=2>" \
"<FONT SIZE=\"-2\">%s</FONT></TH>\n",
FILECOLOR, msg_h_avg, FILECOLOR, msg_h_total);
fprintf(out_fp,"<TH ALIGN=center BGCOLOR=\"%s\">" \
"<FONT SIZE=\"-2\">%s</FONT></TH>\n" \
"<TH ALIGN=center BGCOLOR=\"%s\" COLSPAN=2>" \
"<FONT SIZE=\"-2\">%s</FONT></TH>\n",
PAGECOLOR, msg_h_avg, PAGECOLOR, msg_h_total);
fprintf(out_fp,"<TH ALIGN=center BGCOLOR=\"%s\">" \
"<FONT SIZE=\"-2\">%s</FONT></TH>\n" \
"<TH ALIGN=center BGCOLOR=\"%s\" COLSPAN=2>" \
"<FONT SIZE=\"-2\">%s</FONT></TH></TR>\n",
KBYTECOLOR, msg_h_avg, KBYTECOLOR, msg_h_total);
fprintf(out_fp,"<TR><TH HEIGHT=4 COLSPAN=13></TH></TR>\n");
for (i=0;i<24;i++)
{
fprintf(out_fp,"<TR><TD ALIGN=center>" \
"<FONT SIZE=\"-1\"><B>%d</B></FONT></TD>\n",i);
fprintf(out_fp,
"<TD ALIGN=right><FONT SIZE=\"-1\"><B>%"PRIu64"</B></FONT></TD>\n"\
"<TD ALIGN=right><FONT SIZE=\"-1\"><B>%"PRIu64"</B></FONT></TD>\n"\
"<TD ALIGN=right><FONT SIZE=\"-2\">%3.02f%%</FONT></TD>\n",
th_hit[i]/days_in_month,th_hit[i],
PCENT(th_hit[i],t_hit));
fprintf(out_fp,
"<TD ALIGN=right><FONT SIZE=\"-1\"><B>%"PRIu64"</B></FONT></TD>\n"\
"<TD ALIGN=right><FONT SIZE=\"-1\"><B>%"PRIu64"</B></FONT></TD>\n"\
"<TD ALIGN=right><FONT SIZE=\"-2\">%3.02f%%</FONT></TD>\n",
th_file[i]/days_in_month,th_file[i],
PCENT(th_file[i],t_file));
fprintf(out_fp,
"<TD ALIGN=right><FONT SIZE=\"-1\"><B>%"PRIu64"</B></FONT></TD>\n"\
"<TD ALIGN=right><FONT SIZE=\"-1\"><B>%"PRIu64"</B></FONT></TD>\n"\
"<TD ALIGN=right><FONT SIZE=\"-2\">%3.02f%%</FONT></TD>\n",
th_page[i]/days_in_month,th_page[i],
PCENT(th_page[i],t_page));
fprintf(out_fp,
"<TD ALIGN=right><FONT SIZE=\"-1\"><B>%.0f</B></FONT></TD>\n" \
"<TD ALIGN=right><FONT SIZE=\"-1\"><B>%.0f</B></FONT></TD>\n" \
"<TD ALIGN=right><FONT SIZE=\"-2\">%3.02f%%</FONT></TD></TR>\n",
(th_xfer[i]/days_in_month)/1024,th_xfer[i]/1024,
PCENT(th_xfer[i],t_xfer));
avg_file += th_file[i]/days_in_month;
avg_xfer+= (th_xfer[i]/days_in_month)/1024;
}
fprintf(out_fp,"<TR><TH HEIGHT=4 COLSPAN=13></TH></TR>\n");
fprintf(out_fp,"</TABLE>\n<P>\n");
}
/*********************************************/
/* TOP_SITES_TABLE - generate top n table */
/*********************************************/
void top_sites_table(int flag)
{
u_int64_t cnt=0, h_reg=0, h_grp=0, h_hid=0, tot_num;
int i;
HNODEPTR hptr, *pointer;
cnt=a_ctr; pointer=h_array;
while(cnt--)
{
/* calculate totals */
switch ( ((HNODEPTR)*pointer)->flag )
{
case OBJ_REG: h_reg++; break;
case OBJ_GRP: h_grp++; break;
case OBJ_HIDE: h_hid++; break;
}
pointer++;
}
if ( (tot_num=h_reg+h_grp)==0 ) return; /* split if none */
i=(flag)?ntop_sitesK:ntop_sites; /* Hits or KBytes?? */
if (tot_num > i) tot_num = i; /* get max to do... */
if ((!flag) || (flag&&!ntop_sites)) /* now do <A> tag */
fprintf(out_fp,"<A NAME=\"TOPSITES\"></A>\n");
fprintf(out_fp,"<TABLE WIDTH=510 BORDER=2 CELLSPACING=1 CELLPADDING=1>\n");
fprintf(out_fp,"<TR><TH HEIGHT=4 COLSPAN=10></TH></TR>\n");
if (flag) fprintf(out_fp,"<TR><TH BGCOLOR=\"%s\" ALIGN=CENTER COLSPAN=10>" \
"%s %"PRIu64" %s %"PRIu64" %s %s %s</TH></TR>\n",
GREY, msg_top_top,tot_num,msg_top_of,
t_site,msg_top_s,msg_h_by,msg_h_xfer);
else fprintf(out_fp,"<TR><TH BGCOLOR=\"%s\" ALIGN=CENTER COLSPAN=10>" \
"%s %"PRIu64" %s %"PRIu64" %s</TH></TR>\n",
GREY,msg_top_top, tot_num, msg_top_of, t_site, msg_top_s);
fprintf(out_fp,"<TR><TH HEIGHT=4 COLSPAN=10></TH></TR>\n");
fprintf(out_fp,"<TR><TH BGCOLOR=\"%s\" ALIGN=center>" \
"<FONT SIZE=\"-1\">#</FONT></TH>\n",GREY);
fprintf(out_fp,"<TH BGCOLOR=\"%s\" ALIGN=center COLSPAN=2>" \
"<FONT SIZE=\"-1\">%s</FONT></TH>\n",HITCOLOR,msg_h_hits);
fprintf(out_fp,"<TH BGCOLOR=\"%s\" ALIGN=center COLSPAN=2>" \
"<FONT SIZE=\"-1\">%s</FONT></TH>\n",FILECOLOR,msg_h_files);
fprintf(out_fp,"<TH BGCOLOR=\"%s\" ALIGN=center COLSPAN=2>" \
"<FONT SIZE=\"-1\">%s</FONT></TH>\n",KBYTECOLOR,msg_h_xfer);
fprintf(out_fp,"<TH BGCOLOR=\"%s\" ALIGN=center COLSPAN=2>" \
"<FONT SIZE=\"-1\">%s</FONT></TH>\n",VISITCOLOR,msg_h_visits);
fprintf(out_fp,"<TH BGCOLOR=\"%s\" ALIGN=center>" \
"<FONT SIZE=\"-1\">%s</FONT></TH></TR>\n",MISCCOLOR,msg_h_hname);
fprintf(out_fp,"<TR><TH HEIGHT=4 COLSPAN=10></TH></TR>\n");
pointer=h_array; i=0;
while(tot_num)
{
hptr=*pointer++;
if (hptr->flag != OBJ_HIDE)
{
/* shade grouping? */
if (shade_groups && (hptr->flag==OBJ_GRP))
fprintf(out_fp,"<TR BGCOLOR=\"%s\">\n", GRPCOLOR);
else fprintf(out_fp,"<TR>\n");
fprintf(out_fp,
"<TD ALIGN=center><FONT SIZE=\"-1\"><B>%d</B></FONT></TD>\n" \
"<TD ALIGN=right><FONT SIZE=\"-1\"><B>%"PRIu64"</B></FONT></TD>\n" \
"<TD ALIGN=right><FONT SIZE=\"-2\">%3.02f%%</FONT></TD>\n" \
"<TD ALIGN=right><FONT SIZE=\"-1\"><B>%"PRIu64"</B></FONT></TD>\n" \
"<TD ALIGN=right><FONT SIZE=\"-2\">%3.02f%%</FONT></TD>\n" \
"<TD ALIGN=right><FONT SIZE=\"-1\"><B>%.0f</B></FONT></TD>\n" \
"<TD ALIGN=right><FONT SIZE=\"-2\">%3.02f%%</FONT></TD>\n" \
"<TD ALIGN=right><FONT SIZE=\"-1\"><B>%"PRIu64"</B></FONT></TD>\n" \
"<TD ALIGN=right><FONT SIZE=\"-2\">%3.02f%%</FONT></TD>\n" \
"<TD ALIGN=left NOWRAP><FONT SIZE=\"-1\">",
i+1,hptr->count,
(t_hit==0)?0:((float)hptr->count/t_hit)*100.0,hptr->files,
(t_file==0)?0:((float)hptr->files/t_file)*100.0,hptr->xfer/1024,
(t_xfer==0)?0:((float)hptr->xfer/t_xfer)*100.0,hptr->visit,
(t_visit==0)?0:((float)hptr->visit/t_visit)*100.0);
if ((hptr->flag==OBJ_GRP)&&hlite_groups)
fprintf(out_fp,"<STRONG>%s</STRONG></FONT></TD></TR>\n",
hptr->string);
else fprintf(out_fp,"%s</FONT></TD></TR>\n",
hptr->string);
tot_num--;
i++;
}
}
fprintf(out_fp,"<TR><TH HEIGHT=4 COLSPAN=10></TH></TR>\n");
if ((!flag) || (flag&&!ntop_sites))
{
if ( (all_sites) && ((h_reg+h_grp)>ntop_sites) )
{
if (all_sites_page(h_reg, h_grp))
{
fprintf(out_fp,"<TR BGCOLOR=\"%s\">",GRPCOLOR);
fprintf(out_fp,"<TD COLSPAN=10 ALIGN=\"center\">\n");
fprintf(out_fp,"<FONT SIZE=\"-1\">");
fprintf(out_fp,"<A HREF=\"./site_%04d%02d.%s\">",
cur_year,cur_month,html_ext);
fprintf(out_fp,"%s</A></TD></TR>\n",msg_v_sites);
if (flag) /* do we need to sort? */
qsort(h_array,a_ctr,sizeof(HNODEPTR),qs_site_cmph);
}
}
}
fprintf(out_fp,"</TABLE>\n<P>\n");
}
/*********************************************/
/* ALL_SITES_PAGE - HTML page of all sites */
/*********************************************/
int all_sites_page(u_int64_t h_reg, u_int64_t h_grp)
{
HNODEPTR hptr, *pointer;
char site_fname[256], buffer[256];
FILE *out_fp;
int i=(h_grp)?1:0;
/* generate file name */
snprintf(site_fname,sizeof(site_fname),"site_%04d%02d.%s",
cur_year,cur_month,html_ext);
/* open file */
if ( (out_fp=open_out_file(site_fname))==NULL ) return 0;
snprintf(buffer,sizeof(buffer),"%s %d - %s",
l_month[cur_month-1],cur_year,msg_h_sites);
write_html_head(buffer, out_fp);
fprintf(out_fp,"<FONT SIZE=\"-1\"></CENTER><PRE>\n");
fprintf(out_fp," %12s %12s %12s %12s %s\n",
msg_h_hits, msg_h_files, msg_h_xfer, msg_h_visits, msg_h_hname);
fprintf(out_fp,"---------------- ---------------- ---------------- " \
"---------------- --------------------\n\n");
/* Do groups first (if any) */
pointer=h_array;
while(h_grp)
{
hptr=*pointer++;
if (hptr->flag == OBJ_GRP)
{
fprintf(out_fp,
"%-8"PRIu64" %6.02f%% %8"PRIu64" %6.02f%% %8.0f %6.02f%% " \
"%8"PRIu64" %6.02f%% %s\n",
hptr->count,
(t_hit==0)?0:((float)hptr->count/t_hit)*100.0,hptr->files,
(t_file==0)?0:((float)hptr->files/t_file)*100.0,hptr->xfer/1024,
(t_xfer==0)?0:((float)hptr->xfer/t_xfer)*100.0,hptr->visit,
(t_visit==0)?0:((float)hptr->visit/t_visit)*100.0,
hptr->string);
h_grp--;
}
}
if (i) fprintf(out_fp,"\n");
/* Now do individual sites (if any) */
pointer=h_array;
if (!hide_sites) while(h_reg)
{
hptr=*pointer++;
if (hptr->flag == OBJ_REG)
{
fprintf(out_fp,
"%-8"PRIu64" %6.02f%% %8"PRIu64" %6.02f%% %8.0f %6.02f%% " \
"%8"PRIu64" %6.02f%% %s\n",
hptr->count,
(t_hit==0)?0:((float)hptr->count/t_hit)*100.0,hptr->files,