コード例 #1
0
ファイル: Page.php プロジェクト: wordfence/exkit
 /**
  * Retrieves the given $url and returns any capture groups in $regex for the all matches or false if not found. The 
  * structure of the returned capture groups matches preg_match_all: 
  * http://php.net/manual/en/function.preg-match-all.php with the flag PREG_SET_ORDER.
  * 
  * @param \Requests_Session $session The session to send the request from.
  * @param string $url The page URL.
  * @param string $regex The regex to use.
  * 
  * @return array|false The capture groups if found, otherwise false.
  */
 public static function findAll(\Requests_Session $session, $url, $regex)
 {
     $r = $session->get($url);
     if (preg_match_all($regex, $r->body, $matches, PREG_SET_ORDER)) {
         return $matches;
     }
     return false;
 }
コード例 #2
0
ファイル: WPAuthentication.php プロジェクト: wordfence/exkit
 public static function logInAsUser(\Requests_Session $session, $username, $password)
 {
     $loginPostData = ['log' => $username, 'pwd' => $password, 'rememberme' => 'forever', 'wp-submit' => 'Log+In'];
     $loginURL = \Wordfence\ExKit\Endpoint::loginURL();
     $r = $session->post($loginURL, [], $loginPostData);
     if ($r->url == $loginURL) {
         \Wordfence\ExKit\Cli::write('[-] Authentication failed', 'yellow', null);
         exit(\Wordfence\ExKit\ExitCodes::EXIT_CODE_FAILED_PRECONDITION);
     }
 }
コード例 #3
0
ファイル: Wikimate.php プロジェクト: hamstar/wikimate
 /**
  * Uploads a file to the wiki API.
  *
  * @param   array    $array  Array of details to be used in the upload
  * @return  array            Unserialized php output from the wiki API
  */
 public function upload($array)
 {
     $array['action'] = 'upload';
     $array['format'] = 'php';
     // Construct multipart body: https://www.mediawiki.org/wiki/API:Upload#Sample_Raw_Upload
     $boundary = '---Wikimate-' . md5(microtime());
     $body = '';
     foreach ($array as $fieldName => $fieldData) {
         $body .= "--{$boundary}\r\n";
         $body .= 'Content-Disposition: form-data; name="' . $fieldName . '"';
         // Process the (binary) file
         if ($fieldName == 'file') {
             $body .= '; filename="' . $array['filename'] . '"' . "\r\n";
             $body .= "Content-Type: application/octet-stream; charset=UTF-8\r\n";
             $body .= "Content-Transfer-Encoding: binary\r\n";
             // Process text parameters
         } else {
             $body .= "\r\n";
             $body .= "Content-Type: text/plain; charset=UTF-8\r\n";
             $body .= "Content-Transfer-Encoding: 8bit\r\n";
         }
         $body .= "\r\n{$fieldData}\r\n";
     }
     $body .= "--{$boundary}--\r\n";
     // Construct multipart headers
     $headers = array('Content-Type' => "multipart/form-data; boundary={$boundary}", 'Content-Length' => strlen($body));
     $apiResult = $this->session->post($this->api, $headers, $body);
     return unserialize($apiResult->body);
 }
コード例 #4
0
ファイル: Session.php プロジェクト: VShangxiao/Requests
 public function testSharedCookies()
 {
     $session = new Requests_Session(httpbin('/'));
     $options = array('follow_redirects' => false);
     $response = $session->get('/cookies/set?requests-testcookie=testvalue', array(), $options);
     $this->assertEquals(302, $response->status_code);
     // Check the cookies
     $response = $session->get('/cookies');
     $this->assertTrue($response->success);
     // Check the response
     $data = json_decode($response->body, true);
     $this->assertNotNull($data);
     $this->assertArrayHasKey('cookies', $data);
     $cookies = array('requests-testcookie' => 'testvalue');
     $this->assertEquals($cookies, $data['cookies']);
 }
コード例 #5
0
ファイル: Wikimate.php プロジェクト: iurnah/Wikimate
 /**
  * Perfoms a delete query to the wiki api
  * @param array $array array of details to be passed in the query
  * @return array unserialized php output from the wiki
  */
 public function delete($array)
 {
     $headers = array('Content-Type' => "application/x-www-form-urlencoded");
     $array['action'] = 'delete';
     $array['format'] = 'php';
     $apiResult = $this->session->post($this->api, $headers, $array);
     return unserialize($apiResult);
 }
コード例 #6
0
 /**
  *  Retrieve an array of information about the current
  *  user from the MyEMSL user API
  *
  *  @method get_user_info
  *
  *  @return array
  *
  *  @author Ken Auberry <*****@*****.**>
  */
 function get_user_info()
 {
     // $protocol = isset($_SERVER["HTTPS"]) && $_SERVER["HTTPS"] == "on" ? "https" : "http";
     $protocol = "http";
     $basedir = 'myemsl';
     // $url_base =  dirname(dirname($this->myemsl_ini['getuser']['prefix']));
     $url_base = "{$protocol}://localhost";
     $options = array('verify' => FALSE, 'timeout' => 60, 'connect_timeout' => 30);
     $headers = array();
     foreach ($_COOKIE as $cookie_name => $cookie_value) {
         $headers[] = "{$cookie_name}={$cookie_value}";
     }
     $headers = array('Cookie' => implode(';', $headers));
     $session = new Requests_Session($url_base, $headers, array(), $options);
     try {
         $response = $session->get('/myemsl/userinfo');
         $user_info = json_decode($response->body, TRUE);
     } catch (Exception $e) {
         $user_info = array('error' => 'Unable to retrieve User Information');
         return $user_info;
     }
     $DB_myemsl = $this->load->database('default', TRUE);
     // go retrieve the instrument/group lookup table
     $DB_myemsl->like('type', 'Instrument.')->or_like('type', 'omics.dms.instrument');
     $query = $DB_myemsl->get('groups');
     $inst_group_lookup = array();
     if ($query && $query->num_rows() > 0) {
         foreach ($query->result() as $row) {
             if ($row->type == 'omics.dms.instrument') {
                 $inst_id = intval($row->group_id);
             } else {
                 if (strpos($row->type, 'Instrument.') >= 0) {
                     $inst_id = intval(str_replace('Instrument.', '', $row->type));
                 } else {
                     continue;
                 }
             }
             $inst_group_lookup[$inst_id]['groups'][] = intval($row->group_id);
         }
     }
     $new_instruments_list = array();
     foreach ($user_info['instruments'] as $eus_instrument_id => $inst_info) {
         $new_instruments_list[$eus_instrument_id] = $inst_info;
         if (array_key_exists($eus_instrument_id, $inst_group_lookup)) {
             $new_instruments_list[$eus_instrument_id]['groups'] = $inst_group_lookup[$eus_instrument_id]['groups'];
         } else {
             $new_instruments_list[$eus_instrument_id]['groups'] = array();
         }
     }
     $user_info['instruments'] = $new_instruments_list;
     return $user_info;
 }
コード例 #7
0
ファイル: Auth.php プロジェクト: akmetainfo/vkApi
 /**
  * Разрешаем доступ приложению
  *
  * @param $url
  * @return \Requests_Response
  */
 private function post_confirm($url)
 {
     $v = explode('?', $url);
     return $this->session->post('?' . $v[1]);
 }
コード例 #8
0
ファイル: session.php プロジェクト: jonasvr/lockedornot
<?php

// First, include Requests
include '../library/Requests.php';
// Next, make sure Requests can load internal classes
Requests::register_autoloader();
// Set up our session
$session = new Requests_Session('http://httpbin.org/');
$session->headers['Accept'] = 'application/json';
$session->useragent = 'Awesomesauce';
// Now let's make a request!
$request = $session->get('/get');
// Check what we received
var_dump($request);
// Let's check our user agent!
$request = $session->get('/user-agent');
// And check again
var_dump($request);
コード例 #9
0
ファイル: geoip_update.php プロジェクト: thctlo/1.2.0
 $files['ipv6']['description'] = 'GeoIP IPv6 data file';
 $files['ipv6']['path'] = '/download/geoip/database/GeoIPv6.dat.gz';
 $files['ipv6']['destination'] = __DIR__ . '/temp/GeoIPv6.dat.gz';
 $extract_dir = __DIR__ . '/temp/';
 // Clean-up from last run
 foreach ($files as $file) {
     if (file_exists($file['destination'])) {
         unlink($file['destination']);
     }
 }
 ob_flush();
 flush();
 if (!file_exists($files['ipv4']['destination']) && !file_exists($files['ipv6']['destination'])) {
     if (is_writable($extract_dir) && is_readable($extract_dir)) {
         if (function_exists('fsockopen') || extension_loaded('curl')) {
             $requestSession = new Requests_Session($files_base_url . '/');
             $requestSession->useragent = 'MailWatch/' . str_replace(array(' - ', ' '), array('-', '-'), mailwatch_version());
             if (USE_PROXY === true) {
                 if (PROXY_USER != '') {
                     $requestSession->options['proxy']['authentication'] = array(PROXY_SERVER . ':' . PROXY_PORT, PROXY_USER, PROXY_PASS);
                 } else {
                     $requestSession->options['proxy']['authentication'] = array(PROXY_SERVER . ':' . PROXY_PORT);
                 }
                 switch (PROXY_TYPE) {
                     case 'HTTP':
                     case 'CURLPROXY_HTTP':
                         //BC for old constant name
                         //$requestProxy = new Requests_Proxy_HTTP($requestProxyParams);
                         $requestSession->options['proxy']['type'] = 'HTTP';
                         break;
                     case 'SOCKS5':