]>
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 static void show_ignored_dansguardian ( FILE * fp_ou
, int count
)
34 snprintf ( ignored
, sizeof ( ignored
), ngettext ( "%d more dansguardian entry not shown here…" , "%d more dansguardian entries not shown here…" , count
), count
);
35 fprintf ( fp_ou
, "<tr><td class= \" data \" ></td><td class= \" data \" ></td><td class= \" data \" ></td><td class= \" data2 more \" >%s</td><td class= \" data \" ></td></tr> \n " , ignored
);
38 void dansguardian_report ( void )
40 FILE * fp_in
= NULL
, * fp_ou
= NULL
;
44 char dansguardian_in
[ MAXLEN
];
57 struct getwordstruct gwarea
;
61 snprintf ( dansguardian_in
, sizeof ( dansguardian_in
), "%s/dansguardian.int_log" , tmp
);
62 if (! dansguardian_count
) {
63 if (! KeepTempLog
&& unlink ( dansguardian_in
))
64 debuga ( __FILE__
, __LINE__
, _ ( "Cannot delete \" %s \" : %s \n " ), dansguardian_in
, strerror ( errno
));
65 if ( debugz
>= LogLevel_Process
) debugaz ( __FILE__
, __LINE__
, _ ( "Dansguardian report not generated because it is empty \n " ));
69 sprintf ( report
, "%s/dansguardian.html" , outdirname
);
71 if (( fp_in
= MY_FOPEN ( dansguardian_in
, "r" ))== NULL
) {
72 debuga ( __FILE__
, __LINE__
, _ ( "Cannot open file \" %s \" : %s \n " ), dansguardian_in
, strerror ( errno
));
76 if (( fp_ou
= MY_FOPEN ( report
, "w" ))== NULL
) {
77 debuga ( __FILE__
, __LINE__
, _ ( "Cannot open file \" %s \" : %s \n " ), report
, strerror ( errno
));
81 write_html_header ( fp_ou
,( IndexTree
== INDEX_TREE_DATE
) ? 3 : 1 , _ ( "DansGuardian" ), HTML_JS_NONE
);
82 fputs ( "<tr><td class= \" header_c \" >" , fp_ou
);
83 fprintf ( fp_ou
, _ ( "Period: %s" ), period
. html
);
84 fputs ( "</td></tr> \n " , fp_ou
);
85 fprintf ( fp_ou
, "<tr><th class= \" header_c \" >%s</th></tr> \n " , _ ( "DansGuardian" ));
86 close_html_header ( fp_ou
);
88 fputs ( "<div class= \" report \" ><table cellpadding= \" 1 \" cellspacing= \" 2 \" > \n " , fp_ou
);
89 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><th class= \" header_l \" >%s</th></tr> \n " , _ ( "USERID" ), _ ( "IP/NAME" ), _ ( "DATE/TIME" ), _ ( "ACCESSED SITE" ), _ ( "CAUSE" ));
91 while ( fgets ( buf
, sizeof ( buf
), fp_in
)!= NULL
) {
92 getword_start (& gwarea
, buf
);
93 if ( getword ( user
, sizeof ( user
),& gwarea
, ' \t ' )< 0 || getword ( date2
, sizeof ( date2
),& gwarea
, ' \t ' )< 0 ||
94 getword ( hour
, sizeof ( hour
),& gwarea
, ' \t ' )< 0 || getword ( ip
, sizeof ( ip
),& gwarea
, ' \t ' )< 0 ) {
95 debuga ( __FILE__
, __LINE__
, _ ( "Invalid record in file \" %s \"\n " ), dansguardian_in
);
98 if ( getword_ptr ( buf
,& url
,& gwarea
, ' \t ' )< 0 ) {
99 debuga ( __FILE__
, __LINE__
, _ ( "Invalid url in file \" %s \"\n " ), dansguardian_in
);
102 if ( getword ( rule
, sizeof ( rule
),& gwarea
, ' \n ' )< 0 ) {
103 debuga ( __FILE__
, __LINE__
, _ ( "Invalid rule in file \" %s \"\n " ), dansguardian_in
);
110 memset ( date
, 0 , sizeof ( date
));
112 strncpy ( date
, date2
+ 6 , 2 );
114 strncat ( date
, date2
+ 4 , 2 );
116 strncat ( date
, date2
, 4 );
118 strncpy ( date
, date2
+ 4 , 2 );
120 strncat ( date
, date2
+ 6 , 2 );
122 strncat ( date
, date2
, 4 );
126 ip2name ( ip
, sizeof ( ip
));
133 if ( strcmp ( ouser
, user
) == 0 )
137 if ( strcmp ( oip
, ip
) == 0 )
143 user_find ( name
, sizeof ( name
), user
);
145 if ( DansGuardianReportLimit
) {
146 if ( strcmp ( ouser2
, name
) == 0 ) {
149 if ( count
> DansGuardianReportLimit
&& DansGuardianReportLimit
> 0 )
150 show_ignored_dansguardian ( fp_ou
, count
- DansGuardianReportLimit
);
154 if ( count
> DansGuardianReportLimit
)
158 fprintf ( fp_ou
, "<tr><td class= \" data2 \" >%s</td><td class= \" data2 \" >%s</td><td class= \" data2 \" >%s-%s</td><td class= \" data2 \" >" , name
, ip
, date
, hour
);
159 output_html_link ( fp_ou
, url
, 100 );
160 fprintf ( fp_ou
, "</td><td class= \" data2 \" >%s</td></tr> \n " , rule
);
162 if ( fclose ( fp_in
)== EOF
) {
163 debuga ( __FILE__
, __LINE__
, _ ( "Read error in \" %s \" : %s \n " ), dansguardian_in
, strerror ( errno
));
167 if ( count
> DansGuardianReportLimit
&& DansGuardianReportLimit
> 0 )
168 show_ignored_dansguardian ( fp_ou
, count
- DansGuardianReportLimit
);
170 fputs ( "</table></div> \n " , fp_ou
);
171 write_html_trailer ( fp_ou
);
172 if ( fclose ( fp_ou
)== EOF
) {
173 debuga ( __FILE__
, __LINE__
, _ ( "Write error in \" %s \" : %s \n " ), report
, strerror ( errno
));
177 if (! KeepTempLog
&& unlink ( dansguardian_in
)) {
178 debuga ( __FILE__
, __LINE__
, _ ( "Cannot delete \" %s \" : %s \n " ), dansguardian_in
, strerror ( errno
));