]>
git.ipfire.org Git - thirdparty/sarg.git/blob - authfail.c
860505f9c737880b71a8d27a431f1f0c9978d461
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 authfail_report(void)
33 FILE *fp_in
= NULL
, *fp_ou
= NULL
;
37 char authfail_in
[MAXLEN
];
54 struct getwordstruct gwarea
;
55 struct longlinestruct line
;
56 struct userinfostruct
*uinfo
;
58 if(DataFile
[0] != '\0') return;
63 sprintf(tmp4
,"%s/sarg/authfail.log.unsort",TempDir
);
70 sprintf(authfail_in
,"%s/authfail.log",TempDir
);
71 sprintf(per
,"%s/sarg-period",dirname
);
72 sprintf(report
,"%s/authfail.html",dirname
);
74 if ((fp_in
= fopen(per
, "r")) == 0) {
75 fprintf(stderr
, "SARG: (authfail) %s: %s\n",_("Cannot open file"),per
);
78 if (!fgets(period
,sizeof(period
),fp_in
)) {
79 debuga(_("(authfail) read error in %s"),per
);
84 sprintf(csort
,"sort -b -T \"%s\" -k 3,3 -k 5,5 -o \"%s\" \"%s\"", TempDir
, authfail_in
, tmp4
);
85 cstatus
=system(csort
);
86 if (!WIFEXITED(cstatus
) || WEXITSTATUS(cstatus
)) {
87 debuga(_("sort command return status %d"),WEXITSTATUS(cstatus
));
88 debuga(_("sort command: %s"),csort
);
91 if((fp_in
=MY_FOPEN(authfail_in
,"r"))==NULL
) {
92 fprintf(stderr
, "SARG: (authfail) %s: %s\n",_("Cannot open file"),authfail_in
);
93 debuga(_("sort command: %s"),csort
);
98 if((fp_ou
=MY_FOPEN(report
,"w"))==NULL
) {
99 fprintf(stderr
, "SARG: (authfail) %s: %s\n",_("Cannot open file"),report
);
103 write_html_header(fp_ou
,(IndexTree
== INDEX_TREE_DATE
) ? 3 : 1,_("Authentication Failures"));
104 fprintf(fp_ou
,"<tr><td class=\"header_l\">%s: %s</td></tr>\n",_("Period"),period
);
105 fprintf(fp_ou
,"<tr><th class=\"header_c\">%s</th></tr>\n",_("Authentication Failures"));
106 close_html_header(fp_ou
);
108 fputs("<div class=\"report\"><table cellpadding=\"0\" cellspacing=\"2\">\n",fp_ou
);
109 fputs("<tr><td></td></tr>\n",fp_ou
);
110 fputs("<tr><td></td></tr>\n",fp_ou
);
111 fputs("<tr><td></td></tr>\n",fp_ou
);
112 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"));
114 if (longline_prepare(&line
)<0) {
115 debuga(_("Not enough memory to read file %s"),authfail_in
);
119 while((buf
=longline_read(fp_in
,&line
))!=NULL
) {
120 getword_start(&gwarea
,buf
);
121 if (getword(data
,sizeof(data
),&gwarea
,'\t')<0 || getword(hora
,sizeof(hora
),&gwarea
,'\t')<0 ||
122 getword(user
,sizeof(user
),&gwarea
,'\t')<0 || getword(ip
,sizeof(ip
),&gwarea
,'\t')<0) {
123 debuga(_("There is a broken record or garbage in file %s"),authfail_in
);
126 if (getword_ptr(buf
,&url
,&gwarea
,'\t')<0) {
127 debuga(_("There is a broken url in file %s"),authfail_in
);
131 uinfo
=userinfo_find_from_id(user
);
133 debuga(_("Unknown user ID %s in file %s"),user
,authfail_in
);
144 if(strcmp(ouser
,user
) != 0) {
148 if(strcmp(oip
,ip
) != 0) {
154 if(AuthfailReportLimit
) {
155 if(strcmp(ouser2
,uinfo
->label
) == 0) {
159 strcpy(ouser2
,uinfo
->label
);
161 if(count
>= AuthfailReportLimit
)
167 fprintf(fp_ou
,"<td class=\"data2\">%s</td><td class=\"data2\">%s</td>",uinfo
->label
,ip
);
169 fputs("<td class=\"data2\"></td><td class=\"data2\"></td>",fp_ou
);
170 fprintf(fp_ou
,"<td class=\"data2\">%s-%s</td><td class=\"data2\">",data
,hora
);
171 if(BlockIt
[0]!='\0') {
172 fprintf(fp_ou
,"<a href=\"%s%s?url=",wwwDocumentRoot
,BlockIt
);
173 output_html_url(fp_ou
,url
);
174 fputs("\"><img src=\"../images/sarg-squidguard-block.png\"></a> ",fp_ou
);
176 fputs("<a href=\"",fp_ou
);
177 output_html_url(fp_ou
,url
);
179 output_html_string(fp_ou
,url
,100);
180 fputs("</a></td></th>\n",fp_ou
);
183 longline_free(&line
);
185 fputs("</table></div>\n",fp_ou
);
186 write_html_trailer(fp_ou
);