]>
git.ipfire.org Git - thirdparty/sarg.git/blob - authfail.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 authfail_report ( void )
33 FILE * fp_in
= NULL
, * fp_ou
= NULL
;
36 char authfail_in
[ MAXLEN
];
51 struct getwordstruct gwarea
;
53 if ( DataFile
[ 0 ] != '\0' ) return ;
57 sprintf ( tmp4
, "%s/sarg/authfail.log.unsort" , TempDir
);
64 sprintf ( authfail_in
, "%s/authfail.log" , TempDir
);
65 sprintf ( per
, "%s/sarg-period" , dirname
);
66 sprintf ( report
, "%s/authfail.html" , dirname
);
68 if (( fp_in
= fopen ( per
, "r" )) == 0 ) {
69 fprintf ( stderr
, "SARG: (authfail) %s: %s \n " , text
[ 45 ], per
);
72 if (! fgets ( period
, sizeof ( period
), fp_in
)) {
73 fprintf ( stderr
, "SARG: (authfail) read error in %s \n " , per
);
78 sprintf ( csort
, "sort -b -T \" %s \" -k 3,3 -k 5,5 -o \" %s \" \" %s \" " , TempDir
, authfail_in
, tmp4
);
79 cstatus
= system ( csort
);
80 if (! WIFEXITED ( cstatus
) || WEXITSTATUS ( cstatus
)) {
81 fprintf ( stderr
, "SARG: sort command return status %d \n " , WEXITSTATUS ( cstatus
));
82 fprintf ( stderr
, "SARG: sort command: %s \n " , csort
);
85 if (( fp_in
= MY_FOPEN ( authfail_in
, "r" ))== NULL
) {
86 fprintf ( stderr
, "SARG: (authfail) %s: %s \n " , text
[ 45 ], authfail_in
);
87 fprintf ( stderr
, "SARG: sort command: %s \n " , csort
);
92 if (( fp_ou
= MY_FOPEN ( report
, "w" ))== NULL
) {
93 fprintf ( stderr
, "SARG: (authfail) %s: %s \n " , text
[ 45 ], report
);
97 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
);
99 fputs ( "</head> \n " , fp_ou
);
100 if ( strlen ( FontFace
) > 0 ) fprintf ( fp_ou
, "<font face=%s> \n " , FontFace
);
101 fprintf ( fp_ou
, "<body bgcolor=%s text=%s background='%s'> \n " , BgColor
, TxColor
, BgImage
);
102 write_logo_image ( fp_ou
);
104 if ( IndexTree
== INDEX_TREE_DATE
)
105 show_sarg ( fp_ou
, "../../.." );
107 show_sarg ( fp_ou
, ".." );
108 fputs ( "<div align= \" center \" ><table cellpadding=0 cellspacing=0> \n " , fp_ou
);
109 fprintf ( fp_ou
, "<tr><th class= \" title \" >%s</th></tr> \n " , Title
);
111 fprintf ( fp_ou
, "<tr><td class= \" header \" >%s: %s</td></tr> \n " , text
[ 89 ], period
);
112 fprintf ( fp_ou
, "<tr><th class= \" header3 \" >%s</th></tr> \n " , text
[ 117 ]);
113 fputs ( "</table></div> \n " , fp_ou
);
115 fputs ( "<div align= \" center \" ><table cellpadding= \" 0 \" cellspacing= \" 2 \" > \n " , fp_ou
);
116 fputs ( "<tr><td></td></tr> \n " , fp_ou
);
117 fputs ( "<tr><td></td></tr> \n " , fp_ou
);
118 fputs ( "<tr><td></td></tr> \n " , fp_ou
);
119 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 ]);
121 while ( fgets ( buf
, sizeof ( buf
), fp_in
)!= NULL
) {
122 getword_start (& gwarea
, buf
);
123 if ( getword ( data
, sizeof ( data
),& gwarea
, ' \t ' )< 0 || getword ( hora
, sizeof ( hora
),& gwarea
, ' \t ' )< 0 ||
124 getword ( user
, sizeof ( user
),& gwarea
, ' \t ' )< 0 || getword ( ip
, sizeof ( ip
),& gwarea
, ' \t ' )< 0 ||
125 getword ( url
, sizeof ( url
),& gwarea
, ' \t ' )< 0 ) {
126 printf ( "SARG: Maybe you have a broken record or garbage in your %s file. \n " , authfail_in
);
130 if (( str
=( char *) strstr ( user
, "_" )) != ( char *) NULL
) {
131 if (( str
=( char *) strstr ( str
+ 1 , "_" )) != ( char *) NULL
)
136 ip2name ( ip
, sizeof ( ip
));
143 if ( strcmp ( ouser
, user
) == 0 )
147 if ( strcmp ( oip
, ip
) == 0 )
153 user_find ( name
, sizeof ( 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
);