home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 35 Internet / 35-Internet.zip / srev13h.zip / REALMCFG.CMD < prev    next >
OS/2 REXX Batch file  |  1999-06-27  |  38KB  |  1,085 lines

  1. /*  */
  2. realmcfg:
  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. parse arg ddir,tempfile,sel,list,verb,uri,user,basedir,workdir,privset,enmadd,transaction,verbose, ,
  12.          servername,host_nickname
  13.  
  14.  
  15. if verb="" then do
  16.    say " This SRE-http add-on is NOT meant to be run from the command line."
  17.    say " It can be invoked by using CONFIGUR.HTM "
  18.    exit
  19. end  /* Do */
  20.  
  21.  
  22. list=translate(list, ' ', '+'||'090a0d'x)  /* Whitespace, etc. */
  23.  
  24. crlf='0d0a'x
  25. who2=extract('CLIENTADDR')
  26. saddr2=extract('SERVERADDR')
  27. sport=extract('SERVERPORT')
  28.  
  29. NO_REM=VALUE('SREF_NO_REMOTE_CONFIG',,'OS2ENVIRONMENT')
  30.  
  31. select
  32.    when checkit=1 | (checkit>=0 & no_rem>0) then do
  33.  
  34. /* only if user = serveraddress !!! */
  35.      if who2<>saddr2 | no_rem=2 then do
  36.  
  37.         call lineout tempfile, '<!doctype html public "-//IETF//DTD HTML 3.0//EN">'
  38.         call lineout tempfile, "<html><head><title>SRE-http remote configurator disabled </title>"
  39.         call lineout tempfile, '</head><body  bgcolor="#'||usecolor||'">'
  40.  
  41.         call lineout tempfile,' <strong> Action not allowed remotely.</strong> <pre>'
  42.         call lineout tempfile,' </body> </html> '
  43.         call lineout tempfile
  44.         foo=sref_gos('FILE ERASE TYPE text/html NAME' tempfile)
  45.         return 'REALMCFG: action not allowed remotely. '
  46.      end
  47.    end
  48.    otherwise do
  49.       if wordpos('SUPERUSER',privset)=0 then do
  50.         'RESPONSE HTTP/1.1 401 Unauthorized '     /* Set HTTP response line */
  51.          att=sref_gmt()
  52.         'HEADER Noauto ADD Date: 'att
  53.  
  54.         'header add WWW-Authenticate: Basic Realm=<CONFIGURE>'  /* challenge */
  55.  
  56.         call lineout tempfile, '<!doctype html public "-//IETF//DTD HTML 3.0//EN">'
  57.         call lineout tempfile, "<html><head><title>Not authorized </title>"
  58.         call lineout tempfile, '</head><body  bgcolor="#'||usecolor||'">'
  59.  
  60.         call lineout tempfile,' <strong> You do not have configuration rights.</strong> <pre>'
  61.         if who2=saddr2 then 
  62.                 call lineout tempfile,'<br> <Em> You may want to edit REALMCFG.CMD </em> '
  63.         call lineout tempfile,' </body> </html> '
  64.         call lineout tempfile
  65.          iia=dosdir(tempfile,'s')
  66.  
  67.         'FILE ERASE TYPE text/html NAME' tempfile
  68.         return '401 'iia ' REALMCFG: not permitted to configure. '
  69.       end
  70.    end
  71. end
  72.  
  73. list=strip(list)
  74. select 
  75.    when upper(list)='TODO=SHOW' | upper(list)='TODO=SHOW_HEADER' then
  76.         signal doshow
  77.    when upper(list)='TODO=SET' then
  78.         signal doset
  79.    when abbrev(translate(list),'MATCH')+abbrev(translate(list),'TODO=MATCH')>0 then
  80.         signal findmatch
  81.    when abbrev(translate(list),'TODO=TEMPSHOW')=1 then
  82.         signal showdeftemp
  83.    otherwise
  84.         signal dochange
  85. end  /* select */
  86.  
  87.  
  88. /* jump here to show values */
  89. doshow:
  90.  
  91.  
  92. realmfile=get_realmfile(host_nickname)
  93. if realmfile='' then do
  94.   call lineout tempfile, '<!doctype html public "-//IETF//DTD HTML 3.0//EN">'
  95.   call lineout tempfile, "<html><head><title>REALMCFG: no ATTRIBS.CFG file </title></head><body>"
  96.   call lineout tempfile, 'Sorry, there is no ATTRIBS.CFG file defined for 'servername '(w/host_nickname: 'host_nickname
  97.   call lineout tempfile,'</body></html>'
  98.   call lineout tempfile
  99.   foo=sref_gos('file erase  type text/html name  ' tempfile)
  100.   return ' done '
  101. end /* do */
  102.  
  103. aa=sref_fileread(realmfile,'lins',,'E')
  104.    call lineout tempfile, '<!doctype html public "-//IETF//DTD HTML 3.0//EN">'
  105.    call lineout tempfile, "<html><head><title>SRE-http: Realm Definitions </title>"
  106.    call lineout tempfile, '</head><body  bgcolor="#'||usecolor||'">'
  107.  
  108.  
  109. call lineout tempfile, "<h1> SRE-http:  Realm Definitons  </h1> <p>"
  110.  
  111. if upper(list)='TODO=SHOW' then
  112.    call lineout tempfile, "<h2> List of "header" comments </h2> <pre> <blockquote>"
  113. else
  114.    call lineout tempfile, "<h2> Description of realm entries </h2> <pre> <blockquote>"
  115.  
  116. /* show "header comments" */
  117. iat=0
  118. do until iat >= lins.0
  119.    iat=iat+1
  120.    if  abbrev(strip(lins.iat),';')  then do
  121.         foo=strip(lins.iat) ;foo=strip(foo,'l',';')
  122.          call lineout tempfile, foo 
  123.    end  /* Do */
  124.    else do
  125.         leave
  126.    end
  127. end /* do -- iat is the first non header comment line  */
  128. call lineout tempfile, '</blockquote></pre> '
  129.  
  130. /* view descriptive header only? */
  131. if upper(list)='TODO=SHOW_HEADER' then do
  132.    call lineout tempfile,' <hr> </body></html>'
  133.    call lineout tempfile
  134.    foo=sref_gos('file erase  type text/html name  ' tempfile)
  135.    return ' done '
  136. end  /* Do */
  137.  
  138.  
  139.  
  140. /* read in definitions etc */
  141. nusers=0
  142.  
  143. call lineout tempfile, ' <hr> <h2> List of realms</h2>  '
  144.  
  145. call lineout tempfile,' Notes: <ul> '
  146. if host_nickname='' then
  147.    call lineout tempfile,' <li> Realm definitions, etc. (for the "default host") are stored in: ' realmfile
  148. else
  149.    call lineout tempfile,' <li> Realm definitions, etc. (for the 'host_nickname' host") are stored in: ' realmfile
  150.  
  151. call lineout tempfile,' <li> <em>Comments are in italics </em> '
  152. call lineout tempfile, ' <li> Entries with no <strong>host nickname</strong> apply to all requests '
  153. call lineout tempfile,'</ul>'
  154.  
  155. call lineout tempfile,' <hr> Thanks for checking </body></html>'
  156. call lineout tempfile
  157.  
  158. foo=sref_gos('file erase  type text/html name  ' tempfile)
  159. return ' done '
  160.  
  161. /* jump here if "tempshow" chosen */
  162. showdeftemp:
  163. d1=value(enmadd||'tempdata_dir',,'os2environment')
  164. d2=stream(d1||'\$DFREALM.'||sport,'c','query exists')
  165. if d2='' then do
  166.    astring=' There are no REALMS defined ('d1||'\$DFREALM.'||sport||' does not exist)'
  167.    foo=sref_gos('var type text/plain name  ',astring)
  168.    return foo
  169. end /* do */
  170. foo=sref_gos('file type text/plain name  ' d2)
  171. return foo
  172.  
  173.  
  174. /* jump here if "match sel" chosen */
  175. findmatch:
  176. realmfile=get_realmfile(host_nickname)
  177. if realmfile='' then do
  178.   call lineout tempfile, '<!doctype html public "-//IETF//DTD HTML 3.0//EN">'
  179.   call lineout tempfile, "<html><head><title>REALMCFG: no ATTRIBS.CFG file </title></head><body>"
  180.   call lineout tempfile, 'Sorry, there is no ATTRIBS.CFG file defined for 'servername '(w/host_nickname: 'host_nickname
  181.   call lineout tempfile,'</body></html>'
  182.   call lineout tempfile
  183.   foo=sref_gos('file erase  type text/html name  ' tempfile)
  184.   return ' done '
  185. end /* do */
  186.  
  187. aa=sref_fileread(realmfile,'lins',,'E')
  188. kk=lins.0+1
  189. lins.kk=''
  190. lins.0=kk  /* put an elephant in cairo */
  191. call lineout tempfile, '<!doctype html public "-//IETF//DTD HTML 3.0//EN">'
  192. call lineout tempfile, "<html><head><title>SRE-http: match an ATTRIBS entry </title>"
  193. call lineout tempfile, '</head><body  bgcolor="#'||usecolor||'">'
  194.  
  195. call lineout tempfile,'<!--  a button bar. --> 'crlf ,
  196.            '<a href="/configur.htm">Configurator</a>||' crlf ,
  197.            '<a href="/config2?todo=SET">Parameters</a>||' crlf ,
  198.            '<a href="/usercfg?todo=SET">Usernames</a>||'  crlf ,
  199.            '<a href="/realmcfg?todo=SET">Define-Realms</a>||'||crlf ,
  200.            '<a href="/accescfg?todo=SET">Access-Controls||'  crlf ,
  201.            '<a href="/aliascfg?todo=SET">Aliases</a>||'  crlf ,
  202.            '<a href="/virtcfg?todo=SET">VirtualDir</a><p>'  
  203.  
  204.  
  205. /* note: ignore header stuff */
  206. iat=0
  207.  
  208. /* parse it */
  209. parse var list '=' asel
  210.  
  211. asel=strip(asel,'l','/')
  212. CALL GET_ENTRIES
  213.  
  214. if host_nickname='' then
  215.   call lineout tempfile,'For server at:<tt>' servername '</tt>    '
  216. else
  217.   call lineout tempfile,'Current host=<tt>' servername '<em> (w/nickname: 'host_nickname' </em></tt>    '
  218. call lineout tempfile, ' <em> # of entries='nentries'</em>'
  219.  
  220. call lineout tempfile, '<p>Find match for: <tt>'asel'</tt>'
  221.  
  222.  
  223. gotit=0 ; RESU=' '
  224.  
  225. /* if superceding host, then first check host-specific entries */
  226. if abbrev(host_nickname,'_!')<>1 then  do
  227.   do mm=1 to nentries
  228.      if realm.mm='' then iterate   /* not a realm def */
  229.      if host.mm<>host_nickname then iterate          /* not this host */
  230.      do ll=1 to words(rules.mm)
  231.          arule=strip(word(rules.mm,ll))
  232.          arule=strip(arule,'l','/')
  233.          aresu=sref_wild_match(asel,arule,resu)
  234.          if aresu=0 then iterate     /* no match */
  235.          if aresu=-1 then do  /* exact match */
  236.            gotit=mm
  237.            leave mm
  238.         end                     /* exact */
  239.         resu=aresu
  240.         GOTIT=MM             /* if here, better match found */
  241.      end                        /* words in rules */
  242.    end                  /* nentries */
  243. end
  244.  
  245. /* no host specfic match, and not stricet superceding host? try defaults */
  246. if gotit=0 & abbrev(host_nickname,'_!!')=0 then do
  247.   do mm=1 to nentries
  248.      if realm.mm='' then iterate   /* not a realm def */
  249.      if host.mm<>host_nickname & host.mm<>'' then iterate          /* not this host */
  250.      do ll=1 to words(rules.mm)
  251.          arule=strip(word(rules.mm,ll))
  252.          arule=strip(arule,'l','/')
  253.          aresu=sref_wild_match(asel,arule,resu)
  254.          if aresu=0 then iterate     /* no match */
  255.          if aresu=-1 then do  /* exact match */
  256.            gotit=mm
  257.            leave mm
  258.         end                     /* exact */
  259.         resu=aresu
  260.         GOTIT=MM             /* if here, better match found */
  261.      end                        /* words in rules */
  262.    end                  /* nentries */
  263.  
  264. end
  265.  
  266. call lineout tempfile,'<blockquote>'
  267.  
  268. if gotit=0 then do
  269.  call lineout tempfile,'<b>No match! </b>'
  270. end
  271. else do
  272.   call lineout tempfile,'Entry #'gotit
  273.   rm=realm.gotit
  274.   if subrealm.gotit<>'' then rm=rm'.'subrealm.gotit
  275.   if crealm.gotit=1 then rm=rm '<em>(superceding)</em>'
  276.   call lineout tempfile,'<br>Realm: <b>'rm
  277.   call lineout tempfile,'</b><br>Rule: <tt>'rules.gotit'</tt>'
  278. end
  279. call lineout tempfile,'</blockquote>'
  280.  
  281. call lineout tempfile,'</body></html>'
  282. call lineout tempfile
  283.  
  284. foo=sref_gos('file erase  type text/html name  ' tempfile)
  285. return foo
  286.  
  287.  
  288.  
  289. /* jump here if "set values" chosen */
  290. doset:
  291. realmfile=get_realmfile(host_nickname)
  292. if realmfile='' then do
  293.   call lineout tempfile, '<!doctype html public "-//IETF//DTD HTML 3.0//EN">'
  294.   call lineout tempfile, "<html><head><title>REALMCFG: no ATTRIBS.CFG file </title></head><body>"
  295.   call lineout tempfile, 'Sorry, there is no ATTRIBS.CFG file defined for 'servername '(w/host_nickname: 'host_nickname
  296.   call lineout tempfile,'</body></html>'
  297.   call lineout tempfile
  298.   foo=sref_gos('file erase  type text/html name  ' tempfile)
  299.   return ' done '
  300. end /* do */
  301.  
  302. aa=sref_fileread(realmfile,'lins',,'E')
  303. kk=lins.0+1
  304. lins.kk=''
  305. lins.0=kk  /* put an elephant in cairo */
  306.  
  307. call lineout tempfile, '<!doctype html public "-//IETF//DTD HTML 3.0//EN">'
  308. call lineout tempfile, "<html><head><title>SRE-http: modify realm entries </title>"
  309. call lineout tempfile, '</head><body  bgcolor="#'||usecolor||'">'
  310.  
  311. call lineout tempfile,'<!--  a button bar. --> 'crlf ,
  312.            '<a href="/configur.htm">Configurator</a>||' crlf ,
  313.            '<a href="/config2?todo=SET">Parameters</a>||' crlf ,
  314.            '<a href="/usercfg?todo=SET">Usernames</a>||'  crlf ,
  315.            '<a href="/realmcfg?todo=SET">Define-Realms</a>||'||crlf ,
  316.            '<a href="/accescfg?todo=SET">Access-Controls||'  crlf ,
  317.            '<a href="/aliascfg?todo=SET">Aliases</a>||'  crlf ,
  318.            '<a href="/virtcfg?todo=SET">VirtualDir</a><p>'  
  319.  
  320. /* note: ignore header stuff */
  321. iat=0
  322.  
  323. /* parse it */
  324.  
  325. CALL GET_ENTRIES
  326. call lineout tempfile, "<h1 align="center"> SRE-http: modify <A NAME="top">realm</A> definitions </h1> <p>"
  327. if host_nickname<>'' then do
  328.    call lineout tempfile,' <h4 align="center"> For host: 'servername' (w/nickname:'host_nickname ' </h4>'
  329. end
  330. else do
  331.    call lineout tempfile,' <h4 align="center"> For the "default" host </h4>'
  332. end /* do */
  333.  
  334. call lineout tempfile,' Use this form to modify/remove/add realm definitions, users, and replacement strings.'
  335. call lineout tempfile,' <br><em> Questions? <A HREF="#notes">The notes might help.</A> </em>  '
  336.  
  337. call lineout tempfile,' <blockquote><table border=1><tr><td>'
  338. call lineout tempfile,'<em>Would you like to </em> match a selector to a REALM: '
  339. call lineout tempfile,'<FORM ACTION="/realmcfg" METHOD="GET">'
  340. call lineout tempfile,'<input type="text" name="MATCH" size=40>'
  341. call lineout tempfile,' <input type="submit" value="Match this selector"> </form> '
  342. call lineout tempfile,' </table></blockquote>'
  343.  
  344. call lineout tempfile,' <h2> Modify or remove realm definitions </h2>'
  345. call lineout tempfile,'<FORM ACTION="/realmcfg" METHOD="POST">'
  346.  
  347. call lineout tempfile,' <table border=1>'
  348.  
  349. /* Display "realm" entries */
  350. do mm=1 to nentries
  351.  call lineout tempfile,'<tr>'
  352.  call add_acell mm,'Entry # 'mm 'of 'nentries
  353. end
  354. call lineout tempfile,' </table>'
  355.  
  356. /* --- allow user to enter a realm definition */
  357. call lineout tempfile,'  <p> <h2> Add a realm definition </h2> <table border=1>'
  358. mm=nentries+1
  359. call add_acell mm,' New Entry '
  360. call lineout tempfile,'</table> <p>'
  361.  
  362. /* --- allow user to enter a username */
  363. mm=nentries+2
  364. call lineout tempfile,'  <p> <h2> Add a username</h2> <table border=1>'
  365.    call lineout tempfile,'<td valign="top"><em>New User</em><br>'
  366.    if host_nickname='' then do
  367.      call lineout tempfile,'<tt>Host:</tt>  <INPUT TYPE="text" NAME="host.'||mm||'"'
  368.      call lineout tempfile,'value="'host.mm'" SIZE=10  > <br> '
  369.      call lineout tempfile,'<br> <tt>Port:</tt> <INPUT TYPE="text" NAME="port.'||mm||'"'
  370.      call lineout tempfile,'value="'port.mm'" SIZE=6 >  '
  371.    end
  372.    else do
  373.      call lineout tempfile,'<tt>Host:</tt> 'host_nickname
  374.      call lineout tempfile,'<br> <tt>Port:</tt> 'sport
  375.    end
  376.    call lineout tempfile,'<td><tt>Username:</tt>  <INPUT TYPE="text" NAME="user.'||mm||'"'
  377.    call lineout tempfile,'value="'user.mm'" SIZE=12  >  '
  378.  
  379.    call lineout tempfile,'<br><tt>Password:</tt>  <INPUT TYPE="text" NAME="rules.'||mm||'"'
  380.    call lineout tempfile,'value="'rules.mm'" SIZE=12  > <br> '
  381.  
  382.   call lineout tempfile,'<br><tt>Privileges:</tt>  <INPUT TYPE="text" NAME="privs.'||mm||'"'
  383.   call lineout tempfile,'value="'privs.mm'" SIZE=32  > <br> '
  384.  
  385. call lineout tempfile,'</table> <p>'
  386.  
  387. mm=nentries+3
  388. call lineout tempfile,'  <p> <h2> Add a replacement string</h2> <table border=1>'
  389.    call lineout tempfile,'<td valign="top"><em>Replacement string</em><br>'
  390.    if host_nickname='' then do
  391.      call lineout tempfile,'<tt>Host:</tt>  <INPUT TYPE="text" NAME="host.'||mm||'"'
  392.      call lineout tempfile,'value="'host.mm'" SIZE=10  > <br> '
  393.      call lineout tempfile,'<br> <tt>Port:</tt> <INPUT TYPE="text" NAME="port.'||mm||'"'
  394.      call lineout tempfile,'value="'port.mm'" SIZE=6 >  '
  395.    end
  396.    else do
  397.      call lineout tempfile,'<tt>Host:</tt> 'host_nickname
  398.      call lineout tempfile,'<br> <tt>Port:</tt> 'sport
  399.    end
  400.  
  401.  
  402.    call lineout tempfile,'<td><tt>Replace:</tt>  <INPUT TYPE="text" NAME="replace.'||mm||'"'
  403.    call lineout tempfile,'value="'replace.mm'" SIZE=22  >  '
  404.    call lineout tempfile,'<br><tt> with:</tt>  <INPUT TYPE="text" NAME="rules.'||mm||'"'
  405.    call lineout tempfile,'value="'rules.mm'" SIZE=55  > <br> '
  406.  
  407. call lineout tempfile,'</table> <p>'
  408.  
  409.  
  410. /* ----- add comments information */
  411.  
  412. call lineout tempfile,' <input type="hidden" name="nhiddens" value="'||hiddens.0||'">'
  413. do jj=1 to nhidden
  414.   boo=hiddens.jj
  415.   boo=sref_replacestrg(boo,'"','"','ALL')
  416.   boo=sref_replacestrg(boo,'<','<','ALL')
  417.   boo=sref_replacestrg(boo,'>','>','ALL')
  418.   call lineout tempfile,'<input type="hidden" name="hiddens.'jj'" value="'boo'">'
  419. end /* do */
  420.  
  421. call lineout tempfile,' <input type="hidden" name="nentries" value="'||mm||'">'
  422. call lineout tempfile,' <input type="submit" value="Make these changes"> <input type="reset"> </form> '
  423.  
  424. call lineout tempfile,' <hr> <h3> <A NAME="notes">Notes </A></h3> '
  425. if host_nickname='' then
  426.    call lineout tempfile,' <li> Realm definitions, etc. (for the "default host") are stored in: ' realmfile
  427. else
  428.    call lineout tempfile,' <li> Realm definitions, etc. (for the 'host_nickname' host) are stored in: ' realmfile
  429.  
  430. call lineout tempfile, ' <li> To remove an entry, clear the realm:field (or set it to 0)'
  431.  
  432. call lineout tempfile, ' <li> When defining a realm, you <em>must </em> specify the realm: and rules:  '
  433. call lineout tempfile, ' <li> Rules: can contain multiple entries; with each entry seperated by a space, or on a seperate line '
  434. call lineout tempfile, ' <li> The valid LIMITLIST values are:<tt>!HTML, !CGI-BIN, !ADDONS, and !UPLOAD </tt>'
  435. call lineout tempfile, ' <li> Entries with no <strong>host nickname</strong> will apply to all requests'
  436. call lineout tempfile, ' <li> You can select multiple permissions'
  437. call lineout tempfile, ' <li> A blank requires:, or if requires: contains a *, means open access'
  438.  
  439. call lineout tempfile,' <li> See <a href="/samples/in_files.doc">IN_FILES.DOC</a> for details on  realm definitions'
  440.  
  441. call lineout tempfile,' <li> Would you like to view the<a href="/realmcfg?todo=tempshow">'
  442. call lineout tempfile,'the working copy of ATTRIBS.CFG</a>'
  443.  
  444. call lineout tempfile,'</ul>'
  445.  
  446. call lineout tempfile,' <h3> A list of the <A NAME="hosts">current hosts</A> </h3>  <blockquote> '
  447. ii=value(enmadd||'HOSTS.0',,'os2environment')
  448. if ii=0 then do
  449.    call lineout tempfile,'<strong>There are no hosts defined</strong>'
  450. end 
  451. else do
  452.   hlist=sref_value('$HOSTS.0',,'USE')
  453.   call lineout tempfile,' <table> <th> IP address </th> <th> Host Nickname </th> <th> Data Directory </th> <tr> '
  454.   do ll=1 to words(hlist)
  455.       hh=strip(translate(word(hlist,ll)))
  456.       wow=sref_value('$HOSTS.'||hh,,'use')
  457.       parse var wow ip ',' hn ',' hdir
  458.      call lineout tempfile,' <td> ' ip  '</td> <td> ' hn ' </td> <td> ' hdir '</td> <tr> '
  459.   end /* do */
  460.   call lineout tempfile,' </table> </blockquote>'
  461. end
  462.  
  463. call lineout tempfile,' <p> <A HREF="#top">Return to the top of this form.</A>'
  464.  
  465. call lineout tempfile,'</body></html>'
  466. call lineout tempfile
  467.  
  468. foo=sref_gos('file erase  type text/html name  ' tempfile)
  469. return foo
  470.  
  471.  
  472.  
  473. /***********************************/
  474. /* PARSE INTO ENTRIES  */
  475. GET_ENTRIES:
  476.  
  477. ison=0
  478. nhidden=0; nentries=0
  479. hiddens.0=0
  480. this.=''
  481. realm.=''; subrealm.=''; host.=''; port.=''; crealm.=''
  482. rules.=''; permissions.=''; requires.=''
  483. advopts.=''; failfile.='' ; limitlist.=''
  484. redirect.='';redirect2.=''
  485. opts.=''
  486. include.=''
  487. user.='' ; privs.=''
  488. replace.=''
  489.  
  490. DO MM=1 TO LINS.0
  491.    ALINE=strip(lins.mm)
  492.    if abbrev(aline,';')=1 then do
  493.        nhidden=nhidden+1
  494.        hiddens.nhidden=aline
  495.        hiddens.0=nhidden
  496.        iterate
  497.    end
  498.    if aline='' & ison=0 then iterate /* multiple emptys */
  499.    if aline=' ' then do         /* blank line signals end of entry */
  500.        nentries=nentries+1
  501.        realm.nentries=this.!realm
  502.        subrealm.nentries=this.!subrealm
  503.        crealm.nentries=this.!crealm
  504.  
  505.        host.nentries=this.!host
  506.        port.nentries=this.!port
  507.        rules.nentries=this.!rules     
  508.  
  509.        user.nentries=this.!user
  510.        privs.nentries=this.!privs
  511.        replace.nentries=this.!replace
  512.  
  513.        permissions.nentries=this.!permissions
  514.        requires.nentries=this.!requires
  515.        advopts.nentries=this.!advopts
  516.        opts.nentries=this.!opts
  517.        failfile.nentries=this.!failfile
  518.        limitlist.nentries=this.!limitlist
  519.  
  520.        redirect.nentries=this.!redirect
  521.        redirect2.nentries=this.!redirect2
  522.        include.nentries=this.!include
  523.        this.=''
  524.        ison=0
  525.        iterate
  526.    end /* do */
  527.    
  528. /* otherwise, an action */
  529.     ison=1
  530.    if pos(':',aline)>0 then
  531.      parse var aline action ':' options
  532.    else
  533.       parse var aline action options 
  534.    action=strip(translate(translate(action),' ',':='))
  535.    options=strip(options)
  536.    select
  537.       when action='PORT' then do
  538.         if options='' then options=80
  539.         this.!port=options
  540.       end
  541.       when action='REALM' then do
  542.          if options='' then iterate
  543.          parse var options options crealm
  544.          parse var options this.!realm '.' this.!subrealm
  545.          this.!crealm=0
  546.          if wordpos(translate(strip(crealm)),'1 C S SUPERCEDING SUPER COMPLETE')>0 then
  547.            this.!crealm=1
  548.       end 
  549.  
  550.       when abbrev(action,'REPL')=1 then do 
  551.           this.!REPLACE=strip(translate(options))
  552.       end 
  553.       when abbrev(action,'WITH')=1 then do 
  554.           this.!RULES=options
  555.       end 
  556.  
  557.       when abbrev(action,'USER')=1 then do 
  558.           this.!USER=strip(translate(options))
  559.       end 
  560.       when abbrev(action,'PWD')+abbrev(action,'PASS')>0 then do 
  561.           this.!RULES=strip(options)
  562.       end 
  563.       when abbrev(action,'PRIV')>0 then do 
  564.           this.!PRIVS=strip(options)
  565.       end 
  566.  
  567.       when action='INCLUDE' then do
  568.          if options='' then iterate
  569.          this.!include=options
  570.       end 
  571.       when action='HOST' then do
  572.           this.!HOST=translate(options)
  573.       end 
  574.       when action='INCLUDE' then do
  575.           this.!INCLUDE=translate(options)
  576.       end 
  577.  
  578.       when abbrev(action,'REQ')=1 then do 
  579.           this.!REQUIRES=translate(options)
  580.       end 
  581.       when abbrev(action,'PERM')=1 then do 
  582.           this.!permissions=translate(options)
  583.       end 
  584.       when abbrev(action,'RUL')=1 then do
  585.         this.!RULES=this.!rules' 'options
  586.       end
  587.       when abbrev(action,'ADV')=1 then do
  588.         this.!ADVOPTS=options
  589.       end /* do */
  590.       when abbrev(action,'OPT')=1 then do
  591.         this.!OPTS=this.!opts||'0d0a'x||options
  592.       end /* do */
  593.  
  594.      when abbrev(action,'FAIL')=1 then do
  595.         this.!FAILFILE=options
  596.       end /* do */
  597.      when abbrev(action,'LIMIT')=1 then do
  598.         this.!LIMITLIST=options
  599.       end /* do */
  600.  
  601.      when wordpos(action,'REDIRECT NEGOTIATE LITERAL ALIAS VIRTUAL MOVED MOVE TEMP TEMPMOVE TEMPMOVED PERMMOVE PERMMOVED')>0 then do
  602.          options2=translate(options,' ','=')
  603.          parse var options2 a1  a2 
  604.          a2=strip(a2)
  605.          if words(options2)=1 then a2=a1  /* action=alias, etc */
  606.          a1=strip(translate(a1))
  607.          select   
  608.            when abbrev(a1,"SEL")+abbrev(a1,'INTERN')=1 | action="ALIAS" then do
  609.              this.!REDIRECT='ALIAS'
  610.              this.!redirect2=a2
  611.            end 
  612.            when a1="DIR" | action="VIRTUAL" then do
  613.              this.!REDIRECT='VIRTUAL'
  614.              this.!REDIRECT2=a2
  615.            end 
  616.            when a1="LITERAL" | action="LITERAL" then do
  617.              this.!REDIRECT='LITERAL'
  618.              this.!REDIRECT2=a2
  619.            end 
  620.            when a1="NEGOTIATE" | action="NEGOTIATE" then do
  621.              this.!REDIRECT='NEGOTIATE'
  622.              this.!REDIRECT2=a2
  623.            end 
  624.  
  625.            when abbrev(a1,"PERM")+abbrev(a1,'MOVE')>0 | abbrev(action,"MOVE")=1 then do
  626.              this.!REDIRECT='MOVE'
  627.              this.!REDIRECT2=a2
  628.            end 
  629.            when abbrev(a1,"TEMP")=1 | abbrev(action,"TEMP")=1 then do
  630.               this.!REDIRECT='TEMP'
  631.               this.!REDIRECT2=a2
  632.            end 
  633.            otherwise  do
  634.              nhidden=nhidden+1
  635.              hiddens.nhidden=aline
  636.              hiddens.0=nhidden
  637.            end
  638.          end               /* which kind of redirect */
  639.       end               /* action=redirect */
  640.       otherwise  do
  641.              nhidden=nhidden+1
  642.              hiddens.nhidden=aline
  643.              hiddens.0=nhidden
  644.       end
  645.   end                /* action */
  646.    
  647. end /* lins.0 */
  648. return 1
  649.  
  650.  
  651. /***********************************/
  652. /* add a realm def cell */
  653. add_acell:
  654. parse arg mm,amess
  655. call lineout tempfile,'<td valign="top"><em>'amess'</em><br>'
  656.  
  657. if user.mm='' & replace.mm='' then do
  658.   call lineout tempfile,' <b><tt>Realm:</tt></b> <INPUT TYPE="text" NAME="realm.'||mm||'"'
  659.   call lineout tempfile,'value="'realm.mm'" SIZE=14  > <br> '
  660.   call lineout tempfile,'<b><tt>subRealm:</tt></b> <INPUT TYPE="text" NAME="subrealm.'||mm||'"'
  661.   call lineout tempfile,'value="'subrealm.mm'" SIZE=14  > <br> '
  662.   if crealm.mm=1 then
  663.      call lineout tempfile,'<br><input type="checkbox" value=1 checked name="crealm.'||mm||'"><em>Superceding realm?</em>'
  664.   else
  665.      call lineout tempfile,'<br><input type="checkbox" value=1 name="crealm.'||mm||'"><em>Superceding realm?</em>'
  666. end
  667. if host_nickname='' then do
  668.   call lineout tempfile,'<br><tt>Host:</tt>  <INPUT TYPE="text" NAME="host.'||mm||'"'
  669.   call lineout tempfile,'value="'host.mm'" SIZE=10  > <br> '
  670.   call lineout tempfile,'<br> <tt>Port:</tt> <INPUT TYPE="text" NAME="port.'||mm||'"'
  671.   call lineout tempfile,'value="'port.mm'" SIZE=6 >  '
  672. end
  673. else do
  674.   call lineout tempfile,'<br><tt>Host:</tt> 'host_nickname
  675.   call lineout tempfile,'<br> <tt>Port:</tt> 'sport
  676. end /* do */
  677.  
  678. if include.mm<>'' then do
  679.   call lineout tempfile,'<td><tt>Include file:</tt>  <INPUT TYPE="text" NAME="include.'||mm||'"'
  680.   call lineout tempfile,'value="'include.mm'" SIZE=20  > <br> '
  681.   return 2
  682. end /* do */
  683.  
  684. if user.mm<>'' then do
  685.   call lineout tempfile,'<td><tt>Username:</tt>  <INPUT TYPE="text" NAME="user.'||mm||'"'
  686.   call lineout tempfile,'value="'user.mm'" SIZE=12  >  '
  687.  
  688.   call lineout tempfile,'<br><tt>Password:</tt>  <INPUT TYPE="text" NAME="rules.'||mm||'"'
  689.   call lineout tempfile,'value="'rules.mm'" SIZE=12  > <br> '
  690.  
  691.   call lineout tempfile,'<br><tt>Privileges:</tt>  <INPUT TYPE="text" NAME="privs.'||mm||'"'
  692.   call lineout tempfile,'value="'privs.mm'" SIZE=32  > <br> '
  693.   return 3
  694. end
  695.  
  696. if replace.mm<>'' then do
  697.   call lineout tempfile,'<td><tt>Replace:</tt>  <INPUT TYPE="text" NAME="replace.'||mm||'"'
  698.   call lineout tempfile,'value="'replace.mm'" SIZE=22  >  '
  699.  
  700.   call lineout tempfile,'<br><tt> with:</tt>  <INPUT TYPE="text" NAME="rules.'||mm||'"'
  701.   call lineout tempfile,'value="'rules.mm'" SIZE=55  > <br> '
  702.   return 4
  703. end
  704.  
  705.  
  706.  
  707. /* else, a selector=specific attribite ntry */
  708. call lineout tempfile,'  <td> <tt>Rules:</tt><textarea name="rules.'||mm||'" cols=50 rows=1>'||strip(rules.mm)||'</textarea>'
  709.  
  710. if subrealm.mm=''then do
  711.   call lineout tempfile,'<hr width="66%">  <tt>Requires:</tt>'
  712.   call lineout tempfile,' <INPUT TYPE="text" NAME="requires.'||mm||'"'
  713.   call lineout tempfile,'value="'requires.mm'" SIZE=40  > <br> '
  714. end
  715. else do
  716.   call lineout tempfile,'<hr width="66%">  <tt>Requires:</tt>'
  717.   call lineout tempfile,' <INPUT TYPE="hidden" NAME="requires.'||mm||'"'
  718.   call lineout tempfile,'value=""><em>using value for realm <tt> 'realm.mm'</tt></em> <br> '
  719. end /* do */
  720.  
  721. call lineout tempfile,' <br> <tt>Permissions:</tt>'
  722. permlist='NOCACHE CACHE CACHE* PUT DELETE YES_SSI  NO_SSI  NO_SSP NO_CODE NO_HTACCESS NO_VIRTUAL NO_ALIAS NO_POSTFILTER'
  723. aperm=permissions.mm
  724. call lineout tempfile,' <select name="PERMISSIONS.'||mm'" size=4 multiple>'
  725. do mz=1 to 5
  726.     pw=strip(word(permlist,mz))
  727.     ass='' ; if wordpos(pw,aperm)>0 then ass='SELECTED'
  728.     call lineout tempfile,'<option value="'pw'" 'ass'>'pw
  729. end /* do */
  730. call lineout tempfile,'</select>'
  731. call lineout tempfile,' <select name="PERMISSIONS.'||mm'" size=4 multiple>'
  732. do mz=6 to 9
  733.     pw=strip(word(permlist,mz))
  734.     ass='' ; if wordpos(pw,aperm)>0 then ass='SELECTED'
  735.     call lineout tempfile,'<option value="'pw'" 'ass'>'pw
  736. end /* do */
  737. call lineout tempfile,'</select>'
  738. call lineout tempfile,' <select name="PERMISSIONS.'||mm'" size=4 multiple>'
  739. do mz=10 to words(permlist)
  740.     pw=strip(word(permlist,mz))
  741.     ass='' ; if wordpos(pw,aperm)>0 then ass='SELECTED'
  742.     call lineout tempfile,'<option value="'pw'" 'ass'>'pw
  743. end /* do */
  744. call lineout tempfile,'</select>'
  745.  
  746. call lineout tempfile,'<p><tt>Redirect:</tt> <Select name="redirect.'||mm||'" size=3>'
  747. selecto.=''
  748. if redirect2.mm='' then redirect.mm=''
  749.  
  750. ill=wordpos(redirect.mm,'VIRTUAL ALIAS MOVE TEMP LITERAL NEGOTIATE ')
  751. if ill=0 then ill=7
  752.  
  753. selecto.ill.0='SELECTED'
  754.  
  755. selecto.1='VIRTUAL'
  756. selecto.2='ALIAS'
  757. selecto.3='MOVE'
  758. selecto.4='TEMP'
  759. selecto.5='LITERAL'
  760. selecto.6='NEGOTIATE'
  761.  
  762. selecto.7='NONE'
  763.  
  764. selecto.1.1='Virtual (dir) '
  765. selecto.2.1='Internal (selector) '
  766. selecto.3.1='Permanent (301) '
  767. selecto.4.1='Temporary (302) '
  768. selecto.5.1='Literal'
  769. selecto.6.1='Content Negotiation'
  770.  
  771. selecto.7.1='No redirection'
  772.  
  773. do mmm=1 to 7
  774.    call lineout tempfile,'<option value="'selecto.mmm'" 'selecto.mmm.0'>'selecto.mmm.1
  775. end
  776. call lineout tempfile,'</select>'
  777. call lineout tempfile, '  <tt> to</tt>:  '
  778. call lineout tempfile,'<INPUT TYPE="text" NAME="redirect2.'||mm||'"'
  779. call lineout tempfile,'value="'redirect2.mm'" SIZE=30> <p> '
  780.  
  781. call lineout tempfile,'<table><tr><th align="left">AdvOpts file</th><th align="left">AdvOpts list</th>'
  782. call lineout tempfile,'<tr><td> <INPUT TYPE="text" NAME="advopts.'||mm||'"'
  783. call lineout tempfile,'value="'advopts.mm'" SIZE=20> </td>'
  784. call lineout tempfile,'<td> <textarea NAME="opts.'||mm||'"'
  785. call lineout tempfile,' Cols=30 Rows=2>'opts.mm'</textarea></td> </table> <br>'
  786. call lineout tempfile,'<br><tt>Failure file:</tt>  <INPUT TYPE="text" NAME="failfile.'||mm||'"'
  787. call lineout tempfile,'value="'failfile.mm'" SIZE=20  > <br> '
  788. call lineout tempfile,'<br><tt>Virtual Dir Limit-list:</tt>  <INPUT TYPE="text" NAME="limitlist.'||mm||'"'
  789. call lineout tempfile,'value="'limitlist.mm'" SIZE=20  > <br> '
  790.  
  791.  
  792. call lineout tempfile, '  '
  793.  
  794.  
  795. return 1
  796.  
  797.  
  798.  
  799. /******************** jump here to record changes */
  800. dochange:
  801. ili=0
  802. hidlist.=''
  803. globs.=''
  804. nentries=0; nhiddens=0
  805. do until list=""
  806.    parse var list aa '&' list
  807.   parse var aa avar '=' aval
  808.   parse var avar avar '.' aind
  809.   avar=translate(strip(avar))
  810.   aind=translate(strip(aind))
  811.   aval=strip(packur(aval))
  812.   select
  813.      when avar='NENTRIES' then nentries=aval
  814.      when avar='NHIDDENS' then nhiddens=aval
  815.      otherwise do
  816.         if avar='HIDDENS' then do
  817.              hidlist.aind=aval
  818.         end /* do */
  819.         else do
  820.          rt='!'||avar
  821.          if avar='PERMISSIONS' then
  822.             globs.rt.aind=globs.rt.aind' 'aval
  823.          else
  824.             globs.rt.aind=aval
  825.         end
  826.      end
  827.   end  /* select */
  828. end /* do */
  829.  
  830.  
  831. if nentries+nhiddens=0 then do
  832.   call lineout tempfile, '<!doctype html public "-//IETF//DTD HTML 3.0//EN">'
  833.   call lineout tempfile, "<html><head><titLE> Nothing to change (REALMCFG) </title></head>"
  834.   call lineout tempfile, '<body> Form contained no information (REALMCFG) </body></html>'
  835.   call lineout tempfile
  836.   foo=sref_gos('FILE ERASE TYPE text/html NAME ' tempfile)
  837.   return foo
  838. end
  839.  
  840. realmfile=get_realmfile(host_nickname)
  841. if realmfile='' then do
  842.   call lineout tempfile, '<!doctype html public "-//IETF//DTD HTML 3.0//EN">'
  843.   call lineout tempfile, "<html><head><title>REALMCFG: no ATTRIBS.CFG file </title></head><body>"
  844.   call lineout tempfile, 'Sorry, there is no ATTRIBS.CFG file defined for 'servername '(w/host_nickname: 'host_nickname
  845.   call lineout tempfile,'</body></html>'
  846.   call lineout tempfile
  847.   foo=sref_gos('file erase  type text/html name  ' tempfile)
  848.   return ' done '
  849. end /* do */
  850.  
  851. aa=sref_fileread(realmfile,'lins',,'E')
  852.  
  853. /* save to realmfile.. but rename old realm file*/
  854. foo=lastpos('.',realmfile)
  855. if foo=0 then
  856.    acf1=realmfile||'.'
  857. else
  858.    acf1=left(realmfile,foo)
  859. do hi=1 to 999
  860.    try1=acf1||hi
  861.    if stream(acf1||hi,'c','query exists')='' then leave
  862. end /* do */
  863. foo=dosrename(realmfile,try1)
  864.  
  865. /* write out header lines */
  866. newlines.=''
  867. inew=0
  868. do mm=1 to nhiddens
  869.    inew=inew+1
  870.    newlines.inew=hidlist.mm
  871. end /* do */
  872. inew=inew+1
  873.  
  874. /* write out entries */
  875. do mm=1 to nentries
  876.    inew=inew+1
  877.  
  878.    if globs.!USER.mm<>'' then do
  879.      inew=inew+1
  880.      newlines.inew='Port: 'globs.!port.mm   
  881.      inew=inew+1
  882.      newlines.inew='Host: 'globs.!host.mm   
  883.      inew=inew+1
  884.      newlines.inew='USER: 'globs.!user.mm   
  885.      inew=inew+1
  886.      newlines.inew='PWD: 'globs.!rules.mm   
  887.      inew=inew+1
  888.      newlines.inew='PRIVS: 'globs.!privs.mm   
  889.      iterate
  890.    end /* do */
  891.  
  892.    if globs.!REPLACE.mm<>'' then do
  893.      inew=inew+1
  894.      newlines.inew='Port: 'globs.!port.mm   
  895.      inew=inew+1
  896.      newlines.inew='Host: 'globs.!host.mm   
  897.      inew=inew+1
  898.      newlines.inew='REPLACE: 'globs.!replace.mm   
  899.      inew=inew+1
  900.      newlines.inew='WITH: 'globs.!rules.mm   
  901.      iterate
  902.    end /* do */
  903.  
  904.  
  905.    if globs.!REALM.mm='' then iterate /* skip this entry */
  906.    inew=inew+1
  907.    rr=globs.!realm.mm
  908.    if globs.!subrealm.mm<>'' then rr=rr||'.'||globs.!subrealm.mm
  909.    if globs.!crealm.mm=1 then rr=rr' C'
  910.    newlines.inew='Realm: 'rr
  911.    inew=inew+1
  912.    newlines.inew='Port: 'globs.!port.mm   
  913.    inew=inew+1
  914.    newlines.inew='Host: 'globs.!host.mm   
  915.    inew=inew+1
  916.  
  917.    if globs.!include.mm<>'' then do
  918.       inew=inew+1
  919.       newlines.inew='Include: 'globs.!include.mm   
  920.       iterate
  921.    end    
  922.  
  923.    newlines.inew='Rules: 'globs.!rules.mm   
  924.    if globs.!subrealm.mm='' then do
  925.      inew=inew+1
  926.      newlines.inew='Requires: 'globs.!requires.mm   
  927.    end
  928.  
  929.    if translate(globs.!redirect.mm)<>'NONE' then do
  930.        oof=globs.!redirect.mm
  931.        inew=inew+1
  932.        newlines.inew=oof': 'globs.!redirect2.mm   
  933.    end
  934.  
  935.    if translate(globs.!permissions.mm)<>'' then do
  936.      inew=inew+1
  937.      newlines.inew='Permissions: 'globs.!permissions.mm  
  938.    end
  939.  
  940.    if translate(globs.!limitlist.mm)<>'' then do
  941.       inew=inew+1
  942.       newlines.inew='LIMITLIST: 'globs.!limitlist.mm  
  943.    end
  944.    
  945.    if globs.!failfile.mm<>'' then do
  946.       inew=inew+1
  947.       newlines.inew='FailFile: 'globs.!failfile.mm   
  948.    end    
  949.    if globs.!advopts.mm<>'' then do
  950.       inew=inew+1
  951.       newlines.inew='AdvOpts: 'globs.!advopts.mm   
  952.    end    
  953.    if globs.!opts.mm<>'' then do
  954.       oop=globs.!opts.mm
  955.       do forever
  956.          if oop='' then leave
  957.          parse var oop aoop '0d0a'x oop
  958.          if aoop='' then iterate
  959.          inew=inew+1
  960.          newlines.inew='Option: 'aoop
  961.       end /* do */
  962.    end    
  963.  
  964.  
  965. end /* do */
  966. newlines.0=inew
  967. gfoo=sref_filewrite(realmfile,newlines,'R')
  968.  
  969.  
  970. call lineout tempfile, '<!doctype html public "-//IETF//DTD HTML 3.0//EN">'
  971. call lineout tempfile, "<html><head><titLE> SRE-http: Changed the realm definitions</title>"
  972. call lineout tempfile, '</head><body  bgcolor="#'||usecolor||'">'
  973. if gfoo<>1 then do
  974.    call lineout tempfile,'<b>ERROR:</b> Could not write 'realmfile
  975. end /* do */
  976. else do
  977.   call lineout tempfile,' <h2>The realm definitions have been changed </h2>'
  978.   call lineout tempfile,' The list of realm definitions has been saved to: ' realmfile
  979.   call lineout tempfile,' <p> The old version of 'realmfile' has been moved to ' try1
  980.   call lineout tempfile,'<p> <a href="/config2b.htm">Return to Intermediate Mode Configurator</a>'
  981. end
  982. call lineout tempfile,' </body> </html> '
  983. call lineout tempfile
  984.  
  985. foo=value('SREF_REDO',1,'os2environment')
  986.  
  987.  
  988. foo=sref_gos('FILE ERASE TYPE text/html NAME ' tempfile)
  989.  
  990. return foo
  991.  
  992.  
  993.  
  994. /***********************************/
  995. /* Get generic, or host specific, attribs.cfg file */
  996. get_realmfile:procedure  expose sport
  997. parse arg hn
  998.  
  999. if hn='' then do
  1000.    realmfile=value('SREF_defrealm_FILE',,'os2environment')
  1001. end
  1002. else do /* check cfglist.cfg for first host specific attribs: file */
  1003.   realmfile=chk_cfglist(hn)
  1004. end 
  1005.  
  1006. if realmfile<>'' then
  1007.    realmfile=stream(realmfile,'c','query exists')
  1008.  
  1009. return realmfile
  1010.  
  1011.  
  1012. /* ---------------------------------------------- */
  1013. /* read ATTRIBs from cfglist_File */
  1014. chk_cfglist:procedure expose sport
  1015.  
  1016. parse upper arg hn
  1017.  
  1018. cf=value('SRE_CFGS_DIR',,'os2environment')
  1019. cfglist_file=cf||'\CFGLIST.CFG'
  1020.  
  1021. /* look for files */
  1022. foo=translate(stream(cfglist_file,'c','open read'))
  1023. if abbrev(foo,'READY')<>1 then do
  1024.   call pmprintf('SRE-http REALMCFG: Unable to open: 'cfglist_file)
  1025.   return ''            /* unable to open */
  1026. end
  1027. inj=stream(cfglist_file,'c','query size')
  1028. if inj=0 | inj='' then return   ''        /* empty file, nothing to add */
  1029.  
  1030. astuff=charin(cfglist_file,1,inj)
  1031. foo=stream(cfglist_file,'c','close')
  1032.  
  1033.  
  1034.  
  1035. crlf='0d0a'x
  1036. astuff=astuff||crlf||' '        /* place an elephant in cairo */
  1037. nustuff=''
  1038.  
  1039. /* find an ATTRIBS: entry, for this port and host, by readling CFGLIST.CFG */
  1040. mm=0
  1041.  
  1042. /* note: file is organized in blocks */
  1043. aport=80              /* defaults port and host */
  1044. ahost='' ; afile=''
  1045.  
  1046. do forever              /* for all blocks in file */
  1047.   if astuff='' then leave       /* all done  (note we always put an elephant in cairo */
  1048.   parse var astuff aline (crlf) astuff
  1049.   if abbrev(aline,';')=1 then iterate   /* ignore comments */
  1050.   if aline='' then do           /* block end */
  1051.      if afile<>''  then do      /* attribs was mentioned */
  1052.         if aport=sport & hn=ahost then do  /* this is a match! */
  1053.             ill=stream(afile,'c','query size')
  1054.  
  1055.             if ill=0 | ill='' then do  /* try looking in cfgsdir */
  1056.                  baa=cf'\'afile
  1057.                  ill=stream(baa,'c','query size')
  1058.                  if ill<>0 & ill<>'' then afile=baa
  1059.              end
  1060.              if ill<>0 & ill<>'' then return afile
  1061.         end
  1062.      end 
  1063.      ahost=''           /* not this entry, so reset stuff */
  1064.      afile=''
  1065.      aport=80
  1066.      iterate
  1067.    end
  1068.  
  1069. /* else, more lines in this "block" */
  1070.    parse upper var aline ltype ':' lstuff ;
  1071.    ltype=strip(ltype) ; lstuff=strip(lstuff)
  1072.  
  1073.    select
  1074.        when ltype='PORT' then aport=lstuff
  1075.        when ltype='HOST' then ahost=lstuff
  1076.        when abbrev(ltype,'ATTR')=1 then afile=lstuff
  1077.        otherwise nop
  1078.    end /* select */
  1079.  
  1080. end
  1081.  
  1082. return ''                       /* no match */
  1083.  
  1084.  
  1085.