]>
git.ipfire.org Git - thirdparty/sarg.git/blob - squidguard_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 squidguard_report ( void )
32 FILE * fp_in
= NULL
, * fp_ou
= NULL
;
35 char squidguard_in
[ MAXLEN
];
50 struct getwordstruct gwarea
;
54 sprintf ( squidguard_in
, "%s/squidguard.log" , tmp
);
55 if (! squidguard_count
) {
56 unlink ( squidguard_in
);
60 sprintf ( per
, "%s/sarg-period" , dirname
);
61 sprintf ( report
, "%s/squidguard.html" , dirname
);
63 if (( fp_in
= fopen ( per
, "r" )) == 0 ) {
64 fprintf ( stderr
, "SARG: (squidguard) %s: %s \n " , text
[ 45 ], per
);
68 if (! fgets ( period
, sizeof ( period
), fp_in
)) {
69 fprintf ( stderr
, "SARG: (squidguard) read error in %s \n " , per
);
74 if (( fp_in
= fopen ( squidguard_in
, "r" ))== NULL
) {
75 fprintf ( stderr
, "SARG: (squidguard) %s: %s \n " , text
[ 8 ], squidguard_in
);
79 if (( fp_ou
= fopen ( report
, "w" ))== NULL
) {
80 fprintf ( stderr
, "SARG: (squidguard) %s: %s \n " , text
[ 8 ], report
);
84 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
);
86 fputs ( "</head> \n " , fp_ou
);
87 if ( strlen ( FontFace
) > 0 ) fprintf ( fp_ou
, "<font face=%s> \n " , FontFace
);
88 fprintf ( fp_ou
, "<body bgcolor=%s text=%s background='%s'> \n " , BgColor
, TxColor
, BgImage
);
89 write_logo_image ( fp_ou
);
91 if ( strcmp ( IndexTree
, "date" ) == 0 )
92 show_sarg ( fp_ou
, "../../.." );
94 show_sarg ( fp_ou
, ".." );
95 fputs ( "<div align= \" center \" ><table cellpadding= \" 0 \" cellspacing= \" 0 \" > \n " , fp_ou
);
96 fprintf ( fp_ou
, "<tr><th class= \" title \" >%s</th></tr> \n " , Title
);
98 fprintf ( fp_ou
, "<tr><td class= \" header \" >%s: %s</td></tr> \n " , text
[ 89 ], period
);
99 fprintf ( fp_ou
, "<tr><th class= \" header3 \" >%s</th></tr> \n " , text
[ 120 ]);
100 fputs ( "</table></div> \n " , fp_ou
);
102 fputs ( "<div align= \" center \" ><table cellpadding=1 cellspacing=2> \n " , fp_ou
);
103 fputs ( "<tr><td></td></tr> \n " , fp_ou
);
104 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
[ 121 ]);
106 while ( fgets ( buf
, sizeof ( buf
), fp_in
)!= NULL
) {
107 getword_start (& gwarea
, buf
);
108 if ( getword ( user
, sizeof ( user
),& gwarea
, ' \t ' )< 0 || getword ( data2
, sizeof ( data2
),& gwarea
, ' \t ' )< 0 ||
109 getword ( hora
, sizeof ( hora
),& gwarea
, ' \t ' )< 0 || getword ( ip
, sizeof ( ip
),& gwarea
, ' \t ' )< 0 ||
110 getword ( url
, sizeof ( url
),& gwarea
, ' \t ' )< 0 || getword ( rule
, sizeof ( rule
),& gwarea
, ' \n ' )< 0 ) {
111 printf ( "SARG: Maybe you have a broken record or garbage in your %s file. \n " , squidguard_in
);
119 if ( strncmp ( df
, "u" , 1 ) != 0 ) {
120 strncpy ( data
, data2
+ 6 , 2 );
122 strncat ( data
, data2
+ 4 , 2 );
124 strncat ( data
, data2
, 4 );
126 strncpy ( data
, data2
+ 4 , 2 );
128 strncat ( data
, data2
+ 6 , 2 );
130 strncat ( data
, data2
, 4 );
133 if (( str
=( char *) strstr ( user
, "_" )) != ( char *) NULL
) {
134 if (( str
=( char *) strstr ( str
+ 1 , "_" )) != ( char *) NULL
)
139 ip2name ( ip
, sizeof ( ip
));
146 if ( strcmp ( ouser
, user
) == 0 )
150 if ( strcmp ( oip
, ip
) == 0 )
156 user_find ( name
, sizeof ( name
), user
);
158 if ( dotinuser
&& strchr ( name
, '_' )) {
159 subs ( name
, sizeof ( name
), "_" , "." );
162 if ( SquidGuardReportLimit
) {
163 if ( strcmp ( ouser2
, name
) == 0 ) {
169 if ( count
>= SquidGuardReportLimit
)
173 fprintf ( fp_ou
, "<tr><td class= \" data2 \" >%s</td><td class= \" data2 \" >%s</td><td class= \" data2 \" >%s-%s</td><td class= \" data2 \" ><a href= \" http://%s \" >%s</a></td><td class= \" data2 \" >%s</td></th> \n " , name
, ip
, data
, hora
, url
, url
, rule
);
176 fputs ( "</table> \n " , fp_ou
);
180 fputs ( "</body> \n </html> \n " , fp_ou
);
185 unlink ( squidguard_in
);