コード例 #1
1
 /**
  * @param string
  * @param \Nette\Database\Context
  */
 public function __construct($cryptPassword, Context $db)
 {
     $this->cryptPassword = $cryptPassword;
     $this->baseUrl = new Url('https://nette.org/loginpoint.php');
     $this->httpClient = new Client();
     $this->httpClient->setUserAgent('Nette Addons portal authenticator');
     $this->db = $db;
 }
コード例 #2
0
ファイル: Connection.php プロジェクト: grit45/gumer-psn-php
 /**
  * @param \Guzzle\Http\Client $guzzle
  * @return void
  */
 public function setGuzzle(Client $guzzle)
 {
     $this->guzzle = $guzzle;
     $this->guzzle->setSslVerification(false, false);
     $this->guzzle->setUserAgent('User-Agent: Mozilla/5.0 (Linux; U; Android 4.3; EN; C6502 Build/10.4.1.B.0.101) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30 PlayStation App/1.60.5/EN/EN');
     $this->guzzle->addSubscriber(new CookiePlugin(new ArrayCookieJar()));
 }
コード例 #3
0
 /**
  * Constructor
  *
  * @param \Guzzle\Http\Client $guzzle   Guzzle instance
  * @param \Closure            $rsa      Closure for phpseclib RSA instance
  * @param StorageInterface    $storage  Storage instance
  */
 public function __construct(\Guzzle\Http\Client $guzzle, \Closure $rsa, StorageInterface $storage)
 {
     $this->guzzle = $guzzle;
     $this->guzzle->setUserAgent(AcmePhpClient::USER_AGENT);
     $this->rsa = $rsa;
     $this->storage = $storage;
 }
コード例 #4
0
 /**
  * Instantiates a YoutubeDownloader with a random User-Agent
  * @param string $videoUrl Full Youtube video url or just video ID
  * @example var downloader = new YoutubeDownloader('gmFn62dr0D8');
  * @example var downloader = new YoutubeDownloader('http://www.youtube.com/watch?v=gmFn62dr0D8');
  */
 public function __construct($videoUrl)
 {
     $this->videoId = $this->getVideoIdFromUrl($videoUrl);
     $this->webClient = new \Guzzle\Http\Client();
     $this->webClient->setUserAgent(\random_uagent());
     $this->onProgress = function ($downloadedBytes, $fileSize) {
     };
 }
コード例 #5
0
ファイル: RestClient.php プロジェクト: pars5555/hqv
 /**
  * @param string $apiKey
  * @param string $apiEndpoint
  * @param string $apiVersion
  * @param bool $ssl
  */
 public function __construct($apiKey, $apiEndpoint, $apiVersion, $ssl)
 {
     $this->apiKey = $apiKey;
     $this->mgClient = new Guzzle($this->generateEndpoint($apiEndpoint, $apiVersion, $ssl));
     $this->mgClient->setDefaultOption('curl.options', array('CURLOPT_FORBID_REUSE' => true));
     $this->mgClient->setDefaultOption('auth', array(Api::API_USER, $this->apiKey));
     $this->mgClient->setDefaultOption('exceptions', false);
     $this->mgClient->setUserAgent(Api::SDK_USER_AGENT . '/' . Api::SDK_VERSION);
 }
コード例 #6
0
 /**
  * Constructor.
  *
  * @param Credentials $credentials The credentials to use.
  */
 public function __construct(Credentials $credentials)
 {
     $this->credentials = $credentials;
     $this->apiUrl = self::ENDPOINT_URL;
     //Initialize API Client
     $this->client = new Client(self::ENDPOINT_URL);
     $this->client->setDefaultOption('auth', array($this->credentials->getEmail(), $this->credentials->getAccountKey(), 'Basic'));
     $this->client->setUserAgent(self::USER_AGENT);
 }
コード例 #7
0
 public function connect($errors = 0)
 {
     $client = new Client(null);
     if (!file_exists($this->_cookieFile)) {
         file_put_contents($this->_cookieFile, "");
     }
     $cookiePlugin = new CookiePlugin(new FileCookieJar($this->_cookieFile));
     $client->addSubscriber($cookiePlugin);
     $client->setUserAgent('User-Agent', 'Mozilla/5.0 (Linux; U; Android 4.2.2; de-de; GT-I9195 Build/JDQ39) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30');
     $this->_client = $client;
     try {
         $url = $this->getLoginUrl();
         $this->loginAndGetCode($url);
         $this->enterAnswer();
         $this->gatewayMe();
         $this->auth();
         $this->getSid();
         $this->utasRefreshNucId();
         $this->auth();
         $this->utasAuth();
         $this->utasQuestion();
     } catch (\Exception $e) {
         throw $e;
         // server down, gotta retry
         if ($errors < static::RETRY_ON_SERVER_DOWN && preg_match("/service unavailable/mi", $e->getMessage())) {
             $this->connect(++$errors);
         } else {
             throw new \Exception('Could not connect to the mobile endpoint.');
         }
     }
     return array("nucleusId" => $this->nucId, "userAccounts" => $this->accounts, "sessionId" => $this->sid, "phishingToken" => $this->phishingToken, "platform" => $this->_loginDetails['platform']);
 }
コード例 #8
0
 public function Connect()
 {
     $client = new Client(null);
     if (!file_exists($this->_cookieFile)) {
         file_put_contents($this->_cookieFile, "");
     }
     $cookiePlugin = new CookiePlugin(new FileCookieJar($this->_cookieFile));
     $client->addSubscriber($cookiePlugin);
     $client->setUserAgent("Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/29.0.1547.62 Safari/537.36");
     $this->_client = $client;
     $login_url = $this->GetMainPage($this->urls['main']);
     $this->Login($login_url);
     $nucleusId = $this->GetNucleusId($this->urls['nucleus']);
     $this->GetShards($nucleusId, $this->urls['shards']);
     $userAccounts = $this->GetUserAccounts($nucleusId, $this->urls['userinfo']);
     $sessionId = $this->GetSessionId($nucleusId, $userAccounts, $this->urls['session']);
     $phishing = $this->Phishing($nucleusId, $sessionId, $this->urls['phishing']);
     if (isset($phishing['debug']) && $phishing['debug'] == "Already answered question.") {
         $phishingToken = $phishing['token'];
     } else {
         $phishingToken = $this->Validate($nucleusId, $sessionId, $this->urls['validate']);
     }
     $this->_loginResponse = array("nucleusId" => $nucleusId, "userAccounts" => $userAccounts, "sessionId" => $sessionId, "phishingToken" => $phishingToken, "platform" => $this->_loginDetails['platform']);
     return $this->_loginResponse;
 }
コード例 #9
0
ファイル: Klout.php プロジェクト: oytuntez/klout-sdk-php
 /**
  * Create the default Client
  *
  * @return \Klout\Klout
  */
 protected function createClient()
 {
     $client = new Client($this->apiBaseUri);
     $client->setUserAgent(__CLASS__, true);
     $this->setClient($client);
     return $this;
 }
コード例 #10
0
ファイル: Client.php プロジェクト: seofood/amazon-revenue
 /**
  * @param string $username
  * @param string $password
  * @param string $country
  *
  * @throws Exception
  */
 public function __construct($username, $password, $country = 'DE')
 {
     $this->_username = $username;
     $this->_password = $password;
     $this->_country = $country;
     if (!array_key_exists($country, $this->_hostNames)) {
         throw new Exception('No hostname for the given country available.');
     }
     $this->_host = $this->_hostNames[$country];
     $this->_client = new HttpClient('https://' . $this->_host . '/');
     $this->_client->setSslVerification(false, false, 0);
     $this->_client->setUserAgent('Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.17 (KHTML, like Gecko) Chrome/24.0.1312.57 Safari/537.17', true);
     $cookiePlugin = new CookiePlugin(new ArrayCookieJar());
     $this->_client->addSubscriber($cookiePlugin);
     $this->_login();
 }
コード例 #11
0
ファイル: Request.php プロジェクト: blueprintmrk/cli
 /**
  * Sends a request to the API
  *
  * @param [string] $url    URL for API request
  * @param [string] $method Request method (i.e. PUT, POST, DELETE, or GET)
  * @param [array]  $data   Options for request
  * @return [Guzzle\Http\Message\Response] $response
  */
 public static function send($url, $method, $data = array())
 {
     // Create a new Guzzle\Http\Client
     $browser = new Browser();
     $browser->setUserAgent(self::userAgent());
     $options = self::processOptions($data);
     $request = $browser->createRequest($method, $url, null, null, $options);
     if (!empty($data['postdata'])) {
         foreach ($data['postdata'] as $k => $v) {
             $request->setPostField($k, $v);
         }
     }
     if (!empty($data['cookies'])) {
         foreach ($data['cookies'] as $k => $v) {
             $request->addCookie($k, $v);
         }
     }
     if (!empty($data['headers'])) {
         foreach ($data['headers'] as $k => $v) {
             $request->setHeader($k, $v);
         }
     }
     if (!empty($data['body']) && method_exists($request, 'setBody')) {
         $request->setBody(json_encode($data['body']));
     }
     $debug = '#### REQUEST ####' . PHP_EOL;
     $debug .= $request->getRawHeaders();
     Terminus::getLogger()->debug('Headers: {headers}', array('headers' => $debug));
     if (isset($data['body'])) {
         Terminus::getLogger()->debug('Body: {body}', array('body' => $data['body']));
     }
     $response = $request->send();
     return $response;
 }
コード例 #12
0
 /**
  * @param Client $client
  */
 public function __construct(Client $client = null)
 {
     if (empty($client)) {
         $client = new Client();
         $client->setUserAgent(DEFAULT_USER_AGENT);
     }
     $this->client = $client;
 }
コード例 #13
0
 public function testServerParamsAreRecorded()
 {
     $this->client->setUserAgent('CUSTOM UA')->get('/foo')->setAuth('username', 'password')->setProtocolVersion('1.0')->send();
     $latestRequest = unserialize($this->client->get('/_request/latest')->send()->getBody());
     $this->assertSame(HTTP_MOCK_HOST, $latestRequest['server']['SERVER_NAME']);
     $this->assertSame(HTTP_MOCK_PORT, $latestRequest['server']['SERVER_PORT']);
     $this->assertSame('username', $latestRequest['server']['PHP_AUTH_USER']);
     $this->assertSame('password', $latestRequest['server']['PHP_AUTH_PW']);
     $this->assertSame('HTTP/1.0', $latestRequest['server']['SERVER_PROTOCOL']);
     $this->assertSame('CUSTOM UA', $latestRequest['server']['HTTP_USER_AGENT']);
 }
コード例 #14
0
ファイル: VCRTest.php プロジェクト: alnutile/drunatra
 public function testShouldInterceptGuzzleLibrary()
 {
     VCR::configure()->enableLibraryHooks(array('curl'));
     VCR::turnOn();
     VCR::insertCassette('unittest_guzzle_test');
     $client = new Client();
     $client->setUserAgent(false);
     $response = $client->post('http://example.com')->send();
     $this->assertEquals('This is a guzzle test dummy.', (string) $response->getBody(), 'Guzzle call was not intercepted.');
     VCR::eject();
     VCR::turnOff();
 }
コード例 #15
0
 /**
  * Inject Guzzle in this test class
  * And set up the given client for use on
  * Damn Vulnerable Web Application... A vulnerable application
  * without API...
  * Difficulty resided in finding the way of using
  * cookies and correct documentation for all methods.
  */
 public function __construct()
 {
     parent::__construct();
     //prepare a cookie jar
     $jar = new ArrayCookieJar();
     $cookiePlugin = new CookiePlugin($jar);
     //get a guzzle instance
     $this->_dvwa_guzzle = new Client();
     $this->_dvwa_guzzle->setBaseUrl($this->DVWA_URL);
     $this->_dvwa_guzzle->setUserAgent("Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/48.0.2564.109 Safari/537.36");
     $this->_dvwa_guzzle->addSubscriber($cookiePlugin);
     //first request/response exchange to get CSRF token
     $request = $this->_dvwa_guzzle->get('login.php', null, ["allow_redirects" => false]);
     $response = $request->send();
     $str = $response->getBody();
     preg_match($this->USER_TOKEN_REGEX, $str, $matches);
     $user_token = $matches[1];
     //second exchange to login
     $request = $this->_dvwa_guzzle->createRequest('POST', 'login.php', null, ['username' => 'admin', 'password' => 'password', 'Login' => 'Login', 'user_token' => $user_token], ["allow_redirects" => true]);
     $request->send();
 }
コード例 #16
0
ファイル: Request.php プロジェクト: mikevanwinkle/cli
 public static function send($url, $method, $data = array())
 {
     // create a new Guzzle\Http\Client
     $browser = new Browser();
     $browser->setUserAgent(self::userAgent());
     $options = array();
     $options['allow_redirects'] = @$data['allow_redirects'] ?: false;
     $options['json'] = @$data['json'] ?: false;
     if (@$data['body']) {
         $options['body'] = $data['body'];
         if (\Terminus::get_config("debug")) {
             \Terminus\Loggers\Regular::debug($data['body']);
         }
     }
     $options['verify'] = false;
     $request = $browser->createRequest($method, $url, null, null, $options);
     if (!empty($data['postdata'])) {
         foreach ($data['postdata'] as $k => $v) {
             $request->setPostField($k, $v);
         }
     }
     if (!empty($data['cookies'])) {
         foreach ($data['cookies'] as $k => $v) {
             $request->addCookie($k, $v);
         }
     }
     if (!empty($data['headers'])) {
         foreach ($data['headers'] as $k => $v) {
             $request->setHeader($k, $v);
         }
     }
     if (\Terminus::get_config("debug")) {
         $debug = "#### REQUEST ####" . PHP_EOL;
         $debug .= $request->getRawHeaders();
         \Terminus\Loggers\Regular::debug($debug);
         if (isset($data['body'])) {
             \Terminus\Loggers\Regular::debug($data['body']);
         }
     }
     if (getenv("BUILD_FIXTURES")) {
         Fixtures::put("request_headers", $request->getRawHeaders());
     }
     $response = $request->send();
     if (getenv("BUILD_FIXTURES")) {
         Fixtures::put(array($url, $method, $data), $response);
     }
     return $response;
 }
コード例 #17
0
ファイル: Request.php プロジェクト: nataliejeremy/cli
 public static function send($url, $method, $data = array())
 {
     // create a new Guzzle\Http\Client
     $browser = new Browser();
     $browser->setUserAgent(self::userAgent());
     $options = array('allow_redirects' => false, 'verify' => false, 'json' => false);
     if (isset($data['allow_redirects'])) {
         $options['allow_redirects'] = $data['allow_redirects'];
     }
     if (isset($data['json'])) {
         $options['json'] = $data['json'];
     }
     if (isset($data['body']) && $data['body']) {
         $options['body'] = $data['body'];
         if (Terminus::get_config('debug')) {
             Terminus::log('debug', $data['body']);
         }
     }
     $request = $browser->createRequest($method, $url, null, null, $options);
     if (!empty($data['postdata'])) {
         foreach ($data['postdata'] as $k => $v) {
             $request->setPostField($k, $v);
         }
     }
     if (!empty($data['cookies'])) {
         foreach ($data['cookies'] as $k => $v) {
             $request->addCookie($k, $v);
         }
     }
     if (!empty($data['headers'])) {
         foreach ($data['headers'] as $k => $v) {
             $request->setHeader($k, $v);
         }
     }
     if (Terminus::get_config("debug")) {
         $debug = "#### REQUEST ####" . PHP_EOL;
         $debug .= $request->getRawHeaders();
         Terminus::log('debug', $debug);
         if (isset($data['body'])) {
             Terminus::log('debug', $data['body']);
         }
     }
     $response = $request->send();
     return $response;
 }
コード例 #18
0
 public function Bid($tradeid, $bid)
 {
     $client = new Client(null);
     $client->setUserAgent("Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/29.0.1547.62 Safari/537.36");
     $url = "https://utas.s2.fut.ea.com/ut/game/fifa14/trade/" . $tradeid . "/bid";
     $data_array = array('bid' => $bid);
     $data_string = json_encode($data_array);
     $request = $client->post($url, array(), $data_string);
     $request->addHeader('Origin', 'http://www.easports.com');
     $request->setHeader('Referer', 'http://www.easports.com/iframe/fut/bundles/futweb/web/flash/FifaUltimateTeam.swf');
     $request->addHeader('X-HTTP-Method-Override', 'PUT');
     $request->addHeader('X-UT-Embed-Error', 'true');
     $request->addHeader('X-UT-PHISHING-TOKEN', $this->phish);
     $request->addHeader('X-UT-SID', $this->sess);
     $request->setHeader('Content-Type', 'application/json');
     $request->addHeader('Content-Length', strlen($data_string));
     $response = $request->send();
     $json = $response->json();
     return $json;
 }
コード例 #19
0
ファイル: CreateTrait.php プロジェクト: ebidtech/http-client
 /**
  * Create HTTP client and add listener to catch errors.
  *
  * @param string $host                 Host, eg: http://eb.dev
  * @param string $userAgent            User agent used by the HTTP client.
  * @param array  $config               {@link http://guzzlephp.org/http-client/client.html#configuration-options}
  * @param bool   $retryOnCurlException If true will retry on curl exception
  *
  * @throws InvalidArgumentException
  *
  * @return GuzzleHttpClient
  */
 private function create($host, $userAgent, array $config = array(), $retryOnCurlException = false)
 {
     if (!is_string($host)) {
         throw new InvalidArgumentException(sprintf('Expected host as string got "%s"', gettype($host)));
     }
     // create client
     $client = new GuzzleHttpClient($host, $config);
     $client->setUserAgent((string) $userAgent);
     if ($retryOnCurlException) {
         $this->confRetryOnCurlException($client);
     }
     // listener completed an unsuccessful request
     $client->getEventDispatcher()->addListener('request.error', function (GuzzleEvent $event) {
         $event->stopPropagation();
         /** @var $response GuzzleResponse */
         $response = $event['response'];
         throw new RuntimeException($response->getBody(), $response->getStatusCode());
     });
     return $client;
 }
コード例 #20
0
		public function playerSearch($playerId = 0, $minbin = 0, $maxbin = 0, $start = 0, $num = 16) {
			$client = new Client(null);
			if($this->_cookieFile) {
				$cookiePlugin = new CookiePlugin(new FileCookieJar($this->_cookieFile));
        			$client->addSubscriber($cookiePlugin);
			}
        		$client->setUserAgent("Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/29.0.1547.62 Safari/537.36");
        		switch($this->console) {
				case "XBOX":
					$url = "https://utas.fut.ea.com/ut/game/fifa15/transfermarket?";
				break;
				case "PS":
					$url = "https://utas.s2.fut.ea.com/ut/game/fifa15/transfermarket?";
				break;
			}
			$searchstring = "";
                	if ($minbin > 0){
                        	$searchstring .= "&minb=".$minbin;
                	}
                	if ($maxbin > 0){
                        	$searchstring .= "&maxb=".$maxbin;
                	}
                	if ($playerId > 0) {
                		$searchstring .= "&maskedDefId=".$playerId;
                	}
                	
                	$search = $url . "type=player&start=$start&num=$num".$searchstring;
			$request = $client->post($search);
 			$request->addHeader('Origin', 'http://www.easports.com');
			$request->setHeader('Referer', 'http://www.easports.com/iframe/fut/bundles/futweb/web/flash/FifaUltimateTeam.swf');
			$request->addHeader('X-HTTP-Method-Override', 'GET');
			$request->addHeader('X-UT-Embed-Error', 'true');
			$request->addHeader('X-UT-PHISHING-TOKEN', $this->phish);				
			$request->addHeader('X-UT-SID', $this->sess);	
			$response = $request->send();
			$json = $response->json();
			return $json;
		}
コード例 #21
0
 protected function get($url = '', $params = array(), $headers = array(), $output = 'json')
 {
     $user_token = $this->session->userdata('token');
     if (!empty($user_token)) {
         $headers['X-authorization'] = $user_token;
     }
     $client = new Client();
     $client->setUserAgent($this->input->user_agent());
     $params['source_ip'] = $this->input->ip_address();
     $request = $client->get($url, $headers, array('query' => $params, 'timeout' => self::GUZZLE_TIMEOUT));
     try {
         $response = $request->send();
         return GuzzleWrapper::response($response);
     } catch (Guzzle\Http\Exception\BadResponseException $e) {
         // superclass of ClientErrorResponseException (4xx), ServerErrorResponseException (5xx) and TooManyRedirectsException
         $response = $e->getResponse();
         return GuzzleWrapper::response($response);
     } catch (Guzzle\Http\Exception\CurlException $e) {
         return GuzzleWrapper::exception($e);
     } catch (\Exception $e) {
         return GuzzleWrapper::exception($e);
     }
     return $request;
 }
コード例 #22
0
ファイル: Sender.php プロジェクト: onpaws/honeybadger-php
 private function setup_http_client()
 {
     // Fetch a copy of the configuration.
     $config = Honeybadger::$config;
     $options = array('curl.options' => array('CURLOPT_CONNECTTIMEOUT' => $config->http_open_timeout, 'CURLOPT_TIMEOUT' => $config->http_read_timeout, 'CURLOPT_AUTOREFERER' => TRUE, 'CURLOPT_FOLLOWLOCATION' => TRUE, 'CURLOPT_MAXREDIRS' => 10));
     if ($config->proxy_host) {
         $options['curl.options']['CURLOPT_HTTPPROXYTUNNEL'] = TRUE;
         $options['curl.options']['CURLOPT_PROXY'] = $config->proxy_host;
         $options['curl.options']['CURLOPT_PROXYPORT'] = $config->proxy_user . ':' . $config->proxy_pass;
     }
     if ($config->is_secure()) {
         $options['ssl.certificate_authority'] = $config->certificate_authority;
     }
     try {
         $client = new Client($config->base_url(), $options);
         $client->setDefaultHeaders(self::$default_headers);
         $client->setUserAgent($this->user_agent());
         return $client;
     } catch (Exception $e) {
         // $this->log(Logger::ERROR, '['.__CLASS__.'::setup_http_client] Failure initializing the request client. Error: [ '.$e->getCode().' ] '.$e->getMessage());
         // Rethrow the exception
         throw $e;
     }
 }
コード例 #23
0
ファイル: APIObject.php プロジェクト: nevetS/flame
 /**
  * Initializes the OrgConfig for this class.
  *
  * @param \Apigee\Util\OrgConfig $config
  * @param string $base_url
  */
 protected function init(\Apigee\Util\OrgConfig $config, $base_url)
 {
     $this->config =& $config;
     $base_url = rtrim($config->endpoint, '/') . '/' . ltrim($base_url, '/');
     $opts = array();
     if (is_array($config->http_options) && !empty($config->http_options)) {
         foreach ($config->http_options as $key => $value) {
             if (!array_key_exists('request.options', $opts) || !array_key_exists($key, $opts['request.options'])) {
                 $opts['request.options'][$key] = $value;
             }
         }
     }
     $opts['redirect.disable'] = $config->redirect_disable;
     $this->client = new \Guzzle\Http\Client($base_url, $opts);
     if (is_array($config->subscribers)) {
         foreach ($config->subscribers as $subscriber) {
             $this->client->addSubscriber($subscriber);
         }
     }
     if (!empty($config->user_agent)) {
         $this->client->setUserAgent($config->user_agent, true);
     }
     self::$logger = $config->logger;
 }
コード例 #24
0
ファイル: Application.php プロジェクト: htmldriven/cors-proxy
 /**
  * @param Config
  * @return ClientInterface
  */
 private function createClient(Config $config)
 {
     $client = new Client();
     $client->setUserAgent($config->getUserAgent());
     return $client;
 }
コード例 #25
0
 public function __construct(Client $client = null)
 {
     $this->client = $client ?: new Client();
     $this->client->setDefaultOption('headers', ['accept' => self::DEFAULT_MIME_TYPE]);
     $this->client->setUserAgent(self::DEFAULT_USER_AGENT);
 }
コード例 #26
0
ファイル: Summon.php プロジェクト: phindmarsh/summon
 public function __construct($url)
 {
     $this->url = $url;
     $this->client = new Client($this->url);
     $this->client->setUserAgent(self::USER_AGENT);
 }
コード例 #27
0
ファイル: HttpClient.php プロジェクト: alnutile/drunatra
 /**
  * Creates a new HttpClient instance
  *
  * @param Client $client
  */
 public function __construct(Client $client = null)
 {
     $this->client = $client ?: new Client();
     $this->client->setUserAgent(false);
 }
コード例 #28
0
ファイル: Call.php プロジェクト: mageni/PHPNessusNG
 /**
  * Makes an API call to a Nessus Scanner
  *
  * @param  string $methid   The method that should be used in the HTTP request
  * @param  object $scope    The scope injected from a \Nessus\Client
  * @param  bool   $no_token Should a token be used in this request
  *
  * @return string
  */
 public function call($method, $scope, $no_token = false)
 {
     // Prepare a new Guzzle and set some default options
     $client = new HttpClient($scope->url);
     $client->setUserAgent('PHPNessusNG/' . $scope->version);
     $client->setDefaultOption('verify', $scope->validate_cert);
     $client->setDefaultOption('timeout', $scope->timeout);
     // Detect if we have a proxy configured
     if ($scope->use_proxy) {
         // If we have a username or password, add it to the proxy
         // setting
         if (!is_null($scope->proxy_user) || !is_null($scope->proxy_pass)) {
             $client->setDefaultOption('proxy', 'tcp://' . $scope->proxy_user . ':' . $scope->proxy_pass . '@' . $scope->proxy_host . ':' . $scope->proxy_port);
         } else {
             $client->setDefaultOption('proxy', 'tcp://' . $scope->proxy_host . ':' . $scope->proxy_port);
         }
     }
     // Only really needed by $this->token() method. Otherwise we have
     // a cyclic dependency trying to setup a token
     $cookie_header = $no_token ? array() : array('X-Cookie' => 'token=' . $this->token($scope));
     // Methods such as PUT, DELETE and POST require us to set a body. We will
     // json encode this and set it
     if (in_array($method, array('put', 'post', 'delete'))) {
         $request = $client->{$method}($no_token ? 'session/' : $scope->call, array_merge($cookie_header, array('Accept' => 'application/json')));
         // If we have $no_token set, we assume that this is the login request
         // that we have received. So, we will override the body with the
         // username and password
         if (!$no_token) {
             $request->setBody(json_encode($scope->fields), 'application/json');
         } else {
             $request->setBody(json_encode(array('username' => $scope->username, 'password' => $scope->password)), 'application/json');
         }
     } else {
         $request = $client->{$method}($scope->call, array_merge($cookie_header, array('Accept' => 'application/json')), $scope->fields);
     }
     // Attempt the actual response that has been built thus far
     try {
         $response = $request->send();
     } catch (BadResponseException $badResponse) {
         throw Exception\FailedNessusRequest::exceptionFactory($badResponse->getMessage(), $badResponse->getRequest(), $badResponse->getResponse());
     }
     // If a endpoint is called that does not exist, give a slightly easier to
     // understand error.
     if ($response->getStatusCode() == 404) {
         throw Exception\FailedNessusRequest::exceptionFactory('Nessus responded with a 404 for ' . $scope->url . $scope->call . ' via ' . $method . '. Check your call.', $request, $response);
     }
     // Check if a non success HTTP code is received
     if (!$response->isSuccessful()) {
         throw Exception\FailedNessusRequest::exceptionFactory('Unsuccessfull Request to [' . $method . '] ' . $scope->call, $request, $response);
     }
     // If the response is requested in raw format, return it. We need
     // to be careful to not return raw to a token request too.
     if ($scope->raw && !$no_token) {
         return (string) $response->getBody();
     }
     // Check that the response is not empty. Looks like Nessus returns
     // "null" on empty response :s
     if (is_null($response->getBody()) || trim($response->getBody()) == 'null') {
         return null;
     }
     // Attempt to convert the response to a JSON Object
     $json = json_decode($response->getBody());
     // Check that the JSON turned into a valid Object or Array.
     // Sadly, some calls respond with array(object(<data>)), like /scanners
     if (!is_object($json) && (!is_array($json) && count($json) <= 0)) {
         throw Exception\FailedNessusRequest::exceptionFactory('Failed to parse response JSON. Consider the call with via(method, true).', $request, $response);
     }
     return $json;
 }
コード例 #29
0
ファイル: OAuth.php プロジェクト: bigset1/blueridge
 public function __construct(array $configs)
 {
     $this->configs = $configs;
     $this->client = new Client();
     $this->client->setUserAgent($this->configs['user_agent']);
 }
コード例 #30
0
ファイル: app.php プロジェクト: bnvk/shrewdness
use Exception;
$app = new Application();
$app->register(new UrlGeneratorServiceProvider());
$app['db'] = $app->share(function () use($app) {
    return new PDO($app['db.dsn'], $app['db.username'], $app['db.password'], $app['db.options']);
});
$app['subscriptions.storage'] = $app->share(function () use($app) {
    return new Subscriptions\PdoSubscriptionStorage($app['db'], 'shrewdness_');
});
$app['subscriptions.defaulthub'] = function () use($app) {
    return new Subscriptions\InertHub();
    #return new Subscriptions\SuperfeedrHub($app['superfeedr.username'], $app['superfeedr.password']);
};
$app['http.client'] = function () use($app) {
    $client = new Guzzle\Http\Client(null, ['ssl.certificate_authority' => __DIR__ . '/../mozilla-ca-certs.pem', 'request.options' => ['timeout' => 10, 'connect_timeout' => 2]]);
    $client->setUserAgent('Shrewdness (Guzzle) http://indiewebcamp.com/Shrewdness');
    return $client;
};
$app['encryption'] = function () use($app) {
    return new Encrypter($app['encryption.secret']);
};
$app['elasticsearch'] = $app->share(function () use($app) {
    return new Elasticsearch\Client();
});
$app['cache'] = $app->share(function () use($app) {
    return new Cache\ApcCache();
});
$app['archive'] = $app->share(function () use($app) {
    return new Taproot\Archive(__DIR__ . '/../data/archive/');
});
$app['purifier'] = function () use($app) {