]> git.ipfire.org Git - thirdparty/sarg.git/blame - squidguard_report.c
Write HTML trailer before closing the file.
[thirdparty/sarg.git] / squidguard_report.c
CommitLineData
25697a35 1/*
c37945ed
FM
2 * AUTHOR: Pedro Lineu Orso pedro.orso@gmail.com
3 * 1998, 2008
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"
27
28void squidguard_report()
29{
30
31 FILE *fp_in = NULL, *fp_ou = NULL;
32
33 char url[MAXLEN];
34 char html[MAXLEN];
35 char html2[MAXLEN];
36 char squidguard_in[MAXLEN];
37 char squidguard_ou[MAXLEN];
38 char per[MAXLEN];
39 char report[MAXLEN];
d6e703cc 40 char period[100];
25697a35
GS
41 char ip[MAXLEN];
42 char rule[255];
43 char oip[MAXLEN];
44 char user[MAXLEN];
45 char ouser[MAXLEN];
46 char data[15];
47 char data2[15];
48 char hora[15];
49 char ftime[128];
50 char *str;
51 int z=0;
52 int count=0;
53
54 ouser[0]='\0';
55
56 sprintf(squidguard_in,"%s/squidguard.log",tmp);
57 if(!squidguard_count) {
58 unlink(squidguard_in);
59 return;
60 }
61
d6e703cc 62 sprintf(per,"%s/sarg-period",dirname);
25697a35
GS
63 sprintf(report,"%s/squidguard.html",dirname);
64
65 if ((fp_in = fopen(per, "r")) == 0) {
66 fprintf(stderr, "SARG: (squidguard) %s: %s\n",text[45],per);
67 exit(1);
68 }
69
d6e703cc 70 fgets(period,sizeof(period),fp_in);
25697a35
GS
71 fclose(fp_in);
72
73 if((fp_in=fopen(squidguard_in,"r"))==NULL) {
74 fprintf(stderr, "SARG: (squidguard) %s: %s\n",text[8],squidguard_in);
75 exit(1);
76 }
77
78 if((fp_ou=fopen(report,"w"))==NULL) {
79 fprintf(stderr, "SARG: (squidguard) %s: %s\n",text[8],report);
80 exit(1);
81 }
82
d6e703cc 83 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
84 css(fp_ou);
85 fputs("</head>\n",fp_ou);
d6e703cc
FM
86 if(strlen(FontFace) > 0) fprintf(fp_ou,"<font face=%s>\n",FontFace);
87 fprintf(fp_ou,"<body bgcolor=%s text=%s background='%s'>\n",BgColor,TxColor,BgImage);
88 if(strlen(LogoImage) > 0) fprintf(fp_ou, "<center><table cellpadding=\"0\" cellspacing=\"0\">\n<tr><th class=\"logo\"><img src='%s' border=0 align=absmiddle width=%s height=%s>&nbsp;%s</th></tr>\n<tr><td height=\"5\"></td></tr>\n</table>\n",LogoImage,Width,Height,LogoText);
25697a35 89
491b862f
GS
90 if(strcmp(IndexTree,"date") == 0)
91 show_sarg(fp_ou, "../../..");
92 else
93 show_sarg(fp_ou,"..");
25697a35
GS
94 fputs("<center><table cellpadding=0 cellspacing=0>\n",fp_ou);
95 sprintf(url,"<tr><th class=\"title\">%s</th></tr>\n",Title);
96 fputs(url,fp_ou);
97
d6e703cc 98 sprintf(url,"<tr><td class=\"header\">%s: %s</td></tr>\n",text[89],period);
25697a35 99 fputs(url,fp_ou);
d6e703cc 100 sprintf(url,"<tr><th class=\"header3\">%s</th></tr>\n",text[120]);
25697a35
GS
101 fputs(url,fp_ou);
102 fputs("</table></center>\n",fp_ou);
103
104 fputs("<center><table cellpadding=1 cellspacing=2>\n",fp_ou);
105 fputs("<tr><td></td></tr>\n",fp_ou);
106 sprintf(url,"<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[121]);
107 fputs(url,fp_ou);
108
109 while(fgets(buf,sizeof(buf),fp_in)!=NULL) {
110 getword(user,buf,' ');
111 getword(data2,buf,' ');
112 getword(hora,buf,' ');
113 getword(ip,buf,' ');
114 getword(url,buf,' ');
115 getword(rule,buf,'\n');
116
117 if(strcmp(UserIp,"yes") == 0)
118 strcpy(user,ip);
119
120 bzero(data, 15);
121 if(strncmp(df,"u",1) != 0) {
122 strncpy(data,data2+6,2);
123 strcat(data,"/");
124 strncat(data,data2+4,2);
125 strcat(data,"/");
126 strncat(data,data2,4);
127 } else {
128 strncpy(data,data2+4,2);
129 strcat(data,"/");
130 strncat(data,data2+6,2);
131 strcat(data,"/");
132 strncat(data,data2,4);
133 }
134
135 if((str=(char *) strstr(user, "_")) != (char *) NULL ) {
136 if((str=(char *) strstr(str+1, "_")) != (char *) NULL )
137 fixip(user);
138 }
139
140 if(strcmp(Ip2Name,"yes") == 0)
141 ip2name(ip);
142
143 if(!z) {
144 strcpy(ouser,user);
145 strcpy(oip,ip);
146 z++;
147 } else {
148 if(strcmp(ouser,user) == 0)
149 user[0]='\0';
150 if(user[0] != '\0')
151 strcpy(ouser,user);
152 if(strcmp(oip,ip) == 0)
153 ip[0]='\0';
154 if(ip[0] != '\0')
155 strcpy(oip,ip);
156 }
157
158 if(UserTabFile[0] != '\0') {
159 sprintf(warea,":%s:",user);
160 if((str=(char *) strstr(userfile,warea)) != (char *) NULL ) {
161 z1=0;
162 str2=(char *) strstr(str+1,":");
163 str2++;
164 bzero(name, MAXLEN);
165 while(str2[z1] != ':') {
166 name[z1]=str2[z1];
167 z1++;
168 }
169 } else strcpy(name,user);
170 } else strcpy(name,user);
171
94ff9470
GS
172 if(dotinuser && strstr(name,"_")) {
173 str2=(char *)subs(name,"_",".");
174 strcpy(name,str2);
175 }
176
25697a35
GS
177 if(SquidGuardReportLimit) {
178 if(strcmp(ouser2,name) == 0) {
179 count++;
180 } else {
181 count=1;
182 strcpy(ouser2,name);
183 }
184 if(count >= SquidGuardReportLimit)
185 continue;
186 }
187
188 sprintf(html2,"<tr><td class=\"data2\">%s</td><td class=\"data2\">%s</td><td class=\"data2\">%s-%s</td><td class=\"data2\"><a href=\"http://%s\">%s</a></td><td class=\"data2\">%s</td></th>\n",name,ip,data,hora,url,url,rule);
189 fputs(html2,fp_ou);
190 }
191
192 fputs("</table>\n",fp_ou);
193
194 show_info(fp_ou);
195
196 fputs("</body>\n</html>\n",fp_ou);
197
198 fclose(fp_in);
199 fclose(fp_ou);
200
201 unlink(squidguard_in);
202
203 return;
204}