]> git.ipfire.org Git - thirdparty/sarg.git/blob - index.c
ffd57c595a2d7a68d160bd805cf13c7e52954ce5
[thirdparty/sarg.git] / index.c
1 /*
2 * AUTHOR: Pedro Lineu Orso pedro.orso@gmail.com
3 * 1998, 2010
4 * SARG Squid Analysis Report Generator http://sarg.sourceforge.net
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 #include "include/defs.h"
28
29 static void make_date_index(void);
30 static void make_file_index(void);
31 static void file_index_to_date_index(const char *entry);
32 static void date_index_to_file_index(const char *entry);
33
34 void make_index(void)
35 {
36 DIR *dirp;
37 struct dirent *direntp;
38 char wdir[MAXLEN];
39
40 if(LastLog[0] != '\0') mklastlog(outdir);
41
42 if(strcmp(Index,"no") == 0) {
43 sprintf(wdir,"%sindex.html",outdir);
44 if(access(wdir, R_OK) == 0) unlink(wdir);
45 return;
46 }
47
48 if(debug) debuga("%s",text[53]);
49
50 // convert any old report hierarchy
51 dirp = opendir(outdir);
52 while ((direntp = readdir( dirp )) != NULL) {
53 if(isdigit(direntp->d_name[0]) && isdigit(direntp->d_name[1])) {
54 if(strcmp(IndexTree,"date") == 0)
55 file_index_to_date_index(direntp->d_name);
56 else
57 date_index_to_file_index(direntp->d_name);
58 }
59 }
60
61 if(strcmp(IndexTree,"date") == 0) {
62 make_date_index();
63 } else {
64 make_file_index();
65 }
66 }
67
68 static void make_date_index(void)
69 {
70 FILE *fp_ou, *fp_ou2, *fp_ou3;
71 DIR *dirp, *dirp2, *dirp3;
72 struct dirent *direntp;
73 struct dirent *direntp2;
74 struct dirent *direntp3;
75 char hbc1[30];
76 char yearindex[MAXLEN];
77 char yeardir[MAXLEN];
78 char yearnum[10];
79 char monthindex[MAXLEN];
80 char monthdir[MAXLEN];
81 char monthname1[9], monthname2[9];
82 char nmonth[30];
83 char monthnum[10];
84 char dayindex[MAXLEN];
85 char daynum[10];
86 int yearsort[150];
87 int nyears;
88 int year;
89 int monthsort[144];
90 int nmonths;
91 int m1, m2, month;
92 int daysort[31*31];
93 int ndays;
94 int d1, d2, day;
95 int i, y, m, d;
96 int order;
97
98 sprintf(yearindex,"%sindex.html",outdir);
99 strcpy(hbc1,"class=\"header\"");
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 %s>%s</th><th %s>%s</th></tr>\n",hbc1,text[130],hbc1,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 %s>%s/%s</th></tr>\n",hbc1,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 %s>%s/%s/%s</th></tr>\n",hbc1,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 strcpy(hbc1,"class=\"header\"");
289
290 order=(strcmp(IndexSortOrder,"A") == 0) ? 1 : -1;
291
292 dirp = opendir(outdir);
293
294 nsort=0;
295 nallocated=0;
296 sortlist=NULL;
297 while ((direntp = readdir( dirp )) != NULL) {
298 if (strchr(direntp->d_name,'-') == 0) continue;
299 if (strlen(direntp->d_name)>MAX_DIR_NAME) continue;
300 item=malloc(sizeof(*item));
301 if (!item) {
302 fprintf(stderr,"SARG: not enough memory to sort the index\n");
303 exit(1);
304 }
305 if(strcmp(df,"u") == 0) {
306 strncpy(item->sortname,direntp->d_name,4);
307 strncpy(month,direntp->d_name+4,3);
308 } else {
309 strncpy(item->sortname,direntp->d_name+5,4);
310 strncpy(month,direntp->d_name+2,3);
311 }
312 item->sortname[4]='\0';
313 month[3]='\0';
314 conv_month(month);
315 strcat(item->sortname,month);
316 if(strcmp(df,"u") == 0) strncat(item->sortname,direntp->d_name+7,2);
317 else strncat(item->sortname,direntp->d_name,2);
318 obtdate(outdir,direntp->d_name,data);
319 if (sscanf(data,"%d-%d-%d %d:%d:%d %d",&iyear,&imonth,&iday,&ihour,&iminute,&isecond,&idst)==7) {
320 formatdate(data,sizeof(data),iyear,imonth,iday,ihour,iminute,isecond,idst);
321 snprintf(item->creationdate,sizeof(item->creationdate),"%04d%02d%02d%02d%02d%02d",iyear,imonth,iday,ihour,iminute,isecond);
322 } else {
323 /*
324 Old code to parse a date stored by sarg before 2.2.6.1 in the sarg-date file of each report directory.
325 */
326 getword_start(&gwarea,data);
327 if (getword_skip(16,&gwarea,' ')<0) {
328 printf("SARG: Maybe you have a broken week day in your %s%s/sarg-date file.\n",outdir,direntp->d_name);
329 exit(1);
330 }
331 if (getword_multisep(mon,sizeof(mon),&gwarea,' ')<0) {
332 printf("SARG: Maybe you have a broken month in your %s%s/sarg-date file.\n",outdir,direntp->d_name);
333 exit(1);
334 }
335 if (getword_multisep(day,sizeof(day),&gwarea,' ')<0) {
336 printf("SARG: Maybe you have a broken day in your %s%s/sarg-date file.\n",outdir,direntp->d_name);
337 exit(1);
338 }
339 if (getword_multisep(hour,sizeof(hour),&gwarea,' ')<0) {
340 printf("SARG: Maybe you have a broken time in your %s%s/sarg-date file.\n",outdir,direntp->d_name);
341 exit(1);
342 }
343 do {
344 if (getword_multisep(year,sizeof(year),&gwarea,' ')<0) {
345 printf("SARG: Maybe you have a broken year in your %s%s/sarg-date file.\n",outdir,direntp->d_name);
346 exit(1);
347 }
348 } while (year[0] && !isdigit(year[0])); //skip time zone information with spaces until the year is found
349 if (sscanf(hour,"%d:%d:%d",&ihour,&iminute,&isecond)!=3) {
350 printf("SARG: Maybe you have a broken time in your %s%s/sarg-date file.\n",outdir,direntp->d_name);
351 exit(1);
352 }
353 buildymd(day,mon,year,ftime);
354 snprintf(item->creationdate,sizeof(item->creationdate),"%s%02d%02d%02d",ftime, ihour, iminute, isecond);
355 }
356 strcpy(item->dirname,direntp->d_name);
357 strncpy(item->date,data,sizeof(item->date));
358 if (nsort+1>nallocated) {
359 nallocated+=10;
360 tempsort=realloc(sortlist,nallocated*sizeof(*item));
361 if (!tempsort) {
362 fprintf(stderr,"SARG: not enough memory to sort the index\n");
363 exit(1);
364 }
365 sortlist=tempsort;
366 }
367 for (i=nsort ; i>0 ; i--) {
368 cmp=strcmp(item->sortname,sortlist[i-1]->sortname);
369 if (cmp==0) cmp=strcmp(item->creationdate,sortlist[i-1]->creationdate);
370 if (cmp>=0) {
371 break;
372 }
373 sortlist[i]=sortlist[i-1];
374 }
375 sortlist[i]=item;
376 nsort++;
377 }
378
379 (void)closedir( dirp );
380
381 if((fp_ou=fopen(wdir,"w"))==NULL) {
382 fprintf(stderr, "SARG: (index) %s: %s\n",text[45],wdir);
383 exit(1);
384 }
385 write_html_header(fp_ou,".");
386 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]);
387 for (i=0 ; i<nsort ; i++) {
388 if (order>0)
389 item=sortlist[i];
390 else
391 item=sortlist[nsort-i-1];
392 obtuser(outdir,item->dirname,tuser);
393 obttotal(outdir,item->dirname,tbytes,tuser,media);
394 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);
395 }
396 write_html_trailer(fp_ou);
397 fclose(fp_ou);
398
399 if (sortlist) {
400 for (i=0 ; i<nsort ; i++)
401 free(sortlist[i]);
402 free(sortlist);
403 }
404 }
405
406 static void file_index_to_date_index(const char *entry)
407 {
408 int y1, y2, d1, d2;
409 int i, j;
410 int ndirlen;
411 int monthlen;
412 char m1[8], m2[8];
413 char olddir[MAXLEN], newdir[MAXLEN];
414
415 if(strlen(entry) < 19) return;
416
417 y1=0;
418 y2=0;
419 memset(m1,0,sizeof(m1));
420 memset(m2,0,sizeof(m2));
421 d1=0;
422 d2=0;
423 i=0;
424 if(strcmp(df,"u") == 0) {
425 for (j=0 ; entry[i] && isdigit(entry[i]) ; j++)
426 y1=y1*10+(entry[i++]-'0');
427 if (j!=4) return;
428 for (j=0 ; j<sizeof(m1)-1 && entry[i] && isalpha(entry[i]) ; j++)
429 m1[j]=entry[i++];
430 if (j!=3) return;
431 m1[j]='\0';
432 for (j=0 ; entry[i] && isdigit(entry[i]) ; j++)
433 d1=d1*10+(entry[i++]-'0');
434 if (j!=2) return;
435
436 if (entry[i++]!='-') return;
437
438 for (j=0 ; entry[i] && isdigit(entry[i]) ; j++)
439 y2=y2*10+(entry[i++]-'0');
440 if (j!=4) return;
441 for (j=0 ; j<sizeof(m2)-1 && entry[i] && isalpha(entry[i]) ; j++)
442 m2[j]=entry[i++];
443 if (j!=3) return;
444 m2[j]='\0';
445 for (j=0 ; entry[i] && isdigit(entry[i]) ; j++)
446 d2=d2*10+(entry[i++]-'0');
447 if (j!=2) return;
448 } else if(strcmp(df,"e") == 0) {
449 for (j=0 ; entry[i] && isdigit(entry[i]) ; j++)
450 d1=d1*10+(entry[i++]-'0');
451 if (j!=2) return;
452 for (j=0 ; j<sizeof(m1)-1 && entry[i] && isalpha(entry[i]) ; j++)
453 m1[j]=entry[i++];
454 if (j!=3) return;
455 m1[j]='\0';
456 for (j=0 ; entry[i] && isdigit(entry[i]) ; j++)
457 y1=y1*10+(entry[i++]-'0');
458 if (j!=4) return;
459
460 if (entry[i++]!='-') return;
461
462 for (j=0 ; entry[i] && isdigit(entry[i]) ; j++)
463 d2=d2*10+(entry[i++]-'0');
464 if (j!=2) return;
465 for (j=0 ; j<sizeof(m2)-1 && entry[i] && isalpha(entry[i]) ; j++)
466 m2[j]=entry[i++];
467 if (j!=3) return;
468 m2[j]='\0';
469 for (j=0 ; entry[i] && isdigit(entry[i]) ; j++)
470 y2=y2*10+(entry[i++]-'0');
471 if (j!=4) return;
472 } else
473 return;
474
475 conv_month(m1);
476 conv_month(m2);
477 ndirlen=sprintf(newdir,"%s%04d",outdir,y1);
478 if(access(newdir, R_OK) != 0) mkdir(newdir,0755);
479 if(strcmp(m1,m2) != 0) ndirlen+=sprintf(newdir+ndirlen,"/%s-%s",m1,m2);
480 else ndirlen+=sprintf(newdir+ndirlen,"/%s",m1);
481 if(access(newdir, R_OK) != 0) mkdir(newdir,0755);
482 monthlen=ndirlen;
483 if(d1!=d2) ndirlen+=sprintf(newdir+ndirlen,"/%02d-%02d",d1,d2);
484 else ndirlen+=sprintf(newdir+ndirlen,"/%02d",d1);
485
486 sprintf(olddir,"%s%s",outdir,entry);
487 if (rename(olddir,newdir)) {
488 fprintf(stderr, "SARG: (index) rename error from \"%s\" to \"%s\" - %s\n",olddir,newdir,strerror(errno));
489 exit(1);
490 }
491
492 strcpy(newdir+monthlen,"/images");
493 if(access(newdir, R_OK) != 0) {
494 #ifdef HAVE_SYMLINK
495 char linkdir[MAXLEN];
496
497 sprintf(linkdir,"%simages",outdir);
498 if (symlink(linkdir,newdir)) {
499 fprintf(stderr, "SARG: failed to create link \"%s\" to \"%s\" - %s\n",linkdir,newdir,strerror(errno));
500 exit(1);
501 }
502 #else
503 char cmd[MAXLEN];
504 int cstatus;
505
506 sprintf(cmd,"ln -s \"%simages\" \"%s/images\"",outdir,newdir);
507 cstatus=system(cmd);
508 if (!WIFEXITED(cstatus) || WEXITSTATUS(cstatus)) {
509 fprintf(stderr, "SARG: command return status %d\n",WEXITSTATUS(cstatus));
510 fprintf(stderr, "SARG: command: %s\n",cmd);
511 exit(1);
512 }
513 #endif
514 }
515 }
516
517 static void date_index_to_file_index(const char *entry)
518 {
519 int y1, next;
520 int val1len;
521 int d1, d2;
522 int i, j;
523 char val1[MAXLEN];
524 char m1[8], m2[8];
525 char *str;
526 char newdir[MAXLEN], olddir[MAXLEN];
527 DIR *dirp2, *dirp3;
528 struct dirent *direntp2;
529 struct dirent *direntp3;
530
531 if(strlen(entry) != 4) return;
532
533 next=-1;
534 if (sscanf(entry,"%d%n",&y1,&next)!=1 || next<0 || entry[next]) return;
535
536 val1len=sprintf(val1,"%s%s",outdir,entry);
537 dirp2 = opendir(val1);
538 if (!dirp2) return;
539 while ((direntp2 = readdir( dirp2 )) != NULL) {
540 if(!isdigit(direntp2->d_name[0]) || !isdigit(direntp2->d_name[1])) continue;
541 i=0;
542 str=direntp2->d_name;
543 for (j=0 ; j<sizeof(m1) && str[i] && isdigit(str[i]) ; j++)
544 m1[j]=str[i++];
545 if (j>=sizeof(m1)) continue;
546 m1[j]='\0';
547 conv_month_name(m1);
548 if (str[i]=='-') {
549 i++;
550 for (j=0 ; j<sizeof(m2) && str[i] && isdigit(str[i]) ; j++)
551 m2[j]=str[i++];
552 if (j>=sizeof(m2)) continue;
553 m2[j]='\0';
554 conv_month_name(m2);
555 } else if (!str[i]) {
556 strcpy(m2,m1);
557 } else {
558 continue;
559 }
560
561 sprintf(val1+val1len,"/%s",direntp2->d_name);
562 dirp3 = opendir(val1);
563 if (!dirp3) continue;
564 while ((direntp3 = readdir( dirp3 )) != NULL) {
565 if(!isdigit(direntp3->d_name[0]) || !isdigit(direntp3->d_name[1])) continue;
566 i=0;
567 str=direntp3->d_name;
568 d1=0;
569 for (j=0 ; str[i] && isdigit(str[i]) ; j++)
570 d1=d1*10+(str[i++]-'0');
571 if (j!=2) continue;
572 if (str[i]=='-') {
573 i++;
574 d2=0;
575 for (j=0 ; str[i] && isdigit(str[i]) ; j++)
576 d2=d2*10+(str[i++]-'0');
577 if (j!=2) continue;
578 } else if (!str[i]) {
579 d2=d1;
580 } else {
581 continue;
582 }
583
584 if(strcmp(df,"u") == 0) sprintf(newdir,"%s%04d%s%02d-%04d%s%02d",outdir,y1,m1,d1,y1,m2,d2);
585 else if(strcmp(df,"e") == 0) sprintf(newdir,"%s%02d%s%04d-%02d%s%04d",outdir,d1,m1,y1,d2,m2,y1);
586 else continue;
587 sprintf(olddir,"%s%04d/%s/%s",outdir,y1,direntp2->d_name,direntp3->d_name);
588 if(rename(olddir,newdir)) {
589 fprintf(stderr, "SARG: (index) rename error from \"%s\" to \"%s\" - %s\n",olddir,newdir,strerror(errno));
590 exit(1);
591 }
592 }
593 (void)closedir( dirp3 );
594 }
595 (void)closedir( dirp2 );
596
597 /*!
598 \bug The links to the images in the reports are broken after moving the directories
599 as the the HTML files are not at the right level for the images any more.
600 */
601 }
602