home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Spezial
/
SPEZIAL2_97.zip
/
SPEZIAL2_97.iso
/
ANWEND
/
ONLINE
/
SREFV12J
/
SREFAST.80
< prev
next >
Wrap
Text File
|
1997-07-12
|
18KB
|
532 lines
/* 11 July 1997: This is the SREFAST variant of SRE-Filter.
For details on how to configure SREFAST, please see SREFAST.DOC
*******************/
/* Begin USER CHANGABLE PARMETERS *******************/
/* Begin USER CHANGABLE PARMETERS *******************/
/* Begin USER CHANGABLE PARMETERS *******************/
/*BEGIN --- (this line is used by the EDITSREF.CMD SRE-Filter utility)*/
/* SREFAST configuration information is read from a special
configuration file (SREFAST.HTM can be used to create modify this file).
Alternatively, if you set USE_CFG=0 you can specify entries here.
NOTE: we do NOT recommend use of use_cfg=0 (SSI will NOT be supported).*/
use_cfg=1
/* If you've set USE_CFG=0, then you must set the DOIT. stem variable here.
DOIT.0 should contain the number of entries.
Note that DOIT. is ignored if use_cfg=1 */
DOIT.0=0
/* Changes in the following variables (REFRESH, FORCE_REFRESH,
VERBOSE, KEY_PREFACE,DISK_FREE) will only
take effect when you restart GoServe
------------------------------------
Refresh check rate of the SSI cache, in seconds. */
Refresh=60
/* Force refresh, in # of REFRESH cycles
Note: if refresh=30, and force_refresh=90, then rebuild cache every 45 minutes*/
Force_refresh=60
/* Set verbose to 1 for verbose status info, 2 for VERY verbose */
verbose=1
/* alternative "preface" for SSI keyphrases. Set to 0 to suppress
MUST match the value used in SREFILTR.80! */
key_preface=0
/* amount of space that must be available after a SSI-cache file is written.
This is used to prevent overfilling your disk. Value is in megabytes */
disk_free=10
/* spaced delimited list of numeric IP addresses to not allow access to. Wildcards
are NOT allowed. */
unallowedips=' '
/*END --- (this line is used by the EDITSREF.CMD utility)*/
/* --------- END OF USER CHANGEABLE SECTION ----------------*/
/* --------- END OF USER CHANGEABLE SECTION ----------------*/
/* --------- END OF USER CHANGEABLE SECTION ----------------*/
/* --------- END OF USER CHANGEABLE SECTION ----------------*/
is_csh=0
parse arg source, request , seloriginal
if request=" " then return 'NODATA'
parse var source myaddr port transaction who whoport .
parse var request verb uri protocol . /* split up the request line */
enmadd="SREF_"||port||"_"
basesem='\SEM32\'||enmadd
os2e='os2environment'
servdir=directory()
if transaction<2 then do /* initialize */
foo=srefast1(port) /* load srefiltr.port into macropace */
if aport=80 then do
foo=sref_main_80(source,request,seloriginal)
end
else do
aroutine='SREF_MAIN_'||port
foo2='foo='||aroutine||'(source,request,seloriginal)'
interpret foo2
end
afilt2=servdir'\srefast2.cmd'
tempdata_dir=' '
do while tempdata_dir=' ' /* wait for stuff to stabilize */
tempdata_dir=get_value('TEMPDATA_DIR')
call syssleep 1
end
foo=rexxthread('f',afilt2,port,servdir,refresh,force_refresh,datadir(),tempdata_dir,verbose,key_preface,enmadd,servername(),disk_free)
if verbose>0 then call pmprintf_sref(' Done initializing SREFAST ')
return ' '
end
/* if here, not transaction 1 */
sem_status=eventsem_query(basesem)
if sem_status<0 then do /* patience */
'STRING Server Initalizing: Please try again in a minute '
return ' '
end
/* Check for basic grooviness */
if left(protocol,4)\='HTTP' & protocol\='' then
signal call_bigone
/* if no semaphore/queue for this thread, call bigone */
mytid=dostid()
mysem=basesem||"t"||mytid
myqueue="SREF_"||port||'_t'||mytid
wow=eventsem_query(mysem)
if wow=-187 then signal call_bigone
/* if not a get request, xx?yy, or CGI-BIN, then can't do it here. */
if verb<>'GET' then signal call_bigone
if pos('?',seloriginal)>0 then signal call_bigone
if left(seloriginal,1)='!' then signal call_bigone
tsel=strip(upper(seloriginal))
if pos('CGI-BIN',tsel) then signal call_bigone
temp_dir=get_value("TEMPDATA_DIR")
temp_dir=strip(TEMP_DIR,'t','\')||'\'
/* read in DOIT from a special configuration file? */
if use_cfg=1 then do
afilt2=temp_dir||'_fstindx.'||port
foo=cvread(afilt2,doit)
if verbose>0 & foo=0 then call pmprintf_sref(afilt2', the SREFAST index, is not available')
if foo=0 then signal call_bigone
end
/* fix up seloriginal */
gotit=0
afile=' '
do m=1 to doit.0
asel=strip(upper(doit.m.!sel),'l','/')
ifl= f_wildcard(tsel,asel)
if ifl=0 then iterate /* sel does not match */
host_Nickname=' ' ;aservername=' '
if symbol('DOIT.'m'.!SERVER')='VAR' then do /* check server */
aservername=doit.m.!server
if symbol('DOIT.'m'.!HOST')='VAR' then host_nickname=doit.m.!host /* get host_nickname */
if myaddr<>doit.m.!server then do /* not canonical, perhaps host: header? */
ahost=reqfield('host')
if ahost<>doit.m.!server then iterate /* did not match ip number or host-alias */
if symbol('DOIT.'m'.!HOST')='VAR' then host_nickname=doit.m.!host /* get host_nickname */
end
end
if symbol('DOIT.'m'.!NODO')='VAR' then do /* check nodo*/
if doit.m.!nodo=1 then do
if verbose>1 then say "SREFAST: explicit call to main filter for: " seloriginal
signal call_bigone /* explicit "don't use srefast" entry */
end
end
gotit=m
leave
end
if gotit=0 then signal call_bigone /* no matches, call srefiltr */
if wordpos(who,unallowedips)>0 then signal call_bigone
if verbose>1 then say " SREFAST: Using entry " doit.gotit.!sel ' for ' seloriginal
tempfile=temp_dir'$'transaction'.'port
nocache=' '
privset=' '
/* check for username or password -- if required but not found, call_bigone */
if symbol('DOIT.'gotit'.!USERS')='VAR' then do
owners=get_value('OWNERS')
if wordpos(who,owners)=0 then do
if symbol('DOIT.'gotit'.!PWDS')<>'VAR' then signal call_bigone /* no pwds */
astuff=reqfield('Authorization')
if astuff=' ' then signal call_bigone
parse var astuff . m64 . /* get the encoded cookie */
dec=pack64(m64) /* and decode it */
parse upper var dec auser ':' apwd /* parse out user and pwd */
ii=wordpos(auser,upper(doit.gotit.!users)) /* check for username */
if ii=0 then signal call big_one
bpwd=upper(strip(word(doit.gotit.!pwds,ii)))
if bpwd<>apwd & bpwd<>'*' then signal call_bigone
nocache='NOCACHE'
if symbol('DOIT.'gotit'.!Privset')="VAR" then privset=doit.gotit.!privset /* no pwds */
end /* owners */
end /*authorized */
/* accept this one. Determine file name */
dnameonly=0
if symbol('DOIT.'gotit'.!DIR')<>'VAR' then do
ddir=datadir()
end
else do /* check for "HTTP://", and redirect if found */
ddir=strip(upper(doit.gotit.!dir))
if symbol('DOIT.'gotit'.!DIR_NAMEONLY')='VAR' then do
if doit.gotit.!dir_nameonly=1 then dnameonly=1
end
if abbrev(ddir,'HTTP://')=1 then do
if right(ddir,1)='*' then do
aurl1=left(ddir,1,length(ddir)-1)
aurl1=strip(aurl1,'t','/')||'/'
addme=seloriginal
if dnameonly=1 then do
addme=translate(addme,'\','/')
addme=filespec('n',addme)
end
aurl=aurl1||addme
end
else do
aurl=ddir
end
'HEADER ADD Location:' aurl
'RESPONSE HTTP/1.0 301 Moved Permanently' /* Set HTTP response line */
'STRING '||seloriginal||' moved to '|| aurl
runtot=extract('bytessent') ; rstatus=301
signal checkpost
end
end
addme=strip(translate(seloriginal,'\','/'),,'\')
if dnameonly=1 then addme=filespec('n',addme)
ddir=strip(translate(ddir,'\','/'),,'\')||'\'
afile=ddir||addme
/* see if file exists */
if stream(afile,'c','query exists')=' ' then do
signal call_bigone /* not found, let main filter handle
it (perhaps using an alias, etc. */
end
/* got name, but has it been already completed from goserve cache? */
if completed()<>0 then do
if verbose>1 then say " SREFAST: Got from cache: " seloriginal
runtot=extract('bytessent')
rstatus=200
is_csh=1
signal checkpost
end
/* got filename, it's still alive -- get mimetype and suppress caching flag */
/* get no cache flag */
if symbol('DOIT.'gotit'.!NOCACHE')='VAR' & nocache=' ' then do /* but check cache status first*/
if doit.gotit.!nocache=1 then nocache='NOCACHE'
end
/* get mime type ? */
if symbol('DOIT.'gotit'.!MIME')='VAR' then
mimetype=doit.gotit.!mime
else
mimetype=sref_mediatype(afile)
/* is it an ssi'able file ? */
issii=0
if symbol('DOIT.'gotit'.!SSI')='VAR' then do
if doit.gotit.!ssi=1 then issi=1
end
if issi=1 & (doit.!nossi=1 | use_cfg=0 ) then signal call_bigone
if issi=1 then do /* ssi -- used pre compiled asis or with dynamics */
if doit.gotit.!type='SKIP' then do
if verbose>1 then call pmprintf_sref(' SREFAST: SSI can not be done for 'seloriginal)
signal call_bigone
end
oobfile=doit.gotit.!origfile
anent=sysfiletree(oobfile,yow1,'T')
if space(upper(yow1.1))<>doit.gotit.!stamp then do
if verbose>0 then call pmprintf_sref(' SREFAST: File stamp mismatch, use main filter ('oobfile)
signal call_bigone
end
if symbol('DOIT.'||gotit||'.!TRIGGER')="VAR" then do
atrigger=doit.gotit.!trigger
atfile=strip(word(atrigger,words(atrigger)))
anent=sysfiletree(atfile,yow1,'T')
if yow.0=0 then do
if verbose>0 then call pmprintf_sref(' SREFAST: Missing trigger file: use main filter ('atfile)
signal call_bigone
end
if space(upper(yow1.1))<>doit.gotit.!trigger then do
if verbose>0 then call pmprintf_sref(' SREFAST: Trigger mismatch, use main filter ('atfile)
signal call_bigone
end
end
if doit.gotit.!type='ASIS' then do
if stream(doit.gotit.!file,'c','query exists')=' ' then do
if verbose>0 then call pmprintf_sref(' SREFAST: ASIS cache file missing 'doit.gotit.!file)
signal call_bigone
end
'FILE type text/html nocache name ' doit.gotit.!file
/* unfortunately, the current srefast ssi cache is not robust enough to handle goserve cache */
runtot=dosdir(doit.gotit.!file,'s') ; rstatus=200
end
if doit.gotit.!type='DYNAMIC' then do
AA=CVREAD(doit.gotit.!file,DASTUFF)
IF AA=0 THEN DO
if verbose>0 then say " SREFAST: Dynamic Cache file missing: " doit.gotit.!file ' , for ' seloriginal
SIGNAL CALL_BIGONE
end
sendp=get_value('DO_SEND_PIECE')
if sendp=1 then do
'SET NETBUFFER OFF '
'SEND TYPE text/html as ' afile
end
else do
sendit=""
end
runtot=0
cgi_inc_timefmt="%c"
do ip=1 to dastuff.0
if dastuff.ip.!type=1 then do
aay=DASTUFF.ip
if verbose>1 then say ' SREFAST: chunk '||length( dastuff.ip)
end
else do
aay=process_dynamic(ip,doit.gotit.!origfile)
if symbol('DASTUFF.'||ip||'.!ARGS')='VAR' then
if completed() then leave
if verbose>1 then say ' SREFAST: send dynamic '|| left(dastuff.ip,80)
end
if aay<>' ' then do
if sendp=1 then do
'VAR NAME AAY '
runtot=runtot+length(aay)
end
else do
sendit=sendit||aay
end
end
end /* ip loop */
if sendp=1 then do
'SEND COMPLETE '
rstatus=200
end
else do
fix_expire=get_value('FIX_EXPIRE')
runtot=length(sendit)
if fix_expire>0 then foo=sref_expire_response(fix_expire,runtot)
'VAR type text/html name sendit '
end
end
end /* issi */
else do /* non ssi stuff */
'FILE type ' mimetype ' ' nocache ' name ' afile
runtot=dosdir(afile,'s') ; rstatus=200
end
/* post filter it? */
checkpost:
eej='FAST'
if is_csh=1 then eej='CACHE'
mm=get_value('SREF_FAST_'||eej); if mm=' ' then mm=0
foo=value(enmadd||'SREF_FAST_'||eej,mm+1,'os2environment')
mm=get_value('SREF_FAST_BYTES_'||eej); if mm=' ' then mm=0
if datatype(RUNTOT)<>'NUM' then runtot=extract('bytessent')
foo=value(enmadd||'SREF_FAST_BYTES_'||eej,mm+runtot,'os2environment')
norec=0
if symbol('DOIT.'gotit'.!NORECORD')='VAR' then do
if doit.gotit.!norecord=1 then do
norec=1
end
end
if norec<>1 then do
response_status=rstatus' 'runtot
if aservername=' ' then aservername=servername()
foo=sref_fast_postf(source,request,seloriginal, ,
enmadd,basesem,mysem,myqueue,aservername,host_nickname, ,
response_status,verbose,tempfile,afile)
end
return ' '
end
/* jump here to call srefiltr.80 */
call_bigone:
if verbose>1 then call pmprintf_sref(" SREFAST: calling main filter for " seloriginal)
if aport=80 then do
foo=sref_main_80(source,request,seloriginal)
end
else do
aroutine='SREF_MAIN_'||port
foo2='foo='||aroutine||'(source,request,seloriginal)'
interpret foo2
end
mm=get_value('SREF_FAST_MAIN');if mm=' ' then mm=0
foo=value(enmadd||'SREF_FAST_MAIN',mm+1,'os2environment')
runtot=extract('bytessent')
mm=get_value('SREF_FAST_BYTES_MAIN'); if mm=' ' then mm=0
foo=value(enmadd||'SREF_FAST_BYTES_MAIN',mm+runtot,'os2environment')
return ' '
/********************************/
/* see if needle matches haystack (* wildcards permitted) */
f_wildcard:
parse arg tn ,tc
tn=strip(tn); tc=strip(tc)
if tn=tc then return 1 /* exact match */
/* check for wildcard */
astc=pos('*',tc)
if astc=0 then return 0 /* not a wildcard candidate */
if astc=1 then do
tc1=""
tn1=tc1
len1=0
end
else do
tc1=substr(tc,1,astc-1)
len1=length(tc1)
tn1=left(tn,len1)
end
if astc=length(tc) then do
tn2=""
tc2=""
len2=0
end
else do
tc2=substr(tc,astc+1)
len2=length(tc2)
tn2=right(tn,len2)
end
if tn1<>tc1 | tn2<>tc2 then /* not a wildcard match */
return 0
return 1 /* have a wildcard match */
/* ----------- */
/* get environment value, possibly host specific */
get_value: procedure expose enmadd
parse upper arg vname
vname=strip(vname) ;
aval=value(enmadd||vname,,'os2environment')
return aval
/**************************/
/* the dynamic replacements done by srefast
The include the marker
----------------------------------
HTTPD variables:
cgi_inc_timefmt (used by date_local and date_gmt)
DATE_LOCAL DATE_GMT SERVER_PROTOCOL
REQUEST_METHOD REMOTE_ADDR AUTH_NAME
HTTP_ACCEPT
REPLACE (and sometimes HTTPD) variables:
DATEGMT DATE READ_HEAD
REFER TIME TIME_GMT
USERNAME USER-AGENT
*/
process_dynamic:procedure expose cgi_inc_timefmt transaction basesem enmadd who mysem myqueue dastuff. ,
privset host_nickname aservername seloriginal verbose
parse upper arg i1,origfile
dome=dastuff.i1
putme=' '
select
when dome="CGI_INC_TIMEFMT" then
parse var dome foo cgi_inc_timefmt
when dome='DATE_LOCAL' then putme=sref_datetime_convert(cgi_inc_timefmt)
when dome='DATE_GMT' then do
putme=sref_new_gmt(,,,1)
parse var putme adate atime
putme=sref_datetime_convert(cgi_inc_timefmt,adate,atime)
end
when dome='SERVER_PROTOCOL' then putme=extract( 'serverprotocol')
when dome="REQUEST_METHOD" then putme=extract('clientmethod')
when dome="USERNAME" then do
putme=sref_clientname(who,mysem,myqueue,basesem,enmadd,transaction)
end
when dome="REMOTE_ADDR" then putme=who
when dome="AUTH_NAME" then do
afield=reqfield('Authorization')
parse var afield . m64 . /* get the encoded cookie */
dec=pack64(m64) /* and decode it */
parse upper var dec putme ':' .
end
when dome="HTTP_ACCEPT" then do
i = 1
_acc = REQFIELD("accept")
acc = '%'
ClientAccepts = ''
do while (acc \= _acc)
acc = REQFIELD("accept", i)
if (ClientAccepts \= '') then ClientAccepts = ClientAccepts', 'acc
else ClientAccepts = acc
i = i+1
end
putme=clientaccepts
end
when dome="BROWSER" then putme=reqfield("User-Agent")
when dome="REFERER" then do
putme=reqfield("REFERER")
end
when dome="DATE_LOCAL2" then putme=date('N')
when dome="TIME" then putme=time('N')
when dome="TIME_GMT" then do
fii=sref_new_gmt()
parse var fii eek ',' d1 d2 d3 t1
putme=t1||' GMT '
end
when dome="DATE_GMT2" then do
fii=sref_new_gmt()
parse var fii eek ',' d1 d2 d3 .
putme=d1||' '||d2||' '||d3
end
when dome="READ_HEAD" then do
'READ HEADER VAR PUTME '
putme='<PRE>'||putme||'</pre>'
end
otherwise
nop
end
return putme