]>
git.ipfire.org Git - thirdparty/sarg.git/blob - dansguardian_report.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 dansguardian_report ( void )
33 FILE * fp_in
= NULL
, * fp_ou
= NULL
;
36 char dansguardian_in
[ MAXLEN
];
51 struct getwordstruct gwarea
;
55 sprintf ( dansguardian_in
, "%s/dansguardian.log" , tmp
);
56 if (! dansguardian_count
) {
57 unlink ( dansguardian_in
);
61 sprintf ( per
, "%s/sarg-period" , dirname
);
62 sprintf ( report
, "%s/dansguardian.html" , dirname
);
64 if (( fp_in
= fopen ( per
, "r" )) == 0 ) {
65 fprintf ( stderr
, "SARG: (dansguardian_report) %s: %s \n " , text
[ 45 ], per
);
69 if (! fgets ( period
, sizeof ( period
), fp_in
)) {
70 fprintf ( stderr
, "SARG: (dansguardian_report) read error in %s \n " , per
);
75 if (( fp_in
= MY_FOPEN ( dansguardian_in
, "r" ))== NULL
) {
76 fprintf ( stderr
, "SARG: (dansguardian_report) %s: %s \n " , text
[ 8 ], dansguardian_in
);
80 if (( fp_ou
= MY_FOPEN ( report
, "w" ))== NULL
) {
81 fprintf ( stderr
, "SARG: (dansguardian_report) %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 if ( strlen ( FontFace
) > 0 ) fprintf ( fp_ou
, "<font face=%s> \n " , FontFace
);
89 fprintf ( fp_ou
, "<body bgcolor=%s text=%s background='%s'> \n " , BgColor
, TxColor
, BgImage
);
90 write_logo_image ( fp_ou
);
92 if ( strcmp ( IndexTree
, "date" ) == 0 )
93 show_sarg ( fp_ou
, "../../.." );
95 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</th></tr> \n " , Title
);
99 fprintf ( fp_ou
, "<tr><td class= \" header \" >%s: %s</td></tr> \n " , text
[ 89 ], period
);
100 fprintf ( fp_ou
, "<tr><th class= \" header3 \" >%s</th></tr> \n " , text
[ 128 ]);
101 fputs ( "</table></div> \n " , fp_ou
);
103 fputs ( "<div align= \" center \" ><table cellpadding= \" 1 \" cellspacing= \" 2 \" > \n " , fp_ou
);
104 fputs ( "<tr><td></td></tr> \n " , fp_ou
);
105 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 ]);
107 while ( fgets ( buf
, sizeof ( buf
), fp_in
)!= NULL
) {
108 getword_start (& gwarea
, buf
);
109 if ( getword ( user
, sizeof ( user
),& gwarea
, ' \t ' )< 0 || getword ( date2
, sizeof ( date2
),& gwarea
, ' \t ' )< 0 ||
110 getword ( hour
, sizeof ( hour
),& gwarea
, ' \t ' )< 0 || getword ( ip
, sizeof ( ip
),& gwarea
, ' \t ' )< 0 ||
111 getword ( url
, sizeof ( url
),& gwarea
, ' \t ' )< 0 || getword ( rule
, sizeof ( rule
),& gwarea
, ' \n ' )< 0 ) {
112 printf ( "SARG: Maybe you have a broken record or garbage in your %s file. \n " , dansguardian_in
);
120 if ( strncmp ( df
, "u" , 1 ) != 0 ) {
121 strncpy ( date
, date2
+ 6 , 2 );
123 strncat ( date
, date2
+ 4 , 2 );
125 strncat ( date
, date2
, 4 );
127 strncpy ( date
, date2
+ 4 , 2 );
129 strncat ( date
, date2
+ 6 , 2 );
131 strncat ( date
, date2
, 4 );
134 if (( str
=( char *) strstr ( user
, "_" )) != ( char *) NULL
) {
135 if (( str
=( char *) strstr ( str
+ 1 , "_" )) != ( char *) NULL
)
140 ip2name ( ip
, sizeof ( ip
));
147 if ( strcmp ( ouser
, user
) == 0 )
151 if ( strcmp ( oip
, ip
) == 0 )
157 get_usertab_name ( user
, name
, sizeof ( name
));
159 if ( dotinuser
&& strchr ( name
, '_' )) {
160 subs ( name
, sizeof ( name
), "_" , "." );
163 if ( DansGuardianReportLimit
) {
164 if ( strcmp ( ouser2
, name
) == 0 ) {
170 if ( count
>= DansGuardianReportLimit
)
174 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
);
177 fputs ( "</table> \n " , fp_ou
);
181 fputs ( "</body> \n </html> \n " , fp_ou
);
186 unlink ( dansguardian_in
);