Calling Javascript functions from PHP

If you have designed websites using jQuery, you might have noticed that you are limited to showing certain sections/parts of your websites with direct URL. This is due to the fact that it is mostly user interaction of clicking, mouseover, etc..

This is a small function that will allow you to call certain Javascript functions passed in the URL parameters.

For example, if I would want a user to view the login screen I have on my website, they would visit:

http://www.azizsaleh.com/index.php/?js=login

To pass parameters (pipe delimited), use:

http://www.azizsaleh.com/index.php/ResumeAndPortfolio/?js=showSection&jsp=2

 

<script type="text/javascript"> 
$(document).ready(function() { 
    // Check for JS by URL 
    // by azizsaleh @ azzisaleh.com 

    <?php 
    // Check if there is a javascript function 
    if(isset($_GET['js'])) 
    { 
        // set a time out @ 100 milliseconds 
        $js = 'setTimeout("'; 
        $js .= $_GET['js'].'('; 

        // Check for function paramters 
        if(isset($_GET['jsp'])) 
        { 
            // Print variables 
            $jsParamters = explode('|',$_GET['jsp']); 
            for($x=0;$x<count($jsParamters);$x++){ $js .= "'".$jsParamters[$x]."',";} 
            if(strlen($js) > strlen($_GET['js'])+13    ){ $js = substr($js,0,-1);}             
        } 
        $js .= ')",100);'; 
        echo $js; 
    } 
    ?> 

}); 
</script>

Hijacking, Bypassing, Defeating and Beating the Same Origin Policy

The same origin policy was created as a permission scheme for communication of websites on same/different servers using browser side languages, like Javascript.

You might have ran into a problem trying to access properties of an Iframe of an external server, for example getting an element by point x & y, which I was trying to achieve when working on the flash click tracker (link).

I then had to create an entirely new script, but still using virtually the same flash object and a PHP proxy that will allow me to control the iframe object to my needs. In my case, it will allow me to track the link click and get the actual link for processing (in case of advertisement, visiting the link).

This is the basic idea I had:

You can view an actual demo here (make sure your ad blocker is off) and if it doesn’t work refresh.

Demo

[wpdm_file id=8]

Flash Link Tracker Using Javascript and Jquery

This is a flash object that overlays (using CSS) HTML object, like an iframe/div/span/images/etc. The width and height of the flash object is customizable.

The flash object then calls back a javascript function, also customizable, when a click event occurs on that object.

The only drawback is that the user must “double click” on the flash object. Since the first click is when the flash object is hidden.

Demo

[wpdm_file id=10]

Key Logger with Save, Email and Registry Save for Auto Load

This application allows you to store user input in x milliseconds, store the strokes in a file every x milliseconds, and email that file using SMTP email login and attachment every x milliseconds. You can create a dummy email account to send the information with in the event your application was decoded.

This application features another option that allows you to store the executable path in the system registry for automatic program load on system startup.

 

Part 1:

Part 2:

 

PHP Object Merge and In Object Functions – object_merge

These are two functions to manipulate PHP objects.

The first function is similar to array_merge function in that it merges two objects based on an index.

The second function in_object also acts like in_array to which it checks if a certain index exists in an array at a specific value.

Hopefully someone finds it helpful.

 

<?php

// Object merge and in Object functions
function object_merge($objectFrom,$objectTo,$indexUse) 
{ 
    $objectReturn = array(); 
    foreach($objectFrom as $curObject) 
    {         
        $index = in_object($indexUse,$curObject->$indexUse,$objectTo,true); 
        if(is_int($index)) 
        { 
            foreach($objectTo[$index] as $indexName => $indexValue) 
            { 
                $curObject->$indexName = $indexValue; 
            } 
        } 
        $objectReturn[] = (object) $curObject;         
    } 
    return $objectReturn; 
} 

function in_object($searchFor,$searchValue,$objectSearch,$returnResult) 
{ 
    foreach($objectSearch as $index => $thisObject) 
    { 
        if($thisObject->$searchFor == $searchValue) 
        { 
            if($returnResult) 
            { 
                return $index; 
            } else { 
                return true; 
            } 
        } 
    } 
    return false; 
} 

// Usage 
$obj1[0] = (object) array('catId' => 1, 'catName' => 'Name'); 
$obj1[1] = (object) array('catId' => 2, 'catName' => 'Name2'); 

$obj2[0] = (object) array('catId' => 1, 'catDesc' => 'Desc'); 
$obj2[1] = (object) array('catId' => 2, 'catDesc' => 'Desc2'); 

$obj_merged = object_merge($obj1,$obj2,'catId'); 
print_r($obj_merged);

Currency Converter Using Visual Basic

This tutorial will show you how to create a currency converter the easy way. It covers downloading website contents (from XE) and using regular expression to match the rates. You can download the source code by clicking here.

The video is composed of two parts, all uploaded on youtube.

Part 1:

Part 2:

 

 

 

Currency Converter Using Java Netbeans

This tutorial will show you how to create a currency converter the easy way. It covers downloading website contents (from XE) and using regular expression to match the rates. You can download the source code by clicking here.

The video is composed of three parts, all uploaded on youtube.

 

Part 1:

Part 2:

Part 3:

MegaVideo Premium Link Scraper

This class will allow you to scrape MegaVideo Premium Links to share or use for your own.

Please note that you need to follow these steps:

1) Login into your account at MegaVideo (or MegaUpload).
2) View your cookies that you got from whichever site you loged into.
3) Replace USERNUMBER and SESSIONID with your user number and session id from the cookies in the attached file: megavideoCookie.txt.

If you do this excessively, MegaVideo will ban your IP, so you will have to renew your IP every now and then (depending on how heavy the load is).

Enjoy. Let me know if you have any problems.

Sample Implementation:

<?php
/*
MegaVideo Video Scraper
Premium Account Required
Written by Aziz S. Hussain
@
www.AzizSaleh.com
Produced under LGPL license
@

http://www.gnu.org/licenses/lgpl.html

Example Use of the class: megavideo.class.php
*/

# Include Main Class
require_once('megavideo.class.php');

# Setup the URL
$newVideo = new megaVideo('http://www.megavideo.com/?v=6PTHEVUY');
# Work to get the link
$newVideo->doScrape();
# You now have the link
echo $newVideo->getLink();
# The link can be used for download or stream
# To use for stream, you will need a flash player like JW Flash Player
# http://www.longtailvideo.com/players/jw-flv-player/

Main Class:

<?php

/*
MegaVideo Video Scraper
Premium Account Required
Written by Aziz S. Hussain
@
www.AzizSaleh.com
Produced under LGPL license
@

http://www.gnu.org/licenses/lgpl.html

Class Structure

class megaVideo
{
    # MegaVideo link
    private megaVideoURL
    # Final link
    private finalLink
    
    void __construct(string videoURL)                    # Store video link    
    array getMegaVideoVars(string megaVideoURL)            # Returns vars needed to create viewing key
    string decrypt(string str, string key1, string key2)# Actually decrypts the vars into the key
    void doScrape()                                        # Does the scraping
    string getLink()                                    # Return the URL for download or streaming        
}
*/

class megaVideo
{
    # MegaVideo link
    private $megaVideoURL;
    # Final link
    private $finalLink;
    
    # Construct, just store the vide link
    function __construct($videoURL)
    {
        $this->finalLink = $videoURL;
    }
    
    # This function will return the megaVideo vars
    # Note that it uses CURL and the COOKIE megavideoCookie.txt
    # Cookie text file must be in this format: 
    /*
    
    # Netscape HTTP Cookie File
    # http://www.netscape.com/newsref/std/cookie_spec.html
    # This file was generated by libcurl! Edit at your own risk.

    .megavideo.com    TRUE    /    FALSE    1263332544    user     4BDHJJNEJOKDF4KJHKJFJIUGHUYG3.JKLHDU4

    */
    # You need to change the user number 1263332544 and session  4BDHJJNEJOKDF4KJHKJFJIUGHUYG3.JKLHDU4
    # You can get that information by viewing the cookie information (using firefox)
    # URL passed must be in this format: http://www.megavideo.com/?v=6PTHEVUY
    function getMegaVideoVars()
    {
        $ch = curl_init(); 
        curl_setopt($ch, CURLOPT_URL,$this->finalLink);
        curl_setopt($ch, CURLOPT_COOKIEFILE, 'megavideoCookie.txt');
        curl_setopt($ch, CURLOPT_COOKIEJAR, 'megavideoCookie.txt');
        curl_setopt($ch, CURLOPT_FAILONERROR, 1);
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
        curl_setopt($ch, CURLOPT_TIMEOUT, 50);
    
        $buffer = curl_exec($ch);
        curl_close($ch);
        preg_match('/flashvars\.un = "(.*)";.*flashvars\.k1 = "(.*)";.*flashvars\.k2 = "(.*)";.*flashvars\.s = "(.*)";/Ums',
                $buffer,$results);
        # Return required vars
        $finalResults = array($results[4],$results[1],$results[2],$results[3]);
        return $finalResults;
    }


    # This function will decrypt the required keys form megavideo
    function decrypt($str, $key1, $key2)
    {
        $reg1 = array();
        for($reg3=0; $reg3<strlen($str); $reg3++)
        {
            $reg0 = $str[$reg3];
       
            switch($reg0)
            {
              case '0': $reg1[] = '0000'; break;
              case '1': $reg1[] = '0001'; break;
              case '2': $reg1[] = '0010'; break;
              case '3': $reg1[] = '0011'; break;
              case '4': $reg1[] = '0100'; break;
              case '5': $reg1[] = '0101'; break;
              case '6': $reg1[] = '0110'; break;
              case '7': $reg1[] = '0111'; break;
              case '8': $reg1[] = '1000'; break;
              case '9': $reg1[] = '1001'; break;
              case 'a': $reg1[] = '1010'; break;
              case 'b': $reg1[] = '1011'; break;
              case 'c': $reg1[] = '1100'; break;
              case 'd': $reg1[] = '1101'; break;
              case 'e': $reg1[] = '1110'; break;
              case 'f': $reg1[] = '1111'; break;
           }
        }
          
        $reg1 = join($reg1);
        $reg6 = array();
          
        for($reg3=0; $reg3<384; $reg3++)
        {
            $key1 = ($key1 * 11 + 77213) % 81371;
            $key2 = ($key2 * 17 + 92717) % 192811;
            $reg6[] = ($key1 + $key2) % 128;
        }
          
        for($reg3=256; $reg3>=0; $reg3--)
        {
            $reg5 = $reg6[$reg3];
            $reg4 = $reg3 % 128;
            $reg8 = $reg1[$reg5];
            $reg1[$reg5] = $reg1[$reg4];
            $reg1[$reg4] = $reg8;
        }
          
        for($reg3=0; $reg3<128; $reg3++)
        {
            $reg1[$reg3] = $reg1[$reg3] ^ ($reg6[$reg3+256] & 1);   
        }
          
        $reg12 = $reg1;
        $reg7 = array();
          
        for($reg3=0; $reg3<strlen($reg12); $reg3+=4)
        {
            $reg9 = substr($reg12, $reg3, 4);
            $reg7[] = $reg9;
        }
          
        $reg2 = array();
          
        for($reg3=0; $reg3<count($reg7); $reg3++)
        {
            $reg0 = $reg7[$reg3];
            switch($reg0)
            {
              case '0000': $reg2[] = '0'; break;
              case '0001': $reg2[] = '1'; break;
              case '0010': $reg2[] = '2'; break;
              case '0011': $reg2[] = '3'; break;
              case '0100': $reg2[] = '4'; break;
              case '0101': $reg2[] = '5'; break;
              case '0110': $reg2[] = '6'; break;
              case '0111': $reg2[] = '7'; break;
              case '1000': $reg2[] = '8'; break;
              case '1001': $reg2[] = '9'; break;
              case '1010': $reg2[] = 'a'; break;
              case '1011': $reg2[] = 'b'; break;
              case '1100': $reg2[] = 'c'; break;
              case '1101': $reg2[] = 'd'; break;
              case '1110': $reg2[] = 'e'; break;
              case '1111': $reg2[] = 'f'; break;
            }
        }
        return join($reg2);
    }
    
    # Actually return the URL that the video can be viewed without time restrictions
    function doScrape()
    {
        # Retrieve info
        list($serverID,$un,$k1,$k2) = $this->getMegaVideoVars();
        # Get the key
        $decKey = $this->decrypt($un,$k1,$k2);
        
        $this->finalLink = "http://www$serverID.megavideo.com/files/$decKey/randomName$un.flv";
    }
    
    # Return the link begotten after scraping
    function getLink()
    {
        return $this->finalLink;
    }    

}

Cookie File:

# Netscape HTTP Cookie File
# http://www.netscape.com/newsref/std/cookie_spec.html
# This file was generated by libcurl! Edit at your own risk.
# MegaVideo Premium Link Scraper by Aziz S. Hussain
# @ www.AzizSaleh.com


.megavideo.com    TRUE    /    FALSE    USERNUMBER    user     USERSESSION