home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 35 Internet / 35-Internet.zip / bbs102e.zip / bbscache.cmd < prev    next >
OS/2 REXX Batch file  |  1997-11-16  |  12KB  |  415 lines

  1. /*The  BBS add-on for the SRE-http http server: version 1.02
  2.     This is the "caching" daemon.
  3.     It is meant to be run as a standalond program
  4.     (typically, from the os/2 prompt)
  5.  
  6. Written by:
  7.   Primary author: Daniel Hellerstein (danielh@econ.ag.gov)
  8.   Primary collaborator: Juho Risku (jrisku@paju.oulu.fi)
  9.  
  10.  
  11.                  **** IMPORTANT INSTALLATION NOTE ***
  12.  
  13. 1) A BBS.INI file MUST exist in the same directory BBS.CMD is installed
  14.    to. 
  15.  
  16.                 --- END OF INSTALLATION NOTE --------
  17.  
  18. */
  19.  
  20. /*--------------   Load REXX libraries ----- */
  21. /* Load up advanced REXX functions */
  22. foo=rxfuncquery('sysloadfuncs')
  23. if foo=1 then do
  24.   call RxFuncAdd 'SysLoadFuncs', 'RexxUtil', 'SysLoadFuncs'
  25.   call SysLoadFuncs
  26. end
  27. foo=rxfuncquery('rexxlibregister')
  28. if foo=1 then do
  29.  call rxfuncadd 'rexxlibregister','rexxlib', 'rexxlibregister'
  30.  call rexxlibregister
  31. end
  32.  
  33.  
  34. /* some color stuff */
  35. ansion=checkansi()
  36. if ansion=1 then do
  37.   aesc='1B'x
  38.   cy_ye=aesc||'[37;46;m'
  39.   normal=aesc||'[0;m'
  40.   bold=aesc||'[1;m'
  41.   re_wh=aesc||'[31;47;m'
  42.   reverse=aesc||'[7;m'
  43. end
  44. else do
  45.   cy_ye="" ; normal="" ; bold="" ;re_wh="" ; 
  46.   reverse=""
  47. end  /* Do */
  48.  
  49.  
  50.  
  51.  
  52. /*A few User changeable non bbs.ini  parameters ... */
  53.  
  54. imagesize="width=24 height=24"   /* size of icons */
  55.  
  56.  
  57. /** End of user changeable  "non-BBS.INI parameters " *****************************/
  58.  
  59. foo=rxfuncquery('UZLoadFuncs')
  60. if foo=1 then do
  61.   call RxFuncAdd 'UZLoadFuncs', 'UNZIPAPI', 'UZLoadFuncs'
  62.   call UZLoadFuncs
  63. end
  64. foo=rxfuncquery('UZLoadFuncs')
  65. if foo=1 then do
  66.      say " Can not find UNZIP procedure library: UNZIPAPI.DLL"
  67.      exit
  68. end  /* Do */
  69.  
  70. basedir=directory()
  71. basedir=strip(basedir,'t','\')||'\'
  72.  
  73.  
  74. call load_rxl
  75.  
  76. inifile=basedir||'bbs.ini'
  77. isit=fileread(inifile,inilines,,'E')
  78. if isit<0 then do
  79.      say " ERROR: no BBS initialization file:" inifile
  80.      exit
  81. end  /* Do */
  82.  
  83. signal on syntax name bad1
  84. signal on error name bad1
  85. mm=0
  86.  
  87. gobot:
  88. mm=mm+1
  89. if mm > inilines.0 then signal good1
  90. aline=inilines.mm
  91. interpret aline
  92. signal gobot
  93.  
  94. bad1:
  95. signal off error ; signal off syntax ;
  96. say " ERROR: error in BBS initialization file: " aline
  97. exit
  98.  
  99. /* ------  bbs_ini okay, or skipped.  Check, various values, directories */
  100. /* this is a shortened version of what's in bbs.cmd */
  101. good1:
  102.  
  103. signal off error ; signal off syntax ;
  104. bbs_param=translate(bbs_param_dir,'\','/')
  105. if abbrev(strip(bbs_param,'l','\'),'\') =0 & pos(':',bbs_param)=0 then /* must be relative dir*/
  106.    bbsdir=basedir||bbs_param||'\'
  107. else
  108.    bbsdir=strip(bbs_param,'t','\')'\'
  109.  
  110. if dosisdir(strip(bbsdir,'t','\'))=0 then do
  111.      say " ERROR: no BBS parameters directory:" bbsdir
  112.     exit
  113. end
  114.  
  115.  
  116. option_list='USER PWD DIR FILE SHORT NOSORT NOTABLE NOICONS SORTBY ZIPFILE '
  117. option_list=option_list||' FORCETEXT NODIR NOTIME NODESC NODATE NOSIZE OLDSTUFF '
  118. option_list=option_list||' SIZEFMT DATEFMT TIMEFMT  ROOTDIR  DIRCOLS NOCACHE '
  119.  
  120.  
  121. /* the "directory" icons */
  122. dirgif='<img src="'ImagePath'menu.gif"' imagesize 'align=top alt="[dir] ">'
  123. /* the "back to parent" icon */
  124. backgif='<img src="'ImagePath'back.gif"' imagesize 'align=top alt="[..] ">'
  125. /* The "expand this .ZIP file" icone */
  126. unzipme='<img src="'ImagePath'expand.gif"' imagesize ' align=top alt="[unzip]"></a>'
  127.  
  128. bbscache_dir=translate(bbscache_dir,'\','/')
  129. if abbrev(strip(bbscache_dir,'l','\'),'\')=0 & pos(':',bbscache_dir)=0 then /* must be relative dir*/
  130.    bbscache_dir=bbsdir||bbscache_dir||'\'
  131. else
  132.    bbscache_dir=strip(bbscache_dir,'t,','\')'\'
  133.  
  134. cache.!dir=bbscache_dir
  135. cache.!files=cache_files
  136.  
  137. action="BBS"
  138.  
  139. yani=strip(bbscache_dir,'t','\')
  140. foo=dosisdir(yani)
  141. if foo=0 then do
  142.    say ' The cache directory, ' bbscache_dir ' could not be found.'
  143.    exit
  144. end  /* Do */
  145.  
  146. if datatype(must_wait)<>'NUM' then must_wait=1
  147. if wordpos(default_datefmt,'B C D E M N O S U W')=0 then default_datefmt='N'
  148. imagepath='/'||strip(imagepath,,'/')||'/'
  149.  
  150. tempfile=dostempname(bbscache_dir||'TMP?????.HT')
  151. def_cache_file=bbsdir||'bbscache.idx'
  152.  
  153. if symbol('USE_SERVERNAME')<>'VAR' then do
  154.    servername=get_hostname()
  155. end
  156. else do
  157.   if  use_servername="" | use_servername=0 then 
  158.       servername=get_hostname()
  159.   else
  160.      servername=use_servername
  161. end
  162.  
  163.  
  164. /* a time  date stamp */
  165.  d1=date('b')
  166.  t1=time('m')/(24*60)
  167.  nowtime=d1+t1
  168.  
  169.  user='USER' ; pwd='PWD'
  170.  
  171. cache_file=cache.!dir'bbscache.idx'
  172.  
  173. /* fix up the icons list */
  174.  if icons.1=0 then do
  175.       icons.0=0
  176.  end
  177.  else do
  178.      nn=0
  179.      do forever
  180.          nn=nn+1
  181.          if symbol('ICONS.'||nn)<>'VAR' then leave
  182.          if icons.nn=0 then  leave
  183.     end /* do */
  184.     icons.0=nn-1
  185.  end
  186.  
  187.  
  188. /* if inclusion_mode_file, then modify some others */
  189. if inclusion_mode_file=' ' then inclusion_mode_file=0
  190. if inclusion_mode_file<>0 then do
  191.    description_file=inclusion_mode_file
  192.    auto_describe=0
  193. end  /* Do */
  194.  
  195.  
  196. /* ------- End of parameter initializations ------------ */
  197.  
  198.  
  199.  
  200. say "          " cy_ye " This is the BBS cache daemon." normal
  201. say bold  " It will update the BBS cache on a scheduled basis." normal
  202. say " "
  203. say " Note-- the base directory is: "  bold basedir normal
  204. say "        the bbs parameters directory is: " bold bbsdir normal
  205. say "        the bbs cache directory is: " bold bbscache_dir normal
  206. say "        the BBS program is: " bold  action normal
  207. SAY "        using servername: " bold  servername normal
  208. say " "
  209. if stream(cache_file,'c','query exists')<>' ' then do
  210.   ayes=yesno('Do you want to save a copy of the current "cache index file"')
  211.   if ayes=1 then do
  212.       ty=stream(def_cache_file,'c','query exists')
  213.       ayes=1 
  214.       if ty<>' ' then do
  215.            ayes=yesno(def_cache_file||' exists.  Overwrite?')
  216.       end  /* Do */
  217.       if ayes=1 then do
  218.          foo=doscopy(cache_file,def_cache_file,'R')
  219.          if foo<>0 then do
  220.              say " Problem copying cache file ("cache_file"): " foo
  221.             exit
  222.          end  /* Do */
  223.          else do
  224.           say "Current working index: " bold cache_file normal
  225.           say "            copied to: " bold  def_cache_file normal
  226.         end  /* Do */
  227.       end
  228.   end  /* Do */
  229. end
  230. /* get  the reference cache index file */
  231. saY " "
  232. say bold " ----------             --------------- " normal
  233.  say " This caching daemon requires a 'cache-index' "
  234.  say " For example, you can use the cache-index you (might have) just saved."
  235.  say ' Note: the default "cache index" is:  ' bold def_cache_file normal
  236.  call charout, reverse " Enter the cache-index (ENTER=default): " normal
  237.  parse pull ref_cache_file
  238.  if ref_cache_file="" then ref_cache_file=def_cache_file
  239.  if stream(ref_cache_File,'c','query exists')=' ' then do
  240.       say "ERROR: The cache index, " ref_cache_file " could not be found "
  241.       exit
  242.  end
  243.  
  244.  do forever
  245.    foo=cvread(ref_cache_file,clines)
  246.    if foo=1 then leave
  247.    say ref_cache_file " cache index is busy (^C to exit).. "
  248.    call syssleep(2)
  249.  end
  250.   say "   (the # of entries in " ref_cache_file " is " clines.0 ")"
  251.  
  252. /*NOTE cache file entries: 
  253.                         clines.0 = # of entries:
  254.                         clines.hi = simple comment
  255.                         clines.m.time = date of creation
  256.                         clines.m.cookie= 1 if a "cookie" version
  257.                         clines.m.uri = request string this is caching (capitalized)
  258.                         clines.m.name = name of file containing cache
  259.                         clines.m.thetype=DIR or ZIP
  260.                         clines.m.thedir=the dir, or zipfile, this deals with
  261. */
  262.  
  263.  
  264. say " "
  265. call charout, reverse " What port is your web server running on (ENTER=80) " normal
  266. parse pull sport
  267. if datatype(sport)<>'NUM' | sport="" then  sport=80
  268.  
  269.  
  270. say " "
  271. call charout, reverse " How many minutes to wait between cache-refreshes (0=just do once):" normal
  272. parse pull nmin
  273. if datatype(nmin)<>'NUM' then nmin=0
  274.  
  275. if nmin>0 then do
  276.    say " "
  277.    say   bold "          -------- " normal
  278.    say cy_ye "  Starting BBS cache daemon .... " normal
  279.    say " "
  280.    say " The BBS cache will be refreshed immediately."
  281.    say " (you might want to minimize this session)"
  282. end
  283.  
  284.  
  285. /**** --- For all entries in ref_cache_lines --
  286.    extract the associated url, call bbs.cmd
  287. */
  288.  
  289. icache=0
  290. loopstart:    /* signal here to get next ref_cache_lines */
  291.  
  292. icache=icache+1
  293. list=clines.icache.uri
  294. cache.!cookver=clines.icache.cookie
  295. thisuri=list
  296. if cache.!cookver=1 then
  297.   say icache" of " clines.0 ") Cookie Caching: " list
  298. else
  299.   say icache" of " clines.0 ") Non-cookie Caching: " list
  300.  
  301. list0=translate(list,' ','&')
  302. arf=bbs(0,tempfile,cache.!cookver,list0,'CACHE',list0,'USER', ,
  303.          basedir,0,'*',0,0,1, ,
  304.          servername,0,0)
  305. say "  ::: status: " arf
  306. /*parse arg  ddir, tempfile, reqstrg,list0,verb ,uri,user, ,
  307.           basedir ,workdir,privset,enmadd,transaction,verbose, ,
  308.          servername,host_nickname,homedir */
  309.  
  310. if icache < clines.0 then signal loopstart  /* next entry */
  311.  
  312. if nmin=0 then do
  313.    say " all done .. "
  314.    exit
  315. end
  316.  
  317.  
  318. /* else, sleep nmin minutes */
  319. say " "
  320. say " It is now " bold time('n') normal ". BBS cache daemon will reactivate in  " bold nmin normal " minutes. "
  321. ww=trunc(nmin*60)
  322. if datatype(ww)<>'NUM' then ww=3600
  323. call syssleep(ww)
  324. say ".... BBS CACHE daemon activated "
  325. say " "
  326. icache=0
  327. signal loopstart
  328.  
  329. /* ----------  end of main portion of bbscache  ----------- */
  330.  
  331.  
  332.  
  333.   
  334.  /* ------------------------------------------------------------------ */
  335.  /* function: Check if ANSI is activated                               */
  336.  /*                                                                    */
  337.  /* call:     CheckAnsi                                                */
  338.  /*                                                                    */
  339.  /* where:    -                                                        */
  340.  /*                                                                    */
  341.  /* returns:  1 - ANSI support detected                                */
  342.  /*           0 - no ANSI support available                            */
  343.  /*          -1 - error detecting ansi                                 */
  344.  /*                                                                    */
  345.  /* note:     Tested with the German and the US version of OS/2 3.0    */
  346.  /*                                                                    */
  347.  /*                                                                    */
  348.  CheckAnsi: PROCEDURE
  349.    thisRC = -1
  350.  
  351.    trace off
  352.                          /* install a local error handler              */
  353.    SIGNAL ON ERROR Name InitAnsiEnd
  354.  
  355.    "@ANSI 2>NUL | rxqueue 2>NUL"
  356.  
  357.    thisRC = 0
  358.  
  359.    do while queued() <> 0
  360.      queueLine = lineIN( "QUEUE:" )
  361.      if pos( " on.", queueLine ) <> 0 | ,                       /* USA */
  362.         pos( " (ON).", queueLine ) <> 0 then                    /* GER */
  363.        thisRC = 1
  364.    end /* do while queued() <> 0 */
  365.  
  366.  InitAnsiEnd:
  367.  signal off error
  368.  RETURN thisRC
  369.  
  370. /* -------------------- */
  371. /* get a yes or no , return 1 if yes */
  372. yesno:procedure expose normal reverse bold
  373. parse arg fooa , allopt
  374. ayn='  '||bold||'Y'||normal||'es\'||bold||'N'||normal||'o'
  375. if allopt=1 then
  376.    ayn=ayn||'\'||bold||'A'||normal||'ll'
  377. do forever
  378.  foo1=normal||reverse||fooa||normal||ayn
  379.  call charout,  foo1 normal ':'
  380.  pull anans
  381.  if abbrev(anans,'Y')=1 then return 1
  382.  if abbrev(anans,'N')=1 then return 0
  383.  if allopt=1 & abbrev(anans,'A')=1 then return 2
  384.  
  385. end
  386.  
  387.  
  388.  
  389. /*********************************************************/
  390. /* Load srefilter macro libary, if not already loaded */
  391. load_rxl:procedure expose basedir
  392.  
  393. if macroquery('SREF_VERSION')<>"" then return 1
  394.  
  395. tt=strip(basedir,'t','\')||'\SREFPRC1.RXL'
  396. aa=macroload(tt)
  397.  if aa=0 then do
  398.     say " ERROR: Could not load macrospace library: " tt
  399.    exit
  400. end
  401.  
  402. RETURN 1
  403.  
  404.  
  405.  
  406. /* get the hostname (aa.bb.cc) for this machine */
  407. get_hostname: procedure
  408.     do queued(); pull .; end                   /* flush */
  409.     address cmd '@hostname'  '| rxqueue'    
  410.     parse pull hostname                        
  411.     return hostname
  412.  
  413.  
  414.  
  415.