home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 35 Internet / 35-Internet.zip / srev13g.zip / HTACCFG.CMD < prev    next >
OS/2 REXX Batch file  |  1998-12-09  |  27KB  |  697 lines

  1. /*  */
  2. htaccfg:
  3.  
  4. CHECKIT=0   /* Change this to 0 if you want to enable REMOTE configuration by SUPERUSERS */
  5.  
  6. /* background color */
  7. USECOLOR='2dd52f'
  8.  
  9. /* ---------------- DO NOT MODIFY BELOW THIS LINE  ------------------ */
  10.  
  11.  
  12.  
  13. parse arg ddir,tempfile,sel,list,verb,uri,user,basedir,workdir,privset, ,
  14.                enmadd,transaction,verbose, ,
  15.               servername,host_nickname,homedir
  16.  
  17. if verb=" " then do
  18.     say " This SRE-http procedure is NOT meant to be run from the command line."
  19.    exit
  20. end  /* Do */
  21.  
  22. list=translate(list, ' ', '+'||'090a0d'x)  /* Whitespace, etc. */
  23. /* write results (2nd call */
  24. if pos('WRITETO=',translate(list))>0 then do
  25.    call writeres
  26.   return ' Results written '
  27. end
  28.  
  29.  
  30. who2=extract('CLIENTADDR')
  31. saddr2=extract('SERVERADDR')
  32.  
  33. NO_REM=VALUE('SREF_NO_REMOTE_CONFIG',,'OS2ENVIRONMENT')
  34.  
  35. select
  36.    when checkit=1 | no_rem>0 then do
  37.  
  38. /* only if user = serveraddress !!! */
  39.      if who2<>saddr2 | no_rem=2 then do
  40.  
  41.         call lineout tempfile, '<!doctype html public "-//IETF//DTD HTML 3.0//EN">'
  42.         call lineout tempfile, "<html><head><title>SRE-http  remote configurator disabled </title>"
  43.         call lineout tempfile, '</head><body  bgcolor="#'||usecolor||'"> '
  44.  
  45.  
  46.         call lineout tempfile,' <strong> Action not allowed remotely.</strong> <pre>'
  47.         call lineout tempfile,' </body> </html> '
  48.         call lineout tempfile
  49.         foo=sref_gos('FILE ERASE TYPE text/html NAME' tempfile)
  50.         return 'HTACCFG: action not allowed remotely. '
  51.      end
  52.    end
  53.    otherwise do
  54.       if wordpos('SUPERUSER',privset)=0 then do
  55.         'RESPONSE HTTP/1.1 401 Unauthorized '     /* Set HTTP response line */
  56.          att=sref_gmt()
  57.         'HEADER Noauto ADD Date: 'att
  58.  
  59.         'header add WWW-Authenticate: Basic Realm=<CONFIGURE>'  /* challenge */
  60.  
  61.         call lineout tempfile, '<!doctype html public "-//IETF//DTD HTML 3.0//EN">'
  62.         call lineout tempfile, "<html><head><title>Not authorized </title>"
  63.         call lineout tempfile, '</head><body  bgcolor="#'||usecolor||'"> '
  64.  
  65.         call lineout tempfile,' <strong> You do not have configuration rights.</strong> <pre>'
  66.         if who2=saddr2 then 
  67.                 call lineout tempfile,'<br> <Em> You may want to edit HTACCFG.CMD </em> '
  68.         call lineout tempfile,' </body> </html> '
  69.         call lineout tempfile
  70.          iia=dosdir(tempfile,'s')
  71.  
  72.         'FILE ERASE TYPE text/html NAME' tempfile
  73.         return '401 'iia' HTACCFG: not permitted to configure. '
  74.       end
  75.    end
  76. end
  77.  
  78.  
  79. htfile=' ' ;htacc=' '
  80. list=strip(list)
  81. DO UNTIL LIST=""
  82.     PARSE VAR  list a1 '&' list
  83.     parse var a1 avar '=' aval
  84.     if translate(avar)='HTFILE' then do
  85.          htfile=strip(translate(translate(packur(aval),'\','/')))
  86.          htfile=strip(htfile,'t','\')||'\'
  87.     end
  88.     if translate(avar)='ACCFILE' then
  89.          htacc=strip(translate(translate(packur(aval),'\','/')))
  90. end /* do */
  91. if left(htfile,1)='\' | pos(':',htfile)>0 then
  92.    nop
  93. else 
  94.    htfile=translate(ddir||htfile,'\','/')
  95.  
  96. if htacc=' ' then
  97.    htacc=get_value('htaccess_file')
  98.  
  99. if filespec('p',htfile)='\' then do
  100.    call lineout tempfile,' <h2> ' HTFILE ' not permitted </h2> '
  101.   call lineout tempfile,' Sorry, HTACCESS file can <strong>not</strong> be in the root'
  102.   call lineout tempfile, '</body> </html> '
  103.   call lineout tempfile
  104.   foo=sref_gos('file erase  type text/html name  ' tempfile)
  105.   return 'htaccess not allowed in root '
  106. end
  107. if htfile=' '| htacc=' ' then do
  108.    call lineout tempfile,' <h2> Missing information </h2> '
  109.   call lineout tempfile,' Sorry, the directory, or the name for the HTACCESS file,'
  110.   call lineout tempfile,' was not specified.'
  111.   call lineout tempfile, '</body> </html> '
  112.   call lineout tempfile
  113.   foo=sref_gos('file erase  type text/html name  ' tempfile)
  114.   return ' missing information '
  115. end /* do */
  116.  
  117.  
  118. HTFILE=STRIP(HTFILE); HTFILE=STRIP(HTFILE,'T','\')||'\'
  119. tmp1=get_htaccess(0,HTfile,HTACC,ddir,TEMPFILE,2)
  120.  
  121. parse var tmp1 gotlist ',' tmp1
  122. gotlist=strip(gotlist)
  123.  
  124. this1=htfile||htacc
  125. is1=stream(this1,'c','query exists')
  126.  
  127. vlist='GOTLIST AUTH.NAME AUTH.TYPE AUTH.USERFILE AUTH.GROUPFILE '
  128. vlist=vlist||'AUTH.INDEX REDIRECTFILE AUTH.LIMIT DIR.BUILD DIR.EXCLUDE '
  129. vlist=vlist||'DIR.INFO  DIR.DESCRIBE DIR.FORBID RX.BUILDdir RX.ENABLEPOSTPROCESS'
  130.  
  131. vlist2=' x AuthName AuthType AuthUserFile AuthGroupFile DefaultIndex RedirFile '
  132. vlist2=vlist2||' Limit BuildDir Dir.Exclude Dir.Info Dir.Describe Dir.Forbid '
  133. vlist2=vlist2||' Dir.Builder EnablePostProcess '
  134. gotlist0=gotlist
  135.  
  136. call lineout tempfile, '<!doctype html public "-//IETF//DTD HTML 3.0//EN">'
  137. call lineout tempfile, "<html><head><title>SRE-http HTACCESS configurator </title>"
  138. call lineout tempfile, '</head><body  bgcolor="#'||usecolor||'"> '
  139.  
  140. call lineout tempfile, "<h1> SRE-http: <A NAME="top"> HTACCESS Configurator </A>   </h1> <p>"
  141. call lineout tempfile,' <a href="#review"> Review current parameters & files for ' htfile '</a> ?'
  142.  
  143.  
  144. this1a=strip(this1,'t','.')
  145. foo=wordpos(translate(this1a),translate(gotlist))
  146. if foo>0 then do
  147.     gotlist=delword(gotlist,foo,1)
  148. end  /* Do */
  149.  
  150. call lineout tempfile,' <h2> For directory== ' translate(htfile) ' </h2>'
  151. call lineout tempfile,' <ul> '
  152. if is1=' ' then
  153.   call lineout tempfile,' <li> Currently, there is <strong> no</strong> HTACCESS file in: ' htfile
  154. else
  155.   call lineout tempfile,' <li> The HTACCESS file for ' htfile ' is: <strong> ' this1 '</strong>'
  156.  
  157.  
  158. if gotlist<>' ' then
  159.   call lineout tempfile,' <li> The set of HTACCESS files in the parent directories are: <strong> ' gotlist '</strong>'
  160.  
  161. call lineout tempfile,' </ul>'
  162.  
  163.  
  164. /* get "this files" parameter values (if accessible ) */
  165. if is1 =' ' then do
  166.    call lineout tempfile,' <hr width=30%> <h3> Creating: ' this1 ' </h3>  '
  167. /* initialize some variable */
  168.    auth.name=' '; auth.type=' ' ; auth.userfile=' ' ; auth.groupfile=' '
  169.    auth.index=' '; redirectfile=' '; auth.limit=' '; dir.exclude=' ';
  170.    dir.info=' ' ; dir.describe=' ' ; dir.forbid=' ' ; rx.builddir=' '
  171. end
  172. else do
  173.    tmp1=get_htaccess(0,HTfile,HTACC,ddir,TEMPFILE,3)
  174.  
  175.    do mm=1 to words(vlist)
  176.      parse var tmp1 aval ',' tmp1
  177.      avar=word(vlist,mm) ; aval=strip(aval)
  178.      call value avar,aval
  179.   end /* do */
  180.   call lineout tempfile,' <hr width=30%>  <h3> Modifying: ' this1 ' </h3>  '
  181. end
  182.  
  183. /* let user fill out form */
  184. CALL LINEOUT TEMPFILE,'<FORM ACTION="/HTACCFG" METHOD="POST">'
  185. call lineout tempfile,'<h3> Access control parameters </h3>'
  186.  
  187. ee=makeit('<b>One line comment:</b>','COMMENT',gotlist0,' ')
  188. call lineout tempfile,ee
  189.  
  190.  
  191. ee=makeit(' <p> <b>AuthName</b>: Authorization name (the REALM) ','AuthName',gotlist0,auth.name,10)
  192. call lineout tempfile,ee
  193.  
  194.  
  195. ischeck1=' ' ;IF translate(auth.type)='BASIC' then ischeck1='CHECKED'
  196. ischeck2=' ';IF translate(auth.type)='IDENT' then ischeck2='CHECKED'
  197. call lineout tempfile,' <p><b>AuthType</b>: Authorization type: '
  198. CALL LINEOUT TEMPFILE,' <INPUT TYPE=RADIO NAME="AuthType" VALUE="BASIC"' ISCHECK1 ' >BASIC ||'
  199. CALL LINEOUT TEMPFILE,'<INPUT TYPE=RADIO NAME="AuthType" VALUE="IDENT"' ISCHECK2 ' >IDENT '
  200.  
  201. ee=makeit('<b>AuthUserfile</b>: Userfile (contains usernames and passwords) ','AuthUserFile',gotlist0,auth.userfile)
  202. call lineout tempfile,ee
  203.  
  204. ee=makeit('<b>AuthGroupfile</b>: Group file (groups of users) ','AuthGroupFile',gotlist0,auth.groupfile)
  205. call lineout tempfile,ee
  206.  
  207.  
  208. if wordpos('REQUIRE',translate(auth.limit))=1 then
  209.    auth.limit=delword(auth.limit,1,1)
  210. ee=makeit('<b>Limit</b>:Allowed users list','Limit',gotlist0,auth.limit)
  211. call lineout tempfile,ee
  212.  
  213. call lineout tempfile, ' <p> <h3> Redirection, etc. parameters </h3>'
  214.  
  215. ee=makeit('<b>DefaultIndex</b>: Directory specific default documents ','DefaultIndex',gotlist0,auth.index)
  216. call lineout tempfile,ee
  217.  
  218. ee=makeit('<b>ReDirFile</b>: Redirection file ','ReDirFile',gotlist0,REDIRECTFILE)
  219. call lineout tempfile,ee
  220.  
  221.  
  222. call lineout tempfile,' <p><h3>Parameters used by dynamic directory list processor </h3>'
  223.  
  224. ischeck1=' ' ;IF dir.build=1 then ischeck1='CHECKED'
  225. ischeck2=' ';IF  dir.build=0 then ischeck2='CHECKED'
  226. call lineout tempfile,' <p> <B>BuildDir</b>:Enable dynamic directory list processor: '
  227. CALL LINEOUT TEMPFILE,' <INPUT TYPE=RADIO NAME="Builddir" VALUE="1"' ISCHECK1 ' >YES (allow) || '
  228. CALL LINEOUT TEMPFILE,'<INPUT TYPE=RADIO NAME="Builddir" VALUE="0"' ISCHECK2 ' >NO  (do not allow)'
  229.  
  230. ee=makeit('<b>Dir.Exclude</b>:Exclusion files (these files are not displayed) ', ,
  231.           'Dir.Exclude',gotlist0,dir.exclude)
  232. call lineout tempfile,ee
  233. ischeck1=' ' ;IF _diris=1 then ischeck1='CHECKED'
  234. ischeck0=' ';IF  _diris=0 then ischeck0='CHECKED'
  235. call lineout tempfile,' <br><blockquote> Reset list of exclusion files  '
  236. CALL LINEOUT TEMPFILE,'<menu> <li> <INPUT TYPE=RADIO NAME="_diris" VALUE="1" 'ischeck1' > YES (use _Dir.Exclude) '
  237. CALL LINEOUT TEMPFILE,'<li> <INPUT TYPE=RADIO NAME="_diris" VALUE="0" 'ischeck0'> NO  (use Dir.Exclude) </menu> </blockquote>'
  238.  
  239.  
  240.  
  241. ee=makeit('<b>Dir.Info</b>: Directory Info file (displayed at top of document) ', ,
  242.           'Dir.Info',gotlist0,dir.info)
  243. call lineout tempfile,ee
  244.  
  245.  
  246. ee=makeit('<b>Dir.Describe</b>:File description file (per entry descriptions) ', ,
  247.           'Dir.Describe',gotlist0,dir.describe)
  248. call lineout tempfile,ee
  249.  
  250. ee=makeit('<b>Dir.Builder:</b> Name of dynamic directory list processor ', ,
  251.           'Dir.Builder',gotlist0,rx.builddir)
  252. call lineout tempfile,ee
  253.  
  254. ischeck1=' ' ;IF dir.forbid=1 then ischeck1='CHECKED'
  255. ischeck2=' ';IF  dir.forbid=0 then ischeck2='CHECKED'
  256. call lineout tempfile,' <p><b>Dir.Forbid</b>: Prevent directory list processor from displaying directory: <menu>'
  257. CALL LINEOUT TEMPFILE,' <li> <INPUT TYPE=RADIO NAME="Dir.Forbid" VALUE="1"' ISCHECK1 ' >YES (do NOT allow display) '
  258. CALL LINEOUT TEMPFILE,'<li> <INPUT TYPE=RADIO NAME="Dir.Forbid" VALUE="0"' ISCHECK2 ' >NO  (allow display) </menu>'
  259.  
  260. ischeck=' '; if rx.enablepostprocess=' ' then ischeck='CHECKED'
  261. ischeck0=' ' ;IF rx.enablepostprocess=0 then ischeck0='CHECKED'
  262. ischeck1=' ' ;IF rx.enablepostprocess=1 then ischeck1='CHECKED'
  263. ischeck2=' ' ;IF rx.enablepostprocess=2 then ischeck2='CHECKED'
  264. call lineout tempfile,'<br> <b>EnablePostProcessor</b>: Post processing option: <menu>'
  265. CALL LINEOUT TEMPFILE,' <li><INPUT TYPE=RADIO NAME="EnablePostProcess" VALUE="0"' ISCHECK0 ' >Disable Post Processing ' 
  266. CALL LINEOUT TEMPFILE,' <li><INPUT TYPE=RADIO NAME="EnablePostProcess" VALUE=" "' ISCHECK ' >Enable for all files'
  267. CALL LINEOUT TEMPFILE,' <li><INPUT TYPE=RADIO NAME="EnablePostProcess" VALUE="1"' ISCHECK1 ' >Enable for all files .*HTM* extensions'
  268. CALL LINEOUT TEMPFILE,' <li><INPUT TYPE=RADIO NAME="EnablePostProcess" VALUE="2"' ISCHECK2 ' >Enable for ".SHTML" files only'
  269.  
  270. call lineout tempfile,'</menu>'
  271.  
  272.  
  273. call lineout tempfile,' <p>  <INPUT TYPE="reset" VALUE="reset"> <br>'
  274.  
  275. if is1=' ' then
  276.    call lineout tempfile,'  <INPUT TYPE="submit" VALUE="Create 'this1'"> '
  277. else do
  278.    call lineout tempfile,'<INPUT TYPE="submit" VALUE="Modify 'this1'"> '
  279.   call lineout tempfile,' <br> <Em> --- Caution: the old copy of ' this1 ' will be deleted! </em> '
  280. end
  281.  
  282.  
  283. call lineout tempfile,'<INPUT TYPE="hidden" name="WRITETO" VALUE="'this1'">'
  284. CALL LINEOUT TEMPFILE,'</FORM>'
  285.  
  286.  
  287. /* ------ TIPS AND HINTS SETCION */
  288.  
  289. call lineout tempfile,' <hr> <P> <HR> <a name="review"> <h3> Review: Parameters and Files </h3> </a>'
  290.  
  291. call lineout tempfile," Some notes on SRE-http's use of HTACCESS files "
  292. call lineout tempfile,'<br> For the most part, SRE-http emulates GOHTTP. '
  293. call lineout tempfile,' The following lists some potential differences: '
  294. call lineout tempfile,' <ul> <li> BASIC authorization uses only the "uppermost" HTACCESS file (rather then all of them)'
  295. call lineout tempfile,'<li> EnablePostProcess is ignored for non-file transfers (that is, it is ignored when server side processing are recieved)'
  296. call lineout tempfile,' <li>Dir.Builder works -- we recommend the "SHOWDIR" variant (see SHOWDIR.DOC for details) '
  297. call lineout tempfile,'<li>To invoke the Dir.Builder "dynamic directory list processsor", put !SHOWDIR at the end of the DefaultIndex list '
  298. call lineout tempfile,' <li> IDENT is a bit flaky (it works reasonably well if you * the portion before the @ )'
  299. call lineout tempfile,'</ul>'
  300. /* parameters from own and parent htaccess files */
  301.          tmp1=get_htaccess(0,HTfile,HTACC,ddir,TEMPFILE,2)
  302.  
  303. do mm=1 to words(vlist)
  304.    parse var tmp1 aval ',' tmp1
  305.    avar=word(vlist,mm) ; aval=strip(aval)
  306.    call value avar,aval
  307. end /* do */
  308. call lineout tempfile,' <hr width=30%> <h3> Effective parameters values for ' htfile ' </h3>  '
  309. call lineout tempfile,' These may include parameters set by HTACCESS files in parent directories <br>'
  310. if gotlist0=' ' then do
  311.    call lineout tempfile,' <BLOCKQUOTE> <strong> No HTACCESS parameters! </strong> </BLOCKQUOTE>'
  312. end  /* Do */
  313. else do
  314.   call lineout tempfile,'<dl>'
  315.   do mm=2 to words(vlist)  /* dont show gotlist */
  316.      avar=word(vlist,mm) ; avar2=word(vlist2,mm)
  317.      aval=value(avar)
  318.      call lineout tempfile,' <dt> <var> ' avar2 ' </var> <dd> ' aval
  319.   end /* do */
  320.   call lineout tempfile,'</dl> '
  321. end
  322.  
  323. /* ----- USER FILE */
  324. call lineout tempfile,' <HR WIDTH=30%> <H3> User file </h3>'
  325. call lineout tempfile,' Username/password file should have entries with the following syntax:<br>'
  326. call lineout tempfile,' <blockquote> USERNAME:PASSWORD </blockquote>'
  327. call lineout tempfile,' For example: <menu> <li> John:final1 <li> Sam:invidious <li> ; comment <li> wonder:womack </menu>'
  328. call lineout tempfile,' <h3> User file for: ' htfile' </h3>'
  329. if  auth.userfile=' ' then do
  330.  call lineout tempfile,' <blockquote><strong> No user file selected </strong> </blockquote>'
  331. end
  332. else do
  333.    call lineout tempfile,' Current user file is: <strong> ' auth.userfile '</strong> <p> '
  334.    foo=get_lines(auth.userfile)
  335.  
  336.    if foo>0  then do
  337.       call lineout tempfile,' Contents of ' auth.userfile ' <code> <ul>'
  338.  
  339.       do mm=1 to foo
  340.          alin=strip(somelines.mm)
  341.          if alin=' ' then iterate
  342.          if abbrev(alin,';')=1 then
  343.                 call lineout tempfile, '<li> <em>'alin ' </em> '
  344.          else
  345.                 call lineout tempfile, '<li> 'alin  
  346.       end /* do */
  347.       call lineout tempfile,'</ul>  </code>'
  348.     end
  349.     else do
  350.         call lineout tempfile,' <blockquote>  File does not exist: <strong> 'auth.userfile '</strong> </blockquote>'
  351.     end
  352. end  /* Do */
  353.  
  354.  
  355. /* ----- groups FILE */
  356. call lineout tempfile,' <HR WIDTH=30%> <H3> Groups file </h3>'
  357. call lineout tempfile,' The user Groups file should have entries with the following syntax:<br>'
  358. call lineout tempfile,' <blockquote> GROUPNAME: user1 user2 use33r@xx.yy.zz </blockquote>'
  359. call lineout tempfile,' For example: <menu> '
  360. call lineout tempfile,' <li> Detroit: phil george '
  361. call lineout tempfile,' <li> Boston:  joe *@dept1.school.edu '
  362. call lineout tempfile,' <em>  ... (note the use of the <strong>IDENT</strong> style name, and the * wildcard)</em>'
  363. call lineout tempfile,' <li> ; comment <li> Miami:  Cheryl Ruby Carlos </menu>'
  364. call lineout tempfile,' <h3> Groups file for: ' htfile ' </h3>'
  365. if  auth.groupfile=' ' then do
  366.  call lineout tempfile,' <blockquote><strong> No group file selected </strong> </blockquote>'
  367. end
  368. else do
  369.    call lineout tempfile,' Current group file is: <strong> ' auth.groupfile '</strong> <p> '
  370.    foo=get_lines(auth.groupfile)
  371.  
  372.    if foo>0  then do
  373.       call lineout tempfile,' Contents of ' auth.groupfile ' <code> <ul>'
  374.  
  375.       do mm=1 to foo
  376.          alin=strip(somelines.mm)
  377.          if alin=' ' then iterate
  378.          if abbrev(alin,';')=1 then
  379.                 call lineout tempfile, '<li> <em>'alin ' </em> '
  380.          else
  381.                 call lineout tempfile, '<li> 'alin  
  382.       end /* do */
  383.       call lineout tempfile,'</ul>  </code>'
  384.     end
  385.     else do
  386.         call lineout tempfile,' <blockquote>  File does not exist: <strong> 'auth.groupfile '</strong> </blockquote>'
  387.     end
  388. end  /* Do */
  389.  
  390. /* ----- redirectFILE */
  391. call lineout tempfile,' <HR WIDTH=30%> <H3> Redirection file </h3>'
  392. call lineout tempfile,' The Redirection file should have entries with the following syntax:<br>'
  393. call lineout tempfile,' <blockquote> old_url  : new_url  NOTIFY </blockquote>'
  394. call lineout tempfile, 'Where NOTIFY is optional (if present, redirection will NOT occur; instead, the client recieves a short notification) <p> '
  395. call lineout tempfile,' For example: <menu> '
  396. call lineout tempfile,' <li> zoo/sched.htm : http://www.newzoo.org/index.htm '
  397. call lineout tempfile,' <li> store/toys/*:  http://toys.newstore.com/inventory/*  NOTIFY '
  398. call lineout tempfile,' <em> ... (note the use of the * wildcard) </em> '
  399. call lineout tempfile,' <li> !CASE SENSITIVE  <em> ... (following entries are case sensitive) </em> '
  400. call lineout tempfile,' <li> candy/VANILLA.HTM :  /icecream/vanilla.htm  <EM> ... ( no http:// in the new_url implies redirect to same site) </em> '
  401. call lineout tempfile,'</menu> '
  402. call lineout tempfile,' <h3> Redirection file  for: ' htfile '</h3>'
  403. if  redirectfile=' ' then do
  404.  call lineout tempfile,' <blockquote><strong> No redirection file selected </strong> </blockquote>'
  405. end
  406. else do
  407.    call lineout tempfile,' Current  redirection file is: <strong> ' redirectfile '</strong> <p> '
  408.    foo=get_lines(redirectfile)
  409.  
  410.    if foo>0  then do
  411.       call lineout tempfile,' Contents of ' redirectfile ' <code> <ul>'
  412.  
  413.       do mm=1 to foo
  414.          alin=strip(somelines.mm)
  415.          if alin=' ' then iterate
  416.          if abbrev(alin,'!')=1 then
  417.                 call lineout tempfile, '<li> <em>'alin ' </em> '
  418.          else
  419.                 call lineout tempfile, '<li> 'alin  
  420.       end /* do */
  421.       call lineout tempfile,'</ul>  </code>'
  422.     end
  423.     else do
  424.         call lineout tempfile,' <blockquote>  File does not exist: <strong> 'redirectfile '</strong> </blockquote>'
  425.     end
  426. end  /* Do */
  427.  
  428.  
  429.  
  430.  
  431. call lineout tempfile,' </body> </html> '
  432. call lineout tempfile
  433.  
  434. foo=sref_gos('file erase  type text/html name  ' tempfile)
  435.  
  436. return 'Changes made, now submitting '
  437.  
  438.  
  439. /* do mm=1 to words(vlist)
  440.    parse var tmp1 aval ',' tmp1
  441.    avar=word(vlist,mm) ; aval=strip(aval) ; avar2=word(vlist2,mm)
  442.    if mm=1 then iterate 
  443.    call lineout tempfile,' <dt> <var> ' avar2 ' </var> <dd> ' aval
  444. end
  445. call lineout tempfile,' </dl> <p> '
  446. */
  447.  
  448.  
  449. makeit:procedure
  450. parse arg message,avar,gotlist0,aval,nshow
  451. if nshow=' 'then nshow=28
  452. if gotlist0=' ' then 
  453.   t1=' ' 
  454. else 
  455.   t1=aval
  456. rr=' <p> '|| message|| ':'
  457. rr=rr||' <INPUT TYPE="text" NAME="'||avar||'"  VALUE="'||t1||'"  SIZE='nshow' MAXLENGTH=85> '
  458. return rr
  459.  
  460.  
  461.  
  462.  
  463.  
  464. /* ----------- */                                                        
  465. /* get environment value, possibly host specific */                      
  466. /* ------------ */                                                       
  467. get_value: procedure expose enmadd host_nickname usecolor
  468. parse arg vname,hname0
  469. if hname0=0 then 
  470.         hname=' '
  471. else                                                    
  472.     hname=strip(host_nickname)                          
  473.  
  474. vname=strip(vname) ;
  475. if hname<>' ' then do                                                    
  476.    aval=value(enmadd||vname||'.'||hname,,'os2environment')               
  477.    if aval<>' ' Then                                                     
  478.         return aval                                                      
  479. end                                                                      
  480. aval=value(enmadd||vname,,'os2environment')                              
  481. return aval                   
  482.  
  483.  
  484. /* write results routine */
  485. writeres:
  486. list0=list
  487. do until list=""
  488.     parse var list a1 '&' list
  489.     parse upper var a1 avar '=' aval
  490.     if avar='WRITETO' then do
  491.        htout=strip(packur(aval))
  492.        leave
  493.     end  /* Do */
  494. end /* do */
  495. foo=sysfiledelete(htout)
  496. foo=lineout(htout,,1)
  497. _diris=0
  498. if pos('_DIRIS=1',upper(list0))>0 then _diris=1
  499. list=list0
  500. do until list=""
  501.     parse var list a1 '&' list
  502.     parse var a1 avar '=' aval
  503.     avar=strip(packur(avar));
  504.     aval=strip(packur(aval));
  505.  
  506.     if translate(avar)='_DIRIS' then iterate
  507.     if translate(avar)='WRITETO' then iterate
  508.     if translate(avar)='LIMIT' then aval=' require '||aval
  509.     if translate(avar)='COMMENT' then avar='; ' 
  510.     if translate(avar)='DIR.EXCLUDE' & _diris=1 then
  511.         avar='_'||avar
  512.     if aval \=' ' then
  513.         call lineout htout,avar ':' aval
  514. end
  515. call lineout htout
  516.  
  517. call lineout tempfile, '<!doctype html public "-//IETF//DTD HTML 3.0//EN">'
  518. call lineout tempfile, "<html><head><title>SRE-http HTACCESS configurator </title>"
  519. call lineout tempfile, '</head><body  bgcolor="#'||usecolor||'"> '
  520.  
  521. call lineout tempfile, "<h1> SRE-http: <A NAME="top"> HTACCESS Configurator </A>   </h1> <p>"
  522. call lineout tempfile,' Results were written to ' htout
  523.  
  524. call lineout tempfile, '</body> </html> '
  525. call lineout tempfile
  526. foo=sref_gos('file erase  type text/html name  ' tempfile)
  527.  
  528. return 0
  529.  
  530.  
  531. /* ----------------------------------------------------------------------- */
  532. /* get_HTACCESS --- a modification of Don Meyer's CHECKAUTH & other stuff:
  533.  
  534. This will CHECK all the accessfilenames in the tree underneath
  535. file for access privileges, etc.  
  536.  
  537. For details on how to set up an accessfile, see
  538.      http://w3.ag.uiuc.edu/DLM/GOHTTP/Auth.Guide.html
  539.  
  540.  
  541. ENABLEPOSTPROCESS (use the post_filter stuff), and _DIR.BUILDER
  542.  
  543.  
  544. When dodirs=2, return ALL parameters (used by htaccess configurator)
  545. Dodirs=3, just the "own directory" (if it exists)
  546.  
  547.  
  548. */
  549.  
  550. /* ----------------------------------------------------------------------- */
  551. get_htaccess:procedure expose _diris
  552.  
  553.   parse arg sel,file,accessfilename,dir,TEMPFILE,dodirs
  554.  
  555.   file = translate( file, '/', '\')
  556.  
  557.   dir.exclude=' '
  558.   PathTo = ''
  559.   rest = file
  560.   retCode = 0
  561.   gotlist=' '
  562.   set=' '
  563.  
  564. /* initialize some variable */
  565. auth.name=' '; auth.type=' ' ; auth.userfile=' ' ; auth.groupfile=' '
  566. auth.index=' '; redirectfile=' '; auth.limit=' '; dir.exclude=' ';
  567. dir.info=' ' ; dir.describe=' ' ; dir.forbid=' ';rx.builddir=' '
  568. _diris=0
  569. rx.enablepostprocess=' '
  570. dir.build=0 ; rx.builddir=' '
  571.  
  572.  
  573.   owndir=filespec('d',file)||filespec('p',file)
  574.   owndir=translate(translate(owndir,'/','\'))
  575.   owndir=strip(owndir,'t','/')
  576.  
  577. /* find htaccess files;
  578.    and if found, extract the parameters, starting at base of directory tree
  579.    (thus, own htaccess file is favored */
  580.  
  581.   do while (rest \= '')
  582.     restdoggy=right(rest,1)
  583.     parse var rest _dir'/'rest
  584.     if (right( _dir,1) == ':') then PathTo = _dir
  585.     else PathTo = PathTo'/'_dir
  586.  
  587.     if dodirs==3 then do;
  588.           if translate(pathto) \= owndir then do
  589.                 iterate
  590.           end
  591.     end
  592.  
  593.     goofy=rest ; if goofy=' ' & restdoggy='/' then goofy='/'
  594.     if (left(PathTo,3) == '///') then 
  595.            PathTo = substr(PathTo,2)
  596.     else if (goofy \= '')  & (right( _dir,1) \= ':') then do
  597.          geek1=pathto'/'accessfilename
  598.          ACLfile = stream(geek1, 'c', 'query exists')
  599.  
  600.  
  601.       if (ACLfile \= '') then do /* if not, climb up the tree */
  602.          gotlist=gotlist' 'aclfile
  603.          Auth.GroupFile = ' '
  604.          Auth.Limit = ' '
  605.          rc = stream( ACLfile, 'c', 'OPEN READ')
  606.          line = linein( ACLfile, 1)
  607.          do while (line \= '')
  608.             do while( pos(left(line,1), "2009"x) > 0); line = substr(line, 2); end
  609.             if ( pos(left(line,1), "#") > 0) then line = substr(line, 2)
  610.             if ( left(line,1) == ';') then line = ';COMMENT'
  611.  
  612.             parse var line key ':' val
  613.             val = strip(val)
  614.             key = translate(key)
  615.             if (key = 'AUTHUSERFILE') | (key = 'AUTHGROUPFILE') | (key = 'REDIRLIST') then do
  616.                if (pos(':', val ) == 0) then do
  617.                   val = translate(val, '\', '/')
  618.                   if (left(val,1) == '\') then val = substr( val, 2)
  619.                   val = dir || val
  620.                end
  621.             end
  622.             select
  623.                when (key = 'AUTHNAME') then Auth.Name = val
  624.                when (key = 'AUTHTYPE') then Auth.Type = translate( strip(val))
  625.                when (key = 'AUTHUSERFILE') then Auth.UserFile = val
  626.                when (key = 'AUTHGROUPFILE') then Auth.GroupFile = val
  627.                when (key = 'DEFAULTINDEX') then Auth.Index = val
  628.                when (key = 'REDIRLIST') then RedirectFile = val
  629.                when (key = 'REDIRFILE') then RedirectFile = val  /* bug? in original code */
  630.                when (key = 'LIMIT') then    Auth.Limit = val
  631.                when (key = 'BUILDDIR') then Dir.Build = (val \= '0')
  632.                when (key = 'DIR.EXCLUDE') then Dir.Exclude = Dir.Exclude val
  633.                when (key = '_DIR.EXCLUDE') then do
  634.                       Dir.Exclude = val
  635.                       _diris=1
  636.                end  /* Do */
  637.                when (key = 'DIR.INFO') then Dir.Info = val
  638.                when (key = 'DIR.DESCRIBE') then Dir.Describe = val
  639.                when (key = 'DIR.FORBID') then Dir.Forbid = (val \= '0')
  640.                when (key = 'DIR.BUILDER') then Rx.BuildDir = val
  641.                when (key = 'ENABLEPOSTPROCESS') then do
  642.                      v = left(strip(val),1)
  643.                      if (pos(v, '012') > 0) then Rx.EnablePostProcess = v
  644.                   end
  645.                otherwise 
  646.             end
  647.  
  648.             line = linein( ACLfile)
  649.          end
  650.          rc = stream( ACLfile, 'c', 'close')
  651.  
  652.        end                /* this aclfile */
  653.     end          /* goofy */
  654.   end                       /* climbing up directory tree */
  655.  
  656.     bigone=gotlist', 'auth.name', 'auth.type', 'auth.userfile', 'auth.groupfile
  657.     bigone=bigone', 'auth.index', 'redirectfile', 'auth.limit', 'dir.build
  658.     bigone=bigone', 'dir.exclude', 'dir.info', 'dir.describe', 'dir.forbid', 'rx.builddir
  659.     bigone=bigone', 'rx.enablepostprocess
  660.   return bigone
  661.  
  662.     
  663.  
  664.  
  665.  
  666. /* get file line by line . Return in somelines. variable */
  667.  
  668. get_lines:procedure expose somelines.
  669.  
  670. parse arg afile
  671. crlf='0d0a'x
  672.  
  673. mm=0
  674.  
  675. foo=stream(afile,'c','query exists')
  676. if foo=' ' then do
  677.    somelines.0=0
  678.    return 0
  679. end
  680.  
  681. foo=charin(afile,1,chars(afile))
  682. foo=strip(foo,'t','1a'x)
  683. a=stream(afile,'c','close')
  684.  
  685. do until foo=''
  686.    parse var foo  aline (crlf) foo
  687.    mm=mm+1
  688.    somelines.mm=aline
  689. end
  690. somelines.0=mm
  691.  
  692. return mm
  693.  
  694.  
  695.  
  696.  
  697.