]>
git.ipfire.org Git - thirdparty/sarg.git/blob - authfail.c
0e1a93410eb16351a33ceaced4d6d8812bcfb231
2 * AUTHOR: Pedro Lineu Orso pedro.orso@gmail.com
4 * SARG Squid Analysis Report Generator http://sarg.sourceforge.net
7 * please look at http://sarg.sourceforge.net/donations.php
8 * ---------------------------------------------------------------------
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.
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.
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.
26 #include "include/conf.h"
27 #include "include/defs.h"
29 void authfail_report ( void )
32 FILE * fp_in
= NULL
, * fp_ou
= NULL
;
35 char authfail_in
[ MAXLEN
];
50 struct getwordstruct gwarea
;
52 if ( DataFile
[ 0 ] != '\0' ) return ;
56 sprintf ( tmp4
, "%s/sarg/authfail.log.unsort" , TempDir
);
63 sprintf ( authfail_in
, "%s/authfail.log" , TempDir
);
64 sprintf ( per
, "%s/sarg-period" , dirname
);
65 sprintf ( report
, "%s/authfail.html" , dirname
);
67 if (( fp_in
= fopen ( per
, "r" )) == 0 ) {
68 fprintf ( stderr
, "SARG: (authfail) %s: %s \n " , text
[ 45 ], per
);
71 if (! fgets ( period
, sizeof ( period
), fp_in
)) {
72 fprintf ( stderr
, "SARG: (authfail) read error in %s \n " , per
);
77 sprintf ( csort
, "sort -b -T \" %s \" -k 3,3 -k 5,5 -o \" %s \" \" %s \" " , TempDir
, authfail_in
, tmp4
);
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
);
84 if (( fp_in
= MY_FOPEN ( authfail_in
, "r" ))== NULL
) {
85 fprintf ( stderr
, "SARG: (authfail) %s: %s \n " , text
[ 45 ], authfail_in
);
86 fprintf ( stderr
, "SARG: sort command: %s \n " , csort
);
91 if (( fp_ou
= MY_FOPEN ( report
, "w" ))== NULL
) {
92 fprintf ( stderr
, "SARG: (authfail) %s: %s \n " , text
[ 45 ], report
);
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
);
98 fputs ( "</head> \n " , fp_ou
);
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
);
101 write_logo_image ( fp_ou
);
103 if ( strcmp ( IndexTree
, "date" ) == 0 )
104 show_sarg ( fp_ou
, "../../.." );
106 show_sarg ( fp_ou
, ".." );
107 fputs ( "<div align= \" center \" ><table cellpadding=0 cellspacing=0> \n " , fp_ou
);
108 fprintf ( fp_ou
, "<tr><th class= \" title \" >%s</th></tr> \n " , Title
);
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 ]);
112 fputs ( "</table></div> \n " , fp_ou
);
114 fputs ( "<div align= \" center \" ><table cellpadding= \" 0 \" cellspacing= \" 2 \" > \n " , fp_ou
);
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
);
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 ]);
120 while ( fgets ( buf
, sizeof ( buf
), fp_in
)!= NULL
) {
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 ) {
125 printf ( "SARG: Maybe you have a broken record or garbage in your %s file. \n " , authfail_in
);
129 if (( str
=( char *) strstr ( user
, "_" )) != ( char *) NULL
) {
130 if (( str
=( char *) strstr ( str
+ 1 , "_" )) != ( char *) NULL
)
135 ip2name ( ip
, sizeof ( ip
));
142 if ( strcmp ( ouser
, user
) == 0 )
146 if ( strcmp ( oip
, ip
) == 0 )
152 // get_usertab_name(user,name,sizeof(name));
153 user_find ( name
, user
);
155 if ( dotinuser
&& strchr ( name
, '_' )) {
156 subs ( name
, sizeof ( name
), "_" , "." );
159 if ( AuthfailReportLimit
) {
160 if ( strcmp ( ouser2
, name
) == 0 ) {
166 if ( count
>= AuthfailReportLimit
)
170 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
);
173 fputs ( "</table> \n " , fp_ou
);
177 fputs ( "</body> \n </html> \n " , fp_ou
);