]> git.ipfire.org Git - thirdparty/sarg.git/blob - denied.c
Clarification of labels for header style
[thirdparty/sarg.git] / denied.c
1 /*
2 * SARG Squid Analysis Report Generator http://sarg.sourceforge.net
3 * 1998, 2010
4 *
5 * SARG donations:
6 * please look at http://sarg.sourceforge.net/donations.php
7 * Support:
8 * http://sourceforge.net/projects/sarg/forums/forum/363374
9 * ---------------------------------------------------------------------
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
24 *
25 */
26
27 #include "include/conf.h"
28 #include "include/defs.h"
29
30 void gen_denied_report(void)
31 {
32
33 FILE *fp_in = NULL, *fp_ou = NULL;
34
35 char url[MAXLEN];
36 char denied_in[MAXLEN];
37 char per[MAXLEN];
38 char report[MAXLEN];
39 char period[100];
40 char ip[MAXLEN];
41 char oip[MAXLEN];
42 char user[MAXLEN];
43 char ouser[MAXLEN];
44 char ouser2[MAXLEN];
45 char data[15];
46 char hora[15];
47 char *str;
48 int z=0;
49 int count=0;
50 struct getwordstruct gwarea;
51
52 ouser[0]='\0';
53 ouser2[0]='\0';
54
55 sprintf(denied_in,"%s/sarg/denied.log",TempDir);
56 if(!denied_count) {
57 unlink(denied_in);
58 return;
59 }
60
61 sprintf(per,"%s/sarg-period",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 if (!fgets(period,sizeof(period),fp_in)) {
70 fprintf(stderr,"SARG: (denied) read error in %s\n",per);
71 exit(1);
72 }
73 fclose(fp_in);
74
75 if((fp_in=MY_FOPEN(denied_in,"r"))==NULL) {
76 fprintf(stderr, "SARG: (denied) %s: %s\n",text[8],denied_in);
77 exit(1);
78 }
79
80 if((fp_ou=MY_FOPEN(report,"w"))==NULL) {
81 fprintf(stderr, "SARG: (denied) %s: %s\n",text[8],report);
82 exit(1);
83 }
84
85 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);
86 css(fp_ou);
87 fputs("</head>\n",fp_ou);
88 fprintf(fp_ou,"<body bgcolor=\"%s\" text=\"%s\" background=\"%s\">\n",BgColor,TxColor,BgImage);
89 write_logo_image(fp_ou);
90
91 if(IndexTree == INDEX_TREE_DATE)
92 show_sarg(fp_ou, "../../..");
93 else
94 show_sarg(fp_ou, "..");
95
96 fputs("<div align=\"center\"><table cellpadding=\"0\" cellspacing=\"0\">\n",fp_ou);
97 fprintf(fp_ou,"<tr><th class=\"title\">%s</b></th></tr>\n",Title);
98
99 fprintf(fp_ou,"<tr><td class=\"header_l\">%s: %s</td></tr>\n",text[89],period);
100 fprintf(fp_ou,"<tr><th class=\"header_c\">%s</th></tr>\n",text[46]);
101 fputs("</table></div>\n",fp_ou);
102
103 fputs("<div align=\"center\"><table cellpadding=\"0\" cellspacing=\"2\">\n",fp_ou);
104 fputs("<tr><td></td></tr>\n",fp_ou);
105 fprintf(fp_ou,"<tr><th class=\"header_l\">%s</th><th class=\"header_l\">%s</th><th class=\"header_l\">%s</th><th class=\"header_l\">%s</th></tr>\n",text[98],text[111],text[110],text[91]);
106
107 while(fgets(buf,sizeof(buf),fp_in)!=NULL) {
108 getword_start(&gwarea,buf);
109 if (getword(data,sizeof(data),&gwarea,'\t')<0 || getword(hora,sizeof(hora),&gwarea,'\t')<0 ||
110 getword(user,sizeof(user),&gwarea,'\t')<0 || getword(ip,sizeof(ip),&gwarea,'\t')<0 ||
111 getword(url,sizeof(url),&gwarea,'\t')<0) {
112 printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",denied_in);
113 exit(1);
114 }
115
116 if((str=(char *) strstr(user, "_")) != (char *) NULL ) {
117 if((str=(char *) strstr(str+1, "_")) != (char *) NULL )
118 fixip(user);
119 }
120
121 if(Ip2Name)
122 ip2name(ip,sizeof(ip));
123
124 if(!z) {
125 strcpy(ouser,user);
126 strcpy(oip,ip);
127 z++;
128 } else {
129 if(strcmp(ouser,user) == 0)
130 user[0]='\0';
131 if(user[0] != '\0')
132 strcpy(ouser,user);
133 if(strcmp(oip,ip) == 0)
134 ip[0]='\0';
135 if(ip[0] != '\0')
136 strcpy(oip,ip);
137 }
138
139 user_find(name, sizeof(name), user);
140
141 if(dotinuser && strchr(name,'_')) {
142 subs(name,sizeof(name),"_",".");
143 }
144
145 if(DeniedReportLimit) {
146 if(strcmp(ouser2,name) == 0) {
147 count++;
148 } else {
149 count=1;
150 strcpy(ouser2,name);
151 }
152 if(count >= DeniedReportLimit)
153 continue;
154 }
155
156 if(BlockIt[0] != '\0')
157 sprintf(BlockImage,"<a href=\"%s%s?url=%s\"><img src=\"%s/sarg-squidguard-block.png\" border=\"0\"></a>&nbsp;",wwwDocumentRoot,BlockIt,url,ImageFile);
158 else BlockImage[0]='\0';
159
160 fprintf(fp_ou,"<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);
161 }
162
163 fputs("</table>\n",fp_ou);
164
165 show_info(fp_ou);
166 fputs("</body></html>\n",fp_ou);
167
168 fclose(fp_in);
169 fclose(fp_ou);
170
171 unlink(denied_in);
172
173 return;
174 }