]> git.ipfire.org Git - thirdparty/sarg.git/blob - dansguardian_report.c
Remove all the warnings (inspired from patch #1771501).
[thirdparty/sarg.git] / dansguardian_report.c
1 /*
2 * AUTHOR: Pedro Lineu Orso pedro.orso@gmail.com
3 * 1998, 2008
4 * SARG Squid Analysis Report Generator http://sarg.sourceforge.net
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
28 void dansguardian_report(void)
29 {
30
31 FILE *fp_in = NULL, *fp_ou = NULL;
32
33 char url[MAXLEN];
34 char html2[MAXLEN];
35 char dansguardian_in[MAXLEN];
36 char per[MAXLEN];
37 char report[MAXLEN];
38 char period[100];
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];
47 char *str;
48 int z=0;
49 int count=0;
50
51 ouser[0]='\0';
52
53 sprintf(dansguardian_in,"%s/dansguardian.log",tmp);
54 if(!dansguardian_count) {
55 unlink(dansguardian_in);
56 return;
57 }
58
59 sprintf(per,"%s/sarg-period",dirname);
60 sprintf(report,"%s/dansguardian.html",dirname);
61
62 if ((fp_in = fopen(per, "r")) == 0) {
63 fprintf(stderr, "SARG: (dansguardian_report) %s: %s\n",text[45],per);
64 exit(1);
65 }
66
67 fgets(period,sizeof(period),fp_in);
68 fclose(fp_in);
69
70 #if defined(HAVE_FOPEN64)
71 if((fp_in=fopen64(dansguardian_in,"r"))==NULL) {
72 #else
73 if((fp_in=fopen(dansguardian_in,"r"))==NULL) {
74 #endif
75 fprintf(stderr, "SARG: (dansguardian_report) %s: %s\n",text[8],dansguardian_in);
76 exit(1);
77 }
78
79 #if defined(HAVE_FOPEN64)
80 if((fp_ou=fopen64(report,"w"))==NULL) {
81 #else
82 if((fp_ou=fopen(report,"w"))==NULL) {
83 #endif
84 fprintf(stderr, "SARG: (dansguardian_report) %s: %s\n",text[8],report);
85 exit(1);
86 }
87
88 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);
89 css(fp_ou);
90 fputs("</head>\n",fp_ou);
91 if(strlen(FontFace) > 0) fprintf(fp_ou,"<font face=%s>\n",FontFace);
92 fprintf(fp_ou,"<body bgcolor=%s text=%s background='%s'>\n",BgColor,TxColor,BgImage);
93 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);
94
95 if(strcmp(IndexTree,"date") == 0)
96 show_sarg(fp_ou, "../../..");
97 else
98 show_sarg(fp_ou,"..");
99 fputs("<center><table cellpadding=0 cellspacing=0>\n",fp_ou);
100 sprintf(url,"<tr><th class=\"title\">%s</th></tr>\n",Title);
101 fputs(url,fp_ou);
102
103 sprintf(url,"<tr><td class=\"header\">%s: %s</td></tr>\n",text[89],period);
104 fputs(url,fp_ou);
105 sprintf(url,"<tr><th class=\"header3\">%s</th></tr>\n",text[128]);
106 fputs(url,fp_ou);
107 fputs("</table></center>\n",fp_ou);
108
109 fputs("<center><table cellpadding=1 cellspacing=2>\n",fp_ou);
110 fputs("<tr><td></td></tr>\n",fp_ou);
111 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[129]);
112 fputs(url,fp_ou);
113
114 while(fgets(buf,sizeof(buf),fp_in)!=NULL) {
115 if (getword(user,sizeof(user),buf,' ')<0 || getword(date2,sizeof(date2),buf,' ')<0 ||
116 getword(hour,sizeof(hour),buf,' ')<0 || getword(ip,sizeof(ip),buf,' ')<0 ||
117 getword(url,sizeof(url),buf,' ')<0 || getword(rule,sizeof(rule),buf,'\n')<0) {
118 printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",dansguardian_in);
119 exit(1);
120 }
121
122 if(strcmp(UserIp,"yes") == 0)
123 strcpy(user,ip);
124
125 bzero(date, 15);
126 if(strncmp(df,"u",1) != 0) {
127 strncpy(date,date2+6,2);
128 strcat(date,"/");
129 strncat(date,date2+4,2);
130 strcat(date,"/");
131 strncat(date,date2,4);
132 } else {
133 strncpy(date,date2+4,2);
134 strcat(date,"/");
135 strncat(date,date2+6,2);
136 strcat(date,"/");
137 strncat(date,date2,4);
138 }
139
140 if((str=(char *) strstr(user, "_")) != (char *) NULL ) {
141 if((str=(char *) strstr(str+1, "_")) != (char *) NULL )
142 fixip(user);
143 }
144
145 if(strcmp(Ip2Name,"yes") == 0)
146 ip2name(ip,sizeof(ip));
147
148 if(!z) {
149 strcpy(ouser,user);
150 strcpy(oip,ip);
151 z++;
152 } else {
153 if(strcmp(ouser,user) == 0)
154 user[0]='\0';
155 if(user[0] != '\0')
156 strcpy(ouser,user);
157 if(strcmp(oip,ip) == 0)
158 ip[0]='\0';
159 if(ip[0] != '\0')
160 strcpy(oip,ip);
161 }
162
163 if(UserTabFile[0] != '\0') {
164 sprintf(warea,":%s:",user);
165 if((str=(char *) strstr(userfile,warea)) != (char *) NULL ) {
166 z1=0;
167 str2=(char *) strstr(str+1,":");
168 str2++;
169 bzero(name, MAXLEN);
170 while(str2[z1] != ':') {
171 name[z1]=str2[z1];
172 z1++;
173 }
174 } else strcpy(name,user);
175 } else strcpy(name,user);
176
177 if(dotinuser && strstr(name,"_")) {
178 str2=(char *)subs(name,"_",".");
179 strcpy(name,str2);
180 }
181
182 if(DansGuardianReportLimit) {
183 if(strcmp(ouser2,name) == 0) {
184 count++;
185 } else {
186 count=1;
187 strcpy(ouser2,name);
188 }
189 if(count >= DansGuardianReportLimit)
190 continue;
191 }
192
193 sprintf(html2,"<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);
194 fputs(html2,fp_ou);
195 }
196
197 fputs("</table>\n",fp_ou);
198
199 show_info(fp_ou);
200
201 fputs("</body>\n</html>\n",fp_ou);
202
203 fclose(fp_in);
204 fclose(fp_ou);
205
206 unlink(dansguardian_in);
207
208 return;
209 }