📄 generate.c
字号:
/*** 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.14 2000/08/13 17:08:51 jk Exp $*/#include <libintl.h>#include <locale.h>#include <stdlib.h>#include <stdio.h>#include <time.h>#include <math.h>#include "mconfig.h"#include "mstate.h"#include "mlocale.h"#include "mhash.h"#include "mlist.h"#include "mdatatypes.h"#include "mplugins.h"#include "plugin_config.h"#define HIGHLIGHT 1#define GROUPING 2#define VISITS 4/* 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;}void table_start(FILE *f, char *str, int colspan) { int i = colspan; char numbuf[10]; fprintf(f, "+"); while (i) { fprintf(f, "-"); i--; } fprintf(f, "+\n"); sprintf(numbuf, "| %%-%is |\n", colspan-2); fprintf(f, numbuf, str);}void table_end(FILE *f, int colspan) { int i = colspan; fprintf(f, "+"); while (i) { fprintf(f, "-"); i--; } fprintf(f, "+\n");}void file_start(FILE *f, mconfig *ext_conf) { config_output *conf = ext_conf->output; fprintf(f, "%s %s\n", _("Statistics for"), conf->hostname);}void file_end(FILE *f) { fprintf(f, "Output generated by %s %s\n", PACKAGE, VERSION);}char *table_header(int maxcount, int count, char *str) { static char trans_buf[255]; sprintf(trans_buf, "%i %s %i %s", (maxcount > count) || (maxcount < 0) ? count : maxcount, _("of"), count, str); return trans_buf; }int mplugins_output_generate_monthly_output(mconfig *ext_conf, mstate *state, char *subpath) { return 0;}int mplugins_output_generate_history_output(mconfig *ext_conf, mlist *history, char *subpath) { mlist *l = history; FILE *f; char filename[255]; char numbuf[255]; int colwidth[11] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; data_History max; data_History *data = ((data_History *)l->data); int i, sum, j; sprintf(filename, "%s/overview.txt", ext_conf->outputdir ? ext_conf->outputdir : "."); if (!(f = fopen(filename, "w"))) { return -1; } max.hits = 0; max.files = 0; max.pages = 0; max.visits = 0; max.hosts = 0; max.xfersize = 0; #define SET_MAX(x) if (_data->x > max.x) max.x = _data->x while (l) { data_History *_data = l->data; if (data) { SET_MAX(hits); SET_MAX(files); SET_MAX(pages); SET_MAX(visits); SET_MAX(hosts); SET_MAX(xfersize); } if (!l->next) break; l = l->next; }#undef SET_MAX/* get maximun col width */ colwidth[0] = 8; /* month column */ sprintf( numbuf, "%li", max.hits / data->count ); if (strlen(numbuf) > colwidth[1]) colwidth[1] = strlen(numbuf); sprintf( numbuf, "%li", max.files / data->count ); if (strlen(numbuf) > colwidth[2]) colwidth[2] = strlen(numbuf); sprintf( numbuf, "%li", max.pages / data->count ); if (strlen(numbuf) > colwidth[3]) colwidth[3] = strlen(numbuf); sprintf( numbuf, "%li", max.visits / data->count ); if (strlen(numbuf) > colwidth[4]) colwidth[4] = strlen(numbuf); sprintf( numbuf, "%.0f", max.xfersize / 1024 / data->count ); if (strlen(numbuf) > colwidth[5]) colwidth[5] = strlen(numbuf); sprintf( numbuf, "%li", max.hits ); if (strlen(numbuf) > colwidth[6]) colwidth[6] = strlen(numbuf); sprintf( numbuf, "%li", max.files ); if (strlen(numbuf) > colwidth[7]) colwidth[7] = strlen(numbuf); sprintf( numbuf, "%li", max.pages ); if (strlen(numbuf) > colwidth[8]) colwidth[8] = strlen(numbuf); sprintf( numbuf, "%li", max.visits ); if (strlen(numbuf) > colwidth[9]) colwidth[9] = strlen(numbuf); sprintf( numbuf, "%.0f", max.xfersize / 1024); if (strlen(numbuf) > colwidth[10]) colwidth[10] = strlen(numbuf); sprintf( numbuf, "%s", _("Hits") ); if (strlen(numbuf) > colwidth[1]) colwidth[1] = strlen(numbuf); sprintf( numbuf, "%s", _("Files") ); if (strlen(numbuf) > colwidth[2]) colwidth[2] = strlen(numbuf); sprintf( numbuf, "%s", _("Pages") ); if (strlen(numbuf) > colwidth[3]) colwidth[3] = strlen(numbuf); sprintf( numbuf, "%s", _("Visits") ); if (strlen(numbuf) > colwidth[4]) colwidth[4] = strlen(numbuf); sprintf( numbuf, "%s", _("KBytes") ); if (strlen(numbuf) > colwidth[5]) colwidth[5] = strlen(numbuf); sprintf( numbuf, "%s", _("Hits") ); if (strlen(numbuf) > colwidth[6]) colwidth[6] = strlen(numbuf); sprintf( numbuf, "%s", _("Files") ); if (strlen(numbuf) > colwidth[7]) colwidth[7] = strlen(numbuf); sprintf( numbuf, "%s", _("Pages") ); if (strlen(numbuf) > colwidth[8]) colwidth[8] = strlen(numbuf); sprintf( numbuf, "%s", _("Visits") ); if (strlen(numbuf) > colwidth[9]) colwidth[9] = strlen(numbuf); sprintf( numbuf, "%s", _("KBytes") ); if (strlen(numbuf) > colwidth[10]) colwidth[10] = strlen(numbuf); file_start(f,ext_conf); sum = 11 - 1; for ( i = 0; i < 11; i++) sum += colwidth[i] + 2; table_start(f, _("History"), sum); sprintf(numbuf, "| %%%is | %%%is | %%%is |\n", colwidth[0], colwidth[1] + 3 + colwidth[2] + 3 + colwidth[3] + 3 + colwidth[4] + 3 + colwidth[5], colwidth[6] + 3 + colwidth[7] + 3 + colwidth[8] + 3 + colwidth[9] + 3 + colwidth[10] );/* <HR> */ i = colwidth[0] + 2; fprintf(f, "+"); while (i) { fprintf(f, "-"); i--; } i = colwidth[1] + 3 + colwidth[2] + 3 + colwidth[3] + 3 + colwidth[4] + 3 + colwidth[5] + 2; fprintf(f, "+"); while (i) { fprintf(f, "-"); i--; } i = colwidth[6] + 3 + colwidth[7] + 3 + colwidth[8] + 3 + colwidth[9] + 3 + colwidth[10] + 2; fprintf(f, "+"); while (i) { fprintf(f, "-"); i--; } fprintf(f, "+\n"); fprintf(f, numbuf, "", _("Average/day"), _("Totals") ); /* <HR> */ for (j = 0; j < 11; j++) { i = colwidth[j] + 2; fprintf(f, "+"); while (i) { fprintf(f, "-"); i--; } } fprintf(f, "+\n"); sprintf(numbuf, "| %%%is | %%%is | %%%is | %%%is | %%%is | %%%is | %%%is | %%%is | %%%is | %%%is | %%%is |\n", colwidth[0], colwidth[1], colwidth[2], colwidth[3], colwidth[4], colwidth[5], colwidth[6], colwidth[7], colwidth[8], colwidth[9], colwidth[10] ); fprintf(f, numbuf, _("Month"), _("Hits"), _("Files"), _("Pages"), _("Visits"), _("KBytes"), _("Hits"), _("Files"), _("Pages"), _("Visits"), _("KBytes") );/* <HR> */ for (j = 0; j < 11; j++) { i = colwidth[j] + 2; fprintf(f, "+"); while (i) { fprintf(f, "-"); i--; } } fprintf(f, "+\n"); sprintf(numbuf, "| %%s %%04i | %%%ili | %%%ili | %%%ili | %%%ili | %%%i.0f | %%%ili | %%%ili | %%%ili | %%%ili | %%%i.0f |\n", colwidth[1], colwidth[2], colwidth[3], colwidth[4], colwidth[5], colwidth[6], colwidth[7], colwidth[8], colwidth[9], colwidth[10] ); while (l) { data_History *data = ((data_History *)l->data); if (!data) break; fprintf(f, numbuf, get_month_string(data->month,1), data->year, data->hits / data->count, data->files / data->count, data->pages/ data->count, data->visits/ data->count, data->xfersize / 1024 / data->count, data->hits, data->files, data->pages, data->visits, data->xfersize / 1024 ); l = l->prev; } table_end(f, sum); file_end(f); fclose(f); return 0;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -