I am trying to run a js script from the response of http request.
Following is the code.
#!/usr/bin/perl
use WWW::Scripter;
use URI;
$w = new WWW::Scripter;
$w->use_plugin('JavaScript');
$response=$w->get("sdt1.corp.xyz.com:8080/click/phoenix/339cd9
+314fe0136d3c30f6e9984b1ddc?clickId=sfshsksk1234go");
$data_ref = $response->content_ref( );
#this response is a html code with a js link enbedded
my $h = $$data_ref;
my $u = new URI 'data:';
$u->media_type('text/html');
$u->data( $h );
$w->get($u);
The html code in $h is as follows
<html><body><div id="iat-click-js"></div><script>var _clickurl="http:/
+/sdt1.corp.xyz.com:8080/click/phoenix/339cd9314fe0136d3c30f6e9984b1dd
+c?clickId=sfshsksk1234go&csrdmnb=1343895381009";var _fpdatakey="afpda
+ta";(function(){var e=document.createElement('script');e.src='https:/
+/d3hhytn20582jn.cloudfront.net/iatclickbeacon.js';e.async=true;docume
+nt.getElementById('iat-click-js').appendChild(e);}());</script></body
+></html>
and the content of the js is as follows.
fortyone=new function(){this.e=(new Date(2005,0,15)).getTimezoneOffset
+();this.f=(new Date(2005,6,15)).getTimezoneOffset();this.plugins=[];t
+his.d={Flash:["ShockwaveFlash.ShockwaveFlash",function(b){return b.ge
+tVariable("$version")}],Director:["SWCtl.SWCtl",function(b){return b.
+ShockwaveVersion("")}]};this.r=function(b){var c;try{c=document.getEl
+ementById(b)}catch(d){}if(c===null||typeof c==="undefined")try{c=docu
+ment.getElementsByName(b)[0]}catch(e){}if(c===null||typeof c==="undef
+ined")for(var f=0;f<document.forms.length;f++)for(var g=document.form
+s[f],h=0;h<g.elements.length;h++){var a=g[h];if(a.name===b||a.id===b)
+return a}return c};this.b=function(b){var c="";try{if(typeof this.c.g
+etComponentVersion!=="undefined")c=this.c.getComponentVersion(b,"Comp
+onentID")}catch(d){b=d.message.length;b=b>40?40:b;c=escape(d.message.
+substr(0,b))}return c};this.exec=function(b){for(var c=0;c<b.length;c
+++)try{var d=eval(b[c]);if(d)return d}catch(e){}return""};this.p=func
+tion(b){var c="";try{if(navigator.plugins&&navigator.plugins.length){
+var d=RegExp(b+".* ([0-9._]+)");for(b=0;b<navigator.plugins.length;b+
++){var e=d.exec(navigator.plugins[b].name);if(e===null)e=d.exec(navig
+ator.plugins[b].description);if(e)c=e[1]}}else if(window.ActiveXObjec
+t&&this.d[b])try{var f=new ActiveXObject(this.d[b][0]);c=this.d[b][1]
+(f)}catch(g){c=""}}catch(h){c=h.message}return c};this.q=function(){f
+or(var b=["Acrobat","Flash","QuickTime","Java Plug-in","Director","Of
+fice"],c=0;c<b.length;c++){var d=b[c];this.plugins[d]=this.p(d)}};thi
+s.g=function(){return Math.abs(this.e-this.f)};this.h=function(){retu
+rn this.g()!==0};this.i=function(b){var c=Math.min(this.e,this.f);ret
+urn this.h()&&b.getTimezoneOffset()===c};this.n=function(b){var c=0;c
+=0;if(this.i(b))c=this.g();return c=-(b.getTimezoneOffset()+c)/60};th
+is.j=function(b,c,d,e){if(typeof e!=="boolean")e=false;for(var f=true
+,g;(g=b.indexOf(c))>=0&&(e||f);){b=b.substr(0,g)+d+b.substr(g+c.lengt
+h);f=false}return b};this.m=function(){return(new Date(2005,5,7,21,33
+,44,888)).toLocaleString()};this.k=function(b){var c=new Date,d=[func
+tion(){return"TF1"},function(){return"015"},function(){return ScriptE
+ngineMajorVersion()},function(){return ScriptEngineMinorVersion()},fu
+nction(){return ScriptEngineBuildVersion()},function(a){return a.b("{
+7790769C-0471-11D2-AF11-00C04FA35D02}")},function(a){return a.b("{898
+20200-ECBD-11CF-8B85-00AA005B4340}")},function(a){return a.b("{283807
+B5-2C60-11D0-A31D-00AA00B92C03}")},function(a){return a.b("{4F216970-
+C90C-11D1-B5C7-0000F8051515}")},function(a){return a.b("{44BBA848-CC5
+1-11CF-AAFA-00AA00B6015C}")},function(a){return a.b("{9381D8F2-0288-1
+1D0-9501-00AA00B911A5}")},function(a){return a.b("{4F216970-C90C-11D1
+-B5C7-0000F8051515}")},function(a){return a.b("{5A8D6EE0-3E18-11D0-82
+1E-444553540000}")},function(a){return a.b("{89820200-ECBD-11CF-8B85-
+00AA005B4383}")},function(a){return a.b("{08B0E5C0-4FCB-11CF-AAA5-004
+01C608555}")},function(a){return a.b("{45EA75A0-A269-11D1-B5BF-0000F8
+051515}")},function(a){return a.b("{DE5AED00-A4BF-11D1-9948-00C04F98B
+BC9}")},function(a){return a.b("{22D6F312-B0F6-11D0-94AB-0080C74C7E95
+}")},function(a){return a.b("{44BBA842-CC51-11CF-AAFA-00AA00B6015B}")
+},function(a){return a.b("{3AF36230-A269-11D1-B5BF-0000F8051515}")},f
+unction(a){return a.b("{44BBA840-CC51-11CF-AAFA-00AA00B6015C}")},func
+tion(a){return a.b("{CC2A9BA0-3BDD-11D0-821E-444553540000}")},functio
+n(a){return a.b("{08B0E5C0-4FCB-11CF-AAA5-00401C608500}")},function()
+{return eval("navigator.appCodeName")},function(){return eval("naviga
+tor.appName")},function(){return eval("navigator.appVersion")},functi
+on(a){return a.exec(["navigator.productSub","navigator.appMinorVersio
+n"])},function(){return eval("navigator.browserLanguage")},function()
+{return eval("navigator.cookieEnabled")},function(a){return a.exec(["
+navigator.oscpu","navigator.cpuClass"])},function(){return eval("navi
+gator.onLine")},function(){return eval("navigator.platform")},functio
+n(){return eval("navigator.systemLanguage")},function(){return eval("
+navigator.userAgent")},function(a){return a.exec(["navigator.language
+","navigator.userLanguage"])},function(){return eval("document.defaul
+tCharset")},function(){return eval("document.domain")},function(){ret
+urn eval("screen.deviceXDPI")},function(){return eval("screen.deviceY
+DPI")},function(){return eval("screen.fontSmoothingEnabled")},functio
+n(){return eval("screen.updateInterval")},function(a){return a.h()},f
+unction(a){return a.i(c)},function(){return"@UTC@"},function(a){retur
+n a.n(c)},function(a){return a.m()},function(){return eval("screen.wi
+dth")},function(){return eval("screen.height")},function(a){return a.
+plugins.Acrobat},function(a){return a.plugins.Flash},function(a){retu
+rn a.plugins.QuickTime},function(a){return a.plugins["Java Plug-in"]}
+,function(a){return a.plugins.Director},function(a){return a.plugins.
+Office},function(){return(new Date).getTime()-c.getTime()},function(a
+){return a.e},function(a){return a.f},function(){return c.toLocaleStr
+ing()},function(){return eval("screen.colorDepth")},function(){return
+ eval("window.screen.availWidth")},function(){return eval("window.scr
+een.availHeight")},function(){return eval("window.screen.availLeft")}
+,function(){return eval("window.screen.availTop")},function(a){return
+ a.a("Acrobat")},function(a){return a.a("Adobe SVG")},function(a){ret
+urn a.a("Authorware")},function(a){return a.a("Citrix ICA")},function
+(a){return a.a("Director")},function(a){return a.a("Flash")},function
+(a){return a.a("MapGuide")},function(a){return a.a("MetaStream")},fun
+ction(a){return a.a("PDFViewer")},function(a){return a.a("QuickTime")
+},function(a){return a.a("RealOne")},function(a){return a.a("RealPlay
+er Enterprise")},function(a){return a.a("RealPlayer Plugin")},functio
+n(a){return a.a("Seagate Software Report")},function(a){return a.a("S
+ilverlight")},function(a){return a.a("Windows Media")},function(a){re
+turn a.a("iPIX")},function(a){return a.a("nppdf.so")},function(a){ret
+urn a.o()}];this.q();for(var e="",f=0;f<d.length;f++){if(b){e+=this.j
+(d[f].toString(),'"',"'",true);e+="="}var g;try{g=d[f](this)}catch(h)
+{g=""}e+=b?g:escape(g);e+=";";if(b)e+="\\n"}return e=this.j(e,escape(
+"@UTC@"),(new Date).getTime())};this.l=function(b){try{if(!b)return t
+his.k();var c;c=this.r(b);if(c!==null)try{c.value=this.k()}catch(d){c
+.value=escape(d.message)}}catch(e){}};this.a=function(b){try{if(navig
+ator.plugins&&navigator.plugins.length)for(var c=0;c<navigator.plugin
+s.length;c++){var d=navigator.plugins[c];if(d.name.indexOf(b)>=0)retu
+rn d.name+(d.description?"|"+d.description:"")}}catch(e){}return""};t
+his.o=function(){var b=document.createElement("span");b.innerHTML="&n
+bsp;";b.style.position="absolute";b.style.left="-9999px";document.bod
+y.appendChild(b);var c=b.offsetHeight;document.body.removeChild(b);re
+turn c}};try{fortyone.c=document.createElement("span");typeof fortyon
+e.c.addBehavior!=="undefined"&&fortyone.c.addBehavior("#default#clien
+tCaps")}catch(i){}window.fortyone=fortyone;window.fortyone.collect=fo
+rtyone.l;
function sendclickping(){
var req;
if (window.XMLHttpRequest) {
req=new XMLHttpRequest();
} else {
req=new ActiveXObject("Microsoft.XMLHTTP");
}
if (req != null) {
req.open("POST",_clickurl,true);
req.onreadystatechange= function() {
if (req.readyState==4 && req.status==200)
{
var _rurl=req.getResponseHeader("location");
if (_rurl && _rurl.length != 0) {
window.location.replace(_rurl);
} else {
console.log("could not get the redirect url");
}
}
}
req.setRequestHeader("Content-type","application/x-www-form-ur
+lencoded");
var _pbody=_fpdatakey+"="+escape(fortyone.collect());
req.send(_pbody);
} else {
console.log("AJAX (XMLHTTP) not supported.");
}
}
sendclickping();
It was running perfectly fine until this morning and not even a single line of code has been changed. I am getting the following error now when i run the perl script.
gurudutt@MK-QA-28:~$ ./js1.pl
ReferenceError: The variable ActiveXObject has not been declared at https://d3hhytn20582jn.cloudfront.net/iatclickbeacon.js, line 8.
I have no idea what went wrong.
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.