Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

small bugfix and some error checking in dns_manager web API module #168

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 38 additions & 25 deletions modules/dns_manager/code/webservice.ext.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ private function GetDomainID($uid, $domainName)
$sql->bindParam(':name', $domainName);
$sql->execute();
$domainID = $sql->fetch();
return $domainID['vh_id_pk'];
return $domainID ? $domainID['vh_id_pk'] : -1;
}

/**
Expand All @@ -30,18 +30,20 @@ public function GetAllDNSRecords()
$uid = ws_generic::GetTagValue('uid', $request_data['content']);
$domainID = self::GetDomainID($uid, $domainName);

$sql = $zdbh->prepare("SELECT * FROM x_dns WHERE dn_acc_fk=:userid AND dn_vhost_fk=:domainID AND dn_deleted_ts IS NULL ORDER BY dn_host_vc ASC");
$sql->bindParam(':userid', $uid);
$sql->bindParam(':domainID', $domainID);
$sql->execute();

while ($rowdns = $sql->fetch()) {
$response_xml = $response_xml . ws_xmws::NewXMLContentSection('dns_record', array(
'hostName' => $rowdns['dn_host_vc'],
'type' => $rowdns['dn_type_vc'],
'target' => $rowdns['dn_target_vc'],
'ttl' => $rowdns['dn_ttl_in'],
));
if ($domainID != -1) {
$sql = $zdbh->prepare("SELECT * FROM x_dns WHERE dn_acc_fk=:userid AND dn_vhost_fk=:domainID AND dn_deleted_ts IS NULL ORDER BY dn_host_vc ASC");
$sql->bindParam(':userid', $uid);
$sql->bindParam(':domainID', $domainID);
$sql->execute();

while ($rowdns = $sql->fetch()) {
$response_xml = $response_xml . ws_xmws::NewXMLContentSection('dns_record', array(
'hostName' => $rowdns['dn_host_vc'],
'type' => $rowdns['dn_type_vc'],
'target' => $rowdns['dn_target_vc'],
'ttl' => $rowdns['dn_ttl_in'],
));
}
}

$dataobject = new runtime_dataobject();
Expand Down Expand Up @@ -71,23 +73,27 @@ public function CreateDNSRecord()
$target = ws_generic::GetTagValue('target', $request_data['content']);
$ttl = ws_generic::GetTagValue('ttl', $request_data['content']);
$domainID = self::GetDomainID($uid, $domainName);

module_controller::createDNSRecord(array(
"uid" => $uid,
"domainName" => $domainName,
"domainID" => $domainID,
"type" => $type,
"hostName" => $hostName,
"ttl" => $ttl,
"target" => $target
));
$created = "false";

if ($domainID != -1) {
module_controller::createDNSRecord(array(
"uid" => $uid,
"domainName" => $domainName,
"domainID" => $domainID,
"type" => $type,
"hostName" => $hostName,
"ttl" => $ttl,
"target" => $target
));
$created = "true";
}

$response_xml = $response_xml . ws_xmws::NewXMLContentSection('dns_record', array(
'domainName' => $domainName,
'hostName' => $hostName,
'type' => $type,
'target' => $target,
'created' => 'true'
'created' => $created
));

$dataobject = new runtime_dataobject();
Expand Down Expand Up @@ -117,7 +123,14 @@ public function DeleteDNSRecords()
$domainName = ws_generic::GetTagValue('domainName', $request_data['content']);
$domainID = self::GetDomainID($uid, $domainName);

$sqlstr = "SELECT * FROM x_dns WHERE dn_acc_fk=:userid AND vh_deleted_ts IS NULL AND dn_vhost_fk=:domainID ";
if ($domainID == -1) {
$dataobject = new runtime_dataobject();
$dataobject->addItemValue('response', '');
$dataobject->addItemValue('content', $response_xml);
return $dataobject->getDataObject();
}

$sqlstr = "SELECT * FROM x_dns WHERE dn_acc_fk=:userid AND dn_deleted_ts IS NULL AND dn_vhost_fk=:domainID ";

// iterate through optional parameters
foreach ($tags as $tag => $sql_param) {
Expand Down