Exemplo n.º 1
0
 private static function _execute($url, $method, $post = null)
 {
     $data = parse_url($url);
     if (isset($data['user']) || isset($data['pass'])) {
         // TODO: not yet implemented
         return false;
     }
     if (isset($data['query'])) {
         $data['fullpath'] = $data['path'] . '?' . $data['query'];
     } else {
         $data['fullpath'] = $data['path'];
     }
     switch ($data['scheme']) {
         case 'http':
             $HTTP = new HTTP($data['host'], isset($data['port']) ? $data['port'] : 80);
             break;
         case 'https':
             $HTTP = new HTTP($data['host'], isset($data['port']) ? $data['port'] : 443, true);
             break;
         default:
             return false;
             break;
     }
     switch ($method) {
         case 'GET':
             return $HTTP->GET($data['fullpath']);
             break;
         case 'POST':
             return $HTTP->POST($data['fullpath'], $post);
             break;
         default:
             return false;
             break;
     }
 }
Exemplo n.º 2
0
function _xUpdateGetInstaller()
{
    global $C;
    $post_data = array('upgrade' => true, 'version' => $_REQUEST['version'], 'key' => LIC_KEY, 'domain' => domain_from_url($C['base_url']));
    require_once 'http.php';
    $http = new HTTP();
    if ($http->POST(URL_DOWNLOAD, $post_data)) {
        if (preg_match('~X-SHA1: ([a-z0-9]+)~i', $http->response_headers, $matches)) {
            $installer_file = DIR_DATA . '/install.dat';
            $sha1 = $matches[1];
            file_write($installer_file, $http->body);
            if ($sha1 != sha1_file($installer_file)) {
                file_delete($installer_file);
                JSON::Error('File hash does not match, possible corrupted data.  Please try again.');
            } else {
                JSON::Success();
            }
        } else {
            if (preg_match('~X-Error: ([a-z0-9_]+)~i', $http->response_headers, $matches)) {
                JSON::Error('Unable to locate a license for this domain');
            } else {
                JSON::Error('Download from jmbsoft.com failed, please try again');
            }
        }
    } else {
        JSON::Error('Unable to connect to jmbsoft.com for update: ' + $http->error);
    }
}
Exemplo n.º 3
0
 function Execute()
 {
     require_once 'http.php';
     $http = new HTTP();
     if ($http->POST($this->url, $this->post_data)) {
         if (strpos($http->body, NETWORK_SUCCESS) === 0) {
             return substr($http->body, strlen(NETWORK_SUCCESS));
         } else {
             $this->error = substr(strip_tags($http->body), 0, 100);
             return false;
         }
     } else {
         $this->error = $http->error;
         return false;
     }
 }
Exemplo n.º 4
0
 private function getW3Challs($count)
 {
     $HTTP = new HTTP('w3challs.com');
     $html = $HTTP->GET('/');
     if (!$html) {
         return false;
     }
     if (!preg_match('#<input type="hidden" name="member_token" value="(.+?)" />#', $html, $arr)) {
         return false;
     }
     $token = $arr[1];
     $html = $HTTP->POST('/profile/awe', array('changeLanguage' => 'fr', 'member_token' => $token));
     if (!$html) {
         return false;
     }
     preg_match_all('#<a href="/challenges/challenge(\\d+?)".+?title="(.+?), by (.+?) \\(Points: (\\d+?);#', $html, $arr);
     $challs = array();
     for ($i = 0; $i < sizeof($arr[1]); $i++) {
         $challs[] = array('id' => $arr[1][$i], 'name' => $arr[2][$i], 'author' => $arr[3][$i], 'points' => $arr[4][$i]);
     }
     usort($challs, array('self', 'sortByID'));
     $texts = array();
     for ($i = 0; $i < $count; $i++) {
         $texts[] = sprintf("%s by %s worth %d points ( %s )", $challs[$i]['name'], $challs[$i]['author'], $challs[$i]['points'], 'http://w3challs.com/challenges/challenge' . $challs[$i]['id']);
     }
     return $texts;
 }
Exemplo n.º 5
0
 private function checkMD5Decrypt($hash)
 {
     $HTTP = new HTTP('www.md5decrypt.org');
     $html = $HTTP->GET('/');
     if ($html === false) {
         return false;
     }
     if (!preg_match('/<script>document.cookie=\'(.+?)=(.+?)\';/', $html, $arr)) {
         return false;
     }
     $HTTP->setCookie($arr[1], $arr[2]);
     $res = $HTTP->POST('/index/process', array('value' => base64_encode($hash), 'operation' => 'MD5D'));
     if ($res === false) {
         return false;
     }
     $json = json_decode($res);
     if (!$json) {
         return false;
     }
     if (!empty($json->error)) {
         return false;
     }
     return $json->body;
 }
Exemplo n.º 6
0
 public function request_result($data)
 {
     if ($data["url"][0] != "/") {
         return false;
     }
     if ($_SERVER["HTTPS"] == "on") {
         $http = new HTTPS($_SERVER["HTTP_HOST"]);
     } else {
         $http = new HTTP($_SERVER["HTTP_HOST"]);
     }
     /* Determine URL path
      */
     $url = $data["url"];
     if (strpos($url, "?") === false) {
         $url .= "?";
     } else {
         $url .= "&";
     }
     $url .= "output=";
     switch ($data["type"]) {
         case "ajax":
             $url .= "ajax";
             break;
         case "xml":
             $url .= "restxml";
             break;
         case "json":
             $url .= "restjson";
             break;
         default:
             return false;
     }
     /* Restore cookies
      */
     if (isset($_SESSION["apitest_cookies"])) {
         if (($cookies = json_decode($_SESSION["apitest_cookies"], true)) !== null) {
             foreach ($cookies as $key => $value) {
                 $http->add_cookie($key, $value);
             }
         }
     }
     /* Authentication
      */
     if ($data["username"] != "" && $data["password"] != "") {
         $auth_str = sprintf("%s:%s", $data["username"], $data["password"]);
         $http->add_header("Authorization", "Basic " . base64_encode($auth_str));
     }
     /* Send request
      */
     switch ($data["method"]) {
         case "GET":
             $result = $http->GET($url);
             break;
         case "POST":
             $result = $http->POST($url, $data["postdata"]);
             break;
         case "PUT":
             $result = $http->PUT($url, $data["postdata"]);
             break;
         case "DELETE":
             $result = $http->DELETE($url);
             break;
         default:
             return false;
     }
     /* Decode JSON result
      */
     if ($result["headers"]["content-type"] == "application/json") {
         $result["body"] = $this->indent_json($result["body"]);
     }
     /* Store cookies
      */
     $_SESSION["apitest_cookies"] = json_encode($http->cookies);
     return $result;
 }