| Posted: 10 January 2011 at 4:08am | IP Logged
|
|
|
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 %>
|