]>
git.ipfire.org Git - thirdparty/sarg.git/blob - dansguardian_report.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 dansguardian_report ( void )
32 FILE * fp_in
= NULL
, * fp_ou
= NULL
;
35 char dansguardian_in
[ MAXLEN
];
53 sprintf ( dansguardian_in
, "%s/dansguardian.log" , tmp
);
54 if (! dansguardian_count
) {
55 unlink ( dansguardian_in
);
59 sprintf ( per
, "%s/sarg-period" , dirname
);
60 sprintf ( report
, "%s/dansguardian.html" , dirname
);
62 if (( fp_in
= fopen ( per
, "r" )) == 0 ) {
63 fprintf ( stderr
, "SARG: (dansguardian_report) %s: %s \n " , text
[ 45 ], per
);
67 fgets ( period
, sizeof ( period
), fp_in
);
70 #if defined(HAVE_FOPEN64)
71 if (( fp_in
= fopen64 ( dansguardian_in
, "r" ))== NULL
) {
73 if (( fp_in
= fopen ( dansguardian_in
, "r" ))== NULL
) {
75 fprintf ( stderr
, "SARG: (dansguardian_report) %s: %s \n " , text
[ 8 ], dansguardian_in
);
79 #if defined(HAVE_FOPEN64)
80 if (( fp_ou
= fopen64 ( report
, "w" ))== NULL
) {
82 if (( fp_ou
= fopen ( report
, "w" ))== NULL
) {
84 fprintf ( stderr
, "SARG: (dansguardian_report) %s: %s \n " , text
[ 8 ], report
);
88 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
);
90 fputs ( "</head> \n " , fp_ou
);
91 if ( strlen ( FontFace
) > 0 ) fprintf ( fp_ou
, "<font face=%s> \n " , FontFace
);
92 fprintf ( fp_ou
, "<body bgcolor=%s text=%s background='%s'> \n " , BgColor
, TxColor
, BgImage
);
93 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
);
95 if ( strcmp ( IndexTree
, "date" ) == 0 )
96 show_sarg ( fp_ou
, "../../.." );
98 show_sarg ( fp_ou
, ".." );
99 fputs ( "<center><table cellpadding=0 cellspacing=0> \n " , fp_ou
);
100 fprintf ( fp_ou
, "<tr><th class= \" title \" >%s</th></tr> \n " , Title
);
102 fprintf ( fp_ou
, "<tr><td class= \" header \" >%s: %s</td></tr> \n " , text
[ 89 ], period
);
103 fprintf ( fp_ou
, "<tr><th class= \" header3 \" >%s</th></tr> \n " , text
[ 128 ]);
104 fputs ( "</table></center> \n " , fp_ou
);
106 fputs ( "<center><table cellpadding=1 cellspacing=2> \n " , fp_ou
);
107 fputs ( "<tr><td></td></tr> \n " , fp_ou
);
108 fprintf ( fp_ou
, "<tr><th class= \" header \" >%s</th><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 ], text
[ 129 ]);
110 while ( fgets ( buf
, sizeof ( buf
), fp_in
)!= NULL
) {
111 if ( getword ( user
, sizeof ( user
), buf
, ' ' )< 0 || getword ( date2
, sizeof ( date2
), buf
, ' ' )< 0 ||
112 getword ( hour
, sizeof ( hour
), buf
, ' ' )< 0 || getword ( ip
, sizeof ( ip
), buf
, ' ' )< 0 ||
113 getword ( url
, sizeof ( url
), buf
, ' ' )< 0 || getword ( rule
, sizeof ( rule
), buf
, ' \n ' )< 0 ) {
114 printf ( "SARG: Maybe you have a broken record or garbage in your %s file. \n " , dansguardian_in
);
118 if ( strcmp ( UserIp
, "yes" ) == 0 )
122 if ( strncmp ( df
, "u" , 1 ) != 0 ) {
123 strncpy ( date
, date2
+ 6 , 2 );
125 strncat ( date
, date2
+ 4 , 2 );
127 strncat ( date
, date2
, 4 );
129 strncpy ( date
, date2
+ 4 , 2 );
131 strncat ( date
, date2
+ 6 , 2 );
133 strncat ( date
, date2
, 4 );
136 if (( str
=( char *) strstr ( user
, "_" )) != ( char *) NULL
) {
137 if (( str
=( char *) strstr ( str
+ 1 , "_" )) != ( char *) NULL
)
141 if ( strcmp ( Ip2Name
, "yes" ) == 0 )
142 ip2name ( ip
, sizeof ( ip
));
149 if ( strcmp ( ouser
, user
) == 0 )
153 if ( strcmp ( oip
, ip
) == 0 )
159 if ( UserTabFile
[ 0 ] != '\0' ) {
160 sprintf ( warea
, ":%s:" , user
);
161 if (( str
=( char *) strstr ( userfile
, warea
)) != ( char *) NULL
) {
163 str2
=( char *) strstr ( str
+ 1 , ":" );
166 while ( str2
[ z1
] != ':' ) {
170 } else strcpy ( name
, user
);
171 } else strcpy ( name
, user
);
173 if ( dotinuser
&& strstr ( name
, "_" )) {
174 str2
=( char *) subs ( name
, "_" , "." );
178 if ( DansGuardianReportLimit
) {
179 if ( strcmp ( ouser2
, name
) == 0 ) {
185 if ( count
>= DansGuardianReportLimit
)
189 fprintf ( fp_ou
, "<tr><td class= \" data2 \" nospaw>%s</td><td class= \" data2 \" nospaw>%s</td><td class= \" data2 \" nospaw>%s-%s</td><td class= \" data2 \" nospaw><a href= \" http://%s \" >%s</a></td><td class= \" data2 \" nospaw>%s</td></tr> \n " , name
, ip
, date
, hour
, url
, url
, rule
);
192 fputs ( "</table> \n " , fp_ou
);
196 fputs ( "</body> \n </html> \n " , fp_ou
);
201 unlink ( dansguardian_in
);