⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 generate.c

📁 100 病毒源碼,原始碼,無毒 ......
💻 C
📖 第 1 页 / 共 4 页
字号:
/*** Modular Logfile Analyzer** Copyright 2000 Jan Kneschke <jan@kneschke.de>**** Homepage: http://www.kneschke.de/projekte/modlogan**    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**** $Id: generate.c,v 1.18 2001/01/11 22:30:17 jk Exp $*/#include <libintl.h>#include <locale.h>#include <stdlib.h>#include <stdio.h>#include <time.h>#include <math.h>#include <string.h>#include <unistd.h>#include <sys/types.h>#include <sys/stat.h>#include <fcntl.h>#include <errno.h>#include "mconfig.h"#include "mstate.h"#include "mlocale.h"#include "mhash.h"#include "mlist.h"#include "mdatatypes.h"#include "mplugins.h"#include "pictures.h"#include "plugin_config.h"#define HIGHLIGHT	1#define GROUPING	2#define VISITS		4#define INDEX		8#define BROKEN_LINK	16#define PERCENT		32/* tla -> Three Letter Abbreviation */char *get_month_string(int m, int tla) {	static char monthname[255];		struct tm *tm;	time_t t = time(NULL);		tm = localtime(&t);		tm->tm_mon = m > 0 ? m - 1 : 11;		strftime(monthname, sizeof(monthname)-1, tla ? "%b" : "%B", tm);	return monthname;}char *htmlencode(const char *s) {	char *p;	char *q = NULL;	int q_len = 0;	if (!s) return NULL;		q_len = strlen(s) * 2 + 1;	q = malloc(q_len);	p = q;	*p = '\0';		while (*s) {		switch(*s) {			case '<':				*p = '&';				*(++p) = 'l';				*(++p) = 't';				*(++p) = ';';				break;			case '>':				*p = '&';				*(++p) = 'g';				*(++p) = 't';				*(++p) = ';';				break;			default:				*p = *s;				break;		}		*(++p) = '\0';		s++;				if (strlen(q) > (q_len - 4)) {			q_len += 128;			q = realloc(q, q_len);						p = q + strlen(q);		}	}		return q;}int mhash_get_value(mhash *h[], const char *key) {	int c = 0, i;	if (!h) return 0;		for ( i = 0; i < HASH_SIZE; i++) {		mlist *l = h[i]->list;		while (l) {			if (l->data) {				data_StrInt *data = (data_StrInt *)l->data;								if (!strcmp(key, data->string)) {					c = data->count;					break;				}			}			l = l->next;		}		if (c != 0) break;	}		return c;}long mlist_sumup(mlist *l) {	int c = 0;	if (!l) return 0;		while (l) {		if (l->data) c += ((data_StrInt*)l->data)->count;		l = l->next;	}		return c;}long mhash_sumup(mhash *h[]) {	int i, c = 0;	if (!h) return 0;		for ( i = 0; i < HASH_SIZE; i++) {		c += mlist_sumup(h[i]->list);	}		return c;}int show_mhash (mconfig *ext_conf, FILE *f, mhash *h[], int count, int opt) {	mlist *l, *first;	int i = 0;	config_output *conf = ext_conf->output;	long sum = 0;		if (!h) return 0;		first = l = mlist_init();		sum = mhash_sumup(h);		mhash_unfold_sorted_limited(h, l, count);		while (l && (i++ < count)) {		data_StrInt *data = (data_StrInt *)l->data;				if (data) {			char *enc_url = NULL;			int cut_url = 0;						if (!conf->dont_escape_entities) {				enc_url = htmlencode(data->string);			} else {					enc_url = malloc(strlen(data->string)+1);				strcpy(enc_url, data->string);			}						cut_url = (strlen(enc_url) > 40) && !conf->dont_cut_urls;						if (cut_url) {				enc_url[40] = '\0';			}						fprintf(f,"<TR>");						if (opt & INDEX) {				fprintf(f,"<TD width=\"5%%\" align=right>%d</TD>", i);			}						fprintf(f,"<TD width=\"15%%\" align=right>%d</TD>", data->count);						if (opt & PERCENT && sum) {				fprintf(f,"<TD width=\"5%%\" align=right>%.2f</TD>", data->count * 100.0 / sum);			}						if (opt & VISITS) {				data_Str3Int *_data = (data_Str3Int *)l->data;				fprintf(f,"<TD width=\"15%%\" align=right>%d</TD>", _data->vcount);			}			if ((opt & GROUPING) && data->type == M_GROUP) {				fprintf(f,"<TD class=\"grouping\">%s%s</TD>", enc_url, cut_url ? "..." : "");			} else {				if (opt & HIGHLIGHT) {					if (conf->assumedprotocol == NULL || strstr(data->string, "://")) {						fprintf(f,"<TD><a href=\"%s\">%s</a>%s</TD>", data->string, enc_url, cut_url ? "..." : "");					} else {						fprintf(f,"<TD><a href=\"%s://%s%s%s\">%s</a>%s</TD>", conf->assumedprotocol, conf->hostname, *data->string == '/' ? "" : "/", data->string, enc_url, cut_url ? "..." : "");					}				} else {					fprintf(f,"<TD>%s%s</TD>", enc_url, cut_url ? "..." : "");				}			}			if (opt & BROKEN_LINK) {				data_BrokenLink *_data = l->data;				struct tm *_tm;				char timebuf[32] = "";								if (strcmp(_data->referrer, "-")) {					free(enc_url);					enc_url = htmlencode(_data->referrer);					cut_url = strlen(enc_url) > 40;								if (cut_url) {						enc_url[40] = '\0';					}					fprintf(f,"<TD><a href=\"%s\">%s</a>%s</TD>", _data->referrer, enc_url, cut_url ? "..." : "");				} else {					fprintf(f,"<TD>%s</TD>", _data->referrer);				}								_tm = localtime(&(_data->timestamp));				if (strftime(timebuf, sizeof(timebuf)-1, "%x", _tm) == 0) {					fprintf(stderr, "output::modlogan.show_mhash: strftime failed\n");				}				fprintf(f,"<TD>%s</TD>", timebuf);			}			fprintf(f,"</TR>\n");						free(enc_url);		}				l = l->next;	}		mlist_free(first);	return 0;}int mhash_status_unfold_sorted_limited(mhash *h[], mlist *l, int count ) {	int i, j;	data_StrInt *data, *ins_data;	char __dummy__[] = "999";	char __dummy_2_[] = "";	char *max, *last = __dummy_2_;		for ( j = 0; j < count; j++) {		data = NULL;				max = __dummy__;				for ( i = 0; i < HASH_SIZE; i++) {			if (h[i]->list) {				mlist *hl;							hl = h[i]->list;				while (hl) {					if (hl->data) {						if ( strcmp(((data_StrInt *)hl->data)->string, max) < 0 &&							strcmp(((data_StrInt *)hl->data)->string, last) > 0) {							max = ((data_StrInt *)hl->data)->string;							data = (data_StrInt *)hl->data;						}					}					hl = hl->next;				}			}		}				if (data) {			ins_data = createStrInt(data->string, data->count);						mlist_insert(l, ins_data);						last = data->string;		}	}		return 0;}int show_status_mhash (FILE *f, mhash *h[], int count) {	mlist *l, *first;	int i = 0;		if (!h) return 0;		first = l = mlist_init();		mhash_status_unfold_sorted_limited(h, l, count);		while (l && (i++ < count)) {		data_StrInt *data = (data_StrInt *)l->data;				if (data)			fprintf(f,"<TR><TD width=\"15%%\" align=right>%d</TD><TD>%s - %s</TD></TR>\n", data->count, data->string, mhttpcodes(strtol(data->string, NULL, 10)));				l = l->next;	}		mlist_free(first);	return 0;}void table_start(FILE *f, char *str, int colspan) {	fprintf(f,"<P><CENTER><TABLE BORDER=1 WIDTH=\"%s\" BGCOLOR=\"#eeeeee\"><TR><TH colspan=%d>%s</TH></TR>\n", colspan < 0 ? "100%": "400", colspan < 0 ? -colspan : colspan, str);}void table_end(FILE *f) {	fprintf(f,"</TABLE></CENTER><P>");}void file_start(FILE *f, mconfig *ext_conf, time_t timestamp) {	char buf[255];	struct tm *_tm;	time_t t;	config_output *conf = ext_conf->output;	int show_default = 1;		if (conf->html_header) {		FILE *inf = fopen (conf->html_header, "r");				if (inf == NULL) {			fprintf(stderr, "%s.%d: %s: %s", __FILE__, __LINE__, _("Can't open page header"),strerror(errno));		} else {			char buf[255];						while (fgets(buf, sizeof(buf)-1, inf)) {				if (fputs(buf, f) == EOF) {					fprintf(stderr, "%s.%d: %s: %s", __FILE__, __LINE__, _("Can't write header"),strerror(errno));					break;				}			}						show_default = 0;			fclose(inf);		}	} 		if (show_default) {		fprintf(f, "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\">\n\n");		fprintf(f, "<HTML><HEAD><TITLE>%s</TITLE>", _("Statistics"));		fprintf(f, "<LINK REL=STYLESHEET HREF=\"modlogan.css\" type=\"text/css\">");		fprintf(f, "<META http-equiv=\"Content-Type\" content=\"text/html; charset=%s\">", conf->cont_charset);		fprintf(f, "<META http-equiv=\"Content-Language\" content=\"%s\">", conf->cont_language);		fprintf(f, "</HEAD>\n");		fprintf(f, "<BODY bgcolor=\"%s\">\n", conf->col_body);			fprintf(f, "<H1>%s %s</H1>\n", _("Statistics for"), conf->hostname);		if (timestamp != 0) {			t = timestamp;			_tm = localtime(&t);			strftime(buf, sizeof(buf), "%X %x", _tm);			fprintf(f, "<b>%s: </b>%s<br>\n", _("Last record"), buf);		}		t = time(NULL);		_tm = localtime(&t);		strftime(buf, sizeof(buf), "%X %x", _tm);		fprintf(f, "<b>%s: </b>%s<br>\n", _("Generated at"), buf);		fprintf(f, "<HR><br>\n");	}		fprintf(f, "<TABLE class=\"menu\" width=\"100%%\"><TR valign=top><TD>\n");}void file_end(FILE *f, mconfig *ext_conf) {	config_output *conf = ext_conf->output;	int show_default = 1;		fprintf(f, "</TD></TR></TABLE>\n");		if (conf->html_footer) {		FILE *inf = fopen (conf->html_footer, "r");				if (inf == NULL) {			fprintf(stderr, "%s.%d: %s: %s", __FILE__, __LINE__, _("Can't open page footer"),strerror(errno));		} else {			char buf[255];						while (fgets(buf, sizeof(buf)-1, inf)) {				if (fputs(buf, f) == EOF) {					fprintf(stderr, "%s.%d: %s: %s", __FILE__, __LINE__, _("Can't write footer"),strerror(errno));					break;				}			}						show_default = 0;			fclose(inf);		}	}		if (show_default) {		fprintf(f, "<HR>");				if (conf->show_validation_links) {/* Tell the users that this is valid HTML 4.0  :) */			fprintf(f, "<a href=\"http://validator.w3.org/check/referer\"><img border=0 "\				"src=\"http://validator.w3.org/images/vh40\" "\				"alt=\"Valid HTML 4.0!\" height=31 width=88 align=\"right\"></a>");/* Tell the users that this is even valid CSS  :) */			fprintf(f, "<A HREF=\"http://jigsaw.w3.org/css-validator/check/referer/\"><IMG border=0 width=\"88\" height=\"31\"");			fprintf(f, "SRC=\"http://jigsaw.w3.org/css-validator/images/vcss.gif\" ALT=\"Valid CSS!\" align=\"right\"></A>");		}		

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -