]> git.ipfire.org Git - thirdparty/sarg.git/blame - denied.c
Update the Russian translation.
[thirdparty/sarg.git] / denied.c
CommitLineData
25697a35 1/*
94ff9470 2 * SARG Squid Analysis Report Generator http://sarg.sourceforge.net
e99bf0c0 3 * 1998, 2013
25697a35
GS
4 *
5 * SARG donations:
6 * please look at http://sarg.sourceforge.net/donations.php
1164c474
FM
7 * Support:
8 * http://sourceforge.net/projects/sarg/forums/forum/363374
25697a35
GS
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"
5f3cfd1d 28#include "include/defs.h"
25697a35 29
f209e4f0
FM
30static void show_ignored_denied(FILE *fp_ou,int count)
31{
9bd92830 32 char ignored[80];
f209e4f0 33
9bd92830 34 snprintf(ignored,sizeof(ignored),ngettext("%d more denied access not shown here…","%d more denied accesses not shown here…",count),count);
7ae50eee 35 fprintf(fp_ou,"<tr><td class=\"data\"></td><td class=\"data\"></td><td class=\"data\"></td><td class=\"data2 more\">%s</td></tr>\n",ignored);
f209e4f0
FM
36}
37
32e71fa4 38void gen_denied_report(void)
25697a35 39{
9bd92830
FM
40 FILE *fp_in = NULL, *fp_ou = NULL;
41
42 char *buf;
43 char *url;
44 char denied_in[MAXLEN];
45 char report[MAXLEN];
46 char ip[MAXLEN];
47 char oip[MAXLEN];
48 char user[MAXLEN];
49 char ouser[MAXLEN];
50 char ouser2[MAXLEN];
51 char data[15];
52 char hora[15];
53 bool z=false;
54 int count=0;
55 int day,month,year;
56 bool new_user;
57 struct getwordstruct gwarea;
58 longline line;
59 struct userinfostruct *uinfo;
60 struct tm t;
61
62 ouser[0]='\0';
63 ouser2[0]='\0';
64
c98d6a0f 65 sprintf(denied_in,"%s/denied.int_log",tmp);
08f9b029 66 if (!denied_count) {
11767c6a
FM
67 if (!KeepTempLog && unlink(denied_in))
68 debuga(_("Cannot delete \"%s\": %s\n"),denied_in,strerror(errno));
9f93fec3 69 if (debugz) debugaz(_("Denied report not produced because it is empty\n"));
9bd92830
FM
70 return;
71 }
72
73 sprintf(report,"%s/denied.html",outdirname);
74
75 if((fp_in=MY_FOPEN(denied_in,"r"))==NULL) {
4b06d570 76 debugapos("denied",_("Cannot open file \"%s\": %s\n"),denied_in,strerror(errno));
007905af 77 exit(EXIT_FAILURE);
9bd92830
FM
78 }
79
80 if((fp_ou=MY_FOPEN(report,"w"))==NULL) {
4b06d570 81 debugapos("denied",_("Cannot open file \"%s\": %s\n"),report,strerror(errno));
007905af 82 exit(EXIT_FAILURE);
9bd92830
FM
83 }
84
85 write_html_header(fp_ou,(IndexTree == INDEX_TREE_DATE) ? 3 : 1,_("Denied"),HTML_JS_NONE);
86 fputs("<tr><td class=\"header_c\">",fp_ou);
87 fprintf(fp_ou,_("Period: %s"),period.html);
88 fputs("</td></tr>\n",fp_ou);
89 fprintf(fp_ou,"<tr><th class=\"header_c\">%s</th></tr>\n",_("Denied"));
90 close_html_header(fp_ou);
91
92 fputs("<div class=\"report\"><table cellpadding=\"0\" cellspacing=\"2\">\n",fp_ou);
93 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",_("USERID"),_("IP/NAME"),_("DATE/TIME"),_("ACCESSED SITE"));
94
95 if ((line=longline_create())==NULL) {
b2dad7e7 96 debuga(_("Not enough memory to read file \"%s\"\n"),denied_in);
9bd92830
FM
97 exit(EXIT_FAILURE);
98 }
99
100 while((buf=longline_read(fp_in,line))!=NULL) {
101 getword_start(&gwarea,buf);
102 if (getword(data,sizeof(data),&gwarea,'\t')<0 || getword(hora,sizeof(hora),&gwarea,'\t')<0 ||
007905af 103 getword(user,sizeof(user),&gwarea,'\t')<0 || getword(ip,sizeof(ip),&gwarea,'\t')<0) {
a968fba4 104 debuga(_("Invalid record in file \"%s\"\n"),denied_in);
9bd92830
FM
105 exit(EXIT_FAILURE);
106 }
107 if (getword_ptr(buf,&url,&gwarea,'\t')<0) {
a968fba4 108 debuga(_("Invalid url in file \"%s\"\n"),denied_in);
9bd92830
FM
109 exit(EXIT_FAILURE);
110 }
111 if (sscanf(data,"%d/%d/%d",&day,&month,&year)!=3) continue;
112 computedate(year,month,day,&t);
113 strftime(data,sizeof(data),"%x",&t);
114
115 uinfo=userinfo_find_from_id(user);
116 if (!uinfo) {
a968fba4 117 debuga(_("Unknown user ID %s in file \"%s\"\n"),user,denied_in);
9bd92830
FM
118 exit(EXIT_FAILURE);
119 }
120
121 new_user=false;
122 if(!z) {
123 strcpy(ouser,user);
124 strcpy(oip,ip);
125 z=true;
126 new_user=true;
127 } else {
128 if(strcmp(ouser,user) != 0) {
129 strcpy(ouser,user);
130 new_user=true;
131 }
132 if(strcmp(oip,ip) != 0) {
133 strcpy(oip,ip);
134 new_user=true;
135 }
136 }
137
138 if(DeniedReportLimit) {
139 if(strcmp(ouser2,uinfo->label) == 0) {
140 count++;
141 } else {
142 if(count>DeniedReportLimit && DeniedReportLimit>0)
143 show_ignored_denied(fp_ou,count-DeniedReportLimit);
144 count=1;
145 strcpy(ouser2,uinfo->label);
146 }
147 if(count > DeniedReportLimit)
148 continue;
149 }
150
151 fputs("<tr>",fp_ou);
dbf8818d
FM
152 if (new_user) {
153 if (uinfo->topuser)
154 fprintf(fp_ou,"<td class=\"data\"><a href=\"%s/%s.html\">%s</a></td><td class=\"data\">%s</td>",uinfo->filename,uinfo->filename,uinfo->label,ip);
155 else
156 fprintf(fp_ou,"<td class=\"data\">%s</td><td class=\"data\">%s</td>",uinfo->label,ip);
157 } else
9bd92830
FM
158 fputs("<td class=\"data\"></td><td class=\"data\"></td>",fp_ou);
159 fprintf(fp_ou,"<td class=\"data\">%s-%s</td><td class=\"data2\">",data,hora);
67a93701 160 if(BlockIt[0] != '\0' && url[0]!=ALIAS_PREFIX) {
9bd92830
FM
161 fprintf(fp_ou,"<a href=\"%s%s?url=",wwwDocumentRoot,BlockIt);
162 output_html_url(fp_ou,url);
163 fprintf(fp_ou,"\"><img src=\"%s/sarg-squidguard-block.png\"></a>&nbsp;",ImageFile);
164 }
6fa33a32 165 output_html_link(fp_ou,url,100);
67a93701 166 fputs("</td></tr>\n",fp_ou);
9bd92830
FM
167 }
168 fclose(fp_in);
169 longline_destroy(&line);
170
171 if(count>DeniedReportLimit && DeniedReportLimit>0)
172 show_ignored_denied(fp_ou,count-DeniedReportLimit);
173
174 fputs("</table></div>\n",fp_ou);
175 if (write_html_trailer(fp_ou)<0)
b2dad7e7 176 debuga(_("Write error in file \"%s\"\n"),report);
7f00fa38 177 if (fclose(fp_ou)==EOF)
4b06d570 178 debuga(_("Failed to close file \"%s\": %s\n"),report,strerror(errno));
9bd92830 179
11767c6a
FM
180 if (!KeepTempLog && unlink(denied_in)==-1)
181 debuga(_("Cannot delete \"%s\": %s\n"),denied_in,strerror(errno));
9bd92830
FM
182
183 return;
25697a35 184}