/* *************************************************************** */ /* mwsug95.sas - generates a form or responds to it. */ /* if REQUEST_METHOD is GET then this generates a form. */ /* if REQUEST_METHOD is POST then it responds to the form. */ /* This must be called from a script which sets appropriate */ /* environment variables and redirects std IO without buffering. */ /* */ /* Larry Hoyle, IPPBR, University of Kansas July 1995 */ /* *************************************************************** */ %global maxlen; /* maximum length of name or value string from httpd */ %let maxlen=200; %global host; /* the name host for which statistics are requested */ %global request; /* the type of request eg. "source" or "stats" */ filename mwlist '/homea/http/scripts/ippbr/mwsug95/mw95list'; /* *********************************************************** */ /* read the environment variables into SAS macro variables. */ /* *********************************************************** */ %global rqmeth; /* request method environment variable */ %let rqmeth=%sysget(REQUEST_METHOD); %global cnttyp; /* content type environment variable */ %let cnttyp=%sysget(CONTENT_TYPE); %global cntlen; /* content length environment variable */ %let cntlen=%sysget(CONTENT_LENGTH); %global remadr; /* remote address environment variable */ %let remadr=%sysget(REMOTE_ADDR); %global remhst; /* remote host environment variable */ %let remhst=%sysget(REMOTE_HOST); data _null_; put 'ENVIRONMENT VARIABLES:'; put 'request method = ' "&rqmeth"; put 'content type = ' "&cnttyp"; put 'content length = ' "&cntlen"; put 'remote address = ' "&remadr"; put 'remote host = ' "&remhst"; run; /* macro tstmthd tests for REQUEST_METHOD and either sends a form */ /* or processes one */ %macro tstmthd; %if %upcase(&rqmeth)=GET %then %do; /* GET */ /* *********************************************************** */ /* send back a form which points back to this SAS program */ /* *********************************************************** */ data accesses; infile mwlist lrecl=40 pad; length wkday $ 3 host $ 40 ip $ 40; input wkday $ 1-3 / host $40. / ip $40.; proc sort data=accesses NODUPKEY; by host; run; data _null_; file STDOUT; set accesses end=last; by host; if _n_=1 then do; put 'content-type: text/html'; put; put '
';
put 'revised: Oct. 25, 1995 - changed incorrect use of _n_=1.';
put 'Statistics should now print for any address selected.';
put '
revised May 10, 1996 - the statistics report was printing the address of the client.';
put ' It now prints the proper address in the title';
put '
';
put host "(" ip ") used the MWSUG95 form at the following times:";
put ' Hours are listed in Coordinated Universal Time';
end; /* not(beenhere) */
proc printto print=STDOUT;
proc freq data=accesses;
table hour*wkday;
run;
%end; /* STATS section */
/* ***************************************************** */
/* begin the source section (request=source) */
/* ***************************************************** */
%if %upcase(&request)=SOURCE %then
%do; /* SOURCE section */
filename mwsug95 '/homea/http/scripts/ippbr/mwsug95/mwsug95.sas' recfm=n;
data _null_;
put 'Executing source section';
data _null_;
infile mwsug95 end=last ;
file STDOUT ;
length cr $ 1;
length c $ 1;
cr='0D'x;
if _n_ = 1 then do;
put 'content-type: text/html';
put;
put ' SAS code serving the MWSUG95 form ';
put '';
end;
/* *********************************************** */
input c $char1. @@;
select(c); /* escape the codes for tags */
when('<') put '<'@@;
when('>') put '>'@@;
when('&') put '&'@@;
when('0A'x) put ;
otherwise put c $char1. @@;
end;
/* *********************************************** */
if last then put '';
run;
%end; /* source section */
/* ***************************************************** */
/* begin the script section (request=script) */
/* ***************************************************** */
%if %upcase(&request)=SCRIPT %then
%do; /* SCRIPT section */
filename mwsug95 '/homea/http/scripts/ippbr/mwsug95/cgisas_mwsug95' recfm=n;
data _null_;
put 'Executing script section';
data _null_;
infile mwsug95 end=last ;
file STDOUT ;
length cr $ 1;
length c $ 1;
cr='0D'x;
if _n_ = 1 then do;
put 'content-type: text/html';
put;
put ' Shell script to execute the SAS code ';
put '';
end;
/* *********************************************** */
input c $char1. @@;
select(c); /* escape the codes for tags */
when('<') put '<'@@;
when('>') put '>'@@;
when('&') put '&'@@;
when('0A'x) put ;
otherwise put c $char1. @@;
end;
/* *********************************************** */
if last then put '';
run;
%end; /* script section */
%end; /* POST */
%mend reply;
%tstmthd
%reply