Ver Fonte

add unset DNS

andre há 3 anos atrás
pai
commit
d58573ae93
1 ficheiros alterados com 52 adições e 0 exclusões
  1. 52 0
      cwp7.php

+ 52 - 0
cwp7.php

@@ -973,6 +973,58 @@ function cwp7_setDNS($params) {
 	return 'success';
 }
 
+/**
+ * Removing a DNS 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 cwp7_unssetDNS($params) {
+	if(!filter_var($_POST['d'], FILTER_VALIDATE_DOMAIN, FILTER_FLAG_HOSTNAME)){
+		return 'Error: invalid domain name';
+	}
+	$domainName = $_POST['d'];
+    $zoneRecords = array();
+	if(isset($_POST['s'])){
+		if(!filter_var($_POST['s'], FILTER_VALIDATE_DOMAIN, FILTER_FLAG_HOSTNAME)){
+			return 'Error: invalid subdomain name';
+		}
+		$hostName = $_POST['s'] . '.' . $domainName . '.';
+	} else {
+		$hostName = $domainName . '.';
+	}
+	$zoneIDcollection = Capsule::table('dns_manager2_zone')
+		->select('id')
+		->where('name', '=', $domainName)
+		->where('clientid', '=', $params['userid'])
+		->get();
+	$zoneIDobj = $zoneIDcollection[0];
+	$zoneID = $zoneIDobj->{'id'};
+	if(!isset($zoneID)) {
+		return 'Error: Zone for domain ' . $domainName . ' or not owned by client';
+	}
+	$dnsZone = localAPI('dnsmanager', array( 'dnsaction' => 'getZone', 'zone_id' => $zoneID));
+    foreach($dnsZone['data']->records as $record) {
+        if(($record->name != $hostName) || ($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';
+}
+
 /**
  * Opens a form to inform about the DNS status of a subdomain or domain of a CWP7 account.
  *