Subversion Repositories wimsdev

Rev

Rev 5692 | Rev 6178 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

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