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