]>
git.ipfire.org Git - thirdparty/sarg.git/blob - denied.c
2 * SARG Squid Analysis Report Generator http://sarg.sourceforge.net
6 * please look at http://sarg.sourceforge.net/donations.php
8 * http://sourceforge.net/projects/sarg/forums/forum/363374
9 * ---------------------------------------------------------------------
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.
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.
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.
27 #include "include/conf.h"
28 #include "include/defs.h"
30 void gen_denied_report(void)
33 FILE *fp_in
= NULL
, *fp_ou
= NULL
;
37 char denied_in
[MAXLEN
];
49 struct getwordstruct gwarea
;
51 struct userinfostruct
*uinfo
;
56 sprintf(denied_in
,"%s/sarg/denied.log",TempDir
);
62 sprintf(report
,"%s/denied.html",outdirname
);
64 if((fp_in
=MY_FOPEN(denied_in
,"r"))==NULL
) {
65 debuga(_("(denied) Cannot open log file %s\n"),denied_in
);
69 if((fp_ou
=MY_FOPEN(report
,"w"))==NULL
) {
70 debuga(_("(denied) Cannot open log file %s\n"),report
);
74 write_html_header(fp_ou
,(IndexTree
== INDEX_TREE_DATE
) ? 3 : 1,_("DENIED"));
75 fputs("<tr><td class=\"header_l\">",fp_ou
);
76 fprintf(fp_ou
,_("Period: %s"),period
.text
);
77 fputs("</td></tr>\n",fp_ou
);
78 fprintf(fp_ou
,"<tr><th class=\"header_c\">%s</th></tr>\n",_("DENIED"));
79 close_html_header(fp_ou
);
81 fputs("<div class=\"report\"><table cellpadding=\"0\" cellspacing=\"2\">\n",fp_ou
);
82 fputs("<tr><td></td></tr>\n",fp_ou
);
83 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"));
85 if ((line
=longline_create())==NULL
) {
86 debuga(_("Not enough memory to read the denied accesses\n"));
90 while((buf
=longline_read(fp_in
,line
))!=NULL
) {
91 getword_start(&gwarea
,buf
);
92 if (getword(data
,sizeof(data
),&gwarea
,'\t')<0 || getword(hora
,sizeof(hora
),&gwarea
,'\t')<0 ||
93 getword(user
,sizeof(user
),&gwarea
,'\t')<0 || getword(ip
,sizeof(ip
),&gwarea
,'\t')<0) {
94 debuga(_("There is a broken record or garbage in file %s\n"),denied_in
);
97 if (getword_ptr(buf
,&url
,&gwarea
,'\t')<0) {
98 debuga(_("There is a broken url in file %s\n"),denied_in
);
102 uinfo
=userinfo_find_from_id(user
);
104 debuga(_("Unknown user ID %s in file %s\n"),user
,denied_in
);
115 if(strcmp(ouser
,user
) != 0) {
119 if(strcmp(oip
,ip
) != 0) {
125 if(DeniedReportLimit
) {
126 if(strcmp(ouser2
,uinfo
->label
) == 0) {
130 strcpy(ouser2
,uinfo
->label
);
132 if(count
>= DeniedReportLimit
)
138 fprintf(fp_ou
,"<td class=\"data\">%s</td><td class=\"data\">%s</td>",uinfo
->label
,ip
);
140 fputs("<td class=\"data\"></td><td class=\"data\"></td>",fp_ou
);
141 fprintf(fp_ou
,"<td class=\"data\">%s-%s</td><td class=\"data2\">",data
,hora
);
142 if(BlockIt
[0] != '\0') {
143 fprintf(fp_ou
,"<a href=\"%s%s?url=",wwwDocumentRoot
,BlockIt
);
144 output_html_url(fp_ou
,url
);
145 fprintf(fp_ou
,"\"><img src=\"%s/sarg-squidguard-block.png\"></a> ",ImageFile
);
147 fputs("<a href=\"http://",fp_ou
);
148 output_html_url(fp_ou
,url
);
149 fputs("\">http://",fp_ou
);
150 output_html_string(fp_ou
,url
,100);
151 fputs("</a></td></tr>\n",fp_ou
);
154 longline_destroy(&line
);
156 fputs("</table></div>\n",fp_ou
);
157 if (write_html_trailer(fp_ou
)<0)
158 debuga(_("Write error in file %s\n"),report
);
160 debuga(_("Failed to close file %s - %s\n"),report
,strerror(errno
));