]>
Commit | Line | Data |
---|---|---|
25697a35 | 1 | /* |
c37945ed | 2 | * AUTHOR: Pedro Lineu Orso pedro.orso@gmail.com |
a6e5c172 | 3 | * 1998, 2010 |
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 | 28 | |
32e71fa4 | 29 | void day_totalize(const char *tmp, const char *user, int indexonly) |
25697a35 GS |
30 | { |
31 | ||
32 | FILE *fp_in, *fp_ou; | |
120d768c | 33 | |
25697a35 GS |
34 | char data[20]; |
35 | char hora[20]; | |
36 | char min[20]; | |
37 | char elap[20]; | |
38 | char odata[20]; | |
39 | char ohora[20]; | |
40 | char oelap[20]; | |
25697a35 GS |
41 | char csort[255]; |
42 | char wdirname[MAXLEN]; | |
43 | char sortout[MAXLEN]; | |
44 | char arqout[MAXLEN]; | |
45 | int regs=0; | |
46 | long long int telap=0; | |
456d78a5 | 47 | int cstatus; |
9c7c6346 | 48 | struct getwordstruct gwarea; |
25697a35 GS |
49 | |
50 | if(indexonly) return; | |
51 | if(strstr(ReportType,"users_sites") == 0) return; | |
52 | ||
53 | sprintf(wdirname,"%s/%s.htmp",tmp,user); | |
54 | sprintf(arqout,"%s/%s.day",tmp,user); | |
55 | sprintf(sortout,"%s/%s.sort",tmp,user); | |
56 | ||
9a2efbd0 | 57 | sprintf(csort,"sort -k 1,1 -k 2,2 -o \"%s\" \"%s\"",sortout,wdirname); |
456d78a5 FM |
58 | cstatus=system(csort); |
59 | if (!WIFEXITED(cstatus) || WEXITSTATUS(cstatus)) { | |
60 | fprintf(stderr, "SARG: sort command return status %d\n",WEXITSTATUS(cstatus)); | |
61 | fprintf(stderr, "SARG: sort command: %s\n",csort); | |
62 | exit(1); | |
63 | } | |
25697a35 | 64 | if((fp_in=fopen(sortout,"r"))==NULL) { |
456d78a5 FM |
65 | fprintf(stderr, "SARG: (totday) %s: %s\n",text[8],sortout); |
66 | fprintf(stderr, "SARG: sort command: %s\n",csort); | |
67 | exit(1); | |
25697a35 GS |
68 | } |
69 | ||
456d78a5 FM |
70 | unlink(wdirname); |
71 | ||
25697a35 GS |
72 | if((fp_ou=fopen(arqout,"w"))==NULL) { |
73 | fprintf(stderr, "SARG: (totday) %s: %s\n",text[8],arqout); | |
74 | exit(1); | |
75 | } | |
76 | ||
77 | while(fgets(buf,sizeof(buf),fp_in)!=NULL) { | |
9c7c6346 FM |
78 | fixendofline(buf); |
79 | getword_start(&gwarea,buf); | |
80 | if (getword(data,sizeof(data),&gwarea,'\t')<0 || getword(hora,sizeof(hora),&gwarea,':')<0 || | |
085af286 | 81 | getword(min,sizeof(min),&gwarea,':')<0 || getword_skip(20,&gwarea,'\t')<0 || |
9c7c6346 | 82 | getword(elap,sizeof(elap),&gwarea,0)<0) { |
4bcb77cf FM |
83 | printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",sortout); |
84 | exit(1); | |
85 | } | |
25697a35 GS |
86 | |
87 | if(!regs) { | |
88 | strcpy(odata,data); | |
89 | strcpy(ohora,hora); | |
90 | strcpy(oelap,elap); | |
25697a35 GS |
91 | regs++; |
92 | } | |
93 | ||
d6e703cc | 94 | if(strcmp(hora,ohora) != 0 || strcmp(data,odata) != 0) { |
25697a35 | 95 | my_lltoa(telap,val1,15); |
120d768c | 96 | fprintf(fp_ou,"%s\t%s\t%s\n",odata,ohora,val1); |
25697a35 GS |
97 | strcpy(odata,data); |
98 | strcpy(ohora,hora); | |
25697a35 | 99 | telap=0; |
25697a35 GS |
100 | } |
101 | ||
102 | telap+=my_atoll(elap); | |
25697a35 GS |
103 | } |
104 | ||
25697a35 | 105 | my_lltoa(telap,val1,15); |
120d768c | 106 | fprintf(fp_ou,"%s\t%s\t%s\n",data,hora,val1); |
25697a35 GS |
107 | |
108 | fclose(fp_in); | |
109 | fclose(fp_ou); | |
110 | ||
111 | unlink(sortout); | |
112 | ||
113 | return; | |
114 | ||
115 | } |