]> git.ipfire.org Git - thirdparty/sarg.git/blame - repday.c
LDAP usertab feature added
[thirdparty/sarg.git] / repday.c
CommitLineData
25697a35 1/*
c37945ed 2 * AUTHOR: Pedro Lineu Orso pedro.orso@gmail.com
e3af0ae9 3 * 1998, 2009
94ff9470 4 * SARG Squid Analysis Report Generator http://sarg.sourceforge.net
25697a35
GS
5 *
6 * SARG donations:
7 * please look at http://sarg.sourceforge.net/donations.php
8 * ---------------------------------------------------------------------
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
23 *
24 */
25
26#include "include/conf.h"
5f3cfd1d 27#include "include/defs.h"
25697a35
GS
28
29extern numlist hours;
30
32e71fa4 31void report_day(const char *user)
25697a35
GS
32{
33
34 FILE *fp_in, *fp_ou;
35
36 char data[20];
25697a35 37 char odata[20];
d6e703cc 38 char hour[20];
25697a35
GS
39 char elap[20];
40 char oelap[20];
25697a35
GS
41 char html[8000];
42 char arqout[MAXLEN];
43 char wdirname[MAXLEN];
44 char wuser[255];
45 char c[ 24 ][20];
46 int count=0;
d6e703cc 47 int ihour=0;
120d768c 48 long long int v[ 24 ] = { 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
25697a35 49 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L };
120d768c 50 long long int t[ 24 ] = { 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
25697a35
GS
51 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L };
52 long long int tt=0, ttt=0;
25697a35
GS
53 int i;
54
55 sprintf(arqout,"%s/%s/d%s.html",dirname,user,user);
56 sprintf(wdirname,"%s/%s.day",tmp,user);
57
58 if(access(wdirname, R_OK) != 0)
59 return;
60
61 if((fp_in=fopen(wdirname,"r"))==NULL) {
62 fprintf(stderr, "SARG: (repday) %s: %s\n",text[8],wdirname);
63 exit(1);
64 }
65
66 if((fp_ou=fopen(arqout,"w"))==NULL) {
67 fprintf(stderr, "SARG: (repday) %s: %s\n",text[8],arqout);
68 exit(1);
69 }
70
d6e703cc 71 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);
25697a35
GS
72 css(fp_ou);
73 fputs("</head>\n",fp_ou);
dfb337be
FM
74 //if(strlen(FontFace) > 0) fprintf(fp_ou,"<font face=%s>\n",FontFace);
75 fprintf(fp_ou,"<body bgcolor=\"%s\" text=\"%s\" background=\"%s\">\n",BgColor,TxColor,BgImage);
76 write_logo_image(fp_ou);
25697a35 77
491b862f
GS
78 if(strcmp(IndexTree,"date") == 0)
79 show_sarg(fp_ou, "../../../..");
80 else
81 show_sarg(fp_ou, "../..");
82
dfb337be
FM
83 fputs("<div align=\"center\"><table cellpadding=\"0\" cellspacing=\"0\">\n",fp_ou);
84 fprintf(fp_ou,"<tr><th class=\"title\" colspan=\"2\">%s</th></tr>\n",Title);
85
86 fputs("</table></div>\n",fp_ou);
87 fputs("<div align=\"center\"><table cellpadding=\"0\" cellspacing=\"0\">\n",fp_ou);
25697a35 88
354c1a68 89 fprintf(fp_ou,"<tr><td class=\"header3\" colspan=\"2\">%s:&nbsp;%s</td></tr>\n",text[89],period);
25697a35
GS
90
91 strcpy(wuser,user);
92 if(strstr(wuser,"_") != 0)
93 fixip(wuser);
94
95 if(strcmp(Ip2Name,"yes") == 0)
96 if((str=(char *) strstr(name, ".")) != (char *) NULL) {
97 if((str=(char *) strstr(str+1, ".")) != (char *) NULL)
a1c55d8c 98 ip2name(wuser,sizeof(wuser));
25697a35
GS
99 }
100
e3af0ae9
PO
101// get_usertab_name(wuser,name,sizeof(name));
102 user_find(name, wuser);
94ff9470 103
48864d28
FM
104 if(dotinuser && strchr(name,'_')) {
105 subs(name,sizeof(name),"_",".");
94ff9470 106 }
48864d28 107
354c1a68 108 fprintf(fp_ou,"<tr><th class=\"header3\" colspan=\"2\">%s:&nbsp;%s</th></tr>\n",text[90],name);
25697a35
GS
109
110 fputs("<tr><td></td></tr><tr><td></td></tr>\n",fp_ou);
111 fputs("<tr><td></td></tr><tr><td></td></tr></table>\n",fp_ou);
112
dfb337be 113 fputs("<table cellpadding=\"0\" cellspacing=\"2\">\n", fp_ou);
25697a35 114
dfb337be 115 fputs( "<tr><td></td>\n", fp_ou );
25697a35
GS
116
117 if(strcmp(datetimeby,"bytes") == 0)
d6e703cc 118 strcpy( html, text[93] );
25697a35
GS
119 else
120 strcpy( html, "H:M:S" );
121
122 for( i = 0; i < hours.len; i++ )
dfb337be 123 fprintf( fp_ou, "<td class=\"header3\">%02dH<br>%s</td>\n", hours.list[ i ], html );
25697a35
GS
124 fprintf( fp_ou,
125 "<td class=\"header3\">%s<br>%s</td></tr>\n", text[107], html );
126
127 while(fgets(buf,sizeof(buf),fp_in)!=NULL) {
120d768c 128 if (getword(data,sizeof(data),buf,'\t')<0) {
4bcb77cf
FM
129 printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",wdirname);
130 exit(1);
131 }
25697a35
GS
132 if(!count) {
133 strcpy(odata,data);
134 count++;
135 }
136
120d768c 137 if (getword(hour,sizeof(hour),buf,'\t')<0 || getword(elap,sizeof(elap),buf,'\t')<0) {
4bcb77cf
FM
138 printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",wdirname);
139 exit(1);
140 }
25697a35
GS
141 elap[strlen(elap)-1]='\0';
142
143 if(strcmp(data,odata) != 0) {
144 strcpy(oelap,elap);
145
dfb337be
FM
146 for( i = 0; i < hours.len; i++ )
147 sprintf(c[ hours.list[ i ] ],"%s",fixtime(v[ hours.list[ i ] ]));
148
149 for( i = 8; i <= 17; i++ )
150 if(strcmp(c[ hours.list[ i ] ],"00:00:00") == 0)
151 bzero(c[ hours.list[ i ] ],12);
152
153 fprintf(fp_ou, "<tr><td class=\"data\">%s</td>\n", odata );
154 for( i = 0; i < hours.len; i++ )
155 fprintf(fp_ou,"<td class=\"data\">%s</td>\n", c[ hours.list[ i ] ] );
156 fprintf( fp_ou, "<td class=\"data\">%s</td>\n", fixtime(tt) );
157
25697a35 158 tt=0;
dfb337be 159 for( i = 0; i < hours.len; i++ ) v[ hours.list[ i ] ]=0;
25697a35
GS
160 strcpy(odata,data);
161 strcpy(elap,oelap);
162 }
163
d6e703cc 164 ihour=atoi(hour);
25697a35 165
d6e703cc 166 v[ ihour ]+=my_atoll(elap);
25697a35 167 tt+=my_atoll(elap);
d6e703cc 168 t[ ihour ]+=my_atoll(elap);
25697a35
GS
169 ttt+=my_atoll(elap);
170
171 }
172
173 for( i = 0; i < hours.len; i++ )
174 sprintf(c[ hours.list[ i ] ],"%s",fixtime(v[ hours.list[ i ] ]));
175
176 for( i = 0; i < hours.len; i++ )
177 if(strcmp(c[ hours.list[ i ] ],"00:00:00") == 0) bzero(c[ hours.list[ i ] ],12);
dfb337be
FM
178
179 fprintf(fp_ou, "<tr><td class=\"data\">%s</td>\n", data );
25697a35 180 for( i = 0; i < hours.len; i++ )
dfb337be
FM
181 fprintf(fp_ou, "<td class=\"data\">%s</td>\n", c[ hours.list[ i ] ] );
182 fprintf(fp_ou, "<td class=\"data\">%s</td></tr>\n", fixtime(tt) );
25697a35
GS
183
184 for( i = 0; i < hours.len; i++ )
185 sprintf(c[ hours.list[ i ] ],"%s",fixtime(t[ hours.list[ i ] ]));
186
dfb337be 187 fprintf(fp_ou, "<tr><td class=\"header\">%s</td>\n", text[107] );
25697a35 188 for( i = 0; i < hours.len; i++ )
dfb337be
FM
189 fprintf(fp_ou, "<td class=\"header2\">%s</td>\n", c[ hours.list[ i ] ] );
190 fprintf(fp_ou, "<td class=\"header2\">%s</td></tr>\n", fixtime(ttt) );
25697a35 191
dfb337be 192 fputs("</table></div>\n",fp_ou);
25697a35
GS
193
194 show_info(fp_ou);
195
dfb337be 196 fputs("</body>\n</html>\n",fp_ou);
25697a35
GS
197 fclose(fp_in);
198 fclose(fp_ou);
25697a35
GS
199 return;
200}