<?php
/*
DNR.KZ DOMAIN REGISTRATION APPLICATION PROGRAMMING INTERFACE CALLS EXAMPLES
THIS FILE IS PROVIDED FOR DEMONSTRATION USE ONLY WITHOUT ANY WARRANTY, EXPLICIT OR
IMPLIED. SKILLTEX IS NOT RESPONSIBLE OF ANY CONSEQUENCES THAT FOLLOW USAGE OF THIS
FILE.
MAINTAINER: SERGEY SHEVCHENKO <S.SHEVCHENKO@SKILLTEX.KZ>
*/
//CONSTANTS REQUIRED FOR AUTHENTICATION
define("DNRAPI2_URL","https://www.dnr.kz/api/"); //REQUIRED
define("DNRAPI2_USER","MYDNRLOGIN"); //REQUIRED
define("DNRAPI2_PASS","myDnRpAssW0rd"); //REQUIRED
//BEGIN REMOVABLE BLOCK
//FOLLOWING CODE UNTIL 'END REMOVABLE BLOCK' CAN BE REMOVED FOR PRODUCTION use
//THIS CODE IS FOR DEMONSTRATION ONLY
$commonns = array('ns4.skilltex.kz','ns3.skilltex.kz');
$commonContact = array(
'name'=>'Ivanov Ivan Ivanovich',
'org'=>'Roga i kopyta',
'sp'=>'Abu-dabi',
'cc'=>'EU',
'city'=>'Almaty',
'street'=>'34 Zelenuh pochatkov str',
'voice'=>'+7.63444278433',
'fax'=>'+7.434565345345',
'email'=>'null@dnr.kz',
);
echo "\n".__LINE__."\n";
print_r( api2List());
echo "\n".__LINE__."\n";
print_r( api2Check(array('foo.kz','bar.kz','skilltex.kz','sdsdsdsdsde4444.kz','nic.kz')) );
echo "\n".__LINE__."\n";
$dname = rand(0,1000).'delete-me-now.kz';
$hname = 'foo.'.$dname;
$hip = '1.2.3.4';
print_r( api2Create( $dname, 1, $commonContact, $commonns)); //Create domain
echo "\n".__LINE__."\n";
print_r( api2Info($dname));
echo "\n".__LINE__."\n";
print_r( api2HostInfo($hname));
echo "\n".__LINE__."\n";
print_r( api2HostCreate($hname,array('1.1.2.3')));
echo "\n".__LINE__."\n";
print_r( api2HostInfo($hname));
echo "\n".__LINE__."\n";
print_r( api2HostUpdate($hname,array('1.2.3.4','2.3.4.5')));
echo "\n".__LINE__."\n";
print_r( api2HostInfo($hname));
echo "\n".__LINE__."\n";
print_r( api2Delete($dname)); //remove this domain
echo "\n".__LINE__."\n";
//END REMOVABLE BLOCK
//DO NOT EDIT BELOW THIS LINE
function api2HostInfo($host){
return api2Call('infoHost', array('object'=>$host) );
}
function api2HostCreate($host,$iplist){
return api2Call('createHost', array('object'=>$host, 'addrs' => $iplist) );
}
function api2HostUpdate($host,$iplist){
return api2Call('updateHost', array('object'=>$host, 'addrs' => $iplist) );
}
function api2HostDelete($host){
return api2Call('deleteHost', array('object'=>$host) );
}
function api2HostList(){
return api2Call('listHost');
}
function api2List(){
return api2Call('listDomain');
}
function api2Renew($domain, $period){
return api2Call('renewDomain', array('object'=>$domain,'period'=>$period) );
}
function api2Create($domain, $period, $owner,$ns = array() ){
$data = array( "object"=>$domain,
"period"=>$period
);
$data["owner"] = array(
"name"=>$owner['name'],
"org"=>$owner['org'],
"sp"=>$owner['sp'],
"cc"=>$owner['cc'],
"city"=>$owner['city'],
"street"=>$owner['street'],
"voice"=>$owner['voice'],
"fax"=>$owner['fax'],
"email"=>$owner['email']
);
$data['ns'] = $ns;
return api2Call("createDomain",$data);
}
function api2Update($domain, $ns, $owner = array()){
$data = array("object"=>$domain);
if(!empty($owner)) {
$data["owner"] = array(
"name"=>$owner['name'],
"org"=>$owner['org'],
"sp"=>$owner['sp'],
"cc"=>$owner['cc'],
"city"=>$owner['city'],
"street"=>$owner['street'],
"voice"=>$owner['voice'],
"fax"=>$owner['fax'],
"email"=>$owner['email']
);
}
$data['ns'] = $ns;
return api2Call('updateDomain',$data);
}
function api2Info($domain){
return api2Call('infoDomain', array("object"=>$domain) );
}
function api2Delete($domain){
return api2Call('deleteDomain', array("object"=>$domain) );
}
function api2Check($domains){
return api2Call('checkDomain',array('domains'=>$domains));
}
function api2Call($cmd,$calldata = array()){
$ch = curl_init();
$reqdata = array('username'=>DNRAPI2_USER, 'password'=>DNRAPI2_PASS) + $calldata;
$data = '';
foreach($reqdata as $cv => $cd){
if(!is_array($cd))
$data .= "&$cv=".urlencode($cd);
else
foreach($cd as $k=>$cdx)
$data .= "&$cv"."[$k]=".urlencode($cdx);
}
curl_setopt ($ch, CURLOPT_URL, DNRAPI2_URL."$cmd.json");
curl_setopt ($ch, CURLOPT_HEADER, 0);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt ($ch, CURLOPT_POST,true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
$xml = curl_exec ($ch);
curl_close ($ch);
return $xml;
}
?>
[свернуть]