function http($method = "GET", $url, $argArray = null)
{
    require_once "HTTP/Client.php";
    $agent = new HTTP_Client();
    if ($method == "POST") {
        $code = $agent->post($url, $argArray);
    } else {
        if ($argArray) {
            // build query string from $argArray
            if (strpos("?", $url)) {
                $query = "&";
            } else {
                $query = "?";
            }
            $url .= $query . http_build_query($argArray);
        }
        $code = $agent->get($url);
    }
    if (PEAR::isError($code)) {
        $error = $code->getMessage();
        Logger::log(basename(__FILE__) . " {$method} {$url} failed: {$error}");
        return false;
    } else {
        $responseArray = $agent->currentResponse();
        return $responseArray['body'];
    }
}
Esempio n. 2
0
 public function get_attendees($event_id)
 {
     $url = "http://www.eventbrite.com/myattendeestext/" . $event_id . "/attendees-" . $event_id . ".txt?sortby=&show=gross,type,status,prefix,last_name,first_name,email,job_title,company,work,work_phone,survey,actions&filterby=all,attending,all,all";
     $client = new HTTP_Client();
     // log in
     $ret = $client->post("http://www.eventbrite.com/signin", array("submitted" => "1", "referrer" => "", "email" => $this->email, "passwd" => $this->password, "remember_me" => "0"));
     $response = $client->currentResponse();
     //	var_dump($client->currentResponse());
     $dom = new DOMDocument();
     @$dom->loadHTML($response['body']);
     $xp = new DOMXPath($dom);
     //	echo "----------- generated xml ----------------\n";
     //	echo $dom->saveXML();
     $errors = $xp->query("//div[@id='error']");
     if ($errors->length) {
         // an error occurred - most likely
         $error_text = trim($xp->query("text()", $errors->item(0))->item(0)->nodeValue);
         throw new PAException(USER_NOT_FOUND, "Error from EventBrite: " . $error_text);
     }
     // now fetch the attendee list CSV
     $ret = $client->get($url);
     $response = $client->currentResponse();
     $mime_type = $response['headers']['content-type'];
     if ($mime_type != 'text/plain') {
         throw new PAException(GENERAL_SOME_ERROR, "Invalid MIME type received from EventBrite (expected text/plain, received {$mime_type})");
     }
     return $this->parse_attendee_list($response['body']);
 }
 function testSpamTrapPerformance()
 {
     global $base_url;
     while (@ob_end_clean()) {
     }
     $c = new HTTP_Client();
     echo "Hitting some pages to test how the system performs when hit by spambots\n";
     echo "Spidering content ...\n";
     list($dom, $xp) = $this->get_and_parse("{$base_url}/homepage.php");
     $content = array();
     foreach ($xp->query("//a/@href") as $node) {
         if (preg_match("|/content.php\\?|", $node->value)) {
             $content[$node->value] = true;
         }
     }
     $n_retrieved = 0;
     $total_time = 0.0;
     foreach ($content as $url => $foo) {
         echo "Content page to retrieve: {$url}\n";
         list(, , $t_taken) = $this->get_and_parse($url);
         ++$n_retrieved;
         $total_time += $t_taken;
         if ($n_retrieved >= 3) {
             break;
         }
     }
     echo sprintf("avg time per download: %.1f s\n", $total_time / $n_retrieved);
     echo "Posting spam...\n";
     echo "Testing that we can't post comments without being logged in...\n";
     foreach ($content as $url => $foo) {
         echo "Posting anonymous comment to {$url}\n";
         if (!preg_match("/cid=(\\d+)/", $url, $m)) {
             echo "error determining cid from {$url}\n";
             continue;
         }
         $cid = $m[1];
         $c = new HTTP_Client();
         $c->setMaxRedirects(0);
         $ret = $c->post($url, array("addcomment" => "Submit Comment", "name" => "automatic test robot", "email" => "*****@*****.**", "homepage" => "http://peopleaggregator.net/", "cid" => $cid, "ccid" => ""));
         var_dump($c);
         $this->assertEquals($c->_responses[0]['code'], 302);
         break;
     }
     echo "Posting personal messages...\n";
 }
Esempio n. 4
0
 public function get_and_parse($url, $c = NULL, $method = "GET", $data = NULL)
 {
     if (empty($c)) {
         $c = new HTTP_Client();
     }
     $t_start = microtime(TRUE);
     switch ($method) {
         case "POST":
             //      $c->setDefaultHeader("Content-Type", "application/x-www-form-urlencoded");
             $code = $c->post($url, $data);
             break;
         default:
             $code = $c->get($url);
             break;
     }
     $t_retrieved = microtime(TRUE);
     $this->assertEquals(200, $code, "Error {$code} retrieving {$url}");
     $resp = $c->currentResponse();
     list($dom, $xp) = Test::parse_html($resp['body']);
     $t_finish = microtime(TRUE);
     echo sprintf("Downloaded %s in %.1f s\n", $url, $t_retrieved - $t_start);
     return array($dom, $xp, $t_retrieved - $t_start, $c);
 }
Esempio n. 5
0
 /**
  * Get user information from pear.php.net
  *
  * This function uses the given username and password to authenticate
  * against the pear.php.net website
  *
  * @param string    Username
  * @param string    Password
  * @return mixed    Error object or boolean
  */
 function fetchData($username, $password)
 {
     $this->log('Auth_Container_PEAR::fetchData() called.', AUTH_LOG_DEBUG);
     $client = new HTTP_Client();
     $this->log('Auth_Container_PEAR::fetchData() getting salt.', AUTH_LOG_DEBUG);
     $code = $client->get('https://pear.php.net/rest-login.php/getsalt');
     if ($code != 200) {
         return PEAR::raiseError('Bad response to salt request.', $code);
     }
     $resp = $client->currentResponse();
     $salt = $resp['body'];
     $this->log('Auth_Container_PEAR::fetchData() calling validate.', AUTH_LOG_DEBUG);
     $code = $client->post('https://pear.php.net/rest-login.php/validate', array('username' => $username, 'password' => md5($salt . md5($password))));
     if ($code != 200) {
         return PEAR::raiseError('Bad response to validate request.', $code);
     }
     $resp = $client->currentResponse();
     list($code, $message) = explode(' ', $resp['body'], 1);
     if ($code != 8) {
         return PEAR::raiseError($message, $code);
     }
     return true;
 }
 public function _request($site, $func_name, $request_method, $data, $auth = FALSE)
 {
     $headers = array("User-Agent" => "PeopleAggregator/" . PA_VERSION);
     global $fortythree_api_key;
     $data['api_key'] = $fortythree_api_key;
     if ($auth) {
         switch ($this->pw_type) {
             case 'raw':
                 $data['username'] = $this->login;
                 $data['password'] = $this->password;
                 break;
             case 'wsse':
                 $headers['Authorization'] = 'WSSE profile="UsernameToken"';
                 $headers['X-WSSE'] = $this->_make_wsse($this->login, $this->password);
                 var_dump($headers);
                 break;
             default:
                 throw new PAException(0, "Invalid password type {$this->pw_type}");
         }
     }
     $url = "http://www.{$site}.com/service/{$func_name}";
     $c = new HTTP_Client(null, $headers);
     switch ($request_method) {
         case 'GET':
             $ret = $c->get($url, $data);
             break;
         case 'POST':
             $preEncoded = gettype($data) == "string";
             $ret = $c->post($url, $data, $preEncoded);
             break;
         default:
             throw new PAException("invalid request method: {$request_method}");
     }
     $r = $c->currentResponse();
     echo "did http request to {$url} with data ";
     var_dump($data);
     echo ", returned {$ret}.<br>";
     $xml = $r["body"];
     echo "xml = <pre>" . htmlspecialchars($xml) . "</pre><hr>";
     $dom = DomDocument::loadXML($xml);
     $xp = new DOMXPath($dom);
     $xp->registerNamespace("dc", "http://purl.org/dc/elements/1.1/");
     $xp->registerNamespace("th", "http://43things.com/xml/2005/rc#");
     $xp->registerNamespace("pl", "http://43places.com/xml/2005/rc#");
     $xp->registerNamespace("pe", "http://43people.com/xml/2005/rc#");
     return array("xml" => $xml, "dom" => $dom, "xpath" => $xp);
 }
 private function _request($url, $xml)
 {
     $headers = array("Accept" => "application/xml", "Content-Type" => "application/xml");
     $c = new HTTP_Client(null, $headers);
     $c->setRequestParameter(array("user" => $this->login, "pass" => $this->password));
     $ret = $c->post($url, $xml, TRUE);
     switch ($ret) {
         case 200:
             // ok
             break;
         case 401:
             throw new PAException(USER_INVALID_PASSWORD, "Login incorrect");
         case 403:
             throw new PAException(USER_ACCESS_DENIED, "Access denied");
         default:
             throw new PAException(GENERAL_SOME_ERROR, "BaseCamp API returned HTTP error code {$ret}");
     }
     $r = $c->currentResponse();
     //        echo "did http request to $url with data "; var_dump($xml); echo ", returned $ret.<br>";
     $xmlret = $r["body"];
     //        echo "xml response: <pre>".htmlspecialchars($xmlret)."</pre>";
     return simplexml_load_string($xmlret);
 }
Esempio n. 8
0
}
$prefix = $template[0];
$suffix = $template[1];
// Match the recipient address to the address template
if (!isset($_ENV["RECIPIENT"])) {
    error_log("Recipient address not set, unable to get bounce token");
    exit(1);
}
$recipient = $_ENV["RECIPIENT"];
$token_length = strlen($recipient) - strlen($prefix) - strlen($suffix);
if ($token_length <= 0 || substr($recipient, 0, strlen($prefix)) != $prefix || substr($recipient, strlen($prefix) + $token_length) != $suffix) {
    error_log("Recipient address does not match address template: {$recipient}");
    exit(1);
}
$token = substr($recipient, strlen($prefix), $token_length);
// Log the bounce to the configured bounce logger
if (substr($BOUNCE_LOGGER, 0, strlen("file://")) == "file://") {
    $fh = fopen(substr($BOUNCE_LOGGER, strlen("file://")), "w+");
    if ($fh) {
        fwrite($fh, "{$token}\n");
        fclose($fh);
        exit(0);
    }
} elseif (substr($BOUNCE_LOGGER, 0, strlen("http://")) == "http://" || substr($BOUNCE_LOGGER, 0, strlen("https://")) == "https://") {
    /** @ ignore */
    $client = new HTTP_Client();
    $client->post($BOUNCE_LOGGER, array("token" => $token));
    exit(0);
}
error_log("Error logging bounce token: {$BOUNCE_LOGGER}");
exit(1);
Esempio n. 9
0
function officeautopilot_addContact($info, $tag, $api_key, $api_id)
{
    require_once 'HTTP_Client-1.2.1/Client.php';
    $httpc = new HTTP_Client();
    $first_name = $info['first_name'];
    $last_name = $info['last_name'];
    $email = $info['email'];
    $tagsXml = '<field name="Contact Tags">*/*' . $tag . '*/*</field>';
    $xml = '<contact>
    <Group_Tag name="Contact Information">
        <field name="First Name">' . utf8_encode($first_name) . '</field>
        <field name="Last Name">' . utf8_encode($last_name) . '</field>
        <field name="E-Mail">' . $email . '</field>
    </Group_Tag>
    <Group_Tag name="Sequences and Tags">
        ' . $tagsXml . '
    </Group_Tag>
</contact>';
    $postContact = array('Appid' => $api_id, 'Key' => $api_key, 'reqType' => 'add', 'data' => $xml);
    try {
        $httpc->post('http://api.moon-ray.com/cdata.php', $postContact);
        $response = $httpc->currentResponse();
        return true;
    } catch (Exception $e) {
        return false;
    }
    return true;
}
 private function sendPlaxoCmd($argArray = null)
 {
     if ($this->debug) {
         echo '<pre>';
         echo print_r($argArray, 1);
         echo '</pre>';
     }
     $url = PLAXO_SERVICE_URL;
     $agent = new HTTP_Client();
     $code = $agent->post($url, $argArray, true);
     if (PEAR::isError($code)) {
         $error = $code->getMessage();
         Logger::log(basename(__FILE__) . " {$method} {$url} failed: {$error}");
         return false;
     } else {
         $responseArray = $agent->currentResponse();
         return $responseArray['body'];
     }
 }
Esempio n. 11
0
 /**
  * HTTP_Client::post() のラッパーメソッド
  *
  * @param string $uri
  * @param mixed $data
  * @param bool $preEncoded
  * @param array $files
  * @param array $headers
  * @return array HTTPレスポンス
  * @throws P2Exception
  */
 protected function httpPost($uri, $data, $preEncoded = false, $files = array(), $headers = array())
 {
     $code = $this->_httpClient->post($uri, $data, $preEncoded, $files, $headers);
     P2Exception::pearErrorToP2Exception($code);
     if ($code != 200) {
         throw new P2Exception('HTTP ' . $code);
     }
     return $this->_httpClient->currentResponse();
 }
Esempio n. 12
0
 /**
  * Get user information from pear.php.net
  *
  * This function uses the given username and password to authenticate
  * against the pear.php.net website
  *
  * @param string    Username
  * @param string    Password
  * @return mixed    Error object or boolean
  */
 function fetchData($username, $password)
 {
     $this->log('Auth_Container_PEAR::fetchData() called.', AUTH_LOG_DEBUG);
     $client = new HTTP_Client();
     $this->log('Auth_Container_PEAR::fetchData() getting salt.', AUTH_LOG_DEBUG);
     $code = $client->get($this->url . '/getsalt');
     if ($code instanceof PEAR_Error) {
         return $code;
     }
     if ($code != 200) {
         return PEAR::raiseError('Bad response to salt request.', $code);
     }
     $resp = $client->currentResponse();
     $salt = $resp['body'];
     $this->log('Auth_Container_PEAR::fetchData() calling validate.', AUTH_LOG_DEBUG);
     $postOptions = array('username' => $username, 'password' => md5($salt . md5($password)));
     if (is_array($this->karma) && count($this->karma) > 0) {
         $postOptions['karma'] = implode(',', $this->karma);
     }
     $code = $client->post($this->url . '/validate', $postOptions);
     if ($code instanceof PEAR_Error) {
         return $code;
     }
     if ($code != 200) {
         return PEAR::raiseError('Bad response to validate request.', $code);
     }
     $resp = $client->currentResponse();
     list($code, $message) = explode(' ', $resp['body'], 2);
     if ($code != 8) {
         return PEAR::raiseError($message, $code);
     }
     return true;
 }
Esempio n. 13
0
    /**
     * Send the error details to the server via HTTP.
     * @return void
     */
    public function sendToServer()
    {
        $client = new HTTP_Client();
        $code = $client->post
            ($this->m_newReport, array('f_software' => $this->m_software,
                                       'f_version' => $this->m_version,
                                       'f_num' => $this->m_num,
                                       'f_str' => $this->m_str,
                                       'f_line' => $this->m_line,
                                       'f_id' => $this->getId(),
                                       'f_backtrace' => $this->getBacktraceString(),
                                       'f_time' => $this->getTime(),
                                       'f_description' => $this->getDescription(),
                                       'f_email' => $this->getEmail(),
                                       '__FORM_TOKEN' => $this->getFormToken($client),
                                    ));

        $response = $client->currentResponse();
        $this->__responseHeader = $response['headers'];
        $this->__responseBody = $response['body'];
        $this->__responseCode = $code;

        if ($code != 200) {
        	return false;
        } elseif (preg_match ("/\baccepted\b/", $this->__responseBody)) {
        	// --- Did we get an "accepted"?
        	return true;
        } else {
        	return false;
        }
    } // fn sendToServer
Esempio n. 14
0
/**
 *
 * auto_post.php
 *
 * @package    core
 * @author     John.meng <*****@*****.**>
 * @author     цот╤РШ
 * @author     QQ:3440895
 * @version    CVS: $Id: auto_post.php,v 1.1 2006/10/25 08:55:54 arzen Exp $
 */
set_time_limit(0);
define('APF_ROOT_DIR', realpath(dirname(__FILE__) . '/../..'));
require_once APF_ROOT_DIR . DIRECTORY_SEPARATOR . 'init.php';
require_once 'HTTP/Client.php';
$fields = array('handle' => 'admin', 'passwd' => 'admin', 'category' => '1', 'name' => 'product' . mt_rand(5000, 99999), 'price' => '5.23');
// uploade file
$files = array();
$files[] = array('name' => 'photo', 'filename' => 'C:/Documents and Settings/john.meng/My Documents/My Pictures/001004183175_tb.jpg');
$search_action = 'http://localhost/dev/AutoPhpFramework/web/backend.php/product/apf_product/addsubmit';
$headers = array('User-Agent' => 'Mozilla/4.0 (compatible; MSIE 6.0)', 'Accept-Language' => 'zh-cn');
$h = new HTTP_Client(NULL, $headers);
$code = $h->post($search_action, $fields, false, $files);
//false,$files
if ($code == 200) {
    $resp = $h->currentResponse();
    $body = $resp['body'];
    echo $body;
} else {
    echo "fetch the result error.";
}
Esempio n. 15
0
//Open stdin by hand
$stdin = fopen('php://stdin', 'r');
if (!$stdin) {
    error_log("Cannot open stdin");
    exit(1);
}
//Get the message source from it
$message_source = '';
while (!feof($stdin)) {
    $message_source .= fread($stdin, 4096);
}
fclose($stdin);
//Sanity check
if (empty($message_source)) {
    error_log('Got empty message, aborting');
    exit(1);
}
//Post to target
$client = new HTTP_Client();
$stat = $client->post($POST_TO, array('message_source' => $message_source));
$response = $client->currentResponse();
//If anything at all goes wrong dump debug data and exit with errorcode
if ($stat != 200 || $response['code'] != 200 || stristr($response['body'], 'error')) {
    ob_start();
    print_r($response);
    $response_str = ob_get_contents();
    ob_end_clean();
    error_log("Error posting message to: {$POST_TO} ({$stat}), dumping response data:\n===\n{$response_str}===\n");
    exit(1);
}
exit(0);
Esempio n. 16
0
}
// Domain control
if ($domains) {
    $found = false;
    foreach ($domains as $domain) {
        if (strpos($link, $domain) !== false) {
            $found = true;
        }
    }
    if (!$found) {
        error_log("Forbidden redirect: {$link}");
        header("Status: 403 Forbidden");
        exit(0);
    }
}
// Send the redirect
header("Location: {$link}");
// Log the link to the configured link logger
if (substr($logger, 0, strlen("file://")) == "file://") {
    $fh = fopen(substr($logger, strlen("file://")), "w+");
    if ($fh) {
        fwrite($fh, "{$token} {$link}\n");
        fclose($fh);
    }
} elseif (substr($logger, 0, strlen("http://")) == "http://" || substr($logger, 0, strlen("https://")) == "https://") {
    $client = new HTTP_Client();
    $client->post($logger, array("token" => $token, "link" => $link));
} else {
    error_log("link detected: {$token} {$link}");
}
exit(0);