Пример #1
0
 static function crawlerProgramItems($date, $chnnel)
 {
     $url = replaceStr(CnTVLiveParse::BASE_EPISODE, '{DATE}', $date);
     $url = replaceStr($url, '{TV_CODE}', $chnnel);
     $client = new HttpClient('tv.cntv.cn');
     $client->get('/epg');
     $client->get($url);
     writetofile("program_live_item_crawler.log", "url:[http://tv.cntv.cn" . $url . "]");
     $content = $client->getContent();
     return CnTVLiveParse::parseMovieInfoByContent($content, $p_code, $type);
 }
Пример #2
0
 /**
  * @param Url $url
  *
  * @return File
  * @throws DownloadFailedException
  */
 public function download(Url $url)
 {
     $this->output->writeInfo(sprintf('Downloading %s', $url));
     $response = $this->curl->get($url);
     if ($response->getHttpCode() !== 200) {
         throw new DownloadFailedException(sprintf('Download failed (HTTP status code %s) %s', $response->getHttpCode(), $response->getErrorMessage()));
     }
     if (empty($response->getBody())) {
         throw new DownloadFailedException('Download failed - response is empty');
     }
     return new File($this->getFilename($url), $response->getBody());
 }
Пример #3
0
 /**
  * @param string $keyId
  *
  * @return string
  * @throws DownloadFailedException
  */
 public function download($keyId)
 {
     $params = ['search' => '0x' . $keyId, 'op' => 'get', 'options' => 'mr'];
     foreach ($this->keyServers as $keyServer) {
         $this->output->writeInfo(sprintf('Trying %s', $keyServer));
         $result = $this->httpClient->get(new Url($keyServer . self::PATH), $params);
         if ($result->getHttpCode() == 200) {
             $this->output->writeInfo('Sucessfully downloaded key');
             return $result->getBody();
         }
         $this->output->writeWarning(sprintf('Failed with status code %s: %s', $result->getHttpCode(), $result->getErrorMessage()));
     }
     throw new DownloadFailedException(sprintf('Key %s not found on key servers', $keyId));
 }
Пример #4
0
 /**
  * @dataProvider effectiveUrls
  */
 public function testEffectiveUrl($url, $expected, $params = array())
 {
     $http = new HttpClient();
     $http->get($url, $params);
     $this->assertEquals($expected, $http->getEffectiveUrl());
     $this->assertEquals($expected, $http->effectiveUrl);
 }
Пример #5
0
function http_get_file($url)
{
    $httpClient = new HttpClient("epub.cnki.net");
    $httpClient->get($url);
    $content = $httpClient->getContent();
    return $content;
}
Пример #6
0
 /**
  * Uses httpClient to fetch results and map to an object of type $className
  * 
  * @param string $url
  * @param string $className
  * @return obj
  */
 private function fetch($url, $className)
 {
     $key = sha1($url);
     if (!isset($this->cache[$key])) {
         $xml = $this->httpClient->get($url);
         $this->cache[$key] = call_user_func_array(array($className, 'createFromXml'), array($xml, $this));
     }
     return $this->cache[$key];
 }
Пример #7
0
 /**
  * @param Feed $feed
  */
 public function processFeed($feed)
 {
     $http = new \HttpClient();
     $body = $http->get($this->url);
     if ($body !== false) {
         $this->parseBody($body, $feed);
     } elseif ($this->showErrors) {
         $feed->addItem(['title' => $http->lastError, 'link' => $this->url]);
     }
 }
Пример #8
0
 function _loadVersion()
 {
     require_once JPATH_COMPONENT . DS . 'libraries' . DS . 'httpclient.class.php';
     $client = new HttpClient('www.easy-joomla.org');
     if (!$client->get('/components/com_versions/directinfo.php?catid=3')) {
         $this->setError($client->getError());
         return false;
     }
     $this->_current = $client->getContent();
     return true;
 }
Пример #9
0
 /**
  * download a media
  * @param string $filename - file for downloading to
  * @param string $mediaId - mediaId of file
  * @param bool $https(optional default true) - if downloading video-type file, 
  *		set $https to false for http request
  * @return int - filesize of the media or string - json for error message(if error)
  */
 public function download($filename, $mediaId, $https = true)
 {
     if ($https) {
         $client = new HttpClient("https://api.weixin.qq.com/cgi-bin/media/get?access_token={$this->access_token}&media_id={$mediaId}");
     } else {
         $client = new HttpClient("http://api.weixin.qq.com/cgi-bin/media/get?access_token={$this->access_token}&media_id={$mediaId}");
     }
     $client->get();
     if ($client->getState() == 200) {
         if (!is_null(json_decode($client->getResponse()))) {
             //data of json format(error here)
             return $client->getResponse();
         } else {
             file_put_contents($filename, $client->getResponse());
             return filesize($filename);
         }
     } else {
         return false;
     }
 }
function fixProfile($uri)
{
    $oprofile = Ostatus_profile::getKV('uri', $uri);
    if (!$oprofile) {
        print "No OStatus remote profile known for URI {$uri}\n";
        return false;
    }
    echo "Before:\n";
    showProfileInfo($oprofile);
    $feedurl = $oprofile->feeduri;
    $client = new HttpClient();
    $response = $client->get($feedurl);
    if ($response->isOk()) {
        echo "Updating profile from feed: {$feedurl}\n";
        $dom = new DOMDocument();
        if ($dom->loadXML($response->getBody())) {
            $feed = $dom->documentElement;
            $entries = $dom->getElementsByTagNameNS(Activity::ATOM, 'entry');
            if ($entries->length) {
                $entry = $entries->item(0);
                $activity = new Activity($entry, $feed);
                $oprofile->checkAuthorship($activity);
                echo "  (ok)\n";
            } else {
                echo "  (no entry; skipping)\n";
                return false;
            }
        } else {
            echo "  (bad feed; skipping)\n";
            return false;
        }
    } else {
        echo "Failed feed fetch: {$response->getStatus()} for {$feedurl}\n";
        return false;
    }
    echo "After:\n";
    showProfileInfo($oprofile);
    return true;
}
Пример #11
0
 /**
  * Preferences are handled in _PassUser
  */
 function checkPass($password)
 {
     $userid = $this->_userid;
     if (!loadPhpExtension('openssl')) {
         trigger_error(sprintf(_("The PECL %s extension cannot be loaded."), "openssl") . sprintf(_(" %s AUTH ignored."), 'Facebook'), E_USER_WARNING);
         return $this->_tryNextUser();
     }
     $web = new HttpClient("www.facebook.com", 80);
     if (DEBUG & _DEBUG_LOGIN) {
         $web->setDebug(true);
     }
     // collect cookies from http://www.facebook.com/login.php
     $web->persist_cookies = true;
     $web->cookie_host = 'www.facebook.com';
     $firstlogin = $web->get("/login.php");
     if (!$firstlogin) {
         if (DEBUG & (_DEBUG_LOGIN | _DEBUG_VERBOSE)) {
             trigger_error(sprintf(_("Facebook connect failed with %d %s"), $web->status, $web->errormsg), E_USER_WARNING);
         }
     }
     // Switch from http to https://login.facebook.com/login.php
     $web->port = 443;
     $web->host = 'login.facebook.com';
     if (!($retval = $web->post("/login.php", array('user' => $userid, 'pass' => $password)))) {
         if (DEBUG & (_DEBUG_LOGIN | _DEBUG_VERBOSE)) {
             trigger_error(sprintf(_("Facebook login failed with %d %s"), $web->status, $web->errormsg), E_USER_WARNING);
         }
     }
     $this->_authmethod = 'Facebook';
     if (DEBUG & _DEBUG_LOGIN) {
         trigger_error(get_class($this) . "::checkPass => {$retval}", E_USER_WARNING);
     }
     if ($retval) {
         $this->_level = WIKIAUTH_USER;
     } else {
         $this->_level = WIKIAUTH_ANON;
     }
     return $this->_level;
 }
 function preLogUser($sessionId)
 {
     require_once AJXP_BIN_FOLDER . "/class.HttpClient.php";
     $client = new HttpClient($this->getOption("REMOTE_SERVER"), $this->getOption("REMOTE_PORT"));
     $client->setDebug(false);
     if ($this->getOption("REMOTE_USER") != "") {
         $client->setAuthorization($this->getOption("REMOTE_USER"), $this->getOption("REMOTE_PASSWORD"));
     }
     $client->setCookies(array($this->getOption("REMOTE_SESSION_NAME") ? $this->getOption("REMOTE_SESSION_NAME") : "PHPSESSID" => $sessionId));
     $result = $client->get($this->getOption("REMOTE_URL"), array("session_id" => $sessionId));
     if ($result) {
         $user = $client->getContent();
         if ($this->autoCreateUser()) {
             AuthService::logUser($user, "", true);
         } else {
             // If not auto-create but the user exists, log him.
             if ($this->userExists($user)) {
                 AuthService::logUser($user, "", true);
             }
         }
     }
 }
Пример #13
0
 public function test()
 {
     $request = ['url' => 'http://thegamesdb.net/api/GetGame.php', 'params' => ['name' => 'harry potter']];
     $response = \HttpClient::get($request);
     dd(\Parser::xml($response->content()));
 }
Пример #14
0
function installSlicer($version, $installDir, $filename, $quiet, $disableTls, $cafile)
{
    $installPath = (is_dir($installDir) ? rtrim($installDir, '/') . '/' : '') . $filename;
    $installDir = realpath($installDir) ? realpath($installDir) : getcwd();
    $file = $installDir . DIRECTORY_SEPARATOR . $filename;
    if (is_readable($file)) {
        @unlink($file);
    }
    if (FALSE === $disableTls && empty($cafile) && !HttpClient::getSystemCaRootBundlePath()) {
        $errorHandler = new ErrorHandler();
        set_error_handler([$errorHandler, 'handleError']);
        $home = getenv('COMPOSER_HOME');
        if (!$home) {
            if (defined('PHP_WINDOWS_VERSION_MAJOR')) {
                if (!getenv('APPDATA')) {
                    throw new RuntimeException('The APPDATA or SLICER_HOME environment variable must be set for composer to install correctly');
                }
                $home = strtr(getenv('APPDATA'), '\\', '/') . '/Slicer';
            } else {
                if (!getenv('HOME')) {
                    throw new RuntimeException('The HOME or SLICER_HOME environment variable must be set for composer to install correctly');
                }
                $home = rtrim(getenv('HOME'), '/') . '/.slicer';
            }
        }
        $target = $home . '/cacert.pem';
        if (!is_dir($home)) {
            @mkdir($home, 0777, TRUE);
        }
        $write = file_put_contents($target, HttpClient::getPackagedCaFile(), LOCK_EX);
        @chmod($target, 0644);
        restore_error_handler();
        if (!$write) {
            throw new RuntimeException('Unable to write bundled cacert.pem to: ' . $target);
        }
        $cafile = $target;
    }
    $httpClient = new HttpClient($disableTls, $cafile);
    $retries = 3;
    while ($retries--) {
        if (!$quiet) {
            out("Downloading...", 'info');
        }
        $uriScheme = FALSE === $disableTls ? 'https' : 'http';
        $urlPath = (FALSE !== $version ? "/download/{$version}" : '') . '/slicer.phar';
        $url = "{$uriScheme}://getslicer.com{$urlPath}";
        $errorHandler = new ErrorHandler();
        set_error_handler([$errorHandler, 'handleError']);
        $fh = fopen($file, 'w');
        if (!$fh) {
            out('Could not create file ' . $file . ': ' . $errorHandler->message, 'error');
        }
        if (!fwrite($fh, $httpClient->get($url))) {
            out('Download failed: ' . $errorHandler->message, 'error');
        }
        fclose($fh);
        restore_error_handler();
        if ($errorHandler->message) {
            continue;
        }
        try {
            // create a temp file ending in .phar since the Phar class only accepts that
            if ('.phar' !== substr($file, -5)) {
                copy($file, $file . '.tmp.phar');
                $pharFile = $file . '.tmp.phar';
            } else {
                $pharFile = $file;
            }
            if (!ini_get('phar.readonly')) {
                // test the phar validity
                $phar = new Phar($pharFile);
                // free the variable to unlock the file
                unset($phar);
            }
            // clean up temp file if needed
            if ($file !== $pharFile) {
                unlink($pharFile);
            }
            break;
        } catch (Exception $e) {
            if (!$e instanceof UnexpectedValueException && !$e instanceof PharException) {
                throw $e;
            }
            // clean up temp file if needed
            if ($file !== $pharFile) {
                unlink($pharFile);
            }
            unlink($file);
            if ($retries) {
                if (!$quiet) {
                    out('The download is corrupt, retrying...', 'error');
                }
            } else {
                out('The download is corrupt (' . $e->getMessage() . '), aborting.', 'error');
                exit(1);
            }
        }
    }
    if ($errorHandler->message) {
        out('The download failed repeatedly, aborting.', 'error');
        exit(1);
    }
    chmod($file, 0755);
    if (!$quiet) {
        out(PHP_EOL . "Slicer successfully installed to: " . $file, 'success', FALSE);
        out(PHP_EOL . "Use it: php {$installPath}", 'info');
    }
}
Пример #15
0
 public function onConnect(IWebSocketConnection $user)
 {
     if ($user->getAdminKey() == self::$ADMIN_KEY) {
         $this->say("[ECHO] Admin user connected");
         return;
     }
     $h = $user->getHeaders();
     $c = WebSocketFunctions::cookie_parse($h["Cookie"]);
     $client = new HttpClient($this->host);
     $client->cookies = $c;
     $client->get("/{$this->path}/?get_action=ws_authenticate&key=" . self::$ADMIN_KEY);
     $registry = $client->getContent();
     //$this->say("[ECHO] Registry loaded".$registry);
     $xml = new DOMDocument();
     $xml->loadXML($registry);
     $xPath = new DOMXPath($xml);
     $err = $xPath->query("//message[@type='ERROR']");
     if ($err->length) {
         $this->say($err->item(0)->firstChild->nodeValue);
         $user->disconnect();
     } else {
         $userRepositories = array();
         $repos = $xPath->query("/tree/user/repositories/repo");
         foreach ($repos as $repo) {
             $repoId = $repo->attributes->getNamedItem("id")->nodeValue;
             $userRepositories[] = $repoId;
         }
         $user->ajxpRepositories = $userRepositories;
         $user->ajxpId = $xPath->query("/tree/user/@id")->item(0)->nodeValue;
         if ($xPath->query("/tree/user/@groupPath")->length) {
             $groupPath = $xPath->query("/tree/user/@groupPath")->item(0)->nodeValue;
             if (!empty($groupPath)) {
                 $user->ajxpGroupPath = $groupPath;
             }
         }
     }
     $this->say("[ECHO] User '" . $user->ajxpId . "' connected with " . count($user->ajxpRepositories) . " registered repositories ");
 }
function drupal_remote_auth($host, $uri, $login, $pass, $formId = "")
{
    $client = new HttpClient($host);
    $client->setHandleRedirects(false);
    $res = $client->get($uri);
    $content = $client->getContent();
    $xmlDoc = DOMDocument::loadHTML($content);
    $xPath = new DOMXPath($xmlDoc);
    if ($formId == "") {
        $formId = "user-login-form";
    }
    $nodes = $xPath->query('//form[@id="' . $formId . '"]');
    if (!$nodes->length) {
        return "";
    }
    $form = $nodes->item(0);
    $postUri = $form->getAttribute("action");
    $hiddens = $xPath->query('//input[@type="hidden"]', $form);
    AJXP_Logger::debug("Carry on Drupal hiddens " . $hiddens->length);
    $postData = array("name" => $login, "pass" => $pass, "Submit" => "Log in");
    foreach ($hiddens as $hiddenNode) {
        $postData[$hiddenNode->getAttribute("name")] = $hiddenNode->getAttribute("value");
    }
    $client->setHandleRedirects(false);
    $client->setHeadersOnly(true);
    $client->setCookies(extractResponseCookies($client));
    $res2 = $client->post($postUri, $postData);
    $newCookies = extractResponseCookies($client);
    if (isset($newCookies["AjaXplorer"])) {
        return $newCookies["AjaXplorer"];
    }
    return "";
}
 /**
  * @return HttpClient
  */
 function getRemoteConnexion(&$remoteSessionId, $refreshSessId = false)
 {
     require_once INSTALL_PATH . "/server/classes/class.HttpClient.php";
     $crtRep = ConfService::getRepository();
     $httpClient = new HttpClient($crtRep->getOption("HOST"));
     $httpClient->cookie_host = $crtRep->getOption("HOST");
     $httpClient->timeout = 50;
     //$httpClient->setDebug(true);
     if ($crtRep->getOption("AUTH_URI") != "") {
         $httpClient->setAuthorization($crtRep->getOption("AUTH_NAME"), $crtRep->getOption("AUTH_PASS"));
     }
     if (!isset($_SESSION["AJXP_REMOTE_SESSION"]) || $refreshSessId) {
         $httpClient->setHeadersOnly(true);
         $httpClient->get($crtRep->getOption("AUTH_URI"));
         $httpClient->setHeadersOnly(false);
         $cookies = $httpClient->getCookies();
         if (isset($cookies["PHPSESSID"])) {
             $_SESSION["AJXP_REMOTE_SESSION"] = $cookies["PHPSESSID"];
             $remoteSessionId = $cookies["PHPSESSID"];
         }
     } else {
         $remoteSessionId = $_SESSION["AJXP_REMOTE_SESSION"];
         $httpClient->setCookies(array("PHPSESSID" => $remoteSessionId));
     }
     return $httpClient;
 }
 /**
  * @return HttpClient
  */
 function getRemoteConnexion(&$remoteSessionId, $refreshSessId = false)
 {
     require_once INSTALL_PATH . "/server/classes/class.HttpClient.php";
     $crtRep = ConfService::getRepository();
     $httpClient = new HttpClient($crtRep->getOption("HOST"));
     $httpClient->cookie_host = $crtRep->getOption("HOST");
     $httpClient->timeout = 10;
     //$httpClient->setDebug(true);
     if (!$crtRep->getOption("USE_AUTH")) {
         return $httpClient;
     }
     $uri = "";
     if ($crtRep->getOption("AUTH_URI") != "") {
         $httpClient->setAuthorization($crtRep->getOption("AUTH_USER"), $crtRep->getOption("AUTH_PASS"));
         $uri = $crtRep->getOption("AUTH_URI");
     }
     if (!isset($_SESSION["AJXP_REMOTE_SESSION"]) || $refreshSessId) {
         if ($uri == "") {
             // Retrieve a seed!
             $httpClient->get($crtRep->getOption("URI") . "?get_action=get_seed");
             $seed = $httpClient->getContent();
             $user = $crtRep->getOption("AUTH_USER");
             $pass = $crtRep->getOption("AUTH_PASS");
             $pass = md5(md5($pass) . $seed);
             $uri = $crtRep->getOption("URI") . "?get_action=login&userid=" . $user . "&password="******"&login_seed={$seed}";
         }
         $httpClient->setHeadersOnly(true);
         $httpClient->get($uri);
         $httpClient->setHeadersOnly(false);
         $cookies = $httpClient->getCookies();
         if (isset($cookies["AjaXplorer"])) {
             $_SESSION["AJXP_REMOTE_SESSION"] = $cookies["AjaXplorer"];
             $remoteSessionId = $cookies["AjaXplorer"];
         }
     } else {
         $remoteSessionId = $_SESSION["AJXP_REMOTE_SESSION"];
         $httpClient->setCookies(array("AjaXplorer" => $remoteSessionId));
     }
     return $httpClient;
 }
Пример #19
0
 function listException()
 {
     $now = number_format(1000 * time(), 0, '', '');
     $client = new HttpClient(FEYIN_HOST, FEYIN_PORT);
     if (!$client->get('/api/listException?memberCode=' . MEMBER_CODE . '&reqTime=' . $now . '&securityCode=' . md5(MEMBER_CODE . $now . $this->feyin_key))) {
         //请求失败
         return 'faild';
     } else {
         return $client->getContent();
     }
 }
Пример #20
0
function main($subDir, $class, $cookieURL, $indexURL, $totalClass, $curClass, $code)
{
    $isSleep = true;
    makeDir("./html/{$subDir}/{$class}/");
    $dataFileName = "data/{$subDir}/{$class}.log";
    $httpClient = new HttpClient("epub.cnki.net");
    $content = "";
    $indexFname = "./html/{$subDir}/{$class}/index.html";
    $tf = iconv("utf-8", "gb2312", $indexFname);
    $cookies = "";
    if (file_exists($tf)) {
        $isSleep = false;
        $content = file_get_contents($tf);
        echo "From cache get index.....\n";
    } else {
        /*获取并设置cookie*/
        $httpClient->get($cookieURL);
        $cookies = $httpClient->getCookies();
        $httpClient->setCookies($cookies);
        if (!$cookies) {
            die("cookie error");
        }
        $isSleep = true;
        $httpClient->get($indexURL);
        $content = $httpClient->getContent();
        save($indexFname, $content);
        //保存
        echo "save index file...\n";
    }
    /* 解析出一共有多少页面 */
    $pageCount = parsePageCount($content);
    echo "Page is {$pageCount} ****\n";
    $articleCount = ARTICLE_PRE_PAGE * $pageCount;
    //计算一共有多少篇文章,大于等于实际文章数目,不影响结果
    echo "total article is {$articleCount}\n";
    $pageCount = $articleCount / ARTICLE_PRE_PAGE;
    $pageCount = ceil($pageCount);
    //向上取整,不放过任何数据
    if ($pageCount == 0) {
        $pageCount = 1;
    }
    if ($pageCount > 50) {
        echo "page count is big than 50\n";
    }
    echo "total page of {$class} is : {$pageCount}...............{$curClass} of {$totalClass}\n";
    if ($isSleep) {
        fakeSleep();
    }
    /* 抓取每一个页面并且保存下来,保存的同时进行解析 */
    for ($i = 1; $i <= $pageCount; $i++) {
        $content = NULL;
        $pageI = getPageI($indexURL, $i);
        //第i页的地址
        $htmlI = "./html/{$subDir}/{$class}/{$i}.html";
        if (!file_exists(iconv("utf-8", "gb2312", $htmlI))) {
            $isSleep = true;
            $httpClient->setCookies($cookies);
            $httpClient->get($pageI);
            $content = $httpClient->getContent();
            save($htmlI, $content);
            echo "From newwork & save {$i}.html..........[{$i} of {$pageCount}]\n";
        } else {
            $tmpf2 = iconv("utf-8", "gb2312", $htmlI);
            $content = file_get_contents($tmpf2);
            $ok = validatePageContent($content);
            //是否出现了验证码
            if (!$ok) {
                $i = $i - 1;
                delFile($htmlI);
            } else {
                $isSleep = false;
                echo "Find local file {$htmlI} & skip\n";
            }
            //continue;
        }
        $logName = "./data/{$subDir}/{$class}.log";
        if (!validatePageContent($content)) {
            $i = $i - 1;
            delFile($htmlI);
            dosleep(60);
            $httpClient = new HttpClient("epub.cnki.net");
            $httpClient->get($cookieURL);
            $cookies = $httpClient->getCookies();
            $httpClient->setCookies($cookies);
            continue;
        }
        parseContent($content, $logName, $code);
        if ($i != $pageCount && $isSleep) {
            fakeSleep();
        } else {
            echo "+\n";
            echo "+\n";
            echo "+ {$class} done\n";
            echo "+\n";
            echo "+\n";
        }
    }
}
Пример #21
0
/**
 * installs composer to the current working directory
 */
function installComposer($version, $installDir, $filename, $quiet, $disableTls, $cafile, $channel)
{
    $installPath = (is_dir($installDir) ? rtrim($installDir, '/') . '/' : '') . $filename;
    $installDir = realpath($installDir) ? realpath($installDir) : getcwd();
    $file = $installDir . DIRECTORY_SEPARATOR . $filename;
    if (is_readable($file)) {
        @unlink($file);
    }
    $home = getHomeDir();
    file_put_contents($home . '/keys.dev.pub', <<<DEVPUBKEY
-----BEGIN PUBLIC KEY-----
MIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEAnBDHjZS6e0ZMoK3xTD7f
FNCzlXjX/Aie2dit8QXA03pSrOTbaMnxON3hUL47Lz3g1SC6YJEMVHr0zYq4elWi
i3ecFEgzLcj+pZM5X6qWu2Ozz4vWx3JYo1/a/HYdOuW9e3lwS8VtS0AVJA+U8X0A
hZnBmGpltHhO8hPKHgkJtkTUxCheTcbqn4wGHl8Z2SediDcPTLwqezWKUfrYzu1f
o/j3WFwFs6GtK4wdYtiXr+yspBZHO3y1udf8eFFGcb2V3EaLOrtfur6XQVizjOuk
8lw5zzse1Qp/klHqbDRsjSzJ6iL6F4aynBc6Euqt/8ccNAIz0rLjLhOraeyj4eNn
8iokwMKiXpcrQLTKH+RH1JCuOVxQ436bJwbSsp1VwiqftPQieN+tzqy+EiHJJmGf
TBAbWcncicCk9q2md+AmhNbvHO4PWbbz9TzC7HJb460jyWeuMEvw3gNIpEo2jYa9
pMV6cVqnSa+wOc0D7pC9a6bne0bvLcm3S+w6I5iDB3lZsb3A9UtRiSP7aGSo7D72
8tC8+cIgZcI7k9vjvOqH+d7sdOU2yPCnRY6wFh62/g8bDnUpr56nZN1G89GwM4d4
r/TU7BQQIzsZgAiqOGXvVklIgAMiV0iucgf3rNBLjjeNEwNSTTG9F0CtQ+7JLwaE
wSEuAuRm+pRqi8BRnQ/GKUcCAwEAAQ==
-----END PUBLIC KEY-----
DEVPUBKEY
);
    file_put_contents($home . '/keys.tags.pub', <<<TAGSPUBKEY
-----BEGIN PUBLIC KEY-----
MIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEA0Vi/2K6apCVj76nCnCl2
MQUPdK+A9eqkYBacXo2wQBYmyVlXm2/n/ZsX6pCLYPQTHyr5jXbkQzBw8SKqPdlh
vA7NpbMeNCz7wP/AobvUXM8xQuXKbMDTY2uZ4O7sM+PfGbptKPBGLe8Z8d2sUnTO
bXtX6Lrj13wkRto7st/w/Yp33RHe9SlqkiiS4MsH1jBkcIkEHsRaveZzedUaxY0M
mba0uPhGUInpPzEHwrYqBBEtWvP97t2vtfx8I5qv28kh0Y6t+jnjL1Urid2iuQZf
noCMFIOu4vksK5HxJxxrN0GOmGmwVQjOOtxkwikNiotZGPR4KsVj8NnBrLX7oGuM
nQvGciiu+KoC2r3HDBrpDeBVdOWxDzT5R4iI0KoLzFh2pKqwbY+obNPS2bj+2dgJ
rV3V5Jjry42QOCBN3c88wU1PKftOLj2ECpewY6vnE478IipiEu7EAdK8Zwj2LmTr
RKQUSa9k7ggBkYZWAeO/2Ag0ey3g2bg7eqk+sHEq5ynIXd5lhv6tC5PBdHlWipDK
tl2IxiEnejnOmAzGVivE1YGduYBjN+mjxDVy8KGBrjnz1JPgAvgdwJ2dYw4Rsc/e
TzCFWGk/HM6a4f0IzBWbJ5ot0PIi4amk07IotBXDWwqDiQTwyuGCym5EqWQ2BD95
RGv89BPD+2DLnJysngsvVaUCAwEAAQ==
-----END PUBLIC KEY-----
TAGSPUBKEY
);
    if (false === $disableTls && empty($cafile) && !HttpClient::getSystemCaRootBundlePath()) {
        $errorHandler = new ErrorHandler();
        set_error_handler(array($errorHandler, 'handleError'));
        $target = $home . '/cacert.pem';
        $write = file_put_contents($target, HttpClient::getPackagedCaFile(), LOCK_EX);
        @chmod($target, 0644);
        restore_error_handler();
        if (!$write) {
            throw new RuntimeException('Unable to write bundled cacert.pem to: ' . $target);
        }
        $cafile = $target;
    }
    $httpClient = new HttpClient($disableTls, $cafile);
    $uriScheme = false === $disableTls ? 'https' : 'http';
    if (!$version) {
        $versions = json_decode($httpClient->get($uriScheme . '://getcomposer.org/versions'), true);
        foreach ($versions[$channel] as $candidate) {
            if ($candidate['min-php'] <= PHP_VERSION_ID) {
                $version = $candidate['version'];
                $downloadUrl = $candidate['path'];
                break;
            }
        }
        if (!$version) {
            throw new RuntimeException('There is no version of Composer available for your PHP version (' . PHP_VERSION . ')');
        }
    } else {
        $downloadUrl = "/download/{$version}/composer.phar";
    }
    $retries = 3;
    while ($retries--) {
        if (!$quiet) {
            out("Downloading {$version}...", 'info');
        }
        $url = "{$uriScheme}://getcomposer.org{$downloadUrl}";
        $errorHandler = new ErrorHandler();
        set_error_handler(array($errorHandler, 'handleError'));
        // download signature file
        if (false === $disableTls) {
            $signature = $httpClient->get($url . '.sig');
            if (!$signature) {
                out('Download failed: ' . $errorHandler->message, 'error');
            } else {
                $signature = json_decode($signature, true);
                $signature = base64_decode($signature['sha384']);
            }
        }
        $fh = fopen($file, 'w');
        if (!$fh) {
            out('Could not create file ' . $file . ': ' . $errorHandler->message, 'error');
        }
        if (!fwrite($fh, $httpClient->get($url))) {
            out('Download failed: ' . $errorHandler->message, 'error');
        }
        fclose($fh);
        restore_error_handler();
        if ($errorHandler->message) {
            continue;
        }
        try {
            // create a temp file ending in .phar since the Phar class only accepts that
            if ('.phar' !== substr($file, -5)) {
                copy($file, $file . '.tmp.phar');
                $pharFile = $file . '.tmp.phar';
            } else {
                $pharFile = $file;
            }
            // verify signature
            if (false === $disableTls) {
                $pubkeyid = openssl_pkey_get_public('file://' . $home . '/' . (preg_match('{^[0-9a-f]{40}$}', $version) ? 'keys.dev.pub' : 'keys.tags.pub'));
                $algo = defined('OPENSSL_ALGO_SHA384') ? OPENSSL_ALGO_SHA384 : 'SHA384';
                if (!in_array('SHA384', openssl_get_md_methods())) {
                    out('SHA384 is not supported by your openssl extension, could not verify the phar file integrity', 'error');
                    exit(1);
                }
                $verified = 1 === openssl_verify(file_get_contents($file), $signature, $pubkeyid, $algo);
                openssl_free_key($pubkeyid);
                if (!$verified) {
                    out('Signature mismatch, could not verify the phar file integrity', 'error');
                    exit(1);
                }
            }
            // test the phar validity
            if (!ini_get('phar.readonly')) {
                $phar = new Phar($pharFile);
                // free the variable to unlock the file
                unset($phar);
            }
            // clean up temp file if needed
            if ($file !== $pharFile) {
                unlink($pharFile);
            }
            break;
        } catch (Exception $e) {
            if (!$e instanceof UnexpectedValueException && !$e instanceof PharException) {
                throw $e;
            }
            // clean up temp file if needed
            if ($file !== $pharFile) {
                unlink($pharFile);
            }
            unlink($file);
            if ($retries) {
                if (!$quiet) {
                    out('The download is corrupt, retrying...', 'error');
                }
            } else {
                out('The download is corrupt (' . $e->getMessage() . '), aborting.', 'error');
                exit(1);
            }
        }
    }
    if ($errorHandler->message) {
        out('The download failed repeatedly, aborting.', 'error');
        exit(1);
    }
    chmod($file, 0755);
    if (!$quiet) {
        out(PHP_EOL . "Composer successfully installed to: " . $file, 'success', false);
        out(PHP_EOL . "Use it: php {$installPath}", 'info');
    }
}
Пример #22
0
/**
 * Workaround for allow_url_fopen, to get the content of an external URI.
 * It returns the contents in one slurp. Parsers might want to check for allow_url_fopen
 * and use fopen, fread chunkwise. (see lib/XmlParser.php)
 */
function url_get_contents($uri)
{
    if (get_cfg_var('allow_url_fopen')) {
        // was ini_get('allow_url_fopen'))
        return @file_get_contents($uri);
    } else {
        require_once "lib/HttpClient.php";
        $bits = parse_url($uri);
        $host = $bits['host'];
        $port = isset($bits['port']) ? $bits['port'] : 80;
        $path = isset($bits['path']) ? $bits['path'] : '/';
        if (isset($bits['query'])) {
            $path .= '?' . $bits['query'];
        }
        $client = new HttpClient($host, $port);
        $client->use_gzip = false;
        if (!$client->get($path)) {
            return false;
        } else {
            return $client->getContent();
        }
    }
}
Пример #23
0
 function getGopayServerTime()
 {
     $url = "https://mertest.gopay.com.cn/PGServer/time";
     //如果方法报错,请修改参数为http://mertest.gopay.com.cn/PGServer/time
     $bits = parse_url($url);
     $host = $bits['host'];
     $port = isset($bits['port']) ? $bits['port'] : 80;
     $path = isset($bits['path']) ? $bits['path'] : '/';
     if (isset($bits['query'])) {
         $path .= '?' . $bits['query'];
     }
     $client = new HttpClient($host, $port);
     if (!$client->get($path)) {
         return false;
     } else {
         return $client->getContent();
     }
 }
 /**
  * Initialize and return the HttpClient
  *
  * @return HttpClient
  */
 protected function createHttpClient()
 {
     require_once INSTALL_PATH . "/server/classes/class.HttpClient.php";
     $httpClient = new HttpClient($this->host);
     $httpClient->cookie_host = $this->host;
     $httpClient->timeout = 50;
     AJXP_Logger::debug("Creating Http client", array());
     //$httpClient->setDebug(true);
     if (!$this->use_auth) {
         return $httpClient;
     }
     $uri = "";
     if ($this->auth_path != "") {
         $httpClient->setAuthorization($this->user, $this->password);
         $uri = $this->auth_path;
     }
     if (!isset($_SESSION["AJXP_REMOTE_SESSION"])) {
         if ($uri == "") {
             // Retrieve a seed!
             $httpClient->get($this->path . "?get_action=get_seed");
             $seed = $httpClient->getContent();
             $user = $this->user;
             $pass = $this->password;
             $pass = md5(md5($pass) . $seed);
             $uri = $this->path . "?get_action=login&userid=" . $user . "&password="******"&login_seed={$seed}";
         }
         $httpClient->setHeadersOnly(true);
         $httpClient->get($uri);
         $httpClient->setHeadersOnly(false);
         $cookies = $httpClient->getCookies();
         if (isset($cookies["AjaXplorer"])) {
             $_SESSION["AJXP_REMOTE_SESSION"] = $cookies["AjaXplorer"];
             $remoteSessionId = $cookies["AjaXplorer"];
         }
     } else {
         $remoteSessionId = $_SESSION["AJXP_REMOTE_SESSION"];
         $httpClient->setCookies(array("AjaXplorer" => $remoteSessionId));
     }
     AJXP_Logger::debug("Http Client created", array());
     return $httpClient;
 }
 public function switchAction($action, $httpVars, $fileVars)
 {
     //AJXP_Logger::logAction("DL file", $httpVars);
     $repository = ConfService::getRepository();
     if (!$repository->detectStreamWrapper(false)) {
         return false;
     }
     $plugin = AJXP_PluginsService::findPlugin("access", $repository->getAccessType());
     $streamData = $plugin->detectStreamWrapper(true);
     $dir = AJXP_Utils::decodeSecureMagic($httpVars["dir"]);
     $destStreamURL = $streamData["protocol"] . "://" . $repository->getId() . $dir . "/";
     if (isset($httpVars["file"])) {
         $parts = parse_url($httpVars["file"]);
         $getPath = $parts["path"];
         $basename = basename($getPath);
     }
     if (isset($httpVars["dlfile"])) {
         $dlFile = $streamData["protocol"] . "://" . $repository->getId() . AJXP_Utils::decodeSecureMagic($httpVars["dlfile"]);
         $realFile = file_get_contents($dlFile);
         if (empty($realFile)) {
             throw new Exception("cannot find file {$dlFile} for download");
         }
         $parts = parse_url($realFile);
         $getPath = $parts["path"];
         $basename = basename($getPath);
     }
     switch ($action) {
         case "external_download":
             if (!ConfService::currentContextIsCommandLine() && ConfService::backgroundActionsSupported()) {
                 $unixProcess = AJXP_Controller::applyActionInBackground($repository->getId(), "external_download", $httpVars);
                 if ($unixProcess !== null) {
                     @file_put_contents($destStreamURL . "." . $basename . ".pid", $unixProcess->getPid());
                 }
                 AJXP_XMLWriter::header();
                 AJXP_XMLWriter::triggerBgAction("reload_node", array(), "Triggering DL ", true, 2);
                 AJXP_XMLWriter::close();
                 session_write_close();
                 exit;
             }
             require_once AJXP_BIN_FOLDER . "/class.HttpClient.php";
             $mess = ConfService::getMessages();
             session_write_close();
             $client = new HttpClient($parts["host"]);
             $collectHeaders = array("ajxp-last-redirection" => "", "content-disposition" => "", "content-length" => "");
             $client->setHeadersOnly(true, $collectHeaders);
             $client->setMaxRedirects(8);
             $client->setDebug(false);
             $client->get($getPath);
             $pidHiddenFileName = $destStreamURL . "." . $basename . ".pid";
             if (is_file($pidHiddenFileName)) {
                 $pid = file_get_contents($pidHiddenFileName);
                 @unlink($pidHiddenFileName);
             }
             AJXP_Logger::debug("COLLECTED HEADERS", $client->collectHeaders);
             $collectHeaders = $client->collectHeaders;
             $totalSize = -1;
             if (!empty($collectHeaders["content-disposition"]) && strstr($collectHeaders["content-disposition"], "filename") !== false) {
                 $ar = explode("filename=", $collectHeaders["content-disposition"]);
                 $basename = trim(array_pop($ar));
                 $basename = str_replace("\"", "", $basename);
                 // Remove quotes
             }
             if (!empty($collectHeaders["content-length"])) {
                 $totalSize = intval($collectHeaders["content-length"]);
                 AJXP_Logger::debug("Should download {$totalSize} bytes!");
             }
             if ($totalSize != -1) {
                 $node = new AJXP_Node($destStreamURL . $basename);
                 AJXP_Controller::applyHook("node.before_create", array($node, $totalSize));
             }
             $qData = false;
             if (!empty($collectHeaders["ajxp-last-redirection"])) {
                 $newParsed = parse_url($collectHeaders["ajxp-last-redirection"]);
                 $client->host = $newParsed["host"];
                 $getPath = $newParsed["path"];
                 if (isset($newParsed["query"])) {
                     $qData = parse_url($newParsed["query"]);
                 }
             }
             $tmpFilename = $destStreamURL . $basename . ".dlpart";
             $hiddenFilename = $destStreamURL . "__" . $basename . ".ser";
             $filename = $destStreamURL . $basename;
             $dlData = array("sourceUrl" => $getPath, "totalSize" => $totalSize);
             if (isset($pid)) {
                 $dlData["pid"] = $pid;
             }
             //file_put_contents($hiddenFilename, serialize($dlData));
             $fpHid = fopen($hiddenFilename, "w");
             fputs($fpHid, serialize($dlData));
             fclose($fpHid);
             $client->redirect_count = 0;
             $client->setHeadersOnly(false);
             $destStream = fopen($tmpFilename, "w");
             if ($destStream !== false) {
                 $client->writeContentToStream($destStream);
                 $client->get($getPath, $qData);
                 fclose($destStream);
             }
             rename($tmpFilename, $filename);
             unlink($hiddenFilename);
             if (isset($dlFile) && isset($httpVars["delete_dlfile"]) && is_file($dlFile)) {
                 AJXP_Controller::applyHook("node.before_change", array(new AJXP_Node($dlFile)));
                 unlink($dlFile);
                 AJXP_Controller::applyHook("node.change", array(new AJXP_Node($dlFile), null, false));
             }
             AJXP_Controller::applyHook("node.change", array(null, new AJXP_Node($filename), false));
             AJXP_XMLWriter::header();
             AJXP_XMLWriter::triggerBgAction("reload_node", array(), $mess["httpdownloader.8"]);
             AJXP_XMLWriter::close();
             exit;
             break;
         case "update_dl_data":
             $file = AJXP_Utils::decodeSecureMagic($httpVars["file"]);
             header("text/plain");
             if (is_file($destStreamURL . $file)) {
                 echo filesize($destStreamURL . $file);
             } else {
                 echo "stop";
             }
             exit;
             break;
         case "stop_dl":
             $newName = "__" . str_replace(".dlpart", ".ser", $basename);
             $hiddenFilename = $destStreamURL . $newName;
             $data = @unserialize(@file_get_contents($hiddenFilename));
             header("text/plain");
             AJXP_Logger::debug("Getting {$hiddenFilename}", $data);
             if (isset($data["pid"])) {
                 $process = new UnixProcess();
                 $process->setPid($data["pid"]);
                 $process->stop();
                 unlink($hiddenFilename);
                 unlink($destStreamURL . $basename);
                 echo 'stop';
             } else {
                 echo 'failed';
             }
             exit;
             break;
         default:
             break;
     }
     return true;
 }
 /**
  * @return HttpClient
  */
 public function getRemoteConnexion(&$remoteSecureToken, $refreshSessId = false, $repository = null)
 {
     require_once AJXP_BIN_FOLDER . "/class.HttpClient.php";
     if ($repository != null) {
         $crtRep = $repository;
     } else {
         $crtRep = ConfService::getRepository();
     }
     $httpClient = new HttpClient($crtRep->getOption("HOST"));
     $httpClient->cookie_host = $crtRep->getOption("HOST");
     $httpClient->timeout = 10;
     if (isset($_SESSION["AJXP_REMOTE_SESSION"]) && is_array($_SESSION["AJXP_REMOTE_SESSION"])) {
         $httpClient->setCookies($_SESSION["AJXP_REMOTE_SESSION"]);
     }
     //$httpClient->setDebug(true);
     if (!isset($_SESSION["AJXP_REMOTE_SECURE_TOKEN"])) {
         $httpClient->get($crtRep->getOption("URI") . "?get_action=get_secure_token");
         $remoteSecureToken = $httpClient->getContent();
         $_SESSION["AJXP_REMOTE_SECURE_TOKEN"] = $remoteSecureToken;
     } else {
         $remoteSecureToken = $_SESSION["AJXP_REMOTE_SECURE_TOKEN"];
     }
     if (!$crtRep->getOption("USE_AUTH")) {
         return $httpClient;
     }
     $uri = "";
     if ($crtRep->getOption("AUTH_URI") != "") {
         $httpClient->setAuthorization($crtRep->getOption("AUTH_USER"), $crtRep->getOption("AUTH_PASS"));
         $uri = $crtRep->getOption("AUTH_URI") . "?secure_token={$remoteSecureToken}";
     }
     if (!isset($_SESSION["AJXP_REMOTE_SESSION"]) || !is_array($_SESSION["AJXP_REMOTE_SESSION"]) || $refreshSessId) {
         if ($uri == "") {
             $this->logDebug("Remote_fs : relog necessary");
             // Retrieve a seed!
             $httpClient->get($crtRep->getOption("URI") . "?get_action=get_seed&secure_token={$remoteSecureToken}");
             $seed = $httpClient->getContent();
             $cookies = $httpClient->getCookies();
             if (isset($cookies["AjaXplorer"])) {
                 $_SESSION["AJXP_REMOTE_SESSION"] = $cookies;
             }
             $user = $crtRep->getOption("AUTH_USER");
             $pass = $crtRep->getOption("AUTH_PASS");
             $pass = md5(md5($pass) . $seed);
             $uri = $crtRep->getOption("URI") . "?get_action=login&userid=" . $user . "&password="******"&login_seed={$seed}&secure_token={$remoteSecureToken}";
             $httpClient->get($uri);
             $content = $httpClient->getContent();
             $matches = array();
             if (preg_match_all('#.*?secure_token="(.*?)".*?#s', $content, $matches)) {
                 $remoteSecureToken = $matches[1][0];
                 $_SESSION["AJXP_REMOTE_SECURE_TOKEN"] = $remoteSecureToken;
             }
             $httpClient->setHeadersOnly(false);
         } else {
             $httpClient->setHeadersOnly(true);
             $httpClient->get($uri);
             $httpClient->setHeadersOnly(false);
         }
         $cookies = $httpClient->getCookies();
         $_SESSION["AJXP_REMOTE_SESSION"] = $httpClient->getCookies();
     } else {
         $httpClient->setCookies($_SESSION["AJXP_REMOTE_SESSION"]);
     }
     return $httpClient;
 }
Пример #27
0
 public function testHeader()
 {
     $http = new HttpClient();
     $page = $http->get('http://httpbin.org/redirect/1', array('header' => true, 'curl' => array(CURLOPT_FOLLOWLOCATION => 0)));
     $this->assertNotSame(false, strpos($page, 'Location: /get'));
 }
Пример #28
0
 static function quickGet($url, $time = 30, $justhtml = true, $cks = array())
 {
     $bits = parse_url($url);
     $host = $bits['host'];
     $port = isset($bits['port']) ? $bits['port'] : 80;
     $path = isset($bits['path']) ? $bits['path'] : '/';
     if (isset($bits['query'])) {
         $path .= '?' . $bits['query'];
     }
     $client = new HttpClient($host, $port);
     $client->oldurl = $url;
     $client->setCookies($cks);
     $client->timeout = $time;
     $client->justhtml = $justhtml;
     if (!$client->get($path)) {
         return false;
     } else {
         return $client->getContent();
     }
 }
 function quickGet($url)
 {
     $bits = parse_url($url);
     $host = $bits['host'];
     $port = isset($bits['port']) ? $bits['port'] : 80;
     $path = isset($bits['path']) ? $bits['path'] : '/';
     if (isset($bits['query'])) {
         $path .= '?' . $bits['query'];
     }
     $client = new HttpClient($host, $port);
     if (!$client->get($path)) {
         return false;
     } else {
         return $client->getContent();
     }
 }
Пример #30
0
 public function queryPrinterStatus($device_no)
 {
     $client = new HttpClient(FEIE_HOST, FEIE_PORT);
     if (!$client->get('/FeieServer/queryprinterstatus?clientCode=' . $device_no)) {
         //请求失败
         return 'faild';
     } else {
         $result = $client->getContent();
         return $result;
     }
 }