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