]>
Commit | Line | Data |
---|---|---|
25697a35 | 1 | /* |
c37945ed | 2 | * AUTHOR: Pedro Lineu Orso pedro.orso@gmail.com |
a6e5c172 | 3 | * 1998, 2010 |
94ff9470 GS |
4 | * SARG Squid Analysis Report Generator http://sarg.sourceforge.net |
5 | * | |
6 | * SARG donations: | |
7 | * please look at http://sarg.sourceforge.net/donations.php | |
25697a35 GS |
8 | * --------------------------------------------------------------------- |
9 | * | |
10 | * This program is free software; you can redistribute it and/or modify | |
11 | * it under the terms of the GNU General Public License as published by | |
12 | * the Free Software Foundation; either version 2 of the License, or | |
13 | * (at your option) any later version. | |
14 | * | |
15 | * This program is distributed in the hope that it will be useful, | |
16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
18 | * GNU General Public License for more details. | |
19 | * | |
20 | * You should have received a copy of the GNU General Public License | |
21 | * along with this program; if not, write to the Free Software | |
22 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA. | |
23 | * | |
24 | */ | |
25 | ||
26 | #include "include/conf.h" | |
5f3cfd1d | 27 | #include "include/defs.h" |
25697a35 | 28 | |
32e71fa4 | 29 | void authfail_report(void) |
25697a35 GS |
30 | { |
31 | ||
32 | FILE *fp_in = NULL, *fp_ou = NULL; | |
120d768c | 33 | |
25697a35 | 34 | char url[MAXLEN]; |
25697a35 GS |
35 | char authfail_in[MAXLEN]; |
36 | char per[MAXLEN]; | |
37 | char report[MAXLEN]; | |
d6e703cc | 38 | char period[100]; |
25697a35 GS |
39 | char ip[MAXLEN]; |
40 | char oip[MAXLEN]; | |
41 | char user[MAXLEN]; | |
42 | char ouser[MAXLEN]; | |
43 | char ouser2[MAXLEN]; | |
44 | char data[15]; | |
45 | char hora[15]; | |
25697a35 GS |
46 | char *str; |
47 | int z=0; | |
48 | int count=0; | |
456d78a5 | 49 | int cstatus; |
9c7c6346 | 50 | struct getwordstruct gwarea; |
25697a35 | 51 | |
0a4e18e1 | 52 | if(DataFile[0] != '\0') return; |
25697a35 GS |
53 | |
54 | ouser[0]='\0'; | |
55 | ||
491b862f | 56 | sprintf(tmp4,"%s/sarg/authfail.log.unsort",TempDir); |
120d768c | 57 | |
25697a35 GS |
58 | if(!authfail_count) { |
59 | unlink(tmp4); | |
60 | return; | |
61 | } | |
62 | ||
63 | sprintf(authfail_in,"%s/authfail.log",TempDir); | |
d6e703cc | 64 | sprintf(per,"%s/sarg-period",dirname); |
25697a35 GS |
65 | sprintf(report,"%s/authfail.html",dirname); |
66 | ||
25697a35 GS |
67 | if ((fp_in = fopen(per, "r")) == 0) { |
68 | fprintf(stderr, "SARG: (authfail) %s: %s\n",text[45],per); | |
69 | exit(1); | |
70 | } | |
05b90947 FM |
71 | if (!fgets(period,sizeof(period),fp_in)) { |
72 | fprintf(stderr,"SARG: (authfail) read error in %s\n",per); | |
73 | exit(1); | |
74 | } | |
25697a35 GS |
75 | fclose(fp_in); |
76 | ||
9a2efbd0 | 77 | sprintf(csort,"sort -b -T \"%s\" -k 3,3 -k 5,5 -o \"%s\" \"%s\"", TempDir, authfail_in, tmp4); |
456d78a5 FM |
78 | cstatus=system(csort); |
79 | if (!WIFEXITED(cstatus) || WEXITSTATUS(cstatus)) { | |
80 | fprintf(stderr, "SARG: sort command return status %d\n",WEXITSTATUS(cstatus)); | |
81 | fprintf(stderr, "SARG: sort command: %s\n",csort); | |
82 | exit(1); | |
83 | } | |
936c9905 | 84 | if((fp_in=MY_FOPEN(authfail_in,"r"))==NULL) { |
456d78a5 FM |
85 | fprintf(stderr, "SARG: (authfail) %s: %s\n",text[45],authfail_in); |
86 | fprintf(stderr, "SARG: sort command: %s\n",csort); | |
87 | exit(1); | |
25697a35 | 88 | } |
456d78a5 | 89 | unlink(tmp4); |
25697a35 | 90 | |
936c9905 | 91 | if((fp_ou=MY_FOPEN(report,"w"))==NULL) { |
25697a35 GS |
92 | fprintf(stderr, "SARG: (authfail) %s: %s\n",text[45],report); |
93 | exit(1); | |
94 | } | |
95 | ||
d6e703cc | 96 | 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); |
25697a35 GS |
97 | css(fp_ou); |
98 | fputs("</head>\n",fp_ou); | |
d6e703cc FM |
99 | if(strlen(FontFace) > 0) fprintf(fp_ou,"<font face=%s>\n",FontFace); |
100 | fprintf(fp_ou,"<body bgcolor=%s text=%s background='%s'>\n",BgColor,TxColor,BgImage); | |
dfb337be | 101 | write_logo_image(fp_ou); |
25697a35 | 102 | |
491b862f GS |
103 | if(strcmp(IndexTree,"date") == 0) |
104 | show_sarg(fp_ou, "../../.."); | |
105 | else | |
106 | show_sarg(fp_ou,".."); | |
dfb337be | 107 | fputs("<div align=\"center\"><table cellpadding=0 cellspacing=0>\n",fp_ou); |
354c1a68 | 108 | fprintf(fp_ou,"<tr><th class=\"title\">%s</th></tr>\n",Title); |
25697a35 | 109 | |
354c1a68 FM |
110 | fprintf(fp_ou,"<tr><td class=\"header\">%s: %s</td></tr>\n",text[89],period); |
111 | fprintf(fp_ou,"<tr><th class=\"header3\">%s</th></tr>\n",text[117]); | |
dfb337be | 112 | fputs("</table></div>\n",fp_ou); |
25697a35 | 113 | |
dfb337be | 114 | fputs("<div align=\"center\"><table cellpadding=\"0\" cellspacing=\"2\">\n",fp_ou); |
25697a35 GS |
115 | fputs("<tr><td></td></tr>\n",fp_ou); |
116 | fputs("<tr><td></td></tr>\n",fp_ou); | |
117 | fputs("<tr><td></td></tr>\n",fp_ou); | |
354c1a68 | 118 | fprintf(fp_ou,"<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]); |
25697a35 GS |
119 | |
120 | while(fgets(buf,sizeof(buf),fp_in)!=NULL) { | |
9c7c6346 FM |
121 | getword_start(&gwarea,buf); |
122 | if (getword(data,sizeof(data),&gwarea,'\t')<0 || getword(hora,sizeof(hora),&gwarea,'\t')<0 || | |
123 | getword(user,sizeof(user),&gwarea,'\t')<0 || getword(ip,sizeof(ip),&gwarea,'\t')<0 || | |
124 | getword(url,sizeof(url),&gwarea,'\t')<0) { | |
4bcb77cf FM |
125 | printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",authfail_in); |
126 | exit(1); | |
127 | } | |
25697a35 GS |
128 | |
129 | if((str=(char *) strstr(user, "_")) != (char *) NULL ) { | |
130 | if((str=(char *) strstr(str+1, "_")) != (char *) NULL ) | |
131 | fixip(user); | |
132 | } | |
133 | ||
246c8489 | 134 | if(Ip2Name) |
a1c55d8c | 135 | ip2name(ip,sizeof(ip)); |
25697a35 GS |
136 | |
137 | if(!z) { | |
138 | strcpy(ouser,user); | |
139 | strcpy(oip,ip); | |
140 | z++; | |
141 | } else { | |
142 | if(strcmp(ouser,user) == 0) | |
143 | user[0]='\0'; | |
144 | if(user[0] != '\0') | |
145 | strcpy(ouser,user); | |
120d768c | 146 | if(strcmp(oip,ip) == 0) |
25697a35 GS |
147 | ip[0]='\0'; |
148 | if(ip[0] != '\0') | |
149 | strcpy(oip,ip); | |
150 | } | |
151 | ||
936c9905 | 152 | get_usertab_name(user,name,sizeof(name)); |
25697a35 | 153 | |
48864d28 FM |
154 | if(dotinuser && strchr(name,'_')) { |
155 | subs(name,sizeof(name),"_","."); | |
94ff9470 GS |
156 | } |
157 | ||
25697a35 GS |
158 | if(AuthfailReportLimit) { |
159 | if(strcmp(ouser2,name) == 0) { | |
160 | count++; | |
161 | } else { | |
162 | count=1; | |
163 | strcpy(ouser2,name); | |
164 | } | |
165 | if(count >= AuthfailReportLimit) | |
166 | continue; | |
167 | } | |
168 | ||
354c1a68 | 169 | fprintf(fp_ou,"<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); |
25697a35 GS |
170 | } |
171 | ||
172 | fputs("</table>\n",fp_ou); | |
173 | ||
174 | show_info(fp_ou); | |
175 | ||
176 | fputs("</body>\n</html>\n",fp_ou); | |
177 | ||
178 | fclose(fp_in); | |
179 | fclose(fp_ou); | |
180 | ||
181 | unlink(authfail_in); | |
182 | ||
183 | return; | |
184 | } |