]> git.ipfire.org Git - thirdparty/sarg.git/blob - index.c
5a50d682640c33eaf4abdc4fdd9ff88ca1e5c39f
[thirdparty/sarg.git] / index.c
1 /*
2 * SARG Squid Analysis Report Generator http://sarg.sourceforge.net
3 * 1998, 2010
4 *
5 * SARG donations:
6 * please look at http://sarg.sourceforge.net/donations.php
7 * Support:
8 * http://sourceforge.net/projects/sarg/forums/forum/363374
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"
28 #include "include/defs.h"
29
30 static void make_date_index(void);
31 static void make_file_index(void);
32 static void file_index_to_date_index(const char *entry);
33 static void date_index_to_file_index(const char *entry);
34
35 void make_index(void)
36 {
37 DIR *dirp;
38 struct dirent *direntp;
39 char wdir[MAXLEN];
40
41 if(LastLog > 0) mklastlog(outdir);
42
43 if(Index == INDEX_NO) {
44 sprintf(wdir,"%sindex.html",outdir);
45 if(access(wdir, R_OK) == 0) unlink(wdir);
46 return;
47 }
48
49 if(debug) debuga("%s",text[53]);
50
51 // convert any old report hierarchy
52 dirp = opendir(outdir);
53 while ((direntp = readdir( dirp )) != NULL) {
54 if(isdigit(direntp->d_name[0]) && isdigit(direntp->d_name[1])) {
55 if(IndexTree == INDEX_TREE_DATE)
56 file_index_to_date_index(direntp->d_name);
57 else
58 date_index_to_file_index(direntp->d_name);
59 }
60 }
61 closedir(dirp);
62
63 if(IndexTree == INDEX_TREE_DATE) {
64 make_date_index();
65 } else {
66 make_file_index();
67 }
68 }
69
70 static void make_date_index(void)
71 {
72 FILE *fp_ou, *fp_ou2, *fp_ou3;
73 DIR *dirp, *dirp2, *dirp3;
74 struct dirent *direntp;
75 struct dirent *direntp2;
76 struct dirent *direntp3;
77 char yearindex[MAXLEN];
78 char yeardir[MAXLEN];
79 char yearnum[10];
80 char monthindex[MAXLEN];
81 char monthdir[MAXLEN];
82 char monthname1[9], monthname2[9];
83 char nmonth[30];
84 char monthnum[10];
85 char dayindex[MAXLEN];
86 char daynum[10];
87 int yearsort[150];
88 int nyears;
89 int year;
90 int monthsort[144];
91 int nmonths;
92 int m1, m2, month;
93 int daysort[31*31];
94 int ndays;
95 int d1, d2, day;
96 int i, y, m, d;
97 int order;
98
99 sprintf(yearindex,"%sindex.html",outdir);
100
101 nyears=0;
102 dirp = opendir(outdir);
103 while ((direntp = readdir( dirp )) != NULL) {
104 if(strlen(direntp->d_name) > 4 || !isdigit(direntp->d_name[0]) || !isdigit(direntp->d_name[1]) ||
105 !isdigit(direntp->d_name[2]) || !isdigit(direntp->d_name[3])) continue;
106 year=atoi(direntp->d_name);
107 if (nyears>=sizeof(yearsort)/sizeof(yearsort[0])) {
108 /*
109 If too many years are listed in the directory, we ignore the earliest years. The yearsort array
110 is big enough to accomodate the most ambitious use of sarg but this safety is added to prevent
111 a crash should the directory be polluted by other entries.
112 */
113 if (year>yearsort[0]) {
114 for (i=1 ; i<nyears && year>yearsort[i] ; i++)
115 yearsort[i-1]=yearsort[i];
116 yearsort[i-1]=year;
117 }
118 } else {
119 for (i=nyears ; i>0 && year<yearsort[i-1] ; i--) {
120 yearsort[i]=yearsort[i-1];
121 }
122 yearsort[i]=year;
123 nyears++;
124 }
125 }
126 (void)closedir( dirp );
127
128 order=(strcmp(IndexSortOrder,"A") == 0) ? 1 : -1;
129
130 if((fp_ou=fopen(yearindex,"w"))==NULL) {
131 fprintf(stderr, "SARG: (index) %s: %s - %s\n",text[45],yearindex,strerror(errno));
132 exit(1);
133 }
134 write_html_header(fp_ou, ".");
135 fprintf(fp_ou,"<tr><th class=\"header_l\">%s</th><th class=\"header_l\">%s</th></tr>\n",text[130],text[132]);
136 for (y=0 ; y<nyears ; y++) {
137 if (order>0)
138 year=yearsort[y];
139 else
140 year=yearsort[nyears-1-y];
141 sprintf(yearnum,"%04d",year);
142 fprintf(fp_ou,"<tr><td class=\"data2\"><a href=\"%s/index.html\">%s</a></td><td class=\"data2\">%s</td></tr>\n",yearnum,yearnum,get_size(outdir,yearnum));
143 sprintf(yeardir,"%s%s",outdir,yearnum);
144 // Year dir
145 nmonths=0;
146 dirp2 = opendir(yeardir);
147 while ((direntp2 = readdir( dirp2 )) != NULL) {
148 if(!isdigit(direntp2->d_name[0]) || !isdigit(direntp2->d_name[1])) continue;
149 i=-1;
150 if (sscanf(direntp2->d_name,"%d%n",&m1,&i)!=1 || m1<=0 || m1>12 || i<0) continue;
151 if (direntp2->d_name[i]=='-') {
152 if (sscanf(direntp2->d_name+i+1,"%d",&m2)!=1 || m2<m1 || m2>12) continue;
153 } else if (direntp2->d_name[i]!='\0') {
154 continue;
155 } else {
156 m2=0;
157 }
158 if (nmonths>=sizeof(monthsort)/sizeof(monthsort[0])) {
159 fprintf(stderr,"SARG: Too many month directories in %s\nSupernumerary entries are ignored\n",yeardir);
160 break;
161 }
162 month=m1*16+m2;
163 for (i=nmonths ; i>0 && month<monthsort[i-1] ; i--) {
164 monthsort[i]=monthsort[i-1];
165 }
166 monthsort[i]=month;
167 nmonths++;
168 }
169 (void)closedir(dirp2);
170 sprintf(monthindex,"%s/index.html",yeardir);
171 if((fp_ou2=fopen(monthindex,"w"))==NULL) {
172 fprintf(stderr, "SARG: (index) %s: %s - %s\n",text[45],monthindex,strerror(errno));
173 exit(1);
174 }
175 write_html_header(fp_ou2,"..");
176 fprintf(fp_ou2,"<tr><th class=\"header_l\">%s/%s</th></tr>\n",text[130],text[131]);
177 for (m=0 ; m<nmonths ; m++) {
178 if (order>0)
179 month=monthsort[m];
180 else
181 month=monthsort[nmonths-1-m];
182 m1=month / 16;
183 if(month % 16 != 0) {
184 m2=month % 16;
185 sprintf(monthnum,"%02d-%02d",m1,m2);
186 sprintf(monthname1,"%02d",m1);
187 sprintf(monthname2,"%02d",m2);
188 name_month(monthname1,sizeof(monthname1));
189 name_month(monthname2,sizeof(monthname2));
190 sprintf(nmonth,"%s-%s",monthname1,monthname2);
191 } else {
192 sprintf(nmonth,"%02d",m1);
193 sprintf(monthnum,"%02d",m1);
194 name_month(nmonth,sizeof(nmonth));
195 }
196 fprintf(fp_ou2,"<tr><td class=\"data2\"><a href=\"%s/index.html\">%s %s</a></td></tr>\n",monthnum,yearnum,nmonth);
197
198 sprintf(monthdir,"%s/%s",yeardir,monthnum);
199 // month dir
200 ndays=0;
201 dirp3 = opendir(monthdir);
202 while ((direntp3 = readdir( dirp3 )) != NULL) {
203 if(!isdigit(direntp3->d_name[0]) && !isdigit(direntp3->d_name[1])) continue;
204 i=-1;
205 if (sscanf(direntp3->d_name,"%d%n",&d1,&i)!=1 || d1<=0 || d1>31 || i<0) continue;
206 if (direntp3->d_name[i]=='-') {
207 if (sscanf(direntp3->d_name+i+1,"%d",&d2)!=1 || d2<d1 || d2>31) continue;
208 } else if (direntp3->d_name[i]!='\0') {
209 continue;
210 } else {
211 d2=0;
212 }
213 if (ndays>=sizeof(daysort)/sizeof(daysort[0])) {
214 fprintf(stderr,"SARG: Too many day directories in %s\nSupernumerary entries are ignored\n",monthdir);
215 break;
216 }
217 day=d1*32+d2;
218 for (i=ndays ; i>0 && day<daysort[i-1] ; i--) {
219 daysort[i]=daysort[i-1];
220 }
221 daysort[i]=day;
222 ndays++;
223 }
224 (void)closedir(dirp3);
225 sprintf(dayindex,"%s/index.html",monthdir);
226 if((fp_ou3=fopen(dayindex,"w"))==NULL) {
227 fprintf(stderr, "SARG: (index) %s: %s - %s\n",text[45],dayindex,strerror(errno));
228 exit(1);
229 }
230 write_html_header(fp_ou3,"../..");
231 fprintf(fp_ou3,"<tr><th class=\"header_l\">%s/%s/%s</th></tr>\n",text[130],text[131],text[127]);
232 for (d=0 ; d<ndays ; d++) {
233 if (order>0)
234 day=daysort[d];
235 else
236 day=daysort[ndays-1-d];
237 d1=day / 32;
238 if(day % 32 != 0) {
239 d2=day % 32;
240 sprintf(daynum,"%02d-%02d",d1,d2);
241 } else {
242 sprintf(daynum,"%02d",d1);
243 }
244 fprintf(fp_ou3,"<tr><td class=\"data2\"><a href=\"%s/index.html\">%s %s %s</a></td></tr>\n",daynum,yearnum,nmonth,daynum);
245 }
246 write_html_trailer(fp_ou3);
247 fclose(fp_ou3);
248 }
249 write_html_trailer(fp_ou2);
250 fclose(fp_ou2);
251 }
252
253 write_html_trailer(fp_ou);
254 fclose(fp_ou);
255 }
256
257 static void make_file_index(void)
258 {
259 #define MAX_CREATION_DATE 15
260 #define MAX_DIR_NAME 30
261 FILE *fp_ou;
262 DIR *dirp;
263 struct dirent *direntp;
264 char wdir[MAXLEN];
265 char month[4];
266 char data[80];
267 char tuser[20];
268 char tbytes[20];
269 char media[20];
270 char ftime[128];
271 char day[6], mon[8], year[40], hour[10];
272 int iyear, imonth, iday, ihour, iminute, isecond, idst;
273 int nsort;
274 int nallocated;
275 int order;
276 int i;
277 int cmp;
278 struct getwordstruct gwarea;
279 struct sortstruct
280 {
281 char sortname[9];
282 char creationdate[MAX_CREATION_DATE];
283 char dirname[MAX_DIR_NAME];
284 char date[60];
285 } **sortlist, *item, **tempsort;
286
287 sprintf(wdir,"%sindex.html",outdir);
288
289 order=(strcmp(IndexSortOrder,"A") == 0) ? 1 : -1;
290
291 dirp = opendir(outdir);
292
293 nsort=0;
294 nallocated=0;
295 sortlist=NULL;
296 while ((direntp = readdir( dirp )) != NULL) {
297 if (strchr(direntp->d_name,'-') == 0) continue;
298 if (strlen(direntp->d_name)>MAX_DIR_NAME) continue;
299 item=malloc(sizeof(*item));
300 if (!item) {
301 fprintf(stderr,"SARG: not enough memory to sort the index\n");
302 exit(1);
303 }
304 if(strcmp(df,"u") == 0) {
305 strncpy(item->sortname,direntp->d_name,4);
306 strncpy(month,direntp->d_name+4,3);
307 } else {
308 strncpy(item->sortname,direntp->d_name+5,4);
309 strncpy(month,direntp->d_name+2,3);
310 }
311 item->sortname[4]='\0';
312 month[3]='\0';
313 conv_month(month);
314 strcat(item->sortname,month);
315 if(strcmp(df,"u") == 0) strncat(item->sortname,direntp->d_name+7,2);
316 else strncat(item->sortname,direntp->d_name,2);
317 obtdate(outdir,direntp->d_name,data);
318 if (sscanf(data,"%d-%d-%d %d:%d:%d %d",&iyear,&imonth,&iday,&ihour,&iminute,&isecond,&idst)==7) {
319 formatdate(data,sizeof(data),iyear,imonth,iday,ihour,iminute,isecond,idst);
320 snprintf(item->creationdate,sizeof(item->creationdate),"%04d%02d%02d%02d%02d%02d",iyear,imonth,iday,ihour,iminute,isecond);
321 } else {
322 /*
323 Old code to parse a date stored by sarg before 2.2.6.1 in the sarg-date file of each report directory.
324 */
325 getword_start(&gwarea,data);
326 if (getword_skip(16,&gwarea,' ')<0) {
327 printf("SARG: Maybe you have a broken week day in your %s%s/sarg-date file.\n",outdir,direntp->d_name);
328 exit(1);
329 }
330 if (getword_multisep(mon,sizeof(mon),&gwarea,' ')<0) {
331 printf("SARG: Maybe you have a broken month in your %s%s/sarg-date file.\n",outdir,direntp->d_name);
332 exit(1);
333 }
334 if (getword_multisep(day,sizeof(day),&gwarea,' ')<0) {
335 printf("SARG: Maybe you have a broken day in your %s%s/sarg-date file.\n",outdir,direntp->d_name);
336 exit(1);
337 }
338 if (getword_multisep(hour,sizeof(hour),&gwarea,' ')<0) {
339 printf("SARG: Maybe you have a broken time in your %s%s/sarg-date file.\n",outdir,direntp->d_name);
340 exit(1);
341 }
342 do {
343 if (getword_multisep(year,sizeof(year),&gwarea,' ')<0) {
344 printf("SARG: Maybe you have a broken year in your %s%s/sarg-date file.\n",outdir,direntp->d_name);
345 exit(1);
346 }
347 } while (year[0] && !isdigit(year[0])); //skip time zone information with spaces until the year is found
348 if (sscanf(hour,"%d:%d:%d",&ihour,&iminute,&isecond)!=3) {
349 printf("SARG: Maybe you have a broken time in your %s%s/sarg-date file.\n",outdir,direntp->d_name);
350 exit(1);
351 }
352 buildymd(day,mon,year,ftime);
353 snprintf(item->creationdate,sizeof(item->creationdate),"%s%02d%02d%02d",ftime, ihour, iminute, isecond);
354 }
355 strcpy(item->dirname,direntp->d_name);
356 strncpy(item->date,data,sizeof(item->date));
357 if (nsort+1>nallocated) {
358 nallocated+=10;
359 tempsort=realloc(sortlist,nallocated*sizeof(*item));
360 if (!tempsort) {
361 fprintf(stderr,"SARG: not enough memory to sort the index\n");
362 exit(1);
363 }
364 sortlist=tempsort;
365 }
366 for (i=nsort ; i>0 ; i--) {
367 cmp=strcmp(item->sortname,sortlist[i-1]->sortname);
368 if (cmp==0) cmp=strcmp(item->creationdate,sortlist[i-1]->creationdate);
369 if (cmp>=0) {
370 break;
371 }
372 sortlist[i]=sortlist[i-1];
373 }
374 sortlist[i]=item;
375 nsort++;
376 }
377
378 (void)closedir( dirp );
379
380 if((fp_ou=fopen(wdir,"w"))==NULL) {
381 fprintf(stderr, "SARG: (index) %s: %s\n",text[45],wdir);
382 exit(1);
383 }
384 write_html_header(fp_ou,".");
385 fprintf(fp_ou,"<tr><th class=\"header_l\">%s</th><th class=\"header_l\">%s</th><th class=\"header_l\">%s</th><th class=\"header_l\">%s</th><th class=\"header_l\">%s</th></tr>\n",text[101],text[102],text[103],text[93],text[96]);
386 for (i=0 ; i<nsort ; i++) {
387 if (order>0)
388 item=sortlist[i];
389 else
390 item=sortlist[nsort-i-1];
391 obtuser(outdir,item->dirname,tuser);
392 obttotal(outdir,item->dirname,tbytes,tuser,media);
393 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",item->dirname,ReplaceIndex,item->dirname,item->date,tuser,tbytes,media);
394 }
395 write_html_trailer(fp_ou);
396 fclose(fp_ou);
397
398 if (sortlist) {
399 for (i=0 ; i<nsort ; i++)
400 free(sortlist[i]);
401 free(sortlist);
402 }
403 }
404
405 static void file_index_to_date_index(const char *entry)
406 {
407 int y1, y2, d1, d2;
408 int i, j;
409 int ndirlen;
410 int monthlen;
411 char m1[8], m2[8];
412 char olddir[MAXLEN], newdir[MAXLEN];
413
414 if(strlen(entry) < 19) return;
415
416 y1=0;
417 y2=0;
418 memset(m1,0,sizeof(m1));
419 memset(m2,0,sizeof(m2));
420 d1=0;
421 d2=0;
422 i=0;
423 if(strcmp(df,"u") == 0) {
424 for (j=0 ; entry[i] && isdigit(entry[i]) ; j++)
425 y1=y1*10+(entry[i++]-'0');
426 if (j!=4) return;
427 for (j=0 ; j<sizeof(m1)-1 && entry[i] && isalpha(entry[i]) ; j++)
428 m1[j]=entry[i++];
429 if (j!=3) return;
430 m1[j]='\0';
431 for (j=0 ; entry[i] && isdigit(entry[i]) ; j++)
432 d1=d1*10+(entry[i++]-'0');
433 if (j!=2) return;
434
435 if (entry[i++]!='-') return;
436
437 for (j=0 ; entry[i] && isdigit(entry[i]) ; j++)
438 y2=y2*10+(entry[i++]-'0');
439 if (j!=4) return;
440 for (j=0 ; j<sizeof(m2)-1 && entry[i] && isalpha(entry[i]) ; j++)
441 m2[j]=entry[i++];
442 if (j!=3) return;
443 m2[j]='\0';
444 for (j=0 ; entry[i] && isdigit(entry[i]) ; j++)
445 d2=d2*10+(entry[i++]-'0');
446 if (j!=2) return;
447 } else if(strcmp(df,"e") == 0) {
448 for (j=0 ; entry[i] && isdigit(entry[i]) ; j++)
449 d1=d1*10+(entry[i++]-'0');
450 if (j!=2) return;
451 for (j=0 ; j<sizeof(m1)-1 && entry[i] && isalpha(entry[i]) ; j++)
452 m1[j]=entry[i++];
453 if (j!=3) return;
454 m1[j]='\0';
455 for (j=0 ; entry[i] && isdigit(entry[i]) ; j++)
456 y1=y1*10+(entry[i++]-'0');
457 if (j!=4) return;
458
459 if (entry[i++]!='-') return;
460
461 for (j=0 ; entry[i] && isdigit(entry[i]) ; j++)
462 d2=d2*10+(entry[i++]-'0');
463 if (j!=2) return;
464 for (j=0 ; j<sizeof(m2)-1 && entry[i] && isalpha(entry[i]) ; j++)
465 m2[j]=entry[i++];
466 if (j!=3) return;
467 m2[j]='\0';
468 for (j=0 ; entry[i] && isdigit(entry[i]) ; j++)
469 y2=y2*10+(entry[i++]-'0');
470 if (j!=4) return;
471 } else
472 return;
473
474 conv_month(m1);
475 conv_month(m2);
476 ndirlen=sprintf(newdir,"%s%04d",outdir,y1);
477 if(access(newdir, R_OK) != 0) mkdir(newdir,0755);
478 if(strcmp(m1,m2) != 0) ndirlen+=sprintf(newdir+ndirlen,"/%s-%s",m1,m2);
479 else ndirlen+=sprintf(newdir+ndirlen,"/%s",m1);
480 if(access(newdir, R_OK) != 0) mkdir(newdir,0755);
481 monthlen=ndirlen;
482 if(d1!=d2) ndirlen+=sprintf(newdir+ndirlen,"/%02d-%02d",d1,d2);
483 else ndirlen+=sprintf(newdir+ndirlen,"/%02d",d1);
484
485 sprintf(olddir,"%s%s",outdir,entry);
486 if (rename(olddir,newdir)) {
487 fprintf(stderr, "SARG: (index) rename error from \"%s\" to \"%s\" - %s\n",olddir,newdir,strerror(errno));
488 exit(1);
489 }
490
491 strcpy(newdir+monthlen,"/images");
492 if(access(newdir, R_OK) != 0) {
493 #ifdef HAVE_SYMLINK
494 char linkdir[MAXLEN];
495
496 sprintf(linkdir,"%simages",outdir);
497 if (symlink(linkdir,newdir)) {
498 fprintf(stderr, "SARG: failed to create link \"%s\" to \"%s\" - %s\n",linkdir,newdir,strerror(errno));
499 exit(1);
500 }
501 #else
502 char cmd[MAXLEN];
503 int cstatus;
504
505 sprintf(cmd,"ln -s \"%simages\" \"%s/images\"",outdir,newdir);
506 cstatus=system(cmd);
507 if (!WIFEXITED(cstatus) || WEXITSTATUS(cstatus)) {
508 fprintf(stderr, "SARG: command return status %d\n",WEXITSTATUS(cstatus));
509 fprintf(stderr, "SARG: command: %s\n",cmd);
510 exit(1);
511 }
512 #endif
513 }
514 }
515
516 static void date_index_to_file_index(const char *entry)
517 {
518 int y1, next;
519 int val1len;
520 int d1, d2;
521 int i, j;
522 char val1[MAXLEN];
523 char m1[8], m2[8];
524 char *str;
525 char newdir[MAXLEN], olddir[MAXLEN];
526 DIR *dirp2, *dirp3;
527 struct dirent *direntp2;
528 struct dirent *direntp3;
529
530 if(strlen(entry) != 4) return;
531
532 next=-1;
533 if (sscanf(entry,"%d%n",&y1,&next)!=1 || next<0 || entry[next]) return;
534
535 val1len=sprintf(val1,"%s%s",outdir,entry);
536 dirp2 = opendir(val1);
537 if (!dirp2) return;
538 while ((direntp2 = readdir( dirp2 )) != NULL) {
539 if(!isdigit(direntp2->d_name[0]) || !isdigit(direntp2->d_name[1])) continue;
540 i=0;
541 str=direntp2->d_name;
542 for (j=0 ; j<sizeof(m1) && str[i] && isdigit(str[i]) ; j++)
543 m1[j]=str[i++];
544 if (j>=sizeof(m1)) continue;
545 m1[j]='\0';
546 conv_month_name(m1);
547 if (str[i]=='-') {
548 i++;
549 for (j=0 ; j<sizeof(m2) && str[i] && isdigit(str[i]) ; j++)
550 m2[j]=str[i++];
551 if (j>=sizeof(m2)) continue;
552 m2[j]='\0';
553 conv_month_name(m2);
554 } else if (!str[i]) {
555 strcpy(m2,m1);
556 } else {
557 continue;
558 }
559
560 sprintf(val1+val1len,"/%s",direntp2->d_name);
561 dirp3 = opendir(val1);
562 if (!dirp3) continue;
563 while ((direntp3 = readdir( dirp3 )) != NULL) {
564 if(!isdigit(direntp3->d_name[0]) || !isdigit(direntp3->d_name[1])) continue;
565 i=0;
566 str=direntp3->d_name;
567 d1=0;
568 for (j=0 ; str[i] && isdigit(str[i]) ; j++)
569 d1=d1*10+(str[i++]-'0');
570 if (j!=2) continue;
571 if (str[i]=='-') {
572 i++;
573 d2=0;
574 for (j=0 ; str[i] && isdigit(str[i]) ; j++)
575 d2=d2*10+(str[i++]-'0');
576 if (j!=2) continue;
577 } else if (!str[i]) {
578 d2=d1;
579 } else {
580 continue;
581 }
582
583 if(strcmp(df,"u") == 0) sprintf(newdir,"%s%04d%s%02d-%04d%s%02d",outdir,y1,m1,d1,y1,m2,d2);
584 else if(strcmp(df,"e") == 0) sprintf(newdir,"%s%02d%s%04d-%02d%s%04d",outdir,d1,m1,y1,d2,m2,y1);
585 else continue;
586 sprintf(olddir,"%s%04d/%s/%s",outdir,y1,direntp2->d_name,direntp3->d_name);
587 if(rename(olddir,newdir)) {
588 fprintf(stderr, "SARG: (index) rename error from \"%s\" to \"%s\" - %s\n",olddir,newdir,strerror(errno));
589 exit(1);
590 }
591 }
592 (void)closedir( dirp3 );
593 }
594 (void)closedir( dirp2 );
595
596 /*!
597 \bug The links to the images in the reports are broken after moving the directories
598 as the the HTML files are not at the right level for the images any more.
599 */
600 }
601