]> git.ipfire.org Git - thirdparty/sarg.git/blame - dansguardian_report.c
Fix HTML output
[thirdparty/sarg.git] / dansguardian_report.c
CommitLineData
25697a35 1/*
c37945ed 2 * AUTHOR: Pedro Lineu Orso pedro.orso@gmail.com
a6e5c172 3 * 1998, 2010
94ff9470 4 * SARG Squid Analysis Report Generator http://sarg.sourceforge.net
25697a35
GS
5 *
6 * SARG donations:
7 * please look at http://sarg.sourceforge.net/donations.php
8 * ---------------------------------------------------------------------
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
23 *
24 */
25
26#include "include/conf.h"
5f3cfd1d 27#include "include/defs.h"
25697a35 28
32e71fa4 29void dansguardian_report(void)
25697a35
GS
30{
31
32 FILE *fp_in = NULL, *fp_ou = NULL;
120d768c 33
25697a35 34 char url[MAXLEN];
25697a35 35 char dansguardian_in[MAXLEN];
25697a35
GS
36 char per[MAXLEN];
37 char report[MAXLEN];
d6e703cc 38 char period[100];
25697a35
GS
39 char ip[MAXLEN];
40 char rule[255];
41 char oip[MAXLEN];
42 char user[MAXLEN];
43 char ouser[MAXLEN];
44 char date[15];
45 char date2[15];
46 char hour[15];
25697a35
GS
47 char *str;
48 int z=0;
49 int count=0;
9c7c6346 50 struct getwordstruct gwarea;
25697a35
GS
51
52 ouser[0]='\0';
53
54 sprintf(dansguardian_in,"%s/dansguardian.log",tmp);
55 if(!dansguardian_count) {
56 unlink(dansguardian_in);
57 return;
58 }
59
d6e703cc 60 sprintf(per,"%s/sarg-period",dirname);
25697a35
GS
61 sprintf(report,"%s/dansguardian.html",dirname);
62
63 if ((fp_in = fopen(per, "r")) == 0) {
64 fprintf(stderr, "SARG: (dansguardian_report) %s: %s\n",text[45],per);
65 exit(1);
66 }
67
05b90947
FM
68 if (!fgets(period,sizeof(period),fp_in)) {
69 fprintf(stderr,"SARG: (dansguardian_report) read error in %s\n",per);
70 exit(1);
71 }
25697a35
GS
72 fclose(fp_in);
73
936c9905 74 if((fp_in=MY_FOPEN(dansguardian_in,"r"))==NULL) {
25697a35
GS
75 fprintf(stderr, "SARG: (dansguardian_report) %s: %s\n",text[8],dansguardian_in);
76 exit(1);
77 }
78
936c9905 79 if((fp_ou=MY_FOPEN(report,"w"))==NULL) {
25697a35
GS
80 fprintf(stderr, "SARG: (dansguardian_report) %s: %s\n",text[8],report);
81 exit(1);
82 }
83
d6e703cc 84 fprintf(fp_ou, "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">\n<html>\n<head>\n <meta http-equiv=\"Content-Type\" content=\"text/html; charset=%s\">\n",CharSet);
25697a35
GS
85 css(fp_ou);
86 fputs("</head>\n",fp_ou);
d6e703cc
FM
87 if(strlen(FontFace) > 0) fprintf(fp_ou,"<font face=%s>\n",FontFace);
88 fprintf(fp_ou,"<body bgcolor=%s text=%s background='%s'>\n",BgColor,TxColor,BgImage);
dfb337be
FM
89 write_logo_image(fp_ou);
90
491b862f
GS
91 if(strcmp(IndexTree,"date") == 0)
92 show_sarg(fp_ou, "../../..");
93 else
94 show_sarg(fp_ou,"..");
dfb337be 95 fputs("<div align=\"center\"><table cellpadding=\"0\" cellspacing=\"0\">\n",fp_ou);
354c1a68 96 fprintf(fp_ou,"<tr><th class=\"title\">%s</th></tr>\n",Title);
25697a35 97
354c1a68
FM
98 fprintf(fp_ou,"<tr><td class=\"header\">%s: %s</td></tr>\n",text[89],period);
99 fprintf(fp_ou,"<tr><th class=\"header3\">%s</th></tr>\n",text[128]);
dfb337be 100 fputs("</table></div>\n",fp_ou);
25697a35 101
dfb337be 102 fputs("<div align=\"center\"><table cellpadding=\"1\" cellspacing=\"2\">\n",fp_ou);
25697a35 103 fputs("<tr><td></td></tr>\n",fp_ou);
354c1a68 104 fprintf(fp_ou,"<tr><th class=\"header\">%s</th><th class=\"header\">%s</th><th class=\"header\">%s</th><th class=\"header\">%s</th><th class=\"header\">%s</th></tr>\n",text[98],text[111],text[110],text[91],text[129]);
25697a35
GS
105
106 while(fgets(buf,sizeof(buf),fp_in)!=NULL) {
9c7c6346
FM
107 getword_start(&gwarea,buf);
108 if (getword(user,sizeof(user),&gwarea,'\t')<0 || getword(date2,sizeof(date2),&gwarea,'\t')<0 ||
109 getword(hour,sizeof(hour),&gwarea,'\t')<0 || getword(ip,sizeof(ip),&gwarea,'\t')<0 ||
110 getword(url,sizeof(url),&gwarea,'\t')<0 || getword(rule,sizeof(rule),&gwarea,'\n')<0) {
4bcb77cf
FM
111 printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",dansguardian_in);
112 exit(1);
113 }
25697a35 114
246c8489 115 if(UserIp)
25697a35
GS
116 strcpy(user,ip);
117
118 bzero(date, 15);
119 if(strncmp(df,"u",1) != 0) {
120 strncpy(date,date2+6,2);
121 strcat(date,"/");
122 strncat(date,date2+4,2);
123 strcat(date,"/");
124 strncat(date,date2,4);
125 } else {
126 strncpy(date,date2+4,2);
127 strcat(date,"/");
128 strncat(date,date2+6,2);
129 strcat(date,"/");
130 strncat(date,date2,4);
131 }
132
133 if((str=(char *) strstr(user, "_")) != (char *) NULL ) {
134 if((str=(char *) strstr(str+1, "_")) != (char *) NULL )
135 fixip(user);
136 }
137
246c8489 138 if(Ip2Name)
a1c55d8c 139 ip2name(ip,sizeof(ip));
25697a35
GS
140
141 if(!z) {
142 strcpy(ouser,user);
143 strcpy(oip,ip);
144 z++;
145 } else {
146 if(strcmp(ouser,user) == 0)
147 user[0]='\0';
148 if(user[0] != '\0')
149 strcpy(ouser,user);
120d768c 150 if(strcmp(oip,ip) == 0)
25697a35
GS
151 ip[0]='\0';
152 if(ip[0] != '\0')
153 strcpy(oip,ip);
154 }
155
936c9905 156 get_usertab_name(user,name,sizeof(name));
25697a35 157
48864d28
FM
158 if(dotinuser && strchr(name,'_')) {
159 subs(name,sizeof(name),"_",".");
94ff9470
GS
160 }
161
25697a35
GS
162 if(DansGuardianReportLimit) {
163 if(strcmp(ouser2,name) == 0) {
164 count++;
165 } else {
166 count=1;
167 strcpy(ouser2,name);
168 }
169 if(count >= DansGuardianReportLimit)
170 continue;
171 }
172
354c1a68 173 fprintf(fp_ou,"<tr><td class=\"data2\" nospaw>%s</td><td class=\"data2\" nospaw>%s</td><td class=\"data2\" nospaw>%s-%s</td><td class=\"data2\" nospaw><a href=\"http://%s\">%s</a></td><td class=\"data2\" nospaw>%s</td></tr>\n",name,ip,date,hour,url,url,rule);
25697a35
GS
174 }
175
176 fputs("</table>\n",fp_ou);
177
178 show_info(fp_ou);
120d768c 179
25697a35
GS
180 fputs("</body>\n</html>\n",fp_ou);
181
182 fclose(fp_in);
183 fclose(fp_ou);
184
185 unlink(dansguardian_in);
186
187 return;
188}