]>
git.ipfire.org Git - thirdparty/sarg.git/blob - denied.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 gen_denied_report ( void )
33 FILE * fp_in
= NULL
, * fp_ou
= NULL
;
36 char denied_in
[ MAXLEN
];
50 struct getwordstruct gwarea
;
55 sprintf ( denied_in
, "%s/sarg/denied.log" , TempDir
);
61 sprintf ( per
, "%s/sarg-period" , dirname
);
62 sprintf ( report
, "%s/denied.html" , dirname
);
64 if (( fp_in
= fopen ( per
, "r" )) == 0 ) {
65 fprintf ( stderr
, "SARG: (denied) %s: %s \n " , text
[ 45 ], per
);
69 if (! fgets ( period
, sizeof ( period
), fp_in
)) {
70 fprintf ( stderr
, "SARG: (denied) read error in %s \n " , per
);
75 if (( fp_in
= MY_FOPEN ( denied_in
, "r" ))== NULL
) {
76 fprintf ( stderr
, "SARG: (denied) %s: %s \n " , text
[ 8 ], denied_in
);
80 if (( fp_ou
= MY_FOPEN ( report
, "w" ))== NULL
) {
81 fprintf ( stderr
, "SARG: (denied) %s: %s \n " , text
[ 8 ], report
);
85 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
);
87 fputs ( "</head> \n " , fp_ou
);
88 fprintf ( fp_ou
, "<body bgcolor= \" %s \" text= \" %s \" background= \" %s \" > \n " , BgColor
, TxColor
, BgImage
);
89 write_logo_image ( fp_ou
);
91 if ( IndexTree
== INDEX_TREE_DATE
)
92 show_sarg ( fp_ou
, "../../.." );
94 show_sarg ( fp_ou
, ".." );
96 fputs ( "<div align= \" center \" ><table cellpadding= \" 0 \" cellspacing= \" 0 \" > \n " , fp_ou
);
97 fprintf ( fp_ou
, "<tr><th class= \" title \" >%s</b></th></tr> \n " , Title
);
99 fprintf ( fp_ou
, "<tr><td class= \" header_l \" >%s: %s</td></tr> \n " , text
[ 89 ], period
);
100 fprintf ( fp_ou
, "<tr><th class= \" header_c \" >%s</th></tr> \n " , text
[ 46 ]);
101 fputs ( "</table></div> \n " , fp_ou
);
103 fputs ( "<div align= \" center \" ><table cellpadding= \" 0 \" cellspacing= \" 2 \" > \n " , fp_ou
);
104 fputs ( "<tr><td></td></tr> \n " , fp_ou
);
105 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 " , text
[ 98 ], text
[ 111 ], text
[ 110 ], text
[ 91 ]);
107 while ( fgets ( buf
, sizeof ( buf
), fp_in
)!= NULL
) {
108 getword_start (& gwarea
, buf
);
109 if ( getword ( data
, sizeof ( data
),& gwarea
, ' \t ' )< 0 || getword ( hora
, sizeof ( hora
),& gwarea
, ' \t ' )< 0 ||
110 getword ( user
, sizeof ( user
),& gwarea
, ' \t ' )< 0 || getword ( ip
, sizeof ( ip
),& gwarea
, ' \t ' )< 0 ||
111 getword ( url
, sizeof ( url
),& gwarea
, ' \t ' )< 0 ) {
112 printf ( "SARG: Maybe you have a broken record or garbage in your %s file. \n " , denied_in
);
116 if (( str
=( char *) strstr ( user
, "_" )) != ( char *) NULL
) {
117 if (( str
=( char *) strstr ( str
+ 1 , "_" )) != ( char *) NULL
)
122 ip2name ( ip
, sizeof ( ip
));
129 if ( strcmp ( ouser
, user
) == 0 )
133 if ( strcmp ( oip
, ip
) == 0 )
139 user_find ( name
, sizeof ( name
), user
);
141 if ( dotinuser
&& strchr ( name
, '_' )) {
142 subs ( name
, sizeof ( name
), "_" , "." );
145 if ( DeniedReportLimit
) {
146 if ( strcmp ( ouser2
, name
) == 0 ) {
152 if ( count
>= DeniedReportLimit
)
156 if ( BlockIt
[ 0 ] != '\0' )
157 sprintf ( BlockImage
, "<a href= \" %s%s?url=%s \" ><img src= \" %s/sarg-squidguard-block.png \" border= \" 0 \" ></a> " , wwwDocumentRoot
, BlockIt
, url
, ImageFile
);
158 else BlockImage
[ 0 ]= '\0' ;
160 fprintf ( fp_ou
, "<tr><td class= \" data \" >%s</td><td class= \" data \" >%s</td><td class= \" data \" >%s-%s</td><td class= \" data2 \" >%s<a href= \" %s \" >%s</a></td></th> \n " , name
, ip
, data
, hora
, BlockImage
, url
, url
);
163 fputs ( "</table> \n " , fp_ou
);
166 fputs ( "</body></html> \n " , fp_ou
);