Subversion Repositories wimsdev

Rev

Rev 15547 | Rev 16711 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
12210 bpr 1
/*  Copyright (C) 1998-2003 XIAO, Gang of Universite de Nice - Sophia Antipolis
10 reyssat 2
 *
3
 *  This program is free software; you can redistribute it and/or modify
4
 *  it under the terms of the GNU General Public License as published by
5
 *  the Free Software Foundation; either version 2 of the License, or
6
 *  (at your option) any later version.
7
 *
8
 *  This program is distributed in the hope that it will be useful,
9
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
10
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
 *  GNU General Public License for more details.
12
 *
13
 *  You should have received a copy of the GNU General Public License
14
 *  along with this program; if not, write to the Free Software
15
 *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
16
 */
7563 bpr 17
/* Routines to write log files. */
8185 bpr 18
#include <sys/socket.h>
19
#include <sys/un.h>
10 reyssat 20
 
8185 bpr 21
#include "wims.h"
22
 
10 reyssat 23
char logbuf[4*(MAX_LINELEN+1)];
24
char *logp=logbuf;
25
 
26
void write_logfile(char *fname, char *str)
27
{
12210 bpr 28
  char *p;
29
  if((p=strchr(str,'\n'))!=NULL) *p=0;
30
  snprintf(logp,sizeof(logbuf)-(logp-logbuf),"%s %s\n",fname,str);
31
  logp+=strlen(logp);
10 reyssat 32
}
33
 
34
void flushlog(void)
35
{
12210 bpr 36
  int n, fd;
37
  n=logp-logbuf; logp=logbuf;
38
  if(n<=0) return;
39
  fd=open(temp_log,O_WRONLY|O_APPEND|O_CREAT,S_IRUSR|S_IWUSR);
40
  if(fd==-1) return;
41
  (void)write(fd,logbuf,n); close(fd);
10 reyssat 42
}
43
 
7563 bpr 44
/* Write module log file. */
10 reyssat 45
void module_log(void)
46
{
12210 bpr 47
  /* log string is limited to 100 characters. */
48
  char *logstr, *ip, *sess, lbuf[100], *p;
7563 bpr 49
 
12210 bpr 50
  if(robot_access || !modlog || strstr(session_prefix,"_check")!=NULL) return;
51
  logstr=getvar("wims_module_log");
52
  if(logstr==NULL || *logstr==0) return;
53
  ip=remote_addr;
54
  if(mode==mode_default) sess=getvar("wims_session");
55
  else sess="popup";
56
  if(ip==NULL || sess==NULL) return;
57
  mystrncpy(lbuf,logstr,sizeof(lbuf));
58
  p=strchr(sess,'_'); if(p==NULL) p=sess+strlen(sess);
59
  if(p<sess+4) p=sess; else p=p-4;
60
  snprintf(tmplbuf,sizeof(tmplbuf),"%s %.6s %s\11%s",
61
   nowstr, p, ip, lbuf);
62
  p=getvar(ro_name[ro_module]);
63
  if(p==NULL || *p==0) return;
64
  write_logfile(mkfname(NULL,"%s/%s",module_dir,p),tmplbuf);
10 reyssat 65
}
66
 
7563 bpr 67
/* log http referers */
10 reyssat 68
void referer_log(void)
69
{
12210 bpr 70
  char *c,*s,*ip,*r,*h,refstr[256];
10 reyssat 71
 
12210 bpr 72
  if(robot_access) return;
73
  c=getvar(ro_name[ro_cmd]);
74
  if(c==NULL) c="";
75
  if(mode==mode_default) s=getvar("wims_session"); else s="popup";
76
  if(s==NULL) s="----";
77
  else if(!new_session && strcmp(c,"intro")!=0) return;
78
  if(strlen(s)<4) s="----";
79
  if(strchr(s,'_')!=NULL) return;
80
  ip=remote_addr; if(*ip==0) return;
81
  r=getenv("HTTP_REFERER");
82
  if(r==NULL || *r==0) r="??";
83
  /* skip some useless referers */
84
  else {
85
    if(strstr(r,cgi_name)!=NULL) return;
86
    if(strstr(r,"file:")!=NULL || strchr(r,'.')==NULL) r="??";
87
    if(strstr(r,"http")==NULL && strchr(r,'.')==NULL &&
88
     strstr(r,"bookmark")!=NULL) r="??bookmark";
89
  }
90
  if(strncmp(r,"http://",strlen("http://"))==0) r+=strlen("http://");
91
  /* Take references from the same site or not? No. */
92
  h=getenv("HTTP_HOST");
93
  if(h!=NULL && *h!=0 && strncmp(r,h,strlen(h))==0) return;
94
    /* stop before '#' */
95
  mystrncpy(refstr,r,sizeof(refstr));
96
  r=strchr(refstr,'#'); if(r!=NULL) *r=0;
97
  for(r=refstr;r<refstr+strlen(refstr);r++) {
98
    if(*r=='%' && *(r+1)=='7' && *(r+2)=='E') {
99
    *r='~'; ovlstrcpy(r+1,r+3);
10 reyssat 100
    }
12210 bpr 101
  }
102
  snprintf(tmplbuf,sizeof(tmplbuf),"%s %s %s\11%s",
103
     nowstr,s+strlen(s)-4,ip,refstr);
104
  write_logfile("referer.log",tmplbuf);
10 reyssat 105
}
106
 
7563 bpr 107
/* Log new creation of sessions. For server counting use. */
10 reyssat 108
void session_log(char *c)
109
{
12210 bpr 110
  int i;
111
  char *ip, *p, *agent, *s, *sess;
7563 bpr 112
 
12210 bpr 113
  ip=remote_addr; if(*ip==0) return;
114
  if(mode==mode_default) {
115
    sess=getvar("wims_session");
116
    if(sess==NULL) return;
117
    if(strchr(sess,'_')!=NULL) return;
118
  }
119
  else sess="popup";
120
  p=getenv("REMOTE_HOST"); if(p==NULL) p="";
121
  i=strlen(p); if(i>40) p+=i-40;
122
  agent=getenv("HTTP_USER_AGENT"); if(agent==NULL) agent="";
123
  s=strchr(sess,'_'); if(s==NULL) s=sess+strlen(sess);
124
  if(s<sess+4) s=sess; else s=s-4;
125
    /* limit agent name to 80 chars */
126
  snprintf(tmplbuf,sizeof(tmplbuf),"%s %s %s\11%s\11%.80s",
127
     nowstr, s, ip, p, agent);
128
  write_logfile("session.log",tmplbuf);
10 reyssat 129
}
130
 
7563 bpr 131
/* Log user information. */
10 reyssat 132
void user_log(char *c)
133
{
12210 bpr 134
  char fname[MAX_FNAME+1], logbuf[MAX_LINELEN+1], cbuf[256], sbuf[32], shbuf[32];
12218 bpr 135
  char *user, *classe, *sh, *sess, *exo, *cc, *ip, *allow, *pend, *se;
12210 bpr 136
  char *ex;
137
  double sc,Sc;
12381 bpr 138
  int i, scorelog, testmax;
7563 bpr 139
 
12210 bpr 140
  if(robot_access || strstr("session_prefix","_check")!=NULL) return;
141
  user=getvar("wims_user"); classe=getvar("wims_class");
142
  sc=0;
143
  if(isexam) {
144
    if(user==NULL || classe==NULL || *user==0 || *classe==0) return;
145
    sh=getvar("worksheet"); if(sh==NULL) return;
146
    mystrncpy(shbuf,sh,sizeof(shbuf));
147
    exo=strchr(shbuf,'.'); if(exo==NULL) return;
148
    *exo++=0; sh=shbuf;
149
    if(mode==mode_default) sess=getvar("wims_session");
150
    else sess="popup";
151
    if(sess==NULL) return;
152
    mystrncpy(sbuf,sess,sizeof(sbuf));
153
    sess=strchr(sbuf,'_'); if(sess==NULL) return;
154
    *sess=0; sess=sbuf; ex="E";
155
    accessfile(logbuf,"r","%s/.E%s",class_dir,sh);
156
    if(strchr(logbuf,'#')!=NULL || strcmp(user,"supervisor")==0) simuxam=1;
157
    else {
158
      accessfile(logbuf,"r","%s/%s/examsimu.%d", session_dir,sess,sh);
159
      if(strstr(logbuf,"yes")!=NULL) user_error("expired_exam");
10 reyssat 160
    }
12210 bpr 161
    mkfname(examlogd,"%s/examlog/%s/%s",class_dir,user,sess);
162
    mkfname(examlogf,"%s/%s.%s",examlogd,sh,exo);
163
  }
164
  else {
165
    sh=getvar("wims_sheet");
16647 guerimand 166
    if(sh==NULL || *sh==0) {
167
      sh=getvar("wims_fwnumber");
168
      if(sh==NULL || *sh==0) return;
169
      ex="F";
170
      exo=getvar("wims_fwexo");
171
    }
172
    else {
173
      exo=getvar("wims_exo"); if(exo==NULL) return;
174
      ex="";
175
    }
12210 bpr 176
    sess=getvar("wims_session");
177
    if(sess==NULL) return;
178
  }
179
  if(strcmp(c,"new")!=0 && strcmp(c,"renew")!=0
180
     && strcmp(c,"rafale")!=0
181
     && strcmp(c,"hint")!=0 && parm_restore==0) {
182
    char *s;
183
    s=getvar("module_score");
184
    if(s==NULL || *s==0) return;
185
    sc=atof(s); if(!isfinite(sc)) {sc=0; return;}
186
    snprintf(cbuf,sizeof(cbuf),"score %s",s);
187
    cc=cbuf;
188
  }
189
  else cc=c;
190
  if(classe==NULL || *classe==0) i=1;
191
  else i=getscorestatus(classe,atoi(sh));
12381 bpr 192
  testmax=gettrycheck(classe,user,atoi(sh),atoi(exo))==1;
12210 bpr 193
  pend=getvar("wims_scoring"); if(pend==NULL) pend="";
16647 guerimand 194
  if((i==0 || !exodepOK || strcmp(pend,"pending")!=0 || testmax) && strcmp(cc,"rafale")!=0 && *ex!='F')
12219 bpr 195
    if(testmax) allow="maxtry noscore"; else allow="noscore";
12381 bpr 196
  else allow="";
12210 bpr 197
  ip=remote_addr; if(*ip==0) ip="-"; scorelog=0;
198
  if(user==NULL || *user==0) {
199
    classe="0"; allow="";
200
    mkfname(fname,"../sessions/%s/.score",sess);
201
  }
202
  else {
203
    char *pp;
204
    if(classe==NULL || *classe==0) return;
13011 bpr 205
    pp=getvar("wims_scorereg"); /* contains suspend or exotrymax */
16647 guerimand 206
    if((allow[0]==0 || i==1 || (pp!=NULL && strcmp(pp,"suspend")==0)) && *ex!='E' && *ex!='F')
12210 bpr 207
      scorelog=1;
16647 guerimand 208
    else {
209
      if (*ex=='F')
210
       /* freework activity logged to different file */
211
        mkfname(fname,"classes/%s/freeworksdata/%s.freework",classe,user);
212
      else
213
        mkfname(fname,"classes/%s/noscore/%s",classe,user);
214
      }
12210 bpr 215
  }
216
  if(isexam && user!=NULL && *user!=0) {
217
    allow=exam_sheetexo;
218
    snprintf(logbuf,sizeof(logbuf),":%s %2s %s  \t%s%s\n",
219
    nowstr,exo,cc,ip,allow);
220
    accessfile(logbuf,"a","%s/%s/examscore.%s", session_dir,sess,sh);
221
    Sc=currexamscore(atoi(sh));
222
    accessfile(logbuf,"r","%s/.E%s",class_dir,sh);
223
    if(simuxam==0) {   /* not simulation */
224
      if(sc>0) {
225
        snprintf(logbuf,sizeof(logbuf),
226
        "%s %.5f -1 %u %s %s\n",
227
        sh,Sc,(unsigned int) nowtime,ip,sess);
228
        accessfile(logbuf,"a","%s/score/%s.exam", class_dir,user);
229
      }
10 reyssat 230
    }
12210 bpr 231
    else snprintf(exam_sheetexo+strlen(exam_sheetexo),
232
        sizeof(exam_sheetexo)-strlen(exam_sheetexo), "\tS");
233
  }
12218 bpr 234
  if(strcmp(c,"new")==0 || strcmp(c,"renew")==0)
235
    se=getvar("wims_seed"); else se="";
236
  snprintf(logbuf,sizeof(logbuf),"%s%s %s %2s %2s %s  \t%s\t%s\t%s",
12219 bpr 237
      ex,nowstr,sess,sh,exo,cc,ip,se,allow);
12210 bpr 238
  if(scorelog) {
239
    snprintf(tmplbuf,sizeof(tmplbuf),"-c%s -u%s scorelog %s",
240
       classe,user,logbuf);
241
    _daemoncmd(tmplbuf);
242
  }
243
  else write_logfile(fname,logbuf);
10 reyssat 244
}
245
 
7563 bpr 246
/* Log class information. */
10 reyssat 247
void class_log(char *cl, char *l, char *ip)
248
{
12210 bpr 249
  char logbuf[1024];
7563 bpr 250
 
12210 bpr 251
  if(robot_access) return;
252
  snprintf(logbuf,sizeof(logbuf),"%s %s   \t%s",
253
      nowstr,ip,l);
254
  write_logfile(mkfname(NULL,"classes/%s/.log",cl),logbuf);
10 reyssat 255
}
256
 
7563 bpr 257
/* Log accesses to modules. For server counting use. */
10 reyssat 258
void access_log(char *c)
259
{
12210 bpr 260
  int i;
261
  char *ip, *p, *sess, *s, *agent, *u, *cl;
262
  time_t logtime;
263
  char ag[128], tm[64];
7563 bpr 264
 
12210 bpr 265
  ip=remote_addr;
266
  if(*ip==0) ip="????????";
267
  if(mode==mode_default) sess=getvar("wims_session");
268
  else sess="popup";
269
  if(sess==NULL) sess="----------";
270
  p=getvar(ro_name[ro_module]);
271
  if(p==NULL || *p==0) p="-";
8155 bpr 272
/* limit module name to 40 chars */
12210 bpr 273
  i=strlen(p); if(i>40) p+=i-40;
274
  if(robot_access) {
275
   agent=getenv("HTTP_USER_AGENT"); if(agent==NULL) agent="-";
276
   snprintf(ag,sizeof(ag)," %s",agent);
277
  }
278
  else {
279
   u=getvar("wims_user");
280
   if(u!=NULL && *u!=0) snprintf(ag,sizeof(ag)," %s,%s",u,getvar("wims_class"));
281
   else ag[0]=0;
282
  }
283
  s=strchr(sess,'_'); if(s==NULL) s=sess+strlen(sess);
284
  if(s<sess+4) s=sess; else s=s-4;
285
  tm[0]=0; logtime=time(0); if(logtime>nowtime+2) {
286
   snprintf(tm,sizeof(tm)," (%lus)", logtime-nowtime);
287
  }
288
  snprintf(tmplbuf,sizeof(tmplbuf),"%s %.6s %s\11%s\11%s%s%s",
289
      nowstr, s, ip, c, p, tm, ag);
290
  write_logfile("access.log",tmplbuf);
291
  user_log(c);
292
  cl=getvar("wims_class");
293
  if(cl!=NULL && *cl!=0) {
12288 bpr 294
    char *l;
295
    l=getvar("wims_class_log");
296
    if(l!=NULL && *l!=0) class_log(cl, l, ip);
12210 bpr 297
  }
10 reyssat 298
}
299
 
7563 bpr 300
/* Log of mails. */
10 reyssat 301
void mail_log(char *c)
302
{
12210 bpr 303
  int i;
304
  char *ip, *p, *sess, *s, *cl;
7563 bpr 305
 
12210 bpr 306
  ip=remote_addr;
307
  if(*ip==0) ip="????????";
308
  if(mode==mode_default) sess=getvar("wims_session");
309
  else sess="popup";
310
  if(sess==NULL) sess="----------";
311
  p=getvar(ro_name[ro_module]);
312
  if(p==NULL || *p==0) p="-";
8155 bpr 313
/* limit module name to 40 chars */
12210 bpr 314
  i=strlen(p); if(i>40) p+=i-40;
315
  s=strchr(sess,'_'); if(s==NULL) s=sess+strlen(sess);
316
  if(s<sess+4) s=sess; else s=s-4;
317
  cl=getvar("wims_class"); if(cl==NULL) cl="";
318
  snprintf(tmplbuf,sizeof(tmplbuf),"%s %.6s %s\11%s\11%s\11%s",
319
      nowstr, s, ip, c, cl, p);
320
  write_logfile("mail.log",tmplbuf);
10 reyssat 321
}
322
 
7563 bpr 323
/* log posted data */
10 reyssat 324
void post_log(void)
325
{
12210 bpr 326
  char *h, *l, logstr[2*MAX_LINELEN+2];
327
  char *authpwd, *p, *ll, *l1 ;
15547 bpr 328
  static char *obliterate[]={"auth_password=","passwd=","passsup=","password="};
15546 bpr 329
  int i, oblicnt=sizeof(obliterate)/sizeof(char*);;
10 reyssat 330
 
12210 bpr 331
  h=remote_addr;
332
  if(mpboundary[0]!=0) l="multipart/form-data"; else l=stdinbuf;
4347 reyssat 333
 
12210 bpr 334
  ll=strdup(l);
15546 bpr 335
  for(i=0;i<oblicnt;++i){
336
    authpwd=obliterate[i];
337
    if((p=strstr(ll,authpwd))!=NULL ) {
338
      l1=strdup(ll);
339
      mystrncpy(ll,l1,p-ll+strlen(authpwd)+1);
340
      strcat(ll,"xxxx");
15547 bpr 341
      l1+=(p-ll)+strlen(authpwd);
15546 bpr 342
      if((p=strstr(l1,"&"))!=NULL) strcat(ll,p);
343
    }
12210 bpr 344
  }
345
  snprintf(logstr,sizeof(logstr),"%s %s\t%s",
346
     nowstr, h, ll);
347
  write_logfile("post.log",logstr);
10 reyssat 348
}
349
 
7563 bpr 350
/* It is this routine which is called by main(). */
10 reyssat 351
void write_logs(void)
352
{
12210 bpr 353
  char *p;
354
  p=getvar(ro_name[ro_cmd]); if(p==NULL || *p==0) p="no_cmd";
12277 bpr 355
  access_log(p);
356
  if(strstr(session_prefix,"_check")!=NULL) return;
12210 bpr 357
  module_log(); referer_log();
358
  if(new_session) session_log(p);
10 reyssat 359
}
360
 
361
void user_error_log(char msg[])
362
{
12210 bpr 363
  char *s, *m, *c, *h, *q, *r, *sess, logstr[512];
364
  if(mode==mode_default) sess=getvar("wims_session");
365
  else sess="popup";
366
  if(sess==NULL) sess="----------";
367
  m=getvar(ro_name[ro_module]);if(m==NULL) m="";
368
  c=getvar(ro_name[ro_cmd]);if(c==NULL) c="";
369
  h=remote_addr;
370
  q=getenv("QUERY_STRING");if(q==NULL) q="";
371
  r=getenv("HTTP_REFERER");
372
  if(r==NULL || strstr(r,cgi_name)!=NULL) r="";
373
  s=strchr(sess,'_'); if(s==NULL) s=sess+strlen(sess);
374
  if(s<sess+4) s=sess; else s=s-4;
375
  snprintf(logstr,sizeof(logstr),"%s %.5s %s %s, module=%s cmd=%s: %s %s",
376
     nowstr, s, h, msg, m, c, r, q);
377
  write_logfile("user_error.log",logstr);
378
  if(user_error_nolog) return;
379
  access_log("user_error");referer_log();
10 reyssat 380
}
381
 
382
void module_error_log(char msg[])
383
{
12210 bpr 384
  char *s, *m, *c, logstr[256];
385
  if(strstr(msg,"debug")!=NULL || strstr(msg,"timeup")!=NULL) return;
386
  if(strstr(m_file.name,"sessions/")!=NULL) return;
387
  s=getvar(ro_name[ro_module]);
388
  if(s!=NULL) {
389
   if(strncmp(s,"classes/",strlen("classes/"))==0 ||
390
    strncmp(s,"devel/",strlen("devel/"))==0) return;
391
  }
392
  s=getvar("wims_session"); if(s==NULL) s="  ";
393
  m=getvar(ro_name[ro_module]);if(m==NULL) m="";
394
  c=getvar(ro_name[ro_cmd]);if(c==NULL) c="";
395
  snprintf(logstr,sizeof(logstr),"%s %.10s %s in %s/%s, line %d",
396
     nowstr, s+2, msg, m, m_file.name, m_file.l+1);
397
  write_logfile("module_error.log",logstr);
398
  access_log("module_error");
10 reyssat 399
}
400
 
7563 bpr 401
/* Refused users due to threshold excess */
10 reyssat 402
void refuse_log(int th)
403
{
12210 bpr 404
  char *load, *h;
7563 bpr 405
 
12210 bpr 406
  load=getvar("wims_server_load"); if(load==NULL) load="??";
407
  h=remote_addr;
408
  snprintf(tmplbuf,sizeof(tmplbuf),"%s %s\11%d:%s",
409
      nowstr, h, th, load);
410
  write_logfile("refuse.log",tmplbuf);
10 reyssat 411
}
412
 
413
#define logdpid "../tmp/log/wimslogd.pid"
414
#define newlogd "../tmp/log/wimslogd.new"
415
 
416
void bringuplogd(void)
417
{
12210 bpr 418
  char *arg[]={"../bin/wimslogd",NULL};
419
  struct stat st;
420
  pid_t pid;
10 reyssat 421
 
8155 bpr 422
/* need to update wimslogd? */
12210 bpr 423
  if(stat(newlogd,&st)==0) {
424
   if((S_IXUSR&st.st_mode)!=0 && st.st_size>40000 && st.st_size<200000)
425
     call_ssh("mv %s %s",newlogd,arg[0]);
426
   else call_ssh("rm -f %s",newlogd);
427
  }
428
  pid=fork(); if(pid) return;   /* parent */
8155 bpr 429
/* double fork to escape sysmask orphan. */
12210 bpr 430
  pid=fork(); if(pid) {   /* secondary parent */
431
   snprintf(tmplbuf,sizeof(tmplbuf),"%u",pid);
432
   mkdirs("../tmp/log");
433
   chmod("../tmp/log",S_IRUSR|S_IWUSR|S_IXUSR);
434
   accessfile(tmplbuf,"w",logdpid);
435
   exit(0);
436
  }
15509 bpr 437
// don't change the order: use in Wimslogd/wimslogd.c in parms()
12210 bpr 438
  setreuid(geteuid(),geteuid());setregid(getegid(),getegid());
15509 bpr 439
  snprintf(tmplbuf,sizeof(tmplbuf),"%u %u %u %u %u %u %d %d %d %d",
12210 bpr 440
      idle_time,idle_time2,idle_time3,
441
      OLD_LOG_FILES,GEN_LOG_LIMIT,
442
      MODULE_LOG_LIMIT,backup_hour,site_accounting,
15509 bpr 443
      examlog_limit,LOG_DELETE);
7563 bpr 444
 
12210 bpr 445
  setenv("wimslogd",tmplbuf,1);
446
  execve(arg[0],arg,environ);
447
  fprintf(stderr,"Unable to execute wimslogd: %s\n",strerror(errno));
448
  exit(1);
10 reyssat 449
}
450
 
451
void checklogd(void)
452
{
12210 bpr 453
  int i,t;
454
  char *p1, *p2, *p, buf[MAX_LINELEN+1];
455
  sun.sun_family=PF_UNIX;
456
  snprintf(sun.sun_path,sizeof(sun.sun_path),"%s",ksockfile);
457
  p=getenv("REMOTE_ADDR"); if(p==NULL) p="";
458
  snprintf(buf+sizeof(int),sizeof(buf)-sizeof(int),"ping %s",p);
459
  t=kerneld(buf,sizeof(buf)); if(t<0) {
460
    bringuplogd();
461
    for(i=0; i<10 && t<0; i++) {
462
      msleep(100);
463
        snprintf(buf+sizeof(int),sizeof(buf)-sizeof(int),"ping %s",p);
464
     t=kerneld(buf,sizeof(buf));
10 reyssat 465
    }
12210 bpr 466
  }
467
  if(t<0) internal_error("Unable to bring up wimslogd.");
468
  p1=find_word_start(buf+sizeof(int)); p2=find_word_end(p1);
469
  if(*p2) *p2++=0;
470
  if(strcmp(p1,"OK")!=0) internal_error("wimslogd error.");
471
  if(*p2=='1') hostcquota=1; else hostcquota=0;
472
  p1=find_word_start(find_word_end(p2));
473
  p2=strchr(p1,'\n'); if(p2) *p2++=0; else p2=p1+strlen(p1);
474
  mystrncpy(loadavg,p1,sizeof(loadavg));
475
  p2=find_word_start(p2);
476
  p1=find_word_end(p2); if(*p1) *p1++=0;
7563 bpr 477
 
12210 bpr 478
  p=getenv("SERVER_ADDR");
479
  if(*p2!=0 && memcmp(p,"10.",3)==0) p=p2;
480
  if(p!=NULL) {
481
    i=strlen(cookieheader);
482
    snprintf(cookieheader+i, sizeof(cookieheader)-i,"%s/",p);
483
  }
484
  p=getenv("HTTP_COOKIE"); cookiegot[0]=0;
485
  if(p!=NULL && (p2=strstr(p,cookieheader))!=NULL) {
486
    mystrncpy(cookiegot,find_word_start(p+strlen(cookieheader)),sizeof(cookiegot));
487
    *find_word_end(cookiegot)=0;
488
  }
10 reyssat 489
}