]>
git.ipfire.org Git - thirdparty/sarg.git/blob - topsites.c
906e028e7a3963c03ea94a067fc634f20dd51de4
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"
43 char general2
[ MAXLEN
];
44 char general3
[ MAXLEN
];
54 long long int tnacc
= 0 ;
55 long long int tnbytes
= 0 ;
56 long long int tntime
= 0 ;
57 long long int twork1
= 0 , twork2
= 0 , twork3
= 0 ;
60 struct getwordstruct gwarea
;
65 sprintf ( general
, "%s/sarg-general" , dirname
);
66 sprintf ( sites
, "%s/sarg-sites" , dirname
);
67 sprintf ( general2
, "%s/sarg-general2" , dirname
);
68 sprintf ( general3
, "%s/sarg-general3" , dirname
);
69 sprintf ( per
, "%s/sarg-period" , dirname
);
71 if (( ReportType
& REPORT_TYPE_TOPUSERS
) == 0 )
72 sprintf ( report
, "%s/index.html" , dirname
);
74 sprintf ( report
, "%s/topsites.html" , dirname
);
76 if (( fp_in
= fopen ( per
, "r" )) == 0 ) {
77 fprintf ( stderr
, "SARG: (topuser) %s: %s \n " , text
[ 45 ], per
);
81 if (! fgets ( period
, sizeof ( period
), fp_in
)) {
82 fprintf ( stderr
, "SARG: (topuser) read error in %s \n " , per
);
87 sprintf ( csort
, "sort -k 4,4 -o \" %s \" \" %s \" " , general2
, general
);
88 cstatus
= system ( csort
);
89 if (! WIFEXITED ( cstatus
) || WEXITSTATUS ( cstatus
)) {
90 fprintf ( stderr
, "SARG: sort command return status %d \n " , WEXITSTATUS ( cstatus
));
91 fprintf ( stderr
, "SARG: sort command: %s \n " , csort
);
95 if (( fp_in
= fopen ( general2
, "r" ))== NULL
) {
96 fprintf ( stderr
, "SARG: (topsite) %s: %s \n " , text
[ 8 ], general2
);
97 fprintf ( stderr
, "SARG: sort command: %s \n " , csort
);
101 if (( fp_ou
= fopen ( general3
, "w" ))== NULL
) {
102 fprintf ( stderr
, "SARG: (topsite) %s: %s \n " , text
[ 8 ], general3
);
106 while ( fgets ( buf
, sizeof ( buf
), fp_in
)!= NULL
) {
107 getword_start (& gwarea
, buf
);
108 if ( getword ( url
, sizeof ( url
),& gwarea
, ' \t ' )< 0 ) {
109 printf ( "SARG: Maybe you have an invalid user in your %s file of the topsites. \n " , general2
);
112 if ( strcmp ( url
, "TOTAL" ) == 0 ) {
113 if ( getword ( ttnacc
, sizeof ( ttnacc
),& gwarea
, ' \t ' )< 0 ) {
114 printf ( "SARG: Maybe you have an invalid total number of access in your %s file of the topsites. \n " , general2
);
117 if ( getword ( ttnbytes
, sizeof ( ttnbytes
),& gwarea
, ' \t ' )< 0 ) {
118 printf ( "SARG: Maybe you have an invalid total number of bytes in your %s file of the topsites. \n " , general2
);
121 if ( getword ( ttntime
, sizeof ( ttntime
),& gwarea
, ' \t ' )< 0 ) {
122 printf ( "SARG: Maybe you have an invalid total time in your %s file of the topsites. \n " , general2
);
127 if ( getword_atoll (& nacc
,& gwarea
, ' \t ' )< 0 ) {
128 printf ( "SARG: Maybe you have an invalid number of access in your %s file of the topsites. \n " , general2
);
131 if ( getword_atoll (& nbytes
,& gwarea
, ' \t ' )< 0 ) {
132 printf ( "SARG: Maybe you have an invalid number of bytes in your %s file of the topsites. \n " , general2
);
135 if ( getword ( url
, sizeof ( url
),& gwarea
, ' \t ' )< 0 ) {
136 printf ( "SARG: Maybe you have an invalid url in your %s file of the topsites. \n " , general2
);
139 if ( getword ( ntemp
, sizeof ( ntemp
),& gwarea
, ' \t ' )< 0 ) {
140 printf ( "SARG: Maybe you have a broken record or garbage in column 5 in your %s file of the topsites. \n " , general2
);
143 if ( getword ( ntemp
, sizeof ( ntemp
),& gwarea
, ' \t ' )< 0 ) {
144 printf ( "SARG: Maybe you have a broken record or garbage in column 6 in your %s file of the topsites. \n " , general2
);
147 if ( getword ( ntemp
, sizeof ( ntemp
),& gwarea
, ' \t ' )< 0 ) {
148 printf ( "SARG: Maybe you have a broken record or garbage in column 7 in your %s file of the topsites. \n " , general2
);
151 if ( getword_atoll (& ntime
,& gwarea
, ' \t ' )< 0 ) {
152 printf ( "SARG: Maybe you have a broken record or garbage in column 8 in your %s file of the topsites. \n " , general2
);
161 if ( strcmp ( url
, ourl
) != 0 ) {
162 my_lltoa ( tnacc
, val1
, 15 );
163 my_lltoa ( tnbytes
, val2
, 15 );
164 my_lltoa ( tntime
, val3
, 15 );
165 fprintf ( fp_ou
, "%s \t %s \t %s \t %s \n " , val1
, val2
, val3
, ourl
);
177 my_lltoa ( tnacc
, val1
, 15 );
178 my_lltoa ( tnbytes
, val2
, 15 );
179 my_lltoa ( tntime
, val3
, 15 );
180 fprintf ( fp_ou
, "%s \t %s \t %s \t %s \n " , val1
, val2
, val3
, ourl
);
186 strlow ( TopsitesSortField
);
187 strlow ( TopsitesSortType
);
189 if ( strcmp ( TopsitesSortField
, "connect" ) == 0 )
191 if ( strcmp ( TopsitesSortField
, "bytes" ) == 0 )
193 if ( strcmp ( TopsitesSortType
, "a" ) == 0 )
195 if ( strcmp ( TopsitesSortType
, "d" ) == 0 )
198 sprintf ( csort
, "sort %s -k %s -o \" %s \" \" %s \" " , sortt
, sortf
, sites
, general3
);
199 cstatus
= system ( csort
);
200 if (! WIFEXITED ( cstatus
) || WEXITSTATUS ( cstatus
)) {
201 fprintf ( stderr
, "SARG: sort command return status %d \n " , WEXITSTATUS ( cstatus
));
202 fprintf ( stderr
, "SARG: sort command: %s \n " , csort
);
205 if (( fp_in
= fopen ( sites
, "r" ))== NULL
) {
206 fprintf ( stderr
, "SARG: (topsite) %s: %s \n " , text
[ 8 ], sites
);
207 fprintf ( stderr
, "SARG: sort command: %s \n " , csort
);
214 if (( fp_ou
= fopen ( report
, "w" ))== NULL
) {
215 fprintf ( stderr
, "SARG: (topsite) %s: %s \n " , text
[ 8 ], report
);
221 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
);
223 fputs ( "</head> \n " , fp_ou
);
224 fprintf ( fp_ou
, "<body bgcolor= \" %s \" text= \" %s \" background= \" %s \" > \n " , BgColor
, TxColor
, BgImage
);
225 write_logo_image ( fp_ou
);
227 if ( IndexTree
== INDEX_TREE_DATE
)
228 show_sarg ( fp_ou
, "../../.." );
230 show_sarg ( fp_ou
, ".." );
232 fputs ( "<div align= \" center \" ><table cellpadding= \" 0 \" cellspacing= \" 0 \" > \n " , fp_ou
);
233 fprintf ( fp_ou
, "<tr><th class= \" title \" >%s</th></tr> \n " , Title
);
235 fprintf ( fp_ou
, "<tr><td class= \" header_c \" >%s: %s</td></tr> \n " , text
[ 89 ], period
);
236 fprintf ( fp_ou
, "<tr><th class= \" header_c \" >%s %s %s</th></tr> \n " , text
[ 83 ], TopSitesNum
, text
[ 84 ]);
237 fputs ( "</table></div> \n " , fp_ou
);
239 fputs ( "<div align= \" center \" ><table cellpadding= \" 1 \" cellspacing= \" 2 \" > \n " , fp_ou
);
240 fputs ( "<tr><td></td></tr> \n " , fp_ou
);
241 fprintf ( fp_ou
, "<tr><th class= \" header_l \" >%s</th><th class= \" header_l \" >%s</th> \
242 <th class= \" header_l \" >%s</th><th class= \" header_l \" >%s</th> \
243 <th class= \" header_l \" >%s</th></tr> \n " , \
244 text
[ 100 ], text
[ 91 ], text
[ 92 ], text
[ 93 ], text
[ 99 ]);
249 while ( fgets ( buf
, sizeof ( buf
), fp_in
)!= NULL
) {
250 if ( regs
> atoi ( TopSitesNum
))
252 getword_start (& gwarea
, buf
);
253 if ( getword_atoll (& nacc
,& gwarea
, ' \t ' )< 0 ) {
254 printf ( "SARG: Maybe you have a broken record or garbage in your %s file. \n " , sites
);
257 if ( nacc
== 0 ) continue ;
258 if ( getword_atoll (& nbytes
,& gwarea
, ' \t ' )< 0 ||
259 getword_atoll (& ntime
,& gwarea
, ' \t ' )< 0 || getword ( url
, sizeof ( url
),& gwarea
, ' \t ' )< 0 ) {
260 printf ( "SARG: Maybe you have a broken record or garbage in your %s file. \n " , sites
);
268 strcpy ( wwork1
, fixnum ( twork1
, 1 ));
269 strcpy ( wwork2
, fixnum ( twork2
, 1 ));
270 strcpy ( wwork3
, fixtime ( twork3
));
272 if ( BlockIt
[ 0 ] != '\0' )
273 sprintf ( BlockImage
, "<a href= \" %s%s?url=%s \" ><img src= \" ../images/sarg-squidguard-block.png \" border= \" 0 \" ></a> " , wwwDocumentRoot
, BlockIt
, url
);
274 else BlockImage
[ 0 ]= '\0' ;
277 fprintf ( fp_ou
, "<tr><td class= \" data \" >%d</td><td class= \" data2 \" >%s<a href= \" http://%s \" ><font class= \" link \" >%s</font></a></td><td class= \" data \" >%s</td><td class= \" data \" >%s</td><td class= \" data \" >%s</td></tr> \n " , regs
, BlockImage
, url
, url
, wwork1
, wwork2
, wwork3
);
282 fputs ( "</table> \n </div> \n " , fp_ou
);
286 fputs ( "</body> \n </html> \n " , fp_ou
);