]> git.ipfire.org Git - thirdparty/sarg.git/blame - authfail.c
This commit was generated by cvs2svn to compensate for changes in r2,
[thirdparty/sarg.git] / authfail.c
CommitLineData
25697a35
GS
1/*
2 * AUTHOR: Pedro Lineu Orso orso@brturbo.com
3 * 1998, 2004
4 * SARG Squid Analysis Report Generator http://sarg-squid.org
5 * ---------------------------------------------------------------------
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
20 *
21 */
22
23#include "include/conf.h"
24
25void authfail_report()
26{
27
28 FILE *fp_in = NULL, *fp_ou = NULL;
29
30 char url[MAXLEN];
31 char html[MAXLEN];
32 char html2[MAXLEN];
33 char authfail_in[MAXLEN];
34 char per[MAXLEN];
35 char report[MAXLEN];
36 char periodo[100];
37 char ip[MAXLEN];
38 char oip[MAXLEN];
39 char user[MAXLEN];
40 char ouser[MAXLEN];
41 char ouser2[MAXLEN];
42 char data[15];
43 char hora[15];
44 char ftime[128];
45 char *str;
46 int z=0;
47 int count=0;
48
49 if(strlen(DataFile) > 0) return;
50
51 ouser[0]='\0';
52
53 sprintf(tmp4,"%s/authfail.log.unsort",TempDir);
54
55 if(!authfail_count) {
56 unlink(tmp4);
57 return;
58 }
59
60 sprintf(authfail_in,"%s/authfail.log",TempDir);
61 sprintf(per,"%s/periodo",dirname);
62 sprintf(report,"%s/authfail.html",dirname);
63
64 sprintf(csort,"sort -b -T %s -k 3,3 -k 5,5 -o %s %s", TempDir, authfail_in, tmp4);
65 system(csort);
66 unlink(tmp4);
67
68 if ((fp_in = fopen(per, "r")) == 0) {
69 fprintf(stderr, "SARG: (authfail) %s: %s\n",text[45],per);
70 exit(1);
71 }
72
73 fgets(periodo,sizeof(periodo),fp_in);
74 fclose(fp_in);
75
76 if((fp_in=fopen(authfail_in,"r"))==NULL) {
77 fprintf(stderr, "SARG: (authfail) %s: %s\n",text[45],authfail_in);
78 exit(1);
79 }
80
81 if((fp_ou=fopen(report,"w"))==NULL) {
82 fprintf(stderr, "SARG: (authfail) %s: %s\n",text[45],report);
83 exit(1);
84 }
85
86 fputs("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\"",fp_ou);
87 fputs(" \"http://www.w3.org/TR/html4/loose.dtd\">\n",fp_ou);
88 fputs("<html>\n",fp_ou);
89 fputs("<head>\n",fp_ou);
90 sprintf(html," <meta http-equiv=\"Content-Type\" content=\"text/html; charset=%s\">\n",CharSet);
91 fputs(html,fp_ou);
92 css(fp_ou);
93 fputs("</head>\n",fp_ou);
94
95 if(strlen(FontFace) > 0) {
96 sprintf(url,"<font face=%s>\n",FontFace);
97 fputs(url,fp_ou);
98 }
99
100 sprintf(url,"<body bgcolor=%s text=%s background='%s'>\n",BgColor,TxColor,BgImage);
101 fputs(url,fp_ou);
102
103 if(strlen(LogoImage) > 0) {
104 fputs("<center><table cellpadding=0 cellspacing=0>\n",fp_ou);
105 sprintf(url,"<tr><th align=\"center\"><img src='%s' border=0 align=absmiddle width=%s height=%s><font color=%s>%s</font>\n",LogoImage,Width,Height,LogoTextColor,LogoText);
106 fputs(url,fp_ou);
107 fputs("</table>\n",fp_ou);
108 }
109
110 show_sarg(fp_ou,"..");
111 fputs("<center><table cellpadding=0 cellspacing=0>\n",fp_ou);
112 sprintf(url,"<tr><th class=\"title\">%s</th></tr>\n",Title);
113 fputs(url,fp_ou);
114
115 sprintf(url,"<tr><td class=\"header\">%s: %s</td></tr>\n",text[89],periodo);
116 fputs(url,fp_ou);
117 sprintf(url,"<tr><th class=\"header\">%s %s</th></tr>\n",text[117],text[55]);
118 fputs(url,fp_ou);
119 fputs("</table></center>\n",fp_ou);
120
121 fputs("<center><table cellpadding=0 cellspacing=2>\n",fp_ou);
122 fputs("<tr><td></td></tr>\n",fp_ou);
123 fputs("<tr><td></td></tr>\n",fp_ou);
124 fputs("<tr><td></td></tr>\n",fp_ou);
125 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]);
126 fputs(url,fp_ou);
127
128 while(fgets(buf,sizeof(buf),fp_in)!=NULL) {
129 getword(data,buf,' ');
130 getword(hora,buf,' ');
131 getword(user,buf,' ');
132 getword(ip,buf,' ');
133 getword(url,buf,' ');
134
135 if((str=(char *) strstr(user, "_")) != (char *) NULL ) {
136 if((str=(char *) strstr(str+1, "_")) != (char *) NULL )
137 fixip(user);
138 }
139
140 if(strcmp(Ip2Name,"yes") == 0)
141 ip2name(ip);
142
143 if(!z) {
144 strcpy(ouser,user);
145 strcpy(oip,ip);
146 z++;
147 } else {
148 if(strcmp(ouser,user) == 0)
149 user[0]='\0';
150 if(user[0] != '\0')
151 strcpy(ouser,user);
152 if(strcmp(oip,ip) == 0)
153 ip[0]='\0';
154 if(ip[0] != '\0')
155 strcpy(oip,ip);
156 }
157
158 if(UserTabFile[0] != '\0') {
159 sprintf(warea,":%s:",user);
160 if((str=(char *) strstr(userfile,warea)) != (char *) NULL ) {
161 z1=0;
162 str2=(char *) strstr(str+1,":");
163 str2++;
164 bzero(name, MAXLEN);
165 while(str2[z1] != ':') {
166 name[z1]=str2[z1];
167 z1++;
168 }
169 } else strcpy(name,user);
170 } else strcpy(name,user);
171
172 if(AuthfailReportLimit) {
173 if(strcmp(ouser2,name) == 0) {
174 count++;
175 } else {
176 count=1;
177 strcpy(ouser2,name);
178 }
179 if(count >= AuthfailReportLimit)
180 continue;
181 }
182
183 sprintf(html2,"<tr><td class=\"data2\">%s</td><td class=\"data2\">%s</td><td class=\"data2\">%s-%s</td><td class=\"data2\">%s<a href=\"%s\">%s</a></td></th>\n",name,ip,data,hora,BlockImage,url,url);
184 fputs(html2,fp_ou);
185 }
186
187 fputs("</table>\n",fp_ou);
188
189 show_info(fp_ou);
190
191 fputs("</body>\n</html>\n",fp_ou);
192
193 fclose(fp_in);
194 fclose(fp_ou);
195
196 unlink(authfail_in);
197
198 return;
199}