home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 35 Internet / 35-Internet.zip / srev13h.zip / srefmon.cmd < prev    next >
OS/2 REXX Batch file  |  2001-06-05  |  117KB  |  3,764 lines

  1. /* SRE-http monitor routine (run as a non-transient thread in same process
  2. as goserve */
  3.  
  4. /*  ---------  BEGIN user changeable parameters.  ------------------*/
  5. /*--- In general, we do NOT recommend changing these parameters --- */
  6.  
  7. /*BEGIN --*/
  8.  
  9. /* Fully qualified directory: the location of the SRE-http configuration files
  10.   If blank, use the default (CFG subdirectory under your goserve directory). 
  11.   We STRONGLY recommend using the '' (blank) default! */
  12. CFGs_dir=''
  13.  
  14.  
  15. /* check that GoServe's settings are appropriate for http/1.1 compliance 
  16.   (1=check, 0=do not check). If 1, and not compliant, error occurs*/
  17. check_compliance=1
  18.  
  19. /* macrospace clearing:
  20.        -1 : don't clear anything
  21.        0  : clear srehttp procedures, prior to loading srefprc.rxl (recommended!)
  22.        1  : clear all of macrospace at once
  23. */
  24. clear_macrospace=0
  25.  
  26. /* Fully qualified directory: the location of delta encoding "cache" files.
  27.   If blank, use the default (the DELTAS\ subdirectory under the
  28.   SRE-http TEMPDATA_DIR directory). 
  29.   We STRONGLY recommend using the '' (blank) default!
  30.   However, if your TEMPDATA_DIR is FAT, then you can set DELTAS_DIR to
  31.   point to a directory on an HPFS drive */
  32. deltas_dir=''
  33.  
  34. /* reset parameters after this many loops */
  35. doanyway_loops=300      
  36.  
  37.  /* set = 1 to occasionally cleanup orphaned cgi-bin temp files */
  38. do_cleanup=1     
  39.  
  40. /* the maximum size of common, referer and browser log 
  41.   files (in kbytes). When the size of a log file exceeds
  42.   this length, it will be renamed.
  43.   Set to 0 to supress this renaming.
  44. */
  45. logfile_maxsize=0
  46.  
  47. /* Size of MD5 cache (used by DOMD5.RXX daemon.
  48.    If 0, then do NOT use md5 daemon (compute each
  49.    md5 as needed.
  50.    A non-0 cache (hence use of the md5 daemon) can speed up 
  51.    throughput (especially if the number of commonly used files
  52.    is fairly small), and may avoid sys3175 errors on some
  53.    systems
  54.    A recommended non-zero size is 800.
  55.    Note: if content_md5=0 (in initfilt.80), 
  56.           you SHOULD set md5_cache=0
  57. */
  58. md5_cache=0
  59.  
  60.  
  61. /* Check MEDIATYP.RXX before checking default "mime type mappings".
  62.    If 0, only check MEDIATYP.RXX when no default "extension to
  63.    mimetype" entry can be found.
  64.    If 1, always check MEDIATYP.RXX, and allow MEDIATYP.RXX 
  65.    entries to override default entries.
  66.    Note: default entries are hard coded in MEDIATYP.SRF
  67. */
  68. MEDIATYPE_FILE_ALWAYS=1
  69.  
  70. /* set=1 to suppress clientname lookup (returns ip number whenever
  71.          clientname is asked for (useful if no DNS is available) */
  72. no_dns=0
  73.  
  74. /* set=1 to suppress search-for & use of superceding realms */
  75. NO_SUPERCEDING_REALM=0
  76.  
  77. /* max line length to "sref_pmprintf" */
  78. pmprintf_line_length=150 
  79.  
  80. /* name of the sref_pmprintf log file (in goserve directory) */
  81. pmprintf_log_file='SREHTTP.LOG ' 
  82.  
  83.  
  84. /* Number of "variable storage daemons" to start. If you are use 
  85.    SRE-http queues, it can be useful to start multiple instances of the
  86.    variable storage daemon (say, one per queue). The default is 1 
  87.    (see SREFQUE.DOC for details) */
  88. storage_daemons=1
  89.  
  90. /* set to 0 to suppress dynamic loading of sre-http procedures 
  91.    If you set this to 0, then you must create the SREFPRCS.RXL file
  92.    (using the makelib.cmd program), and it MUST be in the same
  93.    directory as SREFILTR.80 */
  94. use_dynamic_lib=1    
  95.  
  96.  
  97. /* Fully qualified directory: the location of the .SRF "macrospace" 
  98.   procedures. 
  99.   If blank, use the default (LIB subdirectory under your goserve directory). 
  100.   We  STRONGLY recommend using the '' (blank) default! */
  101. use_lib_dir=''
  102.  
  103.  
  104. /*END --- */
  105.  
  106. /*END of userchangeable parameters --- */
  107.  
  108. /* ---------- DO NOT CHANGE BELOW HERE  ----------------*/
  109.  
  110. signal on error name yipes ; signal on syntax name yipes ;
  111. signal on failure name yipes ; signal on halt name yipes ;
  112.  
  113.  
  114. parse arg goserve_pid, thesem,servdir,SERVERPORT,servername, ,
  115.                 envadd,max_semwait,moreargs,key_preface, ,
  116.                 x_limitclients,x_fasfile,x_limittimewait,x_gmtset,x_server
  117.  
  118. if servdir=" " then do
  119.    say " This SRE-http daemon is NOT meant to be invoked from an OS/2 prompt!"
  120.   exit
  121. end  /* Do */
  122.  
  123.  
  124. /* CHeck connection maintain on and gmt */
  125. if check_compliance=1 then do
  126.   a1=x_fastfile   /* extract('fastfile') */
  127.   a2=x_limittimewait /* extract('limittimewait') */
  128.   a3=x_gmtset        /* extract('gmtset') */
  129.   a4=x_server       /*  server('h') */
  130.   parse var a4 .'/' gver
  131.   if a1='ON' then do
  132.      call pmprintf(' Caution: The GoServe Cache is enabled.  ')
  133.      call pmprintf('      The GoServe 2.52 (or less) cache is NOT http/1.1 compliant.')
  134.      call pmprintf('      (that is: the goserve cache should be used with care!')
  135.   end /* do */
  136.   if a2 <= 0 then do
  137.      call pmprintf(' **** ERROR: Connection Maintain is NOT enabled')
  138.      call pmprintf('             Http 1.1 compliance requires persistent connections.')
  139.      call pmprintf('      (set the GoServe-Options-Limits-Connection_Maintain parameter)')
  140.      call gosexit 'Connection Maintain is NOT enabled'
  141.   end /* do */
  142.   if a3='OFF' then do
  143.      call pmprintf(' **** ERROR: GMT not available.')
  144.      call pmprintf('             Http 1.1 compliance requires GMT time information')
  145.      call pmprintf('       (you should check the TZ parameter in CONFIG.SYS)')
  146.      call gosexit 'GMT not available.'
  147.   end /* do */
  148.   if gver<2.52 then do
  149.      call pmprintf(' **** ERROR: Pre 2.52 version of GoServe.')
  150.      call pmprintf('             Http 1.1 compliance requires GoServe 2.52 or above')
  151.      call pmprintf('      (see http://www2.hursley.ibm.com/goserve for the latest GoServe).')
  152.      call gosexit 'Pre 2.52 version of GoServe.'
  153.   end
  154. end
  155.  
  156. parse var moreargs loadthreshold ',' backupserverlist ','  ,
  157.    delay_seconds ',' message_scramble ',' record_cache_lines ',' logon_limit ',' ssi_extensions ',' ,
  158.    ssi_cache_size ',' ssi_cache_duration ',' ssi_cache_stamp ',' no_no_record ',' hit_superuser_suppress ',' pmprintf_opt ',' ,
  159.    NO_REMOTE_CONFIG '!!' custom_inits '!!' cgi_post_long_get ',' get_decode_options ',' ,
  160.    never_publicurls ',' digest_auth ',' proxy_cache ',' suppress_gzip_te','pre_reply_procedure ',' ,
  161.    delta_encoding_enable ',' delta_encoding_maxsize ',' event_check','ce_gzip','dynssi_maxage
  162. loadthreshold=strip(loadthreshold) ; backupserverlist=strip(backupserverlist)
  163. delay_seconds=strip(delay_seconds) ; message_scramble=strip(message_scramble)
  164. record_cache_lines=strip(record_cache_lines)
  165. logon_limit=strip(logon_limit)
  166.  
  167. pmprintf_opt=strip(pmprintf_opt)
  168. if wordpos(pmprintf_opt,'1 2 3')=0 then pmprintf_opt=1
  169. if wordpos(digest_auth,'Y YES 1')=0 then
  170.    digest_auth=0
  171. else
  172.    digest_auth=1
  173.  
  174. if wordpos(SUPPRESS_GZIP_TE,'Y YES 1')=0 then
  175.    suppress_gzip_te=0
  176. else
  177.    suppress_gzip_te=1
  178.  
  179. if wordpos(CE_GZIP,'Y YES 1')=0 then
  180.    ce_gzip=0
  181. else
  182.    ce_gzip=1
  183.  
  184. if ce_gzip=1 then do            /* check for rxgzdeflatestring */
  185.    foo=rxfuncquery('rxgzdeflatestring')
  186.    if foo<>0 then ce_gzip=-1
  187. end /* do */
  188.  
  189. if pre_reply_procedure='' then pre_reply_procedure=0
  190.  
  191. a1=left(strip(proxy_cache),1)  /* n_wait or n (n=0,1,2,3, wait=seconts */
  192. if wordpos(a1,'1 2 3')=0 then proxy_cache=0  /* 0 otherwise */
  193.  
  194. dynssi_maxage=strip(dynssi_maxage)
  195. if datatype(dynssi_maxage)<>'NUM' then dynssi_maxage=' '
  196.  
  197. ssi_extensions=strip(ssi_extensions)
  198. ssi_cache_size=strip(ssi_cache_size)
  199. ssi_cache_duration=strip(ssi_cache_duration)
  200. ssi_cache_stamp=upper(strip(ssi_cache_stamp))
  201. no_no_record=strip(no_no_record)
  202. IF WORDPOS(NO_REMOTE_CONFIG,'0 1 2')=0 THEN NO_REMOTE_CONFIG=0
  203. custom_inits=strip(custom_inits)
  204.  
  205. tmp=upper(strip(cgi_post_long_get))
  206. if datatype(tmp)<>'NUM' then tmp=0
  207. cgi_post_long_get=tmp
  208. if wordpos(tmp,'1 YES Y')>0 then cgi_post_long_get=240
  209. if wordpos(tmp,'0 NO N') then cgi_post_long_get=20000
  210.  
  211. tmp=upper(strip(get_decode_options))
  212. get_decode_options=0
  213. if wordpos(tmp,'1 YES Y')>0 then get_decode_options=1
  214.  
  215.  
  216. /* pmprintf modiification? */
  217. foo=start_pmprintf(pmprintf_opt,pmprintf_line_length,pmprintf_log_file)
  218.  
  219. if datatype(logon_limit)<>'NUM' then logon_limit=0
  220. if datatype(delay_seconds)<>'NUM' then delay_Seconds=9
  221. if datatype(message_scramble)<>'NUM' then message_scramble=12415
  222.  
  223. if datatype(doanyway_loops)<>'NUM' then doanyway_loops=150
  224.  
  225. foo=value('SREF_NODNS',no_dns,'os2environment')
  226.  
  227. foo=value('SREF_MEDIATYPE_FILE_ALWAYS',mediatype_file_always,'os2environment')
  228.  
  229. if no_superceding_realm<>1 then no_superceding_realm=0
  230. foo=value("SREF_NO_SUPERCEDING_REALM",no_superceding_realm,'os2environment')
  231.  
  232. foo=value('SREF_ENABLE_ENCRYPTION',,'OS2ENVIRONMENT')
  233. if wordpos(foo,'0 1 2 3')=0 then do
  234.     foo=value('SREF_ENABLE_ENCRYPTION',0,'os2environment')
  235. end /* do */
  236.  
  237. foo=value('SREF_DEFAULT_ENCRYPTION',,'OS2ENVIRONMENT')
  238. if  foo='' | foo=0 then do
  239.    foo=value('SREF_DEFAULT_ENCRYPTION','SRE_A','OS2ENVIRONMENT')
  240. end
  241.  
  242. tmp=delta_encoding_enable
  243. delta_encoding_enable=pos(strip(delta_encoding_enable),'012')
  244. if delta_encoding_enable=0 then do
  245.   call pmprintf("!! SRE-http Monitor WARNING: bad delta_encoding_enable = "tmp)
  246. end 
  247. else do
  248.    delta_encoding_enable=delta_encoding_enable-1
  249. end 
  250. delta_encoding_maxsize=strip(delta_encoding_maxsize)
  251. if datatype(delta_encoding_maxsize)<>'NUM' then do
  252.   call pmprintf("!! SRE-http Monitor WARNING: bad delta_encoding_maxsize = "delta_encoding_maxsize)
  253. end
  254. else do
  255.    if delta_encoding_maxsize<1 then delta_encoding_enable=0
  256. end
  257. foo=value('SRE_DELTA_ENCODING_MAXSIZE',delta_encoding_maxsize,'Os2environment')
  258.  
  259. if datatype(EVENT_CHECK)<>'NUM' then  event_check=0
  260. if event_check<0  then event_check=0
  261.  
  262. if datatype(md5_cache)<>'NUM' then md5_cache=0
  263.  
  264. /* Load some dlls */
  265.  
  266. if \RxFuncQuery("SockLoadFuncs") then nop
  267. else do
  268.        foo2=RxFuncAdd( "SockLoadFuncs","rxSock","SockLoadFuncs")
  269.        call SockLoadFuncs
  270. end
  271. foo=rxfuncquery('UZLoadFuncs')   /* load UNZIP dll */
  272. if foo=1 then do
  273.   foo2=RxFuncAdd( 'UZLoadFuncs', 'UNZIPAPI', 'UZLoadFuncs')
  274.   if foo2=0 then call UZLoadFuncs
  275. end
  276.  
  277. foo=rxfuncquery('UZLoadFuncs')   /* load UNZIP dll */
  278. if foo=1  then call pmprintf('!! SRE-http Monitor WARNING: UNZIPAPI.DLL not found ')
  279.  
  280. if rxfuncquery('sref_fileread')<>0 then do
  281.   ik=rxfuncadd('sref_fileread','rexxlib','LIB_FILEREAD')
  282.   if ik<>0 then call pmprintf('!! SRE-http Monitor WARNING: unable to register SREF_FILEREAD')
  283. end
  284.  
  285. if rxfuncquery('sref_filewrite')<>0 then do
  286.   ik=rxfuncadd('sref_filewrite','rexxlib','LIB_FILEWRITE')
  287.   if ik<>0 then call pmprintf('!! SRE-http Monitor WARNING: unable to register SREF_FILEWRITE')
  288. end
  289.  
  290.  
  291. if rxfuncquery('srx_md5')=1  then do
  292.   foo2=RXFuncAdd( 'SRXLoadFuncs', 'SRXFUNC', 'SRXLoadFuncs')
  293.   if foo2=0 then call SRXLoadFuncs
  294. end
  295. if rxfuncquery('srx_md5')=1  then 
  296.   call pmprintf("SRE-http Monitor: Unable to load SRX_MD5 from SRXFUNC.DLL")
  297.  
  298. /* Load the rxgzlib functions */
  299. if rxfuncquery('rxgzLoadFuncs') then do
  300.    foo=RxFuncAdd( 'rxgzLoadFuncs', 'rxgzLIB', 'rxgzLoadFuncs')
  301.    if foo=0 then do
  302.       call rxgzLoadFuncs
  303.    end
  304.    else do
  305.       call pmprintF('SRE-http Monitor: rxgzlib.dll is not available')
  306.    end /* do */
  307. end /* if */
  308.  
  309.  
  310.  
  311. if max_semwait="" then max_semwait=3000
  312.  
  313. if clear_macrospace=1 then fo=macroclear()
  314.  
  315. CALL  load_rxl(0)  /* load macrospace library */
  316. IF result<0  then    do       /* fatal error if not found */
  317.   call pmprintf(' SRE-http Monitor: ERROR: could not load macrospace library ')
  318.   call gosEXIT ' could not load macrospace library '
  319. end
  320.  
  321. /* set configuration files directory */
  322. if CFGs_dir='' then
  323.    CFGs_dir=servdir||'\CFGS'
  324. else
  325.    CFGs_dir=strip(cfgs_dir,'t','\')
  326. aa=value('SRE_CFGS_DIR',CFGs_dir,'os2environment')
  327.  
  328. cfglist_file=cfgs_dir||'\CFGLIST.CFG'
  329.  
  330. IF PRE_REPLY_PROCEDURE<>0 then DO
  331.    mustenable=0
  332.    if abbrev(pre_reply_procedure,'!')=1 then do
  333.        mustenable=1 ; pre_reply_procedure=delstr(pre_reply_procedure,1,1)
  334.    end /* do */
  335.    FOO=STREAM(PRE_REPLY_PROCEDURE,'C','query exists')
  336.    if foo='' then do
  337.        call pmprintf("SRE-http Monitor: ERROR: no such PRE_REPLY_PROCEDURE: "pre_reply_procedure)
  338.        call gosEXIT ' missing pre_reply_procedure'
  339.    end /* do */
  340. /* load into macrospace */
  341.    foo=macroadd('SREF_PREREPLY_PROC',pre_reply_procedure,'B')
  342.    if foo=0 then do
  343.        call pmprintf("SRE-http Monitor: ERROR: error loading PRE_REPLY_PROCEDURE: "pre_reply_procedure)
  344.        call gosEXIT ' bad pre_reply_procedure'
  345.    end
  346.    foo=value('SREF_PRE_REPLY',1+mustenable,'os2environment')
  347.    if verbose>1  then call pmprintf("SRE-http Monitor: PRE_REPLY_PROCEDURE enabled ")
  348. end /* do */
  349. else do
  350.    foo=value('SREF_PRE_REPLY',0,'os2environment')
  351. end /* do */
  352.  
  353.  
  354. doo=dostid()
  355. oo=dospid()||' '||dostid()
  356.  
  357. numeric digits 11
  358.  
  359. call pmprintf(" SRE-http Monitor: Initializing on port "|| serverport || ": " || filter_name' ('filter_number)
  360. call pmprintf(" SRE-http Monitor: Goserve pid ="|| goserve_pid' , Monitor thread '||doo)
  361. call pmprintf(" SRE-http Monitor: Using semaphore "|| thesem)
  362. parse upper version rexxtype .
  363. os2ver=sysos2ver()
  364. call pmprintf(" SRE-http Monitor: Using REXX version: " rexxtype ', under OS/2 ver 'os2ver)
  365.  
  366.  
  367. /* cycle through list of custom_init routines */
  368. foo=call_custom_Inits(custom_Inits)
  369.  
  370. /* after this, use pmprintf_sref */
  371.  
  372. /* start variable storage daemon */
  373. if storage_daemons=0 | datatype(storage_daemons)<>'NUM' then storage_Daemoms=1
  374. do iss=1 to storage_daemons
  375.    if iss=1 then
  376.      goon=''
  377.    else
  378.      goon='_'||iss
  379.    aa=start_varstore(goon)
  380. end /* do */
  381. call syssleep 1         /* wait for daemons to settle down */
  382.  
  383. if record_cache_lines>0 then
  384.    foo=pmprintf_sr(" SRE-http Monitor: Record cache file size= "||record_cache_lines)
  385.  
  386.  
  387. /* set location of init_File (check cgs_dir first, then servdir */
  388. init_File=stream(cfgs_dir"\INITFILT."||serverport,'c','query exists')
  389. if init_file='' then  init_file=servdir||"\INITFILT."||serverport
  390. filedate.initfilt=file_juldate(init_file)
  391.  
  392. filedate.cfglist=file_juldate(cfglist_file)
  393.  
  394. call get_initfilt(0)  /* and read cfglist.cfg */
  395. if result<0 then do
  396.           call pmprintf(' SRE-http Monitor ERROR: aborting due to initfilt error(s) ')
  397.           call gosexit 'initfilt error(s) '
  398. end
  399.  
  400. /* set the delta files directory */
  401. if deltas_dir='' then
  402.    deltas_dir=tempdata_dir||'\DELTAS'
  403. else
  404.    deltas_dir=strip(strip(deltas_dir),'t','\')
  405. if dosisdir(deltas_dir)=0 then do
  406.   call pmprintf('!! SRE-http Monitor WARNING: no deltas directory 'deltas_dir)
  407.   deltas_dir=0
  408. end
  409. else do
  410.   oo=dosfilesys(filespec('d',deltas_dir))
  411.   if oo<>'HPFS' then do
  412.      call pmprintf('!! SRE-http Monitor WARNING: delta-encoding disabled (DELTAS_DIR directory must be HPFS')
  413.      deltas_dir=0
  414.   end
  415. end
  416.  
  417. if deltas_dir=0 then do  /* if bad deltas_dir, no delta encoding */
  418.    delta_encoding_enable=0
  419. end /* do */
  420.  
  421. aa= value('SRE_DELTAS_DIR',deltas_dir,'os2environment')
  422.  
  423. /* check that diff is installed? */
  424. if delta_encoding_enable>0 then do
  425.     delta_encoding_enable=checK_diff(delta_encoding_enable)
  426. end
  427. /* and save final value of delta_encoding_enable */
  428. foo=value('SRE_DELTA_ENCODING_ENABLE',delta_encoding_enable,'Os2environment')
  429. foo=value('SRE_DELTA_ENCODING_ENABLE',,'Os2environment')
  430.  
  431. signal on error name yipes ; signal on syntax name yipes ;
  432. signal on failure name yipes ; signal on halt name yipes ;
  433.  
  434. call clear_temp(0)        /* clean up some junk */
  435.  
  436.  
  437. DEFREALM_FILE=cfgs_dir||'\ATTRIBS.CFG'
  438. DEFREALM_FILE_temp=tempdata_dir||'\$DFREALM.'||serverport
  439.  
  440. filedate.DEFREALM=file_juldate(DEFREALM_FILE)
  441.  
  442. foo= update_addons(0)
  443.  
  444. mediatyp_file=servdir||"\MEDIATYP.RXX"
  445. filedate.mediatyp=file_juldate(mediatyp_file)
  446. mediatyp_tfile=tempdata_dir||'\MEDIATYP.TMP'
  447. call value 'SREF_MEDIATYP_TFILE',mediatyp_tfile,'os2environment'
  448. call chk_mediatyp(0)
  449.  
  450.  
  451. call value 'SREF_DEFREALM_FILE',DEFREALM_FILE,'os2environment'
  452. call value 'SREF_DEFREALM_FILE_TEMP',DEFREALM_FILE_temp,'os2environment'
  453. call make_DEFREALM_FILE_temp(0)
  454.  
  455. if event_check>0 then do
  456.    call start_events(event_check)
  457. end /* do */
  458.  
  459. filedate.repstrgs=file_juldate(repstrgs_file)
  460. repsvars.0=0
  461. call chk_repstrgs(0)
  462.  
  463. filedate.access=file_juldate(access_file)
  464. aa=start_access(0)
  465.  
  466. filedate.alias=file_juldate(alias_file)
  467. aa=start_alias(0)
  468.  
  469. filedate.puburl=file_juldate(puburl_file)
  470. aa=start_puburl(0)
  471.  
  472. filedate.user=file_juldate(user_file)
  473. aa=start_user(0)
  474.  
  475. filedate.virtual=file_juldate(virtual_file)
  476. aa=start_virtual(0)
  477.  
  478. call start_srealm(0)
  479.  
  480. aa=start_ssicache(0)
  481.  
  482. aa=start_sreproxy(0)
  483. if aa=-1 then do
  484.    call pmprintf(' SRE-http Monitor ERROR: aborting due to sreproxy error ')
  485.    call gosexit 'SREProxy error '
  486. end 
  487.  
  488. aa=start_postf(0)
  489.  
  490. if md5_cache>0 then do
  491.    arxx=servdir||'\SREdomd5.cmd'
  492.    foo=n_launch('MD5_DMN_SREF',arxx,md5_cache)
  493.   
  494.    if strip(word(foo,1))<0 then do
  495.        call pmprintf(" SRE-http Monitor: could not launch md5 daemon: "foo)
  496.        foo=value('SREF_MD5DMN',1,'os2environment')
  497.    end
  498.    else do
  499.        call pmprintf(" SRE-http Monitor: MD5 daemon in seperate process "foo)
  500.        md5pid=foo
  501.        foo=value('SREF_MD5DMN',1,'os2environment')
  502.    end
  503. end
  504. else do
  505.    foo=value('SREF_MD5DMN',0,'os2environment')
  506. end
  507.  
  508.  
  509. aa=eventsem_create(thesem)
  510. if aa<0 then do
  511.  call pmprintf(" SRE-http Monitor: ERROR: could not create semaphore: "||thesem)
  512.  call gosexit "could not create semaphore: "||thesem
  513. end
  514. foo=eventsem_post(thesem)       /* let the boys have it */
  515.  
  516. foo=value('SREF_WAIT_FLAG',0,'os2environment')
  517. foo=value('SRE_SHUTDOWN',0,'os2environment')
  518. foo=value('SRE_SUSPEND',0,'os2environment')
  519.  
  520.  
  521. foo=pmprintf_sr(' SRE-http Monitor: Begin Monitoring parameters files ..... ')
  522. nloops=0
  523. geelist="INITFILT REPSTRGS MEDIATYP ALIAS ACCESS USER VIRTUAL PUBURL CFGLIST DEFREALM "
  524.  
  525. do forever
  526.   nloops=nloops+1
  527.    IF result<0 then do
  528.       call pmprintf(' SRE-http Monitor ERROR: leaving after rxl error')
  529.       leave
  530.    end
  531.  
  532. /* get dates of current files  -- 0 if doesnt exist */
  533.    t1.initfilt=file_juldate(init_file)
  534.    t1.cfglist=file_Juldate(cfglist_file)
  535.    t1.DEFREALM=file_Juldate(DEFREALM_FILE)
  536.  
  537.    t1.repstrgs=file_juldate(repstrgs_file)
  538.    t1.mediatyp=file_juldate(mediatyp_file)
  539.  
  540.    t1.alias=file_juldate(alias_file)
  541.    t1.puburl=file_juldate(puburl_file)
  542.  
  543.    t1.access=file_juldate(access_file)
  544.    t1.user=file_juldate(user_file)
  545.    t1.virtual=file_juldate(virtual_file)
  546.  
  547.    if md5_cache>0 then do            /* md5 cache still healthy? */
  548.         afoo=dosprocinfo('N',md5pid)
  549.         if afoo='' then do
  550.            foo=value('SREF_MD5DMN',-1,'os2environment')
  551.            call pmprintf(' SRE-http Monitor: MD5 digest wil not be computed -- daemon disappeared! ')
  552.            md5_cache=0
  553.         end
  554.    end
  555.  
  556.  
  557. /* any of them newer then last stored files */
  558.    redo=0
  559.    do mm=1 to words(geelist)
  560.        oo1=word(geelist,mm)
  561.        if t1.oo1 > filedate.oo1 then do
  562.            redo=1
  563.            filedate.oo1=t1.oo1
  564.         end
  565.    end
  566.  
  567.    if nloops>doanyway_loops then do         /* every 60 (or so) minutes, reset it anyways */
  568.         nloops=1                  /* just to be safe! */
  569.         redo=1
  570.    end
  571.    foo=value('SREF_REDO',,'os2environment')
  572.    if foo=1 then do 
  573.       redo=1
  574.    end  /* Do */
  575.    foo=value('SREF_REDO',0,'os2environment')  /* reset to 0*/
  576.  
  577. /* one of three ways of being a redo? then reset */
  578.    if redo=1 then do            /* reset all stuff */
  579.  
  580.       foo=pmprintf_sr(" SRE-http resetting variables ")
  581.  
  582.       call get_initfilt(filedate.initfilt)  /* and read hosts.cfg */
  583.       if result<0 then do
  584.           call pmprintf(' SRE-http Monitor ERROR: aborting due to initfilt error(s) ')
  585.           leave
  586.       end
  587.       call start_access(1)
  588.       call start_alias(1)
  589.       call start_puburl(1)
  590.  
  591.       call start_user(1)
  592.  
  593.       foo=start_pmprintf(pmprintf_opt,pmprintf_line_length,pmprintf_log_file,1)
  594.       aa=start_postf(1)
  595.  
  596.       call start_srealm(1)
  597.  
  598.       call start_virtual(1)
  599.       call chk_repstrgs(0)
  600.       call chk_mediatyp(0)
  601.       call make_DEFREALM_FILE_temp(0)
  602.  
  603.       call start_sreproxy(1)
  604.  
  605.       foo= update_addons(0)
  606.  
  607. /* store dates of just reset files (initfilt may have changed names */
  608.      filedate.access=file_juldate(access_file)
  609.      filedate.alias=file_juldate(alias_file)
  610.      filedate.puburl=file_juldate(puburl_file)
  611.  
  612.      filedate.user=file_juldate(user_file)
  613.      filedate.virtual=file_juldate(virtual_file)
  614.      filedate.repstrgs=file_juldate(repstrgs_file)
  615.      filedate.mediatyp=file_juldate(mediatyp_file)
  616.      filedate.initfilt=file_juldate(init_file)
  617.      filedate.cfglist=file_juldate(cfglist_file)
  618.      filedate.DEFREALM=file_juldate(DEFREALM_FILE)
  619.  
  620.      foo=pmprintf_sr(' SRE-http Monitor: Success resetting parameters ')
  621.     end
  622.  
  623. /* always check up on cached files (note that they may have
  624. changed if initfilt was updated */
  625.  
  626.     n=delay(delay_seconds)
  627.  
  628. /* get current env variables, perhaps write to pmprintf */
  629.    if display_env=1  then do
  630.        foo=pmprintf_sr(" Current SREF environment variables -----  ")
  631.        wow=dosenvlist(envs)
  632.        do kj=1 to envs.0
  633.            tv=strip(envs.kj)
  634.            if abbrev(tv,'SRE')=0 then iterate
  635.            ares=value(tv,,'os2environment')
  636.            iii=min(100,length(ares))
  637.            if abbrev(tv,'SREF_')=1 then 
  638.                 parse var tv . '_' . '_' atv
  639.            else
  640.                 parse var tv . "_" atv 
  641.            foo=pmprintf_sr(atv'='left(ares,iii))
  642.        end
  643.        foo=pmprintf_sr(' --- end of sref environment variables ')
  644.        display_env=0
  645.    end
  646.  
  647. /* CAN'T DO THIS UNDER NEW GOSERVE 
  648.    ext1=extract('clients') */
  649.  
  650. /* note: small chance that this will delete a client's cgi-stuff that
  651. get's invoked just after the above extract('clients'). But, that just
  652. messes 1 client up, and it's so unlikely that it's not worth worrying about */
  653.    if redo=1 & do_cleanup=1 then foo=clear_temp(1)
  654.  
  655. end  /* forever loop */
  656.  
  657.  
  658. exit            /* should never get here ! */
  659.  
  660. yipes:
  661. call pmprintf(" SRE-http Monitor ERROR at: " sigl', rc='rc )
  662. exit 'Error in SREFMON'
  663.  
  664. /* --------- END OF MAIN ---------------------------------------- */
  665.  
  666. /* ------------------------------------------------- */
  667. /* Routine to check, and load if neccessary,  SREFPRC.RXL into macrospace */
  668. /* ------------------------------------------------- */
  669.  
  670. load_rxl:
  671.  
  672. if use_dynamic_lib<>1 then do                /* load srefprc.rxl */
  673.   call load_rxl_old
  674.   return 1
  675. end
  676.  
  677. if use_lib_dir='' then
  678.    lib_dir=servdir||'\LIB'
  679. else
  680.    lib_dir=strip(use_lib_dir,'t','\')
  681.  
  682. aa=value('SRE_LIBDIR',lib_dir,'os2environment')
  683. tempsref=lib_dir||'\TEMPSREF.CMD'
  684.  
  685. if dosisdir(lib_dir)=0 then do
  686.   call pmprintf(' SRE-http Monitor: FATAL ERROR: could not find Library Directory: 'lib_dir)
  687.   call gosexit 'could not find Library Directory: 'lib_dir
  688. end  /* Do */
  689.  
  690. call pmprintf(' SRE-http Monitor: Library directory= 'lib_dir)
  691.  
  692. /* find list of procedures */
  693. if clear_macrospace>=0 then do
  694.  arf=lib_dir||'\SREFPRC.IDX'
  695.  foo=stream(arf,'c','query size')
  696.  if foo=0 | foo=' ' then do
  697.    call pmprintf( ' SRE-http Monitor: WARNING: could not find 'arf)
  698.  end 
  699.  else do                 /* zap old versions of procedures */
  700.    aa=charin(arf,1,foo)
  701.    idid=0
  702.    do until aa=''
  703.       parse var aa aline '0d0a'x aa
  704.       if aline='' then iterate
  705.       aline=strip(aline)
  706.       if abbrev(aline,';')=1 then iterate
  707.       if words(aline)>1 then iterate
  708.       foo=macrodrop(aline)
  709.       if foo<>1 then do
  710.             if macroquery(aline)<>' ' then do
  711.               call pmprintf('SRE-http Monitor: ERROR -- unable to macro_drop 'aline)
  712.               exit
  713.             end         /* otherwise, it's not there */
  714.       end 
  715.       else do
  716.           idid=idid+1
  717.       end
  718.    end 
  719.    call pmprintf(' SRE-http Monitor: 'idid' macrospace procedures removed.')
  720.  end 
  721. end
  722.  
  723. if macroquery('SREF_ERROR')="" then do  /* load rxl library? */
  724.    parse upper version rexxtype .
  725.    if rexxtype="OBJREXX" then do
  726.         call pmprintf(" SRE-http Monitor: ERROR. SRE-http will not run under object rexx ")
  727.         call gosexit  "SRE-http will not run under object rexx "
  728.    end
  729.    else do
  730.        call pmprintf(" SRE-http Monitor: Loading SREFPRC.RXL into macrospace ")
  731.        rxlfile=lib_dir||'\SREFPRC.RXL'
  732.    end
  733. /* get procedure with procnames in it */
  734.    aa=macroload(rxlfile)
  735.    if aa=0 then do
  736.       call pmprintf(" SRE-http Monitor: ERROR: "|| rxlfile ||" not available! "|| aa)
  737.       call gosEXIT  rxlfile ||" not available! "|| aa
  738.    end
  739.    CALL pmprintf(" SRE-http Monitor: Success on macrospace dynamic library load ")
  740. end
  741. filter_name=sref_version()
  742. filter_number=sref_version(,1)
  743.  
  744.  
  745.  
  746. RETURN 1
  747.  
  748. /* old, non-dynamic version */
  749.  
  750. load_rxl_old:
  751. if macroquery('SREF_VERSION')="" then do  /* load rxl library? */
  752.  
  753.    parse upper version rexxtype .
  754.    if rexxtype="OBJREXX" then do
  755.         call pmprintf(" SRE-http Monitor: ERROR. SRE-http will not run under object rexx ")
  756.         call gosexit  "SRE-http will not run under object rexx "
  757.    end
  758.    else do
  759.        call pmprintf(" SRE-http Monitor: Loading SREFPRCS.RXL into macrospace ")
  760.        tt=servdir||'\SREFPRCS.RXL'  
  761.    end
  762.    aa=macroload(tt)
  763.    if aa=0 then do
  764.       call pmprintf(" SRE-http Monitor: ERROR: "|| tt ||" not available! "|| aa)
  765.       RETURN -1
  766.    end
  767.    foo=pmprintf_sr(" SRE-http Monitor: Success on macrospace library load ")
  768. end
  769. filter_name=sref_version()
  770. filter_number=sref_version(,1)
  771. return 1
  772.  
  773.  
  774.  
  775. /* md5 daemon (process) launcher. */
  776. n_launch:procedure 
  777.  
  778. parse arg daemon_name,file_name,init_arg
  779.  
  780. /* relative file name? Then assume it's under the goserve addon
  781. directory */
  782.  
  783. fname=strip(upper(file_name))
  784. if pos(':',fname)=0 & abbrev(fname,'\')=0 then do  /*  a relative file */
  785.    addir=sref_value('ADDON_DIR',,'INI')
  786.    if addir<>"" then fname=strip(addir,'t','\')||'\'||fname
  787. end
  788. if fname=' ' then return '-1 Could not find file: 'file_name
  789. fname=stream(fname,'c','query exists')   /* does this file exist */
  790.  
  791. stat=make_em(daemon_name)            /* create queue and semaphore */
  792. if stat=0 then return '-2 Problem creating queue or semaphore '
  793.  
  794. /* launch the daemon as a thread. Provide opitonal argument 
  795. foo=rexxthread('F',fname,daemon_name,init_arg)
  796. if foo=0 then return '-3 Daemon could not be launched '
  797. */
  798.  
  799. /* launch as process */
  800. '@start "SRE-http MD5 daemon" /C 'fname' 'daemon_name' 'init_arg' '||dospid()
  801. if rc<>0 then call pmprintf('!! SRE-http Monitor WARNING: rc from start 'fname'='rc) 
  802.  
  803. wpid=sref_dmn_ask('MD5_DMN_SREF','*PID*',30)
  804.  
  805. return wpid                /* success */
  806.  
  807.  
  808. /*********/
  809. /* Check for DIFF and GDIFF executables */
  810. check_diff:procedure expose deltas_dir
  811. parse arg kval
  812.  
  813. signal on error name dyipes ; signal on syntax name dyipes ;
  814. signal on failure name dyipes ; signal on halt name dyipes ;
  815.  
  816. aa=''
  817. t1=deltas_dir'\'dospid()'_'dostid()'.1a'
  818. address cmd 'DIFF -v >'||t1
  819. ioo=stream(t1,'c','query size') 
  820. if ioo>0 & ioo<>'' then   aa=translate(charin(t1,1,ioo))
  821.  
  822. dyipes: nop 
  823. if pos('DIFFUTILS',aa)=0 then do
  824.    call pmprintf('!! SRE-http monitor WARNING: DIFF executable not found, no delta encoding.')
  825.    call pmprintf('  ... '||left(aa,80))
  826.    foo=stream(t1,'c','close')
  827.    foo=sysfiledelete(t1)
  828.    return 0
  829. end /* do */
  830. foo=stream(t1,'c','close')
  831. foo=sysfiledelete(t1)
  832.  
  833. isbad=1
  834. if rxfuncquery('rxGdiff')=1  then do
  835.   foo= RXFuncAdd( 'RXGdiffLoad', 'RXGDIFF', 'RxGdiffLoad')
  836.   if foo=0 then do
  837.      call RxGdiffLoad
  838.      isbad= rxfuncquery('rxGdiff')
  839.   end
  840. end
  841. else do
  842.    isbad=0
  843. end /* do */
  844. if isbad=1 then do
  845.    call pmprintf('!! SRE-http monitor WARNING: rxGDIFF.dll not found, no delta encoding.')
  846.    return 0            
  847. end
  848.  
  849. return  kval
  850.  
  851.  
  852. /*****************************/
  853. /* make queue and semaphore */
  854. make_em:procedure
  855. parse arg aname
  856.  
  857. usesem='\SEM32\SRE_DMN_'||aname
  858. usequeue='SRE_DMN_'||aname
  859.  
  860. aqueue=rxqueue('C',usequeue)
  861. if aqueue<>usequeue then do    /* usequese exists, so kill unneeded new q */
  862.   foo=rxqueue('d',aqueue)      /* kill unneeded queue */
  863.   foo=rxqueue('s',usequeue)
  864.   ik=queued()
  865.   do ll=1 to ik               /* clear out pre existing queue */
  866.        pull boop
  867.    end
  868. end
  869.  
  870. wow=eventsem_query(usesem)
  871. if wow=-187 then do
  872.   foo=eventsem_create(usesem)
  873.   if foo<>0 then return 0
  874. end /* do */
  875. oo=eventsem_reset(usesem)
  876.  
  877. return 1
  878.  
  879. /* ------------------------------------------------- */
  880. /* get date (fat and julian) of a file */
  881. /* ------------------------------------------------- */
  882.  
  883. file_juldate:procedure
  884.  
  885.  
  886. parse arg get_file , isquiet
  887. if GET_file=" " then return 0
  888.  
  889. eek=sysfiletree(translate(get_file,'\','/'),'gosh','FT')
  890. if gosh.0=0 then do  /* no file */
  891.    return 0
  892. end
  893. parse var gosh.1  atime .
  894. aa=sref_juldate('F',atime)
  895. return aa
  896.  
  897. /* ------------------------------------------------- */
  898. /* clear all $*.80, and other temporary files out of tempdata_Dir */
  899. /* ------------------------------------------------- */
  900. clear_temp:
  901. parse arg cl1
  902.  
  903. if cl1<>1 then do               /* only do on startup */
  904.   lookstar=tempdata_dir||'\_DIRLIST.IDX'
  905.   foo=sysfiledelete(lookstar)
  906.  
  907.   lookstar=tempdata_dir||'\MEDIATYP.TMP'
  908.   foo=sysfiledelete(lookstar)
  909.  
  910.   lookstar=tempdata_dir||'\_*.DSH'         /* delete old directory cache files */
  911.   foo=sysfiletree(lookstar,stuff,'Fo')
  912.   do mm=1 to stuff.0
  913.     foo=sysfiledelete(stuff.mm)
  914.   end /* do */
  915.   if stuff.0>0 then
  916.   foo=pmprintf_sr('SRE-http Monitor: Deleted ' stuff.0 ' old directory cache files from: 'tempdata_dir)
  917.  
  918.   lookstar=tempdata_dir||'\_*.TMP'         /* delete old .TMP files */
  919.   foo=sysfiletree(lookstar,stuff,'FO')
  920.   do mm=1 to stuff.0
  921.     foo=sysfiledelete(stuff.mm)
  922.   end /* do */
  923.   if stuff.0>0 then
  924.     foo=pmprintf_sr('SRE-http Monitor: Deleted ' stuff.0 ' _*.TMP files from: 'tempdata_dir)
  925.  
  926.   lookstar=strip(tempdata_dir||'\_T*.'||serverport)         /* delete old .TMP  files */
  927.   foo=sysfiletree(lookstar,stuff,'FO')
  928.   do mm=1 to stuff.0
  929.    foo=sysfiledelete(stuff.mm)
  930.   end /* do */
  931.   if stuff.0>0 then
  932.     foo=pmprintf_sr('SRE-http Monitor: Deleted ' stuff.0 ' _T*.'serverport ' files from: 'tempdata_dir)
  933.  
  934.   lookstar=strip(tempdata_dir||'\_HT*.'||serverport)         /* delete old remote virtual files */
  935.   foo=sysfiletree(lookstar,stuff,'FO')
  936.   do mm=1 to stuff.0
  937.    foo=sysfiledelete(stuff.mm)
  938.   end /* do */
  939.   if stuff.0>0 then
  940.     foo=pmprintf_sr('SRE-http Monitor: Deleted ' stuff.0 ' _HT*.'serverport ' files from: 'tempdata_dir)
  941.  
  942.  
  943.   lookstar=strip(tempdata_dir||'\_ADDPRIV.'||serverport)         /* delete old additional privs  files */
  944.   foo=stream(lookstar,'c','query exists')
  945.   if foo<>'' then do
  946.      foo=sysfiledelete(foo)
  947.      foo=pmprintf_sr('SRE-http Monitor: Deleted additional privileges file ')
  948.   end /* do */
  949.  
  950. end             /* cleanup on startup only */
  951.  
  952.  
  953. /* do on startup, and on periodic cleanup */
  954. nowtime=date('b')+(time('s')/(24*60*60))
  955.  
  956. lookstar=tempdata_dir||'\~*.'||serverport         /* delete old cgi-bin temp files */
  957. foo=sysfiletree(lookstar,stuff,'Ft')
  958.  
  959. kkt=0           /* note: only delete if < .1 day (2.4 hours) old */
  960.  
  961. do mm=1 to stuff.0
  962.    parse var stuff.mm adate ff1 ff2 afile ; afile=strip(afile)
  963.    if cl1==1 then do            /* check time before deleting */
  964.         ttime=dateconv_3(adate,'o','b')
  965.         if nowtime-ttime<0.1 then iterate 
  966.    end
  967.    foo=sysfiledelete(afile)
  968.    kkt=kkt+1
  969. end /* do */
  970. if kkt>0 then
  971.   foo=pmprintf_sr('SRE-http Monitor: Deleted ' kkt ' ~*.80 files from: 'tempdata_dir)
  972.  
  973. lookstar=tempdata_dir||'\$*.'||serverport         /* delete old cgi-bin temp files */
  974. foo=sysfiletree(lookstar,stuff,'Ft')
  975. kkt=0
  976. do mm=1 to stuff.0
  977.    parse var stuff.mm adate ff1 ff2 afile ;afile=strip(afile)
  978.    if cl1==1 then do            /* check time before deleting */
  979.         ttime=dateconv_3(adate,'o','b')
  980.         if nowtime-ttime<0.1 then iterate 
  981.    end
  982.    foo=sysfiledelete(afile)
  983.    kkt=kkt+1
  984. end /* do */
  985. if kkt>0 then
  986.   foo=pmprintf_sr('SRE-http Monitor: Deleted ' kkt ' $*.80 files from: 'tempdata_dir)
  987.  
  988.  
  989. lookstar=strip(tempdata_dir||'\F*.cmd')         /* delete old .TMP  files */
  990. foo=sysfiletree(lookstar,stuff,'Ft')
  991. kkt=0
  992. do mm=1 to stuff.0
  993.    parse var stuff.mm adate ff1 ff2 afile ; afile=strip(afile)
  994.    if cl1=1 then do            /* check time before deleting */
  995.         ttime=dateconv_3(adate,'o','b')
  996.         if nowtime-ttime<0.1 then iterate 
  997.    end
  998.    foo=sysfiledelete(afile)
  999.    kkt=kkt+1
  1000. end /* do */
  1001. if kkt>0 then
  1002.   foo=pmprintf_sr('SRE-http Monitor: Deleted ' kkt ' F*.CMD  files from: 'tempdata_dir)
  1003.  
  1004.  
  1005. /* and if deltas are enabled, cleanup LRU cache files S*/
  1006. if delta_encoding_enable>0 then do
  1007.    ndel=cleanup_deltas(deltas_dir,delta_encoding_maxsize)
  1008.    if ndel>0 then
  1009.       foo=pmprintf_sr('SRE-http Monitor: Deleted ' ndel ' old cache files from 'deltas_dir)
  1010. end
  1011.  
  1012.  
  1013.  
  1014. return 0
  1015.  
  1016.  
  1017.  
  1018. /* ------------------------------------------------- */
  1019. /* routine to load initfilt.nnn into macrospace
  1020.    return 0= no change , 1= change,return<0=error 
  1021.   NOte: if line starts with $xxx, then see if xxx = the MACHINE_ID_SRE.
  1022.   If not, skip it
  1023. */
  1024. /* ------------------------------------------------- */
  1025. get_initfilt:
  1026. PARSE ARG DACALL
  1027.  
  1028. get_file=init_file
  1029. if get_file=" " then return 0
  1030. oy=stream(get_file,'c','query exists')
  1031. if oy=' ' then do
  1032.    CALL pmprintf("SRE-http Monitor:FATAL ERROR. INITFILT file not found, "|| get_file)
  1033.    call gosexit  "INITFILT file not found, "|| get_file
  1034. end
  1035.  
  1036. /* get machine if, if set */
  1037. machine_id=value('MACHINE_ID_SRE',,'os2environment')  /* should be a global env var */
  1038. if verbose>2 then call pmprintf(" SRE-http Monitor: Machine ID = " machine_id)
  1039.  
  1040.  
  1041. /* get list of possible host specific variables: and clear their values */
  1042. a=rxqueue('s','session')
  1043. wow=dosenvlist(envs)
  1044. if wow=0 then do
  1045.     call pmprintf("!! SRE-http Monitor WARNING: Environment appears to be empty ")
  1046. end /* do */
  1047. else do
  1048.    do mm=1 to envs.0
  1049.       ares0=envs.mm
  1050.       if abbrev(upper(ares0),'SREF_')=1 then do
  1051.          parse upper var ares0 ares '=' .
  1052.          ibeam=lastpos('.',ares)
  1053.          if ibeam>0 then do
  1054.            cat3=substr(ares,ibeam+1)
  1055.            if datatype(cat3)<>'NUM' then do
  1056.               parse var ares . '_' . '_' ares1 '=' .
  1057.               interpret ares1||'=" " '
  1058.               if verbose>3 then foo=pmprintf_sr('SRE-http Monitor: clearing: ' ares1)
  1059.            end          /* got a host specific entry ; ie. fix_expire.host2= */
  1060.          end  /* got a . ed entry */
  1061.       end
  1062.    end     /* an sref entry */
  1063. end     /* envlist empty */
  1064.  
  1065. call default_initfilt           /* default values */
  1066.  
  1067. ause=sref_fileread(get_file,'filelines',,'E')
  1068. If (ause<=0) then  do               /*no such file,*/
  1069.       CALL pmprintf("SRE-http Monitor: FATAL ERROR. INITFILT file unusable")
  1070.       call pmprintf('      File read: ' get_file)
  1071.       call pmprintf('      fileread response: 'ause)
  1072.       call pmprintf('      filelines.0:' filelines.0)
  1073.       call pmprintf('      filelines.1:' filelines.1)
  1074.       argz=stream(get_file,'c','query size')
  1075.       call pmprintf('     Stream query size= ' argz)
  1076.       call gosexit "INITFILT file unusable"
  1077. end
  1078.  
  1079.  
  1080. /* add  auxillary INITFILT.nnnn files? */
  1081. foa=add_auxillary('INITFILT','INITFILT.80',serverport,1)
  1082. If (foa=0) then  do               /*missing file,*/
  1083.       CALL pmprintf("SRE-http Monitor: FATAL ERROR. Missing auxillary INITFILT file")
  1084.       call gosexit "Missing AUXILLARY INITFILT file"
  1085. end
  1086.  
  1087. /*Allow for gratuitous coding calamity by clumsy users */
  1088.  
  1089. mm=0 ; nerrs=0
  1090.  
  1091. iat1: nop
  1092.  
  1093. ok=0            /* assume an error */
  1094. /* exit here when entire file read. Before exiting, cleanup and save results */
  1095.  
  1096. if mm>=filelines.0 then do    /* nothing more to interpret... SAVE and exit */
  1097.    if nerrs>0 then do
  1098.      signal off syntax ;   signal off error
  1099.      signal on error name yipes ; signal on syntax name yipes ;
  1100.      if  nerrs>0 then do
  1101.         if verbose>0 then foo=pmprintf_sr(' SRE-http Monitor:' nerrs ' errors in initfil.')
  1102.          return  -nerrs               /* any error is fatal */
  1103.       end  /* Do */
  1104.    end
  1105.    call initfilt_checkup
  1106.  
  1107.    call save_envstuff
  1108.  
  1109. /* check on status of counter files (create if necessary ) */
  1110.  
  1111.    if counter_file<>'' then do
  1112.        hitmeter_file=filespec('d',counter_file)||filespec('p',counter_file)
  1113.        hitmeter_file=strip(hitmeter_file,'t','\')||'\HITMETER.CNT'
  1114.    end /* do */
  1115.    else do
  1116.       hitmeter_file='HITMETER.CNT'
  1117.    end 
  1118.    res1=sref_init_counter(counter_file, upload_log , ,
  1119.                          record_all_file , record_option,hitmeter_file)
  1120.    parse var res1 counter_file  upload_log  record_all_file  record_option hitmeter_file
  1121.    call value envadd||'COUNTER_FILE',counter_file,'os2environment'
  1122.    call value envadd||'UPLOAD_LOG',upload_log,'os2environment'
  1123. /*   call value envadd||'RECORD_OPTION',record_option,'os2environment' */
  1124.    call save_em('RECORD_OPTION')
  1125.    call value envadd||'RECORD_ALL_FILE',record_all_file,'os2environment'
  1126.    call value 'SREF_HITMETER_FILE',hitmeter_file,'os2environment'
  1127.  
  1128.    call value envadd||'SERVERPORT',serverport,'os2environment'
  1129.    call value 'SREF_SERVERPORT',serverport,'os2environment'
  1130.  
  1131.    foo=pmprintf_sr(" SRE-http Monitor: InitFilt file loaded, "||get_file)
  1132.  
  1133.    return 1
  1134. end
  1135.  
  1136.  
  1137. /* --- IF here, there is more stuff to INTERPET */
  1138. mm=mm+1
  1139. signal off syntax ;   signal off error
  1140. signal on syntax name foobar1
  1141. signal on error name foobar1
  1142. signal on failure name foobar1
  1143. signal on halt name foobar1
  1144. filelines.mm=fix_me(filelines.mm)  /* convert from foo.host.n to foo.n.host */
  1145.  
  1146. goo=strip(filelines.mm)
  1147. if goo="" | left(goo,1)=";" then  signal iat1
  1148.  
  1149. if abbrev(goo,'$')=1 then do    /* is it machine_Id specific */ 
  1150.    parse var goo anid goo ; goo=strip(goo)
  1151.    anid=substr(upper(strip(anid)),2)
  1152.    if anid<>machine_id then signal iat1  /* not for this "machine" -- so skip it */
  1153. end /* do */
  1154.  
  1155.  
  1156.  
  1157. /* convert PUBLIC_FILES to PUBLC_URLS */
  1158. if abbrev(upper(goo),'PUBLIC_FILES')=1 then
  1159.    goo='PUBLIC_URLS'||delstr(goo,1,12)
  1160.  
  1161. /* convert PUBLIC_URL. to PUBLC_URLS. */
  1162. if abbrev(upper(goo),'PUBLIC_URL.')=1 then
  1163.    goo='PUBLIC_URLS'||delstr(goo,1,10)
  1164.  
  1165.  if abbrev(upper(goo),'SERVDIR')=1 then do
  1166.      foo=pmprintf_sr('!! SRE-http Monitor WARNING: INITFILT not allowed to change SERVDIR variable ')
  1167.      nop /* don't let it be changed! */
  1168.  end
  1169.  else do                        /* THIS does the ACTUAL work */
  1170.     interpret goo
  1171.  end
  1172.  
  1173. ok=1
  1174.  
  1175. foobar1:                /* here on error */
  1176. if ok=0 then do
  1177.    nerrs=nerrs+1
  1178.    call pmprintf(sigl"!!! WARNING: SRE-http Monitor: ERROR: in initfilt at ")
  1179.    call pmprintf("         "||goo)
  1180. end
  1181.  
  1182.  
  1183. signal iat1
  1184.  
  1185. /* ============ END of main  ==================== */
  1186.  
  1187.  
  1188. /**********************************/
  1189. /* start event monitor daemon */
  1190. start_events:
  1191.  
  1192. parse arg icheck
  1193. events_file=cfgs_dir||'\EVENTS.CFG'
  1194. arxx=servdir||'\events.rxx'
  1195. foo=rexxthread('F',arxx,events_file,icheck,serverport,servername)
  1196.  
  1197. if foo=0 then do
  1198.    foo=pmprintf_sr(' SRE-http Monitor: ERROR: Could not create events thread 'arxx)
  1199.    return -1
  1200. end
  1201. return 0
  1202.  
  1203.  
  1204.  
  1205. /**********************************/
  1206. /* Add entries to repstrgs filelines. variable, from the defrealm_file_Temp.
  1207.   Note that this file only has the appropriate port entries
  1208.   in it */
  1209. add_defrealm_rep:procedure expose defrealm_file_temp filelines.
  1210.  
  1211. defrealm=defrealm_file_temp
  1212. parse upper arg atype
  1213. atype=strip(atype)
  1214. crlf='0d0a'x
  1215.  
  1216. if defrealm='' then return 0
  1217. aa=sref_open_read(defrealm,15,'READ')
  1218. if aa<=0 then return 0
  1219.  
  1220. ii=stream(defrealm,'c','query size')
  1221. if ii=0 | ii='' then return 0
  1222.  
  1223. stuff=charin(defrealm,1,ii)
  1224. foo=stream(defrealm,'c','close')
  1225.  
  1226. do forever
  1227.   if stuff="" then return 1
  1228.   parse var stuff aline (crlf) stuff
  1229.   if abbrev(aline,';')=1 then iterate
  1230.   parse var aline btype ':' aline
  1231.   if btype<>atype then iterate
  1232.   ii=filelines.0+1
  1233.   filelines.ii=aline
  1234.   filelines.0=ii
  1235. end
  1236.  
  1237.  
  1238.  
  1239. /* ---------------------------------------------- */
  1240. /* read auxillary INITFILT and repstrgs files */
  1241. add_auxillary:procedure expose filelines. cfglist_file cfgs_dir
  1242. parse upper arg atype,dfile,sport,numeric_tails
  1243.  
  1244.  
  1245. if cfglist_file='' then return  1       /* nothing to do */
  1246.  
  1247. /* look for files */
  1248. foo=translate(stream(cfglist_file,'c','open read'))
  1249. if abbrev(foo,'READY')<>1 then do
  1250.   call pmprintf('SRE-http Monitor: Unable to open 'cfglist_file ' ('foo)
  1251.   return 1            /* unable to open */
  1252. end
  1253. inj=stream(cfglist_file,'c','query size')
  1254. if inj=0 | inj='' then return   1        /* empty file */
  1255. astuff=charin(cfglist_file,1,inj)
  1256. foo=stream(cfglist_file,'c','close')
  1257.  
  1258. crlf='0d0a'x
  1259. astuff=astuff||crlf||' '        /* place an elephant in cairo */
  1260.  
  1261. /* determine which atype apply to this port, by readling CFGLIST.CFG */
  1262. mm=0
  1263.  
  1264. /* note: file is organized in blocks */
  1265. curport=80              /* defaults port and host */
  1266. curhost=''
  1267. curfile=''
  1268.  
  1269. do forever              /* for all blocks in file */
  1270.   if astuff='' then leave       /* all done  (note we always put an elephant in cairo */
  1271.   parse var astuff aline (crlf) astuff
  1272.   if abbrev(aline,';')=1 then iterate   /* ignore comments */
  1273.   if aline='' then do           /* block end */
  1274.      if curport<>sport | curfile='' then do     /* different port, or  file not specified */ 
  1275.         nop 
  1276.      end
  1277.      else do        /* otherwise, add this entry to filelist */
  1278.         mm=mm+1
  1279.         ufiles.mm.!host=curhost
  1280.         ufiles.mm.!file=curfile
  1281.      end
  1282.      curport=80 ; curhost='' ; curfile=''  /* clear block */
  1283.      iterate
  1284.   end
  1285.  
  1286. /* process an entry in this block */
  1287.   parse upper var aline ltype ':' lstuff ;ltype=strip(ltype) ; lstuff=strip(lstuff)
  1288.  
  1289.   select
  1290.     when ltype='PORT' then curport=lstuff
  1291.     when ltype='HOST' then curhost=lstuff
  1292.     when ltype=atype  then do
  1293.        curfile=strip(translate(lstuff,'\','/'),'l','\')
  1294.        if pos(':',curfile)=0 then curfile=cfgs_dir||'\'||curfile
  1295.     end
  1296.     when ltype='*'  then do
  1297.        curfile=strip(translate(lstuff,'\','/'),,'\')
  1298.        if pos(':',curfile)=0 then curfile=cfgs_dir||'\'||curfile
  1299.        curfile=stream(curfile'\'dfile,'c','query exists')
  1300.     end
  1301.  
  1302.     otherwise nop
  1303.   end
  1304.  
  1305. end
  1306.  
  1307. /* done reading cfglist; add entries from appropriate files */
  1308. if mm=0 then return 1     /* no auxillary files of this type */
  1309.  
  1310. ufiles.0=mm
  1311.  
  1312. do mm=1 to filelines.0              /* retain old fileline */
  1313.   ulisttmp.mm=filelines.mm
  1314. end
  1315. ulisttmp.0=filelines.0
  1316.  
  1317.  
  1318. do mm=1 to ufiles.0
  1319.   afile=ufiles.mm.!file
  1320.   ahost=ufiles.mm.!host
  1321.  
  1322.   a=sref_fileread(afile,'ulines',,'E')   /* read it to a stem variable */
  1323.  
  1324.   if a=0 | ulines.0=0 then do
  1325.       call pmprintf('!! SRE-http Monitor WARNING: ** bad auxillary '||atype||': '||afile)
  1326.       iterate
  1327.   end
  1328.    
  1329.    call pmprintf(' SRE-http Monitor: '||lower('adding from '||AHOST|| ' specific 'atype' 'afile ',' ulines.0))
  1330.  
  1331.    do ii=1 to ulines.0
  1332.         aline=strip(ulines.ii)
  1333.         if ALINE=' ' then iterate
  1334.         aline=translate(aline,' ','0009'x)
  1335.         if  abbrev(strip(aline),';')=1 then iterate
  1336.         if atype='REPSTRGS' then
  1337.           parse var aline avar aval
  1338.         else
  1339.             parse var aline avar '=' aval
  1340.         ilp=lastpos('.',avar)
  1341.         if ilp>0 & numeric_tails=1 then do    /* numeric_tails=1 means "last tail must be a number */
  1342.             llstem=substr(avar,ilp+1)
  1343.             if datatype(llstem)<>'NUM' then do
  1344.                 call pmprintf('!! SRE-http Monitor WARNING: disallowed auxillary entry: 'aline)
  1345.                iterate
  1346.             end
  1347.         end
  1348.         if ahost<>'' then  avar=strip(avar)||'.'||strip(ahost)
  1349.         ii2=ulisttmp.0+1
  1350.         if atype='REPSTRGS' then
  1351.            ulisttmp.ii2=avar||' '||aval
  1352.         else
  1353.             ulisttmp.ii2=avar||'='||aval
  1354.         ulisttmp.0=ii2
  1355.    end
  1356. end
  1357.  
  1358. do mm=1 to ulisttmp.0
  1359.    filelines.mm=ulisttmp.mm
  1360. end
  1361. filelines.0=ulisttmp.0
  1362. drop ulisttmp.
  1363. return 1
  1364.  
  1365. /* initfilt repstrgs */
  1366.  
  1367.  
  1368. /* ---------------------------------------------- */
  1369. /* read ATTRIBs from cfglist_File */
  1370. add_attribs:procedure expose  cfglist_file cfgs_dir 
  1371. parse upper arg sport
  1372.  
  1373. if cfglist_file='' then return  ''       /* nothing to do */
  1374.  
  1375. /* look for files */
  1376. foo=translate(stream(cfglist_file,'c','open read'))
  1377. if abbrev(foo,'READY')<>1 then do
  1378.   call pmprintf('SRE-http Monitor: Unable to open: 'cfglist_file' ('foo)
  1379.   return ''            /* unable to open */
  1380. end
  1381. inj=stream(cfglist_file,'c','query size')
  1382. if inj=0 | inj='' then return   ''        /* empty file, nothing to add */
  1383. astuff=charin(cfglist_file,1,inj)
  1384. foo=stream(cfglist_file,'c','close')
  1385.  
  1386. crlf='0d0a'x
  1387. astuff=astuff||crlf||' '        /* place an elephant in cairo */
  1388. nustuff=''
  1389.  
  1390. /* determine if any entries (ATTRIBS:), for this port, by readling CFGLIST.CFG */
  1391. mm=0
  1392.  
  1393. /* note: file is organized in blocks */
  1394. aport=80              /* defaults port and host */
  1395. ahost='' ; afile=''
  1396.  
  1397. do forever              /* for all blocks in file */
  1398.   if astuff='' then leave       /* all done  (note we always put an elephant in cairo */
  1399.   parse var astuff aline (crlf) astuff
  1400.   if abbrev(aline,';')=1 then iterate   /* ignore comments */
  1401.   if aline='' then do           /* block end */
  1402.      if afile<>''  then do
  1403.         if aport=sport then
  1404.             nustuff=nustuff||crlf||'Host: 'ahost||crlf||'Include: 'afile||crlf
  1405.      end /* a defrealm entry */
  1406.      ahost=''
  1407.      afile=''
  1408.      aport=80
  1409.      iterate
  1410.    end
  1411.  
  1412. /* else, info to store? */
  1413.    parse upper var aline ltype ':' lstuff ;
  1414.    ltype=strip(ltype) ; lstuff=strip(lstuff)
  1415.  
  1416.    select
  1417.        when ltype='PORT' then aport=lstuff
  1418.        when ltype='HOST' then ahost=lstuff
  1419.        when abbrev(ltype,'ATTR')=1 then afile=lstuff
  1420.        otherwise nop
  1421.    end /* select */
  1422.  
  1423. end
  1424.  
  1425. return nustuff
  1426.  
  1427.  
  1428.  
  1429. /* ---------------------------------------------- */
  1430. /* Clean up parameters in initfilt */
  1431. /* ---------------------------------------------- */
  1432. initfilt_checkup:
  1433.  
  1434. checklog=STRIP(translate(checklog))
  1435. IF CHECKLOG='YES' then CHECKLOG='ALWAYS'
  1436.   t1=wordpos(checklog,'NO ALWAYS INHOUSE')
  1437.   if t1=0 then checklog='NO'
  1438.  
  1439. user_logon_enable=STRIP(translate(user_logon_enable))
  1440. user_logon_enable=wordpos(user_logon_enable,'NO N 0')
  1441. if user_logon_enable>0 then
  1442.     user_logon_enable=0
  1443. else
  1444.     user_logon_enable=1
  1445.  
  1446. if auto_Name=0 then auto_name=" "
  1447.    auto_name=translate(auto_name)
  1448.  
  1449. /* include html for backward compataability */
  1450. check_alias=is_true(check_alias,'Y YES 1 HTM HTML ')
  1451.  
  1452. accept_range=is_true(accept_range,'Y YES 1')
  1453. no_include=is_true(no_include,'Y YES 1')
  1454. no_interpret_code=is_true(no_interpret_code,'Y YES 1')
  1455. no_processing=is_true(no_processing,'Y YES 1')
  1456. use_stdout=is_true(use_stdout,'Y YES 1')
  1457. add_user_name=is_true(add_user_name,'Y YES 1')
  1458. add_resource_name=is_true(add_resource_name,'Y YES 1')
  1459.  
  1460. check_add_privs=is_true(check_add_privs,'Y YES 1')
  1461.  
  1462. if logon_fail_file=' '  then logon_fail_file=0
  1463. if access_fail_file=' ' then access_fail_file=0
  1464.  
  1465. DEFAULT=STRIP(DEFAULT)
  1466.    if default=' ' then default='INDEX.HTM'
  1467.  
  1468. /* check for existnce of varouse directories */
  1469. mailbox_dir=translate(mailbox_dir,'\','/')
  1470.    mailbox_dir=strip(mailbox_dir,'t','\')
  1471. if dosisdir(mailbox_dir)=0 then do
  1472.      call pmprintf('!! SRE-http Monitor WARNING: could not find mailbox_dir: 'mailbox_dir)
  1473.      mailbox_dir=""
  1474. end  /* Do */
  1475.  
  1476. messbox_dir=translate(messbox_dir,'\','/')
  1477.    messbox_dir=strip(messbox_dir,'t','\')
  1478. if dosisdir(messbox_dir)=0 then do
  1479.      call pmprintf(' !! SRE-http Monitor WARNING: could not find messbox_dir: 'messbox_dir)
  1480.      messbox_dir=""
  1481. end  /* Do */
  1482.  
  1483. config_dir=translate(config_dir,'\','/')
  1484.    config_dir=strip(config_dir,'t','\')
  1485. if dosisdir(config_dir)=0 then do
  1486.      call pmprintf('!! SRE-http Monitor WARNING: could not find config_dir: 'config_dir)
  1487.      config_dir=datadir()
  1488. end  /* Do */
  1489.  
  1490. workdata_dir=translate(workdata_dir,'\','/')
  1491.    workdata_dir=strip(workdata_dir,'t','\')
  1492. if dosisdir(workdata_dir)=0 then do
  1493.      call pmprintf('!! SRE-http Monitor WARNING: could not find workdata_dir: 'workdata_dir)
  1494.      workdata_dir=servdir
  1495. end
  1496.  
  1497. tempdata_dir=translate(tempdata_dir,'\','/')
  1498.    if length(tempdata_dir)>3 then tempdata_dir=strip(tempdata_dir,'t','\')
  1499. if dosisdir(tempdata_dir)=0 then do
  1500.      foo=tempdata_dir
  1501.      tempdata_dir=strip(translate(datadir(),'\','/'),'t','\')
  1502.      call pmprintf('!! SRE-http Monitor WARNING: could not find tempdata_dir: 'foo', (using 'tempdata_dir)
  1503. end
  1504.  
  1505.  
  1506. userinfo_dir=translate(userinfo_dir,'\','/')
  1507.    userinfo_dir=strip(userinfo_dir,'t','\')
  1508. if dosisdir(userinfo_dir)=0 then do
  1509.      call pmprintf('!! SRE-http Monitor WARNING: could not find userinfo_dir: 'userinfo_dir)
  1510.      userinfo_dir=tempdata_dir
  1511. end
  1512.  
  1513. tempfile_dir=translate(tempfile_dir,'\','/')
  1514.    tempfile_dir=strip(tempfile_dir,'t','\')
  1515. if dosisdir(tempfile_dir)=0 then do
  1516.      call pmprintf('!! SRE-http Monitor WARNING: could not find tempfile_dir: 'tempfile_dir)
  1517.      tempfile_dir=servdir
  1518. end
  1519.  
  1520. cgi_bin_dir=translate(cgi_bin_dir,'\','/')
  1521.    cgi_bin_dir=strip(cgi_bin_dir,'t','\')
  1522.    if cgi_bin_dir="" then cgi_bin_dir=0
  1523. if dosisdir(cgi_bin_dir)=0 then do
  1524.      call pmprintf('!! SRE-http Monitor WARNING: could not find cgi-bin-dir: 'cgi_bin_dir)
  1525.      cgi_bin_dir=' '
  1526. end  /* Do */
  1527.  
  1528.  
  1529. /* default addon_dir */
  1530. addon_dir=translate(addon_dir,'\','/')
  1531. addon_dir=strip(addon_dir,'t','\')
  1532. if addon_dir="" then addon_dir=0
  1533. if dosisdir(addon_dir)=0 then do
  1534.      call pmprintf('!! SRE-http Monitor WARNING: could not find addon-dir, 'addon_dir ', using : 'servdir)
  1535.      addon_dir=servdir
  1536. end  /* Do */
  1537.  
  1538.  
  1539. /* chek other stuff */
  1540.  
  1541. HOME_DIR=STRIP(HOME_DIR)
  1542. inhouse_privs=translate(inhouse_privs)
  1543.    if inhouse_privs=0 then inhouse_privs=" "
  1544. public_privs=translate(public_privs)
  1545.    if public_privs=0 then public_privs=" "
  1546. user_privs=translate(user_privs)
  1547.    if user_privs=0 then user_privs=" "
  1548.  
  1549.  
  1550. virtual_file=strip(virtual_file)
  1551.  
  1552. ALLOW_ACCESS=TRANSLATE(STRIP(ALLOW_ACCESS))
  1553. if allow_access="Y" | allow_access=1 then allow_access="YES"
  1554.  
  1555. do_Htaccess=is_true(do_htaccess,'Y YES 1')
  1556.  
  1557.  
  1558. ssi_cache_on=is_true(ssi_cache_on,'Y YES 1 ')
  1559.  
  1560. ssi_shtml_only=is_true(ssi_shtml_only,'Y YES 1')
  1561. DNS_CHECK=translate(dns_check)
  1562. if upload_log="" then upload_log=0
  1563. if datatype(upload_maxsize)<>'NUM' then
  1564.     upload_maxsize=50
  1565. if datatype(upload_minfree)<>'NUM' then
  1566.     upload_minfree=20000
  1567.  
  1568. if datatype(ssi_cache_size)<>'NUM' then
  1569.    ssi_cache_size=5000
  1570.  
  1571. if datatype(ssi_cache_duration)<>'NUM' then ssi_cache_duration=1
  1572. if ssi_cache_duration=0 then ssi_cache_duration=1000000 /* infiinte*/
  1573.  
  1574. if wordpos(ssi_cache_stamp,'TIME DATE TIMEDATE DATETIME SIZE ALL')=0 then
  1575.    ssi_cache_stamp='ALL'
  1576.  
  1577.  
  1578. pre_filter=translate(pre_filter)
  1579. post_filter=is_true(post_filter,'Y YES 1')
  1580.  
  1581. if smtp_gateway=" " then smtp_gateway=0
  1582.  
  1583. hit_owner_suppress=is_true(hit_owner_suppress,'Y YES 1')
  1584. hit_superuser_suppress=is_true(hit_superuser_suppress,'Y YES 1')
  1585.  
  1586. write_logs=is_true(write_logs,'Y YES 1')
  1587.  
  1588. if upper(hit_cache_len)="FILE" then do
  1589.    nop
  1590. end  /* Do */
  1591.  
  1592. else do
  1593.   if datatype(hit_cache_len)<>'NUM' then do 
  1594.      hit_cache_len=0
  1595.   end
  1596.   else do
  1597.     hit_cache_len=min(hit_cache_len,50)  /* 50 k max */
  1598.   end  /* Do */
  1599. end
  1600.  
  1601. if datatype(hit_cache_DURATION)<>'NUM' then do
  1602.      hit_cache_DURATION=15
  1603. END
  1604. ELSE DO
  1605.    HIT_cache_DURATION=MAX(1,HIT_cache_DURATION)
  1606. end  /* Do */
  1607.  
  1608.  
  1609. if the_realm=0 then do
  1610.   if  symbol('inhouse_name')<>"VAR"  then
  1611.         the_realm=inhouse_name
  1612.   else
  1613.        the_realm="OUR WEB SITE"           /* name we call "ourselves" */
  1614. end
  1615.  
  1616.  
  1617. RECORD_OPTION=TRANSLATE(RECORD_OPTION)
  1618. if wordpos(record_option,'YES YES_ALL FILE ')=0 then
  1619.      record_option="NO"              /* recording option on?*/
  1620.  
  1621. gots=0
  1622.  
  1623. hosts.0=0
  1624. do m=1 to 100000
  1625.    if symbol('hosts.m')<>"VAR" then leave
  1626.    if hosts.m=0 then leave
  1627.    hosts.0=m
  1628. end /* do */
  1629.  
  1630.  
  1631. /* add entries from cfgs/cfglist.cfg */
  1632.  
  1633. hostfile=cfglist_file
  1634. inj=stream(hostfile,'c','query size')
  1635. hstuff=''
  1636. if inj<>'' & inj<>0 then do
  1637.   foo=translate(stream(hostfile,'c','open read'))
  1638.   if abbrev(foo,'READY')<>1 then do
  1639.      call pmprintf('!! SRE-http Monitor WARNING: unable to read 'hostfile)
  1640.   end /* do */
  1641.   else do
  1642.      hstuff=charin(hostfile,1,inj)
  1643.      foo=stream(hostfile,'c','close')
  1644.   end
  1645. end /* do */
  1646. if hstuff<>'' then do           /* process the hostfile */
  1647.   crlf='0d0a'x
  1648.   hstuff=hstuff||crlf||' '
  1649.   defdata=strip(translate(datadir(),'\','/'),'t','\')
  1650.   ahost='' ; adata='' ; anickname=''
  1651.   ahitcount='' ; acounter_rxx='' ; asendfile='' ; arecordall=''
  1652.   do forever  
  1653.      if hstuff="" then leave
  1654.      parse var hstuff aline (crlf) hstuff
  1655.      aline=translate(strip(aline))
  1656.      if abbrev(aline,';')=1 then iterate
  1657.      if aline='' then do                /* end of block */
  1658.         if ahost<>'' & anickname<>'' then do
  1659.           if adata='' then adata=defdata
  1660.           alin2=ahost','anickname','adata','ahitcount','acounter_rxx','asendfile','arecordall
  1661.           ih=hosts.0+1
  1662.           hosts.ih=alin2
  1663.           hosts.0=ih
  1664.         end
  1665.         ahost='' ; anickname='' ; adata=''
  1666.         ahitcount='' ; acounter_rxx='' ; asendfile='' ; arecordall=''
  1667.         iterate
  1668.      end
  1669. /* else, process an entry */
  1670.      parse var  aline avar ':' avalue ; avar=strip(translate(avar)); avalue=strip(translate(avalue))
  1671.      select
  1672.         when abbrev(avar,'IP')=1 then ahost=avalue
  1673.         when abbrev(avar,'NICK')=1 | avar="HOST" then anickname=avalue
  1674.         when abbrev(avar,'DATA')=1 then adata=avalue
  1675.         when abbrev(avar,'SEND')=1 then do
  1676.           if pos(':',avalue)>0 then
  1677.              asendfile=avalue
  1678.           else
  1679.              call pmprintf("SRE-http Monitor: Ignoring: must use fully qualifed name ("avalue)
  1680.         end
  1681.         when abbrev(avar,'RECORD')=1 then do
  1682.           if pos(':',avalue)>0 then
  1683.              arecordall=avalue
  1684.          else
  1685.              call pmprintf("SRE-http Monitor: Ignoring: must use fully qualifed name ("avalue)
  1686.  
  1687.         end
  1688.         when abbrev(avar,'HIT')=1 then  do
  1689.           if pos(':',avalue)>0 then
  1690.             ahitcount=avalue
  1691.          else
  1692.              call pmprintf("SRE-http Monitor: Ignoring: must use fully qualifed name ("avalue)
  1693.  
  1694.         end
  1695.         when abbrev(avar,'COUNTER')=1 then do
  1696.           if pos(':',avalue)>0 then
  1697.             acounter_rxx=avalue
  1698.          else
  1699.              call pmprintf("SRE-http Monitor: Ignoring: must use fully qualifed name ("avalue)
  1700.  
  1701.         end
  1702.         otherwise nop
  1703.      end
  1704.   end                   /* forever scan */
  1705. end                     /* hstuff exsits */
  1706.         
  1707.  
  1708. ralphie=cvtails('DELIM_1',dlist)
  1709.  
  1710. delims=0
  1711. do m=1 to ralphie
  1712.  
  1713.    a1=dlist.m
  1714.    a2=translate(a1,' ','.')
  1715.    if words(a2)=1 then do
  1716.         if datatype(a1)='NUM' then do
  1717.            tmp1=DELIM_1.a1
  1718.            if tmp1='0' then iterate
  1719.            delims=max(delims,a1)
  1720.         end  /* Do */
  1721.     end  /* Do */
  1722.    if words(a2)=2 then do
  1723.         if datatype(word(a2,1))='NUM' then do
  1724.            ahost=word(a2,2)
  1725.            tmp1=DELIM_1.a1
  1726.            if tmp1='0' then iterate
  1727.            if symbol('DELIMS.'||ahost)='VAR' then
  1728.                 delims.ahost=max(delims.ahost,word(a2,1))
  1729.            else
  1730.                 delims.ahost=word(a2,1)
  1731.         end  /* Do */
  1732.     end  /* Do */
  1733. end
  1734.  
  1735.  
  1736.  
  1737. crlf='0d0a'x
  1738. FPO=MAKE_HEAD_FOOT()
  1739.  
  1740. /* creates HEADERS FOOTERS HEADERS. FOOTERS. HEADLIST. FOOTLIST. NHEADS NFOOTS */
  1741.  
  1742. auto_header=upper(auto_header)
  1743.  
  1744. suppress_alias=0 ; suppress_virtual=0 ; suppress_access=0
  1745. suppress_user=0 ; check_doq=0
  1746. if (alias_file=" " | alias_file=0)  then
  1747.         suppress_alias=1
  1748. if virtual_file=" " | virtual_file=0 then
  1749.         suppress_virtual=1
  1750. if (user_file=" " | user_file=0 ) then
  1751.         suppress_user=1
  1752. if access_file=" "| access_file=0  then
  1753.         suppress_access=1
  1754.  
  1755. if (suppress_alias+suppress_user+suppress_access+suppress_virtual+never_publicurls)>0 then
  1756.    check_doq=1
  1757.  
  1758. return 0
  1759.  
  1760.  
  1761. /* ------------------------------------------------- */
  1762. /* routine to set default initfilt.80  */
  1763. /* ------------------------------------------------- */
  1764. default_initfilt:
  1765.  
  1766. /* variables that can be changed by configure */
  1767.  
  1768. display_env=0
  1769. checklog='NO'           /* Free entry */
  1770. user_logon_enable=1     /* enable user of "user logon" procedure (if specified) */
  1771. the_realm=0           /* name we call "ourselves" , 0 will be replaced generically*/
  1772. home_name=" "              /* The colloquial (not necessrily ip) domain name */
  1773. auto_header="NO"        /* no, always, head */
  1774. AUTO_NAME=0         /* 0=none, or a list with *.HTM, !CREATE, file.nam */
  1775. CHECK_alias="YES"   /* : YES=yes, NO=None, HTML=.HTM (or .HTML)  */
  1776. not_found_url='<a href="/"> Visit the home_name home page? </a> '   /* Message that is sent with no such url  */
  1777. pre_filter="NO"         /* no  yes first */
  1778. post_filter="NO"
  1779. noext_type="HTM"  /* NONE DIR HTM or HTML REDIR */
  1780. record_option="NO"   /* YES, YES_ALL */
  1781. allow_access="YES"  /* access control on file transfers (YES=none) */
  1782. default='index.htm'     /* use if default home page selected */
  1783. add_privs_prefix='!'
  1784. inhouse_privs=" INHOUSE "    /* additional privs for inhouseips and owners */
  1785. public_privs=" PUBLIC "    /* additional privs for veryone */
  1786. user_privs=' USER '
  1787. inhouse.1=" (INHOUSE User) "   /* Used with REPLACE:INHOUSE1, etc. */
  1788. suPEruser.1="(Super User)"
  1789. replace_rules.0=0                /* no replace rules */
  1790. headers.1=0  /* stuff to put at beginning / end of */
  1791. footers.1=0  /* all htm documents. 0= nothing */
  1792. OPTION_hit_line=":: still access # "
  1793. webmaster=' (no contact available) '
  1794. owners   = 'none'  /* Owners are automatically superusers (seperate with spaces) */
  1795. inhouse_privs="INHOUSE"
  1796. smtp_gateway=" "    /* smtp_gateway, used by post-filter "e-mail alert" facility */
  1797.  
  1798. /* note: Directories and files  do NOT have defaults!*/
  1799.  
  1800. logon_fail_file=0
  1801. access_fail_file=0
  1802.  
  1803. htaccess_file=0
  1804. do_htaccess=0
  1805.  
  1806. accept_range="NO"
  1807. check_add_privs='NO'
  1808. use_stdout="YES"
  1809. add_user_name='YES'
  1810. add_resource_name='NO'
  1811.  
  1812. /* variables not changed by configure */
  1813. max_pointdist=50     /* max distance acceptable for a "assign to point" in ncsa map */
  1814. ssi_shtml_only='NO'    /* yes no, ssi on .sht or .shtml only */
  1815. ssi_cache_on='YES'    /* use ssi-caching (no, yes) */
  1816.  
  1817. fix_expire=0    /* set to non zero to redo response headers */
  1818. content_md5=0    /* add a content-md5 header */
  1819. no_include="NO"   /* yes no , disallow all ssi */
  1820. no_processing="NO"   /* if yes, then no server side processing allowed */
  1821. no_interpret_code='NO'
  1822. delim_1.1='<!--'     /* the left and right side "keyphrase" delimeters */
  1823. delim_2.1='-->'      /* can be any string combo */
  1824. upload_maxsize=50             /* max size that a uploaded file can be, in k */
  1825. upload_minfree=20000        /* minimum free in K, in dowload_dir, AFTER file upload */
  1826. postfilter_name="POSTFILT"
  1827. prefilter_name="PREFILTR"
  1828.  
  1829. interpret_types=' PL=PERL5 '  /* used by CGI-BIN to invoke alternate interpeters */
  1830.  
  1831. dir_exclusion='HTACCESS. /PRIVATE *.CNT '
  1832. DIR_OPTIONS='  notime auto_describe describe=describe.txt no_recurse_dir  '
  1833.  
  1834.  
  1835. dir_access=' PRIVATE/* SYSTEM* ' 
  1836. dir_access_privs='SUPERUSER '
  1837.  
  1838.  
  1839. check_doq=0
  1840. verbose=1
  1841.  
  1842. hit_cache_len=0        /* not on (otherwise, # of k) */
  1843. hit_cache_duration=15     /* # of minutes */
  1844. hit_cache=' '
  1845. hit_owner_suppress='YES'
  1846. write_logs='YES'
  1847.  
  1848.  
  1849. return 0
  1850.  
  1851.  
  1852. /* ----------------------------- */
  1853. /* save some initfilt varibles to the environment */
  1854. /* ----------------------------- */
  1855. save_envstuff:
  1856.  
  1857. ALIST='USER_LOGON_ENABLE CHECKLOG AUTO_HEADER VERBOSE DNS_CHECK ALLOW_ACCESS '
  1858. do mm=1 to words(alist)
  1859.   call save_em(word(alist,mm))
  1860. end
  1861. foo=value('SREF_VERBOSE',verbose,'os2environment')
  1862.  
  1863.  
  1864. call value enVadd||'SUPPRESS_ALIAS',suppress_alias,'os2environment'
  1865. call value enVadd||'NEVER_PUBLICURLS',never_publicurls,'os2environment'
  1866.  
  1867. call value 'SREF_DIGEST_AUTH',digest_auth,'os2environment'
  1868. call value 'SREF_SUPPRESS_GZIP_TE',suppress_gzip_te,'os2environment'
  1869. call value 'SREF_CE_GZIP',ce_gzip,'os2environment'
  1870.  
  1871. call value 'SREF_PROXY_CACHE',proxy_cache,'os2environment'
  1872.  
  1873. call value 'SREF_DYNSSI_MAXAGE',dynssi_maxage,'os2environment'
  1874.  
  1875. call value enVadd||'suppress_virtual',suppress_virtual,'os2environment'
  1876. call value enVadd||'suppress_access',suppress_access,'os2environment'
  1877. call value enVadd||'suppress_user',suppress_user,'os2environment'
  1878. call value enVadd||'CHECK_DOQ',CHECK_DOQ,'os2environment'
  1879. call value enVadd||'LOADTHRESHOLD',loadthreshold,'os2environment'
  1880. foo=value('SREF_KEY_PREFACE',key_preface,'os2environment')
  1881. call value enVadd||'BACKUPSERVERLIST',backupserverlist,'os2environment'
  1882. call value enVadd||'CGI_POST_LONG_GET',cgi_post_long_get,'os2environment'
  1883. call value enVadd||'GET_DECODE_OPTIONS',get_decode_options,'os2environment'
  1884.  
  1885. call value enVadd||'NO_NO_RECORD',no_no_record,'os2environment'
  1886. call value enVadd||'MESSAGE_SCRAMBLE',MESSAGE_SCRAMBLE,'os2environment'
  1887. CALL VALUE 'SREF_NO_REMOTE_CONFIG',NO_REMOTE_CONFIG,'OS2ENVIRONMENT'
  1888. call value enVadd||'SSI_EXTENSIONS',ssi_extensions,'os2environment'
  1889.  
  1890.  
  1891. ALIST='AUTO_NAME DEFAULT CHECK_ALIAS NOEXT_TYPE ADD_PRIVS_PREFIX INTERPRET_TYPES DIR_OPTIONS DIR_EXCLUSION DIR_ACCESS DIR_ACCESS_PRIVS'
  1892. do mm=1 to words(alist)
  1893.   call save_em(word(alist,mm))
  1894. end
  1895.  
  1896. ALIST='PRE_FILTER PREFILTER_NAME POST_FILTER POSTFILTER_NAME  '
  1897. do mm=1 to words(alist)
  1898.   call save_em(word(alist,mm))
  1899. end
  1900.  
  1901. call value envadd||'HEADERS',headers,'os2environment'
  1902. call value envadd||'FOOTERS',footers,'os2environment'
  1903.  
  1904. do mm=1 to nheads
  1905.    foo=strip(headlist.mm)
  1906.    aval0=aheaders.foo
  1907.    tty=strip(envadd||'HEADERS.'||foo)
  1908.    call value tty,aval0,'os2environment'
  1909. end /* do */
  1910. do mm=1 to nfoots
  1911.    foo=strip(footlist.mm)
  1912.    aval0=afooters.foo
  1913.    call value envadd||'FOOTERS.'||foo,aval0,'os2environment'
  1914. end /* do */
  1915.  
  1916. alist='THE_REALM HOME_NAME NOT_FOUND_URL USER_PRIVS PUBLIC_PRIVS INHOUSE_PRIVS OPTION_HIT_LINE LOGON_FAIL_FILE ACCESS_FAIL_FILE'
  1917. do mm=1 to words(alist)
  1918.   call save_em(word(alist,mm))
  1919. end
  1920.  
  1921. alist='WEBMASTER OWNERS SMTP_GATEWAY ACCEPT_RANGE USE_STDOUT ADD_USER_NAME ADD_RESOURCE_NAME '
  1922. do mm=1 to words(alist)
  1923.   call save_em(word(alist,mm))
  1924. end
  1925.  
  1926.  
  1927. call value envadd||'HOSTS.0',hosts.0,'os2environment'
  1928.  
  1929. select
  1930.    when wordpos(upper(content_md5),'1 Y YES')>0 then content_md5=1
  1931.    when wordpos(content_md5,'2 MD5.EXE')>0 then content_md5=2
  1932.    otherwise  content_md5=0
  1933. end
  1934.  
  1935. ALIST='MAX_POINTDIST NO_INCLUDE NO_INTERPRET_CODE NO_PROCESSING CONTENT_MD5 FIX_EXPIRE SSI_SHTML_ONLY CHECK_ADD_PRIVS SSI_CACHE_ON '
  1936. do mm=1 to words(alist)
  1937.   call save_em(word(alist,mm))
  1938. end
  1939.  
  1940. ALIST='UPLOAD_MINFREE UPLOAD_MAXSIZE HOME_DIR HIT_CACHE_LEN HIT_CACHE_DURATION HIT_CACHE WRITE_LOGS HIT_OWNER_SUPPRESS SSI_CACHE_SIZE SSI_CACHE_DURATION SSI_CACHE_STAMP '
  1941. do mm=1 to words(alist)
  1942.   call save_em(word(alist,mm))
  1943. end
  1944.  
  1945. call value envadd||'cgi_bin_dir',cgi_bin_dir,'os2environment'
  1946.  
  1947. /* call value envadd||'addon_dir',addon_dir,'os2environment' */
  1948. alist='ADDON_DIR'
  1949. do mm=1 to words(alist)
  1950.   call save_em(word(alist,mm))
  1951. end
  1952.  
  1953.  
  1954. tempfile_dir=upper(strip(tempfile_dir))
  1955. call value envadd||'tempfile_dir',tempfile_dir,'os2environment'
  1956.  
  1957. tempdata_dir=upper(strip(tempdata_dir))
  1958. call value envadd||'tempdata_dir',tempdata_dir,'os2environment'
  1959. call value 'sref_temp_data_dir',tempdata_dir,'os2environment'
  1960.  
  1961. userinfo_dir=upper(strip(userinfo_dir))
  1962. call value envadd||'userinfo_dir',userinfo_dir,'os2environment'
  1963.  
  1964.  
  1965. upload_dir=upper(strip(upload_dir))
  1966. call value envadd||'upload_dir',upload_dir,'os2environment'
  1967.  
  1968. messbox_dir=upper(strip(messbox_dir))
  1969. call value envadd||'messbox_dir',messbox_dir,'os2environment'
  1970.  
  1971. config_dir=upper(strip(config_dir))
  1972. call value envadd||'config_dir',config_dir,'os2environment'
  1973.  
  1974. workdata_dir=upper(strip(workdata_dir))
  1975. call value envadd||'workdata_dir',workdata_dir,'os2environment'
  1976.  
  1977.  
  1978. mailbox_dir=upper(strip(mailbox_dir))
  1979. call value envadd||'mailbox_dir',mailbox_dir,'os2environment'
  1980.  
  1981.  
  1982. call value envadd||'SERVDIR',servdir,'os2environment'
  1983. call value 'SREF_PREFIX',envadd,'os2environment'
  1984.  
  1985. call value envadd||'INITFILT_FILE',INIT_file,'os2environment'
  1986. call value envadd||'USER_FILE',user_file,'os2environment'
  1987. call value envadd||'ACCESS_FILE',access_file,'os2environment'
  1988. call value envadd||'VIRTUAL_FILE',virtual_file,'os2environment'
  1989. call value envadd||'ALIAS_FILE',alias_file,'os2environment'
  1990. call value envadd||'PUBURL_FILE',puburl_file,'os2environment'
  1991.  
  1992. call value envadd||'REPSTRGS_FILE',repstrgs_file,'os2environment'
  1993.  
  1994. call value envadd||'INTERPRET_FILE',interpret_file,'os2environment'
  1995. call value envadd||'SENDFILE_FILE',sendfile_file,'os2environment'
  1996.  
  1997.  
  1998. IF DACALL=0 then do
  1999.    call lineout error_log,' ==== The SRE-http error log. '||time('n')' 'date('n')
  2000.    call lineout error_log
  2001. end
  2002. ELSE  do
  2003.    if verbose>1 then do 
  2004.       call lineout error_log,' ==== (parameter reset '||time('n')' 'date('n')
  2005.       call lineout error_log
  2006.    end /* do */
  2007. end
  2008.  
  2009. if stream(error_log,'c','query exists')="" then do
  2010.     foo=pmprintf_sr(' SRE-http Monitor: could not initialize error log: 'error_log)
  2011.     error_log=''
  2012. end /* do */
  2013. else do
  2014.    foo=pmprintf_sr(" SRE-http Monitor: using error log: " error_log)
  2015.    xaa=stream(error_log,'c','query size')
  2016.    if xaa>100000 then foo=pmprintf_sr('!! SRE-http Monitor WARNING: error log file is getting large ('xaa' bytes)')
  2017. end /* do */
  2018. call value envadd||'ERROR_LOG',error_log,'os2environment'
  2019.  
  2020. call value envadd||'HTACCESS_FILE',htaccess_file,'os2environment'
  2021. call value envadd||'DO_HTACCESS',DO_htaccess,'os2environment'
  2022.  
  2023. /* create a HOST listing, stored in sref_value environment */
  2024. /*  IP_address,  host_nickname,  default_directory */
  2025. foo=pmprintf_sr(' SRE-http Monitor: looking up '||hosts.0||' HOST IP addresses')
  2026. hostlist=''
  2027.  
  2028. do m=1 to hosts.0
  2029.    aah=upper(hosts.m)
  2030.  
  2031.    parse upper var aah  sname ','  hn ',' adir ','ahitcount','acounter_rxx','asendfile','arecordall
  2032.    SNAME=STRIP(SNAME); adir=strip(adir)
  2033.    hostlist=hostlist' 'sname
  2034.    hn=upper(hn)
  2035.    adir=translate(strip(adir),'\','/'); adir=strip(adir,'t','\')||'\'
  2036.    tmp.m=sname','hn','adir
  2037.    tmp.m.!name=sname
  2038.    foo=sref_value('$HOSTS.'||sname,tmp.m,'USER',,serverport)
  2039.  
  2040.    fpp=value(envadd||'COUNTER_FILE.'||hn,ahitcount,'OS2ENVIRONMENT')
  2041.    fpp=value(envadd||'COUNTER_RXX_DIR.'||hn,acounter_rxx,'OS2ENVIRONMENT')
  2042.    fpp=value(envadd||'SENDFILE_FILE.'||hn,asendfile,'OS2ENVIRONMENT')
  2043.    fpp=value(envadd||'RECORD_ALL_FILE.'||hn,arecordall,'OS2ENVIRONMENT')
  2044.  
  2045.  
  2046. end
  2047.  
  2048. /*  -- HOSTS. ENTRIES MUST BE COMPLETE -- WE NO LONGER FILL IN
  2049.    PROBABLE VALUES 
  2050. do aa=1 to words(hostlist)   
  2051.    sname=tmp.aa.!name
  2052.    isnumip=verify(sname,'1234567890.')  
  2053.    if isnumip=0 then iterate  
  2054.    astat=sockgethostbyname(sname,'stuff.!')
  2055.    if astat<>1 then iterate      
  2056.    sname=stuff.!addr
  2057.    if wordpos(sname,hostlist)>0 then iterate 
  2058.    foo=sref_value('$HOSTS.'||sname,tmp.aa,'USER',,serverport)
  2059.    hostlist=hostlist' 'sname
  2060. end
  2061. */
  2062. foo=sref_value('$HOSTS.0',hostlist' ','USER',,serverport)
  2063.  
  2064. /* end of hosts. section */
  2065.  
  2066. call save_em('inhouseips.')
  2067. do m=1 to plist.0            /* fix and save INHOUSEIPS */
  2068.   t1=plist.m
  2069.   anval=inhouseips.t1
  2070.   w1=word(anval,1)   /* look for host nickname */
  2071.   if right(w1,2)='//' then do
  2072.        geti=2
  2073.   end
  2074.   else do
  2075.      geti=1
  2076.   end
  2077.   call value envadd||'inhouseips.'||t1,anval,'os2environment'
  2078. end
  2079.  
  2080. call save_em('unallowedips.')
  2081. isu=0
  2082. do m=1 to plist.0            /* fix and save unallowedIPS */
  2083.   t1=plist.m
  2084.   anval=unallowedips.t1
  2085.   w1=word(anval,1)   /* look for host nickname */
  2086.   if right(w1,2)='//' then do
  2087.        geti=2
  2088.   end
  2089.   else do
  2090.      geti=1
  2091.   end
  2092.   if verify(word(anval,geti),'1234567890.')<>0 then do  /* convert numeric ip */
  2093.       astat=sockgethostbyname(word(anval,geti),'stuff.!')
  2094.       if astat=1 then do
  2095.            if geti=1 then do
  2096.               parse var anval vv anval
  2097.               anval=stuff.!addr||' '||anval
  2098.             end
  2099.             else do
  2100.                parse var anval vv1 vv2  anval
  2101.                anval=vv1||' '||stuff.!addr||' '||anval
  2102.             end  /* Do */
  2103.       end  /* Do */
  2104.   end
  2105.   call value envadd||'unallowedips.'||t1,anval,'os2environment'
  2106.   if anval<>'' & anval<>0 then isu=1
  2107. end
  2108. if isu>0 then 
  2109.   call value envadd||'UNALLOWEDIPS',1,'os2environment'
  2110. else
  2111.   call value envadd||'UNALLOWEDIPS',0,'os2environment'
  2112.  
  2113.  
  2114. do m=1 to delims
  2115.   if symbol('DELIM_1.'||m)<>'VAR' then iterate
  2116.   call value envadd||'DELIM_1.'||m,delim_1.m,'os2environment'
  2117.   if symbol('DELIM_2.'||m)<>'VAR' then iterate
  2118.   call value envadd||'DELIM_2.'||m,delim_2.m,'os2environment'
  2119. end
  2120. call value envadd||'DELIMS',delims,'os2environment'
  2121.  
  2122. ralphie=cvtails('DELIMS',dlist)
  2123. do mm=1 to ralphie
  2124.    booboo=dlist.mm
  2125.    call value envadd||'DELIMS.'||booboo,delims.booboo,'os2environment'
  2126.    do m=1 to delims.booboo
  2127.     if symbol('DELIM_1.'||m||'.'||booboo)<>'VAR' then iterate
  2128.      call value envadd||'DELIM_1.'||m||'.'||booboo,delim_1.m.booboo,'os2environment'
  2129.     if symbol('DELIM_2.'||m||'.'||booboo)<>'VAR' then iterate
  2130.      call value envadd||'DELIM_2.'||m||'.'||booboo,delim_2.m.booboo,'os2environment'
  2131.    end
  2132. end /* do */
  2133.  
  2134.  
  2135. CALL SAVE_EM('SUPERUSER')
  2136. CALL SAVE_EM('INHOUSE')
  2137. call save_em('REPLACE_RULES')
  2138.  
  2139. foo=pmprintf_sr(' SRE-http Monitor: number of hosts= 'hosts.0 )
  2140. return 0
  2141.  
  2142.  
  2143. /* ----------------------------------------------------------------------- */
  2144. /* -- create temporary sel-specific-options file  -- */
  2145. /* ----------------------------------------------------------------------- */
  2146. make_DEFREALM_FILE_temp:
  2147.  
  2148. /* 
  2149. 1) parse defrealm file into an array of entries. Each entry (numbered 1...n)
  2150.    can have several fields. One of these MUST be a REALM, and one of these
  2151.    must be a RULE
  2152. 2) Fill in a  stem (using REALM as tails) using values from the above array
  2153. 3) Fill in missing values in each "REALM tail"  -- this means using
  2154.    higher order realms to fill in values for subrealms.
  2155. Values that can be filled are:
  2156.    REQUIRES and PERMISSIONS. 
  2157. REQUIRES can NOT be subrealm specific -- the same REQUIRES
  2158. must be used in all subrealms (or a realm).
  2159. */
  2160.  
  2161. blocks.='01'x
  2162. wasline='' ; nthblock=1
  2163. blocks.nthblock.!useit=1
  2164. blocks.0=0
  2165.  
  2166. if stream(defrealm_file_temp,'c','query exists')<>'' then do
  2167.   foo=sysfiledelete(DEFREALM_FILE_temp)  /* delete temporary defrealm_file */
  2168.   if foo<>0 then do  /* wait 15 seconds, try again */
  2169.      oy=syssleep(15)
  2170.      foo=sysfiledelete(DEFREALM_FILE_temp)   
  2171.      if foo<>0 then do  /* wait 15 seconds, try again */
  2172.         call pmprintf("!! SRE-http Monitor WARNING: ("foo") unable to delete "defrealm_file_temp)
  2173.        return 0   
  2174.      end 
  2175.   end
  2176. end
  2177. /* look for files */
  2178. foo=translate(stream(DEFREALM_FILE,'c','open read'))
  2179. if abbrev(foo,'READY')<>1 then do
  2180.   call pmprintf('SRE-http Monitor: ... unable to open 'DEFREALM_FILE ' ('foo)
  2181.   return 1            /* unable to open */
  2182. end
  2183. inj=stream(DEFREALM_FILE,'c','query size')
  2184. if inj=0 | inj='' then return   1        /* empty file */
  2185. astuff=charin(DEFREALM_FILE,1,inj)
  2186. foo=stream(DEFREALM_FILE,'c','close')
  2187. crlf='0d0a'x
  2188.  
  2189. /* add host/port specific files (from cfglist.cfg?) */
  2190. rr=add_attribs(serverport)
  2191. astuff=astuff||crlf||crlf||rr
  2192.  
  2193. astuff=astuff||crlf||' '        /* place an elephant in cairo */
  2194.  
  2195. /* look for entry blocks (each block is delimited by a blank line */
  2196. do forever
  2197.    if astuff='' then leave
  2198.    parse var astuff aline (crlf) astuff
  2199.    aline=strip(aline)
  2200.    if abbrev(aline,';')=1 then iterate   /* skip comment lines */
  2201.    if aline='' & wasline='' then iterate /* skip multiple blank lines */
  2202.  
  2203.    if aline=''  then do          /* first blank line signals end of entry*/
  2204.       foo=add_include_nthblock(nthblock)    /* "INCLUDE" (to astuff)? */
  2205.       if blocks.nthblock.!INCLUDE<>'01'x then do
  2206.            blocks.nthblock.!useit=0         /* don't use this block */
  2207.       end
  2208.       blocks.0=blocks.0+1  /* actual # of entries */
  2209.       nthblock=nthblock+1               /* initialize for next entry */
  2210.       blocks.nthblock.!useit=1
  2211.       wasline=''
  2212.       iterate
  2213.    end
  2214.    if pos(':',aline)>0 then
  2215.      parse var aline action ':' options
  2216.    else
  2217.       parse var aline action options 
  2218.    wasline=aline
  2219.    action=strip(translate(translate(action),' ',':='))
  2220.    options=strip(options)
  2221.    select
  2222.       when action='PORT' then do
  2223.         if options='' then options=80
  2224.         if options<>serverport then blocks.nthblock.!useit=0  /* this entry does not apply */
  2225.       end
  2226.       when action='REALM' then do
  2227.          if options='' then iterate
  2228.          parse var options drealm iscomplete 
  2229.          blocks.nthblock.!REALM=strip(translate(drealm))
  2230.          blocks.nthblock.!REALM.!C=strip(translate(iscomplete))
  2231.       end 
  2232.       when abbrev(action,'REPL')=1 then do 
  2233.           blocks.nthblock.!REPLACE=strip(translate(options))
  2234.       end 
  2235.       when abbrev(action,'WITH')=1 then do 
  2236.           blocks.nthblock.!RULES=options
  2237.       end 
  2238.  
  2239.       when abbrev(action,'USER')=1 then do 
  2240.           blocks.nthblock.!USER=strip(translate(options))
  2241.       end 
  2242.       when abbrev(action,'PWD')+abbrev(action,'PASS')>0 then do 
  2243.           blocks.nthblock.!RULES=strip(options)
  2244.       end 
  2245.       when abbrev(action,'PRIV')>0 then do 
  2246.           blocks.nthblock.!PRIVS=strip(options)
  2247.       end 
  2248.  
  2249.       when action='INCLUDE' then do
  2250.          if options='' then iterate
  2251.          blocks.nthblock.!INCLUDE=options
  2252.       end 
  2253.       when action='HOST' then do
  2254.           blocks.nthblock.!HOST=translate(options)
  2255.       end 
  2256.       when abbrev(action,'REQ')=1 then do 
  2257.           blocks.nthblock.!REQUIRES=translate(options)
  2258.       end 
  2259.       when abbrev(action,'PERM')=1 then do 
  2260.           blocks.nthblock.!permissions=translate(options)
  2261.       end 
  2262.       when abbrev(action,'RUL')=1 then do
  2263.         blocks.nthblock.!RULES=blocks.nthblock.!rules' 'options
  2264.       end
  2265.       when abbrev(action,'ADV')=1 then do
  2266.         blocks.nthblock.!ADVOPTS=options
  2267.       end /* do */
  2268.       when abbrev(action,'OPT')=1 then do
  2269.         blocks.nthblock.!OPTS=options' |#| 'blocks.nthblock.!opts 
  2270.       end /* do */
  2271.  
  2272.      when abbrev(action,'FAIL')=1 then do
  2273.         blocks.nthblock.!FAILURE=options
  2274.       end /* do */
  2275.      when abbrev(action,'LIMIT')=1 then do
  2276.         blocks.nthblock.!LIMITLIST=options
  2277.      end /* do */
  2278.  
  2279.       when wordpos(action,'REDIRECT  NEGOTIATE LITERAL ALIAS VIRTUAL MOVE TEMP MOVED TEMPMOVE PERMMOVE')>0 then do
  2280.          options2=translate(options,' ','=')
  2281.          parse var options2 a1  a2 
  2282.          if words(options2)=1 & translate(a1)<>'LITERAL' & translate(a1)<>'NEGOTIATE' then
  2283.              a2=a1  /* action=alias, etc */
  2284.          a1=strip(translate(a1))
  2285.          select   
  2286.            when action='ALIAS' then do
  2287.                blocks.nthblock.!RTYPE='ALIAS'
  2288.                blocks.nthblock.!DEST=options
  2289.            end /* do */
  2290.            when abbrev(a1,"SEL")+abbrev(a1,'INTERN')+abbrev(a1,'ALIAS')>0 then do
  2291.              blocks.nthblock.!RTYPE='ALIAS'
  2292.              blocks.nthblock.!DEST=a2
  2293.            end 
  2294.            when action="LITERAL"  then do
  2295.              blocks.nthblock.!RTYPE='LITERAL'
  2296.              blocks.nthblock.!DEST=options
  2297.            end
  2298.            when  a1="LITERAL" then do
  2299.              blocks.nthblock.!RTYPE='LITERAL'
  2300.              blocks.nthblock.!DEST=a2
  2301.            end
  2302.            when action="NEGOTIATE" then do
  2303.              blocks.nthblock.!RTYPE='NEGOTIATE'
  2304.              blocks.nthblock.!DEST=options
  2305.            end
  2306.            when a1="NEGOTIATE" then do
  2307.              blocks.nthblock.!RTYPE='NEGOTIATE'
  2308.              blocks.nthblock.!DEST=a2
  2309.            end
  2310.  
  2311.            when action="VIRTUAL" then do
  2312.              blocks.nthblock.!RTYPE='VIRTUAL'
  2313.              blocks.nthblock.!DEST=options
  2314.            end
  2315.            when a1="DIR" then do
  2316.              blocks.nthblock.!RTYPE='VIRTUAL'
  2317.              blocks.nthblock.!DEST=a2
  2318.            end 
  2319.            when abbrev(action,"MOVE")=1 then do
  2320.              blocks.nthblock.!RTYPE='PERM'
  2321.              blocks.nthblock.!DEST=options
  2322.            end
  2323.            when abbrev(a1,"PERM")+abbrev(a1,'MOVE')>0 then do
  2324.              blocks.nthblock.!RTYPE='PERM'
  2325.              blocks.nthblock.!DEST=a2
  2326.            end 
  2327.            when abbrev(action,"TEMP")=1 then do
  2328.               blocks.nthblock.!RTYPE='TEMP'
  2329.               blocks.nthblock.!DEST=options
  2330.            end
  2331.            when abbrev(a1,"TEMP")=1  then do
  2332.               blocks.nthblock.!RTYPE='TEMP'
  2333.               blocks.nthblock.!DEST=a2
  2334.            end 
  2335.            otherwise  do
  2336.              call pmprintf(' SRE-http Monitor: unsupported REDIRECT action = 'action ','options)
  2337.            end
  2338.          end               /* which kind of redirect */
  2339.       end               /* action=redirect */
  2340.       otherwise  do
  2341.             call pmprintf(' SRE-http Monitor: unsupported ATTRIBS action = 'action ','options)
  2342.       end
  2343.   end                /* action */
  2344.    
  2345. end             /* do forever */
  2346.  
  2347.  
  2348. if verbose>0 then call pmprintf(' SRE-http Monitor: # of ATTRIBS.CFG entries: 'blocks.0)
  2349.  
  2350. if blocks.0=0 then do /* create a stub file */
  2351.    call lineout defrealm_file_temp,'; Do NOT edit this transient "realm definitions" file (created: 'date('n')' 'time('n')
  2352.    call lineout defrealm_file_temp
  2353.    return 1     
  2354. end
  2355.  
  2356. /* clean up entries */
  2357. do nn=1 to blocks.0
  2358.    if blocks.nn.!useit=0 then iterate /* not for this port */
  2359.  
  2360.    if blocks.nn.!REPLACE<>'01'x then do
  2361.       blocks.nn.!realm='##REPLACE'
  2362.       iterate
  2363.    end
  2364.    if blocks.nn.!USER<>'01'x then do
  2365.       blocks.nn.!realm='##USER'
  2366.       iterate
  2367.    end
  2368.    if blocks.nn.!REALM='01'x then do
  2369.          call pmprintf(" SRE-http Monitor: ERROR missing REALM: in ATTRIBS block #"nn)
  2370.          blocks.nn.!useit=0    /* don't use this one */
  2371.          iterate
  2372.    end /* do */
  2373.  
  2374.    if blocks.nn.!RULES='01'x then do
  2375.          call pmprintf(" SRE-http Monitor: ERROR: missing RULE, PWD or WITH: in ATTRIBS block #"nn)
  2376.          blocks.nn.!useit=0    /* don't use this one */
  2377.          iterate
  2378.    end /* do */
  2379.  
  2380. /* create an idenfitying stem (using realm and host */
  2381.     trealm='!'||blocks.nn.!realm
  2382.     if blocks.nn.!host<>'01'x  & blocks.nn.!Host<>'' then do
  2383.             trealm=trealm||'.!!'||blocks.nn.!host
  2384.     end /* do */
  2385.  
  2386. /* is this a main realm -- if so, then check on REQUIRES: */
  2387.     if pos('.',blocks.nn.!realm)=0 then do
  2388.            if blocks.nn.!REQUIRES='01'x | blocks.nn.!requires='' then blocks.nn.!requires='*'
  2389.             blocks.nn.!ismain=1
  2390.      end
  2391.      blocks.nn.!stem=trealm
  2392. end
  2393.  
  2394. requires.='' ; permissions.=''
  2395.  
  2396.  
  2397. /* set REQUIRES. PERMISSIONS. stem arrays */
  2398. do nn=1 to blocks.0
  2399.    if blocks.nn.!useit=0 then iterate /* this entry not for this port, or missing info */
  2400.  
  2401. /* no realm for user and replace entries */
  2402.    if blocks.nn.!realm='##USER' | blocks.nn.!realm='##REPLACE' then iterate
  2403.  
  2404.    trealm=blocks.nn.!stem
  2405.    if blocks.nn.!ismain=1 then do        /* this is a main realm? then save requires */
  2406.        REQUIRES.trealm=blocks.nn.!requires
  2407.    end
  2408. /* save permissions (if they were set ) */
  2409.    if blocks.nn.!permissions<>'01'x then do
  2410.         permissions.trealm=blocks.nn.!permissions
  2411.    end /* do */
  2412.  
  2413. end
  2414.  
  2415.  
  2416. /* set the "requires" and "permissions" of subrealms */
  2417. do nn=1 to blocks.0
  2418.    if blocks.nn.!useit=0 then iterate
  2419.    if blocks.nn.!ismain=1 then iterate /* no super realms to check */
  2420.  
  2421. /* no requires or permissions for user and replace entries */
  2422.    if blocks.nn.!realm='##USER' | blocks.nn.!realm='##REPLACE' then iterate
  2423.  
  2424.    trealm=blocks.nn.!stem
  2425.    parse var trealm '!' arealm '.!!' ahost
  2426.    parse var arealm mrealm '.' .
  2427. /* fix up REQUIRES */
  2428.    mrealm2='!'||mrealm
  2429.    if ahost<>'' then mrealm2=mrealm2||'.!!'||ahost
  2430.  
  2431.  
  2432.    if requires.mrealm2='' & mrealm<>'PUBLIC' then do
  2433.          call pmprintf(" SRE-http Monitor: error: no main realm for subrealm: "arealm' ('mrealm2)
  2434.          blocks.nn.!useit=0
  2435.          iterate
  2436.     end
  2437.     blocks.nn.!requires=requires.mrealm2  /* subrealm MUST have main realm rules */
  2438.  
  2439.  
  2440. /* fill in with "superrealm's" PERMISSIONS, if need be */
  2441.    if permissions.trealm<>'' then iterate  /* explicit-- no need to fill in */
  2442.    do forever           /* look in higher "superealms" */
  2443.        iip=lastpos('.',arealm)
  2444.        if iip>0 then arealm=left(arealm,iip-1)
  2445.        urealm='!'||arealm
  2446.        if ahost<>'' then urealm=urealm||'.!!'||ahost
  2447.        if permissions.urealm<>'' then do
  2448.           blocks.nn.!permissions=permissions.urealm
  2449.          leave
  2450.        end
  2451.        if iip=0 then leave
  2452.    end
  2453.       
  2454. end
  2455.  
  2456. /* write results */
  2457. /* call pmprintf(' ---- writing to 'defrealm_file_temp)  */
  2458.  
  2459. call lineout defrealm_file_temp,'; Do NOT edit this transient "realm definitions" file (created: 'date('n')' 'time('n')
  2460.  
  2461. do mm=1 to blocks.0
  2462.  if blocks.mm.!useit=0 then iterate /* skip this block */
  2463.  
  2464.  ahost=strip(translate(blocks.mm.!Host,' ','01'x))
  2465.  arealm=translate(blocks.mm.!realm)
  2466.  parse upper var arealm mainrealm '.' .
  2467.  rulist=strip(translate(blocks.mm.!rules,' ','01'x))
  2468.  adest=translate(blocks.mm.!dest,' ','01'x)
  2469.  do ii=1 to words(rulist)
  2470.     arule=strip(word(rulist,ii))
  2471.  
  2472.     call lineout defrealm_file_temp,' '
  2473.     if wordpos(blocks.mm.!REALM.!C,'1 C COMPLETE')>0 then
  2474.       call lineout defrealm_file_temp,';C_REALM:' arealm ', rule='arule
  2475.     else
  2476.       call lineout defrealm_file_temp,';REALM:' arealm ', rule='arule
  2477.  
  2478.    if arealm='##REPLACE' then do
  2479.        if ahost<>'' then
  2480.           aline='REPLACE: 'blocks.mm.!replace||'.'||ahost||' '||blocks.mm.!rules
  2481.        else
  2482.           aline='REPLACE: 'blocks.mm.!replace' '||blocks.mm.!rules
  2483.  
  2484.       call lineout defrealm_file_temp,aline    
  2485.       leave             
  2486.     end
  2487.  
  2488.    if arealm='##USER' then do
  2489.        if ahost<>'' then
  2490.           aline='USER: '||ahost||'// 'blocks.mm.!user
  2491.        else
  2492.           aline='USER: '||blocks.mm.!user
  2493.        aline=aline||' 'blocks.mm.!rules 
  2494.        if blocks.mm.!privs<>'01'x then
  2495.           aline=aline||' 'blocks.mm.!privs
  2496.       call lineout defrealm_file_temp,aline    
  2497.       leave
  2498.     end
  2499.  
  2500. /* is this a public url? */
  2501.     if mainrealm='PUBLIC' then do
  2502.        if ahost<>'' then
  2503.           aline='PUBURLS: '||ahost||'// 'arule
  2504.        else
  2505.           aline='PUBURLS: 'arule
  2506.        select
  2507.              when blocks.mm.!rtype='LITERAL' & pos('NO_POSTFILTER',blocks.mm.!permissions)>0 then 
  2508.                    aat=' LITERAL_NORECORD  '||blocks.mm.!dest
  2509.              when blocks.mm.!rtype='LITERAL'  then 
  2510.                    aat=' LITERAL '||blocks.mm.!dest
  2511.              when pos('NO_POSTFILTER',blocks.mm.!permissions)>0 then 
  2512.                    aat=' NORECORD '
  2513.              otherwise
  2514.                   aat=''
  2515.        end
  2516.        call lineout defrealm_file_temp,aline||aat  
  2517.        if blocks.mm.!rtype='LITERAL' then blocks.mm.!rtype='' /* suppres below */
  2518.        blocks.mm.!requires='*'          /* force open access */
  2519.     end /* do */
  2520.  
  2521. /* generate an access.in entry */
  2522.     if ahost<>'' then
  2523.        aline='ACCESS: '||ahost||'// 'arule
  2524.     else
  2525.        aline='ACCESS: 'arule
  2526.     aline=aline' '||translate(blocks.mm.!requires,' ','01'x)
  2527.     aline=aline','||translate(blocks.mm.!permissions,' ','01'x)
  2528.     aline=aline','||mainrealm
  2529.     aline=aline','||translate(blocks.mm.!failure,' ','01'x)
  2530.     aline=aline','||translate(blocks.mm.!advopts,' ','01'x)
  2531.     aline=aline','||translate(blocks.mm.!opts,' ','01'x)
  2532.     call lineout defrealm_file_temp,aline    
  2533.  
  2534. /* generate a virtual ? */
  2535.    if blocks.mm.!RTYPE='VIRTUAL' then do
  2536.       jj=pos('*',arule)
  2537.       if jj>0 then
  2538.          isit=left(arule,jj-1)
  2539.       else
  2540.          isit=arule
  2541.  
  2542.       bb=strip(strip(translate(isit,'/','\')),'t','/')||'/'
  2543.  
  2544.       if ahost<>'' then
  2545.          aline='VIRTUAL: '||ahost||'// 'bb
  2546.       else
  2547.          aline='VIRTUAL: 'bb
  2548.       bb2=blocks.mm.!dest
  2549.       if abbrev(translate(bb2),'HTTP://')=0 then do
  2550.           bb2=translate(bb2)
  2551.           bb2=strip(translate(bb2,'\','/'))
  2552.          if right(bb2,1)<>'*' then bb2=strip(bb2,'t','\')||'\'
  2553.       end
  2554.       aline=aline' 'bb2' '||translate(blocks.mm.!limitlist,' ','01'x)
  2555.       call lineout defrealm_file_temp,aline    
  2556.    end     
  2557.  
  2558.  
  2559.    if blocks.mm.!RTYPE='ALIAS' then do
  2560.       if ahost<>'' then
  2561.          aline='ALIAS: '||ahost||'// 'ARULE
  2562.       else
  2563.          aline='ALIAS: 'ARULE
  2564.       aline=aline' 'blocks.mm.!dest
  2565.       call lineout defrealm_file_temp,aline    
  2566.    end     
  2567.  
  2568.    if blocks.mm.!RTYPE='LITERAL' then do   /* note : not done with public realm */
  2569.       if ahost<>'' then
  2570.          aline='ALIAS: '||ahost||'// 'ARULE
  2571.       else
  2572.          aline='ALIAS: 'ARULE
  2573.       aline=aline' !TRANSFER='||strip(blocks.mm.!dest)
  2574.       call lineout defrealm_file_temp,aline    
  2575.    end
  2576.  
  2577.    if blocks.mm.!RTYPE='NEGOTIATE' then do   
  2578.       if ahost<>'' then
  2579.          aline='ALIAS: '||ahost||'// 'ARULE
  2580.       else
  2581.          aline='ALIAS: 'ARULE
  2582.       aline=aline' !NEGOTIATE '||translate(blocks.mm.!dest,' ','01'x)
  2583.       call lineout defrealm_file_temp,aline    
  2584.    end
  2585.  
  2586.  
  2587.    if blocks.mm.!RTYPE='PERM' then do
  2588.       jj=pos('*',blocks.mm.!dest)
  2589.       if jj>0 then
  2590.          isit=left(arule,jj-1)
  2591.       else
  2592.          isit=arule
  2593.  
  2594.       if ahost<>'' then
  2595.          aline='ALIAS: '||ahost||'// 'ARULE
  2596.       else
  2597.          aline='ALIAS: 'ARULE
  2598.       aline=aline' !MOVED='||STRIP(blocks.mm.!dest)
  2599.       call lineout defrealm_file_temp,aline    
  2600.    end     
  2601.  
  2602.  
  2603.    if blocks.mm.!RTYPE='TEMP' then do
  2604.       jj=pos('*',blocks.mm.!dest)
  2605.       if jj>0 then
  2606.          isit=left(arule,jj-1)
  2607.       else
  2608.          isit=arule
  2609.  
  2610.       if ahost<>'' then
  2611.          aline='ALIAS: '||ahost||'// 'ARULE
  2612.       else
  2613.          aline='ALIAS: 'ARULE
  2614.       aline=aline' !TEMP='||STRIP(blocks.mm.!dest)
  2615.       call lineout defrealm_file_temp,aline    
  2616.    end     
  2617.   end         /* this rule */
  2618.  
  2619.   if verbose<3  then iterate /* don't write background info */
  2620.  
  2621. end
  2622. call lineout defrealm_file_temp
  2623.  
  2624. return 1
  2625.  
  2626.  
  2627. /***************/
  2628. /* add an INCLUDE: file to astuff? If so,
  2629. possibly reset all HOST and PORT actions */
  2630.  
  2631. add_include_nthblock:procedure expose blocks. astuff crlf cfgs_dir
  2632. parse arg nthb
  2633.  
  2634. if blocks.nthb.!INCLUDE='01'x then return 0        /* no INCLUDE */
  2635.  
  2636. ill=stream(blocks.nthb.!INCLUDE,'c','query size')
  2637. if ill=0 | ill='' then do  /* try looking in cfgsdir */
  2638.   baa=cfgs_dir'\'blocks.nthb.!include
  2639.   ill=stream(baa,'c','query size')
  2640.   if ill<>0 & ill<>'' then blocks.nthb.!include=baa
  2641. end /* do */
  2642.  
  2643. if ill=0 | ill='' then do
  2644.     call pmprintf('!! SRE-http Monitor WARNING: bad ATTRIBS INCLUDE = 'blocks.nthb.!include)
  2645.     return 0
  2646. end /* do */
  2647. foo=stream(blocks.nthb.!include,'c','open read')
  2648. if abbrev(translate(foo),'READY')<>1 then do
  2649.     call pmprintf('!! SRE-http Monitor WARNING: 'foo' ATTRIBS INCLUDE = 'blocks.nthb.!include)
  2650.     return 0
  2651. end
  2652. aget=charin(blocks.nthb.!include,1,ill)  /* read in the INCLUDE file */
  2653. foo=stream(blocks.nthb.!include,'c','close')
  2654. aget=aget||crlf
  2655.  
  2656. /* now parse it, adding a PORT and HOST to each entry, and removing
  2657. any existing PORT and HOST actions */
  2658. if verbose>1 then call pmprintf('SRE-http Monitor: including ATTRIBS file='blocks.nthb.!include) 
  2659. ngot=0
  2660. astuff=astuff||crlf||crlf
  2661. do forever
  2662.    if aget='' then return ngot
  2663.    parse var aget aline (crlf) aget
  2664.    aline=strip(aline);taline=translate(aline)
  2665.    if aline=';' then iterate  /* ignore comments */
  2666.  
  2667.    if abbrev(taline,'REALM')+abbrev(taline,'USER')+abbrev(taline,'REPL')>0 then do   /* all entries MUST have a REALM, USER or REPLACE */
  2668.       astuff=astuff||aline||crlf     /* WITH CURRENT HOST AND PORT */
  2669.       if blocks.nthb.!HOST<>'01'x then do
  2670.           astufF=astuff||'HOST: 'blocks.nthb.!host||crlf
  2671.       end
  2672.       if blocks.nthb.!PORT<>'01'x then do
  2673.           astufF=astuff||'PORT: 'blocks.nthb.!port||crlf
  2674.       end
  2675.       iterate
  2676.    end
  2677. /* suppress HOST and PORT -- always use this "blocks" host and port */
  2678.    if abbrev(taline,'HOST')+abbrev(taline,'PORT')>0 then iterate
  2679. /* else, add this line */
  2680.    astuff=astuff||aline||crlf
  2681. end
  2682.  
  2683.  
  2684. /* ----------------------------------------------------------------------- */
  2685. /* --  update mediatype temporary file */
  2686. /* ----------------------------------------------------------------------- */
  2687.  
  2688. chk_mediatyp:
  2689.  
  2690. if stream(mediatyp_file,'c','query exists')='' then do
  2691.    foo=' '
  2692.    aa=sysfiledelete(mediatyp_tfile)
  2693.    if aa<>0 then do
  2694.       call pmprintf(" SRE-http Monitor ERROR: could not delete MEDIATYP.TMP ("aa)
  2695.       return 0
  2696.    end /* do */
  2697.    afoo=charout(mediatyp_tfile,foo,1)
  2698.    afoo=stream(mediatyp_tfile,'c','close')
  2699.    call pmprintf('SRE-http Monitor: no mediatyp.rxx file ')
  2700.    return 0
  2701. end /* do */
  2702.  
  2703. /* else, a mediatype file. Process, converting new style entries to 
  2704. old style entries*/
  2705.  
  2706. jin=stream(mediatyp_file,'c','query size')
  2707. iin=charin(mediatyp_file,1,jin)
  2708. oo=stream(mediatyp_file,'c','close')
  2709. /* remove comments (between /* and */ */
  2710. iin0=''
  2711. do forever
  2712.    parse var iin a1 '/*' ac '*/' iin
  2713.    iin0=iin0' 'a1
  2714.    if iin='' then leave
  2715. end
  2716. /* Look for type= entries, and convert 'em */
  2717. iin1=''; crlf='0d0a'x
  2718. do forever
  2719.   parse var iin0 a1 (crlf) iin0
  2720.   isnew1=0
  2721.   parse upper var a1 fa1  .  /* check for bad syntax of new style entries */
  2722.   if abbrev(strip(fa1),'TYPE')=1 then do  /* this is a new style entry */
  2723.     isnew1=1
  2724.     if pos('=',a1)=0 then do 
  2725.      call pmprintf('!! SRE-http monitor WARNING: Ignoring bad mediatyp.rxx entry: 'a1)
  2726.      iterate
  2727.    end 
  2728.   end
  2729.   if isnew1=0 then do
  2730.       iin1=iin1||a1||'; '
  2731.   end
  2732.   else do               /* convert new style entry */
  2733.       parse  var a1 . '=' amtype . '=' extlist
  2734. /* host specific? */
  2735.       nohh=1
  2736.       if pos('.',fa1)>0 then do
  2737.          parse var fa1 . '.' bhost '=';bhost=translate(strip(bhost))
  2738.          iin1=iin1||' if translate(host_nickname)="'bhost'" then do ;' 
  2739.          nohh=0
  2740.       end /* do */
  2741.       extlist=translate(extlist,' ',','||'09'x)
  2742.       do forever
  2743.          parse upper var extlist aext extlist ; aext=strip(aext)
  2744.          iin1=iin1||"GARG='"||aext||"' ; KNOWN.GARG='"||amtype||"'; "
  2745.          if extlist='' then leave  /* done with this entry */
  2746.       end
  2747.       if nohh=0 then iin1=iin1||' ; end ;' 
  2748.   end
  2749.   if iin0='' then leave         /* done processing mediatyp file */
  2750. end
  2751. afoo=sysfiledelete(mediatyp_tfile)
  2752. afoo=charout(mediatyp_tfile,iin1,1)
  2753. afoo=stream(mediatyp_tfile,'c','close')
  2754. foo=pmprintf_sr(' SRE-http Monitor: updated MEDIATYP.RXX file ')
  2755.  
  2756. return 1
  2757.   
  2758.  
  2759. /* ----------------------------------------------------------------------- */
  2760. /* --  copy repstrgs file to environment */
  2761. /* ----------------------------------------------------------------------- */
  2762.  
  2763. chk_repstrgs:
  2764. parse arg resetit
  2765.  
  2766. if repstrgs_file=" " then
  2767.   return 0
  2768. oy=stream(repstrgs_file,'c','query exists')
  2769. if oy="" then do
  2770.    foo=pmprintf_sr("SRE-http Monitor: Replacement strings file not found, "|| get_file)
  2771.    return -1
  2772. end
  2773.  
  2774. /* yep, reinitialize repstrgs file (set semaphore first */
  2775. ause=sref_fileread(repstrgs_file,'filelines',,'E')
  2776.  
  2777. aa=add_auxillary('REPSTRGS','REPSTRGS.IN',serverport,0)
  2778.  
  2779. foo=add_defrealm_rep('REPLACE')
  2780.  
  2781. If (ause<=0) then  do               /*no such file,*/
  2782.       foo=pmprintf_sr("SRE-http Monitor: error " ause " when reading replacement strings file, "|| repstrgs_file)
  2783.       return -1
  2784. end
  2785.  
  2786. crlf='0d0a'x
  2787. j=0
  2788. /* zap current list of repstrings variables */
  2789. do rr=1 to repsvars.0
  2790.   call value repsvars.rr,' ','os2environment'
  2791. end
  2792. repsvars.0=0
  2793. do mm=1 to filelines.0
  2794.   goo=strip(filelines.mm)
  2795.   if goo="" | left(goo,1)=";" then  iterate
  2796.   parse var goo aname avalue
  2797.   aname=envadd||upper(aname)
  2798.   t1=value(aname,,'os2environment')
  2799.   if t1=' ' then do
  2800.       t1=avalue
  2801.       j=j+1
  2802.       repsvars.j=aname
  2803.       repsvars.0=j
  2804.   end
  2805.   else do
  2806.         t1=t1||crlf||avalue
  2807.   end
  2808.   call value aname,t1,'os2environment'
  2809. end
  2810. foo=pmprintf_sr(' SRE-http Monitor: loaded replacements strings: 'j)
  2811. return j
  2812.  
  2813.  
  2814. /* ----------------------------------------------------------------------- */
  2815. /* -- See if a "generic" YES answer. If so, return 1 */
  2816. /* ----------------------------------------------------------------------- */
  2817. is_true:procedure
  2818. parse upper arg ans,anslist
  2819. if wordpos(ans,anslist)>0 then
  2820.  return 1
  2821. else
  2822.  return 0
  2823.  
  2824.  
  2825.  
  2826. /*=========     Start various threads   ===================== */
  2827.  
  2828.  
  2829. /* ------------------------------------------------------------ */
  2830. /* start access processor thread */
  2831. start_access:
  2832. parse arg resetit
  2833.  
  2834. if access_file= ' ' | SUPPRESS_ACCESS=1 then
  2835.       return 0
  2836. oy=stream(access_file,'c','query exists')
  2837. if oy="" then do
  2838.    foo=pmprintf_sr("SRE-http Monitor: access file not found, "|| access_file)
  2839.    access_file=' '
  2840.    return -1
  2841. end
  2842.  
  2843. arxx=servdir||'\acceschk.rxx'
  2844. usequeue='SREF_'||serverport||'_ACCESS'
  2845. usesem='\SEM32\SREF_'||serverport||'_ACCESS'
  2846. badt=value('SREF_ACCESS_BAD',,'os2environment')
  2847.  
  2848. if  badt=1 | resetit=1 then do            /* already opened --just send a *RESET* */
  2849.    foo=eventsem_query(usesem)   /* is it still alive? */
  2850.    if foo<0 then do
  2851.        call pmprintf("SRE-http Monitor: relaunching access daemon (semaphore was:"foo)
  2852.    end /* do */
  2853.    else do   
  2854.       a=rxqueue('s',usequeue)
  2855.       push '1, 1, 2, *RESET* ' access_file
  2856.       return 1
  2857.    end                  /* otherwise, relaunch it */
  2858. end
  2859.  
  2860. /* if here, first time, or a relaunch */
  2861.  
  2862. a=rxqueue('d',usequeue)
  2863. a=rxqueue('c',usequeue)
  2864. if a<>usequeue then do
  2865.   bb=rxqueue('d',a)
  2866.   a=rxqueue('s',usequeue)
  2867.   do queued()
  2868.        pull
  2869.   end /* do */
  2870. end
  2871.  
  2872.  
  2873.  
  2874. a=eventsem_close(usesem)
  2875. A=EVENTSEM_CREATE(USESEM)
  2876. IF A<>0 then DO
  2877.     foo=pmprintf_sr(' SRE-http Monitor ERROR: creating access semaphore: 'A' 'usesem)
  2878.     access_file=' '
  2879.     return -1
  2880. end
  2881.  
  2882. badt=value('SREF_ACCESS_BAD',0,'os2environment')
  2883.  
  2884. access_tid=rexxthread('f',arxx,access_file,usequeue,USESEM,max_semwait,serverport)
  2885. if access_tid=0 then do
  2886.    foo=pmprintf_sr(' SRE-http Monitor: Could not open access thread 'arxx)
  2887.     access_file=' '
  2888.    return -1
  2889. end
  2890.  
  2891. return 1
  2892.  
  2893. /* ---------------- */
  2894. /* start alias processor thread */
  2895. start_alias:
  2896. parse arg resetit
  2897.  
  2898. if alias_file= ' ' | SUPPRESS_ALIAS=1 then
  2899.       return 0
  2900. oy=stream(alias_file,'c','query exists')
  2901.  
  2902. if oy="" then do
  2903.    foo=pmprintf_sr("SRE-http Monitor: alias file not found, "|| alias_file)
  2904.    alias_file=' '
  2905.    return -1
  2906. end
  2907.  
  2908. arxx=servdir||'\aliaschk.rxx'
  2909. usequeue='SREF_'||serverport||'_ALIAS'
  2910. usesem='\SEM32\SREF_'||serverport||'_ALIAS'
  2911. badt=value('SREF_ALIAS_BAD',,'os2environment')
  2912.  
  2913. if  badt=1 | resetit=1 then do            /* already opened --just send a *RESET* */
  2914.    foo=eventsem_query(usesem)   /* is it still alive? */
  2915.    if foo<0 then do
  2916.        call pmprintf("SRE-http Monitor: relaunching aliases daemon (semaphore was:"foo)
  2917.    end /* do */
  2918.    else do   
  2919.       a=rxqueue('s',usequeue)
  2920.       push '1,1,2,*RESET* ' alias_file
  2921.       foo=eventsem_post(usesem)
  2922.       return 1
  2923.    end
  2924. end
  2925.  
  2926. /* if here, first time */
  2927.  
  2928. a=rxqueue('d',usequeue)
  2929. a=rxqueue('c',usequeue)
  2930. if a<>usequeue then do
  2931.   bb=rxqueue('d',a)
  2932.   a=rxqueue('s',usequeue)
  2933.   do queued()
  2934.        pull
  2935.   end /* do */
  2936. end
  2937.  
  2938. a=eventsem_close(usesem)
  2939. A=EVENTSEM_CREATE(USESEM)
  2940. IF A<>0 then DO
  2941.     foo=pmprintf_sr(' SRE-http Monitor ERROR: creating alias semaphore: 'A' 'usesem)
  2942.     return 0
  2943. end
  2944.  
  2945. badt=value('SREF_ALIAS_BAD',0,'os2environment')
  2946.  
  2947.  
  2948. alias_tid=rexxthread('f',arxx,alias_file,usequeue,USESEM,max_semwait,serverport)
  2949. if alias_tid=0 then do
  2950.    foo=pmprintf_sr(' SRE-http Monitor: Could not open alias thread 'arxx)
  2951.    return 0
  2952. end
  2953.  
  2954. return 1
  2955.  
  2956.  
  2957. /* ---------------- */
  2958. /* start public-urls processor thread */
  2959. start_puburl:
  2960. parse arg resetit
  2961.  
  2962. if puburl_file= ' ' | never_publicurls=1 then do
  2963.     puburl_file=''
  2964.     call value envadd||'PUBURL_FILE',puburl_file,'os2environment'
  2965.    return 0
  2966. end /* do */
  2967.  
  2968. oy=stream(puburl_file,'c','query exists')
  2969. if oy="" then do
  2970.    foo=pmprintf_sr("!! SRE-http Monitor WARNING: public urls file not found, "|| puburl_file)
  2971.    puburl_file=' '
  2972.    call value envadd||'PUBURL_FILE',puburl_file,'os2environment'
  2973.    return -1
  2974. end
  2975.  
  2976. arxx=servdir||'\puburchk.rxx'
  2977. usequeue='SREF_'||serverport||'_PUBURL'
  2978. usesem='\SEM32\SREF_'||serverport||'_PUBURL'
  2979. badt=value('SREF_PUBURL_BAD',,'os2environment')
  2980.  
  2981.  
  2982. if  badt=1 | resetit=1 then do            /* already opened --just send a *RESET* */
  2983.    foo=eventsem_query(usesem)   /* is it still alive? */
  2984.    if foo<0 then do
  2985.        call pmprintf("SRE-http Monitor: relaunching puburls daemon (semaphore was:"foo)
  2986.    end /* do */
  2987.    else do   
  2988.       a=rxqueue('s',usequeue)
  2989.       push '1,1,2,*RESET* ' puburl_file
  2990.       foo=eventsem_post(usesem)
  2991.       return 1
  2992.    end
  2993. end
  2994.  
  2995. /* if here, first time */
  2996.  
  2997. a=rxqueue('d',usequeue)
  2998. a=rxqueue('c',usequeue)
  2999. if a<>usequeue then do
  3000.   bb=rxqueue('d',a)
  3001.   a=rxqueue('s',usequeue)
  3002.   do queued()
  3003.        pull
  3004.   end /* do */
  3005. end
  3006.  
  3007.  
  3008. a=eventsem_close(usesem)
  3009. A=EVENTSEM_CREATE(USESEM)
  3010. IF A<>0 then DO
  3011.     foo=pmprintf_sr(' SRE-http Monitor ERROR: creating puburl semaphore: 'A' 'usesem)
  3012.     return 0
  3013. end
  3014.  
  3015. badt=value('SREF_PUBURL_BAD',0,'os2environment')
  3016.  
  3017.  
  3018. puburl_tid=rexxthread('f',arxx,puburl_file,usequeue,USESEM,max_semwait,serverport)
  3019. if puburl_tid=0 then do
  3020.    foo=pmprintf_sr(' SRE-http Monitor: Could not open puburl thread 'arxx)
  3021.    return 0
  3022. end
  3023.  
  3024. return 1
  3025.  
  3026.  
  3027.  
  3028. /* ---------------- */
  3029. /* start virtual dir processor thread */
  3030. start_virtual:
  3031. parse arg resetit
  3032.  
  3033. IF VIRTUAL_FILE="" | SUPPRESS_VIRTUAL=1 then RETURN 0
  3034.  
  3035. dlistx=upload_dir||' '||cgi_bin_dir||'  '||addon_dir||' '
  3036. dlistx=dlistx||translate(datadir(),'\','/')
  3037.  
  3038. arxx=servdir||'\virtchk.rxx'
  3039. usequeue='SREF_'||serverport||'_VIRTUAL'
  3040. usesem='\SEM32\SREF_'||serverport||'_VIRTUAL'
  3041. badt=value('SREF_VIRTUAL_BAD',,'os2environment')
  3042.  
  3043. if  badt=1 |  resetit=1 then do            /* already opened --just send a *RESET* */
  3044.    foo=eventsem_query(usesem)   /* is it still alive? */
  3045.    if foo<0 then do
  3046.        call pmprintf("SRE-http Monitor: relaunching virtual_Dir daemon (semaphore was:"foo)
  3047.    end /* do */
  3048.    else do   
  3049.       a=rxqueue('s',usequeue)
  3050.       push '1,1,2, *RESET* ' virtual_file
  3051.       foo=eventsem_post(usesem)
  3052.       return 1
  3053.    end
  3054. end
  3055.  
  3056. if virtual_file= ' ' then
  3057.       return 0
  3058. oy=stream(virtual_file,'c','query exists')
  3059. if oy="" then do
  3060.    foo=pmprintf_sr("SRE-http Monitor: virtual file not found, "|| virtual_file)
  3061.    virtual_file=' '
  3062.    return 0
  3063. end
  3064.  
  3065. /* if here, first time */
  3066.  
  3067. a=rxqueue('d',usequeue)
  3068. a=rxqueue('c',usequeue)
  3069. if a<>usequeue then do
  3070.   bb=rxqueue('d',a)
  3071.   a=rxqueue('s',usequeue)
  3072.   do queued()
  3073.        pull
  3074.   end /* do */
  3075. end
  3076.  
  3077. a=eventsem_close(usesem)
  3078. A=EVENTSEM_CREATE(USESEM)
  3079. IF A<>0 then DO
  3080.     foo=pmprintf_sr(' SRE-http Monitor ERROR: creating virtual semaphore: 'A' 'usesem)
  3081.     return 0
  3082. end
  3083.  
  3084. badt=value('SREF_VIRTUAL_BAD',0,'os2environment')
  3085.  
  3086.  
  3087. mm1=max_semwait
  3088. virtual_tid=rexxthread('f',arxx,virtual_file||' '||dlistx,usequeue,USESEM,mm1,serverport)
  3089. if virtual_tid=0 then do
  3090.    foo=pmprintf_sr(' SRE-http Monitor:Could not open virtual thread 'arxx)
  3091.    return 0
  3092. end
  3093.  
  3094. return 1
  3095.  
  3096.  
  3097.  
  3098. /* ---------------- */
  3099. /* start variable storage thread */
  3100. start_varstore:
  3101. parse arg addme
  3102.  
  3103. arxx=servdir||'\varstore.rxx'
  3104. usequeue='SREF_'||serverport||'_VARSTORE'||addme
  3105. usesem='\SEM32\SREF_'||serverport||'_VARSTORE'||addme
  3106. a=rxqueue('d',usequeue)
  3107. a=rxqueue('c',usequeue)
  3108. if a<>usequeue then do
  3109.   bb=rxqueue('d',a)
  3110.   a=rxqueue('s',usequeue)
  3111.   do queued()
  3112.        pull
  3113.   end /* do */
  3114. end
  3115.  
  3116. a=eventsem_close(usesem)
  3117. A=EVENTSEM_CREATE(USESEM)
  3118. IF A<>0 then DO
  3119.     call pmprintf(' SRE-http Monitor ERROR: creating variable storage semaphore:'usesem)
  3120.     return 0
  3121. end
  3122. mm1=max_semwait
  3123. v_tid=rexxthread('f',arxx,usequeue,USESEM,mm1,serverport,x_limitclients)
  3124. if v_tid=0 then do
  3125.    call pmprintf(' SRE-http Monitor:Could not start variable storage thread 'arxx)
  3126.    return 0
  3127. end
  3128.  
  3129. return 1
  3130.  
  3131.  
  3132.  
  3133.  
  3134. /* ---------------- */
  3135. /* start superceding realm  thread */
  3136. start_srealm:
  3137. parse arg resetit
  3138.  
  3139. if no_superceding_realm=1 then return 0
  3140.  
  3141. arxx=servdir||'\srealm.rxx'
  3142. usequeue='SREF_'||serverport||'_SREALM'
  3143. usesem='\SEM32\SREF_'||serverport||'_SREALM'
  3144. badt=value('SREF_SREALM_BAD',,'os2environment')
  3145.  
  3146. if  badt=1 |  resetit=1 then do            /* already opened --just send a *RESET* */
  3147.    foo=eventsem_query(usesem)   /* is it still alive? */
  3148.    if foo<0 then do
  3149.        call pmprintf("SRE-http Monitor: relaunching superceding_realms daemon (semaphore was:"foo)
  3150.    end /* do */
  3151.    else do   
  3152.       a=rxqueue('s',usequeue)
  3153.       push '1,1,2, *RESET* ' 
  3154.       foo=eventsem_post(usesem)
  3155.       return 1
  3156.    end
  3157. end
  3158.  
  3159.  
  3160. a=rxqueue('d',usequeue)
  3161. a=rxqueue('c',usequeue)
  3162. if a<>usequeue then do
  3163.   bb=rxqueue('d',a)
  3164.   a=rxqueue('s',usequeue)
  3165.   do queued()
  3166.        pull
  3167.   end /* do */
  3168. end
  3169.  
  3170. a=eventsem_close(usesem)
  3171. A=EVENTSEM_CREATE(USESEM)
  3172. IF A<>0 then DO
  3173.     foo=pmprintf_sr(' SRE-http Monitor ERROR: creating superceding realm semaphore:'usesem)
  3174.     return 0
  3175. end
  3176. mm1=max_semwait
  3177.  
  3178. badt=value('SREF_SREALM_BAD',0,'os2environment')
  3179.  
  3180.  
  3181. ssicache_tid=rexxthread('f',arxx,defrealm_file_temp,usequeue,USESEM,mm1,serverport)
  3182. if ssicache_tid=0 then do
  3183.    foo=pmprintf_sr(' SRE-http Monitor:Could not open superceding realm thread 'arxx)
  3184.    return 0
  3185. end
  3186.  
  3187. return 1
  3188.  
  3189.  
  3190.  
  3191.  
  3192.  
  3193. /* ---------------- */
  3194. /* start virtual dir processor thread */
  3195. start_ssicache:
  3196. if ssi_cache_size="" then return 0
  3197.  
  3198. arxx=servdir||'\ssicache.rxx'
  3199. usequeue='SREF_'||serverport||'_SSICACHE'
  3200. usesem='\SEM32\SREF_'||serverport||'_SSICACHE'
  3201.  
  3202.  
  3203. a=rxqueue('d',usequeue)
  3204. a=rxqueue('c',usequeue)
  3205. if a<>usequeue then do
  3206.   bb=rxqueue('d',a)
  3207.   a=rxqueue('s',usequeue)
  3208.   do queued()
  3209.        pull
  3210.   end /* do */
  3211. end
  3212.  
  3213. a=eventsem_close(usesem)
  3214. A=EVENTSEM_CREATE(USESEM)
  3215. IF A<>0 then DO
  3216.     foo=pmprintf_sr(' SRE-http Monitor ERROR: creating ssi-cache semaphore:'usesem)
  3217.     return 0
  3218. end
  3219. mm1=max_semwait
  3220. ssicache_tid=rexxthread('f',arxx,tempdata_dir,usequeue,USESEM,mm1,serverport,ssi_cache_size,ssi_cache_duration,ssi_cache_stamp,serverport)
  3221. if ssicache_tid=0 then do
  3222.    foo=pmprintf_sr(' SRE-http Monitor:Could not open ssi-cache thread 'arxx)
  3223.    return 0
  3224. end
  3225.  
  3226. return 1
  3227.  
  3228.  
  3229.  
  3230. /* ---------------- */
  3231. /* start virtual dir processor thread */
  3232. start_sreproxy:
  3233. parse arg resetit
  3234.  
  3235. oo=value('SREF_PROXY',,'os2environment')
  3236. if oo='' | oo=0 then return 0
  3237.  
  3238. arxx=servdir||'\sreproxy.rxx'
  3239. afilter=servdir||'\SREFILTR.'||serverport
  3240. usequeue='SREF_SREPROXY'
  3241. usesem='\SEM32\SREF_SREPROXY'
  3242. badt=value('SREF_SREPROXY_BAD',,'os2environment')
  3243.  
  3244. if  badt=1 | resetit=1 then do            /* already opened --just send a *RESET* */
  3245.    foo=eventsem_query(usesem)   /* is it still alive? */
  3246.    if foo<0 then do
  3247.        call pmprintf("SRE-http Monitor: relaunching SRE_Proxy daemon (semaphore was:"foo)
  3248.    end /* do */
  3249.    else do   
  3250.       a=rxqueue('s',usequeue)
  3251.       push '1,1,2,RESET'
  3252.       foo=eventsem_post(usesem)
  3253.       return 1
  3254.    end
  3255. end
  3256.  
  3257. a=rxqueue('d',usequeue)
  3258. a=rxqueue('c',usequeue)
  3259. if a<>usequeue then do
  3260.   bb=rxqueue('d',a)
  3261.   a=rxqueue('s',usequeue)
  3262.   do queued()
  3263.        pull
  3264.   end /* do */
  3265. end
  3266.  
  3267. a=eventsem_close(usesem)
  3268. A=EVENTSEM_CREATE(USESEM)
  3269. IF A<>0 then DO
  3270.     foo=pmprintf_sr(' SRE-http Monitor ERROR: creating sreproxy:'usesem)
  3271.     return -1
  3272. end
  3273.  
  3274. badt=value('SREF_SREPROXY_BAD',0,'os2environment')
  3275.  
  3276.  
  3277. mm1=max_semwait
  3278. sreproxy_tid=rexxthread('f',arxx,tempdata_dir,usequeue,USESEM,mm1,serverport,afilter)
  3279. if sreproxy_tid=0 then do
  3280.    foo=pmprintf_sr(' SRE-http Monitor: Could not open sre-proxy thread 'arxx)
  3281.    return -1
  3282. end
  3283.  
  3284. return 1
  3285.  
  3286.  
  3287. /* ---------------- */
  3288. /* start user check processor thread */
  3289. start_user:
  3290. parse arg resetit
  3291. if user_file= ' ' | SUPPRESS_USER=1 then
  3292.       return 0
  3293.  
  3294. oy=stream(user_File,'c','query exists')
  3295. if oy="" then do
  3296.    foo=pmprintf_sr("SRE-http Monitor: userl file not found, "||user_file)
  3297.     user_file=' '
  3298.    return -1
  3299. end
  3300.  
  3301. arxx=servdir||'\userchk.rxx'
  3302. usequeue='SREF_'||serverport||'_USER'
  3303. usesem='\SEM32\SREF_'||serverport||'_USER'
  3304. badt=value('SREF_USER_BAD',,'os2environment')
  3305.  
  3306. if badt=1 | resetit=1 then do            /* already opened --just send a *RESET* */
  3307.    foo=eventsem_query(usesem)   /* is it still alive? */
  3308.    if badt=1 |  foo<0 then do
  3309.        call pmprintf("SRE-http Monitor: relaunching users daemon (semaphore was:"foo)
  3310.    end /* do */
  3311.    else do   
  3312.       a=rxqueue('s',usequeue)
  3313.       push '1,1,2, *RESET* ' user_File
  3314.       foo=eventsem_post(usesem)
  3315.       return 1
  3316.    end
  3317. end
  3318.  
  3319. /* if here, first time */
  3320. a=rxqueue('d',usequeue)
  3321. a=rxqueue('c',usequeue)
  3322. if a<>usequeue then do
  3323.   bb=rxqueue('d',a)
  3324.   a=rxqueue('s',usequeue)
  3325.   do queued()
  3326.        pull
  3327.   end /* do */
  3328. end
  3329.  
  3330. a=eventsem_close(usesem)
  3331. A=EVENTSEM_CREATE(USESEM)
  3332. IF A<>0 then DO
  3333.      if a=285  then do
  3334.         foo=pmprintf_sr('!! SRE-http Monitor WARNING:  user semaphore exists: 'A' 'usesem)
  3335.      end /* do */
  3336.      else do
  3337.          foo=pmprintf_sr('!! SRE-http Monitor ERROR: creating user semaphore: 'A' 'usesem)
  3338.           return 0
  3339.      end
  3340. end
  3341.  
  3342. badt=value('SREF_USER_BAD',0,'os2environment')
  3343.  
  3344. user_tid=rexxthread('f',arxx,user_file,usequeue,USESEM,max_semwait,logon_limit,serverport)
  3345. if user_tid=0 then do
  3346.    foo=pmprintf_sr(' SRE-http Monitor:Could not open user thread 'arxx)
  3347.    return 0
  3348. end
  3349.  
  3350.  
  3351. return 1
  3352.  
  3353.  
  3354. /* ---------------- */
  3355. /* start postfilter / recordall processor thread */
  3356. start_postf:
  3357. parse arg resetit
  3358.  
  3359. arxx=servdir||'\postfchk.rxx'
  3360. usequeue='SREF_'||serverport||'_POSTF'
  3361. usesem='\SEM32\SREF_'||serverport||'_POSTF'
  3362. badt=value('SREF_POSTF_BAD',,'os2environment')
  3363.  
  3364. if  badt=1 | resetit=1 then do                /* check that everything is okay */
  3365.    foo=eventsem_query(usesem)   /* is it still alive? */
  3366.    if foo<0 then do
  3367.        call pmprintf("SRE-http Monitor: relaunching postfilter daemon (semaphore was:"foo)
  3368.    end /* do */
  3369.    else do
  3370.      return 0             /* otherwise, it's okay */ 
  3371.    end
  3372. end /* do */
  3373.  
  3374.  
  3375. a=rxqueue('d',usequeue)
  3376. a=rxqueue('c',usequeue)
  3377. if a<>usequeue then do
  3378.   bb=rxqueue('d',a)
  3379.   a=rxqueue('s',usequeue)
  3380.   do queued()
  3381.        pull
  3382.   end /* do */
  3383. end
  3384.  
  3385.  
  3386. a=eventsem_close(usesem)
  3387. A=EVENTSEM_CREATE(USESEM)
  3388. IF A<>0 then DO
  3389.     foo=pmprintf_sr('SRE-http Monitor ERROR: creating postfilter semaphore: 'A' 'usesem)
  3390.     return 0
  3391. end
  3392.  
  3393. badt=value('SREF_POSTF_BAD',0,'os2environment')
  3394.  
  3395. mm1=max_semwait*1.5
  3396. postf_tid=rexxthread('f',arxx,usequeue,USESEM,thesem,mm1,record_cache_lines' 'workdata_dir,serverport,logfile_maxsize)
  3397. if postf_tid=0 then do
  3398.    foo=pmprintf_sr(' SRE-http Monitor:Could not open postfilter thread 'arxx)
  3399.    return 0
  3400. end
  3401.  
  3402. return 1
  3403.  
  3404.  
  3405.  
  3406. /* ----  */
  3407. /* make headers and footers, host specific possibly */
  3408. make_head_foot:procedure expose aheaders. afooters. headlist. footlist. ,
  3409.         headers footers  nheads nfoots headers. footers. serverport
  3410.  
  3411. foo=cvtails('headers.','b')
  3412. if b.0>0 then joe=arraysort('b')
  3413. crlf=' '
  3414. headers=' ' ; nheads=0 ; HDDONE=0
  3415. do mm=1 to b.0
  3416.     a1=b.mm
  3417.     a2=headers.a1
  3418.     if a2=" " then a2=0
  3419.     IF A2=0 then HDDONE=1
  3420.     if pos('.',a1)=0  then do
  3421.        if HDDONE=0 then  headers=headers||a2||crlf
  3422.     end  /* Do */
  3423.     else do             /* headers.hn */
  3424.        parse var a1 aval '.' ahost ; ahost=strip(ahost) ; aval=strip(aval)
  3425.        if strip(a2)=0 then do
  3426.              headstops.ahost=1
  3427.        end  /* Do */
  3428.        else do          /* not a stop */
  3429.          if aval=1 then  do
  3430.              nheads=nheads+1
  3431.               headlist.nheads=ahost
  3432.               aheaders.ahost=a2||crlf
  3433.              headstops.ahost=0
  3434.          end
  3435.          else do
  3436.            if headstops.ahost<>1 then
  3437.               aheaders.ahost=aheaders.ahost||a2||crlf
  3438.          end
  3439.        end              /* headstop */
  3440.     end                 /* .hn */
  3441. end
  3442. foo=cvtails('footers.','b')
  3443. if b.0>0 then joe=arraysort('b')
  3444. footers=' ' ; nfoots=0 ; FTDONE=0
  3445. do mm=1 to b.0
  3446.     a1=b.mm
  3447.     a2=footers.a1
  3448.     if a2=" " then a2=0
  3449.     IF A2=0 then FTDONE=1
  3450.     if pos('.',a1)=0  then do
  3451.        if FTDONE=0 then footers=footers||a2||crlf
  3452.     end  /* Do */
  3453.     else do             /* footers.hn */
  3454.        parse var a1 aval '.' ahost ; ahost=strip(ahost) ; aval=strip(aval)
  3455.        if strip(a2)=0 then do
  3456.              footstops.ahost=1
  3457.        end  /* Do */
  3458.        else do          /* not a stop */
  3459.          if aval=1 then  do
  3460.              nfoots=nfoots+1
  3461.               footlist.nfoots=ahost
  3462.               afooters.ahost=a2||crlf
  3463.              footstops.ahost=0
  3464.          end
  3465.          else do
  3466.            if footstops.ahost<>1 then
  3467.               afooters.ahost=afooters.ahost||a2||crlf
  3468.          end
  3469.        end              /* footstop */
  3470.     end                 /* .hn */
  3471. end
  3472.  
  3473. return 0
  3474.  
  3475.  
  3476. /*----------------------*/
  3477. save_em:
  3478. parse arg avar ;avar=strip(avar)
  3479.  
  3480. igot=0
  3481. drop plist
  3482.  
  3483. avar0=strip(avar,'t','.')
  3484. avar=avar0||'.'
  3485. rr=cvtails(avar,'plist')
  3486. do r1=1 to rr
  3487.    atail=plist.r1
  3488.    interpret 't1='||avar||atail
  3489.    call value envadd||avar||atail,t1,'os2environment'
  3490.    igot=igot+1
  3491. end
  3492.  
  3493. /* save the default (non hostname) version */
  3494.    if upper(symbol(avar0))="VAR" then do
  3495.       interpret 't1='||avar0
  3496.       call value envadd||avar0,t1,'os2environment'
  3497.       igot=igot+1
  3498.    end
  3499.  
  3500. return igot
  3501.  
  3502.  
  3503. /* --- variable names of convert foo.bar.1 to foo.1.bar */
  3504. fix_me:procedure
  3505. parse arg a1
  3506.  
  3507. if a1=' '  then return a1
  3508. a1=strip(a1)
  3509. if abbrev(a1,';') then return a1
  3510.  
  3511. parse var a1  aname '=' avalue
  3512. if pos('.',aname)=0 then return a1
  3513.  
  3514. foo=translate(aname,' ','.')
  3515. if words(foo)<>3 then return a1
  3516.  
  3517. /* if here, array.x.y (3 elements) */
  3518. if datatype(word(foo,3))='NUM' & datatype(word(foo,2))<>'NUM' then do  /* rearrange */
  3519.    foo2=word(foo,1)||'.'||word(foo,3)||'.'||word(foo,2)||' = '||avalue
  3520.    return foo2
  3521. end  /* Do */
  3522. else do
  3523.    return a1
  3524. end  /* Do */
  3525.  
  3526.  
  3527. /******************************/
  3528. /* clean up delta directory -- uses HPFS "last accessed" field
  3529.   to remove least recently used files*/
  3530.  
  3531. cleanup_deltas:procedure 
  3532.  
  3533. parse arg deltas_dir,maxsize
  3534. oo=deltas_dir'\*.*'
  3535. foo=sysfiletree(oo,'alist','FT')
  3536. do ii=1 to alist.0
  3537.    parse var alist.ii .  size . aname ; aname=strip(aname)
  3538.    ainfo=dosfileinfo(aname,'A')
  3539.    parse var ainfo mnth '/' dy '/' yr  hr ':' mnt ':' sc
  3540.    adate=yr'/'mnth'/'dy'/'hr'/'mnt'/'sc
  3541.    if yr>80 then 
  3542.        adate='19'||adate
  3543.    else
  3544.        adate='20'||adate
  3545.   alist.ii=adate' '||left(size,9,' ')||' 'aname
  3546. end /* do */
  3547.  
  3548. if alist.0>0 then do 
  3549.   oo=arraysort('alist',1,alist.0,1,19,'D')
  3550.   if oo=0 then do
  3551.     call pmprintf(left('!! SRE-http monitor WARNING: too many files ('alist.0') in delta cache directory '||deltas_dir,90))
  3552.     return 0
  3553.   end
  3554. end
  3555.  
  3556. /* add up size until maxsize */
  3557. runsize=0
  3558. ndel=0
  3559. maxsize=maxsize*1000
  3560. do ii=1 to alist.0
  3561.   if runsize>maxsize then do
  3562.      foo=sysfiledelete(substr(alist.ii,31))
  3563.       ndel=ndel+1
  3564.   end
  3565.   else do
  3566.      runsize=runsize + substr(alist.ii,21,9)
  3567.      if runsize>maxsize then do
  3568.         foo=sysfiledelete(substr(alist.ii,31))
  3569.         ndel=ndel+1
  3570.      end
  3571.   end
  3572. end /* do */
  3573. return ndel 
  3574.  
  3575.  
  3576.  
  3577.  
  3578. /***************/
  3579. /* update addon's to macrospace. */
  3580. update_addons:procedure expose keep_addons. verbose envadd serverport
  3581. if symbol('KEEP_ADDONS.0')<>'VAR' then return  0 /* none specified*/
  3582. if datatype(keep_addons.0)<>'NUM'  then return 0
  3583.  
  3584. do iy=1 to keep_addons.0
  3585.    if symbol('KEEP_ADDONS.'||iy)<>'VAR' then iterate
  3586.    parse var keep_addons.iy asel afile . ; afile=strip(afile); asel=strip(asel)
  3587.    IF AFILE="" then DO          /* REMOVE ASEL */
  3588.       asel=strip(translate(asel,'/','\'),,'/')          
  3589.       tt=envadd||'ADDON_'||translate(asel,'__','/\')    
  3590.       FOO=MACROdROP(TT)
  3591.       ITERATE
  3592.    END
  3593.    if stream(afile,'c','query exists')="" then do
  3594.         if verbose>0 then foo=pmprintf_sr("!! SRE-http Monitor WARNING: bad file in KEEP_ADDON entry: " asel ',' afile)
  3595.         iterate
  3596.    end  /* Do */
  3597.    asel=strip(translate(asel,'/','\'),,'/')
  3598.    tt=envadd||'ADDON_'||translate(asel,'__','/\')
  3599.    foo=macroadd(tt,afile,'B')
  3600.    if foo=0 then do
  3601.       if verbose>0 then foo=pmprintf_sr("!! SRE-http Monitor WARNING: problem with KEEP_ADDON entry: " keep_addons.iy)
  3602.        iterate
  3603.    end  /* Do */
  3604.    if verbose>1 then foo=pmprintf_sr(' SRE-http Monitor: Okay ADDON entry: ' tt ' : ' afile)
  3605. end /* do */
  3606. return 0
  3607.  
  3608. go
  3609. /****************/
  3610. /* start the pmprintf thread 
  3611. itype: 1= use pmprintf, but check line lengths
  3612.        2= use pmprintf, and write to afile
  3613.        3= just write to afile
  3614. */
  3615.  
  3616. start_pmprintf:
  3617. parse arg itype, ilen, afile,goo
  3618.  
  3619. arxx=servdir||'\pmprintf.rxx'
  3620. usequeue='SREF_'||serverport||'_PMPRINTF'
  3621. usesem='\SEM32\SREF_'||serverport||'_PMPRINTF'
  3622. badt=value('SREF_PMPRINTF_BAD',,'os2environment')
  3623.  
  3624. if badt=1 |  goo=1 then do                /* check that everything is okay */
  3625.    foo=eventsem_query(usesem)   /* is it still alive? */
  3626.    if foo<0 then do
  3627.        call pmprintf("SRE-http Monitor: relaunching pmprintf daemon (semaphore was:"foo)
  3628.    end /* do */
  3629.    else do
  3630.      return 0             /* otherwise, it's okay */ 
  3631.    end
  3632. end /* do */
  3633.  
  3634. if ilen<2 then ilen=80
  3635.  
  3636. /* check variables */
  3637. if itype=3 then ilen=0
  3638. if itype=1 then 
  3639.   afile=' '
  3640. else
  3641.   afile=servdir||'\'||strip(afile,,'\')
  3642.  
  3643. if itype>1 then do
  3644.   call lineout afile,' -- SRE-http log file: '||time('n')||' '||date('n')
  3645.   call lineout afile
  3646. end
  3647.  
  3648.  
  3649. /* start thread */
  3650. a=rxqueue('d',usequeue)
  3651. a=rxqueue('c',usequeue)
  3652. if a<>usequeue then do
  3653.   bb=rxqueue('d',a)
  3654.   a=rxqueue('s',usequeue)
  3655.   do queued()
  3656.        pull
  3657.   end /* do */
  3658. end
  3659.  
  3660. a=eventsem_close(usesem)
  3661. A=EVENTSEM_CREATE(USESEM)
  3662. IF A<>0 then DO
  3663.     call pmprintf(' SRE-http Monitor ERROR: creating PMPRINTF semaphore:'usesem)
  3664.     return 0
  3665. end
  3666.  
  3667. badt=value('SREF_PMPRINTF_BAD',0,'os2environment')
  3668.  
  3669.  
  3670. mm1=max_semwait
  3671. v_tid=rexxthread('f',arxx,usequeue,USESEM,mm1,ilen,itype,afile)
  3672. if v_tid=0 then do
  3673.    call pmprintf(' SRE-http Monitor:Could not start PMPRINTF thread 'arxx)
  3674.    return 0
  3675. end
  3676.  
  3677. return 1
  3678.  
  3679.  
  3680.  
  3681.  
  3682. /***************/
  3683. pmprintf_sr:procedure expose serverport
  3684. parse arg amess
  3685. foo=pmprintf_sref(amess,,serverport)
  3686. return 0
  3687.  
  3688.  
  3689. /*********************/
  3690. /* call the procedures listed in custom_inits */
  3691. call_custom_inits:procedure expose serverport
  3692. parse arg alist
  3693. signal off error ; signal off syntax ;
  3694. signal on error name yipes2 ; signal on syntax name yipes2 ;
  3695. if alist=0 then alist=""
  3696.  
  3697. if alist="" then do
  3698.     call pmprintf(' SRE-http Monitor: no custom initialization procedures specified')
  3699.    return 1
  3700. end /* do */
  3701.  
  3702. do until alist=""
  3703.     parse var alist aproc ',' alist
  3704.     if aproc="" then leave
  3705.     parse var aproc aname anarg
  3706.     call pmprintf('SRE-http Monitor: executing initialization procedure 'aproc)
  3707.     dog='okay='||aname||'("'anarg'")'
  3708.     interpret dog
  3709. end /* do */
  3710.  
  3711.  
  3712. signal on error name yipes ; signal on syntax name yipes ;
  3713.  
  3714. return 1
  3715.  
  3716. yipes2:
  3717. call pmprintf(' SRE-http Monitor ERROR: running external initialization procedure: 'aproc)
  3718. call pmprintf(dog)
  3719. return 0
  3720.  
  3721. /******************/
  3722. /* call rexxlib date conversion, but check y2k first */
  3723. dateconv_3:procedure 
  3724. parse upper arg aval,t1,t2
  3725. hh=''
  3726. select 
  3727.  when t1='O' | t1='U' | t1='E' then do
  3728.    if t1='O' then      parse var aval yy '/' mo '/' dd '/' hh '/' mm .
  3729.    if t1='U' then     parse var aval mo '/' dd '/' yy
  3730.    if t1='E' then     parse var aval dd '/' mo '/' yy
  3731.    if yy<78 then 
  3732.        yy=2000+yy 
  3733.    else
  3734.       yy=yy+1900
  3735.     yip=strip(yy)||strip(mo)||strip(dd)
  3736.     adatef=dateconv(yip,'S',t2)
  3737.  end
  3738.  otherwise do
  3739.     adatef=dateconv(aval,t1,t2)
  3740.  end
  3741. end
  3742.  
  3743. if hh<>'' then do
  3744.      adatef=adatef+(((hh*60)+mm)/1440)
  3745. end /* do */
  3746.  
  3747. return adatef
  3748.  
  3749.  
  3750. 
  3751. /******/
  3752. /* set an error flag, wake up srefilter, exit */
  3753. gosexit:
  3754. PARSE ARG AA
  3755. foo1=value('SREF_WAIT_FLAG',-2,'os2environment')
  3756. FOO2=VALUE('SREF_WAIT_FLAG_ERROR',AA,'OS2ENVIRONMENT')
  3757. foo3=eventsem_create(thesem)
  3758. foo2=eventsem_post(thesem)
  3759.  
  3760. exit  
  3761.  
  3762.  
  3763.  
  3764.