Subversion Repositories wimsdev

Rev

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