|
|
@@ -112,6 +112,11 @@ function siteBuilder_Testconnection($params) {
|
|
|
function siteBuilder_CreateAccount($params) {
|
|
|
$username = strtolower(substr($params['clientsdetails']['firstname'],0,2) . substr($params['clientsdetails']['lastname'],0,3)) . $params['serviceid'];
|
|
|
$userdomain = $params['domain'];
|
|
|
+ // set DNS
|
|
|
+ $response = siteBuildersetDNS($params, $userdomain);
|
|
|
+ if($response != 'success') {
|
|
|
+ return $response;
|
|
|
+ }
|
|
|
try {
|
|
|
Capsule::table('tblhosting')
|
|
|
->where('id', '=', $params['serviceid'])
|
|
|
@@ -558,6 +563,11 @@ function siteBuilder_addSite($params) {
|
|
|
}
|
|
|
$site = $_POST['d'] . '.' . $params['domain'];
|
|
|
}
|
|
|
+ // set DNS
|
|
|
+ $response = siteBuildersetDNS($params, $site);
|
|
|
+ if($response != 'success') {
|
|
|
+ return $response;
|
|
|
+ }
|
|
|
$siteBuilder = new ApiClient(getSiteBuilderApiURL($params), $params['serveraccesshash']);
|
|
|
// init prod
|
|
|
$response = $siteBuilder->init($params['username'], $site, $params['serverusername'], $params['serverpassword']);
|
|
|
@@ -767,7 +777,11 @@ function siteBuilder_delSite($params) {
|
|
|
);
|
|
|
return 'Error: could remove site from database';
|
|
|
}
|
|
|
-
|
|
|
+ // unset DNS
|
|
|
+ $response = siteBuilderunsetDNS($params, $site);
|
|
|
+ if($response != 'success') {
|
|
|
+ return $response;
|
|
|
+ }
|
|
|
return 'success';
|
|
|
}
|
|
|
|
|
|
@@ -949,6 +963,98 @@ function siteBuilder_disableSite($params) {
|
|
|
return 'success';
|
|
|
}
|
|
|
|
|
|
+/**
|
|
|
+ * Update a DNS zone for a domain setting a new record for a domain or subdomain of a CWP7 account.
|
|
|
+ *
|
|
|
+ * @param array $params common module parameters
|
|
|
+ *
|
|
|
+ * @see https://developers.whmcs.com/provisioning-modules/supported-functions/
|
|
|
+ *
|
|
|
+ * @return string "success" or an error message
|
|
|
+ */
|
|
|
+function siteBuildersetDNS($params, $site) {
|
|
|
+ $siteName = $site . '.';
|
|
|
+ $zoneRecords = array();
|
|
|
+ $domainRecord = array(
|
|
|
+ 'line' => $siteName.'|A|0',
|
|
|
+ 'name' => $siteName,
|
|
|
+ 'type' => 'A',
|
|
|
+ 'class' => 'IN',
|
|
|
+ 'data' => array(
|
|
|
+ 'address' => $params['serverip'],
|
|
|
+ ),
|
|
|
+ );
|
|
|
+ array_push($zoneRecords, $domainRecord);
|
|
|
+ $zoneIDcollection = Capsule::table('dns_manager2_zone')
|
|
|
+ ->select('id')
|
|
|
+ ->where('name', '=', $params['domain'])
|
|
|
+ ->where('clientid', '=', $params['userid'])
|
|
|
+ ->get();
|
|
|
+ $zoneIDobj = $zoneIDcollection[0];
|
|
|
+ $zoneID = $zoneIDobj->{'id'};
|
|
|
+ if(!isset($zoneID)) {
|
|
|
+ return 'Error: Zone for domain ' . $params['domain'] . ' or not owned by client';
|
|
|
+ }
|
|
|
+ $dnsZone = localAPI('dnsmanager', array( 'dnsaction' => 'getZone', 'zone_id' => $zoneID));
|
|
|
+ foreach($dnsZone['data']->records as $record) {
|
|
|
+ if(($record->name != $siteName) || ($record->type != 'A' && $record->type != 'CNAME')) {
|
|
|
+ array_push($zoneRecords, $record);
|
|
|
+ };
|
|
|
+ }
|
|
|
+ $result = localAPI('dnsmanager' ,
|
|
|
+ array(
|
|
|
+ 'dnsaction' => 'updateZone',
|
|
|
+ 'zone_id' => $zoneID,
|
|
|
+ 'records' => $zoneRecords,
|
|
|
+ )
|
|
|
+ );
|
|
|
+ if($result['result'] != 'success') {
|
|
|
+ return 'Error: ' . $result['message'];
|
|
|
+ }
|
|
|
+ return 'success';
|
|
|
+}
|
|
|
+
|
|
|
+/**
|
|
|
+ * Removing a DNS record for a site of a siteBuilder account.
|
|
|
+ *
|
|
|
+ * @param array $params common module parameters
|
|
|
+ *
|
|
|
+ * @see https://developers.whmcs.com/provisioning-modules/supported-functions/
|
|
|
+ *
|
|
|
+ * @return string "success" or an error message
|
|
|
+ */
|
|
|
+function siteBuilderunsetDNS($params, $site) {
|
|
|
+ $siteName = $site . '.';
|
|
|
+ $zoneRecords = array();
|
|
|
+ $zoneIDcollection = Capsule::table('dns_manager2_zone')
|
|
|
+ ->select('id')
|
|
|
+ ->where('name', '=', $params['domain'])
|
|
|
+ ->where('clientid', '=', $params['userid'])
|
|
|
+ ->get();
|
|
|
+ $zoneIDobj = $zoneIDcollection[0];
|
|
|
+ $zoneID = $zoneIDobj->{'id'};
|
|
|
+ if(!isset($zoneID)) {
|
|
|
+ return 'Error: Zone for domain ' . $params['domain'] . ' or not owned by client';
|
|
|
+ }
|
|
|
+ $dnsZone = localAPI('dnsmanager', array( 'dnsaction' => 'getZone', 'zone_id' => $zoneID));
|
|
|
+ foreach($dnsZone['data']->records as $record) {
|
|
|
+ if(($record->name != $siteName) || ($record->type != 'A' && $record->type != 'CNAME')) {
|
|
|
+ array_push($zoneRecords, $record);
|
|
|
+ };
|
|
|
+ }
|
|
|
+ $result = localAPI('dnsmanager' ,
|
|
|
+ array(
|
|
|
+ 'dnsaction' => 'updateZone',
|
|
|
+ 'zone_id' => $zoneID,
|
|
|
+ 'records' => $zoneRecords,
|
|
|
+ )
|
|
|
+ );
|
|
|
+ if($result['result'] != 'success') {
|
|
|
+ return 'Error: ' . $result['message'];
|
|
|
+ }
|
|
|
+ return 'success';
|
|
|
+}
|
|
|
+
|
|
|
/**
|
|
|
* Returns API Url .
|
|
|
*
|