]> git.ipfire.org Git - thirdparty/sarg.git/blob - repday.c
This commit was generated by cvs2svn to compensate for changes in r2,
[thirdparty/sarg.git] / repday.c
1 /*
2 * AUTHOR: Pedro Lineu Orso orso@brturbo.com.br
3 * 1998, 2005
4 * SARG Squid Analysis Report Generator http://sarg-squid.org
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"
27
28 extern numlist hours;
29
30 void report_day(char *user, int *iprel, int *ipuser)
31 {
32
33 FILE *fp_in, *fp_ou;
34
35 char data[20];
36 char dia[3];
37 char mes[3];
38 char ano[3];
39 char odata[20];
40 char hora[20];
41 char elap[20];
42 char oelap[20];
43 char whora[3];
44 char html[8000];
45 char arqout[MAXLEN];
46 char wdirname[MAXLEN];
47 char wuser[255];
48 char c[ 24 ][20];
49 int count=0;
50 int ihora=0;
51 long long int telap=0;
52 long long int v[ 24 ] = { 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
53 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L };
54 long long int t[ 24 ] = { 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
55 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L };
56 long long int tt=0, ttt=0;
57 char ftime[128];
58 int i;
59
60 sprintf(arqout,"%s/%s/d%s.html",dirname,user,user);
61 sprintf(wdirname,"%s/%s.day",tmp,user);
62
63 if(access(wdirname, R_OK) != 0)
64 return;
65
66 if((fp_in=fopen(wdirname,"r"))==NULL) {
67 fprintf(stderr, "SARG: (repday) %s: %s\n",text[8],wdirname);
68 exit(1);
69 }
70
71 if((fp_ou=fopen(arqout,"w"))==NULL) {
72 fprintf(stderr, "SARG: (repday) %s: %s\n",text[8],arqout);
73 exit(1);
74 }
75
76 fputs("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\"",fp_ou);
77 fputs(" \"http://www.w3.org/TR/html4/loose.dtd\">\n",fp_ou);
78 fputs("<html>\n",fp_ou);
79 fputs("<head>\n",fp_ou);
80 sprintf(html," <meta http-equiv=\"Content-Type\" content=\"text/html; charset=%s\">\n",CharSet);
81 fputs(html,fp_ou);
82 css(fp_ou);
83 fputs("</head>\n",fp_ou);
84
85 if(strlen(FontFace) > 0) {
86 sprintf(html,"<font face=%s>\n",FontFace);
87 fputs(html,fp_ou);
88 }
89
90 sprintf(html,"<body bgcolor=%s text=%s background='%s'>\n",BgColor,TxColor,BgImage);
91 fputs(html,fp_ou);
92
93 if(strlen(LogoImage) > 0) {
94 fputs("<center><table cellpadding=0 cellspacing=0>\n",fp_ou);
95 sprintf(html,"<tr><th align=left><img src='%s' border=0 align=absmiddle width=%s height=%s><font color=%s>%s</font>\n",LogoImage,Width,Height,LogoTextColor,LogoText);
96 fputs(html,fp_ou);
97 fputs("</table>\n",fp_ou);
98 }
99
100 show_sarg(fp_ou,"../..");
101 fputs("<center><table cellpadding=0 cellspacing=0>\n",fp_ou);
102 sprintf(html,"<tr><th class=\"title\" colspan=2>%s</th></tr>\n",Title);
103 fputs(html,fp_ou);
104
105 fputs("</table></center>\n",fp_ou);
106 fputs("<center><table cellpadding=0 cellspacing=0>\n",fp_ou);
107
108 sprintf(html,"<tr><td class=\"header3\" colspan=\"2\">%s:&nbsp;%s</td></tr>\n",text[89],periodo);
109 fputs(html,fp_ou);
110
111 strcpy(wuser,user);
112 if(strstr(wuser,"_") != 0)
113 fixip(wuser);
114
115 if(strcmp(Ip2Name,"yes") == 0)
116 if((str=(char *) strstr(name, ".")) != (char *) NULL) {
117 if((str=(char *) strstr(str+1, ".")) != (char *) NULL)
118 ip2name(wuser);
119 }
120
121 if(UserTabFile[0] != '\0') {
122 sprintf(warea,":%s:",wuser);
123 if((str=(char *) strstr(userfile,warea)) != (char *) NULL ) {
124 z1=0;
125 str2=(char *) strstr(str+1,":");
126 str2++;
127 bzero(name, MAXLEN);
128 while(str2[z1] != ':') {
129 name[z1]=str2[z1];
130 z1++;
131 }
132 } else strcpy(name,wuser);
133 } else strcpy(name,user);
134
135 sprintf(html,"<tr><td class=\"header3\" colspan=\"2\">%s:&nbsp;%s</td></tr>\n",text[90],name);
136 fputs(html,fp_ou);
137
138 fputs("<tr><td></td></tr><tr><td></td></tr>\n",fp_ou);
139 fputs("<tr><td></td></tr><tr><td></td></tr></table>\n",fp_ou);
140
141 fputs("<table cellpadding=0 cellspacing=2>\n", fp_ou);
142
143 fputs( "<tr><td border=0></td>\n", fp_ou );
144
145 if(strcmp(datetimeby,"bytes") == 0)
146 strcpy( html, "BYTES" );
147 else
148 strcpy( html, "H:M:S" );
149
150 for( i = 0; i < hours.len; i++ )
151 fprintf( fp_ou,
152 "<td class=\"header3\">%02dH<br>%s</td>\n", hours.list[ i ], html );
153 fprintf( fp_ou,
154 "<td class=\"header3\">%s<br>%s</td></tr>\n", text[107], html );
155
156 while(fgets(buf,sizeof(buf),fp_in)!=NULL) {
157 getword(data,buf,' ');
158 if(!count) {
159 strcpy(odata,data);
160 count++;
161 }
162
163 getword(hora,buf,' ');
164 getword(elap,buf,' ');
165 elap[strlen(elap)-1]='\0';
166
167 if(strcmp(data,odata) != 0) {
168 strcpy(oelap,elap);
169
170 for( i = 0; i < hours.len; i++ )
171 sprintf(c[ hours.list[ i ] ],"%s",fixtime(v[ hours.list[ i ] ]));
172
173 for( i = 8; i <= 17; i++ )
174 if(strcmp(c[ hours.list[ i ] ],"00:00:00") == 0)
175 bzero(c[ hours.list[ i ] ],12);
176
177 fprintf( fp_ou,
178 "<tr><td class=\"data\">%s</td>\n", odata );
179 for( i = 0; i < hours.len; i++ )
180 fprintf( fp_ou,
181 "<td class=\"data\">%s</td>\n", c[ hours.list[ i ] ] );
182 fprintf( fp_ou,
183 "<td class=\"data\">%s</td>\n", fixtime(tt) );
184
185 tt=0;
186 for( i = 0; i < hours.len; i++ ) v[ hours.list[ i ] ]=0;
187 strcpy(odata,data);
188 strcpy(elap,oelap);
189 }
190
191 ihora=atoi(hora);
192
193 v[ ihora ]+=my_atoll(elap);
194 tt+=my_atoll(elap);
195 t[ ihora ]+=my_atoll(elap);
196 ttt+=my_atoll(elap);
197
198 }
199
200 for( i = 0; i < hours.len; i++ )
201 sprintf(c[ hours.list[ i ] ],"%s",fixtime(v[ hours.list[ i ] ]));
202
203 for( i = 0; i < hours.len; i++ )
204 if(strcmp(c[ hours.list[ i ] ],"00:00:00") == 0) bzero(c[ hours.list[ i ] ],12);
205
206 fprintf( fp_ou,
207 "<tr><td class=\"data\">%s</td>\n", data );
208 for( i = 0; i < hours.len; i++ )
209 fprintf( fp_ou,
210 "<td class=\"data\">%s</td>\n", c[ hours.list[ i ] ] );
211 fprintf( fp_ou,
212 "<td class=\"data\">%s</td></tr>\n", fixtime(tt) );
213
214 for( i = 0; i < hours.len; i++ )
215 sprintf(c[ hours.list[ i ] ],"%s",fixtime(t[ hours.list[ i ] ]));
216
217 fprintf( fp_ou,
218 "<tr><td class=\"header\">%s</td>\n", text[107] );
219 for( i = 0; i < hours.len; i++ )
220 fprintf( fp_ou,
221 "<td class=\"header2\">%s</td>\n", c[ hours.list[ i ] ] );
222 fprintf( fp_ou,
223 "<td class=\"header2\">%s</td></tr>\n", fixtime(ttt) );
224
225 fputs("</body>\n</html>\n",fp_ou);
226
227 show_info(fp_ou);
228
229 fclose(fp_in);
230 fclose(fp_ou);
231
232 return;
233 }