Esempio n. 1
0
/**
 * 
 * @param type $encryptedPassword
 * @param type $rsaTime
 * @return boolean
 */
function authSteam($encryptedPassword, $rsaTime, $debug = false)
{
    include_once _SYSDIR_ . 'private/libs/phpseclib/Math/BigInteger.php';
    include_once _SYSDIR_ . 'private/libs/phpseclib/Crypt/RSA.php';
    include_once _SYSDIR_ . 'system/inc/Imap.php';
    $login = STEAM_LOGIN;
    $password = STEAM_PASSWORD;
    $cookies = _SYSDIR_ . 'private/cookies/cookies.txt';
    if ($debug) {
        echo "[" . date("H:i:s") . "] " . "Auth manager loaded. Sleeping for 10 s." . "\n";
    }
    sleep(10);
    if ($debug) {
        echo "[" . date("H:i:s") . "] " . "Opening IMAP." . "\n";
    }
    if (!Imap::open(EMAIL_IMAP, EMAIL_USERNAME, EMAIL_PASSWORD)) {
        //connection to emailbox
        return false;
    }
    if ($debug) {
        echo "[" . date("H:i:s") . "] " . "Opened. Ping Steam." . "\n";
    }
    if (!geturl("https://steamcommunity.com", null, $cookies, null, 0, $info)) {
        //ping Steam
        return false;
    }
    if ($debug) {
        echo "[" . date("H:i:s") . "] " . "Steam accessible." . "\n";
    }
    if (!$encryptedPassword) {
        return false;
    }
    $captchaGid = -1;
    $emailSteamId = null;
    $captchaText = null;
    if ($debug) {
        echo "[" . date("H:i:s") . "] " . "Searching list on email server via IMAP." . "\n";
    }
    Imap::search('BODY "Steam Guard code"');
    //Imap::search('ALL');
    $array = Imap::getMail();
    $codes = array();
    if ($debug) {
        echo "[" . date("H:i:s") . "] " . "Found " . count($array) . " emails in INBOX." . "\n";
    }
    foreach ($array as $row) {
        //if ($row['from'] == '*****@*****.**') {
        //if (preg_match("/Here\'s the Steam Guard code you\'ll need to complete the process\:/", $row['plain'])) {
        if (preg_match("/need to complete the process\\:/", $row['plain'])) {
            if (preg_match("/\\<h2\\>([A-Z0-9]{5})\\<\\/h2\\>/", $row['html'], $code)) {
                $codes[strtotime($row['date'])] = $code[1];
            }
        }
        //}
    }
    if ($debug) {
        echo "[" . date("H:i:s") . "] " . "Found " . count($codes) . " codes in INBOX." . "\n";
        echo "\n";
        var_dump($codes);
        echo "\n";
        echo "\n";
    }
    if ($codes && count($codes) > 0) {
        if (krsort($codes)) {
            $emailAuth = $codes[key($codes)];
        }
    }
    if (!$emailAuth) {
        return false;
    }
    if ($debug) {
        echo "[" . date("H:i:s") . "] " . "Found last code - " . $emailAuth . "." . "\n";
    }
    $params = array('username' => $login, 'password' => $encryptedPassword, 'rsatimestamp' => $rsaTime, 'captcha_gid' => $captchaGid, 'captcha_text' => $captchaText, 'emailauth' => $emailAuth, 'emailsteamid' => $emailSteamId);
    if ($debug) {
        echo "[" . date("H:i:s") . "] " . "Sending AUTH CODE to Steam." . "\n";
    }
    $output = geturl("https://steamcommunity.com/login/dologin/", null, $cookies, $params, 0, $info);
    $data = json_decode($output, true);
    if ($data['captcha_needed']) {
        return false;
    } else {
        if ($data['success'] && $data['login_complete']) {
            $output = geturl($data['transfer_url'], null, $cookies, $data['transfer_parameters'], 0, $info);
            //ping Steam
            return true;
        } elseif (!$data['login_complete']) {
            if (!$data['success'] && $data['emailauth_needed']) {
                return false;
            }
            //authSteam($encryptedPassword, $rsaTime);
        }
    }
    return false;
}