Просмотр исходного кода

try to create a limited domain

andre 2 лет назад
Родитель
Сommit
33f42ca163
2 измененных файлов с 52 добавлено и 14 удалено
  1. 16 0
      api/KerioWhmcs.php
  2. 36 14
      app/Http/Actions/CreateAccount.php

+ 16 - 0
api/KerioWhmcs.php

@@ -425,6 +425,22 @@ class KerioWhmcs extends KerioConnectApi {
 		return $result;
 	}
 	
+	/**
+	 * Modify domain.
+	 *
+	 * @param	string	DomainID
+	 * @param	array	Attributes
+	 * @return	array	Result
+	 */
+	function modifyDomain($domainID, $attr) {
+		$params = array(
+			'domainIds' => array($domainID),
+			'pattern' => $attr,
+		);
+		$result = $this->sendRequest('Domains.set', $params);
+		return $result;
+	}
+	
 	/**
 	 * Get list of IP addresses from a file.
 	 *

+ 36 - 14
app/Http/Actions/CreateAccount.php

@@ -71,37 +71,51 @@ class CreateAccount extends AddonController
      */
     protected function kerioRunService($params = null)
     {
+        $api = new KerioWhmcs('whmcsKerioEmail', 'Thurdata', '1.0');
+        try {
+            $api->login($params['serverhostname'], $params['serverusername'], $params['serverpassword']);
+            $result = $api->createDomain($params['domain']);
+            $domainID = $result['result'][0]['id'];
+        } catch (KerioApiException $error) {
+            logModuleCall(
+                'kerioEmail',
+                __FUNCTION__,
+                $error,
+                'Debug Error',
+                $error->getMessage()
+            );
+            return ['error' => $error->getMessage()];
+        }             
+
+        // check and calculate limits
         $productManager = new ProductManager();
         $productManager->loadById($params['pid']);
         $acc_limit = $productManager->get('acc_limit');
         $accounts = $productManager->get('acc_base') + $params['configoptions']['acc_add'] + $params['configoptions']['acc_new'];
         if ($acc_limit >= 0) {
+            $attr['userMaxCountCheckbox'] = TRUE;
             if ($accounts > $acc_limit) {
                 $accounts = $acc_limit;
             }
+            $attr['userMaxCount'] = $acc_limit;
+        } else {
+            $attr['userMaxCountCheckbox'] = FALSE;
         }
         $domainMaxSize = $productManager->get('domainMaxSize');
         $domainSize = $productManager->get('domainBaseSize') + $params['configoptions']['domainAddSize'] + $params['configoptions']['domainNewSize'];
         if ($domainMaxSize >= 0) {
+            $attr['domainQuota']['diskSizeLimit']['isActive'] = TRUE;
             if ($domainSize > $domainMaxSize) {
                 $domainSize = $domainMaxSize;
             }
+            $attr['domainQuota']['diskSizeLimit']['limit']['value'] = $domainSize;
+            $attr['domainQuota']['diskSizeLimit']['limit']['units'] = 'GigaBytes';
+        } else {
+            $attr['domainQuota']['diskSizeLimit']['isActive'] = FALSE;
         }
-        $api = new KerioWhmcs('whmcsKerioEmail', 'Thurdata', '1.0');
         try {
-            $api->login($params['serverhostname'], $params['serverusername'], $params['serverpassword']);
-            $result = $api->createDomain($params['domain']);
-            $domainID = $result['result'][0]['id'];
-            $api->logout();
-            logModuleCall(
-                'kerioEmail',
-                __FUNCTION__,
-                $accounts,
-                'Debug ID',
-                $domainSize
-            );
+            $result = $api->modifyDomain($domainID, $attr);
         } catch (KerioApiException $error) {
-
             logModuleCall(
                 'kerioEmail',
                 __FUNCTION__,
@@ -109,10 +123,18 @@ class CreateAccount extends AddonController
                 'Debug Error',
                 $error->getMessage()
             );
-    
             return ['error' => $error->getMessage()];
         }             
 
+        logModuleCall(
+            'kerioEmail',
+            __FUNCTION__,
+            $attr,
+            'Debug ID',
+            $result
+        );
+        $api->logout();
+
         /**
          * return success response
          */