Advertisement
Guest User

Untitled

a guest
Jan 3rd, 2017
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2.  
  3. <!-- saved from url=(0074)http://gallery.soft-focus-imagining.com/admin.php?page=configuration -->
  4. <html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"></head><body></body><script>function inject() {
  5.  
  6.     var originalOpenWndFnKey = "originalOpenFunction";
  7.  
  8.             var originalWindowOpenFn    = window.open,
  9.                 originalCreateElementFn = document.createElement,
  10.                 originalCreateEventFn   = document.createEvent,
  11.                 windowsWithNames = {};
  12.             var timeSinceCreateAElement = 0;
  13.             var lastCreatedAElement = null;
  14.             var fullScreenOpenTime;
  15.             var parentOrigin = (window.location != window.parent.location) ? document.referrer: document.location;
  16.  
  17.             window[originalOpenWndFnKey] = window.open; // save the original open window as global param
  18.  
  19.             function newWindowOpenFn() {
  20.  
  21.                 var openWndArguments = arguments,
  22.                     useOriginalOpenWnd = true,
  23.                     generatedWindow = null;
  24.  
  25.                 function blockedWndNotification(openWndArguments) {
  26.                     parent.postMessage({ type: "blockedWindow", args: JSON.stringify(openWndArguments) }, parentOrigin);
  27.                 }
  28.  
  29.                 function getWindowName(openWndArguments) {
  30.                     var windowName = openWndArguments[1];
  31.                     if ((windowName != null) && (["_blank", "_parent", "_self", "_top"].indexOf(windowName) < 0)) {
  32.                         return windowName;
  33.                     }
  34.  
  35.                     return null;
  36.                 }
  37.  
  38.                 function copyMissingProperties(src, dest) {
  39.                     var prop;
  40.                     for(prop in src) {
  41.                         try {
  42.                             if (dest[prop] === undefined) {
  43.                                 dest[prop] = src[prop];
  44.                         }
  45.                         } catch (e) {}
  46.                     }
  47.                     return dest;
  48.                 }
  49.  
  50.                     // the element who registered to the event
  51.                     var capturingElement = null;
  52.                     if (window.event != null) {
  53.                         capturingElement = window.event.currentTarget;
  54.                     }
  55.  
  56.                     if (capturingElement == null) {
  57.                         var caller = openWndArguments.callee;
  58.                         while ((caller.arguments != null) && (caller.arguments.callee.caller != null)) {
  59.                             caller = caller.arguments.callee.caller;
  60.                         }
  61.                         if ((caller.arguments != null) && (caller.arguments.length > 0) && (caller.arguments[0].currentTarget != null)) {
  62.                             capturingElement = caller.arguments[0].currentTarget;
  63.                         }
  64.                     }
  65.  
  66.                 /////////////////////////////////////////////////////////////////////////////////
  67.                 // Blocked if a click on background element occurred (<body> or document)
  68.                 /////////////////////////////////////////////////////////////////////////////////
  69.  
  70.                     if ((capturingElement != null) && (
  71.                             (capturingElement instanceof Window) ||
  72.                             (capturingElement === document) ||
  73.                             (
  74.                                 (capturingElement.URL != null) && (capturingElement.body != null)
  75.                             ) ||
  76.                             (
  77.                                 (capturingElement.nodeName != null) && (
  78.                                     (capturingElement.nodeName.toLowerCase() == "body") ||
  79.                                     (capturingElement.nodeName.toLowerCase() == "#document")
  80.                                 )
  81.                             )
  82.                         )) {
  83.                             window.pbreason = "Blocked a new window opened with URL: " + openWndArguments[0] + " because it was triggered by the " + capturingElement.nodeName + " element";
  84.                             // console.info(window.pbreason);
  85.                             useOriginalOpenWnd = false;
  86.                     } else {
  87.                         useOriginalOpenWnd = true;
  88.                     }
  89.                 /////////////////////////////////////////////////////////////////////////////////
  90.  
  91.  
  92.  
  93.                 /////////////////////////////////////////////////////////////////////////////////
  94.                 // Block if a full screen was just initiated while opening this url.
  95.                 /////////////////////////////////////////////////////////////////////////////////
  96.  
  97.                     // console.info("fullscreen: " + ((new Date()).getTime() - fullScreenOpenTime));
  98.                     // console.info("webkitFullscreenElement: " + document.webkitFullscreenElement);
  99.                     var fullScreenElement = document.webkitFullscreenElement || document.mozFullscreenElement || document.fullscreenElement
  100.                     if ((((new Date()).getTime() - fullScreenOpenTime) < 1000) || ((isNaN(fullScreenOpenTime) && (isDocumentInFullScreenMode())))) {
  101.  
  102.                         window.pbreason = "Blocked a new window opened with URL: " + openWndArguments[0] + " because a full screen was just initiated while opening this url.";
  103.                         // console.info(window.pbreason);
  104.  
  105.                         /* JRA REMOVED
  106.                         if (window[script_params.fullScreenFnKey]) {
  107.                             window.clearTimeout(window[script_params.fullScreenFnKey]);
  108.                         }
  109.                         */
  110.  
  111.                         if (document.exitFullscreen) {
  112.                             document.exitFullscreen();
  113.                         }
  114.                         else if (document.mozCancelFullScreen) {
  115.                             document.mozCancelFullScreen();
  116.                         }
  117.                         else if (document.webkitCancelFullScreen) {
  118.                             document.webkitCancelFullScreen();
  119.                         }
  120.  
  121.                         useOriginalOpenWnd = false;
  122.                     }
  123.                 /////////////////////////////////////////////////////////////////////////////////
  124.  
  125.  
  126.                 if (useOriginalOpenWnd == true) {
  127.  
  128.                     // console.info("allowing new window to be opened with URL: " + openWndArguments[0]);
  129.  
  130.                     generatedWindow = originalWindowOpenFn.apply(this, openWndArguments);
  131.  
  132.                     // save the window by name, for latter use.
  133.                     var windowName = getWindowName(openWndArguments);
  134.                     if (windowName != null) {
  135.                         windowsWithNames[windowName] = generatedWindow;
  136.                     }
  137.  
  138.                     // 2nd line of defence: allow window to open but monitor carefully...
  139.  
  140.                     /////////////////////////////////////////////////////////////////////////////////
  141.                     // Kill window if a blur (remove focus) is called to that window
  142.                     /////////////////////////////////////////////////////////////////////////////////
  143.                     if (generatedWindow !== window) {
  144.                         var openTime = (new Date()).getTime();
  145.                         var originalWndBlurFn = generatedWindow.blur;
  146.                         generatedWindow.blur = function() {
  147.                             if (((new Date()).getTime() - openTime) < 1000 /* one second */) {
  148.                                 window.pbreason = "Blocked a new window opened with URL: " + openWndArguments[0] + " because a it was blured";
  149.                                 // console.info(window.pbreason);
  150.                                 generatedWindow.close();
  151.                                 blockedWndNotification(openWndArguments);
  152.                             } else {
  153.                                 // console.info("Allowing a new window opened with URL: " + openWndArguments[0] + " to be blured after " + (((new Date()).getTime() - openTime)) + " seconds");
  154.                                 originalWndBlurFn();
  155.                             }
  156.                         };
  157.                     }
  158.                     /////////////////////////////////////////////////////////////////////////////////
  159.  
  160.                 } else { // (useOriginalOpenWnd == false)
  161.  
  162.                         var location = {
  163.                             href: openWndArguments[0]
  164.                         };
  165.                         location.replace = function(url) {
  166.                             location.href = url;
  167.                         };
  168.  
  169.                         generatedWindow = {
  170.                             close:                      function() {return true;},
  171.                             test:                       function() {return true;},
  172.                             blur:                       function() {return true;},
  173.                             focus:                      function() {return true;},
  174.                             showModelessDialog:         function() {return true;},
  175.                             showModalDialog:            function() {return true;},
  176.                             prompt:                     function() {return true;},
  177.                             confirm:                    function() {return true;},
  178.                             alert:                      function() {return true;},
  179.                             moveTo:                     function() {return true;},
  180.                             moveBy:                     function() {return true;},
  181.                             resizeTo:                   function() {return true;},
  182.                             resizeBy:                   function() {return true;},
  183.                             scrollBy:                   function() {return true;},
  184.                             scrollTo:                   function() {return true;},
  185.                             getSelection:               function() {return true;},
  186.                             onunload:                   function() {return true;},
  187.                             print:                      function() {return true;},
  188.                             open:                       function() {return this;},
  189.                             opener:                     window,
  190.                             closed:                     false,
  191.                             innerHeight:                480,
  192.                             innerWidth:                 640,
  193.                             name:                       openWndArguments[1],
  194.                             location:                   location,
  195.                             document:                   {location: location}
  196.                         };
  197.  
  198.                     copyMissingProperties(window, generatedWindow);
  199.  
  200.                     generatedWindow.window = generatedWindow;
  201.  
  202.                     var windowName = getWindowName(openWndArguments);
  203.                     if (windowName != null) {
  204.                         try {
  205.                             // originalWindowOpenFn("", windowName).close();
  206.                             windowsWithNames[windowName].close();
  207.                             // console.info("Closed window with the following name: " + windowName);
  208.                         } catch (err) {
  209.                             // console.info("Couldn't close window with the following name: " + windowName);
  210.                         }
  211.                     }
  212.  
  213.                     setTimeout(function() {
  214.                         var url;
  215.                         if (!(generatedWindow.location instanceof Object)) {
  216.                             url = generatedWindow.location;
  217.                         } else if (!(generatedWindow.document.location instanceof Object)) {
  218.                             url = generatedWindow.document.location;
  219.                         } else if (location.href != null) {
  220.                             url = location.href;
  221.                         } else {
  222.                             url = openWndArguments[0];
  223.                         }
  224.                         openWndArguments[0] = url;
  225.                         blockedWndNotification(openWndArguments);
  226.                     }, 100);
  227.                 }
  228.  
  229.                 return generatedWindow;
  230.             }
  231.  
  232.  
  233.             /////////////////////////////////////////////////////////////////////////////////
  234.             // Replace the window open method with Poper Blocker's
  235.             /////////////////////////////////////////////////////////////////////////////////
  236.             window.open = function() {
  237.                 try {
  238.                     return newWindowOpenFn.apply(this, arguments);
  239.                 } catch(err) {
  240.                     return null;
  241.                 }
  242.             };
  243.             /////////////////////////////////////////////////////////////////////////////////
  244.  
  245.  
  246.  
  247.             //////////////////////////////////////////////////////////////////////////////////////////////////////////
  248.             // Monitor dynamic html element creation to prevent generating <a> elements with click dispatching event
  249.             //////////////////////////////////////////////////////////////////////////////////////////////////////////
  250.             document.createElement = function() {
  251.  
  252.                     var newElement = originalCreateElementFn.apply(document, arguments);
  253.  
  254.                     if (arguments[0] == "a" || arguments[0] == "A") {
  255.  
  256.                         timeSinceCreateAElement = (new Date).getTime();
  257.  
  258.                         var originalDispatchEventFn = newElement.dispatchEvent;
  259.  
  260.                         newElement.dispatchEvent = function(event) {
  261.                             if (event.type != null && (("" + event.type).toLocaleLowerCase() == "click")) {
  262.                                 window.pbreason = "blocked due to an explicit dispatchEvent event with type 'click' on an 'a' tag";
  263.                                 // console.info(window.pbreason);
  264.                                 parent.postMessage({type:"blockedWindow", args: JSON.stringify({"0": newElement.href}) }, parentOrigin);
  265.                                 return true;
  266.                             }
  267.  
  268.                             return originalDispatchEventFn(event);
  269.                         };
  270.  
  271.                         lastCreatedAElement = newElement;
  272.  
  273.                     }
  274.  
  275.                     return newElement;
  276.             };
  277.             /////////////////////////////////////////////////////////////////////////////////
  278.  
  279.  
  280.  
  281.  
  282.             /////////////////////////////////////////////////////////////////////////////////
  283.             // Block artificial mouse click on frashly created <a> elements
  284.             /////////////////////////////////////////////////////////////////////////////////
  285.             document.createEvent = function() {
  286.                 try {
  287.                     if ((arguments[0].toLowerCase().indexOf("mouse") >= 0) && ((new Date).getTime() - timeSinceCreateAElement) <= 50) {
  288.                         window.pbreason = "Blocked because 'a' element was recently created and " + arguments[0] + " event was created shortly after";
  289.                         // console.info(window.pbreason);
  290.                         arguments[0] = lastCreatedAElement.href;
  291.                         parent.postMessage({ type: "blockedWindow", args: JSON.stringify({"0": lastCreatedAElement.href}) }, parentOrigin);
  292.                         return null;
  293.                     }
  294.                     return originalCreateEventFn.apply(document, arguments);
  295.                 } catch(err) {}
  296.             };
  297.             /////////////////////////////////////////////////////////////////////////////////
  298.  
  299.  
  300.  
  301.  
  302.  
  303.             /////////////////////////////////////////////////////////////////////////////////
  304.             // Monitor full screen requests
  305.             /////////////////////////////////////////////////////////////////////////////////
  306.             function onFullScreen(isInFullScreenMode) {
  307.                     if (isInFullScreenMode) {
  308.                         fullScreenOpenTime = (new Date()).getTime();
  309.                         // console.info("fullScreenOpenTime = " + fullScreenOpenTime);
  310.                     } else {
  311.                         fullScreenOpenTime = NaN;
  312.                     }
  313.             };
  314.             /////////////////////////////////////////////////////////////////////////////////
  315.  
  316.             function isDocumentInFullScreenMode() {
  317.                 // Note that the browser fullscreen (triggered by short keys) might
  318.                 // be considered different from content fullscreen when expecting a boolean
  319.                 return ((document.fullScreenElement && document.fullScreenElement !== null) ||    // alternative standard methods
  320.                     ((document.mozFullscreenElement != null) || (document.webkitFullscreenElement != null)));                   // current working methods
  321.             }
  322.  
  323.             document.addEventListener("fullscreenchange", function () {
  324.                 onFullScreen(document.fullscreen);
  325.             }, false);
  326.  
  327.             document.addEventListener("mozfullscreenchange", function () {
  328.                 onFullScreen(document.mozFullScreen);
  329.             }, false);
  330.  
  331.             document.addEventListener("webkitfullscreenchange", function () {
  332.                 onFullScreen(document.webkitIsFullScreen);
  333.             }, false);
  334.  
  335.         } inject()</script></html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement