]> git.ipfire.org Git - thirdparty/sarg.git/blob - denied.c
Remove all the warnings (inspired from patch #1771501).
[thirdparty/sarg.git] / denied.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 gen_denied_report(void)
29 {
30
31 FILE *fp_in = NULL, *fp_ou = NULL;
32
33 char url[MAXLEN];
34 char html2[MAXLEN];
35 char denied_in[MAXLEN];
36 char per[MAXLEN];
37 char report[MAXLEN];
38 char period[100];
39 char ip[MAXLEN];
40 char oip[MAXLEN];
41 char user[MAXLEN];
42 char ouser[MAXLEN];
43 char ouser2[MAXLEN];
44 char data[15];
45 char hora[15];
46 char *str;
47 int z=0;
48 int count=0;
49
50 ouser[0]='\0';
51
52 sprintf(denied_in,"%s/sarg/denied.log",TempDir);
53 if(!denied_count) {
54 unlink(denied_in);
55 return;
56 }
57
58 sprintf(per,"%s/sarg-period",dirname);
59 sprintf(report,"%s/denied.html",dirname);
60
61 if ((fp_in = fopen(per, "r")) == 0) {
62 fprintf(stderr, "SARG: (denied) %s: %s\n",text[45],per);
63 exit(1);
64 }
65
66 fgets(period,sizeof(period),fp_in);
67 fclose(fp_in);
68
69 #if defined(HAVE_FOPEN64)
70 if((fp_in=fopen64(denied_in,"r"))==NULL) {
71 #else
72 if((fp_in=fopen(denied_in,"r"))==NULL) {
73 #endif
74 fprintf(stderr, "SARG: (denied) %s: %s\n",text[8],denied_in);
75 exit(1);
76 }
77
78 #if defined(HAVE_FOPEN64)
79 if((fp_ou=fopen64(report,"w"))==NULL) {
80 #else
81 if((fp_ou=fopen(report,"w"))==NULL) {
82 #endif
83 fprintf(stderr, "SARG: (denied) %s: %s\n",text[8],report);
84 exit(1);
85 }
86
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);
88 css(fp_ou);
89 fputs("</head>\n",fp_ou);
90 fprintf(fp_ou,"<body bgcolor=%s text=%s background='%s'>\n",BgColor,TxColor,BgImage);
91 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);
92
93 if(strcmp(IndexTree,"date") == 0)
94 show_sarg(fp_ou, "../../..");
95 else
96 show_sarg(fp_ou, "..");
97
98 fputs("<center><table cellpadding=0 cellspacing=0>\n",fp_ou);
99 sprintf(url,"<tr><th class=\"title\">%s</b></th></tr>\n",Title);
100 fputs(url,fp_ou);
101
102 sprintf(url,"<tr><td class=\"header\">%s: %s</td></tr>\n",text[89],period);
103 fputs(url,fp_ou);
104 sprintf(url,"<tr><th class=\"header3\">%s</th></tr>\n",text[46]);
105 fputs(url,fp_ou);
106 fputs("</table></center>\n",fp_ou);
107
108 fputs("<center><table cellpadding=0 cellspacing=2>\n",fp_ou);
109 fputs("<tr><td></td></tr>\n",fp_ou);
110 sprintf(url,"<tr><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]);
111 fputs(url,fp_ou);
112
113 while(fgets(buf,sizeof(buf),fp_in)!=NULL) {
114 if (getword(data,sizeof(data),buf,' ')<0 || getword(hora,sizeof(hora),buf,' ')<0 ||
115 getword(user,sizeof(user),buf,' ')<0 || getword(ip,sizeof(ip),buf,' ')<0 ||
116 getword(url,sizeof(url),buf,' ')<0) {
117 printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",denied_in);
118 exit(1);
119 }
120
121 if((str=(char *) strstr(user, "_")) != (char *) NULL ) {
122 if((str=(char *) strstr(str+1, "_")) != (char *) NULL )
123 fixip(user);
124 }
125
126 if(strcmp(Ip2Name,"yes") == 0)
127 ip2name(ip,sizeof(ip));
128
129 if(!z) {
130 strcpy(ouser,user);
131 strcpy(oip,ip);
132 z++;
133 } else {
134 if(strcmp(ouser,user) == 0)
135 user[0]='\0';
136 if(user[0] != '\0')
137 strcpy(ouser,user);
138 if(strcmp(oip,ip) == 0)
139 ip[0]='\0';
140 if(ip[0] != '\0')
141 strcpy(oip,ip);
142 }
143
144 if(UserTabFile[0] != '\0') {
145 sprintf(warea,":%s:",user);
146 if((str=(char *) strstr(userfile,warea)) != (char *) NULL ) {
147 z1=0;
148 str2=(char *) strstr(str+1,":");
149 str2++;
150 bzero(name, MAXLEN);
151 while(str2[z1] != ':') {
152 name[z1]=str2[z1];
153 z1++;
154 }
155 } else strcpy(name,user);
156 } else strcpy(name,user);
157
158 if(dotinuser && strstr(name,"_")) {
159 str2=(char *)subs(name,"_",".");
160 strcpy(name,str2);
161 }
162
163 if(DeniedReportLimit) {
164 if(strcmp(ouser2,name) == 0) {
165 count++;
166 } else {
167 count=1;
168 strcpy(ouser2,name);
169 }
170 if(count >= DeniedReportLimit)
171 continue;
172 }
173
174 if(strlen(BlockIt) > 0)
175 sprintf(BlockImage,"<a href=\"%s%s?url=%s\"><img src=\"%s/sarg-squidguard-block.png\" border=\"0\"></a>&nbsp;",wwwDocumentRoot,BlockIt,url,ImageFile);
176 else BlockImage[0]='\0';
177
178 sprintf(html2,"<tr><td class=\"data\">%s</td><td class=\"data\">%s</td><td class=\"data\">%s-%s</td><td class=\"data2\">%s<a href=\"%s\">%s</a></td></th>\n",name,ip,data,hora,BlockImage,url,url);
179 fputs(html2,fp_ou);
180 }
181
182 fputs("</table>\n",fp_ou);
183
184 show_info(fp_ou);
185 fputs("</body></html>\n",fp_ou);
186
187 fclose(fp_in);
188 fclose(fp_ou);
189
190 unlink(denied_in);
191
192 return;
193 }