home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 35 Internet
/
35-Internet.zip
/
srev13h.zip
/
BYCLIENT.RXX
< prev
next >
Wrap
Text File
|
1998-09-21
|
5KB
|
146 lines
/* the "by client" INTERPRETable addon for SRE-http
See ByCLIENT.DOC for usage instructions */
userdir=filespec('d',usedfile)||filespec('p',usedfile)
/* Determine .USR file */
parse arg usrfile;usrfile=strip(usrfile)
if usrfile<>'' then do /* use specified .usr file */
usrfile=translate(usrfile,'/','\')
if abbrev(usrfile,'/')=0 then
usedfile=userdir||usrfile
else /* virtual file */
USEDFILE=sref_do_virtual(ddir,usrFILE,enmadd,0,homedir,host_nickname)
end
else do /* use .usr file with same name as requesting doc */
ap=lastpos('.',usedfile)
if ap=0 then do
usedfile=usedfile'.USR'
end
else do
usedfile=left(usedfile,ap)'USR'
end
end
usedfile=translate(usedfile,'\','/')
/* if not exists, return '' */
if stream(usedfile,'c','query exists')='' then return ''
oo=sref_open_read(usedfile,30)
if oo<0 then return '' /* giveup */
holdem=charin(usedfile,1,chars(usedfile))
foo=stream(usedfile,'c','close')
if verbose>2 then say "ByCLIENT: .USR file="usedfile
/* parse the .USR file */
tt=0 ; crlf='0d0a'x; cids.0=0; cprivs.0=0; cips.0=0
do until holdem=''
parse var holdem aline (crlf) holdem ; aline=strip(aline)
if aline='' then iterate
if abbrev(aline,';')=1 then iterate
parse upper var aline atype afil ids
atype=strip(atype)
select
when abbrev(atype,'COOK')=1 then do
tt1=cids.0+1
cids.tt1.!file=afil ; cids.tt1.!ids=ids
cids.0=tt1
end
when abbrev(atype,'PRIV') then do
tt1=cprivs.0+1
cprivs.tt1.!file=afil ; cprivs.tt1.!ids=ids
cprivs.0=tt1
end
when abbrev(atype,'IP') then do
tt1=cips.0+1
cips.tt1.!file=afil ; cips.tt1.!ids=ids
cips.0=tt1
end
otherwise nop
end
end
gotfile=''
/* search for a match to ByClient cookie */
acook=upper(strip(sref_get_cookie('ByClient')))
if acook<>'' then do
do mm=1 to cids.0
if wordpos(acook,upper(cids.mm.!ids))>0 then do
gotfile=strip(translate(cids.mm.!file,'/','\'))
damatch=gotfile
if abbrev(gotfile,'/')=0 then
gotfile=userdir||gotfile
else /* virtual file */
gotFILE=sref_do_virtual(ddir,gotFILE,enmadd,0,,homedir,
,host_nickname)
gotfile=stream(gotfile,'c','query exists')
if gotfile='' & verbose>1 then say "ByCLIENT. Warning, missing file:"damatch
end
if gotfile<>'' then leave /* got a successful match */
end
end
/* search for a matching privilege (if no cookie match */
privset=upper(privset)
if gotfile<>'' then cprivs.0=0 /* a hack. */
do mm=1 to cprivs.0
/* check if any of the ips are in privset */
ccprivs=upper(cprivs.mm.!ids)
do mm1=1 to words(ccprivs)
aid=strip(word(ccprivs,mm1))
if wordpos(aid,privset)>0 then do
gotfile=strip(translate(cprivs.mm.!file,'/','\'))
damatch=gotfile
if abbrev(gotfile,'/')=0 then
gotfile=userdir||gotfile
else /* virtual file */
gotFILE=sref_do_virtual(ddir,gotFILE,enmadd,0,,homedir,
,host_nickname)
gotfile=stream(gotfile,'c','query exists')
if gotfile='' & verbose>1 then say "ByCLIENT. Warning, missing file:"damatch
end
if gotfile<>'' then leave
end
if gotfile<>'' then leave /* got a successful match */
end
if gotfile<>'' then cips.0=0 /* a hack. */
do mm=1 to cips.0
ccip=upper(cips.mm.!Ids)
numip=extract('clientaddr')
if value('SREF_NODNS',,'OS2ENVIRONMENT')=1 then
nameip=numip
else
nameip=clientname()
do mm1=1 to words(ccip)
aip=strip(word(ccip,mm1))
if sref_wild_match(numip,aip)<>0 | ,
sref_wild_match(nameip,aip)<>0 then do
gotfile=strip(translate(cips.mm.!file,'/','\'))
damatch=gotfile
if abbrev(gotfile,'/')=0 then
gotfile=userdir||gotfile
else /* virtual file */
gotFILE=sref_do_virtual(ddir,gotFILE,enmadd,0,,homedir,
,host_nickname)
gotfile=stream(gotfile,'c','query exists')
if gotfile='' & verbose>1 then say "ByCLIENT. Warning, missing file:"damatch
end
if gotfile<>'' then leave
end
if gotfile<>'' then leave
end
/* return damatch (assuming gotfile exists */
if gotfile='' then return ''
if abbrev(damatch,'/')=1 then
return '<!-- #include virtual="'||damatch||'" -->'
else
return '<!-- #include file="'||damatch||'" -->'