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