]>
git.ipfire.org Git - thirdparty/sarg.git/blob - datafile.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 saverecs ( char * dirname
, char * user
, long long int nacc
, char * url
, long long int nbytes
, char * ip
, char * hora
, char * dia
, long long int nelap
, long long int incache
, long long int oucache
);
32 void data_file ( char * tmp
)
37 char accdia
[ 11 ], acchora
[ 9 ], accuser
[ MAXLEN
], accip
[ MAXLEN
], accurl
[ MAXLEN
];
38 char oldaccdia
[ 11 ], oldacchora
[ 9 ], oldaccip
[ MAXLEN
];
39 char dirname
[ MAXLEN
], wdirname
[ MAXLEN
], oldurl
[ MAXLEN
], oldaccuser
[ MAXLEN
];
40 char olduser
[ MAXLEN
], oldmsg
[ 50 ], acccode
[ 50 ], oldacccode
[ 50 ];
41 char ipantes
[ MAXLEN
], nameantes
[ MAXLEN
];
42 char accsmart
[ MAXLEN
];
47 struct dirent
* direntp
;
48 long long int nbytes
= 0 ;
49 long long int nelap
= 0 ;
51 long long int rtotal
= 0 ;
52 long long int incache
= 0 ;
53 long long int oucache
= 0 ;
54 long long int accbytes
;
55 long long int accelap
;
56 struct getwordstruct gwarea
;
62 strncat ( tmp
, "/sarg" , 5 );
65 while ( ( direntp
= readdir ( dirp
)) != NULL
) {
66 if ( strstr ( direntp
-> d_name
, ".log" ) == 0 )
68 if ( snprintf ( tmp3
, sizeof ( tmp3
), "%s/%s" , tmp
, direntp
-> d_name
)>= sizeof ( tmp3
)) {
69 fprintf ( stderr
, "SARG: (datafile) directory path too long: %s/%s \n " , tmp
, direntp
-> d_name
);
73 if (( fp_in
= MY_FOPEN ( tmp3
, "r" ))== NULL
){
74 fprintf ( stderr
, "SARG: (datafile) %s: %s \n " , text
[ 45 ], tmp
);
77 strcpy ( wdname
, direntp
-> d_name
);
78 str
= strchr ( wdname
, '.' );
83 while ( fgets ( buf
, sizeof ( buf
), fp_in
)!= NULL
) {
84 getword_start (& gwarea
, buf
);
85 if ( getword ( accdia
, sizeof ( accdia
),& gwarea
, ' ' )< 0 || getword ( acchora
, sizeof ( acchora
),& gwarea
, ' ' )< 0 ||
86 getword ( accuser
, sizeof ( accuser
),& gwarea
, ' ' )< 0 || getword ( accip
, sizeof ( accip
),& gwarea
, ' ' )< 0 ||
87 getword ( accurl
, sizeof ( accurl
),& gwarea
, ' ' )< 0 || getword_atoll (& accbytes
,& gwarea
, ' ' )< 0 ||
88 getword ( acccode
, sizeof ( acccode
),& gwarea
, ' ' )< 0 || getword_atoll (& accelap
,& gwarea
, ' ' )< 0 ||
89 getword_skip ( 20000 ,& gwarea
, ' ' )< 0 || getword ( accsmart
, sizeof ( accsmart
),& gwarea
, '"' )< 0 ) {
90 printf ( "SARG: Maybe you have a broken record or garbage in your %s file. \n " , tmp3
);
95 if ( strcmp ( accip
, ipantes
) != 0 ) {
96 strcpy ( ipantes
, accip
);
97 ip2name ( accip
, sizeof ( accip
));
98 strcpy ( nameantes
, accip
);
100 else strcpy ( accip
, nameantes
);
104 strcpy ( oldurl
, accurl
);
105 strcpy ( oldacccode
, acccode
);
106 strcpy ( oldaccuser
, accuser
);
107 strcpy ( oldaccip
, accip
);
108 strcpy ( oldaccdia
, accdia
);
109 strcpy ( oldacchora
, acchora
);
113 if ( strcmp ( oldurl
, accurl
) != 0 || strcmp ( oldaccuser
, accuser
) != 0 ){
115 if ( strstr ( oldacccode
, "DENIED" ) != 0 ) strcpy ( oldmsg
, text
[ 46 ]);
116 gravatmp ( oldaccuser
, oldurl
, nacc
, nbytes
, oldmsg
, nelap
, indexonly
, incache
, oucache
);
117 strcpy ( wdirname
, dirname
);
118 saverecs ( wdirname
, oldaccuser
, nacc
, oldurl
, nbytes
, oldaccip
, oldacchora
, oldaccdia
, nelap
, incache
, oucache
);
124 if ( strcmp ( oldaccuser
, accuser
) != 0 ) ind2
= 0 ;
131 strcpy ( crc2
, acccode
);
132 str
= strchr ( crc2
, '/' );
135 if ( strstr ( crc2
, "MISS" ) != 0 ) oucache
+= accbytes
;
136 else incache
+= accbytes
;
138 strcpy ( oldurl
, accurl
);
139 strcpy ( oldaccuser
, accuser
);
140 strcpy ( oldacccode
, acccode
);
141 strcpy ( oldaccip
, accip
);
142 strcpy ( oldaccdia
, accdia
);
143 strcpy ( oldacchora
, acchora
);
149 ( void ) closedir ( dirp
);
151 debuga ( "Datafile %s successfully" , DataFile
);
154 void saverecs ( char * dirname
, char * user
, long long int nacc
, char * url
, long long int nbytes
, char * ip
, char * hora
, char * dia
, long long int nelap
, long long int incache
, long long int oucache
)
159 if (( fp_ou
= MY_FOPEN ( DataFile
, "a" ))== NULL
){
160 fprintf ( stderr
, "SARG: (datafile) %s: %s \n " , text
[ 45 ], DataFile
);
164 my_lltoa ( nacc
, val1
, 0 );
165 my_lltoa ( nbytes
, val2
, 0 );
166 my_lltoa ( nelap
, val3
, 0 );
167 my_lltoa ( incache
, val4
, 0 );
168 my_lltoa ( oucache
, val5
, 0 );
170 if ( strstr ( DataFileFields
, "user" ) != 0 ) {
172 strncat ( reg
, DataFileDelimiter
, 1 );
174 if ( strstr ( DataFileFields
, "date" ) != 0 ) {
175 strncat ( reg
, dia
, strlen ( dia
));
176 strncat ( reg
, DataFileDelimiter
, 1 );
178 if ( strstr ( DataFileFields
, "time" ) != 0 ) {
179 strncat ( reg
, hora
, strlen ( hora
));
180 strncat ( reg
, DataFileDelimiter
, 1 );
182 if ( strstr ( DataFileFields
, "url" ) != 0 ) {
184 if ( strcmp ( DataFileUrl
, "ip" ) == 0 ) name2ip ( name
);
185 strncat ( reg
, name
, strlen ( name
));
186 strncat ( reg
, DataFileDelimiter
, 1 );
188 if ( strstr ( DataFileFields
, "connect" ) != 0 ) {
189 strncat ( reg
, val1
, strlen ( val1
));
190 strncat ( reg
, DataFileDelimiter
, 1 );
192 if ( strstr ( DataFileFields
, "bytes" ) != 0 ) {
193 strncat ( reg
, val2
, strlen ( val2
));
194 strncat ( reg
, DataFileDelimiter
, 1 );
196 if ( strstr ( DataFileFields
, "in_cache" ) != 0 ) {
197 strncat ( reg
, val4
, strlen ( val4
));
198 strncat ( reg
, DataFileDelimiter
, 1 );
200 if ( strstr ( DataFileFields
, "out_cache" ) != 0 ) {
201 strncat ( reg
, val5
, strlen ( val5
));
202 strncat ( reg
, DataFileDelimiter
, 1 );
204 if ( strstr ( DataFileFields
, "elapsed" ) != 0 ) {
205 strncat ( reg
, val3
, strlen ( val3
));
206 strncat ( reg
, DataFileDelimiter
, 1 );
209 reg
[ strlen ( reg
)- 1 ]= ' \n ' ;