]> git.ipfire.org Git - thirdparty/sarg.git/blame - denied.c
Changed Pedro's address in headers.
[thirdparty/sarg.git] / denied.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 gen_denied_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 denied_in[MAXLEN];
37 char denied_ou[MAXLEN];
38 char per[MAXLEN];
39 char report[MAXLEN];
40 char periodo[100];
41 char ip[MAXLEN];
42 char oip[MAXLEN];
43 char user[MAXLEN];
44 char ouser[MAXLEN];
45 char ouser2[MAXLEN];
46 char data[15];
47 char hora[15];
48 char ftime[128];
49 char *str;
50 int z=0;
51 int count=0;
52
53 ouser[0]='\0';
54
491b862f 55 sprintf(denied_in,"%s/sarg/denied.log",TempDir);
25697a35
GS
56 if(!denied_count) {
57 unlink(denied_in);
58 return;
59 }
60
61 sprintf(per,"%s/periodo",dirname);
62 sprintf(report,"%s/denied.html",dirname);
63
64 if ((fp_in = fopen(per, "r")) == 0) {
65 fprintf(stderr, "SARG: (denied) %s: %s\n",text[45],per);
66 exit(1);
67 }
68
69 fgets(periodo,sizeof(periodo),fp_in);
70 fclose(fp_in);
71
72 if((fp_in=fopen(denied_in,"r"))==NULL) {
73 fprintf(stderr, "SARG: (denied) %s: %s\n",text[8],denied_in);
74 exit(1);
75 }
76
77 if((fp_ou=fopen(report,"w"))==NULL) {
78 fprintf(stderr, "SARG: (denied) %s: %s\n",text[8],report);
79 exit(1);
80 }
81
82 fputs("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\"",fp_ou);
83 fputs(" \"http://www.w3.org/TR/html4/loose.dtd\">\n",fp_ou);
84 fputs("<html>\n",fp_ou);
85 fputs("<head>\n",fp_ou);
86 sprintf(html," <meta http-equiv=\"Content-Type\" content=\"text/html; charset=%s\">\n",CharSet);
87 fputs(html,fp_ou);
88 css(fp_ou);
89 fputs("</head>\n",fp_ou);
90
91 sprintf(url,"<body bgcolor=%s text=%s background='%s'>\n",BgColor,TxColor,BgImage);
92 fputs(url,fp_ou);
93
94 fputs("<center><table cellpadding=0 cellspacing=0>\n",fp_ou);
95
96 if(strlen(LogoImage) > 0) {
94ff9470
GS
97 fputs("<center><table cellpadding=\"0\" cellspacing=\"0\">\n",fp_ou);
98 sprintf(url,"<tr><th class=\"logo\"><img src='%s' border=0 align=absmiddle width=%s height=%s>&nbsp;%s</th></tr>\n",LogoImage,Width,Height,LogoText);
25697a35 99 fputs(url,fp_ou);
94ff9470
GS
100 fputs("<tr><td height=\"5\"></td></tr>\n",fp_ou);
101 fputs("</table>\n",fp_ou);
25697a35
GS
102 }
103
491b862f
GS
104 if(strcmp(IndexTree,"date") == 0)
105 show_sarg(fp_ou, "../../..");
106 else
107 show_sarg(fp_ou, "..");
25697a35
GS
108 sprintf(url,"<tr><th class=\"title\">%s</b></th></tr>\n",Title);
109 fputs(url,fp_ou);
110
111 sprintf(url,"<tr><td class=\"header\">%s: %s</td></tr>\n",text[89],periodo);
112 fputs(url,fp_ou);
113 sprintf(url,"<tr><th class=\"header3\">%s %s</th></tr>\n",text[46],text[55]);
114 fputs(url,fp_ou);
115 fputs("</table></center>\n",fp_ou);
116
117 fputs("<center><table cellpadding=0 cellspacing=2>\n",fp_ou);
118 fputs("<tr><td></td></tr>\n",fp_ou);
119 fputs("<tr><td></td></tr>\n",fp_ou);
120 fputs("<tr><td></td></tr>\n",fp_ou);
121 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]);
122 fputs(url,fp_ou);
123
124 while(fgets(buf,sizeof(buf),fp_in)!=NULL) {
125 getword(data,buf,' ');
126 getword(hora,buf,' ');
127 getword(user,buf,' ');
128 getword(ip,buf,' ');
129 getword(url,buf,' ');
130
131 if((str=(char *) strstr(user, "_")) != (char *) NULL ) {
132 if((str=(char *) strstr(str+1, "_")) != (char *) NULL )
133 fixip(user);
134 }
135
136 if(strcmp(Ip2Name,"yes") == 0)
137 ip2name(ip);
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);
148 if(strcmp(oip,ip) == 0)
149 ip[0]='\0';
150 if(ip[0] != '\0')
151 strcpy(oip,ip);
152 }
153
154 if(UserTabFile[0] != '\0') {
155 sprintf(warea,":%s:",user);
156 if((str=(char *) strstr(userfile,warea)) != (char *) NULL ) {
157 z1=0;
158 str2=(char *) strstr(str+1,":");
159 str2++;
160 bzero(name, MAXLEN);
161 while(str2[z1] != ':') {
162 name[z1]=str2[z1];
163 z1++;
164 }
165 } else strcpy(name,user);
166 } else strcpy(name,user);
167
94ff9470
GS
168 if(dotinuser && strstr(name,"_")) {
169 str2=(char *)subs(name,"_",".");
170 strcpy(name,str2);
171 }
172
25697a35
GS
173 if(DeniedReportLimit) {
174 if(strcmp(ouser2,name) == 0) {
175 count++;
176 } else {
177 count=1;
178 strcpy(ouser2,name);
179 }
180 if(count >= DeniedReportLimit)
181 continue;
182 }
183
184 if(strlen(BlockIt) > 0)
491b862f 185 sprintf(BlockImage,"<a href=\"%s%s?url=%s\"><img src=\"%s/sarg-squidguard-block.png\" border=\"0\"></a>&nbsp;",wwwDocumentRoot,BlockIt,url,ImageFile);
25697a35
GS
186 else BlockImage[0]='\0';
187
188 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);
189 fputs(html2,fp_ou);
190 }
191
192 fputs("</table>\n",fp_ou);
193
194 show_info(fp_ou);
195 fputs("</body></html>\n",fp_ou);
196
197 fclose(fp_in);
198 fclose(fp_ou);
199
200 unlink(denied_in);
201
202 return;
203}