]> git.ipfire.org Git - thirdparty/sarg.git/blame - dansguardian_report.c
All the sprintf/fputs have been replaced by fprintf to avoid an intermediary buffer...
[thirdparty/sarg.git] / dansguardian_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
32e71fa4 28void dansguardian_report(void)
25697a35
GS
29{
30
31 FILE *fp_in = NULL, *fp_ou = NULL;
32
33 char url[MAXLEN];
25697a35 34 char dansguardian_in[MAXLEN];
25697a35
GS
35 char per[MAXLEN];
36 char report[MAXLEN];
d6e703cc 37 char period[100];
25697a35
GS
38 char ip[MAXLEN];
39 char rule[255];
40 char oip[MAXLEN];
41 char user[MAXLEN];
42 char ouser[MAXLEN];
43 char date[15];
44 char date2[15];
45 char hour[15];
25697a35
GS
46 char *str;
47 int z=0;
48 int count=0;
49
50 ouser[0]='\0';
51
52 sprintf(dansguardian_in,"%s/dansguardian.log",tmp);
53 if(!dansguardian_count) {
54 unlink(dansguardian_in);
55 return;
56 }
57
d6e703cc 58 sprintf(per,"%s/sarg-period",dirname);
25697a35
GS
59 sprintf(report,"%s/dansguardian.html",dirname);
60
61 if ((fp_in = fopen(per, "r")) == 0) {
62 fprintf(stderr, "SARG: (dansguardian_report) %s: %s\n",text[45],per);
63 exit(1);
64 }
65
d6e703cc 66 fgets(period,sizeof(period),fp_in);
25697a35
GS
67 fclose(fp_in);
68
0dda06bf 69#if defined(HAVE_FOPEN64)
32e71fa4 70 if((fp_in=fopen64(dansguardian_in,"r"))==NULL) {
0dda06bf 71#else
25697a35 72 if((fp_in=fopen(dansguardian_in,"r"))==NULL) {
0dda06bf 73#endif
25697a35
GS
74 fprintf(stderr, "SARG: (dansguardian_report) %s: %s\n",text[8],dansguardian_in);
75 exit(1);
76 }
77
0dda06bf 78#if defined(HAVE_FOPEN64)
32e71fa4 79 if((fp_ou=fopen64(report,"w"))==NULL) {
0dda06bf 80#else
25697a35 81 if((fp_ou=fopen(report,"w"))==NULL) {
0dda06bf 82#endif
25697a35
GS
83 fprintf(stderr, "SARG: (dansguardian_report) %s: %s\n",text[8],report);
84 exit(1);
85 }
86
d6e703cc 87 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
88 css(fp_ou);
89 fputs("</head>\n",fp_ou);
d6e703cc
FM
90 if(strlen(FontFace) > 0) fprintf(fp_ou,"<font face=%s>\n",FontFace);
91 fprintf(fp_ou,"<body bgcolor=%s text=%s background='%s'>\n",BgColor,TxColor,BgImage);
92 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);
93
491b862f
GS
94 if(strcmp(IndexTree,"date") == 0)
95 show_sarg(fp_ou, "../../..");
96 else
97 show_sarg(fp_ou,"..");
25697a35 98 fputs("<center><table cellpadding=0 cellspacing=0>\n",fp_ou);
354c1a68 99 fprintf(fp_ou,"<tr><th class=\"title\">%s</th></tr>\n",Title);
25697a35 100
354c1a68
FM
101 fprintf(fp_ou,"<tr><td class=\"header\">%s: %s</td></tr>\n",text[89],period);
102 fprintf(fp_ou,"<tr><th class=\"header3\">%s</th></tr>\n",text[128]);
25697a35
GS
103 fputs("</table></center>\n",fp_ou);
104
105 fputs("<center><table cellpadding=1 cellspacing=2>\n",fp_ou);
106 fputs("<tr><td></td></tr>\n",fp_ou);
354c1a68 107 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
108
109 while(fgets(buf,sizeof(buf),fp_in)!=NULL) {
4bcb77cf
FM
110 if (getword(user,sizeof(user),buf,' ')<0 || getword(date2,sizeof(date2),buf,' ')<0 ||
111 getword(hour,sizeof(hour),buf,' ')<0 || getword(ip,sizeof(ip),buf,' ')<0 ||
112 getword(url,sizeof(url),buf,' ')<0 || getword(rule,sizeof(rule),buf,'\n')<0) {
113 printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",dansguardian_in);
114 exit(1);
115 }
25697a35
GS
116
117 if(strcmp(UserIp,"yes") == 0)
118 strcpy(user,ip);
119
120 bzero(date, 15);
121 if(strncmp(df,"u",1) != 0) {
122 strncpy(date,date2+6,2);
123 strcat(date,"/");
124 strncat(date,date2+4,2);
125 strcat(date,"/");
126 strncat(date,date2,4);
127 } else {
128 strncpy(date,date2+4,2);
129 strcat(date,"/");
130 strncat(date,date2+6,2);
131 strcat(date,"/");
132 strncat(date,date2,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)
a1c55d8c 141 ip2name(ip,sizeof(ip));
25697a35
GS
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(DansGuardianReportLimit) {
178 if(strcmp(ouser2,name) == 0) {
179 count++;
180 } else {
181 count=1;
182 strcpy(ouser2,name);
183 }
184 if(count >= DansGuardianReportLimit)
185 continue;
186 }
187
354c1a68 188 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
189 }
190
191 fputs("</table>\n",fp_ou);
192
193 show_info(fp_ou);
194
195 fputs("</body>\n</html>\n",fp_ou);
196
197 fclose(fp_in);
198 fclose(fp_ou);
199
200 unlink(dansguardian_in);
201
202 return;
203}