forked from pointergr/api-example
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpointer_api.php
119 lines (99 loc) · 3.96 KB
/
pointer_api.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
<?php
class pointer_api {
var $login_username = 'YOUR_API_USERNAME';
var $login_password = 'YOUR_API_PASSWORD';
var $key;
function index() {
$this->login();
$this->domainCheck('pointerdemo.gr');
$this->logout();
}
function request($xml) {
$url = "https://www.pointer.gr/api";
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_HTTPHEADER, Array("Content-Type:text/xml", "testserver: 0")); // testserver 0=Normal registry, 1=test registry
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HEADER, 0);
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, $xml);
curl_setopt($curl, CURLOPT_TIMEOUT, 20);
return curl_exec($curl);
}
function login($username = null, $password = null) {
if( ! is_null($username)) {
$this->login_username = $username;
}
if( ! is_null($password)) {
$this->login_password = $password;
}
$chksum = md5($this->login_username . $this->login_password . 'login');
$xml = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>
<pointer>
<login>
<password>" . md5($this->login_password) . "</password>
</login>
<username>" . $this->login_username . "</username>
<chksum>$chksum</chksum>
</pointer>";
$result = $this->request($xml);
$xml = $this->_parseRequest($result);
$tmp = $xml->xpath('/pointer/login/key');
$this->key = (string) $tmp[0];
}
function logout() {
$chksum = md5($this->login_username . $this->login_password . 'logout' . $this->key);
$xml = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>
<pointer>
<logout>
</logout>
<key>" . $this->key . "</key>
<username>" . $this->login_username . "</username>
<chksum>" . $chksum . "</chksum>
</pointer>";
$result = $this->request($xml);
}
function domainCheck($domain, $tlds = NULL) {
$default_tlds = array(".gr", ".eu", ".com", ".net");
if (!is_array($tlds))
$tlds = array();
$tlds = array_merge($default_tlds, $tlds);
$tld_xml = '';
foreach ($tlds as $tld) {
$tld_xml .= "<tld>" . $tld . "</tld>";
}
$chksum = md5($this->login_username . $this->login_password . 'domainCheck' . $this->key);
$xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>
<pointer>
<domain-check>
<tlds>
" . $tld_xml . "
</tlds>
<domains>
<domain>" . $domain . "</domain>
</domains>
</domain-check>
<username>" . $this->login_username . "</username>
<chksum>" . $chksum . "</chksum>
</pointer>";
$result = $this->request($xml);
$xml = $this->_parseRequest($result);
$xml_result = $xml->xpath('/pointer/login/key');
$tmp = $xml->xpath('/pointer/domain-check/result/item');
$arr = array();
foreach($tmp as $tld_result) {
$arr[(string) $tld_result->domain] = (string) $tld_result->available;
}
return $arr;
}
protected function _parseRequest($request_string) {
try {
$xml = new SimpleXMLElement($request_string);
if (!is_a($xml, 'SimpleXMLElement'))
throw new Exception("Invalid request", 106);
} catch (Exception $e) {
throw new Exception("Invalid request", 106);
}
return $xml;
}
}