Subversion Repositories wimsdev

Rev

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

Rev Author Line No. Line
10 reyssat 1
/*    Copyright (C) 1998-2003 XIAO, Gang of Universite de Nice - Sophia Antipolis
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
 */
17
 
8185 bpr 18
/* This file contains various configuration routines for wims. */
10 reyssat 19
 
8185 bpr 20
/* Limitations are essentially for security reasons:
21
 * to curb attacks by resource exhaustion of the server.
22
 */
10 reyssat 23
 
8185 bpr 24
#include "wims.h"
25
 
26
/* maximal length of any module's variable definition file. */
10 reyssat 27
int VAR_DEF_LENGTH_LIMIT=50000;
7673 bpr 28
/* Limit for frames in an animation. */
10 reyssat 29
int ANIM_LIMIT=400;
7673 bpr 30
/* module log file length */
10 reyssat 31
int MODULE_LOG_LIMIT=102400;
7673 bpr 32
/* general log file length */
10 reyssat 33
int GEN_LOG_LIMIT=1024000;
7673 bpr 34
/* number of old log files */
10 reyssat 35
int OLD_LOG_FILES=2;
36
 
7673 bpr 37
/* Resource limits */
13730 obado 38
int threshold1=150; /* First load threshold */
39
int threshold2=300; /* Second load threshold */
7673 bpr 40
int ispriority=0; /* whether the connection is from priority sites */
10 reyssat 41
 
7673 bpr 42
/* sessions not accessed more than these seconds will be erased. */
10 reyssat 43
int idle_time=5400;
7673 bpr 44
/* non-class sessions not accessed more than these seconds will be erased. */
10 reyssat 45
int idle_time2=2400;
7673 bpr 46
/* first-time sessions not accessed more than these seconds will be erased. */
10 reyssat 47
int idle_time3=900;
48
 
7673 bpr 49
int rafalvl=10; /* anti-rapidfire severity */
10 reyssat 50
 
13730 obado 51
/* Explanation: two real numbers a,b such as * |a+b|>|a-b|*compare_precision
7673 bpr 52
 * will be considered equal in !ifvalue comparisons. */
10 reyssat 53
int DEFAULT_COMPARE_PRECISION=10000;
7673 bpr 54
/* Precision of printing (hence of all evaluations). */
10 reyssat 55
int DEFAULT_PRINT_PRECISION=8;
7673 bpr 56
/* Defaults for instex, insplot, etc. */
10 reyssat 57
char *DEFAULT_INS_FORMAT="gif";
58
char *DEFAULT_ANIM_FORMAT="gif";
59
char *DEFAULT_INS_DENSITY="100x100";
60
char *DEFAULT_INSPLOT_FONT="small";
61
 
7673 bpr 62
/* gnuplot intermediate graphics format */
10 reyssat 63
char *gnuplot_format="gif";
64
 
8185 bpr 65
/* electronic address of site manager. */
10 reyssat 66
char *site_manager="wims@$httpd_HTTP_HOST";
8185 bpr 67
/* Main configure file, this name cannot be configured! */
10 reyssat 68
char *config_file="../log/wims.conf";
69
char PATH[512];  /* directory settings */
8191 bpr 70
char *commonpath="/usr/local/bin:/usr/bin:/usr/games:/bin:/usr/bin/X11:/usr/X11R6/bin:/usr/texbin:/usr/local/texbin";
4331 bpr 71
char *gap_command="gap.sh -T -m 64M";
9336 bpr 72
char *maxima_command="maxima -X '--dynamic-space-size 512'";
10 reyssat 73
char *pari_command="gp -f -q -p 150000";
10875 obado 74
char *octave_command="octave -Hfq --no-line-editing --no-window-system --silent";
4417 bpr 75
char *scilab_command="scilab -nwni";
6717 guerimand 76
char *QRencode_command="qrencode -o";
10 reyssat 77
 
8284 bpr 78
/* default languages */
10 reyssat 79
char site_langbuf[]="en fr cn es it nl";
80
char *site_languages=site_langbuf;
8284 bpr 81
/* Statistics shows up? */
10 reyssat 82
char *show_stat="no";
8284 bpr 83
/* Author names show up in search result? */
10 reyssat 84
char *show_author="no";
13730 obado 85
/* Show user IP address to supervisor */
7079 bpr 86
char *show_ip="yes";
8284 bpr 87
/* busy hours definition */
10 reyssat 88
char *busyhours="";
8284 bpr 89
/* Presentation theme */
3048 bpr 90
char *theme="standard";
8284 bpr 91
/* directory of session files */
10 reyssat 92
char session_dir[MAX_FNAME+1], s2_dir[MAX_FNAME+1];
8284 bpr 93
/* standardised header model for modules' output. Will be stored
94
 * into the variable $wims_html_header. If the theme contains
95
 * a file 'head.phtml', html_header will be defined by the address
96
 * of this file  in subroutine define_html_header
97
 */
10 reyssat 98
char *html_header="html/header.phtml";
8284 bpr 99
/* standardised about table for modules */
10 reyssat 100
char *module_about_file="html/module_about";
8284 bpr 101
/* title definition page */
10 reyssat 102
char *title_page="title.phtml";
13730 obado 103
/* standardised header menu bar, to be included in module pages
8284 bpr 104
 * via command !headmenu */
10 reyssat 105
char *header_menu="headmenu.phtml";
106
char *header_menu_user="headmenu_user.phtml";
107
char *header_menu_supervisor="headmenu_supervisor.phtml";
8284 bpr 108
/* standardised referer to wims home, to be included in
109
 * module pages via command !homeref */
10 reyssat 110
char *home_referer="homeref.phtml";
111
char *home_referer_user="homeref_user.phtml";
112
char *home_referer_supervisor="homeref_supervisor.phtml";
8284 bpr 113
/* background color in standard reference tables */
3079 bpr 114
char *ref_bgcolor="#777777";
12357 obado 115
/* standard link color */
14734 obado 116
char *link_color="#1468A0";
12357 obado 117
/* visited link color */
14734 obado 118
char *vlink_color="#1779BA";
12357 obado 119
/* hover link color */
120
char *hlink_color="#004077";
8284 bpr 121
/* link color in standard reference tables */
8696 obado 122
char *ref_menucolor="#FFFFFF";
8284 bpr 123
/* background help button color */
8696 obado 124
char *ref_button_help_bgcolor="#008f00";
8284 bpr 125
/* background help button color */
8696 obado 126
char *ref_button_help_color="#FFFFFF";
3064 bpr 127
  /* button background color */
3078 bpr 128
char *ref_button_bgcolor="#666666";
3064 bpr 129
  /* button color */
8696 obado 130
char *ref_button_color="#FFFFFF";
12884 obado 131
  /* Default colors for activity types */
14838 obado 132
char *actcolor="#000000,#CCCCFF,#99CCFF,#9999FF,#6666FF,#FFFFFF,#99CCDD,#AFB31E,#E6A493";
8185 bpr 133
/* module log disabled by default */
10 reyssat 134
int modlog=0;
8185 bpr 135
/* name of the variable definition file for every module.
136
 * It is this file which defines the presence of the module.
137
* Better do not make it configurable.
138
*/
10 reyssat 139
char var_def_file[256];
8185 bpr 140
/* name of variable init file. Processed only when cmd=new or renew. */
10 reyssat 141
char *var_init_file="var.init";
8185 bpr 142
/* name of variable calculation file. Parsed at each call. */
10 reyssat 143
char *main_var_proc_file="var.proc";
8185 bpr 144
/* name of the main (programmable) html file. */
10 reyssat 145
char *html_file="main.phtml";
8185 bpr 146
/* Introduction page name */
10 reyssat 147
char *intro_file="intro.phtml";
8185 bpr 148
/* Reference page */
10 reyssat 149
char *ref_file="wims_ref.phtml";
8185 bpr 150
/* script to process different inserts.
151
 * The two consecutive points in the name prohibits ordinary
152
 * user execution of the script.
153
 */
10 reyssat 154
char *insdraw_processor="insdraw..processor";
155
char *insplot_processor="insplot..processor";
156
char *tex2gif="bin/tex..gif";
7673 bpr 157
char *priority=""; /* IPs of priority sites */
10 reyssat 158
char *texgif_fontdir="w/texgif";
159
char *texgif_texheader="mathfonts/header";
14734 obado 160
char *bgcolor="#F6F6F6"; /* page background color */
7673 bpr 161
char *bgimg="";  /* page background image file */
162
char *pagecss="-theme-";  /* style sheet file */
163
char *theme_icon="default";  /* icon */
164
char *usecookie="no";  /* whether to send cookies to anon requests */
165
char *mail_opt="";  /* !mailto options */
166
char nodeip[256]="";  /* ip of cluster node if relevant */
167
char temp_log[MAX_FNAME+1]; /* temp log file name */
168
 /* 0: low; 1: high; 2: MathML */
169
int mathalign_base=0;  /* Not use <sup> for middle alignment */
170
char *disable_zoom="no";  /* yes/no:  default zooming allowed (if enabled via "useropts")  */
15297 bpr 171
 
6178 bpr 172
int spec_font=0; /* choose of some fonts*/
173
 /* special font can be configured in log/wims.conf with variable special_font*/
8909 bpr 174
char *special_font="letter-spacing:0.1em;line-height:2.7em;word-spacing:0.8em;font-family:OpenDyslexic3,OpenDyslexic,sans-serif !important;";
7673 bpr 175
int backup_hour=-1; /* Hour for daily backup; -1 means no backup. */
176
int site_accounting=0; /* whether accounting should be activated */
177
int examlog_limit=7; /* number of logged exam sessions for each student */
10 reyssat 178
 
8284 bpr 179
/* Automatic module update */
10 reyssat 180
char *mu_auto="none";
181
char *mu_cat="all";
6533 bpr 182
char *mu_delay="3";
2715 guerimand 183
char *mu_site="http://wims.unice.fr/download/modules";
10 reyssat 184
char *mu_zone="all";
3121 bpr 185
char *mu_download_site="unice,wimsedu";
3046 bpr 186
char *mu_publish_site="unice";
10 reyssat 187
 
13730 obado 188
/* keywords destined to robots */
10 reyssat 189
char *site_keywords="interactive mathematics, interactive math, server side interactivity";
190
char *site_description="interactive exercises, online calculators and plotters, mathematical recreation and games";
191
 
8284 bpr 192
/* class and document authorization */
13730 obado 193
int class_quota=150;
194
int superclass_quota=150;
10 reyssat 195
int doc_quota=32;
196
char *class_regpass="email,email,deny";
197
char *doc_regpass="";
198
 
8284 bpr 199
/* Where to find programs; if your httpd sets /bin:/usr/bin in PATH,
200
 * this should be OK.
201
 */
10 reyssat 202
char *sed_prog="sed";
203
char *tr_prog="tr";
204
char *awk_prog="awk";
205
 
206
  /* myname */
207
char *cgi_name="wims.cgi";
208
char *aliased_cgi="no";
209
char *aliased_getfile="yes";
210
 
211
  /* Limits for classes and participants */
212
int class_limit=200; /* limit of number of classes */
213
int user_limit=5000; /* limit of total number of registered users */
214
int class_user_limit=300; /* limit of users in one class */
215
int forum_limit=100;  /* Limit of message boards */
216
 
217
CONFIG_DATA main_config[]={
12270 bpr 218
  {"PATH",0, &commonpath},
219
  {"QRencode_command",2, &QRencode_command},
12884 obado 220
  {"actcolor",0, &actcolor},
12270 bpr 221
  {"aliased_cgi",0, &aliased_cgi},
222
  {"aliased_getfile",0, &aliased_getfile},
223
  {"backup_hour",1, &backup_hour},
224
  {"busyhours",0, &busyhours},
225
  {"cgi_name",0, &cgi_name},
226
  {"class_limit",1, &class_limit},
227
  {"class_quota",1, &class_quota},
228
  {"class_regpass",0, &class_regpass},
229
  {"class_user_limit",1, &class_user_limit},
230
  {"css",0, &pagecss},
231
  {"default_anim_format",0, &DEFAULT_ANIM_FORMAT},
232
  {"default_ins_format",0, &DEFAULT_INS_FORMAT},
233
  {"default_insplot_font",0, &DEFAULT_INSPLOT_FONT},
234
  {"default_texposition",1, &mathalign_base},
235
  {"devel_modules",0, &devel_modules},
236
  {"doc_quota",1, &doc_quota},
237
  {"doc_regpass",0, &doc_regpass},
238
  {"examlog_limit",1, &examlog_limit},
239
  {"forum_limit",1, &forum_limit},
240
  {"gap_command",2, &gap_command},
241
  {"general_log_limit",1, &GEN_LOG_LIMIT},
242
  {"gnuplot_format",0, &gnuplot_format},
12357 obado 243
  {"hlink_color",0, &hlink_color},
12270 bpr 244
  {"home_module",0, &home_module},
245
  {"idle_time",1, &idle_time},
246
  {"idle_time2",1, &idle_time2},
247
  {"idle_time3",1, &idle_time3},
248
  {"insdraw_processor",0, &insdraw_processor},
249
  {"link_color",0, &link_color},
250
  {"mail_opt",0, &mail_opt},
251
  {"manager_https",1, &manager_https},
252
  {"manager_site",0, &manager_site},
253
  {"maxima_command",2, &maxima_command},
254
  {"module_log",1, &modlog},
255
  {"module_log_limit",1, &MODULE_LOG_LIMIT},
256
  {"mu_auto",0, &mu_auto},
257
  {"mu_cat",0, &mu_cat},
258
  {"mu_delay",0, &mu_delay},
259
  {"mu_download_site",0, &mu_download_site},
260
  {"mu_publish_site",0, &mu_publish_site},
261
  {"mu_site",0, &mu_site},
262
  {"mu_zone",0, &mu_zone},
263
  {"octave_command",2, &octave_command},
264
  {"old_log_files",1, &OLD_LOG_FILES},
265
  {"page_bgcolor",0, &bgcolor},
266
  {"page_bgimg",0, &bgimg},
267
  {"pari_command",2, &pari_command},
268
  {"priority",0, &priority},
269
  {"rafale_level",1, &rafalvl},
270
  {"ref_bgcolor",0, &ref_bgcolor},
271
  {"ref_button_bgcolor",0, &ref_button_bgcolor},
272
  {"ref_button_color",0, &ref_button_color},
273
  {"ref_button_help_bgcolor",0, &ref_button_help_bgcolor},
274
  {"ref_button_help_color",0, &ref_button_help_color},
275
  {"ref_menucolor",0, &ref_menucolor},
276
  {"rlimit_cpu",1, &rlimit_cpu},
277
  {"scilab_command",2, &scilab_command},
278
  {"show_author",0, &show_author},
279
  {"show_ip",0, &show_ip},
280
  {"show_stat",0, &show_stat},
281
  {"site_accounting",1, &site_accounting},
282
  {"site_description",0, &site_description},
283
  {"site_keywords",0, &site_keywords},
284
  {"site_languages",0, &site_languages},
285
  {"site_manager",0, &site_manager},
286
  {"superclass_quota",1, &superclass_quota},
287
  {"texbasesize",1, &texbasesize},
288
  {"theme",0, &theme},
289
  {"theme_icon",0, &theme_icon},
290
  {"threshold1",1, &threshold1},
291
  {"threshold2",1, &threshold2},
292
  {"tmp_debug",0, &tmp_debug},
293
  {"tmp_debug_var",0, &tmp_debug_var},
294
  {"trusted_modules",0, &trusted_modules},
295
  {"usecookie",0, &usecookie},
296
  {"user_limit",1, &user_limit},
297
  {"var_def_length_limit",1, &VAR_DEF_LENGTH_LIMIT},
298
  {"vlink_color",0, &vlink_color},
299
  {"workfile_limit",1, &WORKFILE_LIMIT}
10 reyssat 300
};
8185 bpr 301
int MAIN_CONFIG_NO=(sizeof(main_config)/sizeof(main_config[0]));
10 reyssat 302
 
8851 bpr 303
/* processes the list of languages supported on the site */
10 reyssat 304
void language_list(void)
305
{
12239 bpr 306
  int i,k;
307
  char *lbuf[MAX_LANGUAGES];
308
  calc_tolower(site_languages); items2words(site_languages);
309
  setvar("wims_site_languages",site_languages);
310
  i=cutwords(site_languages,lbuf,MAX_LANGUAGES);
311
  available_lang_no=i;
312
  for(i=k=0;i<available_lang_no;i++) {
313
    if(strlen(lbuf[i])==2) memmove(available_lang[k++],lbuf[i],3);
314
  }
315
  if(k>0) memmove(lang,available_lang[0],3);
10 reyssat 316
}
317
 
318
char hostname[256];
319
int html_call=0;
320
 
8851 bpr 321
/* determine the http reference name of the server */
10 reyssat 322
void determine_ref_name(void)
323
{
12239 bpr 324
  char *s1, *s2, *p, *pl;
325
  char buf[MAX_LINELEN+1];
326
  int len;
10 reyssat 327
 
12239 bpr 328
  hostname[0]=0;
329
  s1=getvar("httpd_HTTP_HOST");s2=getvar("httpd_SCRIPT_NAME");
330
  gethostname(hostname,sizeof(hostname));
331
  if(hostname[0]==0 && s1 && *s1!=0) mystrncpy(hostname,s1,sizeof(hostname));
332
  if(s1==NULL || *s1==0) s1=hostname;
333
  setvar("wims_myhostname",hostname);
334
  ref_base[0]=0;
335
  if(s2!=NULL) mystrncpy(buf,s2,sizeof(buf));
336
  else buf[0]=0;
337
  if(s1!=NULL && *buf=='/') {
338
    p=strrchr(buf,'/'); if(p==NULL) p=buf; else *p++=0;
12357 obado 339
    /* address of type /wims/fr_H2~algebra~oeffraction.fr.html */
12239 bpr 340
    if(strcmp(p,cgi_name)!=0 && strlen(p)>4 &&
341
       p[2]=='_' && islower(p[0]) && islower(p[1])) {
342
      pre_language[0]=p[0];pre_language[1]=p[1];pre_language[2]=0;
343
      p[2]=0; setenv("HTTP_ACCEPT_LANGUAGE",p,1); pl=p; p+=3;
12270 bpr 344
      s2=strrchr(p,'.');
345
      if(s2!=NULL) {
346
        *s2=0;
347
        if(strcasecmp(s2+1,"cgi")!=0) html_call=1;
8851 bpr 348
      }
12239 bpr 349
      s2=p; while((s2=strpbrk(s2,"@~"))!=NULL) *s2='/';
350
      if(strncmp(p,"doc/",4)==0) {
351
        char *pd, *pb;
352
        pd=p+4;
353
        if(*pd) {
354
          pb=strchr(pd,'/');
355
          if(pb) *pb++=0; else pb="main";
356
          setvar("doc",pd); setvar("block",pb); setvar("job","read");
357
        }
358
        setvar(ro_name[ro_module],mkfname(NULL,"adm/doc.%s",pl));
8851 bpr 359
      }
12239 bpr 360
      else setvar(ro_name[ro_module],p);
361
      module_defined=1;
10 reyssat 362
    }
12239 bpr 363
    p=strchr(buf,'_');
364
    if(p!=NULL && p>buf+3 && myislower(*(p-1)) && myislower(*(p-2))
365
         && *(p-3)=='/' && myisalpha(*(p+1))) {
366
      char *pp;
367
      for(pp=p+1; myisalnum(*pp); pp++){};
368
      if(*pp=='/') *(p-3)=0;
369
    }
13395 bpr 370
    p=getenv("HTTPS");
371
    if(p!=NULL && strcmp(p,"on")==0)
372
      snprintf(ref_name,sizeof(ref_name)-2,"https://%s%s/%s",s1,buf,cgi_name);
373
    else
374
      snprintf(ref_name,sizeof(ref_name)-2,"http://%s%s/%s",s1,buf,cgi_name);
12239 bpr 375
    mystrncpy(ref_base,ref_name,sizeof(ref_base)-2);
376
    p=strrchr(ref_base,'/');
377
    if(p!=NULL) *(p+1)=0;
378
  }
379
  else mystrncpy(ref_name,cgi_name,sizeof(ref_name)-1);
11689 obado 380
 
381
    // XSS PROTECTION (remove unwanted chars to avoid a possible XSS hack)
12270 bpr 382
    // Search for a first occurence of forbidden chars
383
  len = strcspn(ref_name, "<>'\"\\");
11689 obado 384
    // Give only the ref_name before forbidden chars
12270 bpr 385
  ref_name[len]=0;
11689 obado 386
 
12239 bpr 387
  setvar("wims_ref_name",ref_name);
10 reyssat 388
}
389
 
13730 obado 390
      /* Read and interpret wims configuration file. */
10 reyssat 391
void main_configure(void)
392
{
12239 bpr 393
  int i;
394
  char *conf_buf,*e,*p,*p2,*p3;
395
  char buf[MAX_LINELEN+1];
7079 bpr 396
 
12239 bpr 397
  conf_buf=readfile(config_file,NULL,WORKFILE_LIMIT);
398
  if(conf_buf==NULL) goto fileend;
399
  e=conf_buf-1; while(e) {
400
    p=e+1; e=strchr(p,'\n'); if(e) *e=0;
401
    p=find_word_start(p);
402
    if(*p==0 || *p==comment_prefix_char) continue; /* empty or comment line */
403
    p2=strchr(p,'=');
404
    if(p2==NULL) continue; /* syntax error */
405
    *p2=0; *find_word_end(p)=0; p2=find_word_start(p2+1);
406
    p3=p2+strlen(p2); while(myislspace(p3[-1])) p3--;
407
    while(p3[-1]=='\\') p3--;
408
    *p3=0;
409
    i=search_list(main_config,MAIN_CONFIG_NO,sizeof(main_config[0]),p);
410
    if(i<0) continue; /* name non-defined */
411
    if(main_config[i].is_integer==1) {
412
      int *ip;
413
      ip=main_config[i].address;
414
      *ip=atoi(p2); if(*ip<0) *ip=0;
10 reyssat 415
    }
416
    else {
12239 bpr 417
      char **cp;
418
      cp=main_config[i].address;
419
      *cp=p2;
10 reyssat 420
    }
12239 bpr 421
  }
422
  fileend:
423
  setenv("session_base_dir",session_dir,1);
424
  determine_ref_name();
425
  language_list();
426
  for(i=0;i<MAIN_CONFIG_NO;i++) {
427
    char **pp;
428
    if(main_config[i].is_integer==2) {
429
      pp=main_config[i].address;
430
      setenv(main_config[i].name,*pp,1);
10 reyssat 431
    }
12239 bpr 432
  }
433
        /* check priority */
434
  if(priority[0] && checkhost(priority)>0) ispriority=1;
435
  (void)getcwd(cwdbuf,sizeof(cwdbuf)); setvar("httpd_PWD",cwdbuf);
436
  setenv("wims_server_base",cwdbuf,1);
437
  p=strrchr(cwdbuf,'/');
438
  if(p!=NULL && strcmp(p,"/public_html")==0) {
439
    *p=0; snprintf(PATH,sizeof(PATH),"%s/other/bin:%s",cwdbuf,commonpath);
440
    force_setvar("wims_home",cwdbuf);
441
    *p='/';
442
  }
443
  else {
444
    snprintf(PATH,sizeof(PATH),"%s/../other/bin:%s",cwdbuf,commonpath);
445
    force_setvar("wims_home",cwdbuf);
446
  }
447
  setenv("PATH",PATH,1);
448
  p=getvar("httpd_SERVER_SOFTWARE");
449
  if(p && (strstr(p,"Apache"))!=NULL && strstr(aliased_getfile,"yes")!=NULL)
450
    good_httpd=1;
451
  accessfile(buf,"r","../tmp/log/myip");
452
  *find_word_end(buf)=0;
453
  if(buf[0]) {
454
    snprintf(nodeip,sizeof(nodeip),"%s",buf);
455
    snprintf(temp_log,sizeof(temp_log),"%s.%s",TEMP_LOG_FILE,nodeip);
456
    force_setvar("wims_priv_nodeip",nodeip);
457
  }
458
  else {
459
    nodeip[0]=0;
460
    snprintf(temp_log,sizeof(temp_log),"%s",TEMP_LOG_FILE);
461
  }
10 reyssat 462
}
463
 
464
struct {
12239 bpr 465
  int rname;
466
  int *rval;
10 reyssat 467
} resource_table[]={
468
#ifdef RLIMIT_CPU
12270 bpr 469
  {RLIMIT_CPU, &rlimit_cpu},
10 reyssat 470
#endif
471
#ifdef RLIMIT_FSIZE
12270 bpr 472
  {RLIMIT_FSIZE, &rlimit_fsize},
10 reyssat 473
#endif
474
#ifdef RLIMIT_AS
12270 bpr 475
  {RLIMIT_AS, &rlimit_as},
10 reyssat 476
#endif
477
#ifdef RLIMIT_DATA
12270 bpr 478
  {RLIMIT_DATA, &rlimit_data},
10 reyssat 479
#endif
480
#ifdef RLIMIT_STACK
12270 bpr 481
  {RLIMIT_STACK, &rlimit_stack},
10 reyssat 482
#endif
483
#ifdef RLIMIT_CORE
12270 bpr 484
  {RLIMIT_CORE, &rlimit_core},
10 reyssat 485
#endif
486
#ifdef RLIMIT_RSS
12270 bpr 487
  {RLIMIT_RSS, &rlimit_rss},
10 reyssat 488
#endif
489
#ifdef RLIMIT_NPROC
12270 bpr 490
  {RLIMIT_NPROC, &rlimit_nproc},
10 reyssat 491
#endif
492
#ifdef RLIMIT_NOFILE
12270 bpr 493
  {RLIMIT_NOFILE, &rlimit_nofile},
10 reyssat 494
#endif
495
#ifdef RLIMIT_MEMLOCK
12270 bpr 496
  {RLIMIT_MEMLOCK, &rlimit_memlock}
10 reyssat 497
#endif
498
};
499
#define RESOURCE_NO (sizeof(resource_table)/sizeof(resource_table[0]))
500
 
7673 bpr 501
/* set system resource limits */
10 reyssat 502
void set_rlimits(void)
503
{
12239 bpr 504
  int i;
505
  struct rlimit rlim;
7079 bpr 506
 
12239 bpr 507
  for(i=0;i<RESOURCE_NO;i++) {
508
    rlim.rlim_cur=rlim.rlim_max=*(resource_table[i].rval);
509
    setrlimit(resource_table[i].rname,&rlim);
510
    if(resource_table[i].rname==RLIMIT_CPU) {
511
      setvar("wims_cpu_limit",int2str(rlim.rlim_max));
512
      initalarm();
10 reyssat 513
    }
12239 bpr 514
  }
10 reyssat 515
}
516
 
517
struct {
12239 bpr 518
  char *name;
519
  int is_integer;
520
  void *default_value;
10 reyssat 521
} module_default[]={
12239 bpr 522
  {"anim_format",0, &DEFAULT_ANIM_FORMAT},
523
  {"gnuplot_format",0, &gnuplot_format},
524
  {"ins_anim_limit",1, &ANIM_LIMIT},
525
  {"ins_density",0, &DEFAULT_INS_DENSITY},
526
  {"ins_format",0, &DEFAULT_INS_FORMAT},
527
  {"insplot_font",0, &DEFAULT_INSPLOT_FONT},
528
  {"wims_busyhours",0, &busyhours},
529
  {"wims_class_limit",1, &class_limit},
530
  {"wims_class_quota",1, &class_quota},
531
  {"wims_class_regpass",0, &class_regpass},
532
  {"wims_class_user_limit",1, &class_user_limit},
533
  {"wims_compare_precision",1, &DEFAULT_COMPARE_PRECISION},
534
  {"wims_devel_modules",0, &devel_modules},
535
  {"wims_doc_quota",1, &doc_quota},
536
  {"wims_doc_regpass",0, &doc_regpass},
537
  {"wims_examlog_limit",1, &examlog_limit},
538
  {"wims_forum_limit",1, &forum_limit},
539
  {"wims_bgcolor",0, &bgcolor},
540
  {"wims_bgimg",0, &bgimg},
541
  {"wims_css",0, &pagecss},
542
  {"wims_link_color",0, &link_color},
543
  {"wims_print_precision", 1, &DEFAULT_PRINT_PRECISION},
544
  {"wims_ref_bgcolor",0, &ref_bgcolor},
545
  {"wims_ref_button_bgcolor",0, &ref_button_bgcolor},
546
  {"wims_ref_button_color",0, &ref_button_color},
547
  {"wims_ref_button_help_bgcolor",0, &ref_button_help_bgcolor},
548
  {"wims_ref_button_help_color",0, &ref_button_help_color},
549
  {"wims_ref_menucolor",0, &ref_menucolor},
550
  {"wims_show_author",0, &show_author},
551
  {"wims_show_ip",0, &show_ip},
552
  {"wims_show_stat",0, &show_stat},
553
  {"wims_site_description",0, &site_description},
554
  {"wims_site_keywords",0, &site_keywords},
555
  {"wims_site_manager",0, &site_manager},
556
  {"wims_texalign",1, &mathalign_base},
557
  {"wims_texbasesize",1, &texbasesize},
558
  {"wims_theme",0, &theme},
559
  {"wims_theme_icon",0, &theme_icon},
560
  {"wims_tmp_debug",0, &tmp_debug},
561
  {"wims_usecookie",0, &usecookie},
562
  {"wims_user_limit",1, &user_limit},
563
  {"wims_vlink_color",0, &vlink_color},
12357 obado 564
  {"wims_hlink_color",0, &hlink_color},
12239 bpr 565
  {"wims_superclass_quota", 1, &superclass_quota}
10 reyssat 566
};
567
#define MODULE_DEFAULT_NO (sizeof(module_default)/sizeof(module_default[0]))
568
 
8851 bpr 569
/* Set defaults for module, and set corresponding variables. */
10 reyssat 570
void module_configure(void)
571
{
12239 bpr 572
  int i;
573
  confset=1;
574
  for(i=0;i<MODULE_DEFAULT_NO;i++) {
575
    if(module_default[i].is_integer) {
576
      int j, *jp;
577
      jp=module_default[i].default_value;
578
      j=*jp; if(j<0) j=0;
579
      setvar(module_default[i].name,int2str(j));
10 reyssat 580
    }
12239 bpr 581
    else {
582
      char **cp;
583
      cp=module_default[i].default_value;
584
      setvar(module_default[i].name,*cp);
585
    }
586
  }
587
  setenv("texgif_fontdir",texgif_fontdir,1);
588
  setenv("texgif_texheader",texgif_texheader,1);
589
  setvar("wims_texsize","0");
590
  setvar("disable_zoom","0");
591
  setvar("disable_mathml","0");
592
  setvar("force_mathml","0");
593
  /* if 'force_mathml=yes' , a check should be done on the value of 'disable_mathml'.
594
     so it's not fool-proof.
595
  */
596
  confset=0;
10 reyssat 597
}
598
 
599
char *modindex[]={
12239 bpr 600
  "address",
601
  "author",
602
  "category",
603
  "copyright",
604
  "data",
605
  "description",
606
  "description_ca",
607
  "description_cn",
608
  "description_de",
609
  "description_en",
610
  "description_es",
611
  "description_fr",
612
  "description_it",
613
  "description_nl",
614
  "description_si",
615
  "description_tw",
616
  "domain",
617
  "help",
618
  "keywords",
619
  "keywords_ca",
620
  "keywords_cn",
621
  "keywords_de",
622
  "keywords_en",
623
  "keywords_es",
624
  "keywords_fr",
625
  "keywords_it",
626
  "keywords_nl",
627
  "keywords_si",
628
  "keywords_tw",
629
  "language",
630
  "level",
631
  "maintainer",
632
  "maintainer_address",
633
  "mode",
634
  "require",
635
  "scoring",
636
  "title",
637
  "title_ca",
638
  "title_cn",
639
  "title_de",
640
  "title_en",
641
  "title_es",
642
  "title_fr",
643
  "title_it",
644
  "title_nl",
645
  "title_si",
646
  "title_tw",
647
  "translator",
648
  "translator_address",
649
  "translator_address_ca",
650
  "translator_address_cn",
651
  "translator_address_de",
652
  "translator_address_en",
653
  "translator_address_es",
654
  "translator_address_fr",
655
  "translator_address_it",
656
  "translator_address_nl",
657
  "translator_address_si",
658
  "translator_address_tw",
659
  "translator_ca",
660
  "translator_cn",
661
  "translator_de",
662
  "translator_en",
663
  "translator_es",
664
  "translator_fr",
665
  "translator_it",
666
  "translator_nl",
667
  "translator_si",
668
  "translator_tw",
669
  "vardef",
670
  "version",
671
  "wims_version",
10 reyssat 672
};
8185 bpr 673
int MODINDEX_NO=(sizeof(modindex)/sizeof(modindex[0]));
674
 
10 reyssat 675
char *module_special_file[]={
12239 bpr 676
  "intro","help"
10 reyssat 677
};
678
#define MODSPEC_NO (sizeof(module_special_file)/sizeof(module_special_file[0]))
679
 
8185 bpr 680
/* read and treat module's INDEX file */
10 reyssat 681
void module_index(void)
682
{
12239 bpr 683
  char buf[MAX_NAMELEN+1], ind_buf[MAX_LINELEN+1];
684
  char *e, *p, *p2, *ft;
685
  double v1, v2;
686
  int i,l;
687
  long indf_len;
7079 bpr 688
 
12239 bpr 689
  memmove(var_def_file,default_var_def,strlen(default_var_def)+1);
690
  ft=readfile(mkfname(NULL,"%s/INDEX",module_prefix),
691
          ind_buf,sizeof(ind_buf));
692
  if(ft==NULL) ft=readfile(mkfname(NULL,"%s/index",module_prefix),
693
                     ind_buf,sizeof(ind_buf));
694
  if(ft==NULL) return;
695
  e=ind_buf-1; indf_len=strlen(ind_buf);
696
  for(l=0; e<ind_buf+indf_len && e!=NULL ;l++) {
697
    p=e+1; e=strchr(p,'\n'); if(e!=NULL) *e=0;
698
    strip_trailing_spaces(p); p=find_word_start(p);
699
    if(*p==0 || *p==comment_prefix_char) continue; /* empty or comment line */
700
    p2=strchr(p,'=');
701
    if(p2==NULL) continue; /* syntax error */
702
    *p2=0; *find_word_end(p)=0; p2=find_word_start(p2+1);
703
    i=search_list(modindex,MODINDEX_NO,sizeof(modindex[0]),p);
704
    if(i<0) continue; /* name not in list */
705
    snprintf(buf,sizeof(buf),"module_%s",p);
706
    setvar(buf,p2);
707
  }
708
  if(mode!=mode_default) {
709
    char *s;
710
    s=getvar("module_mode");
711
    if(s==NULL) {
712
      nomode: mode=mode_default; force_setvar("wims_mode","");
10 reyssat 713
    }
12239 bpr 714
    else switch(mode) {
715
      case mode_popup: {
716
        if(strstr(s,"popup")==NULL) goto nomode;
717
        else break;
8851 bpr 718
      }
12239 bpr 719
      case mode_raw: {
720
        if(strstr(s,"raw")==NULL) goto nomode;
721
        else break;
722
      }
723
      default: break;
10 reyssat 724
    }
12239 bpr 725
  }
7673 bpr 726
/* test for existence of some special files in module's directory */
12239 bpr 727
  for(i=0;i<MODSPEC_NO;i++) {
728
    if(ftest(mkfname(NULL,"%s/%s.phtml",module_prefix,module_special_file[i]))
729
      ==is_file) {
730
      snprintf(buf,sizeof(buf),"module_has_%s",module_special_file[i]);
731
      setvar(buf,"yes");
10 reyssat 732
    }
12239 bpr 733
  }
734
  p=getvar("module_language"); if(p==NULL || *p==0) setvar("module_language","en");
735
  setvar("module_has_about","yes"); /* now we have default about.phtml */
7673 bpr 736
/* Set var_def */
12239 bpr 737
  p=getvar("module_vardef");
738
  if(p!=NULL && *p!=0) mystrncpy(var_def_file,p,sizeof(var_def_file));
739
  p=getvar("module_wims_version"); if(p!=NULL && *p!=0) {
740
    v1=atof(p); v2=atof(wims_version);
741
    if(isfinite(v1) && isfinite(v2) &&
7673 bpr 742
        (v1>v2 || (v1==v2 && strcmp(find_word_start(p),wims_version)>0))) {
12239 bpr 743
      setvar("module_wims_version",p);
744
      setvar("wims_version",wims_version);
745
      module_error("antidated_version");
10 reyssat 746
    }
12239 bpr 747
  }
748
  if(isdevelmodule) {
749
    p=getvar("module_scoring");
750
    if(p==NULL || strcasecmp(p,"yes")!=0) isdevelmodule=0;
751
  }
10 reyssat 752
}
753
 
7673 bpr 754
/* Set up a unique job identity as a 4-bytes integer */
10 reyssat 755
unsigned long create_job_ident(void)
756
{
2348 czzmrn 757
/* unsigned long it; // 64-bit compatibility: take away _long_ */
12239 bpr 758
  unsigned long it;
759
  int i;
7673 bpr 760
/* Is this enough to guarantee uniqueness? */
7079 bpr 761
 
12239 bpr 762
  it=(nowtime<<16)+(getpid()&0xffff);
7673 bpr 763
/* The encryption is very simple. */
12239 bpr 764
  it=it^0x5a3c9671;
765
  for(i=0;i<MAX_SESRANDOM;i++) sesrandomtab[i]=random();
1679 bpr 766
    /* ensure that the result will be a 4-bytes integer gives random problem on 32 bits
2607 bpr 767
    return it;*/
12239 bpr 768
  return it & 0xffffffff;
10 reyssat 769
}
770
 
7673 bpr 771
/* Setup a job identifier */
10 reyssat 772
void set_job_ident(void)
773
{
12239 bpr 774
  unsigned long l,r;
7079 bpr 775
 
12239 bpr 776
  l=create_job_ident();
777
  /* the last 4 bits always make 0xA. A bug of glibc random()? */
778
  r=random()>>4;
779
  snprintf(job_identifier,sizeof(job_identifier),"%lX%08lX",r,l);
780
  var_noexport=1;
781
  setvar("job_identifier",job_identifier);
782
  var_noexport=0;
10 reyssat 783
}
784
 
7673 bpr 785
/* define the variable $wims_html_header */
10 reyssat 786
void define_html_header(void)
787
{
12239 bpr 788
  char *sp, *cp, *ladirection, *mp, *s2;
789
  char buf[MAX_LINELEN+1];
12442 obado 790
  int buf_length = 0;
12239 bpr 791
  int noc;
792
  noc=0;
793
  cp=getvar("wims_expire"); if(cp!=NULL) goto css;
794
  if(!robot_access && cmd_type==cmd_intro && isclassmodule) {
795
    sp=getvar("special_parm"); if(sp==NULL) sp="";
796
    if(strcmp(sp,".nocache.")==0) {
797
      force_setvar("special_parm",""); noc=1;
10 reyssat 798
    }
12239 bpr 799
    if(!noc) {
800
      mp=getvar(ro_name[ro_module]);
801
      if(mp!=NULL && strncmp(mp,"devel/",strlen("devel/"))==0) noc=1;
802
    }
803
  }
13359 obado 804
  if(noc==1){
805
    _output_("Cache-Control: no-cache, no-store, must-revalidate\r\n");
806
  }
12417 obado 807
  css:
808
  setvar("wims_CSS","");
809
  /* wims_css peut avoir pour valeur "---" ou "-theme-" au niveau du site
810
    + la valeur "class" si une classe décide d'utiliser son propre css à la place du theme
811
  */
12239 bpr 812
  cp=getvar("wims_css");
813
  ladirection=getvar("wims_main_dirn");
814
  if (strcmp(ladirection,"ltr")==0) ladirection="";
12417 obado 815
 
12239 bpr 816
  if(!robot_access && cp!=NULL && *cp!=0 && strstr(cp,"---")==NULL) {
817
    char *nbuf;
818
    cp=find_word_start(cp);
819
    if(strchr(cp,'/')==NULL) {
12417 obado 820
      char *pc, *th, *ti; int class_style=0;
12239 bpr 821
      pc=getvar("wims_class");
12425 obado 822
 
823
      /* When a class choose its own css instead of theme css */
12239 bpr 824
      if(pc!=NULL && *pc!=0 && strcmp(cp,"class")==0) {
825
        nbuf=mkfname(NULL,"%s/%s/css",class_base,pc);
826
        th=getvar("class_theme");ti=getvar("class_theme_icon") ;
827
        if(th==NULL || *th==0) th=getvar("wims_theme");
828
        if(ti==NULL || *ti==0) ti=getvar("wims_theme_icon");
12417 obado 829
 
830
        // Check content of "nbuf" file. (if file is too heavy (>45Ko), it will raise a user_error)
12425 obado 831
        if( readfile(nbuf,tmplbuf,sizeof(tmplbuf)) ){
832
          // file exist
833
          //snprintf(buf,sizeof(buf),"<style>%s</style>",tmplbuf);
834
          // The content will be added by scripts/adm/css.phtml
835
          class_style = 1;
12417 obado 836
        }
12239 bpr 837
      }
12425 obado 838
 
839
      if (!class_style) {
12239 bpr 840
        th=getvar("wims_theme");
12425 obado 841
        /* when wims_css is everything but '---' */
842
        if(strcmp(cp,"---")!=0 && strchr(th,'.')==NULL) {
843
          if(th==NULL || *th==0) th="standard";
844
          nbuf=mkfname(NULL,"html/themes/%s/css.css",th);
12417 obado 845
 
12425 obado 846
          // Check if theme css file exists (use access from unistd.h)
847
          if( access( nbuf, F_OK ) != -1 ) {
12442 obado 848
            buf_length = snprintf(buf,sizeof(buf),"<link href=\"%s\" rel=\"stylesheet\" />",nbuf);
12425 obado 849
          }
12239 bpr 850
        }
851
      }
12425 obado 852
      /* icon theme */
853
      ti=getvar("wims_theme_icon");
854
      if(ti==NULL || *ti==0) ti="default";
12484 bpr 855
      snprintf(buf+buf_length,sizeof(buf)-buf_length,"<link href=\"gifs/themes/%s/icon-min.css\" rel=\"stylesheet\" />",ti);
7673 bpr 856
 
12425 obado 857
      setvar("wims_CSS",buf);
858
 
859
      /* case of theme */
12239 bpr 860
      if (th) {
861
        s2=getvar("module_title");
862
        if(s2!=NULL && *s2!=0) {
863
          mystrncpy(nbuf,s2,sizeof(buf)); calc_detag(nbuf); setvar("module_title2",nbuf);
864
        };
865
        nbuf=mkfname(NULL,"html/themes/%s/htmlheader.phtml",th) ;
866
        if (readfile(nbuf,tmplbuf,sizeof(tmplbuf))) html_header=nbuf ;
867
      }
10 reyssat 868
    }
12239 bpr 869
  }
12417 obado 870
  if(readfile(html_header,buf,sizeof(buf)))
871
  setvar("wims_html_header",buf);
10 reyssat 872
}
873
 
10875 obado 874
/* Set Session Dir */
10 reyssat 875
void setsesdir(char *d)
876
{
12239 bpr 877
  char buf[MAX_FNAME+1];
878
  if(strstr(d,parent_dir_string)!=NULL) {
879
    force_setvar("wims_session",robot_session);
880
    mystrncpy(buf,robot_session,sizeof(buf));
881
    mkfname(session_dir,"../tmp");
882
    mkfname(s2_dir,"../tmp");
883
  }
884
  else {
885
    force_setvar("wims_session",d);
886
    snprintf(buf,sizeof(buf),"%s/%s",SESSION_BASE,d);
887
    mkfname(session_dir,"../%s",SESSION_BASE);
7673 bpr 888
/* mkfname(s2_dir,"../%s",S2_BASE); */
12239 bpr 889
  }
890
  force_setvar("wims_sesdir",buf);
10 reyssat 891
}