home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 35 Internet / 35-Internet.zip / gohttp.zip / SPECIAL.CMD < prev    next >
OS/2 REXX Batch file  |  1995-07-04  |  3KB  |  59 lines

  1. /********************/
  2. /* SPECIAL: Mini-scripts that execute within this function.*/
  3. /********************/
  4.  
  5. /*    Albert Crosby's "special" function - handles execution of some     */
  6. /*    local commands & passing results back to client.        */
  7.  
  8.   parse arg sel '?' options, tempfile, who
  9.   /* Allow support for user-created scripts that return other information     */
  10.   /* from the server.                             */
  11.   /*                                    */
  12.   /*  Make sure to return the command to the filter - returning an empty    */
  13.   /*   string will result in a "not found" message returned to the client...     */
  14.   select
  15.     when sel='time'          then return 'STRING The server''s time is 'time()' on 'date()
  16.     when sel='dir'           then return 'STRING The working directory is 'directory()
  17.     when sel='who'           then do
  18.       if options\="" then header="Information about "options
  19.       else header="Users logged on to the Domain"
  20.       return execute('net who 'options,"Information about Network Users",header)
  21.       end
  22.     when sel='printers'      then return execute('net print \\sig','Jobs Printing at the Microcomputer Lab')
  23.     when sel='ping'          then do
  24.       parse var options host '&count=' count
  25.       if host="" | host="*" then host=who
  26.       if count="" then count=1
  27.       return execute('ping 'host 56 count,'Ping 'host)
  28.       end
  29.     otherwise return ''
  30.   end                                                                   
  31. /* End of the Special commands */                                     
  32.  return    /* Should never get here... */
  33.  
  34.  
  35. /* ----------------------------------------------------------------------- */
  36. /* EXECUTE: Executes an OS/2 command and sends the result to the remote    */
  37. /*          client.  Care should be taken to prevent creating a security   */
  38. /*          hole.                                                          */
  39. /* ----------------------------------------------------------------------- */
  40. execute: procedure expose tempfile
  41.   parse arg command, title, header
  42.   if title="" then title="Results of "command
  43.   if header="" then header=title
  44.   call lineout tempfile, '<!doctype html public "-//IETF//DTD HTML 2.0//EN">'
  45.   call lineout tempfile, "<html><head><title>" title "</title></head>"
  46.   call lineout tempfile, "<body><h2>"header"</h2>"
  47.   call lineout tempfile, "<hr><pre>"
  48.   call lineout tempfile  /* close */
  49.   address cmd command ">>"tempfile
  50.   call lineout tempfile, "</body></html>"
  51.   call lineout tempfile  /* close */
  52.   return 'FILE ERASE TYPE text/html NAME' tempfile
  53.  
  54. extension: procedure
  55. arg filename
  56. /* If no period or only period is first char, then return "" */
  57. if lastpos(".",filename)<2 then return ""
  58. return translate(substr(filename, lastpos('.',filename)+1))
  59.