Rev 15779 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 15779 | Rev 17094 | ||
---|---|---|---|
Line 22... | Line 22... | ||
22 | /* The maximal number of sessions within one day */ |
22 | /* The maximal number of sessions within one day */ |
23 | #define MAX_SESSIONS (128*1024) |
23 | #define MAX_SESSIONS (128*1024) |
24 | /* The maximal number of classes within one day */ |
24 | /* The maximal number of classes within one day */ |
25 | #define MAX_CLASSES 8192 |
25 | #define MAX_CLASSES 8192 |
26 | /* At least these minutes will be counted for each session */ |
26 | /* At least these minutes will be counted for each session */ |
27 | #define MIN_CONNECT |
27 | #define MIN_CONNECT 1 |
28 | /* Add this number of minutes to each session */ |
28 | /* Add this number of minutes to each session */ |
29 | #define MIN_ADD 1 |
29 | #define MIN_ADD 1 |
30 | /* Accounting discontinues after this number of idle minutes */ |
30 | /* Accounting discontinues after this number of idle minutes */ |
31 | #define MAX_LAPSE 15 |
31 | #define MAX_LAPSE 15 |
32 | 32 | ||
33 | struct { |
33 | struct { |
34 | char s[4], u[32]; |
34 | char s[4], u[32], cl[20]; |
35 | int |
35 | int start, end, cnt; |
- | 36 | ||
36 | } ses[MAX_SESSIONS]; |
37 | } ses[MAX_SESSIONS]; |
37 | int sescnt; |
38 | int sescnt; |
38 | 39 | ||
39 | char *datestr; |
40 | char *datestr; |
40 | 41 | ||
41 | struct cls { |
42 | struct cls { |
- | 43 | char cl[20]; |
|
42 | int |
44 | int cnt; |
43 | } cls[MAX_CLASSES]; |
45 | } cls[MAX_CLASSES]; |
44 | int clscnt; |
46 | int clscnt; |
45 | 47 | ||
46 | /* Read/write to a file with variable parms to print filename */ |
48 | /* Read/write to a file with variable parms to print filename */ |
47 | /* same in Interfaces/common.c and wlogdaccessfile */ |
49 | /* same in Interfaces/common.c and wlogdaccessfile */ |
Line 62... | Line 64... | ||
62 | } |
64 | } |
63 | switch(*type) { |
65 | switch(*type) { |
64 | case 'a': |
66 | case 'a': |
65 | case 'w': { |
67 | case 'w': { |
66 | l=strlen(content); fwrite(content,1,l,f); break; |
68 | l=strlen(content); fwrite(content,1,l,f); break; |
67 | } |
69 | } |
68 | case 'r': { |
70 | case 'r': { |
69 | l=fread(content,1,MAX_LINELEN-1,f); |
71 | l=fread(content,1,MAX_LINELEN-1,f); |
70 | if(l>0 && l<MAX_LINELEN) content[l]=0; |
72 | if(l>0 && l<MAX_LINELEN) content[l]=0; |
71 | else content[0]=0; |
73 | else content[0]=0; |
72 | break; |
74 | break; |
Line 77... | Line 79... | ||
77 | } |
79 | } |
78 | fclose(f); |
80 | fclose(f); |
79 | } |
81 | } |
80 | /* recursively generate a directory structure */ |
82 | /* recursively generate a directory structure */ |
81 | void mkdirs2(char *s) |
83 | void mkdirs2(char *s) |
82 | { |
84 | { |
83 | struct stat st; |
85 | struct stat st; |
84 | char *buf; |
86 | char *buf; |
85 | if(stat(s,&st)==-1) { |
87 | if(stat(s,&st)==-1) { |
86 | if(strrchr(s,'/')!=NULL) { |
88 | if(strrchr(s,'/')!=NULL) { |
87 | buf=xmalloc(strlen(s)+1); |
89 | buf=xmalloc(strlen(s)+1); |
88 | ovlstrcpy(buf,s); *strrchr(buf,'/')=0; |
90 | ovlstrcpy(buf,s); *strrchr(buf,'/')=0; |
89 | mkdirs2(buf); free(buf); |
91 | mkdirs2(buf); free(buf); |
90 | } |
92 | } |
91 | mkdir(s,-1); |
93 | mkdir(s,-1); |
92 | } |
94 | } |
93 | } |
95 | } |
94 | 96 | ||
- | 97 | /* line format is : |
|
- | 98 | YYYYMMDD.HH:MM:SS session IP cmd module (time) login,class |
|
- | 99 | time is displayed only for long request |
|
- | 100 | */ |
|
95 | static |
101 | static |
96 | void oneline(char *p) |
102 | void oneline(char *p) |
97 | { |
103 | { |
98 | char tbuf[8], sbuf[8], ubuf[32], |
104 | char tbuf[8], sbuf[8], ubuf[32], cl[20]; |
99 | char *p1 |
105 | char *p1 /*, *p2*/; |
100 | int i,t |
106 | int i,t; |
101 | memmove(tbuf,p+9,6); tbuf[2]=tbuf[5]=0; |
107 | memmove(tbuf,p+9,6); tbuf[2]=tbuf[5]=0; |
102 | t=atoi(tbuf)*60+atoi(tbuf+3); |
108 | t=atoi(tbuf)*60+atoi(tbuf+3); |
103 | memmove(sbuf,p+18,4); sbuf[4]=0; |
109 | memmove(sbuf,p+18,4); sbuf[4]=0; |
104 | p1=strchr(p,','); if(p1==NULL) return; |
110 | p1=strchr(p,','); if(p1==NULL) return; |
105 | if(!isdigit(*(p1+1))) return; |
111 | if(!isdigit(*(p1+1))) return; |
106 | snprintf( |
112 | snprintf(cl,sizeof(cl),"%s",p1+1); |
107 | for(p2=cbuf;isdigit(*p2); p2++){}; |
- | |
108 | *p2=0; cl=atoi(cbuf); |
- | |
109 | *p1=0; for(p1--;p1>p && !isspace(*(p1-1)); p1--); |
113 | *p1=0; for(p1--;p1>p && !isspace(*(p1-1)); p1--); |
110 | snprintf(ubuf,sizeof(ubuf),"%s",p1); |
114 | snprintf(ubuf,sizeof(ubuf),"%s",p1); |
111 | for(i=0;i<sescnt;i++) { |
115 | for(i=0;i<sescnt;i++) { |
112 | if( |
116 | if(memcmp(cl,ses[i].cl,20)==0 && memcmp(sbuf,ses[i].s,4)==0 && |
113 | ses[i].end>=t-MAX_LAPSE) { |
117 | ses[i].end>=t-MAX_LAPSE) { |
114 | ses[i].end=t; return; |
118 | ses[i].end=t; return; |
115 | } |
119 | } |
116 | } |
120 | } |
117 | if(sescnt>=MAX_SESSIONS) return; |
121 | if(sescnt>=MAX_SESSIONS) return; |
118 | memmove(ses[sescnt].s,sbuf,4) |
122 | memmove(ses[sescnt].s,sbuf,4); |
- | 123 | memmove(ses[sescnt].cl,cl,20); |
|
119 | ses[sescnt].start=ses[sescnt].end=t; |
124 | ses[sescnt].start=ses[sescnt].end=t; |
120 | snprintf(ses[sescnt].u,sizeof(ses[sescnt].u),"%s",ubuf); |
125 | snprintf(ses[sescnt].u,sizeof(ses[sescnt].u),"%s",ubuf); |
121 | sescnt++; |
126 | sescnt++; |
122 | } |
127 | } |
123 | 128 | ||
Line 146... | Line 151... | ||
146 | if(ses[i].cnt<MIN_CONNECT) ses[i].cnt=MIN_CONNECT; |
151 | if(ses[i].cnt<MIN_CONNECT) ses[i].cnt=MIN_CONNECT; |
147 | for(j=0;j<clscnt && ses[i].cl!=cls[j].cl;j++); |
152 | for(j=0;j<clscnt && ses[i].cl!=cls[j].cl;j++); |
148 | if(j<clscnt) cls[j].cnt+=ses[i].cnt; |
153 | if(j<clscnt) cls[j].cnt+=ses[i].cnt; |
149 | else |
154 | else |
150 | if(clscnt<MAX_CLASSES) { |
155 | if(clscnt<MAX_CLASSES) { |
151 |
|
156 | memmove(cls[clscnt].cl,ses[i].cl,20); |
152 | cls[clscnt].cnt=ses[i].cnt; |
157 | cls[clscnt].cnt=ses[i].cnt; |
153 | clscnt++; |
158 | clscnt++; |
154 | } |
159 | } |
155 | } |
160 | } |
156 | } |
161 | } |
Line 166... | Line 171... | ||
166 | { |
171 | { |
167 | char *p, buf[1024], dbuf[1024]; |
172 | char *p, buf[1024], dbuf[1024]; |
168 | int i,t; |
173 | int i,t; |
169 | p=getenv("ccsum_outdir"); if(p==NULL || *p==0) return; |
174 | p=getenv("ccsum_outdir"); if(p==NULL || *p==0) return; |
170 | for(i=0;i<sescnt;i++) { |
175 | for(i=0;i<sescnt;i++) { |
171 | snprintf(dbuf,sizeof(dbuf),"%s/ |
176 | snprintf(dbuf,sizeof(dbuf),"%s/%s",p,ses[i].cl); |
172 | mkdirs2(dbuf); |
177 | mkdirs2(dbuf); |
173 | snprintf(buf,sizeof(buf),"%s.%02d:%02d %d\n", |
178 | snprintf(buf,sizeof(buf),"%s.%02d:%02d %d\n", |
174 | datestr,ses[i].start/60,ses[i].start%60,ses[i].cnt); |
179 | datestr,ses[i].start/60,ses[i].start%60,ses[i].cnt); |
175 | accessfile(buf,"a","%s/%s",dbuf,ses[i].u); |
180 | accessfile(buf,"a","%s/%s",dbuf,ses[i].u); |
176 | } |
181 | } |
Line 179... | Line 184... | ||
179 | snprintf(dbuf+strlen(dbuf),sizeof(dbuf)-strlen(dbuf),"/%.2s",datestr+4); |
184 | snprintf(dbuf+strlen(dbuf),sizeof(dbuf)-strlen(dbuf),"/%.2s",datestr+4); |
180 | t=0; |
185 | t=0; |
181 | qsort(cls,clscnt,sizeof(cls[0]),clscmp); |
186 | qsort(cls,clscnt,sizeof(cls[0]),clscmp); |
182 | for(i=0;i<clscnt;i++) { |
187 | for(i=0;i<clscnt;i++) { |
183 | snprintf(buf,sizeof(buf),"%s %d\n",datestr,cls[i].cnt); |
188 | snprintf(buf,sizeof(buf),"%s %d\n",datestr,cls[i].cnt); |
184 | accessfile(buf,"a","%s/ |
189 | accessfile(buf,"a","%s/%s/.total",p,cls[i].cl); |
185 | snprintf(buf,sizeof(buf),"%s |
190 | snprintf(buf,sizeof(buf),"%s %s %d\n",datestr+4,cls[i].cl,cls[i].cnt); |
186 | accessfile(buf,"a","%s",dbuf); |
191 | accessfile(buf,"a","%s",dbuf); |
187 | t+=cls[i].cnt; |
192 | t+=cls[i].cnt; |
188 | } |
193 | } |
189 | snprintf(buf,sizeof(buf),"%s %d %d\n",datestr,t,(t+30)/60); |
194 | snprintf(buf,sizeof(buf),"%s %d %d\n",datestr,t,(t+30)/60); |
190 | accessfile(buf,"a","%s/done",p); |
195 | accessfile(buf,"a","%s/done",p); |