This forum has been moved here:
Helicon Tech Community Forum

  Active TopicsActive Topics  Display List of Forum MembersMemberlist  HelpHelp   RegisterRegister  LoginLogin
ISAPI_Rewrite 2.x (Forum Locked Forum Locked)
 Helicon Tech : ISAPI_Rewrite 2.x
Subject Topic: asp proxy script
Author
Message |
davidw53
Newbie


Joined: 12 March 2007
Location: United Kingdom
Posts: 11
Posted: 14 November 2007 at 4:43am

Proxiing script which authenticates by looking for an asp session variable "Login". Also useful because it keeps the asp session alive while proxiing in case the application returns to an asp page.

The Script calls a second asp script "check-session.asp" that has enabelsessionstate set to true
-------- checksession.asp ------------------
<%@ Language=JScript EnableSessionState=True%>
<% if (Session("Login")) Response.Write ("1"); else Response.write ("0") %>
----------------------------------------

The proxiing script "rails-proxy.asp"
--------- rails-proxy.asp ----------------
<%@ Language=JScript EnableSessionState=False%>
<%
var HttpReq = new ActiveXObject("WinHttp.WinHttpRequest.5.1");
HttpReq.Option( 6) = false //WinHttpRequestOption_EnableRedirects
var cookie =Request.ServerVariables( "HTTP_COOKIE")

HttpReq.open( "GET", "http://"+ Request.ServerVariables("HTTP_HOST") +"/stats/check-session.asp", true);
HttpReq.setRequestHeader( "Cookie", cookie); HttpReq.send

if(!HttpReq.WaitForResponse(5)){ HttpReq.Abort();
 Response.Redirect( Request.ServerVariables("HTTP_X_REWRITE_URL")) }
if( HttpReq.responseText !="1") Response.redirect( "/stats/userLogin.asp?logout=2")

HttpReq.open( Request.ServerVariables("REQUEST_METHOD"), "http://192.168.4.218:3000/rails/" + Request.QueryString, false);
HttpReq.setRequestHeader( "Cookie", cookie);
if( String( Request.ServerVariables( "CONTENT_TYPE"))) HttpReq.setRequestHeader( "Content-Type", Request.ServerVariables( "CONTENT_TYPE"))
HttpReq.setRequestHeader( "User-Agent", Request.ServerVariables( "HTTP_USER_AGENT"));
if( Request.ServerVariables( "HTTPS") =="on") HttpReq.setRequestHeader( "X-Forwarded-Proto", "https");
HttpReq.setRequestHeader( "X-Forwarded-Host", Request.ServerVariables( "HTTP_HOST"));

if( Request.TotalBytes) HttpReq.send( Request.BinaryRead( Request.TotalBytes)); else HttpReq.send;

Response.Status = "" + HttpReq.status + " " + HttpReq.statusText;

var contentType = HttpReq.getResponseHeader("Content-Type")
if (contentType) Response.ContentType = contentType

headers=String( HttpReq.getAllResponseHeaders()).split("\n");
for( var i=0; i<headers.length && headers; i++) {
 var header = headers.match(/([\w-\.]+):\s*([ \S]*)/);
 if( header &&( header[1] !="Content-Type")) Response.AddHeader( header[1], header[2]);
}

Response.BinaryWrite( HttpReq.responseBody);
%>
-----------------------------------------------

 

Back to Top Visit davidw53's Homepage
 
davidw53
Newbie


Joined: 12 March 2007
Location: United Kingdom
Posts: 11
Posted: 23 November 2007 at 4:46am

Updated script also handles "304 not modified" responses.

-------------------------------------------------------------
<%@ Language=JScript EnableSessionState=False %>
<%
var HttpReq = new ActiveXObject("WinHttp.WinHttpRequest.5.1");
HttpReq.Option( 6) = false //WinHttpRequestOption_EnableRedirects

HttpReq.open( "GET", "http://"+ Request.ServerVariables("HTTP_HOST") +"/stats/check-session.asp", true);
HttpReq.setRequestHeader( "Cookie", Request.ServerVariables( "HTTP_COOKIE")); HttpReq.send

if(!HttpReq.WaitForResponse(1)){ HttpReq.Abort(); %>
 <form name=retry method="<%= Request.ServerVariables("REQUEST_METHOD") %>"
   action="<%= Request.ServerVariables("HTTP_X_REWRITE_URL") %>">
  <% for( var f =new Enumerator( Request.Form()); !f.atEnd(); f.moveNext()){
   var key = f.item(); %>
   <input type=hidden name="<%= key %>" value="<%= Request.Form( key) %>">
  <% } %>
 </form>
 <script>window.onload=function(){retry.submit()}</script>
 <% Response.end }
if( HttpReq.responseText !="1") Response.redirect( "/stats/userLogin.asp?logout=2")

HttpReq.open( Request.ServerVariables("REQUEST_METHOD"), "http://192.168.4.218:3000/rails/" + Request.QueryString, false);

//fs=new ActiveXObject("Scripting.FileSystemObject")
//Application("fno") =Application("fno") +1
//of=fs.OpenTextFile("C:\\Websites\\syntec\\stats\\proxy." +Application("fno") +".log", 8, true, 0)

var rheaders= String( Request.ServerVariables("ALL_RAW")).split("\n");
for(var i=0; i<rheaders.length && rheaders; i++){
 var rheader = rheaders.match(/([\w-\.]+):\s*([ \S]*)/);
// of.write( rheader[1] +"=" +rheader[2] +"\n")
 if(( rheader[1] !="Host")) HttpReq.setRequestHeader( rheader[1], rheader[2])
}

if( String( Request.ServerVariables( "CONTENT_TYPE"))) HttpReq.setRequestHeader( "Content-Type", Request.ServerVariables( "CONTENT_TYPE"))
if( Request.ServerVariables( "HTTPS") =="on") HttpReq.setRequestHeader( "X-Forwarded-Proto", "https")
HttpReq.setRequestHeader( "X-Forwarded-Host", Request.ServerVariables( "HTTP_HOST"))

if( Request.TotalBytes) HttpReq.send( Request.BinaryRead( Request.TotalBytes)); else HttpReq.send
Response.Status =HttpReq.status +" " +HttpReq.statusText

//of.write( "\n" +Request.QueryString +" - " +Request.ServerVariables("REQUEST_METHOD") +" " +Response.Status +"\n\n")

var headers= String( HttpReq.getAllResponseHeaders()).split("\n")
for( var i=0; i<headers.length && headers; i++) {
 var header = headers.match(/([\w-\.]+):\s*([ \S]*)/);
// if(header) of.write( "" +header[1] +"=" +header[2] +"\n")
 if( header) switch( header[1]){
  case "Cache-Control": Response.CacheControl =header[2]; break
  case "Content-Type": Response.ContentType =header[2]; break
//  case "Content-Length": break;
  case "Expires": Response.ExpiresAbsolute =header[2]; break
  case "Server": break
  default: Response.AddHeader( header[1], header[2]) }
}

//of.close()
if( HttpReq.status !=304) Response.BinaryWrite( HttpReq.responseBody)
%>

Back to Top Visit davidw53's Homepage
 
davidw53
Newbie


Joined: 12 March 2007
Location: United Kingdom
Posts: 11
Posted: 06 January 2008 at 12:29am

Latest version of this script is below.

Notes:
1.   The commented lines are for debug purposes
2.   Enablesessionstate must be false otherwise the script just hangs (I don't know why). If it could be true then the authentication part could be done in the body of the script instead of calling a separate asp page.
3.   Auto-redirect by the winhttp proxy must be disabled for most web applications to work effectively. If we did not need to do this we could use ServerXMLhttp which is more scaleable then winhttprequest.
4.   When the IIS server is restarted or the proxy script is edited, the first call to check-session.asp hangs - hence the redirect/retry code which fixes this problem with effectively a browser refresh.
5.   check-session.asp contains the authentication code which checks the requested url and session vars and returns -1 for session timeout, 1 if authenticated and 0 (or anything else) if not.

----------------------------------
<%@ Language=JScript EnableSessionState=False %>
<%
//Application( "fno") =Application( "fno") +1
//var fs =new ActiveXObject( "Scripting.FileSystemObject")
//var of =fs.OpenTextFile( "C:\\Websites\\syntec\\stats\\proxy." +Application("fno") +".log", 8, true, 0)

var HttpReq =new ActiveXObject( "WinHttp.WinHttpRequest.5.1");
HttpReq.Option( 6) =false //WinHttpRequestOption_EnableRedirects

HttpReq.open( "GET", "http://"+ Request.ServerVariables( "HTTP_HOST") +"/stats/check-session.asp?" +Request.QueryString, true);
HttpReq.setRequestHeader( "Cookie", Request.ServerVariables( "HTTP_COOKIE")); HttpReq.send

if( !HttpReq.WaitForResponse( 1)){ HttpReq.Abort();
// of.write( Request.QueryString +" - " +Request.ServerVariables( "REQUEST_METHOD") +" Retrying\n")
// of.write( "\nHTTP_X_REWRITE_URL=" +Request.ServerVariables( "HTTP_X_REWRITE_URL"))
 if( Request.ServerVariables( "REQUEST_METHOD") =="GET") Response.redirect( Request.ServerVariables( "HTTP_X_REWRITE_URL")) %>
 <form name=retry method="<%= Request.ServerVariables( "REQUEST_METHOD") %>"
   action="<%= Request.ServerVariables( "HTTP_X_REWRITE_URL") %>">
  <% for( var f =new Enumerator( Request.Form); !f.atEnd(); f.moveNext()){
   var key = f.item(); %>
   <input type=hidden name="<%= key %>" value="<%= Request.Form( key) %>">
  <% } %>
 </form>
 <script>window.onload=function(){retry.submit()}</script>
 <% Response.end }
if( HttpReq.responseText =="-1") Response.redirect( "/stats/userLogin.asp?logout=2")
if( HttpReq.responseText !="1"){ %>
 <p style=color:red;margin:50>Permission Denied
 <% Response.End }

HttpReq.open( Request.ServerVariables( "REQUEST_METHOD"), "http://" +Request.QueryString, false);

var rheaders= String( Request.ServerVariables( "ALL_RAW")).split("\n");
for(var i=0; i<rheaders.length && rheaders; i++){
 var rheader = rheaders.match(/([\w-\.]+):\s*([ \S]*)/);
// of.write( rheader[1] +"=" +rheader[2] +"\n")
 if(( rheader[1] !="Host")) HttpReq.setRequestHeader( rheader[1], rheader[2])
}

if( String( Request.ServerVariables( "CONTENT_TYPE"))) HttpReq.setRequestHeader( "Content-Type", Request.ServerVariables( "CONTENT_TYPE"))
if( Request.ServerVariables( "HTTPS") =="on") HttpReq.setRequestHeader( "X-Forwarded-Proto", "https")
HttpReq.setRequestHeader( "X-Forwarded-Host", Request.ServerVariables( "HTTP_HOST"))

if( Request.TotalBytes) HttpReq.send( Request.BinaryRead( Request.TotalBytes)); else HttpReq.send
Response.Status =HttpReq.status +" " +HttpReq.statusText

//of.write( "\n" +Request.QueryString +" - " +Request.ServerVariables( "REQUEST_METHOD") +" " +Response.Status +"\n\n")

var headers= String( HttpReq.getAllResponseHeaders()).split("\n")
for( var i=0; i<headers.length && headers; i++) {
 var header = headers.match(/([\w-\.]+):\s*([ \S]*)/);
// if(header) of.write( "" +header[1] +"=" +header[2] +"\n")
 if( header) switch( header[1]){
  case "Cache-Control": Response.CacheControl =header[2]; break
  case "Content-Type": Response.ContentType =header[2]; break
  case "Content-Length": var content= header[2] >0; break;
  case "Expires": Response.ExpiresAbsolute =header[2]; break
  case "Server": break
  default: Response.AddHeader( header[1], header[2]) }
}

if( content) Response.BinaryWrite( HttpReq.responseBody)
%>

Back to Top Visit davidw53's Homepage
 
davidw53
Newbie


Joined: 12 March 2007
Location: United Kingdom
Posts: 11
Posted: 15 February 2008 at 3:24pm

I forgot to mention. Need rewrie rule, eg.

RewriteRule /rails(/.*) /stats/reverse-proxy.asp\?192.168.4.218:3000$1 [L]

RewriteRule (/(?:search\?|smb/).*) /stats/reverse-proxy.asp\?129.178.88.72$1 [L]

to reverse-proxy a child domain (to some internal server) with the script.

Back to Top Visit davidw53's Homepage
 
davidw53
Newbie


Joined: 12 March 2007
Location: United Kingdom
Posts: 11
Posted: 25 July 2008 at 11:32am

The latest version is below.

Notes

  1. Allows proxiing based on the referer header. Sometimes you want to proxy all the images/calls from a page without identifying all possibilities.
  2. If enablesessionstate is true then the page will 'hang' if the user clicks elsewhere and the page has not fully loaded. Very noticable from a page with continuously running ajax calls that monitor something.
  3. No longer rely on correct 'content-lengh' header. Send response only if length>0. Fixes some problems.
  4. Logging now uses single file opened in global.asa. A number reference is used to identify the log lines of each call.

----------------------------------------------------------
Use in httpd.ini-

# FOR RAILS
RewriteCond URL /rails/note_attachment/upload\?(_SynBill_session_id=.*)(ASPSESSIONID.{8})%3D(.*)$
RewriteHeader Cookie: .* $1;$2=$3
RewriteRule /rails(/.*) /stats/reverse-proxy.asp\?192.168.4.218:3000$1 [L]

# FOR GOOGLE
RewriteRule (/(?:search\?|smb/).*) /stats/reverse-proxy.asp\?129.178.88.72$1 [L]

# QVIEW
RewriteRule (/qview\.htm\b.*) /stats/reverse-proxy.asp\?10.41.68.18:8081$1 [L]
RewriteRule (/stats/(?:check-session|userLogin)\.asp\b.*) $1 [L]
RewriteCond Cookie: .*qviewrdr=on.*
RewriteCond Referer: .*/qview\.htm\b.*
RewriteRule (.*) /stats/reverse-proxy.asp\?10.41.68.18:8081$1 [L]

----------------------------------------------------------

<%@ Language=JScript EnableSessionState=False %><%
//var lno= Application( "lno")= Application( "lno")+1
//function log( msg){
//    function pad( n){ return '00000'.slice( n.toString().length) +n }
// Application( "log").write( pad( lno) +': '+ msg +'\n') }

var HttpReq =new ActiveXObject( "WinHttp.WinHttpRequest.5.1");
HttpReq.Option( 6) =false //WinHttpRequestOption_EnableRedirects

HttpReq.open( "GET", "http://"+ Request.ServerVariables( "HTTP_HOST") +"/stats/check-session.asp?" +Request.QueryString, true);
HttpReq.setRequestHeader( "Referer", (Request.ServerVariables( "HTTP_REFERER").Item || 'x'))
HttpReq.setRequestHeader( "Cookie", Request.ServerVariables( "HTTP_COOKIE")); HttpReq.send

if( !HttpReq.WaitForResponse( 1)){ HttpReq.Abort();
// log( Request.QueryString +" - " +Request.ServerVariables( "REQUEST_METHOD") +" Retrying\n \
//  HTTP_X_REWRITE_URL=" +Request.ServerVariables( "HTTP_X_REWRITE_URL"))
 if( Request.ServerVariables( "REQUEST_METHOD") =="GET") Response.redirect( Request.ServerVariables( "HTTP_X_REWRITE_URL")) %>
 <form name=retry method="<%= Request.ServerVariables( "REQUEST_METHOD") %>"
   action="<%= Request.ServerVariables( "HTTP_X_REWRITE_URL") %>">
  <% for( var f =new Enumerator( Request.Form); !f.atEnd(); f.moveNext()){
   var key = f.item(); %>
   <input type=hidden name="<%= key %>" value="<%= Request.Form( key) %>">
  <% } %>
 </form>
 <script>window.onload=function(){ retry.submit() }</script>
 <% Response.end }

if( HttpReq.responseText =="-1"){
 if( Request.QueryString.Item == "10.41.68.18:8081/init"){
  Response.Cookies( "qviewrdr") ="off"; Response.Cookies( "qviewrdr").Path = "/"
  Response.write( '"RDR:/stats/userLogin.asp?logout=2"'); Response.end }
 Response.redirect( "/stats/userLogin.asp?logout=2") }
if( HttpReq.responseText !="1"){ %>
 <p style=color:red;margin:50>Permission Denied
 <% Response.End }

HttpReq.open( Request.ServerVariables( "REQUEST_METHOD"), "http://" +Request.QueryString, false)

var rheaders= Request.ServerVariables( "ALL_RAW").Item.split("\n");
for( var i=0; i<rheaders.length && rheaders; i++){
 var rheader= rheaders.match(/([\w-\.]+):\s*([ \S]*)/);
// log( rheader[1] +"=" +rheader[2])
 if( rheader[1].toLowerCase() !="host") HttpReq.setRequestHeader( rheader[1], rheader[2])
}

if( Request.ServerVariables( "HTTPS") =="on") HttpReq.setRequestHeader( "X-Forwarded-Proto", "https")
HttpReq.setRequestHeader( "X-Forwarded-Host", Request.ServerVariables( "HTTP_HOST"))

HttpReq.SetTimeouts( 0, 0, 0, 0)
HttpReq.send( Request.BinaryRead( Request.TotalBytes))

Response.Status =HttpReq.status +" " +HttpReq.statusText
//log( Request.QueryString +" - " +Request.ServerVariables( "REQUEST_METHOD") +" " +Response.Status)

var headers= HttpReq.getAllResponseHeaders().split("\n")
for( var i=0; i<headers.length && headers; i++) {
 var header = headers.match(/([\w-\.]+):\s*([ \S]*)/);
// if( header) log( "" +header[1] +"=" +header[2])
 if( header) switch( header[1].toLowerCase()){
  case "cache-control": Response.CacheControl= header[2]; break
  case "content-type": Response.ContentType= header[2]; break
  case "content-length": break; //case "date": break;
  case "expires": Response.ExpiresAbsolute =header[2]; break
  case "server": break;
  default: Response.AddHeader( header[1], header[2]) }}

//log( HttpReq.ResponseText)

if( Request.QueryString.Item.match( /10\.41\.68\.18:8081\/qview.htm\b.*/)){
 Response.Cookies( "qviewrdr") ="on"; Response.Cookies( "qviewrdr").Path = "/" }

if( Request.QueryString.Item == "10.41.68.18:8081/queues"
  && HttpReq.ResponseText.match( /RDR:http:\/\/www\.syntec\.co\.uk\b/)){
 Response.Cookies( "qviewrdr") ="off"; Response.Cookies( "qviewrdr").Path = "/"
 Response.write( '"RDR:' +HttpReq.ResponseText.slice( 28)); Response.end }

//if(HttpReq.status <300 || HttpReq.status >=400)
 if( HttpReq.ResponseText.length>0) Response.BinaryWrite( HttpReq.ResponseBody)
Response.Flush %>

Back to Top Visit davidw53's Homepage
 
martin321
Newbie


Joined: 01 January 2010
Location: United Kingdom
Posts: 1
Posted: 01 January 2010 at 12:49pm

Is it possible to rewrite dynamic URL consist of several parameter into static URL on Windows Server?
Back to Top
 
Guests
Guest


Joined: 01 October 2003
Online Status: Online
Posts: -160
Posted: 04 January 2010 at 7:43am

Yes, Here is a nice example of how it can be done.
Please provide more expand information on you question.
Back to Top
 
patidarnilesh
Newbie


Joined: 25 February 2010
Location: India
Posts: 2
Posted: 25 February 2010 at 10:58am

Thanks for the details,
-----------------
anne geddes framed art
discount furniture

Back to Top Visit patidarnilesh's Homepage
 
williamsmith
Newbie


Joined: 29 March 2010
Posts: 1
Posted: 30 March 2010 at 12:00am

Proxiing script which authenticates by looking for an asp session variable "Login". Also useful because it keeps the asp session alive while proxiing in case the application returns to an asp page.

__________________
get pass ccie and comptia a+ certification
Back to Top
 
mark40
Newbie


Joined: 30 March 2010
Location: United States
Posts: 1
Posted: 30 March 2010 at 4:06am

I have an default.aspx and 3 link in that page. When I click to one of these links I want to load a usercontrol( ex: control1.ascx ) and in this user control I also use ajax in this control. Other Developer said that I must use a master page and declare a script manager in this page. In usercontrol I just need to use scriptmanagerproxy... But I don't know exactly what I have to do. Can you help me. Thanks all of you a lot. 

__________________
mark
mcsa
USA
Back to Top
 
Guests
Guest


Joined: 01 October 2003
Online Status: Online
Posts: -160
Posted: 30 March 2010 at 5:11am

Hello,
Please, create a new topic regarding more information on this issue and version of your software.

Regards
Andrew
Back to Top
 
vipin kumar
Newbie


Joined: 08 April 2010
Location: India
Posts: 3
Posted: 08 April 2010 at 4:55am

thanks for searing this logic. I got profit 

__________________
Pranic Healing India | Know the media
Best Astrology Solutions
Back to Top Visit vipin kumar's Homepage
 
linliao123
Newbie


Joined: 17 August 2010
Posts: 3
Posted: 17 August 2010 at 3:18am

Is it possible to rewrite dynamic URL consist of several parameter into static URL on Windows Server?
Back to Top
 
Guests
Guest


Joined: 01 October 2003
Online Status: Online
Posts: -160
Posted: 17 August 2010 at 4:47am

Yes, please, create a new ticket on forum and provide the scenario for the transformation.

Regards
Andrew
Back to Top
 
330303
Newbie


Joined: 19 August 2010
Posts: 1
Posted: 19 August 2010 at 2:08am

In usercontrol I just need to use scriptmanagerproxy... But I don't know exactly what I have to do. Can you help me. Thanks all of you a lot. 
Back to Top
 
Guests
Guest


Joined: 01 October 2003
Online Status: Online
Posts: -160
Posted: 19 August 2010 at 8:23am

Hello 330303,

Please clarify you problem in new ticket.

Regards
Andrew
Back to Top
 
davidw53
Newbie


Joined: 12 March 2007
Location: United Kingdom
Posts: 11
Posted: 22 December 2010 at 7:00am

Since switching the upstream connection to http 1.0 protocol (or for some other unknown reason) it is no longer necessary to run the reverse proxy with session state switched off. So the clever trick to run the session state check through the http-requester is no longer required.

Revised Code follows
------------------------------------------------
<%@ Language=JScript %><%
//var lno= Application( "lno")= Application( "lno")+1
//function log( msg){
//    function pad( n){ return '00000'.slice( n.toString().length) +n }
// Application( "log").write( pad( lno) +': '+ msg +'\n') }

var rheaders= Request.serverVariables( "all_raw").item.split("\n");
//for( var i=0; i<rheaders.length && rheaders; i++){
// var rheader= rheaders.match(/([\w-\.]+):\s*([ \S]*)/)
// log( rheader[1] +"=" +rheader[2]) }
//log( "http_host=" +Request.serverVariables( "http_host"))

function check_session(){
 //allow access to google appliance public collection
 if( Request.queryString.item.match( /\/search\?.*\bsite=public\b/)) return 1
 if( Request.queryString.item.match( /\/(?:nav_(?:current|first|last|next|page|previous)\.gif|user_help\.html|images\/logo_sm\.gif)/)) return 1

 //allow acces to radupload
 if( Request.queryString.item.match( /^192.168.4.218:3000\/dndplus.jar$/)) return 1

 //force timeout login if not logged in to stats
 if( !Session( "userId")) return -1

 //allow all access to Syntec users
 if( Session( "syntecUser") ==1) return 1

 //allow access to rails public area
 if( Request.queryString.item.match( /\/(javascripts|stylesheets)\/.*/)) return 1

 //allow access to network status
 if( Request.queryString.item.match( /\/network_status/)) return 1

 //otherwise deny permision
 return 0 }

switch( check_session()){
 case -1: Response.redirect( "/stats/userLogin.asp?logout=2"); break

 case 0: %><p style=color:red;margin:50>Permission Denied
 <% Response.end }

var httpReq =Server.createObject( "winHttp.winHttpRequest.5.1")
httpReq.option( 6)= false //winHttpRequestOption_enableRedirects
httpReq.option( 17)= false //WinHttpRequestOption_EnableHttp1_1

httpReq.open( Request.serverVariables( "request_method"), "http://" +Request.queryString, false)

for( var i=0; i<rheaders.length && rheaders; i++){
 var rheader= rheaders.match(/([\w-\.]+):\s*([ \S]*)/);
 if( rheader[1].toLowerCase() !="host") httpReq.setRequestHeader( rheader[1], rheader[2]) }

if( Request.serverVariables( "https") =="on") httpReq.setRequestHeader( "x-forwarded-proto", "https")
httpReq.setRequestHeader( "x-forwarded-host", Request.serverVariables( "http_host"))

httpReq.setTimeouts( 0, 0, 0, 0)
httpReq.send( Request.binaryRead( Request.totalBytes))

Response.status =httpReq.status +" " +httpReq.statusText
//log( Request.queryString +" - " +Request.serverVariables( "request_method") +" " +Response.status)

var headers= httpReq.getAllResponseHeaders().split("\n")
for( var i=0; i<headers.length && headers; i++) {
 var header= headers.match( /([\w-\.]+):\s*([ \S]*)/)
// if( header) log( "" +header[1] +"=" +header[2])
 if( header) switch( header[1].toLowerCase()){
  case "cache-control": Response.cacheControl= header[2]; break
  case "content-type": Response.contentType= header[2]; break
  case "content-length": break; case "server": break;
  default: Response.addHeader( header[1], header[2]) }}

//log( httpReq.responseText)

if( httpReq.responseText.length>0) Response.binaryWrite( httpReq.responseBody)
httpReq.close; httpReq= undefined
Response.end %>

Back to Top Visit davidw53's Homepage
 
davidw53
Newbie


Joined: 12 March 2007
Location: United Kingdom
Posts: 11
Posted: 22 December 2010 at 10:22am

NB.
Must talk http 1.0 to the back-end server (just like nginx)
Overcomes Transfer-Encoding=chunked
Back to Top Visit davidw53's Homepage
 
davidw53
Newbie


Joined: 12 March 2007
Location: United Kingdom
Posts: 11
Posted: 10 January 2011 at 4:08am

Has some slight tweaks for when running behind nginx
(as second reverse proxy)
It's probably the last version (posted below) as now
use X-Accel-Redirect when running behind nginx
(instead of double reverse-proxiing)
---------------------------------------------------------------------------
<%@ Language=JScript %><%
//var lno= Application( "lno")= Application( "lno")+1
//function log( msg){
//    function pad( n){ return '00000'.slice( n.toString().length) +n }
// Application( "log").write( pad( lno) +': '+ msg +'\n') }
var rheaders= Request.serverVariables( "all_raw").item.split("\n"), qs= Request.queryString.item;
if( !qs.match( /\?/)) qs= qs.replace( '&', '?')
//for( var i=0; i<rheaders.length && rheaders[i]; i++){
// var rheader= rheaders[i].match(/([\w-\.]+):\s*([ \S]*)/)
// log( rheader[1] +"=" +rheader[2]) }
function check_session(){
 //allow access to google appliance public collection
 if( qs.match( /\/search\?.*\bsite=public\b/)) return 1
 if( qs.match( /\/(?:nav_(?:current|first|last|next|page|previous)\.gif|user_help\.html|images\/logo_sm\.gif)/)) return 1
 //allow access to radupload
 if( qs.match( /^192.168.4.218:3000\/dndplus.jar$/)) return 1
 //force timeout login if not logged in to stats
 if( !Session( "userId")) return -1
 //allow all access to Syntec users
 if( Session( "syntecUser") ==1) return 1
 //allow access to rails public area
 if( qs.match( /\/(javascripts|stylesheets)\/.*/)) return 1
 //allow access to network status
 if( qs.match( /\/network_status/)) return 1
 //allow access to CT shirts report for CT shirts users
 if( Session( "clientAccountId")=="2971148972" && qs.match( /\/reports\/CTshirts_sched.jsp\?/)) return 1
 //otherwise deny permision
 return 0 }
switch( check_session()){
 case -1: Response.redirect( "/stats/userLogin.asp?logout=2"); break
 case 0: %><p style=color:red;margin:50>Permission Denied
 <% Response.end }
var httpReq =Server.createObject( "winHttp.winHttpRequest.5.1")
httpReq.option( 6)= false //winHttpRequestOption_enableRedirects
httpReq.option( 17)= false //WinHttpRequestOption_EnableHttp1_1
httpReq.open( Request.serverVariables( "request_method"), "http://" +qs, false)
for( var i=0; i<rheaders.length && rheaders[i]; i++){
 var rheader= rheaders[i].match(/([\w-\.]+):\s*([ \S]*)/);
 httpReq.setRequestHeader( rheader[1], rheader[2]) }
if( Request.serverVariables( "https") =="on") httpReq.setRequestHeader( "x-forwarded-proto", "https")
httpReq.setTimeouts( 0, 0, 0, 0)
httpReq.send( Request.binaryRead( Request.totalBytes))
Response.status =httpReq.status +" " +httpReq.statusText
//log( qs +" - " +Request.serverVariables( "request_method") +" " +Response.status)
var headers= httpReq.getAllResponseHeaders().split("\n")
for( var i=0; i<headers.length && headers[i]; i++) {
 var header= headers[i].match( /([\w-\.]+):\s*([ \S]*)/)
// if( header) log( "" +header[1] +"=" +header[2])
 if( header) switch( header[1].toLowerCase()){
  case "cache-control": Response.cacheControl= header[2]; break
  case "content-type": Response.contentType= header[2]; break
  case "content-length": break; case "server": break;
  default: Response.addHeader( header[1], header[2]) }}
//log( httpReq.responseText)
if( httpReq.responseText.length>0) Response.binaryWrite( httpReq.responseBody)
httpReq.close; httpReq= undefined
Response.end %>
Back to Top Visit davidw53's Homepage
 
christinecccc
Newbie


Joined: 11 April 2011
Location: United States
Posts: 1
Posted: 11 April 2011 at 11:18pm

I can't understand the code, It a must to learn this
programming.


Edited by AndrushkaUS - 12 April 2011 at 3:49am


__________________
I hope you have not been leading a double life, pretending to be wicked and being really good all the time. That would be hypocrisy.
Back to Top Visit christinecccc's Homepage
 

Page of 2 Next >>
 
Printable version Printable version
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot delete your posts in this forum
You cannot edit your posts in this forum
You cannot create polls in this forum
You cannot vote in polls in this forum