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

  1. /*  BBS add-on for the SRE-http http server: version 1.02
  2.        This is the    new user registration  facility.
  3.     See BBS.CMD for download,
  4.     and BBSUP.CMD for upload support.
  5.  
  6. This uses the BBS.INI file. 
  7. */
  8.  
  9. parse arg  ddir, tempfile, reqstrg,list,verb ,uri,user, ,
  10.           basedir ,workdir,privset,enmadd,transaction,verbose, ,
  11.          servername,host_nickname,homedir 
  12.  
  13. if verb="" then do
  14.    say " This is an add-on for the SRE-http web server. "
  15.    say " It is NOT meant be run from the command line! "
  16.    exit
  17. end  /* Do */
  18.  
  19.  
  20. basedir=strip(basedir,'t','\')
  21. inifile=strip(basedir,'t','\')||'\bbs.ini'
  22. isit=fileread(inifile,inilines,,'E')
  23. if isit<0 then do
  24.      say " ERROR: no BBS initialization file "
  25.      foo=responsebbs('forbid','BBS new user registration is unavailable')
  26.      return foo||' Error in BBS parameters file (bbsnewu) '
  27. end  /* Do */
  28.  
  29. signal on syntax name bad1 
  30. signal on error name bad1 
  31. mm=0
  32.  
  33. gobot:
  34. mm=mm+1
  35. if mm > inilines.0 then signal good1
  36. aline=inilines.mm
  37. interpret aline
  38. signal gobot
  39.  
  40. bad1:
  41. signal off error ; signal off syntax ;
  42. say " ERROR: error in BBS initialization file: " aline
  43. foo=responsebbs('forbid','error in BBS initialization file')
  44. return foo||' Error in BBS parameters file '
  45.  
  46. /* bbs_ini okay, or skipped.  Check, etc. various values, directories */
  47. good1:
  48. signal off error ; signal off syntax ;
  49. bbs_param=translate(bbs_param_dir,'\','/')
  50. if abbrev(strip(bbs_param,'l','\'),'\') =0 & pos(':',bbs_param)=0 then /* must be relative dir*/
  51.    bbsdir=basedir||'\'bbs_param||'\'
  52. else
  53.    bbsdir=strip(bbs_param,'t','\')'\'
  54.  
  55. userlog_dir=translate(userlog_dir,'\','/')
  56. if abbrev(strip(userlog_dir,'l','\'),'\')=0 & pos(':',userlog_dir)=0 then /* must be relative dir*/
  57.    userlog_dir=bbsdir||userlog_dir||'\'
  58. else
  59.    userlog_dir=strip(userlog_dir,'t','\')'\'
  60.  
  61. reqratio=default_ratio||' '||default_byte_ratio
  62.  
  63.  
  64. /* check on own_download_dir and own_upload_dir */
  65. if symbol('own_download_dir')<>'VAR' | own_download_dir=0 then do
  66.    own_download_dir=' '
  67. end
  68. else do
  69.  own_load_dir=translate(strip(own_download_dir),'\','/')
  70.  own_download_dir=strip(own_download_dir,'t','\')
  71.  if dosisdir(own_download_dir)=0 then do
  72.      say " Could not find own_download_dir : " own_download_dir
  73.      own_download_dir=' '
  74.  end
  75. end
  76.  
  77. if symbol('own_upload_dir')<>'VAR' | own_upload_dir=0 then do
  78.    own_upload_dir=' '
  79. end
  80. else do
  81.  own_upload_dir=translate(strip(own_upload_dir),'\','/')
  82.  own_upload_dir=strip(own_upload_dir,'t','\')
  83.  if dosisdir(own_upload_dir)=0 then  do
  84.      say " Could not find own_upload_dir : " own_upload_dir
  85.      own_upload_dir=' '
  86.  end
  87. end
  88.  
  89. if symbol('Own_flag')<>' ' then
  90.     own_flag='PERSONAL'
  91.  
  92.  
  93. /* parse the input list, but initialize values first */
  94. reqargs='USER PWD PWD2 REALNAME EMAIL HELLO '
  95. do mm=1 to words(reqargs)
  96.    aw='!'||strip(word(reqargs,mm))
  97.    arglist.aw=' '
  98. end
  99. /* note:there may be several other optional fields */
  100. allargs=""
  101.  
  102. /* now pull out options */
  103. do until list=""
  104.        parse var list anarg '&' list
  105.        parse var anarg avar '=' aval ; avar=upper(avar)
  106.        foo1='!'||avar
  107.        arglist.foo1=packur(translate(aval,' ','+'))
  108.        if wordpos(avar,reqargs)=0 then
  109.           allargs=allargs' 'avar
  110. end /* do */
  111.  
  112. /* Check for errors */
  113.   select 
  114.     when arglist.!user=' ' then damess="You did not enter a username "
  115.     when abbrev(arglist.!user,'!')=1 then damess="You can not use ! in a username" 
  116.     when arglist.!pwd=' ' then damess="You did not enter a password "
  117.     when arglist.!pwd2<>arglist.!pwd then damess="Password verification failed "
  118.     when arglist.!realname=' ' then damess="You did not enter your real name"
  119.     when arglist.!email=' ' then damess="You did not enter your e-mail address"
  120.     when pos('@',arglist.!email)=0 then damess="Error in e-mail address (no @ found) "
  121.     otherwise damess=' '
  122.   end  /* Do */
  123.   if damess<>' ' then do
  124.     call lineout tempfile, '<!doctype html public "-//IETF//DTD HTML 2.0//EN">'
  125.     call lineout tempfile, "<html><head><title>Error in BBS Registration Form</title></head>"
  126.     call lineout tempfile, "<body><h2>Error in BBS Registration</h2>"
  127.     call lineout tempfile,damess
  128.     call lineout tempfile, "</body></html>"
  129.     call lineout tempfile  /* close */
  130.     'FILE ERASE TYPE text/html NAME' tempfile
  131.     return 'Bad BBS registration form '
  132.   end
  133.  
  134. /* basic checks are done. See if this user exists */
  135.  
  136. tryit=userlog_dir||arglist.!user||'.IN'
  137. wow=stream(tryit,'c','query exists')
  138. if wow<>' ' | upper(arglist.!user)='USER' then do
  139.     call lineout tempfile, '<!doctype html public "-//IETF//DTD HTML 2.0//EN">'
  140.     call lineout tempfile, "<html><head><title>Problem with BBS Registration</title></head>"
  141.     call lineout tempfile, "<body><h2>Problem with BBS Registration</h2>"
  142.     call lineout tempfile,' The user-name you selected, <b> ' arglist.!user ','
  143.     call lineout tempfile,' </b> is not available. Please select a different user-name '
  144.     call lineout tempfile, "</body></html>"
  145.     call lineout tempfile  /* close */
  146.     'FILE ERASE TYPE text/html NAME' tempfile
  147.      return 'BBS Registration disallowed: existing username '
  148. end
  149.  
  150.  
  151. /* write the user stuff */
  152. ll.1='; User file for : ' arglist.!user
  153. ll.2='Status: 0 0 0 0 0 '
  154. ll.3='User: ' arglist.!user ' ' arglist.!pwd
  155. ll.4='Privileges:  NEWUSER '
  156. ll.5='Name: ' arglist.!realname
  157. ll.6='Email: ' arglist.!email
  158. ll.7='Ratio : ' reqratio
  159. i7=7
  160. if own_download_dir<>' ' then do
  161.   atmp=own_download_dir||'\'||arglist.!user
  162.   foo=dosmakedir(atmp)
  163.   if foo<>0 then do
  164.      say " Created own_download_directory: " atmp
  165.      i7=i7+1
  166.      ll.i7='Download_dir: '||own_flag||' '||STRIP(own_download_dir)||'\'||STRIP(arglist.!user)
  167.   end
  168.   else do
  169.      say " Could not create own_download_directory: " atmp
  170.   end  /* Do */
  171.  
  172. end
  173. if own_upload_dir<>' ' then do
  174.   atmp=own_upload_dir||'\'||STRIP(arglist.!user)
  175.   foo=dosmakedir(atmp)
  176.   if foo<>0 then do
  177.      say " Created own_upload_directory: " atmp
  178.      i7=i7+1
  179.      ll.i7='Upload_dir: '||own_flag||' '||STRIP(own_upload_dir)||'\'||arglist.!user
  180.   end
  181.   else do
  182.      say " Could not create own_upload_directory: " atmp
  183.   end  /* Do */
  184. end
  185.  
  186.  
  187. if allargs<>' ' then do
  188.   do jj=1 to words(allargs)
  189.      oop0=word(allargs,jj) ; oop='!'||oop0
  190.      oop2=arglist.oop
  191.      jj2=jj+i7
  192.      ll.jj2=oop0':' oop2
  193.   end
  194. end
  195. jj2=jj2+1
  196. ll.jj2=';'
  197. jj2=jj2+1
  198. ll.jj2='Messages:'
  199. ll.0=jj2
  200.  
  201. foo=filewrite(tryit,ll)
  202. if foo=0  then do
  203.      say " ERROR: problem initializing user file "
  204.      foo=responsebbs('forbid','BBS new user registration is unavailable')
  205.      return foo||' Error in BBS users file ' tryit
  206. end  /* Do */
  207.  
  208. /* generic response if no response file given */
  209. if arglist.!hello=' ' then do
  210.     call lineout tempfile, '<!doctype html public "-//IETF//DTD HTML 2.0//EN">'
  211.     call lineout tempfile, "<html><head><title>BBS Registration</title></head>"
  212.     call lineout tempfile, "<body><h2>BBS Registration was Successful </h2>"
  213.     call lineout tempfile,' You have successfully registered. '
  214.     call lineout tempfile, "</body></html>"
  215.     call lineout tempfile  /* close */
  216. end
  217. else do
  218.    serverport=extract('serverport')
  219.    sel='http://'||servername
  220.    if serverport<>80 then sel=sel||':'||serverport
  221.     sel=sel||'/'||strip(arglist.!hello,'l','/')
  222.    'RESPONSE HTTP/1.0 302 Moved Temporarily'  /* Set HTTP response line */
  223.     call lineout tempfile, '<!doctype html public "-//IETF//DTD HTML 2.0//EN">'
  224.     call lineout tempfile, "<html><head><title>Successful BBS Registration</title></head>"
  225.    'HEADER ADD Location:' sel
  226.     call lineout tempfile, "<body><h2>Successful BBS Registration<</h2>"
  227.     call lineout tempfile, 'You can go to the BBS <a href="'sel'">now<a>.'
  228.     call lineout tempfile, "</body></html>"
  229.    call lineout tempfile  /* close */
  230. end
  231.  
  232. 'FILE ERASE TYPE text/html NAME' tempfile
  233.  
  234.  
  235. return 'BBS  new user registration was successful '
  236.  
  237.  
  238.  
  239.  
  240. /********************************************/
  241. responsebbs:procedure
  242.  parse arg  request,text,stuff
  243.  
  244.  
  245.   select
  246.     when request='badreq'   then use='400 Bad request syntax'
  247.     when request='notfound' then use='404 Not found'
  248.     when request='forbid'   then use='403 Forbidden'
  249.     when request='unauth'   then use='401 Unauthorized'
  250.     when request='notallowed' then use='405 Method not allowed'
  251.     when request='notimplemented' then use='501 Not implemented'
  252.     otherwise do
  253.         use='406 Not acceptable'
  254.         call pmprintf('weird response '|| request||' '|| message)
  255.       end
  256.     end  /* Add others to this list as needed */
  257.  
  258.  
  259.   /* Now set the response and build the response file */
  260.   'RESPONSE HTTP/1.0' use     /* Set HTTP response line */
  261.   parse var use code text
  262.   if request='notallowed' then do
  263.      'HEADER ADD Allow:HEAD '
  264.   end
  265.  
  266.   call lineout tempfile, '<!doctype html public "-//IETF//DTD HTML 2.0//EN">'
  267.   call lineout tempfile, "<html><head><title>"text"</title></head>"
  268.   call lineout tempfile, "<body><h2>Sorry...</h2>"
  269.   select
  270.     when request='unauth' then do
  271.         'header add WWW-Authenticate: Basic Realm=<'text'>'  /* challenge */
  272.        if stuff=' ' then
  273.          call lineout tempfile,' You are not authorized to visit this area of the bulletin board '
  274.        else
  275.          call lineout tempfile,' You must supply a Username if you wish to use this BBS '
  276.     end
  277.     when request='notfound' then
  278.       call lineout tempfile,' File is unavailable: ' stuff
  279.     when request='forbid' then
  280.       call lineout tempfile,' BBS is unavailable.'
  281.     otherwise
  282.        call lineout tempfile,' Request denied: ' stuff
  283.   end
  284.   call lineout tempfile, "</body></html>"
  285.   call lineout tempfile  /* close */
  286.  
  287.  
  288.   iia=dosdir(tempfile,'s')
  289.   'FILE ERASE TYPE text/html NAME' tempfile
  290.  
  291.  
  292.  
  293.   return word(use,1)||' '||iia
  294.  
  295.  
  296.  
  297.  
  298.