Subversion Repositories wimsdev

Rev

Rev 7557 | Rev 8185 | 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 tha * |a+b|>|a-b|*compare_precision
  56.  * will be considered equal in !ifvalue comparisons. */
  57. int DEFAULT_COMPARE_PRECISION=10000;
  58. /* Precision of printing (hence of all evaluations). */
  59. int DEFAULT_PRINT_PRECISION=8;
  60. /* Defaults for instex, insplot, etc. */
  61. char *DEFAULT_INS_FORMAT="gif";
  62. char *DEFAULT_ANIM_FORMAT="gif";
  63. char *DEFAULT_INS_DENSITY="100x100";
  64. char *DEFAULT_INSPLOT_FONT="small";
  65.  
  66. /* gnuplot intermediate graphics format */
  67. char *gnuplot_format="gif";
  68.  
  69.   /* electronic address of site manager. */
  70. char *site_manager="wims@$httpd_HTTP_HOST";
  71.   /* Main configure file, this name cannot be configured! */
  72. char *config_file="../log/wims.conf";
  73. char PATH[512];  /* directory settings */
  74. #ifdef MACOSX
  75.  char *commonpath="/usr/local/bin:/usr/bin:/usr/games:/bin:/sw/bin:/usr/bin/X11:/usr/X11R6/bin";
  76. #else
  77.  char *commonpath="/usr/local/bin:/usr/bin:/usr/games:/bin:/usr/bin/X11:/usr/X11R6/bin:/opt/teTeX/bin";
  78. #endif
  79. char *gap_command="gap.sh -T -m 64M";
  80. char *maxima_command="maxima";
  81. char *pari_command="gp -f -q -p 150000";
  82. char *scilab_command="scilab -nwni";
  83. char *QRencode_command="qrencode -o";
  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 spec_font=0; /* choose of some fonts*/
  172.  /* special font can be configured in log/wims.conf with variable special_font*/
  173. char *special_font="letter-spacing:0.3em;line-height:2.7em;word-spacing:0.8em;";
  174. int backup_hour=-1; /* Hour for daily backup; -1 means no backup. */
  175. int site_accounting=0; /* whether accounting should be activated */
  176. int examlog_limit=7; /* number of logged exam sessions for each student */
  177.  
  178.   /* Automatic module update */
  179. char *mu_auto="none";
  180. char *mu_cat="all";
  181. char *mu_delay="3";
  182. char *mu_site="http://wims.unice.fr/download/modules";
  183. char *mu_zone="all";
  184. char *mu_download_site="unice,wimsedu";
  185. char *mu_publish_site="unice";
  186.  
  187.   /* keywords destinated to robots */
  188. char *site_keywords="interactive mathematics, interactive math, server side interactivity";
  189. char *site_description="interactive exercises, online calculators and plotters, mathematical recreation and games";
  190.  
  191.   /* class and document authorization */
  192. int class_quota=100;
  193. int superclass_quota=100;
  194. int doc_quota=32;
  195. char *class_regpass="email,email,deny";
  196. char *doc_regpass="";
  197.  
  198.   /* Where to find programs; if your httpd sets /bin:/usr/bin in PATH,
  199.    * this should be OK. */
  200. char *sed_prog="sed";
  201. char *tr_prog="tr";
  202. char *awk_prog="awk";
  203.  
  204.   /* myname */
  205. char *cgi_name="wims.cgi";
  206. char *aliased_cgi="no";
  207. char *aliased_getfile="yes";
  208.  
  209.   /* Limits for classes and participants */
  210. int class_limit=200; /* limit of number of classes */
  211. int user_limit=5000; /* limit of total number of registered users */
  212. int class_user_limit=300; /* limit of users in one class */
  213. int forum_limit=100;  /* Limit of message boards */
  214.  
  215. typedef struct {
  216.     char *name;
  217.     int is_integer;
  218.     void  *address;
  219. } CONFIG_DATA;
  220.  
  221. CONFIG_DATA main_config[]={
  222.       {"PATH",                  0, &commonpath},
  223.       {"QRencode_command",      2, &QRencode_command},
  224.       {"aliased_cgi",           0, &aliased_cgi},
  225.       {"aliased_getfile",       0, &aliased_getfile},
  226.       {"backup_hour",           1, &backup_hour},
  227.       {"busyhours",             0, &busyhours},
  228.       {"cgi_name",              0, &cgi_name},
  229.       {"class_limit",           1, &class_limit},
  230.       {"class_quota",           1, &class_quota},
  231.       {"class_regpass",         0, &class_regpass},
  232.       {"class_user_limit",      1, &class_user_limit},
  233.       {"css",                   0, &pagecss},
  234.       {"default_anim_format",   0, &DEFAULT_ANIM_FORMAT},
  235.       {"default_ins_format",    0, &DEFAULT_INS_FORMAT},
  236.       {"default_insplot_font",  0, &DEFAULT_INSPLOT_FONT},
  237.       {"default_texposition",   1, &mathalign_base},
  238.       {"devel_modules",         0, &devel_modules},
  239.       {"doc_quota",             1, &doc_quota},
  240.       {"doc_regpass",           0, &doc_regpass},
  241.       {"examlog_limit",         1, &examlog_limit},
  242.       {"forum_limit",           1, &forum_limit},
  243.       {"gap_command",           2, &gap_command},
  244.       {"general_log_limit",     1, &GEN_LOG_LIMIT},
  245.       {"gnuplot_format",        0, &gnuplot_format},
  246.       {"home_module",           0, &home_module},
  247.       {"idle_time",             1, &idle_time},
  248.       {"idle_time2",            1, &idle_time2},
  249.       {"idle_time3",            1, &idle_time3},
  250.       {"insdraw_processor",     0, &insdraw_processor},
  251.       {"link_color",            0, &link_color},
  252.       {"mail_opt",              0, &mail_opt},
  253.       {"manager_https",         1, &manager_https},
  254.       {"manager_site",          0, &manager_site},
  255.       {"maxima_command",        2, &maxima_command},
  256.       {"module_log",            1, &modlog},
  257.       {"module_log_limit",      1, &MODULE_LOG_LIMIT},
  258.       {"mu_auto",               0, &mu_auto},
  259.       {"mu_cat",                0, &mu_cat},
  260.       {"mu_delay",              0, &mu_delay},
  261.       {"mu_download_site",              0, &mu_download_site},
  262.       {"mu_publish_site",               0, &mu_publish_site},
  263.       {"mu_site",               0, &mu_site},
  264.       {"mu_zone",               0, &mu_zone},
  265.       {"old_log_files",         1, &OLD_LOG_FILES},
  266.       {"page_bgcolor",          0, &bgcolor},
  267.       {"page_bgimg",            0, &bgimg},
  268.       {"pari_command",          2, &pari_command},
  269.       {"priority",              0, &priority},
  270.       {"rafale_level",          1, &rafalvl},
  271.       {"ref_bgcolor",           0, &ref_bgcolor},
  272.       {"ref_button_bgcolor",            0, &ref_button_bgcolor},
  273.       {"ref_button_color",              0, &ref_button_color},
  274.       {"ref_button_help_bgcolor",               0, &ref_button_help_bgcolor},
  275.       {"ref_button_help_color",         0, &ref_button_help_color},
  276.       {"ref_menucolor",         0, &ref_menucolor},
  277.       {"rlimit_cpu",            1, &rlimit_cpu},
  278.       {"scilab_command",        2, &scilab_command},
  279.       {"show_author",           0, &show_author},
  280.       {"show_ip",               0, &show_ip},
  281.       {"show_stat",             0, &show_stat},
  282.       {"site_accounting",       1, &site_accounting},
  283.       {"site_description",      0, &site_description},
  284.       {"site_keywords",         0, &site_keywords},
  285.       {"site_languages",        0, &site_languages},
  286.       {"site_manager",          0, &site_manager},
  287.       {"superclass_quota",      1, &superclass_quota},
  288.       {"texbasesize",           1, &texbasesize},
  289.       {"theme",                 0, &theme},
  290.       {"theme_icon",                    0, &theme_icon},
  291.       {"threshold1",            1, &threshold1},
  292.       {"threshold2",            1, &threshold2},
  293.       {"tmp_debug",             0, &tmp_debug},
  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}
  300. };
  301. #define MAIN_CONFIG_NO (sizeof(main_config)/sizeof(main_config[0]))
  302.  
  303.         /* processes the list of languages supported on the site */
  304. void language_list(void)
  305. {
  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);
  316. }
  317.  
  318. char hostname[256];
  319. int html_call=0;
  320.  
  321.         /* determine the http reference name of the server */
  322. void determine_ref_name(void)
  323. {
  324.     char *s1, *s2, *p, *pl;
  325.     char buf[MAX_LINELEN+1];
  326.  
  327.     hostname[0]=0;
  328.     s1=getvar("httpd_HTTP_HOST");s2=getvar("httpd_SCRIPT_NAME");
  329.     gethostname(hostname,sizeof(hostname));
  330.     if(hostname[0]==0 && s1 && *s1!=0) mystrncpy(hostname,s1,sizeof(hostname));
  331.     if(s1==NULL || *s1==0) s1=hostname;
  332.     setvar("wims_myhostname",hostname);
  333.     ref_base[0]=0;
  334.     if(s2!=NULL) mystrncpy(buf,s2,sizeof(buf));
  335.     else buf[0]=0;
  336.     if(s1!=NULL && *buf=='/') {
  337.         p=strrchr(buf,'/'); if(p==NULL) p=buf; else *p++=0;
  338.         if(strcmp(p,cgi_name)!=0 && strlen(p)>4 &&
  339.            p[2]=='_' && islower(p[0]) && islower(p[1])) {
  340.             pre_language[0]=p[0];pre_language[1]=p[1];pre_language[2]=0;
  341.             p[2]=0; setenv("HTTP_ACCEPT_LANGUAGE",p,1); pl=p; p+=3;
  342.             s2=strrchr(p,'.'); if(s2!=NULL) {
  343.                 *s2=0; if(strcasecmp(s2+1,"cgi")!=0) html_call=1;
  344.             }
  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));
  355.             }
  356.             else setvar(ro_name[ro_module],p);
  357.             module_defined=1;
  358.         }
  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.         }
  366.         snprintf(ref_name,sizeof(ref_name)-2,"http://%s%s/%s",s1,buf,cgi_name);
  367.         mystrncpy(ref_base,ref_name,sizeof(ref_base)-2);
  368.         p=strrchr(ref_base,'/');
  369.         if(p!=NULL) *(p+1)=0;
  370.     }
  371.     else mystrncpy(ref_name,cgi_name,sizeof(ref_name)-1);
  372.     setvar("wims_ref_name",ref_name);
  373. }
  374.  
  375.         /* Read and interprete wims configuration file. */
  376. void main_configure(void)
  377. {
  378.     int i;
  379.     char *conf_buf,*e,*p,*p2,*p3;
  380.     char buf[MAX_LINELEN+1];
  381.  
  382.     conf_buf=readfile(config_file,NULL,WORKFILE_LIMIT);
  383.     if(conf_buf==NULL) goto fileend;
  384.     e=conf_buf-1; while(e) {
  385.         p=e+1; e=strchr(p,'\n'); if(e) *e=0;
  386.         p=find_word_start(p);
  387.         if(*p==0 || *p==comment_prefix_char) continue; /* empty or comment line */
  388.         p2=strchr(p,'=');
  389.         if(p2==NULL) continue; /* syntax error */
  390.         *p2=0; *find_word_end(p)=0; p2=find_word_start(p2+1);
  391.         p3=p2+strlen(p2); while(myislspace(p3[-1])) p3--;
  392.         while(p3[-1]=='\\') p3--; *p3=0;
  393.         i=search_list(main_config,MAIN_CONFIG_NO,sizeof(main_config[0]),p);
  394.         if(i<0) continue; /* name non-defined */
  395.         if(main_config[i].is_integer==1) {
  396.             int *ip;
  397.             ip=main_config[i].address;
  398.             *ip=atoi(p2); if(*ip<0) *ip=0;
  399.         }
  400.         else {
  401.             char **cp;
  402.             cp=main_config[i].address;
  403.             *cp=p2;
  404.         }
  405.     }
  406.     fileend:
  407.     setenv("session_base_dir",session_dir,1);
  408.     determine_ref_name();
  409.     language_list();
  410.     for(i=0;i<MAIN_CONFIG_NO;i++) {
  411.         char **pp;
  412.         if(main_config[i].is_integer==2) {
  413.             pp=main_config[i].address;
  414.             setenv(main_config[i].name,*pp,1);
  415.         }
  416.     }
  417.         /* check priority */
  418.     if(priority[0] && checkhost(priority)>0) ispriority=1;
  419.     (void)getcwd(cwdbuf,sizeof(cwdbuf)); setvar("httpd_PWD",cwdbuf);
  420.     setenv("wims_server_base",cwdbuf,1);
  421.     p=strrchr(cwdbuf,'/');
  422.     if(p!=NULL && strcmp(p,"/public_html")==0) {
  423.         *p=0; snprintf(PATH,sizeof(PATH),"%s/other/bin:%s",cwdbuf,commonpath);
  424.         force_setvar("wims_home",cwdbuf);
  425.         *p='/';
  426.     }
  427.     else {
  428.         snprintf(PATH,sizeof(PATH),"%s/../other/bin:%s",cwdbuf,commonpath);
  429.         force_setvar("wims_home",cwdbuf);
  430.     }
  431.     setenv("PATH",PATH,1);
  432.     p=getvar("httpd_SERVER_SOFTWARE");
  433.     if(p && (p2=strstr(p,"Apache"))!=NULL && strcmp(p2,"Apache/1.3")>=0
  434.        && strstr(aliased_getfile,"yes")!=NULL)
  435.       good_httpd=1;
  436.     accessfile(buf,"r","../tmp/log/myip");
  437.     *find_word_end(buf)=0;
  438.     if(buf[0]) {
  439.      snprintf(nodeip,sizeof(nodeip),"%s",buf);
  440.      snprintf(temp_log,sizeof(temp_log),"%s.%s",TEMP_LOG_FILE,nodeip);
  441.      force_setvar("wims_priv_nodeip",nodeip);
  442.     }
  443.     else {
  444.      nodeip[0]=0;
  445.      snprintf(temp_log,sizeof(temp_log),"%s",TEMP_LOG_FILE);
  446.     }
  447. }
  448.  
  449. struct {
  450.     int rname;
  451.     int *rval;
  452. } resource_table[]={
  453. #ifdef RLIMIT_CPU
  454.       {RLIMIT_CPU, &rlimit_cpu},
  455. #endif
  456. #ifdef RLIMIT_FSIZE
  457.       {RLIMIT_FSIZE,  &rlimit_fsize},
  458. #endif
  459. #ifdef RLIMIT_AS
  460.       {RLIMIT_AS, &rlimit_as},
  461. #endif
  462. #ifdef RLIMIT_DATA
  463.       {RLIMIT_DATA, &rlimit_data},
  464. #endif
  465. #ifdef RLIMIT_STACK
  466.       {RLIMIT_STACK, &rlimit_stack},
  467. #endif
  468. #ifdef RLIMIT_CORE
  469.       {RLIMIT_CORE, &rlimit_core},
  470. #endif
  471. #ifdef RLIMIT_RSS
  472.       {RLIMIT_RSS, &rlimit_rss},
  473. #endif
  474. #ifdef RLIMIT_NPROC
  475.       {RLIMIT_NPROC, &rlimit_nproc},
  476. #endif
  477. #ifdef RLIMIT_NOFILE
  478.       {RLIMIT_NOFILE, &rlimit_nofile},
  479. #endif
  480. #ifdef RLIMIT_MEMLOCK
  481.       {RLIMIT_MEMLOCK, &rlimit_memlock}
  482. #endif
  483. };
  484. #define RESOURCE_NO (sizeof(resource_table)/sizeof(resource_table[0]))
  485.  
  486. /* set system resource limits */
  487. void set_rlimits(void)
  488. {
  489.     int i;
  490.     struct rlimit rlim;
  491.  
  492.     for(i=0;i<RESOURCE_NO;i++) {
  493.      rlim.rlim_cur=rlim.rlim_max=*(resource_table[i].rval);
  494.      setrlimit(resource_table[i].rname,&rlim);
  495.      if(resource_table[i].rname==RLIMIT_CPU) {
  496.          setvar("wims_cpu_limit",int2str(rlim.rlim_max));
  497.          initalarm();
  498.      }
  499.     }
  500. }
  501.  
  502. struct {
  503.     char *name;
  504.     int is_integer;
  505.     void *default_value;
  506. } module_default[]={
  507.       {"anim_format",  0, &DEFAULT_ANIM_FORMAT},
  508.       {"gnuplot_format",        0, &gnuplot_format},
  509.       {"ins_anim_limit",        1, &ANIM_LIMIT},
  510.       {"ins_density",           0, &DEFAULT_INS_DENSITY},
  511.       {"ins_format",            0, &DEFAULT_INS_FORMAT},
  512.       {"insplot_font",          0, &DEFAULT_INSPLOT_FONT},
  513.       {"wims_busyhours",        0, &busyhours},
  514.       {"wims_class_limit",      1, &class_limit},
  515.       {"wims_class_quota",      1, &class_quota},
  516.       {"wims_class_regpass",    0, &class_regpass},
  517.       {"wims_class_user_limit", 1, &class_user_limit},
  518.       {"wims_compare_precision",1, &DEFAULT_COMPARE_PRECISION},
  519.       {"wims_devel_modules",    0, &devel_modules},
  520.       {"wims_doc_quota",        1, &doc_quota},
  521.       {"wims_doc_regpass",      0, &doc_regpass},
  522.       {"wims_examlog_limit",    1, &examlog_limit},
  523.       {"wims_forum_limit",      1, &forum_limit},
  524.       {"wims_bgcolor",          0, &bgcolor},
  525.       {"wims_bgimg",            0, &bgimg},
  526.       {"wims_css",              0, &pagecss},
  527.       {"wims_link_color",       0, &link_color},
  528.       {"wims_print_precision",  1, &DEFAULT_PRINT_PRECISION},
  529.       {"wims_ref_bgcolor",      0, &ref_bgcolor},
  530.       {"wims_ref_button_bgcolor",               0, &ref_button_bgcolor},
  531.       {"wims_ref_button_color",         0, &ref_button_color},
  532.       {"wims_ref_button_help_bgcolor",          0, &ref_button_help_bgcolor},
  533.       {"wims_ref_button_help_color",            0, &ref_button_help_color},
  534.       {"wims_ref_menucolor",            0, &ref_menucolor},
  535.       {"wims_ref_menucolor",    0, &ref_menucolor},
  536.       {"wims_show_author",      0, &show_author},
  537.       {"wims_show_ip",          0, &show_ip},
  538.       {"wims_show_stat",        0, &show_stat},
  539.       {"wims_site_description", 0, &site_description},
  540.       {"wims_site_keywords",    0, &site_keywords},
  541.       {"wims_site_manager",     0, &site_manager},
  542.       {"wims_texalign",         1, &mathalign_base},
  543.       {"wims_texbasesize",      1, &texbasesize},
  544.       {"wims_theme",            0, &theme},
  545.       {"wims_theme_icon",       0, &theme_icon},
  546.       {"wims_tmp_debug",        0, &tmp_debug},
  547.       {"wims_usecookie",        0, &usecookie},
  548.       {"wims_user_limit",       1, &user_limit},
  549.       {"wims_vlink_color",      0, &vlink_color},
  550.       {"wims_superclass_quota", 1, &superclass_quota}
  551. };
  552. #define MODULE_DEFAULT_NO (sizeof(module_default)/sizeof(module_default[0]))
  553.  
  554.         /* Set defaults for module, and set corresponding variables. */
  555. void module_configure(void)
  556. {
  557.     int i;
  558.     confset=1;
  559.     for(i=0;i<MODULE_DEFAULT_NO;i++) {
  560.         if(module_default[i].is_integer) {
  561.             int j, *jp;
  562.             jp=module_default[i].default_value;
  563.             j=*jp; if(j<0) j=0;
  564.             setvar(module_default[i].name,int2str(j));
  565.         }
  566.         else {
  567.             char **cp;
  568.             cp=module_default[i].default_value;
  569.             setvar(module_default[i].name,*cp);
  570.         }
  571.     }
  572.     setenv("texgif_fontdir",texgif_fontdir,1);
  573.     setenv("texgif_texheader",texgif_texheader,1);
  574.     setvar("wims_texsize","0");
  575.     setvar("disable_zoom","0");
  576.     confset=0;
  577. }
  578.  
  579. char *modindex[]={
  580.       "address",
  581.       "author",
  582.       "category",
  583.       "copyright",
  584.       "data",
  585.       "description",
  586.       "description_ca",
  587.       "description_cn",
  588.       "description_de",
  589.       "description_en",
  590.       "description_es",
  591.       "description_fr",
  592.       "description_it",
  593.       "description_nl",
  594.       "description_si",
  595.       "description_tw",
  596.       "domain",
  597.       "help",
  598.       "keywords",
  599.       "keywords_ca",
  600.       "keywords_cn",
  601.       "keywords_de",
  602.       "keywords_en",
  603.       "keywords_es",
  604.       "keywords_fr",
  605.       "keywords_it",
  606.       "keywords_nl",
  607.       "keywords_si",
  608.       "keywords_tw",
  609.       "language",
  610.       "level",
  611.       "maintainer",
  612.       "maintainer_address",
  613.       "mode",
  614.       "require",
  615.       "scoring",
  616.       "title",
  617.       "title_ca",
  618.       "title_cn",
  619.       "title_de",
  620.       "title_en",
  621.       "title_es",
  622.       "title_fr",
  623.       "title_it",
  624.       "title_nl",
  625.       "title_si",
  626.       "title_tw",
  627.       "translator",
  628.       "translator_address",
  629.       "translator_address_ca",
  630.       "translator_address_cn",
  631.       "translator_address_de",
  632.       "translator_address_en",
  633.       "translator_address_es",
  634.       "translator_address_fr",
  635.       "translator_address_it",
  636.       "translator_address_nl",
  637.       "translator_address_si",
  638.       "translator_address_tw",
  639.       "translator_ca",
  640.       "translator_cn",
  641.       "translator_de",
  642.       "translator_en",
  643.       "translator_es",
  644.       "translator_fr",
  645.       "translator_it",
  646.       "translator_nl",
  647.       "translator_si",
  648.       "translator_tw",
  649.       "vardef",
  650.       "version",
  651.       "wims_version",
  652. };
  653. #define MODINDEX_NO (sizeof(modindex)/sizeof(modindex[0]))
  654. char *module_special_file[]={
  655.     "intro","help"
  656. };
  657. #define MODSPEC_NO (sizeof(module_special_file)/sizeof(module_special_file[0]))
  658.  
  659. #ifdef WEBMATH
  660.  
  661.         /* read and treat module's INDEX file */
  662. void module_index(void)
  663. {
  664.     char buf[MAX_NAMELEN+1], ind_buf[MAX_LINELEN+1];
  665.     char *e, *p, *p2, *ft;
  666.     double v1, v2;
  667.     int i,l;
  668.     long indf_len;
  669.  
  670.     memmove(var_def_file,default_var_def,strlen(default_var_def)+1);
  671.     ft=readfile(mkfname(NULL,"%s/INDEX",module_prefix),
  672.                 ind_buf,sizeof(ind_buf));
  673.     if(ft==NULL) ft=readfile(mkfname(NULL,"%s/index",module_prefix),
  674.                              ind_buf,sizeof(ind_buf));
  675.     if(ft==NULL) return;
  676.     e=ind_buf-1; indf_len=strlen(ind_buf);
  677.     for(l=0; e<ind_buf+indf_len && e!=NULL ;l++) {
  678.         p=e+1; e=strchr(p,'\n'); if(e!=NULL) *e=0;
  679.         strip_trailing_spaces(p); p=find_word_start(p);
  680.         if(*p==0 || *p==comment_prefix_char) continue; /* empty or comment line */
  681.         p2=strchr(p,'=');
  682.         if(p2==NULL) continue; /* syntax error */
  683.         *p2=0; *find_word_end(p)=0; p2=find_word_start(p2+1);
  684.         i=search_list(modindex,MODINDEX_NO,sizeof(modindex[0]),p);
  685.         if(i<0) continue; /* name not in list */
  686.         snprintf(buf,sizeof(buf),"module_%s",p);
  687.         setvar(buf,p2);
  688.     }
  689.     if(mode!=mode_default) {
  690.         char *s;
  691.         s=getvar("module_mode");
  692.         if(s==NULL) {
  693.             nomode: mode=mode_default; force_setvar("wims_mode","");
  694.         }
  695.         else switch(mode) {
  696.             case mode_popup: {
  697.                 if(strstr(s,"popup")==NULL) goto nomode;
  698.                 else break;
  699.          }
  700.          case mode_raw: {
  701.           if(strstr(s,"raw")==NULL) goto nomode;
  702.           else break;
  703.          }
  704.          default: break;
  705.      }
  706.     }
  707. /* test for existence of some special files in module's directory */
  708.     for(i=0;i<MODSPEC_NO;i++) {
  709.      if(ftest(mkfname(NULL,"%s/%s.phtml",module_prefix,module_special_file[i]))
  710.         ==is_file) {
  711.          snprintf(buf,sizeof(buf),"module_has_%s",module_special_file[i]);
  712.          setvar(buf,"yes");
  713.      }
  714.     }
  715.     p=getvar("module_language"); if(p==NULL || *p==0) setvar("module_language","en");
  716.     setvar("module_has_about","yes"); /* now we have default about.phtml */
  717. /* Set var_def */
  718.     p=getvar("module_vardef");
  719.     if(p!=NULL && *p!=0) mystrncpy(var_def_file,p,sizeof(var_def_file));
  720.     p=getvar("module_wims_version"); if(p!=NULL && *p!=0) {
  721.      v1=atof(p); v2=atof(wims_version);
  722.      if(finite(v1) && finite(v2) &&
  723.         (v1>v2 || (v1==v2 && strcmp(find_word_start(p),wims_version)>0))) {
  724.          setvar("module_wims_version",p);
  725.          setvar("wims_version",wims_version);
  726.          module_error("antidated_version");
  727.      }
  728.     }
  729.     if(isdevelmodule) {
  730.      p=getvar("module_scoring");
  731.      if(p==NULL || strcasecmp(p,"yes")!=0) isdevelmodule=0;
  732.     }
  733. }
  734.  
  735. #endif
  736.  
  737. /* Set up a unique job identity as a 4-bytes integer */
  738. unsigned long create_job_ident(void)
  739. {
  740. /* unsigned long it; // 64-bit compatibility: take away _long_ */
  741.     unsigned long it;
  742.     int i;
  743. /* Is this enough to guarantee uniqueness? */
  744.  
  745.     it=(nowtime<<16)+(getpid()&0xffff);
  746. /* The encryption is very simple. */
  747.     it=it^0x5a3c9671;
  748.     for(i=0;i<MAX_SESRANDOM;i++) sesrandomtab[i]=random();
  749.     /* ensure that the result will be a 4-bytes integer gives random problem on 32 bits
  750.     return it;*/
  751.     return it & 0xffffffff;
  752. }
  753.  
  754. /* Setup a job identifier */
  755. void set_job_ident(void)
  756. {
  757.     unsigned long l,r;
  758.  
  759.     l=create_job_ident();
  760.     /* the last 4 bits always make 0xA. A bug of glibc random()? */
  761.     r=random()>>4;
  762.     snprintf(job_identifier,sizeof(job_identifier),"%lX%08lX",r,l);
  763.     var_noexport=1;
  764.     setvar("job_identifier",job_identifier);
  765.     var_noexport=0;
  766. }
  767.  
  768. /* define the variable $wims_html_header */
  769. void define_html_header(void)
  770. {
  771.   char *expir, *sp, *cp, *ladirection, *mp;
  772.     char buf[MAX_LINELEN+1],ebuf[128];
  773.     char *nocache="<meta http-equiv=\"Pragma\" content=\"no-cache\" />\n\
  774. <meta http-equiv=\"Cache-Control\" content=\"no-cache\" />\n";
  775.     int noc;
  776.     time_t t;
  777.  
  778.     noc=0;
  779.     cp=getvar("wims_expire"); if(cp!=NULL) goto css;
  780.     if(!robot_access && cmd_type==cmd_intro && isclassmodule) {
  781.      sp=getvar("special_parm"); if(sp==NULL) sp="";
  782.      if(strcmp(sp,".nocache.")==0) {
  783.          force_setvar("special_parm",""); noc=1;
  784.      }
  785.      if(!noc) {
  786.          mp=getvar(ro_name[ro_module]);
  787.          if(mp!=NULL && strncmp(mp,"devel/",strlen("devel/"))==0) noc=1;
  788.      }
  789.     }
  790.     if(mode==mode_default) {
  791.      if(!robot_access && (cmd_type!=cmd_intro || noc)) {
  792.          if(html_call) {
  793. /* expiration in 1 day for html call. */
  794.           t=nowtime+(long) 24*3600; expir=ctime(&t);
  795.           nocache="";
  796.          }
  797.          else expir="1 Jan 1990";
  798.      }
  799.      else {
  800. /* expiration in 10 days for robot access or intro page. */
  801.          t=nowtime+(long) 10*24*3600; expir=ctime(&t); nocache="";
  802.      }
  803.      snprintf(ebuf,sizeof(ebuf),"%s",expir); strip_trailing_spaces(ebuf);
  804.      snprintf(buf,sizeof(buf),
  805.            "<meta http-equiv=\"expires\" content=\"%s\" />\n%s",ebuf,nocache);
  806.      setvar("wims_expire",buf);
  807.     }
  808.     css: setvar("wims_CSS","");
  809.     cp=getvar("wims_css");
  810.     ladirection=getvar("wims_main_dirn");
  811.     if (strcmp(ladirection,"ltr")==0) ladirection="";
  812.     if(!robot_access && cp!=NULL && *cp!=0 && strstr(cp,"---")==NULL) {
  813.      char *nbuf;
  814.      cp=find_word_start(cp);
  815.      if(strchr(cp,'/')==NULL) {
  816.          char *pc, *th, *ti; int st=0;
  817.          pc=getvar("wims_class");
  818.          if(pc!=NULL && *pc!=0 && strcmp(cp,"class")==0) {
  819.            nbuf=mkfname(NULL,"%s/%s/css",class_base,pc);
  820.            th=getvar("class_theme");ti=getvar("class_theme_icon") ;
  821.            if(th==NULL || *th==0) th=getvar("wims_theme"); st=1;
  822.            if(ti==NULL || *ti==0) ti=getvar("wims_theme_icon");
  823.          }
  824.          else {/* Il faut peut-être changer là aussi pour direction */
  825.           nbuf=mkfname(NULL,"html/css/%s/%s.css",lang,cp);
  826.           th=getvar("wims_theme");
  827.           ti=getvar("wims_theme_icon");
  828.          }
  829.          if(strcmp(cp,"-theme-")==0 && strchr(th,'.')==NULL) {
  830.             if(th==NULL || *th==0) th="default";
  831.             nbuf=mkfname(NULL,"html/themes/%s/css%s.css",th,ladirection);
  832.          }
  833.          if(readfile(nbuf,tmplbuf,sizeof(tmplbuf))) {
  834.          }
  835.          else {
  836.           th=getvar("wims_theme");
  837.           nbuf=mkfname(NULL,"html/themes/%s/css%s.css",th,ladirection);
  838.           }
  839.           if(readfile(nbuf,tmplbuf,sizeof(tmplbuf))) {
  840.            if (st) {snprintf(buf,sizeof(buf),"<style type=\"text/css\"><!--\n\
  841. %s\n\
  842. --></style>",tmplbuf); }
  843.             else {
  844.             snprintf(buf,sizeof(buf),"<link href=\"%s\" rel=\"stylesheet\" type=\"text/css\" />\n\
  845. <link href=\"gifs/themes/%s/icon-min.css\" rel=\"stylesheet\" type=\"text/css\" />",nbuf,ti);
  846.            }
  847.           setvar("wims_CSS",buf);
  848.          }
  849.          else {
  850.  
  851.          }
  852.          if (th) {
  853.             nbuf=mkfname(NULL,"html/themes/%s/htmlheader.phtml",th) ;
  854.             if (readfile(nbuf,tmplbuf,sizeof(tmplbuf))) html_header=nbuf ;
  855.          }
  856.        }
  857.     }
  858.     if(readfile(html_header,buf,sizeof(buf))) setvar("wims_html_header",buf);
  859. }
  860.  
  861. void setsesdir(char *d)
  862. {
  863.     char buf[MAX_FNAME+1];
  864.     if(strstr(d,parent_dir_string)!=NULL) {
  865.      force_setvar("wims_session",robot_session);
  866.      mystrncpy(buf,robot_session,sizeof(buf));
  867.      mkfname(session_dir,"../tmp");
  868.      mkfname(s2_dir,"../tmp");
  869.     }
  870.     else {
  871.      force_setvar("wims_session",d);
  872.      snprintf(buf,sizeof(buf),"%s/%s",SESSION_BASE,d);
  873.      mkfname(session_dir,"../%s",SESSION_BASE);
  874. /* mkfname(s2_dir,"../%s",S2_BASE); */
  875.     }
  876.     force_setvar("wims_sesdir",buf);
  877. }
  878.  
  879.