home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 35 Internet / 35-Internet.zip / srev13g.zip / STATUS.CMD < prev    next >
OS/2 REXX Batch file  |  1999-06-18  |  10KB  |  266 lines

  1. /* This is the STATUS demo of SRE-http's server side proceessing
  2.  
  3. Use STATUS.SHT to invoke this routine.
  4. */
  5.  
  6. status:
  7. parse arg  ddir, tempfile, reqstrg,list,verb ,uri,user, ,
  8.           basedir ,workdir,privset,enmadd,transaction,verbose, ,
  9.          servername,host_nickname,homedir,aparam,semqueue,prog_file,reqnum
  10.  
  11. /* aparam is obsoloete. Semqueue is semaphore/queue information
  12. that can be used by some sre-daemon procedures */
  13.  
  14. if verb=" " then do
  15.    say "This SRE-http procedure is not meant to be run in standalone mode "
  16.    exit
  17. end  /* Do */
  18.  
  19. parse var privset privset ',' privset_secret 
  20.  
  21. list=translate(list, ' ', '+'||'090a0d'x)  /* Whitespace, etc. */
  22.  
  23. /* special request: initialize dircache */
  24. if pos('INIT_DIRCACHE=1',upper(list)) then do
  25.   if wordpos('SUPERUSER',upper(privset))=0 then do
  26.       'header add WWW-Authenticate: Basic Realm=<!DIR Cache>'  /* challenge */
  27.        return sref_response('unauth', "You do not have !DIR cache deletion rights ",tempfile,servername)
  28.   end  /* Do */
  29.  
  30.   call init_dircache
  31.  foo=sref_gos('FILE ERASE TYPE text/html NAME' tempfile) 
  32.  return 'Done with STATUS (initialize !dir cache)'
  33.  
  34. end  /* Do */
  35.  
  36. /* Information will be returned in a temporary file, whose name
  37. is provided in the tempfile variable.
  38. Note that it's a good idea to start your HTML documents with a dtd doctype statement
  39.  */
  40.         call lineout tempfile, '<!doctype html public "-//IETF//DTD HTML 2.0//EN">'
  41.  
  42.         call lineout tempfile, "<html><head><title>Results from STATUS request</title>"
  43.         call lineout tempfile, "</head><body>"
  44.         call lineout tempfile,' <h2>Results from  Status Request </h2>'
  45.  
  46.         call lineout tempfile,' <h3>The arguments recieved by STATUS </h3> '
  47.  
  48.         call lineout tempfile,' <dl> '
  49.  
  50.         call lineout tempfile,' <dt>  DDIR = <code>' ddir '</code> '
  51.         call lineout tempfile,' <dd>  The "data directory" (where your HTML documents should be) '
  52.         call lineout tempfile,' <dt>  TEMPFILE = <code>' tempfile ' </code> '
  53.         call lineout tempfile,' <dd> The "temporary file" (used to build this response)'
  54.  
  55.         call lineout tempfile,' <dt>  ACTION = <code>' reqstrg ' </code> '
  56.         call lineout tempfile,' <dd>  The  <b>action</b> portion of the request selector'
  57.  
  58.  
  59.         call lineout tempfile,' <dt>  LIST = <code>' list ' </code> '
  60.         call lineout tempfile,' <dd> The <b>parameters</b>: '
  61.         call lineout tempfile, '<br> ... if POST method, from the "body" of the request '
  62.         call lineout tempfile,' <br> ... if GET method ,  from after the "?" in the request selector.  '
  63.  
  64.         call lineout tempfile,' <dt>  VERB = <code>' VERB ' </code> '
  65.         call lineout tempfile,' <dd>  The HTTP method '
  66.         call lineout tempfile,' <dt>  URI = <code>' URI ' </code> '
  67.         call lineout tempfile,' <dd> The full <b>request string</b> '
  68.  
  69.         call lineout tempfile,' <dt> CLIENT = <code>' user ' </code> '
  70.         call lineout tempfile," <dd> Client's ip address "
  71.  
  72.         call lineout tempfile,' <dt>  BASEDIR = <code>' basedir ' </code> '
  73.         call lineout tempfile,' <dd> The "working directory" (where SRE-http lives) '
  74.  
  75.         call lineout tempfile,' <dt>  WORKDIR = <code>' workdir ' </code> '
  76.         call lineout tempfile,' <dd>  Temporary working files area (for <em>user-supplied </em> programs ) '
  77.  
  78.         call lineout tempfile,' <Dt> Your privileges are: '
  79.         call lineout tempfile,' <DD> <code> ' privset ' </code> '
  80.         if privset_secret<>'' then 
  81.             call lineout tempfile,'(with '||words(privset_secret)||' secret privileges)'
  82.  
  83.         call lineout tempfile,' <Dt> The host nickname '
  84.         call lineout tempfile,' <DD> <code> ' host_nickname ' </code> '
  85.  
  86.         call lineout tempfile, '<dt> The ~ (home directory) string '
  87.         call lineout tempfile,' <Dd> <code> ' homedir  ' </code>'
  88.  
  89.         call lineout tempfile,' <dt> The program file '
  90.         if prog_file=' ' then
  91.           call lineout tempfile,' <dd><code> run from macrospace </code>'
  92.         else
  93.           call lineout tempfile,' <dd><code> ' prog_file '</code>'
  94.  
  95.         call lineout tempfile,'<dt>Transaction and request '
  96.         call lineout tempfile,'<DD>' transaction ', 'reqnum
  97.         call lineout tempfile,'</dl>'
  98.  
  99. /* Read the "header" -- and display the results */
  100.        'READ HEADER VAR FOO '
  101.          call lineout tempfile,' <h3> The Request Header </h3> '
  102.  
  103.         call lineout tempfile,' <blockquote> <pre>' foo  '</pre> </blockquote>'
  104.  
  105.         call lineout tempfile,' <h3> Some User & Server Info </h3> '
  106.  
  107. /* This section demonstrates the use of some GOSERVE functions */
  108.    caddr=extract('CLIENTADDR')
  109.    if value('SREF_NODNS',,'OS2ENVIRONMENT')=1 then
  110.       cname=caddr
  111.    else
  112.        cname=clientname()
  113.    ssoft=server()
  114.    sname=servername
  115.    saddr=extract('SERVERADDR')
  116.    sport=extract('SERVERPORT')
  117.  
  118.    call lineout tempfile,' <ul> '
  119.    call lineout tempfile,' <li> Client ip address:  <code>' caddr '</code>'
  120.    call lineout tempfile,' <li> Client name:  <code>' cname '</code>'
  121.    call lineout tempfile,' <li> Server ip address: <code>' saddr '</code>'
  122.    call lineout tempfile,' <li> Server port:  <code>' sport '</code>'
  123.  
  124.    call lineout tempfile,' <li> Server name:  <code>' sname '</code>'
  125.    call lineout tempfile, ' <li> Server software:  <code>' ssoft '</code>'
  126.   aver=sref_version()
  127.    call lineout tempfile,' <li>  Filter version: <code> ' aver ' </code>'
  128.    call lineout tempfile,' <li> Your privileges are: <tt> ' privset ' </tt>'
  129.    call lineout tempfile,' </ul> '
  130.  
  131. /* superusers and inhouse users get to see SRE-http's parameters,
  132. if desired (by pressing a link to configure */
  133.  
  134.   if wordpos('SUPERUSER',privset)=0 then signal getuse
  135.   call lineout tempfile,' <h3> SRE-http settings </h3> '
  136.   call lineout tempfile,' <br>   Do you want to see the  <A href='
  137.   call lineout tempfile,' "/config2?todo=show">current settings of SRE-http'"'s parameters</A>? <br>"
  138.  
  139.  
  140. getuse: nop
  141. /* get some "intensity of use " statistics */
  142.  reptime=extract('RESPONSETIME')
  143.  numtrans=extract('TRANSACTIONS')
  144.  whenstart=extract('LASTSTART')
  145.  nclients=extract('CLIENTS')
  146.  
  147.    call lineout tempfile,' <h3> Use Statistics </h3> '
  148.    call lineout tempfile,' GoServe started: ' whenstart
  149.  
  150.    call lineout tempfile,'<BR> # of transactions ' numtrans  ', avg. reponsetime = 'reptime ' sec. '
  151.  
  152.    call lineout tempfile,'<BR> Current # of clients = ' nclients
  153.  
  154.  
  155. /* review cache etnries */
  156. Srelite=VALUE('SRELITE_INIT',,'OS2ENVIRONMENT')
  157. IF Srelite<>1 then DO
  158.   foo=strip(get_value('tempdata_dir'),'t','\')
  159.   call lineout tempfile,'<h3> Cache status (in ' foo ') </h3> '
  160.   dshs=foo||'\_*.DSH'
  161.   oo=sysfiletree(dshs,fred,'FO')
  162.   call lineout tempfile,' # of files in the <EM>!DIR cache </EM>= ' fred.0
  163.   aport=extract('serverport')
  164.   cshs=foo||'\_*.'||aport
  165.   oo=sysfiletree(cshs,fred,'FO')  
  166.   call lineout tempfile,'<br> # of files in the <EM>SSI-Cache files </EM> = ' fred.0 '<br>'
  167. END
  168.  
  169. /* Use the HOST function -- demonstrates the use of external calls */
  170.  
  171. /* but first "parse" the parameter list, and store in a simple stem variable */
  172.   m=0
  173.   do until list=""
  174.     parse var list opt1 '&' list
  175.     m=m+1
  176.     parse var opt1 optname.m '=' optvalue.m
  177.   end
  178.   optname.0=m
  179.  
  180. /* see if one of the opts is "getip" */
  181.    chkip=0 ;
  182.    do mm=1 to optname.0
  183.       if translate(optname.mm)='GETIP' then do
  184.          chkip=optvalue.mm
  185.          leave
  186.       end
  187.   end
  188.  
  189. /* if we found a GETIP, and got it's value, then lookit up */
  190.   if chkip<>0 & chkip<>"" then do
  191. /* Note use of the address cmd xxx to call a OS/2 level command  */
  192.     A=RXQUEUE('S','SESSION')    /* SINCE QUEUE MIGHT BE A THREAD'S QUEUE */
  193.     do queued(); pull .; end                   /* flush */
  194.     address cmd '@host' chkip '| rxqueue'     /* execute the command */
  195.     parse pull hostresult                      /* get result */
  196.  
  197.     call lineout tempfile,' <h3> Look up address </h3> '
  198.  
  199.     call lineout tempfile,' <pre> ' hostresult ' </pre>'
  200.   end
  201.  
  202.  
  203. if srelite=1 then do
  204.    call lineout tempfile,'<h3>Reset parameters</h3>'
  205.   call lineout tempfile,'<em>Superusers </em> can <a href="/!RESET">reset parameters</a>'
  206. end /* do */
  207.  
  208.  
  209. /* all done, write final end-of-html elements */
  210.   call lineout tempfile,'<body> </html>'
  211.   call lineout tempfile
  212.   foo=sref_gos('FILE ERASE TYPE text/html NAME' tempfile)
  213.   return 'Done with STATUS'
  214.  
  215. /* ----------- */
  216. /* get environment value. Typically, look for host-specific
  217. value first, and then look for generic value (if no host given,
  218. skip host-specific lookup )
  219. vname: variable to lookup
  220. hname0: Special instructions:
  221.   hname0=0 -- do not look under host nickname
  222.   hname0=1 -- do not look under default
  223.  */
  224. /* ------------ */
  225. get_value: procedure expose enmadd host_nickname
  226. parse upper arg vname,hname0
  227. if hname0=0 then
  228.         hname=' '
  229. else
  230.     hname=strip(host_nickname)
  231.  
  232. vname=strip(vname) ;
  233. if hname<>' ' then do
  234.    booger=strip(enmadd||vname||'.'||hname)
  235.    aval=value(booger,,'os2environment')
  236.    if aval<>' ' | hname0=1 Then
  237.         return aval
  238. end
  239. aval=value(enmadd||vname,,'os2environment')
  240. return aval
  241.  
  242.  
  243. /* *********** */
  244. /* initialize dir cache */
  245. init_dircache:
  246.   call lineout tempfile, '<!doctype html public "-//IETF//DTD HTML 2.0//EN">'
  247.   call lineout tempfile, "<html><head><title>Initialize !DIR Cache</title>"
  248.   call lineout tempfile, "</head><body>"
  249.   call lineout tempfile,' <h2>Initialize !DIR Cache</h2>'
  250.   foo=strip(get_value('tempdata_dir'),'t','\')
  251.   dshs=foo||'\_*.DSH'
  252.   oo=sysfiletree(dshs,fred,'FO')
  253.   do mm=1 to fred.0
  254.      foo2=sysfiledelete(fred.mm)
  255.   end /* do */
  256.   iid=foo||'\_DIRLIST.IDX'
  257.   foo=sysfiledelete(iid)
  258.   call lineout tempfile,  ' # of files <b>deleted</b> from the <EM>!DIR cache </EM> = ' fred.0
  259. /* all done, write final end-of-html elements */
  260.   call lineout tempfile,'<body> </html>'
  261.   call lineout tempfile
  262.  
  263.   return 0
  264.  
  265.  
  266.