home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 35 Internet / 35-Internet.zip / srev13h.zip / BYCLIENT.RXX < prev    next >
Text File  |  1998-09-21  |  5KB  |  146 lines

  1. /* the "by client" INTERPRETable addon for SRE-http 
  2.    See ByCLIENT.DOC for usage instructions */
  3.  
  4. userdir=filespec('d',usedfile)||filespec('p',usedfile)
  5.  
  6. /* Determine .USR file */
  7. parse arg usrfile;usrfile=strip(usrfile)
  8. if usrfile<>'' then do   /* use specified .usr file */
  9.   usrfile=translate(usrfile,'/','\')
  10.   if abbrev(usrfile,'/')=0 then 
  11.       usedfile=userdir||usrfile
  12.   else                /* virtual file */
  13.     USEDFILE=sref_do_virtual(ddir,usrFILE,enmadd,0,homedir,host_nickname)
  14. end     
  15. else do   /* use .usr file with same name as requesting doc */
  16.    ap=lastpos('.',usedfile)
  17.    if ap=0 then do
  18.        usedfile=usedfile'.USR'
  19.    end
  20.    else do
  21.        usedfile=left(usedfile,ap)'USR'
  22.    end
  23. end
  24. usedfile=translate(usedfile,'\','/')
  25.  
  26. /* if not exists, return '' */
  27. if stream(usedfile,'c','query exists')='' then return ''
  28.  
  29. oo=sref_open_read(usedfile,30)
  30. if oo<0 then return ''          /* giveup */
  31. holdem=charin(usedfile,1,chars(usedfile))
  32. foo=stream(usedfile,'c','close')
  33. if verbose>2 then say "ByCLIENT: .USR file="usedfile
  34.  
  35. /* parse the .USR file */
  36. tt=0 ; crlf='0d0a'x; cids.0=0; cprivs.0=0; cips.0=0
  37. do until holdem=''
  38.    parse var holdem aline (crlf) holdem ; aline=strip(aline)
  39.    if aline='' then iterate
  40.    if abbrev(aline,';')=1 then iterate
  41.    parse upper var aline atype afil ids 
  42.    atype=strip(atype)
  43.    select
  44.      when abbrev(atype,'COOK')=1 then do
  45.          tt1=cids.0+1
  46.          cids.tt1.!file=afil ; cids.tt1.!ids=ids
  47.          cids.0=tt1
  48.      end
  49.      when abbrev(atype,'PRIV') then do
  50.          tt1=cprivs.0+1
  51.          cprivs.tt1.!file=afil ; cprivs.tt1.!ids=ids
  52.          cprivs.0=tt1
  53.      end
  54.      when abbrev(atype,'IP') then do
  55.          tt1=cips.0+1
  56.          cips.tt1.!file=afil ; cips.tt1.!ids=ids
  57.          cips.0=tt1
  58.      end
  59.      otherwise nop
  60.    end
  61. end
  62.  
  63. gotfile=''
  64.  
  65. /* search for a match to ByClient cookie */
  66. acook=upper(strip(sref_get_cookie('ByClient')))
  67. if acook<>'' then do
  68.  do mm=1 to cids.0
  69.       if wordpos(acook,upper(cids.mm.!ids))>0 then do
  70.           gotfile=strip(translate(cids.mm.!file,'/','\'))
  71.           damatch=gotfile
  72.           if abbrev(gotfile,'/')=0 then
  73.              gotfile=userdir||gotfile
  74.           else                /* virtual file */
  75.             gotFILE=sref_do_virtual(ddir,gotFILE,enmadd,0,,homedir,
  76.                             ,host_nickname)
  77.           gotfile=stream(gotfile,'c','query exists')
  78.           if gotfile='' & verbose>1 then say "ByCLIENT. Warning, missing file:"damatch
  79.        end
  80.        if gotfile<>'' then leave /* got a successful match */
  81.   end
  82. end
  83.          
  84.  
  85. /* search for a matching privilege (if no cookie match */
  86. privset=upper(privset)
  87. if gotfile<>'' then cprivs.0=0  /* a hack. */
  88. do mm=1 to cprivs.0
  89. /* check if any of the ips are in privset */
  90.   ccprivs=upper(cprivs.mm.!ids)
  91.   do mm1=1 to words(ccprivs)
  92.      aid=strip(word(ccprivs,mm1))
  93.      if wordpos(aid,privset)>0 then do
  94.           gotfile=strip(translate(cprivs.mm.!file,'/','\'))
  95.           damatch=gotfile
  96.           if abbrev(gotfile,'/')=0 then
  97.              gotfile=userdir||gotfile
  98.           else                /* virtual file */
  99.             gotFILE=sref_do_virtual(ddir,gotFILE,enmadd,0,,homedir,
  100.                             ,host_nickname)
  101.           gotfile=stream(gotfile,'c','query exists')
  102.  
  103.           if gotfile='' & verbose>1 then say "ByCLIENT. Warning, missing file:"damatch
  104.        end
  105.        if gotfile<>'' then leave
  106.   end
  107.   if gotfile<>'' then leave /* got a successful match */
  108. end
  109.  
  110.  
  111. if gotfile<>'' then cips.0=0  /* a hack. */
  112. do mm=1 to cips.0
  113.    ccip=upper(cips.mm.!Ids)
  114.    numip=extract('clientaddr')
  115.    if value('SREF_NODNS',,'OS2ENVIRONMENT')=1 then
  116.        nameip=numip
  117.    else
  118.        nameip=clientname()
  119.    do mm1=1 to words(ccip)
  120.      aip=strip(word(ccip,mm1))
  121.      if sref_wild_match(numip,aip)<>0 | ,
  122.        sref_wild_match(nameip,aip)<>0 then do
  123.         gotfile=strip(translate(cips.mm.!file,'/','\'))
  124.           damatch=gotfile
  125.           if abbrev(gotfile,'/')=0 then
  126.              gotfile=userdir||gotfile
  127.           else                /* virtual file */
  128.             gotFILE=sref_do_virtual(ddir,gotFILE,enmadd,0,,homedir,
  129.                             ,host_nickname)
  130.           gotfile=stream(gotfile,'c','query exists')
  131.           if gotfile='' & verbose>1 then say "ByCLIENT. Warning, missing file:"damatch
  132.        end
  133.        if gotfile<>'' then leave
  134.   end
  135.   if gotfile<>'' then leave
  136. end       
  137.  
  138. /* return damatch (assuming gotfile exists */
  139. if gotfile='' then return ''
  140.  
  141. if abbrev(damatch,'/')=1 then
  142.    return '<!-- #include virtual="'||damatch||'" -->'
  143. else
  144.    return '<!-- #include file="'||damatch||'" -->'
  145.  
  146.