]> git.ipfire.org Git - thirdparty/sarg.git/blame - squidguard_report.c
Ported r161 from branches/v2_2_6_1 (fix regression in sarg-date)
[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"
5f3cfd1d 27#include "include/defs.h"
25697a35 28
32e71fa4 29void squidguard_report(void)
25697a35
GS
30{
31
32 FILE *fp_in = NULL, *fp_ou = NULL;
120d768c 33
25697a35 34 char url[MAXLEN];
25697a35 35 char squidguard_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 data[15];
45 char data2[15];
46 char hora[15];
25697a35
GS
47 char *str;
48 int z=0;
49 int count=0;
50
51 ouser[0]='\0';
52
53 sprintf(squidguard_in,"%s/squidguard.log",tmp);
54 if(!squidguard_count) {
55 unlink(squidguard_in);
56 return;
57 }
58
d6e703cc 59 sprintf(per,"%s/sarg-period",dirname);
25697a35
GS
60 sprintf(report,"%s/squidguard.html",dirname);
61
62 if ((fp_in = fopen(per, "r")) == 0) {
63 fprintf(stderr, "SARG: (squidguard) %s: %s\n",text[45],per);
64 exit(1);
65 }
66
05b90947
FM
67 if (!fgets(period,sizeof(period),fp_in)) {
68 fprintf(stderr,"SARG: (squidguard) read error in %s\n",per);
69 exit(1);
70 }
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);
dfb337be 88 write_logo_image(fp_ou);
25697a35 89
491b862f
GS
90 if(strcmp(IndexTree,"date") == 0)
91 show_sarg(fp_ou, "../../..");
92 else
93 show_sarg(fp_ou,"..");
dfb337be 94 fputs("<div align=\"center\"><table cellpadding=\"0\" cellspacing=\"0\">\n",fp_ou);
354c1a68 95 fprintf(fp_ou,"<tr><th class=\"title\">%s</th></tr>\n",Title);
25697a35 96
354c1a68
FM
97 fprintf(fp_ou,"<tr><td class=\"header\">%s: %s</td></tr>\n",text[89],period);
98 fprintf(fp_ou,"<tr><th class=\"header3\">%s</th></tr>\n",text[120]);
dfb337be 99 fputs("</table></div>\n",fp_ou);
25697a35 100
dfb337be 101 fputs("<div align=\"center\"><table cellpadding=1 cellspacing=2>\n",fp_ou);
25697a35 102 fputs("<tr><td></td></tr>\n",fp_ou);
354c1a68 103 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[121]);
25697a35
GS
104
105 while(fgets(buf,sizeof(buf),fp_in)!=NULL) {
120d768c
FM
106 if (getword(user,sizeof(user),buf,'\t')<0 || getword(data2,sizeof(data2),buf,'\t')<0 ||
107 getword(hora,sizeof(hora),buf,'\t')<0 || getword(ip,sizeof(ip),buf,'\t')<0 ||
108 getword(url,sizeof(url),buf,'\t')<0 || getword(rule,sizeof(rule),buf,'\n')<0) {
4bcb77cf
FM
109 printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",squidguard_in);
110 exit(1);
111 }
25697a35
GS
112
113 if(strcmp(UserIp,"yes") == 0)
114 strcpy(user,ip);
115
116 bzero(data, 15);
117 if(strncmp(df,"u",1) != 0) {
118 strncpy(data,data2+6,2);
119 strcat(data,"/");
120 strncat(data,data2+4,2);
121 strcat(data,"/");
122 strncat(data,data2,4);
123 } else {
124 strncpy(data,data2+4,2);
125 strcat(data,"/");
126 strncat(data,data2+6,2);
127 strcat(data,"/");
128 strncat(data,data2,4);
129 }
130
131 if((str=(char *) strstr(user, "_")) != (char *) NULL ) {
132 if((str=(char *) strstr(str+1, "_")) != (char *) NULL )
133 fixip(user);
134 }
135
120d768c 136 if(strcmp(Ip2Name,"yes") == 0)
a1c55d8c 137 ip2name(ip,sizeof(ip));
25697a35
GS
138
139 if(!z) {
140 strcpy(ouser,user);
141 strcpy(oip,ip);
142 z++;
143 } else {
144 if(strcmp(ouser,user) == 0)
145 user[0]='\0';
146 if(user[0] != '\0')
147 strcpy(ouser,user);
120d768c 148 if(strcmp(oip,ip) == 0)
25697a35
GS
149 ip[0]='\0';
150 if(ip[0] != '\0')
151 strcpy(oip,ip);
152 }
153
936c9905 154 get_usertab_name(user,name,sizeof(name));
25697a35 155
48864d28
FM
156 if(dotinuser && strchr(name,'_')) {
157 subs(name,sizeof(name),"_",".");
94ff9470
GS
158 }
159
25697a35
GS
160 if(SquidGuardReportLimit) {
161 if(strcmp(ouser2,name) == 0) {
162 count++;
163 } else {
164 count=1;
165 strcpy(ouser2,name);
166 }
167 if(count >= SquidGuardReportLimit)
168 continue;
169 }
170
354c1a68 171 fprintf(fp_ou,"<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);
25697a35
GS
172 }
173
174 fputs("</table>\n",fp_ou);
175
176 show_info(fp_ou);
dfb337be 177
25697a35
GS
178 fputs("</body>\n</html>\n",fp_ou);
179
180 fclose(fp_in);
181 fclose(fp_ou);
182
183 unlink(squidguard_in);
184
185 return;
186}