sarg
2.4.0
About: SARG ia a Squid Analysis Report Generator. Fossies Dox: sarg-2.4.0.tar.gz ("unofficial" and yet experimental doxygen-generated source code documentation) 
|
Go to the documentation of this file.
62 if ((fp_ou=fopen(tusr,
"w"))==NULL) {
63 debuga(__FILE__,__LINE__,
_(
"Cannot open file \"%s\": %s\n"),tusr,strerror(errno));
67 if (fclose(fp_ou)==EOF) {
68 debuga(__FILE__,__LINE__,
_(
"Write error in \"%s\": %s\n"),tusr,strerror(errno));
87 long long int elap, incac, oucac;
90 double inperc=0.00, ouperc=0.00;
108 if ((fp_top3=fopen(top3,
"w"))==NULL) {
109 debuga(__FILE__,__LINE__,
_(
"Cannot open file \"%s\": %s\n"),top3,strerror(errno));
113 snprintf(title,
sizeof(title),
_(
"SARG report for %s"),
period.
text);
115 fputs(
"<tr><td class=\"header_c\">",fp_top3);
117 fputs(
"</td></tr>\n",fp_top3);
119 fputs(
"<tr><td class=\"header_c\">",fp_top3);
121 fputs(
"</td></tr>\n",fp_top3);
122 fprintf(fp_top3,
"<tr><th class=\"header_c\">%s</th></tr>\n",
_(
"Top users"));
127 fprintf(fp_top3,
"<tr><th class=\"header_c\">%s</th></tr>\n",
_(
"Table of content"));
132 fputs(
"<div class=\"report\"><table cellpadding=\"1\" cellspacing=\"2\">\n",fp_top3);
135 if (
dansguardian_count) fprintf(fp_top3,
"<tr><td class=\"link\" colspan=\"0\"><a href=\"dansguardian.html\">%s</a></td></tr>\n",
_(
"DansGuardian"));
136 if (
redirector_count) fprintf(fp_top3,
"<tr><td class=\"link\" colspan=\"0\"><a href=\"redirector.html\">%s</a></td></tr>\n",
_(
"Redirector"));
137 if (
is_download()) fprintf(fp_top3,
"<tr><td class=\"link\" colspan=\"0\"><a href=\"download.html\">%s</a></td></tr>\n",
_(
"Downloads"));
138 if (
is_denied()) fprintf(fp_top3,
"<tr><td class=\"link\" colspan=\"0\"><a href=\"denied.html\">%s</a></td></tr>\n",
_(
"Denied accesses"));
139 if (
is_authfail()) fprintf(fp_top3,
"<tr><td class=\"link\" colspan=\"0\"><a href=\"authfail.html\">%s</a></td></tr>\n",
_(
"Authentication Failures"));
140 if (
smartfilter) fprintf(fp_top3,
"<tr><td class=\"link\" colspan=\"0\"><a href=\"smartfilter.html\">%s</a></td></tr>\n",
_(
"SmartFilter"));
141 if (
useragent_count) fprintf(fp_top3,
"<tr><td class=\"link\" colspan=\"0\"><a href=\"useragent.html\">%s</a></td></tr>\n",
_(
"Useragent"));
142 fputs(
"<tr><td></td></tr>\n</table></div>\n",fp_top3);
146 fputs(
"</body>\n</html>\n",fp_top3);
147 if (fclose (fp_top3)==EOF) {
148 debuga(__FILE__,__LINE__,
_(
"Write error in \"%s\": %s\n"),top3,strerror(errno));
155 fputs(
"<div class=\"report\"><table cellpadding=\"1\" cellspacing=\"2\"",fp_top3);
157 fputs(
" class=\"sortable\"",fp_top3);
158 fputs(
">\n<thead><tr>",fp_top3);
161 fprintf(fp_top3,
"<th class=\"header_l\">%s</th>",
_(
"NUM"));
163 fputs(
"<th class=\"header_l",fp_top3);
164 if (
SortTableJs[0]) fputs(
" sorttable_nosort",fp_top3);
165 fputs(
"\"></th>",fp_top3);
168 fputs(
"<th class=\"header_l",fp_top3);
169 if (
SortTableJs[0]) fputs(
" sorttable_alpha",fp_top3);
170 fprintf(fp_top3,
"\">%s</th>",
_(
"USERID"));
173 fputs(
"<th class=\"header_l",fp_top3);
174 if (
SortTableJs[0]) fputs(
" sorttable_alpha",fp_top3);
175 fprintf(fp_top3,
"\">%s</th>",
_(
"USERIP"));
178 fprintf(fp_top3,
"<th class=\"header_l\">%s</th>",
_(
"CONNECT"));
180 fprintf(fp_top3,
"<th class=\"header_l\">%s</th>",
_(
"BYTES"));
182 fprintf(fp_top3,
"<th class=\"header_l\">%%%s</th>",
_(
"BYTES"));
184 fprintf(fp_top3,
"<th class=\"header_c\" colspan=\"2\">%s</th><th style=\"display:none;\"></th>",
_(
"IN-CACHE-OUT"));
186 fprintf(fp_top3,
"<th class=\"header_l\">%s</th>",
_(
"ELAPSED TIME"));
188 fprintf(fp_top3,
"<th class=\"header_l\">%s</th>",
_(
"MILLISEC"));
190 fprintf(fp_top3,
"<th class=\"header_l\">%%%s</th>",
pgettext(
"duration",
"TIME"));
192 fputs(
"</tr></thead>\n",fp_top3);
197 debuga(__FILE__,__LINE__,
_(
"Not enough memory to read file \"%s\"\n"),ListFile);
203 if (
getword(user,
sizeof(user),&gwarea,
'\t')<0) {
204 debuga(__FILE__,__LINE__,
_(
"Invalid user in file \"%s\"\n"),ListFile);
208 debuga(__FILE__,__LINE__,
_(
"Invalid number of bytes in file \"%s\"\n"),ListFile);
212 debuga(__FILE__,__LINE__,
_(
"Invalid number of accesses in file \"%s\"\n"),ListFile);
216 debuga(__FILE__,__LINE__,
_(
"Invalid elapsed time in file \"%s\"\n"),ListFile);
220 debuga(__FILE__,__LINE__,
_(
"Invalid in-cache size in file \"%s\"\n"),ListFile);
224 debuga(__FILE__,__LINE__,
_(
"Invalid out-of-cache size in file \"%s\"\n"),ListFile);
234 debuga(__FILE__,__LINE__,
_(
"Unknown user ID %s in file \"%s\"\n"),user,ListFile);
239 fputs(
"<tr>",fp_top3);
243 fprintf(fp_top3,
"<td class=\"data\">%d</td>",posicao);
247 fputs(
"<td class=\"data2\">",fp_top3);
252 fprintf(fp_top3,
"<a href=\"%s/graph.html\"><img src=\"%s/graph.png\" title=\"%s\" alt=\"G\"></a> ",uinfo->
filename,
ImageFile,
_(
"Graphic"));
256 fprintf(fp_top3,
"<a href=\"%s/d%s.html\"><img src=\"%s/datetime.png\" title=\"%s\" alt=\"T\"></a></td>",uinfo->
filename,uinfo->
filename,
ImageFile,
_(
"date/time report"));
262 fprintf(fp_top3,
"<td class=\"data2\">%s</td>",uinfo->
label);
264 fprintf(fp_top3,
"<td class=\"data2\"><a href=\"%s/%s.html\">%s</a></td>",uinfo->
filename,uinfo->
filename,uinfo->
label);
267 fprintf(fp_top3,
"<td class=\"data2\">%s</td>",uinfo->
ip);
270 fputs(
"<td class=\"data\"",fp_top3);
271 if (
SortTableJs[0]) fprintf(fp_top3,
" sorttable_customkey=\"%"PRId64
"\"",(int64_t)nacc);
272 fprintf(fp_top3,
">%s</td>",
fixnum(nacc,1));
275 fputs(
"<td class=\"data\"",fp_top3);
276 if (
SortTableJs[0]) fprintf(fp_top3,
" sorttable_customkey=\"%"PRId64
"\"",(int64_t)nbytes);
277 fprintf(fp_top3,
">%s</td>",
fixnum(nbytes,1));
281 fprintf(fp_top3,
"<td class=\"data\">%3.2lf%%</td>",perc);
284 inperc=(nbytes) ? incac * 100. / nbytes : 0.;
285 ouperc=(nbytes) ? oucac * 100. / nbytes : 0.;
286 fprintf(fp_top3,
"<td class=\"data\">%3.2lf%%</td><td class=\"data\">%3.2lf%%</td>",inperc,ouperc);
287 #ifdef ENABLE_DOUBLE_CHECK_DATA
288 if ((inperc!=0. || ouperc!=0.) && fabs(inperc+ouperc-100.)>=0.01) {
289 debuga(__FILE__,__LINE__,
_(
"The total of the in-cache and cache-miss is not 100%% at position %d (user %s)\n"),posicao,uinfo->
label);
294 fputs(
"<td class=\"data\"",fp_top3);
295 if (
SortTableJs[0]) fprintf(fp_top3,
" sorttable_customkey=\"%"PRId64
"\"",(int64_t)elap);
296 fprintf(fp_top3,
">%s</td>",
buildtime(elap));
299 fputs(
"<td class=\"data\"",fp_top3);
300 if (
SortTableJs[0]) fprintf(fp_top3,
" sorttable_customkey=\"%"PRId64
"\"",(int64_t)elap);
301 fprintf(fp_top3,
">%s</td>",
fixnum2(elap,1));
305 fprintf(fp_top3,
"<td class=\"data\">%3.2lf%%</td>",perc2);
308 fputs(
"</tr>\n",fp_top3);
317 debuga(__FILE__,__LINE__,
_(
"Cannot delete \"%s\": %s\n"),ListFile,strerror(errno));
323 fputs(
"<tfoot><tr>",fp_top3);
325 fputs(
"<td></td>",fp_top3);
327 fputs(
"<td></td>",fp_top3);
329 fprintf(fp_top3,
"<th class=\"header_l\" colspan=\"2\">%s</th>",
_(
"TOTAL"));
331 fprintf(fp_top3,
"<th class=\"header_l\">%s</th>",
_(
"TOTAL"));
334 fprintf(fp_top3,
"<th class=\"header_r\">%s</th>",
fixnum(Statis->
ttnacc,1));
336 fprintf(fp_top3,
"<th class=\"header_r\">%15s</th>",
fixnum(Statis->
ttnbytes,1));
338 fputs(
"<td></td>",fp_top3);
343 fprintf(fp_top3,
"<th class=\"header_r\">%3.2lf%%</th><th class=\"header_r\">%3.2lf%%</th>",inperc,ouperc);
344 #ifdef ENABLE_DOUBLE_CHECK_DATA
345 if (fabs(inperc+ouperc-100.)>=0.01) {
346 debuga(__FILE__,__LINE__,
_(
"The total of the in-cache and cache-miss is not 100%%\n"));
351 fprintf(fp_top3,
"<th class=\"header_r\">%s</th>",
buildtime(Statis->
ttnelap));
353 fprintf(fp_top3,
"<th class=\"header_r\">%s</th>",
fixnum2(Statis->
ttnelap,1));
355 fputs(
"</tr>\n",fp_top3);
360 fputs(
"<tr>",fp_top3);
362 fputs(
"<td></td>",fp_top3);
364 fputs(
"<td></td>",fp_top3);
366 fprintf(fp_top3,
"<th class=\"header_l\" colspan=\"2\">%s</th>",
_(
"AVERAGE"));
368 fprintf(fp_top3,
"<th class=\"header_l\">%s</th>",
_(
"AVERAGE"));
371 fprintf(fp_top3,
"<th class=\"header_r\">%s</th>",
fixnum(Statis->
ttnacc/Statis->
totuser,1));
374 fprintf(fp_top3,
"<th class=\"header_r\">%15s</th>",
fixnum(nbytes,1));
377 fputs(
"<td></td>",fp_top3);
379 fputs(
"<td></td><td></td>",fp_top3);
384 fputs(
"</tr></tfoot>\n",fp_top3);
387 fputs(
"</table></div>\n",fp_top3);
389 if (fclose(fp_top3)==EOF) {
390 debuga(__FILE__,__LINE__,
_(
"Write error in \"%s\": %s\n"),top3,strerror(errno));
407 long long int nbytes;
409 long long int elap, incac, oucac;
412 long long int tnbytes=0;
413 long long int avgacc, avgelap;
428 debuga(__FILE__,__LINE__,
_(
"Not enough memory to read file \"%s\"\n"),ListFile);
432 safe_strcpy(strip1,
_(
"Squid User Access Report"),
sizeof(strip1));
434 fprintf(fp_mail,
"%s\n",strip1);
438 fprintf(fp_mail,
"%s\n",strip1);
440 snprintf(strip1,
sizeof(strip1),
_(
"Period: %s"),
period.
text);
442 fprintf(fp_mail,
"%s\n\n",strip1);
459 fprintf(fp_mail,
"%-7s %-20s %-9s %-15s %%%-6s %-11s %-10s %%%-7s\n------- -------------------- -------- --------------- ------- ---------- ---------- -------\n",strip1,strip2,strip3,strip4,strip4,strip5,strip6,strip7);
464 if (
getword(user,
sizeof(user),&gwarea,
'\t')<0) {
465 debuga(__FILE__,__LINE__,
_(
"Invalid user in file \"%s\"\n"),ListFile);
469 debuga(__FILE__,__LINE__,
_(
"Invalid number of bytes in file \"%s\"\n"),ListFile);
473 debuga(__FILE__,__LINE__,
_(
"Invalid number of accesses in file \"%s\"\n"),ListFile);
477 debuga(__FILE__,__LINE__,
_(
"Invalid elapsed time in file \"%s\"\n"),ListFile);
481 debuga(__FILE__,__LINE__,
_(
"Invalid in-cache size in file \"%s\"\n"),ListFile);
485 debuga(__FILE__,__LINE__,
_(
"Invalid out-of-cache size in file \"%s\"\n"),ListFile);
494 debuga(__FILE__,__LINE__,
_(
"Unknown user ID %s in file \"%s\"\n"),user,ListFile);
504 #if defined(__FreeBSD__)
505 fprintf(fp_mail,
"%7d %20s %8lld %15s %5.2lf%% %10s %10qu %3.2lf%%\n",topcount,uinfo->
label,nacc,
fixnum(nbytes,1),perc,
buildtime(elap),elap,perc2);
507 fprintf(fp_mail,
"%7d %20s %8"PRIu64
" %15s %6.2lf%% %10s %10"PRIu64
" %3.2lf%%\n",topcount,uinfo->
label,(uint64_t)nacc,
fixnum(nbytes,1),perc,
buildtime(elap),(uint64_t)elap,perc2);
515 debuga(__FILE__,__LINE__,
_(
"Cannot delete \"%s\": %s\n"),ListFile,strerror(errno));
521 fputs(
"------- -------------------- -------- --------------- ------- ---------- ---------- -------\n",fp_mail);
522 #if defined(__FreeBSD__)
541 #if defined(__FreeBSD__)
542 fprintf(fp_mail,
"%-7s %20s %8qu %15s %8s %9s %10qu\n",strip1,
" ",avgacc,
fixnum(tnbytes,1),
" ",
buildtime(avgelap),avgelap);
544 fprintf(fp_mail,
"%-7s %20s %8"PRIu64
" %15s %8s %9s %10"PRIu64
"\n",strip1,
" ",(uint64_t)avgacc,
fixnum(tnbytes,1),
" ",
buildtime(avgelap),(uint64_t)avgelap);
548 local = localtime(&t);
549 fprintf(fp_mail,
"\n%s\n", asctime(local));
552 Subject=
_(
"Sarg: top user report");
567 long long int tnacc=0;
568 long long int tnbytes=0, tnelap=0;
569 long long int tnincache=0, tnoucache=0;
573 const char *sfield=
"-n -k 2,2";
580 debuga(__FILE__,__LINE__,
_(
"Creating top users report...\n"));
582 memset(&Statis,0,
sizeof(Statis));
591 if ((fp_top2=fopen(top2,
"w"))==NULL) {
592 debuga(__FILE__,__LINE__,
_(
"Cannot open file \"%s\": %s\n"),top2,strerror(errno));
599 debuga(__FILE__,__LINE__,
_(
"Not enough memory to read file \"%s\"\n"),wger);
605 if (item.
total)
continue;
606 if (strcmp(olduser,item.
user) != 0) {
609 if (olduser[0] !=
'\0') {
614 fprintf(fp_top2,
"%s\t%"PRIu64
"\t%"PRIu64
"\t%"PRIu64
"\t%"PRIu64
"\t%"PRIu64
"\n",olduser,(uint64_t)tnbytes,(uint64_t)tnacc,(uint64_t)tnelap,(uint64_t)tnincache,(uint64_t)tnoucache);
642 if (olduser[0] !=
'\0') {
647 fprintf(fp_top2,
"%s\t%"PRIu64
"\t%"PRIu64
"\t%"PRIu64
"\t%"PRIu64
"\t%"PRIu64
"\n",olduser,(uint64_t)tnbytes,(uint64_t)tnacc,(uint64_t)tnelap,(uint64_t)tnincache,(uint64_t)tnoucache);
655 if (fclose(fp_top2)==EOF) {
656 debuga(__FILE__,__LINE__,
_(
"Write error in \"%s\": %s\n"),top2,strerror(errno));
660 #ifdef ENABLE_DOUBLE_CHECK_DATA
663 debuga(__FILE__,__LINE__,
_(
"Total statistics mismatch when reading \"%s\" to produce the top users\n"),wger);
692 if (snprintf(csort,
sizeof(csort),
"sort -T \"%s\" -t \"\t\" %s %s -o \"%s\" \"%s\"",
tmp, order, sfield, top1, top2)>=
sizeof(csort)) {
693 debuga(__FILE__,__LINE__,
_(
"Sort command too long when sorting file \"%s\" to \"%s\"\n"),top2,top1);
696 cstatus=system(csort);
697 if (!WIFEXITED(cstatus) || WEXITSTATUS(cstatus)) {
698 debuga(__FILE__,__LINE__,
_(
"sort command return status %d\n"),WEXITSTATUS(cstatus));
699 debuga(__FILE__,__LINE__,
_(
"sort command: %s\n"),csort);
704 debuga(__FILE__,__LINE__,
_(
"Cannot delete \"%s\": %s\n"),top2,strerror(errno));
static void set_total_users(int totuser)
#define REPORT_TYPE_USERS_SITES
#define TOPUSERFIELDS_MILISEC
#define TOPUSERFIELDS_USED_TIME
int topuser
True if this user is in the topuser list.
void getword_start(struct getwordstruct *gwarea, const char *line)
void write_html_header(FILE *fp_ou, int depth, const char *title, int javascript)
void debuga(const char *File, int Line, const char *msg,...)
#define HTML_JS_SORTTABLE
Bit to include sorttable.js in the html plage.
#define TOPUSER_SORT_REVERSE
struct globalstatstruct globstat
The global statistics of the whole log read.
What is known about a user.
#define INDEX_HTML_FILE
Name of the html file containing the index of a report file.
char * longline_read(FileObject *fp_in, longline line)
int format_path(const char *file, int line, char *output_buffer, int buffer_size, const char *format,...)
const char * FileObject_GetLastCloseError(void)
#define TOPUSERFIELDS_USERID
#define TOPUSERFIELDS_IN_CACHE_OUT
#define TOPUSERFIELDS_SETYB
bool KeepTempLog
True to keep the temporary files for inspection.
static void TopUser_TextEmail(const char *ListFile, struct TopUserStatistics *Statis, struct SortInfoStruct *SortInfo)
const char * FileObject_GetLastOpenError(void)
long long nbytes
The number of bytes transfered.
#define REPORT_TYPE_DATE_TIME
FILE * Email_OutputFile(const char *Module)
#define REPORT_TYPE_TOPUSERS
void Email_Send(FILE *fp, const char *Subject)
#define TOPUSER_SORT_TIME
long long int incache
Amount of data fetched from the cache.
char * fixnum2(long long int value, int n)
long long oucache
The number of bytes fetched from the site (cache miss).
char * buildtime(long long int elap)
long long incache
The number of bytes fetched from the cache of the proxy (cache hit).
struct userinfostruct * userinfo_find_from_id(const char *id)
#define TOPUSERFIELDS_PTIME
const char * label
The name of the user to display in the report.
#define TOPUSERFIELDS_USERIP
long long int oucache
Amount of data not fetched from the cache.
void greport_cleanup(void)
unsigned long int ReportType
void day_deletefile(const struct userinfostruct *uinfo)
#define TOPUSERFIELDS_DATE_TIME
void close_html_header(FILE *fp_ou)
#define TOPUSERFIELDS_TOTAL
char SortTableJs[256]
The full path to sorttable.js if the table in the reports must be dynamicaly sorted.
unsigned long int IndexTree
How to display the index of the reports.
void strip_latin(char *line)
#define TOPUSERFIELDS_CONNECT
char html[90]
The HTML representation of the date.
int ger_read(char *buffer, struct generalitemstruct *item, const char *filename)
long long int nacc
Total number of accesses.
char * fixnum(long long int value, int n)
int getword(char *word, int limit, struct getwordstruct *gwarea, char stop)
FileObject * FileObject_Open(const char *FileName)
unsigned long int TopUserFields
Include headers and define global variables. */.
#define TOPUSER_SORT_USER
#define pgettext(Msgctxt, Msgid)
longline longline_create(void)
const char * filename
The mangled name to use in file names of that user.
long long nelap
The number of milliseconds spend processing the request.
#define TOPUSER_SORT_CONNECT
void report_day(const struct userinfostruct *user)
char * user
The user to which the entry apply. The length is limited to MAX_USER_LEN.
#define TOPUSERFIELDS_NUM
void longline_destroy(longline *line_ptr)
char text[90]
The textual representation of the date.
#define TOPUSERFIELDS_BYTES
const char * ip
The user's IP address.
void debugaz(const char *File, int Line, const char *msg,...)
void safe_strcpy(char *dest, const char *src, int length)
void write_html_trailer(FILE *fp_ou)
long long nacc
The number of accesses performed by the user.
long long int nbytes
Total number of bytes.
static void TopUser_HtmlReport(const char *ListFile, struct TopUserStatistics *Statis, struct SortInfoStruct *SortInfo)
unsigned long int TopuserSort
Declaration of the structures and functions.
int totuser
The number of users in the topuser list.
int total
True if the entry is for the total of the file or false if it is a single line.
#define REPORT_TYPE_SITES_USERS
#define REPORT_TYPE_TOPSITES
struct periodstruct period
int getword_atoll(long long int *number, struct getwordstruct *gwarea, char stop)
#define TOPUSERFIELDS_AVERAGE
void greport_day(const struct userinfostruct *uinfo)
int FileObject_Close(FileObject *File)
long long int elap
Total time spent processing the requests.
void greport_prepare(void)
bool smartfilter
True to enable the smart filter.
@ LogLevel_Process
Process informational messages.