]> git.ipfire.org Git - thirdparty/sarg.git/blame - html.c
More translations for gettext.
[thirdparty/sarg.git] / html.c
CommitLineData
25697a35 1/*
94ff9470 2 * SARG Squid Analysis Report Generator http://sarg.sourceforge.net
1164c474 3 * 1998, 2010
25697a35
GS
4 *
5 * SARG donations:
6 * please look at http://sarg.sourceforge.net/donations.php
1164c474
FM
7 * Support:
8 * http://sourceforge.net/projects/sarg/forums/forum/363374
25697a35
GS
9 * ---------------------------------------------------------------------
10 *
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.
15 *
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.
20 *
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.
24 *
25 */
26
27#include "include/conf.h"
5f3cfd1d 28#include "include/defs.h"
25697a35 29
32e71fa4 30void htmlrel(void)
25697a35
GS
31{
32 DIR *dirp;
32e71fa4 33 FILE *fp_in, *fp_ou, *fp_ip, *fp_ip2, *fp_usr;
25697a35
GS
34
35 struct dirent *direntp;
36 long long int nnbytes=0, unbytes=0, tnbytes=0, totbytes=0, totbytes2=0;
37 long long int totelap=0, totelap2=0, nnelap=0, unelap=0, tnelap=0;
9f20cdae 38 long long int incache=0, oucache=0, tnincache=0, tnoucache=0, twork=0;
0a4e18e1
FM
39 long long int ltemp;
40 long long int ntotuser;
41 long long int userbytes, userelap;
e5b2c6f0 42 char *buf;
25697a35 43 char arqin[MAXLEN], arqou[MAXLEN], arqper[MAXLEN], arqip[MAXLEN];
e5b2c6f0 44 char *url, tmsg[50], csort[MAXLEN];
d25d4e6a 45 char period[MAXLEN], user[MAXLEN], duser[MAXLEN];
e5b2c6f0 46 char userhora[9], userdia[9];
0a4e18e1 47 char user_ip[MAXLEN], olduserip[MAXLEN], tmp2[MAXLEN], tmp3[MAXLEN];
f2ec8c75 48 char denied_report[255];
25697a35 49 char *str;
32e71fa4 50 char warea[MAXLEN];
0a4e18e1 51 char totuser[8];
ac422f9b 52 char ltext110[100];
2240dcea 53 char tmp6[MAXLEN];
25697a35 54 long long int tnacc=0, ttnacc=0, unacc=0;
9f20cdae 55 double perc=0, perc2=0, ouperc=0, inperc=0;
25697a35 56 char *s;
32e71fa4 57 int count;
456d78a5 58 int cstatus;
936c9905
FM
59 const char txtext[]=".txt";
60 int dlen;
e5b2c6f0 61 char siteind[MAX_TRUNCATED_URL];
9c7c6346 62 struct getwordstruct gwarea;
e5b2c6f0 63 struct longlinestruct line,line1;
2240dcea 64 struct generalitemstruct item;
f2ec8c75 65 const struct userinfostruct *uinfo;
25697a35 66
085c1e1f 67 if((ReportType & REPORT_TYPE_USERS_SITES) == 0) return;
25697a35
GS
68
69 strcpy(tmp2,TempDir);
70 strcat(tmp2,"/sargtmp.unsort");
71
72 strcpy(tmp3,TempDir);
73 strcat(tmp3,"/sargtmp.log");
74
75 strcpy(arqper,dirname);
d6e703cc 76 strcat(arqper,"/sarg-period");
25697a35 77 if ((fp_in = fopen(arqper, "r")) == 0){
c36c7384 78 fprintf(stderr, "SARG: (html1) %s: %s\n",_("Cannot open file"),arqper);
25697a35
GS
79 exit(1);
80 }
05b90947
FM
81 if (!fgets(period,sizeof(period),fp_in)) {
82 fprintf(stderr,"SARG: (html1) read error in %s\n",arqper);
83 exit(1);
84 }
25697a35
GS
85 fclose(fp_in);
86
87 strcpy(arqper,dirname);
d6e703cc 88 strcat(arqper,"/sarg-general");
25697a35 89 if ((fp_in = fopen(arqper, "r")) == 0){
c36c7384 90 fprintf(stderr, "SARG: (html2) %s: %s\n",_("Cannot open file"),arqper);
25697a35
GS
91 exit(1);
92 }
e5b2c6f0 93 if (longline_prepare(&line)<0) {
10210234 94 debuga(_("Not enough memory to read file %s\n"),arqper);
e5b2c6f0
FM
95 exit(1);
96 }
9f20cdae
FM
97 ttnacc=0;
98 totbytes=0;
99 totelap=0;
e5b2c6f0 100 while((buf=longline_read(fp_in,&line))!=NULL) {
2240dcea
FM
101 ger_read(buf,&item,arqper);
102 if(item.total) {
103 ttnacc+=item.nacc;
104 totbytes+=item.nbytes;
105 totelap+=item.nelap;
25697a35
GS
106 }
107 }
9f20cdae 108 fclose(fp_in);
e5b2c6f0 109 longline_free(&line);
25697a35 110
9f20cdae
FM
111 strcpy(arqper,dirname);
112 strcat(arqper,"/sarg-users");
113 if ((fp_in = fopen(arqper, "r")) == 0){
c36c7384 114 fprintf(stderr, "SARG: (html11) %s: %s\n",_("Cannot open file"),arqper);
9f20cdae
FM
115 exit(1);
116 }
117 if (!fgets(totuser,sizeof(totuser),fp_in)) {
118 fprintf(stderr,"SARG: (html11) read error in %s\n",arqper);
119 exit(1);
120 }
25697a35 121 fclose(fp_in);
9f20cdae
FM
122 ntotuser=my_atoll(totuser);
123 if (ntotuser<=0) ntotuser=1;
25697a35
GS
124
125 dirp = opendir(tmp);
126 while ( (direntp = readdir( dirp )) != NULL ) {
936c9905
FM
127 dlen=strlen(direntp->d_name)-(sizeof(txtext)-1);
128 if (dlen<0) continue;
129 if(strcmp(direntp->d_name+dlen,txtext) != 0)
25697a35
GS
130 continue;
131
132 count=1;
936c9905 133 if (dlen>0) {
d25d4e6a
FM
134 if (dlen>=sizeof(user)) continue;
135 strncpy(user,direntp->d_name,dlen);
136 user[dlen]=0;
936c9905 137 } else {
d25d4e6a 138 user[0]=0;
25697a35 139 }
f2ec8c75 140
d25d4e6a 141 uinfo=userinfo_find_from_file(user);
f2ec8c75 142 if (!uinfo) {
10210234 143 debuga(_("Unknown user ID %s in directory %s\n"),user,tmp);
f2ec8c75
FM
144 exit(1);
145 }
d25d4e6a 146 str=strrchr(user,'.');
936c9905
FM
147 if (str)
148 strcpy(denied_report,str+1);
149 else
d25d4e6a 150 strcpy(denied_report,user);
936c9905 151
d25d4e6a 152 if (snprintf(warea,sizeof(warea),"%s/%s",dirname,user)>=sizeof(warea)) {
10210234 153 debuga(_("Destination directory too long: %s/%s\n"),dirname,user);
05b90947
FM
154 exit(1);
155 }
25697a35
GS
156 mkdir(warea,0755);
157
f2ec8c75
FM
158 report_day(uinfo);
159 greport_day(uinfo);
25697a35 160
f2ec8c75 161 if (snprintf(arqin,sizeof(arqin),"%s/%s",tmp,direntp->d_name)>=sizeof(arqin)) {
10210234 162 debuga(_("Input file name too long: %s/%s\n"),tmp,direntp->d_name);
f2ec8c75
FM
163 exit(1);
164 }
165 if (snprintf(arqou,sizeof(arqou),"%s/%s/%s.html",dirname,uinfo->filename,uinfo->filename)>=sizeof(arqou)) {
10210234 166 debuga(_("Output file name too long: %s/%s/%s.html\n"),dirname,uinfo->filename,uinfo->filename);
f2ec8c75
FM
167 exit(1);
168 }
169 if (snprintf(duser,sizeof(duser),"%s/%s/denied_%s.html",tmp,direntp->d_name,denied_report)>=sizeof(duser)) {
10210234 170 debuga(_("File name too long: %s/%s/denied_%s.html\n"),tmp,direntp->d_name,denied_report);
f2ec8c75 171 exit(1);
25697a35 172 }
25697a35
GS
173 if(access(duser, R_OK) != 0)
174 denied_report[0]='\0';
936c9905 175
25697a35 176 if ((fp_in = fopen(arqin, "r")) == 0){
c36c7384 177 fprintf(stderr, "SARG: (html3) %s: %s\n",_("Cannot open file"),arqin);
25697a35
GS
178 exit(1);
179 }
48864d28 180
ac422f9b 181 if (longline_prepare(&line)<0) {
10210234 182 debuga(_("Not enough memory to read file %s\n"),arqin);
ac422f9b
FM
183 exit(1);
184 }
185
9f20cdae
FM
186 tnacc=0;
187 tnbytes=0;
188 tnelap=0;
189 tnincache=0;
190 tnoucache=0;
e5b2c6f0
FM
191 while((buf=longline_read(fp_in,&line))!=NULL) {
192 getword_start(&gwarea,buf);
0a4e18e1 193 if (getword_atoll(&ltemp,&gwarea,'\t')<0) {
10210234 194 debuga(_("There is a broken number of access in file %s\n"),arqin);
4bcb77cf
FM
195 exit(1);
196 }
0a4e18e1
FM
197 tnacc+=ltemp;
198 if (getword_atoll(&ltemp,&gwarea,'\t')<0) {
10210234 199 debuga(_("There is a broken downloaded size in file %s\n"),arqin);
4bcb77cf
FM
200 exit(1);
201 }
0a4e18e1 202 tnbytes+=ltemp;
e5b2c6f0 203 if (getword_ptr(NULL,NULL,&gwarea,'\t')<0) {
10210234 204 debuga(_("There is a broken url in file %s\n"),arqin);
ac422f9b
FM
205 exit(1);
206 }
207 if (getword_skip(MAXLEN,&gwarea,'\t')<0) {
10210234 208 debuga(_("There is a broken access code in file %s\n"),arqin);
ac422f9b
FM
209 exit(1);
210 }
211 if (getword_atoll(&ltemp,&gwarea,'\t')<0) {
10210234 212 debuga(_("There is a broken elapsed time in file %s\n"),arqin);
4bcb77cf
FM
213 exit(1);
214 }
0a4e18e1
FM
215 tnelap+=ltemp;
216 if (getword_atoll(&ltemp,&gwarea,'\t')<0) {
10210234 217 debuga(_("There is a broken in-cache volume in file %s\n"),arqin);
4bcb77cf
FM
218 exit(1);
219 }
0a4e18e1
FM
220 tnincache+=ltemp;
221 if (getword_atoll(&ltemp,&gwarea,'\n')<0) {
10210234 222 debuga(_("There is a broken out-cache volume in file %s\n"),arqin);
4bcb77cf
FM
223 exit(1);
224 }
0a4e18e1 225 tnoucache+=ltemp;
25697a35
GS
226 }
227
ec7b26a5 228 rewind(fp_in);
32d1c674 229
25697a35 230 if ((fp_ou = fopen(arqou, "w")) == 0){
c36c7384 231 fprintf(stderr, "SARG: (html5) %s: %s\n",_("Cannot open file"),arqou);
25697a35
GS
232 exit(1);
233 }
32d1c674 234
c0ec9cc7 235 write_html_header(fp_ou,(IndexTree == INDEX_TREE_DATE) ? 4 : 2,_("User report"));
c36c7384
FM
236 fprintf(fp_ou,"<tr><td class=\"header_l\">%s:&nbsp;%s</td></tr>\n",_("Period"),period);
237 fprintf(fp_ou,"<tr><td class=\"header_l\">%s:&nbsp;%s</td></tr>\n",_("User"),uinfo->label);
238 fprintf(fp_ou,"<tr><td class=\"header_l\">%s:&nbsp;%s, %s</td></tr>\n",_("Sort"),UserSortField,UserSortOrder);
239 fprintf(fp_ou,"<tr><td class=\"header_c\">%s %s</td></tr>\n",_("User"),_("Report"));
c0ec9cc7
FM
240 //fputs("<tr><td></td></tr>\n",fp_ou);
241 close_html_header(fp_ou);
25697a35 242
c0ec9cc7 243 fputs("<div class=\"report\"><table cellpadding=\"2\" cellspacing=\"1\">\n",fp_ou);
32d1c674 244
4157aa09 245 if(denied_report[0]!='\0') {
c36c7384 246 fprintf(fp_ou,"<tr><td class=\"header_l\" colspan=\"11\"><a href=\"denied_%s.html\">%s</a> %s</td></tr>\n",denied_report,_("SmartFilter"),_("Report"));
25697a35 247 }
32d1c674 248
c36c7384 249 fprintf(fp_ou,"<tr><th></th><th class=\"header_l\">%s</th>",_("ACCESSED SITE"));
594c9da4
FM
250
251 if((UserReportFields & USERREPORTFIELDS_CONNECT) != 0)
c36c7384 252 fprintf(fp_ou,"<th class=\"header_l\">%s</th>",_("CONNECT"));
594c9da4 253 if((UserReportFields & USERREPORTFIELDS_BYTES) != 0)
c36c7384 254 fprintf(fp_ou,"<th class=\"header_l\">%s</th>",_("BYTES"));
594c9da4 255 if((UserReportFields & USERREPORTFIELDS_SETYB) != 0)
c36c7384 256 fprintf(fp_ou,"<th class=\"header_l\">%%%s</th>",_("BYTES"));
594c9da4 257 if((UserReportFields & USERREPORTFIELDS_IN_CACHE_OUT) != 0)
c36c7384 258 fprintf(fp_ou,"<th class=\"header_c\" colspan=\"2\">%s-%s-%s</th>",_("IN"),_("CACHE"),_("OUT"));
594c9da4 259 if((UserReportFields & USERREPORTFIELDS_USED_TIME) != 0)
c36c7384 260 fprintf(fp_ou,"<th class=\"header_l\">%s</th>",_("ELAPSED TIME"));
594c9da4 261 if((UserReportFields & USERREPORTFIELDS_MILISEC) != 0)
c36c7384 262 fprintf(fp_ou,"<th class=\"header_l\">%s</th>",_("MILISEC"));
594c9da4 263 if((UserReportFields & USERREPORTFIELDS_PTIME) != 0)
c36c7384 264 fprintf(fp_ou,"<th class=\"header_l\">%%%s</th>",_("TIME"));
594c9da4
FM
265
266 fputs("</tr>\n",fp_ou);
32d1c674 267
25697a35 268 if(debug) {
10210234 269 debuga(_("Making report: %s\n"),uinfo->id);
25697a35
GS
270 }
271
e5b2c6f0
FM
272 while((buf=longline_read(fp_in,&line))!=NULL) {
273 getword_start(&gwarea,buf);
0a4e18e1 274 if (getword_atoll(&twork,&gwarea,'\t')<0) {
4157aa09
FM
275 printf("SARG: Maybe you have a broken number of access in your %s file.\n",arqin);
276 exit(1);
277 }
0a4e18e1 278 if (getword_atoll(&nnbytes,&gwarea,'\t')<0) {
4157aa09
FM
279 printf("SARG: Maybe you have a broken number of bytes in your %s file.\n",arqin);
280 exit(1);
281 }
e5b2c6f0 282 if (getword_ptr(buf,&url,&gwarea,'\t')<0) {
10210234 283 debuga(_("Maybe you have a broken url in your %s file\n"),arqin);
4157aa09
FM
284 exit(1);
285 }
9c7c6346 286 if (getword(tmsg,sizeof(tmsg),&gwarea,'\t')<0) {
4157aa09
FM
287 printf("SARG: Maybe you have a broken status in your %s file.\n",arqin);
288 exit(1);
289 }
0a4e18e1 290 if (getword_atoll(&nnelap,&gwarea,'\t')<0) {
4157aa09
FM
291 printf("SARG: Maybe you have a broken elapsed time in your %s file.\n",arqin);
292 exit(1);
293 }
0a4e18e1 294 if (getword_atoll(&incache,&gwarea,'\t')<0) {
4157aa09
FM
295 printf("SARG: Maybe you have a broken in cache column in your %s file.\n",arqin);
296 exit(1);
297 }
0a4e18e1
FM
298 if (getword_atoll(&oucache,&gwarea,'\n')<0) {
299 printf("SARG: Maybe you have a broken not in cache column in your %s file (%d).\n",arqin,__LINE__);
4157aa09
FM
300 exit(1);
301 }
25697a35 302
594c9da4
FM
303 if(UserReportLimit<=0 || count<=UserReportLimit) {
304 fputs("<tr>",fp_ou);
25697a35 305
0349fa24 306 if(IndexTree == INDEX_TREE_DATE)
dfb337be
FM
307 sprintf(tmp6,"../%s",ImageFile);
308 else
309 strcpy(tmp6,"../../images");
25697a35 310
c0ec9cc7 311 if((ReportType & REPORT_TYPE_SITE_USER_TIME_DATE) != 0) {
c36c7384 312 s=_("DATE/TIME");
ac422f9b
FM
313 for(z1=0 ; z1<sizeof(ltext110)-1 && s[z1] ; z1++)
314 ltext110[z1]=tolower(s[z1]);
315 ltext110[z1]='\0';
e5b2c6f0 316 url_to_file(url,siteind,sizeof(siteind));
c36c7384 317 fprintf(fp_ou,"<td class=\"data\"><a href=\"tt%s-%s.html\"><img src=\"%s/datetime.png\" title=\"%s %s\" alt=\"T\"></a></td>",uinfo->filename,siteind,tmp6,ltext110,_("Report"));
c0ec9cc7
FM
318 } else {
319 fprintf(fp_ou,"<td class=\"data\"></td>");
320 }
321
594c9da4
FM
322 if(Privacy)
323 fprintf(fp_ou,"<td class=\"data2\"><span style=\"color:%s;\">%s</span></td>",PrivacyStringColor,PrivacyString);
324 else {
e5b2c6f0 325 fputs("<td class=\"data2\">",fp_ou);
594c9da4 326 if(BlockIt[0]!='\0') {
e5b2c6f0
FM
327 fprintf(fp_ou,"<a href=\"%s%s?url=",wwwDocumentRoot,BlockIt);
328 output_html_url(fp_ou,url);
329 fprintf(fp_ou,"\"><img src=\"%s/sarg-squidguard-block.png\"></a>&nbsp;",tmp6);
330 }
331 fputs("<a href=\"http://",fp_ou);
332 output_html_url(fp_ou,url);
e6c0aebd 333 fputs("\">",fp_ou);
e5b2c6f0
FM
334 output_html_string(fp_ou,url,100);
335 fputs("</a></td>",fp_ou);
594c9da4 336 }
4157aa09 337
594c9da4
FM
338 if((UserReportFields & USERREPORTFIELDS_CONNECT) != 0)
339 fprintf(fp_ou,"<td class=\"data\">%s</td>",fixnum(twork,1));
340 if((UserReportFields & USERREPORTFIELDS_BYTES) != 0)
341 fprintf(fp_ou,"<td class=\"data\">%s</td>",fixnum(nnbytes,1));
9f20cdae
FM
342 if((UserReportFields & USERREPORTFIELDS_SETYB) != 0) {
343 perc=(tnbytes) ? nnbytes * 100. / tnbytes : 0.;
344 fprintf(fp_ou,"<td class=\"data\">%3.2lf%%</td>",perc);
345 }
346 if((UserReportFields & USERREPORTFIELDS_IN_CACHE_OUT) != 0) {
347 inperc=(nnbytes) ? incache * 100. / nnbytes : 0.;
348 ouperc=(nnbytes) ? oucache * 100. / nnbytes : 0.;
349 fprintf(fp_ou,"<td class=\"data\">%3.2lf%%</td><td class=\"data\">%3.2lf%%</td>",inperc,ouperc);
350 }
594c9da4
FM
351 if((UserReportFields & USERREPORTFIELDS_USED_TIME) != 0)
352 fprintf(fp_ou,"<td class=\"data\">%s</td>",buildtime(nnelap));
353 if((UserReportFields & USERREPORTFIELDS_MILISEC) != 0)
354 fprintf(fp_ou,"<td class=\"data\">%s</td>",fixnum2(nnelap,1));
9f20cdae
FM
355 if((UserReportFields & USERREPORTFIELDS_PTIME) != 0) {
356 perc2=(tnelap) ? nnelap * 100. / tnelap : 0.;
357 fprintf(fp_ou,"<td class=\"data\">%3.2lf%%</td>",perc2);
358 }
594c9da4
FM
359
360 if(strncmp(tmsg,"OK",2) != 0)
c36c7384 361 fprintf(fp_ou,"<td class=\"data\">%s</td>",_("DENIED"));
594c9da4
FM
362
363 fputs("</tr>\n",fp_ou);
354c1a68
FM
364 count++;
365 }
25697a35
GS
366
367 if(iprel) {
d25d4e6a 368 if (snprintf(arqip,sizeof(arqip),"%s/%s.ip",tmp,uinfo->filename)>=sizeof(arqip)) {
10210234 369 debuga(_("File name too long: %s/%s.ip\n"),tmp,uinfo->filename);
d25d4e6a
FM
370 exit(1);
371 }
936c9905 372
25697a35 373 if ((fp_ip = fopen(arqip, "r")) == 0){
c36c7384 374 fprintf(stderr, "SARG: (html6) %s: %s\n",_("Cannot open file"),arqip);
25697a35
GS
375 exit(1);
376 }
0dda06bf 377
936c9905 378 if ((fp_ip2 = MY_FOPEN(tmp2, "a")) == 0){
c36c7384 379 fprintf(stderr, "SARG: (html7) %s: %s\n",_("Cannot open file"),tmp2);
25697a35
GS
380 exit(1);
381 }
936c9905 382
e5b2c6f0 383 if (longline_prepare(&line1)<0) {
10210234 384 debuga(_("Not enough memory to read file %s\n"),arqip);
e5b2c6f0
FM
385 exit(1);
386 }
387 while((buf=longline_read(fp_ip,&line1))!=NULL) {
25697a35
GS
388 if(strstr(buf,url) != 0)
389 fputs(buf,fp_ip2);
390 }
e5b2c6f0 391 longline_free(&line1);
936c9905 392
25697a35
GS
393 fclose(fp_ip);
394 fclose(fp_ip2);
395
9a2efbd0 396 sprintf(csort,"sort -n -T \"%s\" -k 1,1 -k 5,5 -o \"%s\" \"%s\"",TempDir,tmp3,tmp2);
456d78a5
FM
397 cstatus=system(csort);
398 if (!WIFEXITED(cstatus) || WEXITSTATUS(cstatus)) {
399 fprintf(stderr, "SARG: sort command return status %d\n",WEXITSTATUS(cstatus));
400 fprintf(stderr, "SARG: sort command: %s\n",csort);
401 exit(1);
402 }
936c9905
FM
403
404 if ((fp_ip = MY_FOPEN(tmp3, "r")) == 0) {
c36c7384 405 fprintf(stderr, "SARG: (html8) %s: %s\n",_("Cannot open file"),tmp3);
25697a35
GS
406 exit(1);
407 }
408
05b90947 409 olduserip[0]='\0';
dfb337be 410
e5b2c6f0 411 if (longline_prepare(&line1)<0) {
10210234 412 debuga(_("Not enough memory to read file %s\n"),arqip);
e5b2c6f0
FM
413 exit(1);
414 }
415 while((buf=longline_read(fp_ip,&line1))!=NULL) {
9c7c6346
FM
416 getword_start(&gwarea,buf);
417 if (getword(user_ip,sizeof(user_ip),&gwarea,'\t')<0) {
05b90947
FM
418 printf("SARG: Maybe you have a broken user IP in your %s file.\n",tmp3);
419 exit(1);
420 }
e5b2c6f0 421 if (getword_ptr(NULL,NULL,&gwarea,'\t')<0) {
10210234 422 debuga(_("Maybe you have a broken user url in your %s file\n"),tmp3);
05b90947
FM
423 exit(1);
424 }
9c7c6346 425 if (getword(userdia,sizeof(userdia),&gwarea,'\t')<0) {
05b90947
FM
426 printf("SARG: Maybe you have a broken day in your %s file.\n",tmp3);
427 exit(1);
428 }
9c7c6346 429 if (getword(userhora,sizeof(userhora),&gwarea,'\t')<0) {
05b90947
FM
430 printf("SARG: Maybe you have a broken time in your %s file.\n",tmp3);
431 exit(1);
432 }
0a4e18e1 433 if (getword_atoll(&userbytes,&gwarea,'\t')<0) {
05b90947
FM
434 printf("SARG: Maybe you have a broken size in your %s file.\n",tmp3);
435 exit(1);
436 }
0a4e18e1
FM
437 if (getword_atoll(&userelap,&gwarea,'\t')<0) {
438 printf("SARG: Maybe you have a broken elapsed time in your %s file (%d).\n",tmp3,__LINE__);
05b90947
FM
439 exit(1);
440 }
25697a35 441 if(strcmp(user_ip,olduserip) != 0) {
25697a35 442 sprintf(wwork1,"%s",fixnum(unbytes,1));
e5b2c6f0 443 fprintf(fp_ou,"<tr><td></td><td class=\"data\">%s</td><td></td><td class=\"data\">%s</td><td></td><td></td><td></td><td class=\"data\">%s</td><td class=\"data\">%lld</td></tr>\n",olduserip,wwork1,buildtime(unelap),unelap);
dfb337be 444
25697a35
GS
445 strcpy(olduserip,user_ip);
446 unacc=0;
447 unbytes=0;
448 unelap=0;
449 }
dfb337be 450
0a4e18e1
FM
451 unbytes=unbytes+userbytes;
452 unelap=unelap+userelap;
25697a35
GS
453 }
454
455 fclose(fp_ip);
e5b2c6f0 456 longline_free(&line1);
25697a35
GS
457
458 unlink(tmp2);
459 unlink(tmp3);
460
25697a35 461 sprintf(wwork1,"%s",fixnum(unbytes,1));
e5b2c6f0 462 fprintf(fp_ou,"<tr><td></td><td class=\"data\">%s</td><td></td><td class=\"data\">%s</td><td></td><td></td><td></td><td class=\"data\">%s</td><td class=\"data\">%lld</td></tr>\n",olduserip,wwork1,buildtime(unelap),unelap);
25697a35
GS
463 }
464
465 unacc=0;
466 unbytes=0;
467 unelap=0;
25697a35
GS
468 }
469
9f20cdae 470 fclose(fp_in);
ac422f9b 471 longline_free(&line);
9f20cdae 472
25697a35
GS
473 if(iprel)
474 unlink(arqip);
475 unlink(arqin);
476
085c1e1f 477 if((UserReportFields & USERREPORTFIELDS_TOTAL) != 0) {
c36c7384 478 fprintf(fp_ou,"<tr><th></th><th class=\"header_l\">%s</th>",_("TOTAL"));
594c9da4 479 if((UserReportFields & USERREPORTFIELDS_CONNECT) != 0)
b18ce4a0 480 fprintf(fp_ou,"<th class=\"header_r\">%s</th>",fixnum(tnacc,1));
594c9da4 481 if((UserReportFields & USERREPORTFIELDS_BYTES) != 0)
b18ce4a0 482 fprintf(fp_ou,"<th class=\"header_r\">%s</th>",fixnum(tnbytes,1));
9f20cdae
FM
483 if((UserReportFields & USERREPORTFIELDS_SETYB) != 0) {
484 perc=(totbytes) ? tnbytes *100. / totbytes :0.;
b18ce4a0 485 fprintf(fp_ou,"<th class=\"header_r\">%3.2lf%%</th>",perc);
9f20cdae
FM
486 }
487 if((UserReportFields & USERREPORTFIELDS_IN_CACHE_OUT) != 0) {
488 inperc=(tnbytes) ? tnincache * 100. / tnbytes : 0.;
489 ouperc=(tnbytes) ? tnoucache * 100. / tnbytes : 0.;
b18ce4a0 490 fprintf(fp_ou,"<th class=\"header_r\">%3.2lf%%</th><th class=\"header_r\">%3.2lf%%</th>",inperc,ouperc);
9f20cdae 491 }
594c9da4 492 if((UserReportFields & USERREPORTFIELDS_USED_TIME) != 0)
b18ce4a0 493 fprintf(fp_ou,"<th class=\"header_r\">%s</th>",buildtime(tnelap));
594c9da4 494 if((UserReportFields & USERREPORTFIELDS_MILISEC) != 0)
b18ce4a0 495 fprintf(fp_ou,"<th class=\"header_r\">%s</th>",fixnum2(tnelap,1));
9f20cdae
FM
496 if((UserReportFields & USERREPORTFIELDS_PTIME) != 0) {
497 perc2=(totelap) ? tnelap * 100. / totelap : 0.;
b18ce4a0 498 fprintf(fp_ou,"<th class=\"header_r\">%3.2lf%%</th>",perc2);
9f20cdae 499 }
594c9da4 500 fputs("</tr>\n",fp_ou);
25697a35
GS
501 }
502
e6414a9d
FM
503 if(PerUserLimit > 0) {
504 if(tnbytes > (PerUserLimit*1000000)) {
25697a35
GS
505 limit_flag=0;
506 if(access(PerUserLimitFile, R_OK) == 0) {
507 if((fp_usr = fopen(PerUserLimitFile, "r")) == 0) {
c36c7384 508 fprintf(stderr, "SARG: (html9) %s: %s\n",_("Cannot open file"),PerUserLimitFile);
25697a35
GS
509 exit(1);
510 }
491b862f 511 while(fgets(tmp6,sizeof(tmp6),fp_usr)!=NULL) {
9f20cdae 512 fixendofline(tmp6);
f2ec8c75 513 if(strcmp(tmp6,uinfo->label) == 0) {
25697a35
GS
514 limit_flag=1;
515 break;
516 }
517 }
518 fclose(fp_usr);
519 }
936c9905 520
25697a35
GS
521 if(!limit_flag) {
522 if((fp_usr = fopen(PerUserLimitFile, "a")) == 0) {
c36c7384 523 fprintf(stderr, "SARG: (html10) %s: %s\n",_("Cannot open file"),PerUserLimitFile);
25697a35
GS
524 exit(1);
525 }
f2ec8c75 526 fprintf(fp_usr,"%s\n",uinfo->label);
25697a35 527 fclose(fp_usr);
936c9905 528
d2fe0c32 529 if(debug)
10210234 530 debuga(_("User %s limit exceeded (%d MB). Added to file %s\n"),uinfo->label,PerUserLimit,PerUserLimitFile);
25697a35
GS
531 }
532 }
533 }
534
d6e703cc
FM
535// if(indexonly) {
536// unlink(arqou);
537// continue;
538// }
539
9f20cdae 540 if ((ReportType & REPORT_TYPE_TOPUSERS) != 0 && (UserReportFields & USERREPORTFIELDS_AVERAGE) != 0) {
0a4e18e1
FM
541 totbytes2=totbytes/ntotuser;
542 totelap2=totelap/ntotuser;
dfb337be 543
c36c7384 544 fprintf(fp_ou,"<tr><th></th><th class=\"header_l\">%s</th>",_("AVERAGE"));
9f20cdae 545 if((UserReportFields & USERREPORTFIELDS_CONNECT) != 0)
b18ce4a0 546 fprintf(fp_ou,"<th class=\"header_r\">%s</th>",fixnum(ttnacc/ntotuser,1));
9f20cdae 547 if((UserReportFields & USERREPORTFIELDS_BYTES) != 0)
b18ce4a0 548 fprintf(fp_ou,"<th class=\"header_r\">%s</th>",fixnum(totbytes2,1));
9f20cdae
FM
549 fprintf(fp_ou,"<th></th><th></th><th></th>");
550 if((UserReportFields & USERREPORTFIELDS_USED_TIME) != 0)
b18ce4a0 551 fprintf(fp_ou,"<th class=\"header_r\">%s</th>",buildtime(totelap2));
9f20cdae 552 if((UserReportFields & USERREPORTFIELDS_MILISEC) != 0)
b18ce4a0 553 fprintf(fp_ou,"<th class=\"header_r\">%s</th>",fixnum2(totelap2,1));
9f20cdae
FM
554 if((UserReportFields & USERREPORTFIELDS_PTIME) != 0) {
555 perc2 = (totelap) ? totelap2 * 100. / totelap : 0.;
b18ce4a0 556 fprintf(fp_ou,"<th class=\"header_r\">%3.2lf%%</th>",perc2);
936c9905 557 }
9f20cdae
FM
558 fputs("</tr>\n",fp_ou);
559 }
25697a35 560
dfb337be 561 fputs("</table></div>\n",fp_ou);
c0ec9cc7 562 write_html_trailer(fp_ou);
25697a35
GS
563 fclose(fp_ou);
564
d25d4e6a 565 htaccess(uinfo);
25697a35
GS
566 }
567
25697a35 568 (void)closedir(dirp);
c274f011 569 greport_cleanup();
25697a35
GS
570
571 return;
572}