<?php //sends HTTP request using CURL function query_host($conn_server, $params = "", $get_header = false) { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $conn_server.$params); if (preg_match("/^https:\/\//i", $conn_server)) { curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); } curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); if ($get_header) { curl_setopt($ch, CURLOPT_HEADER, 1); } else { curl_setopt($ch, CURLOPT_HEADER, 0); } $result = curl_exec($ch); if (curl_errno($ch)) { print "curl error"; } else { curl_close($ch); } return $result; } //builds query, sends request and gets the answer back function execute_request($request, $params, &$sessid) { //build the query $http_query = "/request/" . $request . "?" . $params ."&auth-sid=".$sessid."&client-ip=".$_SERVER["REMOTE_ADDR"]; //send the request $raw_res = query_host("https://dmapi.joker.com", $http_query, true); $temp_arr = @explode("\r\n\r\n", $raw_res, 2); //split the response for further processing if (is_array($temp_arr) && 2 == count($temp_arr)) { return $temp_arr[1]; } else { return false; } } //basic parsing of the DMAPI header function parse_response_header($header) { $raw_arr = explode("\n", trim($header)); $result = array(); if (is_array($raw_arr)) { foreach ($raw_arr as $key => $value) { $keyval = array(); if (preg_match("/^([^\s]+):\s+(.+)\s*$/", $value, $keyval)) { $arr[strtolower($keyval[1])] = $keyval[2]; } else { print "Header line not parseable - pattern does not match\nRaw header:\n$value"; } } } else { $arr = ""; print "Unidentified error\nRaw header:\n$header"; } return $arr; } //parses the reply from DMAPI into a header and body function parse_response($res) { $raw_arr = explode("\n\n", trim($res)); $arr_elements = count($raw_arr); if ($arr_elements > 0) { $temp["response_header"] = parse_response_header($raw_arr["0"]); $temp["response_body"] = $raw_arr["1"]; } else { print "Couldn't split the response into response header and response body\nRaw result:\n$res"; $temp = ""; } return $temp; } $response = ""; $authid = "none"; //first obtaining an Auth-ID $username = "<your username here>"; $password = "<your password here>"; $fields = "username=".urlencode($username)."&password=".urlencode($password); $result = execute_request("login", $fields, $authid); $result = parse_response($result); $authid = $result["response_header"]["auth-sid"]; if (!$authid) { print "no auth-id was obtained - probably due to wrong username or password"; exit; } //now asking for the domain list $pattern = "*"; $fields = "pattern=".urlencode($pattern); $result = execute_request("query-domain-list", $fields, $authid); $result = parse_response($result); print_r($result["response_header"]); print "< br /> "; print_r($result["response_body"]);