]>
git.ipfire.org Git - thirdparty/sarg.git/blob - denied.c
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 gen_denied_report ( void )
32 FILE * fp_in
= NULL
, * fp_ou
= NULL
;
35 char denied_in
[ MAXLEN
];
52 sprintf ( denied_in
, "%s/sarg/denied.log" , TempDir
);
58 sprintf ( per
, "%s/sarg-period" , dirname
);
59 sprintf ( report
, "%s/denied.html" , dirname
);
61 if (( fp_in
= fopen ( per
, "r" )) == 0 ) {
62 fprintf ( stderr
, "SARG: (denied) %s: %s \n " , text
[ 45 ], per
);
66 fgets ( period
, sizeof ( period
), fp_in
);
69 #if defined(HAVE_FOPEN64)
70 if (( fp_in
= fopen64 ( denied_in
, "r" ))== NULL
) {
72 if (( fp_in
= fopen ( denied_in
, "r" ))== NULL
) {
74 fprintf ( stderr
, "SARG: (denied) %s: %s \n " , text
[ 8 ], denied_in
);
78 #if defined(HAVE_FOPEN64)
79 if (( fp_ou
= fopen64 ( report
, "w" ))== NULL
) {
81 if (( fp_ou
= fopen ( report
, "w" ))== NULL
) {
83 fprintf ( stderr
, "SARG: (denied) %s: %s \n " , text
[ 8 ], report
);
87 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
);
89 fputs ( "</head> \n " , fp_ou
);
90 fprintf ( fp_ou
, "<body bgcolor=%s text=%s background='%s'> \n " , BgColor
, TxColor
, BgImage
);
91 if ( strlen ( LogoImage
) > 0 ) fprintf ( fp_ou
, "<center><table cellpadding= \" 0 \" cellspacing= \" 0 \" > \n <tr><th class= \" logo \" ><img src='%s' border=0 align=absmiddle width=%s height=%s> %s</th></tr> \n <tr><td height= \" 5 \" ></td></tr> \n </table> \n " , LogoImage
, Width
, Height
, LogoText
);
93 if ( strcmp ( IndexTree
, "date" ) == 0 )
94 show_sarg ( fp_ou
, "../../.." );
96 show_sarg ( fp_ou
, ".." );
98 fputs ( "<center><table cellpadding=0 cellspacing=0> \n " , fp_ou
);
99 fprintf ( fp_ou
, "<tr><th class= \" title \" >%s</b></th></tr> \n " , Title
);
101 fprintf ( fp_ou
, "<tr><td class= \" header \" >%s: %s</td></tr> \n " , text
[ 89 ], period
);
102 fprintf ( fp_ou
, "<tr><th class= \" header3 \" >%s</th></tr> \n " , text
[ 46 ]);
103 fputs ( "</table></center> \n " , fp_ou
);
105 fputs ( "<center><table cellpadding=0 cellspacing=2> \n " , fp_ou
);
106 fputs ( "<tr><td></td></tr> \n " , fp_ou
);
107 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 ]);
109 while ( fgets ( buf
, sizeof ( buf
), fp_in
)!= NULL
) {
110 if ( getword ( data
, sizeof ( data
), buf
, ' ' )< 0 || getword ( hora
, sizeof ( hora
), buf
, ' ' )< 0 ||
111 getword ( user
, sizeof ( user
), buf
, ' ' )< 0 || getword ( ip
, sizeof ( ip
), buf
, ' ' )< 0 ||
112 getword ( url
, sizeof ( url
), buf
, ' ' )< 0 ) {
113 printf ( "SARG: Maybe you have a broken record or garbage in your %s file. \n " , denied_in
);
117 if (( str
=( char *) strstr ( user
, "_" )) != ( char *) NULL
) {
118 if (( str
=( char *) strstr ( str
+ 1 , "_" )) != ( char *) NULL
)
122 if ( strcmp ( Ip2Name
, "yes" ) == 0 )
123 ip2name ( ip
, sizeof ( ip
));
130 if ( strcmp ( ouser
, user
) == 0 )
134 if ( strcmp ( oip
, ip
) == 0 )
140 if ( UserTabFile
[ 0 ] != '\0' ) {
141 sprintf ( warea
, ":%s:" , user
);
142 if (( str
=( char *) strstr ( userfile
, warea
)) != ( char *) NULL
) {
144 str2
=( char *) strstr ( str
+ 1 , ":" );
147 while ( str2
[ z1
] != ':' ) {
151 } else strcpy ( name
, user
);
152 } else strcpy ( name
, user
);
154 if ( dotinuser
&& strstr ( name
, "_" )) {
155 str2
=( char *) subs ( name
, "_" , "." );
159 if ( DeniedReportLimit
) {
160 if ( strcmp ( ouser2
, name
) == 0 ) {
166 if ( count
>= DeniedReportLimit
)
170 if ( strlen ( BlockIt
) > 0 )
171 sprintf ( BlockImage
, "<a href= \" %s%s?url=%s \" ><img src= \" %s/sarg-squidguard-block.png \" border= \" 0 \" ></a> " , wwwDocumentRoot
, BlockIt
, url
, ImageFile
);
172 else BlockImage
[ 0 ]= '\0' ;
174 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
);
177 fputs ( "</table> \n " , fp_ou
);
180 fputs ( "</body></html> \n " , fp_ou
);