📄 output.c
字号:
/* webalizer - a web server log analysis program Copyright (C) 1997-2001 Bradford L. Barrett (brad@mrunix.net) 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 This software uses the gd graphics library, which is copyright by Quest Protein Database Center, Cold Spring Harbor Labs. Please see the documentation supplied with the library for additional information and license terms, or visit www.boutell.com/gd/ for the most recent version of the library and supporting documentation.*//*********************************************//* STANDARD INCLUDES *//*********************************************/#include <time.h>#include <stdio.h>#include <stdlib.h>#include <string.h>#include <unistd.h> /* normal stuff */#include <ctype.h>#include <sys/utsname.h>#include <sys/times.h>/* ensure getopt */#ifdef HAVE_GETOPT_H#include <getopt.h>#endif/* ensure sys/types */#ifndef _SYS_TYPES_H#include <sys/types.h>#endif/* some systems need this */#ifdef HAVE_MATH_H#include <math.h>#endif/* SunOS 4.x Fix */#ifndef CLK_TCK#define CLK_TCK _SC_CLK_TCK#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 URL's 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_long load_url_array( UNODEPTR *); /* load URL array */u_long load_site_array( HNODEPTR *); /* load Site array */u_long load_ref_array( RNODEPTR *); /* load Refs array */u_long load_agent_array(ANODEPTR *); /* load Agents array */u_long load_srch_array( SNODEPTR *); /* load srch str array */u_long 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_long, u_long); /* output site page */int all_urls_page(u_long, u_long); /* output urls page */int all_refs_page(u_long, u_long); /* output refs page */int all_agents_page(u_long, u_long); /* output agents page */int all_search_page(u_long, u_long); /* output search page */int all_users_page(u_long, u_long); /* 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"/* sort arrays */UNODEPTR *u_array = NULL; /* Sort array for URL's */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_long 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-2000 Bradford L. Barrett -->\n"); fprintf(out_fp,"<!-- (brad@mrunix.net http://www.mrunix.net) -->\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.mrunix.net/webalizer/ -->\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>\n<HEAD>\n"); fprintf(out_fp," <TITLE>%s %s - %s</TITLE>\n", msg_title, hname, period); 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); fprintf(out_fp,"<SMALL><STRONG>\n%s: %s<BR>\n",msg_hhdr_sp,period); 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.mrunix.net/webalizer/\">"); 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(){ int i; 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); /* update history */ i=cur_month-1; hist_month[i] = cur_month; hist_year[i] = cur_year; hist_hit[i] = t_hit; hist_files[i] = t_file; hist_page[i] = t_page; hist_visit[i] = t_visit; hist_site[i] = t_site; hist_xfer[i] = t_xfer/1024; hist_fday[i] = f_day; hist_lday[i] = l_day; /* fill in filenames */ sprintf(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) { sprintf(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) { sprintf(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;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -