Example #1
0
function http_get($url)
{
    global $http_code, $http_ohtml, $http_html;
    // Local file code
    $http_code = 200;
    if (!$url) {
        re(false);
        return false;
    }
    if (strpos($url, '://') === false) {
        // Local file specified
        if (file_exists($url)) {
            $http_html = file_get_contents($url);
            $http_ohtml = $http_html;
            set_source($http_html);
            re($http_html);
            return $http_html;
        }
        $http_code = 404;
        re(false);
        return false;
    }
    $url = if_inside('', '#', $url);
    // Retry and cache code
    if (substr($url, 0, 1) != "%") {
        if (g('http_cache')) {
            $data = load_hash_cache($url);
            if ($data) {
                $http_code = 200;
                $http_ohtml = $data;
                $http_html = flatty_html($data);
                global $http_url_base;
                $base = inside("href=", "", inside("<base", ">", $http_html));
                if ($base) {
                    $base = substr($base, 1, -1);
                } else {
                    $base = $url;
                }
                $base = if_inside("", "?", $base);
                if ($p = strrpos($base, '/')) {
                    $base = substr($base, 0, $p);
                }
                if ($base) {
                    $http_url_base = $base . "/";
                }
                xlog("Fetching <a rel='nofollow' href='{$url}' target='_blank'>{$url}</a> (cache)");
                if (g('debug_nesting_level') and ini_get('display_errors')) {
                    // Write result to output
                    mx_debug_fetch_result($http_html);
                }
                set_source($http_html);
                re($http_html);
                return $http_html;
            }
        }
        $n = 3;
        if (strpos($url, 'yandex.ru')) {
            $n = 10;
        }
        for ($i = 0; $i < $n; $i++) {
            $http_html = http_get("%" . $url);
            if ($http_html || $http_code == 404) {
                re($http_html);
                return $http_html;
            }
        }
        re(false);
        return false;
    }
    $url = substr($url, 1);
    // Remove % marker
    // Proxy code
    global $http_proxy, $http_proxies_file;
    if (g('http_use_proxies') and !$http_proxy) {
        if (!($http_proxy = mx_config_get("proxy"))) {
            clearstatcache();
            if (!file_exists($http_proxies_file) or filemtime($http_proxies_file) < microtime(true) - 24 * 60 * 60) {
                xlog('Receiving fresh proxies list...');
                $proxies = @http_curl("http://parsemx.com/getmxp.php", "url=http://{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}", $http_proxies_file);
                if ($proxies) {
                    $proxies = file_get_contents($http_proxies_file);
                }
                if ($proxies) {
                    xsuccess("Received " . round(strlen($proxies) / 6) . " proxies.");
                }
            }
            $proxies = file_get_contents($http_proxies_file);
            $n = (int) (strlen($proxies) / 6);
            // Testproxy URL
            $proxy_url = $url;
            if (strpos($url, 'aliexpress.com')) {
                $proxy_url = 'http://www.aliexpress.com/activities/';
            } elseif (strpos($url, 'translate.yandex.net/api/v1')) {
                $proxy_url = 'http://translate.yandex.net/api/v1/tr.json';
            } elseif ($p = strpos($url, '/', 8)) {
                $proxy_url = substr($url, 0, $p + 1);
            }
            while (!$http_proxy) {
                xlog("Checking proxies...");
                // Get 20 proxies
                $xproxies = array();
                for ($i = 0; $i < 20; $i++) {
                    $p = rand(0, $n - 1) * 6;
                    $proxy = ord($proxies[$p]) . "." . ord($proxies[$p + 1]) . "." . ord($proxies[$p + 2]) . "." . ord($proxies[$p + 3]) . ":" . (ord($proxies[$p + 4]) + ord($proxies[$p + 5]) * 256);
                    $xproxies[] = $proxy;
                }
                $http_proxy = testproxies($xproxies, $proxy_url);
                if ($http_proxy) {
                    xlog("Using proxy: " . $http_proxy);
                    mx_config_set("proxy", $http_proxy);
                    break;
                }
            }
        }
    }
    $http_html = http_curl($url);
    $http_ohtml = $http_html;
    if (!$http_html) {
        re(false);
        return false;
    }
    if (g('http_cache')) {
        save_hash_cache($url, $http_html);
    }
    $http_html = flatty_html($http_html);
    set_source($http_html);
    re($http_html);
    return $http_html;
}
Example #2
0
             xerror($r["error"], "json");
         } else {
             xlogin($r["success"], "json");
         }
         // this will probably be the same
     }
 }
 $authinfo = checkAuth($username, $login, "json");
 if ($mode == "delete") {
     $updates = array();
     foreach ($json["devices"] as $link) {
         $updates[$i++] = $link["id"];
     }
     //insertLinks($updates, $developer, $authinfo["userid"], $authinfo["device"]);
     deleteAuth($updates, $authinfo["userid"], $username);
     xsuccess(count($updates) . " links updated", "json");
 } else {
     if ($mode == "history") {
         $result = readHistory($authinfo["userid"], "json");
         echo $result;
         die;
     } else {
         if ($mode == "devices") {
             $result = getDevices($authinfo["userid"], "json");
             echo $result;
             die;
         } else {
             if ($mode == "addauth") {
                 $device = $json["device"];
                 $r = addAuth($username, $authinfo["userid"], $device, $developer);
                 if ($r["success"] == "") {
Example #3
0
     foreach ($links as $link) {
         $updates[$link]["link"] = 1;
         //echo "found";
     }
     foreach ($comments as $comment) {
         if (!(strpos($comment, ":") === FALSE)) {
             $comment = explode(":", $comment);
             if (count($comment) == 2) {
                 $updates[$comment[0]]["comment"] = $comment[1];
             }
         }
     }
     //var_dump($updates);
     $developer = isset($_POST['dev']) ? $_POST['dev'] : "unknown";
     insertLinks($updates, $developer, $authinfo["userid"], $authinfo["device"]);
     xsuccess(count($updates) . " links updated");
 } else {
     $username = $_POST['username'];
     $auth = $_POST['auth'];
     // try to update last used time of auth. if fails, auth doesnt exist
     $authinfo = checkAuth($username, $auth);
     if (strpos($_POST['links'], ",") === FALSE) {
         $links = array($_POST['links']);
     } else {
         $links = explode(",", $_POST['links']);
     }
     // no comments for reading
     // comment count is returned by default
     $result = readLinks($links, $authinfo["userid"], null);
     echo $result;
 }