<%@ language="javascript" %> <% /********************************************** * RSS Replay v 1.6.2 build 069 * ASP Proxy Service v 1.3 * Coded by Ronald Northrip * Jan-Mar 2009 * * All code here is Copyright Protected. * Use or distribution without permission is * strictly prohibited. * Copyright 2009. All Rights Reserved. * Ronald Northrip Software Incorporated * http://www.rnsoft.com/ *********************************************** * Parameter Notes * cache = true - enable caching * cachettl = num - duration in minutes * source = id - the url to request from * the sources list * utf8 = 0/1 - utf8 enforment * XX OLD request = url - the url to request * format = js - empty js request used for * link maintenance in DW ***********************************************/ //allowed sources list var sources=new Array; sources["newsgo3"]="http://news.google.com.au/news?ned=au&hl=en&q=%22iraq+security%22&output=rss" sources["newsgo1"]="http://news.google.com.au/news?hl=en&ned=au&ie=UTF-8&scoring=d&q=%22private+security%22+iraq&output=rss" //disallow cacheing settings var neverCache=false //globals var errorprefix="RSS Replay Proxy Error:"; var cachedir="rssReplayCache"; var gotfromcache=false; var now=new Date().getTime(); //time is measured in milliseconds //map the path to a full dir path for use later cachedir=Server.MapPath(cachedir) //localizable strings var localJavascriptResponse="Javascript empty response for link maintenance"; var localErrorNoRequest="No Request Passed"; var localErrorUnsupportedProto="Unsupported Protocol for"; var localErrorNoNetConnection="Unable to create network connections for proxy"; var localErrorNoDataReturned="No Data Returned from"; var localErrorNoMatchingSourceID="No matching source for the specified ID"; var localErrorOldRequestMethod="Old request method is not compatible with this proxy"; //remove queryString variables from method so they //may be overridden/modified - store in array var httpGetVars=new Array httpGetVars["cache"]="" httpGetVars["cachettl"]="" httpGetVars["source"]="" httpGetVars["format"]="" httpGetVars["utf8"]="" httpGetVars["request"]="" if (Request.queryString("cache").Count==1) {httpGetVars["cache"]=Request.queryString("cache")} if (Request.queryString("cachettl").Count==1) {httpGetVars["cachettl"]=Request.queryString("cachettl")} if (Request.queryString("source").Count==1) {httpGetVars["source"]=Request.queryString("source")} if (Request.queryString("format").Count==1) {httpGetVars["format"]=Request.queryString("format")} if (Request.queryString("utf8").Count==1) {httpGetVars["utf8"]=Request.queryString("utf8")} if (Request.queryString("request").Count==1) {httpGetVars["request"]=Request.queryString("request")} //enforce UTF8 in the response if (httpGetVars["utf8"]!="0") { Response.Charset = "utf-8" Response.Codepage = 65001 } //if a "request" was passed then error out if (httpGetVars["request"]+""!="") { Response.write(errorprefix+" "+localErrorOldRequestMethod); Response.end() } //if format=js then break out if ((httpGetVars["source"]+""=="") || (httpGetVars["format"]=="js")) { Response.ContentType="text/javascript" Response.write("// "+localJavascriptResponse) Response.end() } //set the caching based on neverCache local setting //overrides what is passed in the get if (neverCache) { httpGetVars["cache"]="false"; } //default for cachettl var cachettlsec=0 if (httpGetVars["cachettl"]=="") { //get fresh every 4 hours * 60 min * 60 sec cachettlsec=4*60*60; } else { cachettlsec=httpGetVars["cachettl"]*60; } var cachettlmillisec=cachettlsec*1000 //there doesn't seem to be a referrer with firefox browser //checking references is useless //check for a matching source if (!sources[httpGetVars["source"]]) { Response.write(errorprefix+" "+localErrorNoMatchingSourceID+" "+httpGetVars["source"]); Response.end(); } var req=(sources[httpGetVars["source"]]).toLowerCase() if (req=="") { Response.write(errorprefix+" "+localErrorNoRequest); Response.end(); } //restrict request to be http var ref="" if (req.substring(0,7)=="http://"){ ref=req.substring(7,req.length); //} elseif (substr(req,0,8)=="https://"){ // ref=substr(req,8); } else { Response.write(errorprefix+" "+localErrorUnsupportedProto+" "+req); Response.end(); } //if caching check for a cache dir and change to it var hascachedir=false; var fs=Server.CreateObject("Scripting.FileSystemObject") if (httpGetVars["cache"]=="true") { if (!fs.FileExists(cachedir)) { if (!fs.FolderExists(cachedir)) { try { var fo=fs.CreateFolder(cachedir) } catch(err) { var fo=null } } else { var fo=fs.GetFolder(cachedir) } if (fo!=null) {hascachedir=true;} } } //check cache - DateLastModified var data="" if ((httpGetVars["cache"]=="true") && (hascachedir==true)) { var breakthewhile=false; //an enumarator objects is require to iterate the collection is ASP-JS var e = new Enumerator(fo.Files); for (e.moveFirst(); (!e.atEnd()) && (!breakthewhile); e.moveNext()) { var f = e.item(); //get url from first line of cache file var ts=f.OpenAsTextStream(1) var url=ts.ReadLine() ts.Close() var d=new Date(f.DateLastModified).getTime() //check the url against the request if (url==sources[httpGetVars["source"]]) { breakthewhile=true; //check the ttl if ((now-d)>cachettlmillisec) { //too old - delete cache file f.Delete() } else { //read and remove the first line of the file ts=f.OpenAsTextStream(1) ts.SkipLine() data=ts.ReadAll() ts.Close() gotfromcache=true } } } } //pass on request if not already pulled from cached if (gotfromcache!=true) { //get the requested file var objWinHttp=null var gotErrors=false // Create our XML HTTP request object try { objWinHttp = Server.CreateObject("MSXML2.ServerXMLHTTP") } catch(err) { gotErrors=true } if (gotErrors==true) { gotErrors=false // try a different HTTP request object try { objWinHttp = Server.CreateObject("Microsoft.XMLHTTP") } catch(err) { gotErrors=true } } //check for errors if (gotErrors==true) { Response.write(errorprefix+" "+localErrorNoNetConnection) Response.end() } else { //connector is available - so use it objWinHttp.open("GET",sources[httpGetVars["source"]],false) objWinHttp.send() data=objWinHttp.responseText if (objWinHttp.status != 200) { data=""} if (data=="") { Response.write(errorprefix+" "+localErrorNoDataReturned+" "+sources[httpGetVars["source"]]) Response.end() } } //cache the result if ((httpGetVars["cache"]=="true") && (hascachedir) && (data!="")) { try { cachefile=""+Server.CreateObject("Scriptlet.Typelib").guid cachefile=cachefile.replace(/\{/,"") cachefile=cachefile.replace(/\}/,"") cachefile=cachefile.replace(/-/g,"_") cachefile="rrpcache_"+cachefile } catch(err) { var d=new Date().getTime() cachefile="rrpcache_"+d+"_"+Math.floor(Math.random()*99999999) } //write the collected data to the cache folder try { ts=fo.CreateTextFile(cachefile,true) } catch(err) { ts=null } if (ts!=null) { ts.WriteLine(sources[httpGetVars["source"]]) ts.Write(data) ts.Close() } } } //xml header Response.ContentType="text/xml" //finish the output by sending the data Response.write(data) //clear out objects that might be persistent objWinHttp=null ts=null f=null e=null fo=null fs=null %>