Rev 8342 | Rev 12474 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 8342 | Rev 8849 | ||
---|---|---|---|
Line 30... | Line 30... | ||
30 | char session_name[MAX_LINELEN+1]; |
30 | char session_name[MAX_LINELEN+1]; |
31 | 31 | ||
32 | sdir_base=opendir(di); |
32 | sdir_base=opendir(di); |
33 | if(sdir_base==NULL) return; |
33 | if(sdir_base==NULL) return; |
34 | while((ses=readdir(sdir_base))!=NULL) { |
34 | while((ses=readdir(sdir_base))!=NULL) { |
35 |
|
35 | if(ses->d_name[0]=='.') continue; |
36 |
|
36 | snprintf(session_name,sizeof(session_name),"%s/%s", |
37 |
|
37 | di,ses->d_name); |
38 |
|
38 | if(lstat(session_name,&session_stat)) { |
39 |
|
39 | wimslogd_error("wimslog cleaning(): session stat failure."); |
40 |
|
40 | return; |
41 |
|
41 | } |
42 |
|
42 | if(!S_ISDIR(session_stat.st_mode)) { /* not a directory: remove it. */ |
43 |
|
43 | if(remove(session_name)<0) { |
44 |
|
44 | wimslogd_error("wimslogd cleaning(): unable to chase squatter file."); |
45 |
|
45 | return; |
46 |
|
46 | } |
47 |
|
47 | } |
48 | /* remove idle session. */ |
48 | /* remove idle session. */ |
49 |
|
49 | else { |
50 |
|
50 | struct stat fst; |
51 |
|
51 | char fbuf[4096],cbuf[MAX_LINELEN+1]; |
52 |
|
52 | char *pp; |
53 |
|
53 | if(session_stat.st_mtime<nowtime-idle_time || |
54 |
|
54 | session_stat.st_mtime>nowtime+anti_time) { |
55 |
|
55 | remove: |
56 |
|
56 | if(remove_tree(session_name)!=0) { |
57 |
|
57 | if(strstr(session_name,"chroot")!=NULL) { |
58 |
|
58 | char tbuf[4096]; |
59 |
|
59 | snprintf(tbuf,sizeof(tbuf),"/%s",session_name); |
60 |
|
60 | setenv("tmp_dir",tbuf,1); |
61 |
|
61 | chmod(session_name, |
62 |
|
62 | S_IRUSR|S_IWUSR|S_IXUSR| |
63 |
|
63 | S_IRGRP|S_IWGRP|S_IXGRP| |
64 |
|
64 | S_IROTH|S_IWOTH|S_IXOTH); |
65 |
|
65 | (void)chdir("public_html"); |
66 |
|
66 | call_ssh(1,"bin/ch..root cleantmpdir"); |
67 |
|
67 | (void)chdir(cwd); |
68 |
|
68 | chmod(session_name,S_IRUSR|S_IWUSR|S_IXUSR); |
69 |
|
69 | fprintf(stderr,"%s\n",tbuf); |
70 |
|
70 | } |
71 |
|
71 | if(remove_tree(session_name)!=0) { |
72 |
|
72 | fprintf(stderr,"Unable to remove session %s: %s.\n", |
73 |
|
73 | session_name,strerror(errno)); |
74 |
|
74 | } |
75 |
|
75 | } |
76 |
|
76 | continue; |
77 |
|
77 | } |
78 |
|
78 | if(hardcheck==2) { |
79 |
|
79 | char dbuf[MAX_FNAME+1]; |
80 |
|
80 | struct dirent *s2d; |
81 |
|
81 | struct stat fst; |
82 |
|
82 | int t; |
83 |
|
83 | DIR *s2D; |
84 |
|
84 | snprintf(dbuf,sizeof(dbuf),"%s/%s",sesd,ses->d_name); |
85 |
|
85 | if(ftest(dbuf)!=is_dir) goto remove; |
86 |
|
86 | s2D=opendir(session_name); |
87 |
|
87 | if(sdir_base==NULL) goto remove; |
88 |
|
88 | while((s2d=readdir(s2D))!=NULL) { /* remove individual files */ |
89 |
|
89 | snprintf(dbuf,sizeof(dbuf),"%s/%s",session_name,s2d->d_name); |
90 |
|
90 | t=stat(dbuf,&fst); |
91 |
|
91 | if(t==0 && fst.st_mtime<nowtime-INS_DELAY && |
92 |
|
92 | fst.st_mtime>=nowtime+anti_time) remove(dbuf); |
93 |
|
93 | } |
94 |
|
94 | closedir(s2D); |
95 |
|
95 | continue; |
96 |
|
96 | } |
97 |
|
97 | if(!hardcheck || strchr(session_name,'_')!=NULL) continue; |
98 |
|
98 | if(session_stat.st_mtime>=nowtime-idle_time3 && |
99 |
|
99 | session_stat.st_mtime<nowtime+anti_time) continue; |
100 |
|
100 | snprintf(fbuf,sizeof(fbuf),"%s/var.stat",session_name); |
101 |
|
101 | if(stat(fbuf,&fst)==0) continue; |
102 |
|
102 | wlogdaccessfile(cbuf,"r","%s/var",session_name); |
103 |
|
103 | if(cbuf[0]==0) goto remove; /* no var file */ |
104 |
|
104 | pp=strstr(cbuf,"\nw_wims_ismanager="); |
105 |
|
105 | if(pp!=NULL) { |
106 |
|
106 | pp+=strlen("\nw_wims_ismanager="); |
107 |
|
107 | if(*pp>'0' && *pp<='9') continue; |
108 |
|
108 | } |
109 |
|
109 | if(session_stat.st_mtime<nowtime-idle_time2 || |
110 |
|
110 | session_stat.st_mtime>nowtime+anti_time) goto remove; |
111 |
|
111 | if(session_stat.st_mtime<nowtime-idle_time3 && |
112 |
|
112 | strstr(cbuf,"\nwims_new_session=yes\n")!=NULL) goto remove; |
113 |
|
113 | /* popup session: 50 sec only. */ |
114 |
|
114 | if(session_stat.st_mtime<nowtime-50 && |
115 |
|
115 | strstr(cbuf,"\nw_wims_mode=popup\n")!=NULL) goto remove; |
116 |
|
116 | } |
117 | } |
117 | } |
118 | closedir(sdir_base); |
118 | closedir(sdir_base); |
119 | } |
119 | } |
120 | 120 | ||
121 | /* Clean obsolete session directories. */ |
121 | /* Clean obsolete session directories. */ |
Line 144... | Line 144... | ||
144 | lastclean=fopen(lastclean_name,"w"); fclose(lastclean); |
144 | lastclean=fopen(lastclean_name,"w"); fclose(lastclean); |
145 | lastcleantime=nowtime; |
145 | lastcleantime=nowtime; |
146 | snprintf(lastclean_name,sizeof(lastclean_name),"%s/trap.check",tmpd); |
146 | snprintf(lastclean_name,sizeof(lastclean_name),"%s/trap.check",tmpd); |
147 | if(stat(lastclean_name,&lastclean_stat)==0 && |
147 | if(stat(lastclean_name,&lastclean_stat)==0 && |
148 | (lastclean_stat.st_mtime<nowtime-3600 || |
148 | (lastclean_stat.st_mtime<nowtime-3600 || |
149 |
|
149 | lastclean_stat.st_mtime>nowtime+anti_time)) unlink(lastclean_name); |
150 | exit(0); |
150 | exit(0); |
151 | } |
151 | } |
152 | 152 |