]>
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 | ||
491b862f | 28 | void make_index() |
25697a35 GS |
29 | { |
30 | ||
491b862f GS |
31 | FILE *fp_ou, *fp_ou2, *fp_ou3, *fp_tmp, *fp_tmp2, *fp_tmp3; |
32 | DIR *dirp, *dirp2, *dirp3; | |
25697a35 | 33 | struct dirent *direntp; |
491b862f GS |
34 | struct dirent *direntp2; |
35 | struct dirent *direntp3; | |
25697a35 GS |
36 | char html[MAXLEN]; |
37 | char wdir[MAXLEN]; | |
38 | char wdir_tmp[MAXLEN]; | |
39 | char wdir_tmp2[MAXLEN]; | |
491b862f | 40 | char wdir_tmp3[MAXLEN]; |
25697a35 GS |
41 | char newname[512]; |
42 | char month[4]; | |
43 | char period[80]; | |
44 | char data[80]; | |
45 | char tuser[20]; | |
46 | char tbytes[20]; | |
47 | char media[20]; | |
48 | char ftime[128]; | |
49 | char day[4], mon[4], year[6], hour[10]; | |
50 | char h[3], m[3], s[3]; | |
456d78a5 | 51 | int cstatus; |
25697a35 | 52 | |
d6e703cc | 53 | if(LastLog[0] != '\0') mklastlog(outdir,debug); |
25697a35 GS |
54 | |
55 | sprintf(wdir,"%sindex.html",outdir); | |
56 | sprintf(wdir_tmp,"%sindex.unsort",outdir); | |
57 | sprintf(wdir_tmp2,"%sindex.sort",outdir); | |
58 | strcpy(hbc1,"class=\"header\""); | |
59 | ||
60 | if(strcmp(Index,"no") == 0) { | |
d6e703cc | 61 | if(access(wdir, R_OK) == 0) unlink(wdir); |
25697a35 GS |
62 | return; |
63 | } | |
64 | ||
d6e703cc | 65 | if(debug) debuga(text[53]); |
25697a35 | 66 | |
491b862f GS |
67 | // Root dir |
68 | dirp = opendir(outdir); | |
69 | while ((direntp = readdir( dirp )) != NULL) { | |
70 | if(strcmp(IndexTree,"date") == 0) { | |
d6e703cc | 71 | if(!isdigit(direntp->d_name[0]) && !isdigit(direntp->d_name[1])) continue; |
491b862f GS |
72 | if(strlen(direntp->d_name) > 4) { |
73 | bzero(y1,5); | |
74 | bzero(y2,5); | |
75 | bzero(m1,4); | |
76 | bzero(m2,4); | |
77 | bzero(d1,3); | |
78 | bzero(d2,3); | |
79 | if(strcmp(df,"u") == 0) { | |
80 | strncpy(y1,direntp->d_name,4); | |
81 | strncpy(m1,direntp->d_name+4,3); | |
82 | strncpy(d1,direntp->d_name+7,2); | |
83 | strncpy(y2,direntp->d_name+10,4); | |
84 | strncpy(m2,direntp->d_name+14,3); | |
85 | strncpy(d2,direntp->d_name+17,2); | |
86 | } else if(strcmp(df,"e") == 0) { | |
87 | strncpy(y1,direntp->d_name+5,4); | |
88 | strncpy(m1,direntp->d_name+2,3); | |
89 | strncpy(d1,direntp->d_name,2); | |
90 | strncpy(y2,direntp->d_name+15,4); | |
91 | strncpy(m2,direntp->d_name+12,3); | |
92 | strncpy(d2,direntp->d_name+10,2); | |
93 | } | |
94 | conv_month(m1); | |
95 | conv_month(m2); | |
96 | } | |
97 | sprintf(val1,"%s%s",outdir,y1); | |
d6e703cc FM |
98 | if(access(val1, R_OK) != 0) mkdir(val1,0755); |
99 | if(strcmp(m1,m2) != 0) sprintf(val2,"%s/%s-%s",val1,m1,m2); | |
100 | else sprintf(val2,"%s/%s",val1,m1); | |
101 | if(access(val2, R_OK) != 0) mkdir(val2,0755); | |
102 | if(strcmp(d1,d2) != 0) sprintf(val3,"%s/%s-%s",val2,d1,d2); | |
103 | else sprintf(val3,"%s/%s",val2,d1); | |
491b862f GS |
104 | sprintf(val4,"%s%s",outdir,direntp->d_name); |
105 | rename(val4,val3); | |
106 | sprintf(val5,"%s/images",val2); | |
107 | if(access(val5, R_OK) != 0) { | |
108 | sprintf(val5,"ln -s %simages %s/images",outdir,val2); | |
456d78a5 FM |
109 | cstatus=system(val5); |
110 | if (!WIFEXITED(cstatus) || WEXITSTATUS(cstatus)) { | |
111 | fprintf(stderr, "SARG: command return status %d\n",WEXITSTATUS(cstatus)); | |
112 | fprintf(stderr, "SARG: command: %s\n",val5); | |
113 | exit(1); | |
114 | } | |
491b862f GS |
115 | } |
116 | } else { | |
d6e703cc | 117 | if(!isdigit(direntp->d_name[0]) && !isdigit(direntp->d_name[1])) continue; |
491b862f GS |
118 | if(strlen(direntp->d_name) == 4) { |
119 | strcpy(y1,direntp->d_name); | |
120 | sprintf(val1,"%s%s",outdir,direntp->d_name); | |
121 | dirp2 = opendir(val1); | |
122 | while ((direntp2 = readdir( dirp2 )) != NULL) { | |
d6e703cc | 123 | if(!isdigit(direntp2->d_name[0]) && !isdigit(direntp2->d_name[1])) continue; |
491b862f GS |
124 | sprintf(val2,"%s/%s",val1,direntp2->d_name); |
125 | dirp3 = opendir(val2); | |
126 | while ((direntp3 = readdir( dirp3 )) != NULL) { | |
d6e703cc | 127 | if(!isdigit(direntp3->d_name[0]) && !isdigit(direntp3->d_name[1])) continue; |
491b862f GS |
128 | bzero(newname,512); |
129 | strcpy(warea,direntp2->d_name); | |
130 | if(strstr(warea,"-") != 0) { | |
4bcb77cf FM |
131 | if (getword_multisep(m1,sizeof(m1),warea,'-')<0) { |
132 | printf("SARG: Maybe you have a broken record or garbage in your %s directory.\n",val2); | |
133 | exit(1); | |
134 | } | |
491b862f GS |
135 | strcpy(m2,warea); |
136 | conv_month_name(m1); | |
137 | conv_month_name(m2); | |
138 | } else { | |
139 | strcpy(m1,warea); | |
140 | conv_month_name(m1); | |
141 | strcpy(m2,m1); | |
142 | } | |
143 | strcpy(warea,direntp3->d_name); | |
144 | if(strstr(warea,"-") != 0) { | |
4bcb77cf FM |
145 | if (getword_multisep(d1,sizeof(d1),warea,'-')<0) { |
146 | printf("SARG: Maybe you have a broken record or garbage in your %s directory.\n",val2); | |
147 | exit(1); | |
148 | } | |
491b862f GS |
149 | strcpy(d2,warea); |
150 | } else { | |
151 | strcpy(d1,warea); | |
152 | strcpy(d2,warea); | |
153 | } | |
d6e703cc FM |
154 | if(strcmp(df,"u") == 0) sprintf(val4,"%s%s%s%s-%s%s%s",outdir,y1,m1,d1,y1,m2,d2); |
155 | else if(strcmp(df,"e") == 0) sprintf(val4,"%s%s%s%s-%s%s%s",outdir,d1,m1,y1,d2,m2,y1); | |
491b862f GS |
156 | sprintf(val5,"%s%s/%s/%s",outdir,y1,direntp2->d_name,direntp3->d_name); |
157 | if(rename(val5,val4)) { | |
158 | fprintf(stderr, "SARG: (index) rename error - %s\n",strerror(errno)); | |
159 | exit(1); | |
160 | } | |
161 | } | |
162 | (void)rewinddir( dirp3 ); | |
163 | (void)closedir( dirp3 ); | |
164 | } | |
165 | (void)rewinddir( dirp2 ); | |
166 | (void)closedir( dirp2 ); | |
167 | } | |
168 | // sprintf(cmd,"rm -rf %s%s\n",outdir,direntp->d_name); | |
169 | // system(cmd); | |
170 | } | |
25697a35 | 171 | } |
491b862f GS |
172 | (void)rewinddir( dirp ); |
173 | (void)closedir( dirp ); | |
25697a35 GS |
174 | |
175 | if((fp_tmp=fopen(wdir_tmp,"w"))==NULL) { | |
176 | fprintf(stderr, "SARG: (index) %s: %s\n",text[45],wdir_tmp); | |
177 | exit(1); | |
178 | } | |
179 | ||
180 | dirp = opendir(outdir); | |
491b862f | 181 | while ((direntp = readdir( dirp )) != NULL) { |
4bcb77cf | 182 | char *p; |
491b862f | 183 | if(strcmp(IndexTree,"date") == 0) { |
d6e703cc FM |
184 | if(strlen(direntp->d_name) > 4 || !isdigit(direntp->d_name[0]) && !isdigit(direntp->d_name[1])) continue; |
185 | fprintf(fp_tmp,"%s %s\n",direntp->d_name,get_size(outdir,direntp->d_name)); | |
25697a35 | 186 | continue; |
491b862f | 187 | } else { |
d6e703cc | 188 | if(strstr(direntp->d_name,"-") == 0) continue; |
491b862f GS |
189 | bzero(newname, 512); |
190 | if(strcmp(df,"u") == 0) { | |
191 | strncat(newname,direntp->d_name,4); | |
192 | strncpy(month,direntp->d_name+4,3); | |
193 | } else { | |
194 | strncat(newname,direntp->d_name+5,4); | |
195 | strncpy(month,direntp->d_name+2,3); | |
196 | } | |
197 | month[3]='\0'; | |
198 | conv_month(month); | |
199 | strcat(newname,month); | |
d6e703cc FM |
200 | if(strcmp(df,"u") == 0) strncat(newname,direntp->d_name+7,2); |
201 | else strncat(newname,direntp->d_name,2); | |
491b862f GS |
202 | obtdate(outdir,direntp->d_name,data); |
203 | obtuser(outdir,direntp->d_name,tuser); | |
204 | obttotal(outdir,direntp->d_name,tbytes,tuser,media); | |
205 | strcpy(html,data); | |
4bcb77cf FM |
206 | if (getword_multisep(mon,sizeof(mon),html,' ')<0) { |
207 | printf("SARG: Maybe you have a broken week day in your %s%s/sarg-date file.\n",outdir,direntp->d_name); | |
208 | exit(1); | |
209 | } | |
210 | if (getword_multisep(mon,sizeof(mon),html,' ')<0) { | |
211 | printf("SARG: Maybe you have a broken month in your %s%s/sarg-date file.\n",outdir,direntp->d_name); | |
212 | exit(1); | |
213 | } | |
214 | if (getword_multisep(day,sizeof(day),html,' ')<0) { | |
215 | printf("SARG: Maybe you have a broken day in your %s%s/sarg-date file.\n",outdir,direntp->d_name); | |
216 | exit(1); | |
217 | } | |
218 | if (getword_multisep(hour,sizeof(hour),html,' ')<0) { | |
219 | printf("SARG: Maybe you have a broken time in your %s%s/sarg-date file.\n",outdir,direntp->d_name); | |
220 | exit(1); | |
221 | } | |
222 | p = strchr(html, ' '); | |
223 | if (!p) p = html; | |
224 | if (getword_multisep(year,sizeof(year),html,' ')<0) { | |
225 | printf("SARG: Maybe you have a broken year in your %s%s/sarg-date file.\n",outdir,direntp->d_name); | |
226 | exit(1); | |
227 | } | |
491b862f | 228 | strcpy(html,hour); |
4bcb77cf FM |
229 | if (getword_multisep(h,sizeof(h),html,':')<0) { |
230 | printf("SARG: Maybe you have a broken hour in your %s%s/sarg-date file.\n",outdir,direntp->d_name); | |
231 | exit(1); | |
232 | } | |
233 | if (getword_multisep(m,sizeof(m),html,':')<0) { | |
234 | printf("SARG: Maybe you have a broken minute in your %s%s/sarg-date file.\n",outdir,direntp->d_name); | |
235 | exit(1); | |
236 | } | |
237 | if (getword_multisep(s,sizeof(s),html,0)<0) { | |
238 | printf("SARG: Maybe you have a broken second in your %s%s/sarg-date file.\n",outdir,direntp->d_name); | |
239 | exit(1); | |
240 | } | |
491b862f | 241 | buildymd(day,mon,year,ftime); |
d6e703cc | 242 | fprintf(fp_tmp,"%s%s%s%s;%s;%s;%s;%s;%s;%s\n",ftime, h, m, s, direntp->d_name, data, tuser, tbytes, media,newname); |
491b862f GS |
243 | continue; |
244 | } | |
25697a35 | 245 | } |
94ff9470 | 246 | |
491b862f GS |
247 | if(fp_tmp) fclose(fp_tmp); |
248 | if(strcmp(IndexTree,"file") == 0) { | |
249 | (void)rewinddir( dirp ); | |
250 | (void)closedir( dirp ); | |
25697a35 GS |
251 | } |
252 | ||
491b862f | 253 | if(strcmp(IndexTree,"date") == 0) { |
d6e703cc FM |
254 | if(strcmp(IndexSortOrder,"A") == 0) sprintf(warea,"sort -k 1,1 '%s' -o '%s'", wdir_tmp, wdir_tmp2); |
255 | else sprintf(warea,"sort -r -k 1,1 '%s' -o '%s'", wdir_tmp, wdir_tmp2); | |
456d78a5 FM |
256 | cstatus=system(warea); |
257 | if (!WIFEXITED(cstatus) || WEXITSTATUS(cstatus)) { | |
258 | fprintf(stderr, "SARG: sort command return status %d\n",WEXITSTATUS(cstatus)); | |
259 | fprintf(stderr, "SARG: sort command: %s\n",warea); | |
260 | exit(1); | |
261 | } | |
491b862f GS |
262 | if((fp_tmp=fopen(wdir_tmp2,"r"))==NULL) { |
263 | fprintf(stderr, "SARG: (index) %s: %s\n",text[45],wdir_tmp2); | |
456d78a5 | 264 | fprintf(stderr, "SARG: sort command: %s\n",warea); |
491b862f GS |
265 | exit(1); |
266 | } | |
456d78a5 | 267 | unlink(wdir_tmp); |
491b862f GS |
268 | if((fp_ou=fopen(wdir,"w"))==NULL) { |
269 | fprintf(stderr, "SARG: (index) %s: %s\n",text[45],wdir); | |
270 | exit(1); | |
271 | } | |
272 | write_html_header(fp_ou, "."); | |
d6e703cc | 273 | fprintf(fp_ou,"<tr><th %s>%s</th><th %s>%s</th></tr>\n",hbc1,text[130],hbc1,text[132]); |
491b862f | 274 | while(fgets(wwork1,MAXLEN,fp_tmp)!=NULL) { |
4bcb77cf FM |
275 | if (getword_multisep(tmp4,sizeof(tmp4),wwork1,' ')<0) { |
276 | printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",wdir_tmp2); | |
277 | exit(1); | |
278 | } | |
d6e703cc | 279 | fprintf(fp_ou,"<tr><td class=\"data2\"><a href=\"%s\">%s</a></td><td class=\"data2\">%s</td></tr>\n",tmp4,tmp4,wwork1); |
491b862f GS |
280 | sprintf(tmp2,"%s%s",outdir,tmp4); |
281 | sprintf(tmp3,"%s%s/index.unsort",outdir,tmp4); | |
282 | // Year dir | |
283 | if((fp_ou2=fopen(tmp3,"w"))==NULL) { | |
284 | fprintf(stderr, "SARG: (index) %s: %s\n",text[45],tmp3); | |
285 | exit(1); | |
286 | } | |
287 | dirp2 = opendir(tmp2); | |
288 | while ((direntp2 = readdir( dirp2 )) != NULL) { | |
d6e703cc FM |
289 | if(!isdigit(direntp2->d_name[0]) && !isdigit(direntp2->d_name[1])) continue; |
290 | fprintf(fp_ou2,"%s\n",direntp2->d_name); | |
491b862f GS |
291 | } |
292 | if(fp_ou2) fclose(fp_ou2); | |
293 | (void)rewinddir(dirp2); | |
294 | (void)closedir(dirp2); | |
295 | sprintf(wdir_tmp3,"%s%s/index.sort",outdir,tmp4); | |
d6e703cc FM |
296 | if(strcmp(IndexSortOrder,"A") == 0) sprintf(csort,"sort -n '%s' -o '%s'", tmp3, wdir_tmp3); |
297 | else sprintf(csort,"sort -n -r '%s' -o '%s'", tmp3, wdir_tmp3); | |
456d78a5 FM |
298 | cstatus=system(csort); |
299 | if (!WIFEXITED(cstatus) || WEXITSTATUS(cstatus)) { | |
300 | fprintf(stderr, "SARG: sort command return status %d\n",WEXITSTATUS(cstatus)); | |
301 | fprintf(stderr, "SARG: sort command: %s\n",csort); | |
302 | exit(1); | |
303 | } | |
491b862f GS |
304 | unlink(tmp3); |
305 | if((fp_tmp2=fopen(wdir_tmp3,"r"))==NULL) { | |
306 | fprintf(stderr, "SARG: (index) %s: %s\n",text[45],wdir_tmp3); | |
307 | exit(1); | |
308 | } | |
309 | sprintf(tmp3,"%s%s/index.html",outdir,tmp4); | |
310 | if((fp_ou2=fopen(tmp3,"w"))==NULL) { | |
311 | fprintf(stderr, "SARG: (index) %s: %s\n",text[45],wdir); | |
312 | exit(1); | |
313 | } | |
314 | write_html_header(fp_ou2,".."); | |
d6e703cc | 315 | fprintf(fp_ou2,"<tr><th %s>%s/%s</th></tr>\n",hbc1,text[130],text[131]); |
491b862f GS |
316 | while(fgets(wwork1,MAXLEN,fp_tmp2)!=NULL) { |
317 | wwork1[strlen(wwork1)-1]='\0'; | |
318 | strcpy(tmp5,wwork1); | |
319 | if(strstr(tmp5,"-") != 0) { | |
4bcb77cf FM |
320 | if (getword_multisep(warea,sizeof(warea),tmp5,'-')<0) { |
321 | printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",wdir_tmp3); | |
322 | exit(1); | |
323 | } | |
324 | name_month(warea,sizeof(warea)); | |
491b862f | 325 | sprintf(tmp6,"%s-",warea); |
4bcb77cf | 326 | name_month(tmp5,sizeof(tmp5)); |
491b862f GS |
327 | sprintf(nmonth,"%s%s",tmp6,tmp5); |
328 | } else { | |
329 | strcpy(nmonth,tmp5); | |
4bcb77cf | 330 | name_month(nmonth,sizeof(nmonth)); |
491b862f | 331 | } |
d6e703cc | 332 | fprintf(fp_ou2,"<tr><td class=\"data2\"><a href=\"%s\">%s %s</a></td></tr>\n",wwork1,tmp4,nmonth); |
491b862f GS |
333 | |
334 | sprintf(val1,"%s%s/%s",outdir,tmp4,wwork1); | |
335 | sprintf(tmp5,"%s%s/%s/index.unsort",outdir,tmp4,wwork1); | |
336 | if((fp_ou3=fopen(tmp5,"w"))==NULL) { | |
337 | fprintf(stderr, "SARG: (index) %s: %s\n",text[45],tmp5); | |
338 | exit(1); | |
339 | } | |
340 | // month dir | |
341 | dirp3 = opendir(val1); | |
342 | while ((direntp3 = readdir( dirp3 )) != NULL) { | |
d6e703cc FM |
343 | if(!isdigit(direntp3->d_name[0]) && !isdigit(direntp3->d_name[1])) continue; |
344 | fprintf(fp_ou3,"%s\n",direntp3->d_name); | |
491b862f GS |
345 | } |
346 | if(fp_ou3) fclose(fp_ou3); | |
347 | (void)rewinddir(dirp3); | |
348 | (void)closedir(dirp3); | |
349 | unlink(wdir_tmp3); | |
350 | sprintf(tmp6,"%s%s/%s/index.sort",outdir,tmp4,wwork1); | |
d6e703cc FM |
351 | if(strcmp(IndexSortOrder,"A") == 0) sprintf(csort,"sort -n '%s' -o '%s'", tmp5, tmp6); |
352 | else sprintf(csort,"sort -n -r '%s' -o '%s'", tmp5, tmp6); | |
456d78a5 FM |
353 | cstatus=system(csort); |
354 | if (!WIFEXITED(cstatus) || WEXITSTATUS(cstatus)) { | |
355 | fprintf(stderr, "SARG: sort command return status %d\n",WEXITSTATUS(cstatus)); | |
356 | fprintf(stderr, "SARG: sort command: %s\n",csort); | |
357 | exit(1); | |
358 | } | |
491b862f GS |
359 | unlink(tmp5); |
360 | sprintf(val2,"%s%s/%s/index.html",outdir,tmp4,wwork1); | |
361 | sprintf(val3,"%s/%s",tmp4,wwork1); | |
362 | unlink(val2); | |
363 | if((fp_ou3=fopen(val2,"w"))==NULL) { | |
364 | fprintf(stderr, "SARG: (index) %s: %s\n",text[45],val2); | |
365 | exit(1); | |
366 | } | |
367 | if((fp_tmp3=fopen(tmp6,"r"))==NULL) { | |
368 | fprintf(stderr, "SARG: (index) %s: %s\n",text[45],tmp6); | |
369 | exit(1); | |
370 | } | |
371 | write_html_header(fp_ou3,"../.."); | |
d6e703cc | 372 | fprintf(fp_ou3,"<tr><th %s>%s/%s/%s</th></tr>\n",hbc1,text[130],text[131],text[127]); |
491b862f GS |
373 | while(fgets(warea,MAXLEN,fp_tmp3)!=NULL) { |
374 | warea[strlen(warea)-1]='\0'; | |
d6e703cc | 375 | fprintf(fp_ou3,"<tr><td class=\"data2\"><a href=\"%s\">%s %s %s</a></td></tr>\n",warea,tmp4,nmonth,warea); |
491b862f GS |
376 | } |
377 | if(fp_tmp3) fclose(fp_tmp3); | |
491b862f | 378 | write_html_trailer(fp_ou3); |
121c2a89 | 379 | if(fp_ou3) fclose(fp_ou3); |
491b862f GS |
380 | unlink(tmp6); |
381 | } | |
382 | write_html_trailer(fp_ou2); | |
383 | if(fp_ou2) fclose(fp_ou2); | |
384 | } | |
385 | (void)rewinddir(dirp); | |
386 | (void)closedir(dirp); | |
387 | write_html_trailer(fp_ou); | |
388 | if(fp_ou) fclose(fp_ou); | |
389 | if(fp_tmp) fclose(fp_tmp); | |
390 | unlink(tmp6); | |
391 | unlink(wdir_tmp2); | |
392 | } else { | |
d6e703cc FM |
393 | if(strcmp(IndexSortOrder,"A") == 0) sprintf(warea,"sort -t';' -k 7,7 -k 1,1 '%s' -o '%s'", wdir_tmp, wdir_tmp2); |
394 | else sprintf(warea,"sort -r -t';' -k 7,7 -k 1,1 '%s' -o '%s'", wdir_tmp, wdir_tmp2); | |
456d78a5 FM |
395 | cstatus=system(warea); |
396 | if (!WIFEXITED(cstatus) || WEXITSTATUS(cstatus)) { | |
397 | fprintf(stderr, "SARG: sort command return status %d\n",WEXITSTATUS(cstatus)); | |
398 | fprintf(stderr, "SARG: sort command: %s\n",warea); | |
399 | exit(1); | |
400 | } | |
401 | if((fp_tmp2=fopen(wdir_tmp2,"r"))==NULL) { | |
402 | fprintf(stderr, "SARG: (index) %s: %s\n",text[45],wdir_tmp2); | |
403 | fprintf(stderr, "SARG: sort command: %s\n",warea); | |
404 | exit(1); | |
405 | } | |
491b862f GS |
406 | unlink(wdir_tmp); |
407 | if((fp_ou=fopen(wdir,"w"))==NULL) { | |
408 | fprintf(stderr, "SARG: (index) %s: %s\n",text[45],wdir); | |
409 | exit(1); | |
410 | } | |
411 | write_html_header(fp_ou,"."); | |
d6e703cc | 412 | fprintf(fp_ou,"<tr><th %s>%s</th><th %s>%s</th><th %s>%s</th><th %s>%s</th><th %s>%s</th></tr>\n",hbc1,text[101],hbc1,text[102],hbc1,text[103],hbc1,text[93],hbc1,text[96]); |
491b862f | 413 | while(fgets(buf,MAXLEN,fp_tmp2)!=NULL) { |
4bcb77cf FM |
414 | if (getword_multisep(period,sizeof(period),buf,';')<0) { |
415 | printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",wdir_tmp2); | |
416 | exit(1); | |
417 | } | |
418 | if (getword_multisep(period,sizeof(period),buf,';')<0) { | |
419 | printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",wdir_tmp2); | |
420 | exit(1); | |
421 | } | |
422 | if (getword_multisep(data,sizeof(data),buf,';')<0) { | |
423 | printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",wdir_tmp2); | |
424 | exit(1); | |
425 | } | |
426 | if (getword_multisep(tuser,sizeof(tuser),buf,';')<0) { | |
427 | printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",wdir_tmp2); | |
428 | exit(1); | |
429 | } | |
430 | if (getword_multisep(tbytes,sizeof(tbytes),buf,';')<0) { | |
431 | printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",wdir_tmp2); | |
432 | exit(1); | |
433 | } | |
434 | if (getword_multisep(media,sizeof(media),buf,';')<0) { | |
435 | printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",wdir_tmp2); | |
436 | exit(1); | |
437 | } | |
d6e703cc | 438 | fprintf(fp_ou,"<tr><td class=\"data2\"><a href='%s/%s'>%s</a></td><td class=\"data2\">%s</td><td class=\"data\">%s</td><td class=\"data\">%s</td><td class=\"data\">%s</td></tr>\n",period,ReplaceIndex,period,data,tuser,tbytes,media); |
491b862f GS |
439 | } |
440 | if(fp_tmp2) fclose(fp_tmp2); | |
441 | unlink(wdir_tmp2); | |
25697a35 | 442 | } |
491b862f | 443 | |
d6e703cc | 444 | fputs("</table></center>",fp_ou); |
25697a35 GS |
445 | |
446 | zdate(ftime, DateFormat); | |
447 | ||
448 | show_info(fp_ou); | |
449 | ||
d6e703cc | 450 | fputs("</body>\n</html>\n",fp_ou); |
25697a35 | 451 | } |