andre hace 2 años
padre
commit
ae852b184e
Se han modificado 1 ficheros con 34 adiciones y 35 borrados
  1. 34 35
      app/Http/Actions/ListAccounts.php

+ 34 - 35
app/Http/Actions/ListAccounts.php

@@ -8,6 +8,7 @@ use ThurData\Servers\KerioEmail\App\Helpers\KerioManager;
 use ThurData\Servers\KerioEmail\App\Libs\Product\ProductManager;
 use ThurData\Servers\KerioEmail\App\Traits\ExtensionsCheckerTrait;
 use ThurData\Servers\KerioEmail\Core\App\Controllers\Instances\AddonController;
+use ThurData\Servers\KerioEmail\Api\KerioWhmcs;
 
 class ListAccounts extends AddonController
 {
@@ -15,42 +16,40 @@ class ListAccounts extends AddonController
 
     public function execute($params = null)
     {
-        try
-        {
-            $servers =(new KerioManager())
-                ->getApiByServer($params['serverid'])
-                ->soap
-                ->repository()
-                ->domains()
-                ->getAll();
-
-            $accounts = [];
-
-            foreach ($servers as $server)
-            {
-                $created = explode('.', $server->getAttr('kerioCreateTimestamp'));
-                $created = date( 'Y-m-d H:i:s', strtotime($created[0]));
-
-                $accounts[] = [
-                    'domain' => $server->getName(),
-                    'status' => 'Active',
-                    'created' => $created,
-                    'primaryip' => $params['serverip'],
-                    'uniqueIdentifier' => $server->getName(),
-                    'product' => '',
-                ];
-            }
-
-            return [
-                'success' => true,
-                'accounts' => $accounts
-            ];
-
-        }
-        catch (\Exception $ex)
-        {
-            return ['error' => $ex->getMessage()];
+        $api = new KerioWhmcs('whmcsKerioEmail', 'Thurdata', '1.0');
+        try {
+            $api->login($params['serverhostname'], $params['serverusername'], $params['serverpassword']);
+            $domainID = $api->getDomainId($params['domain']);
+        } catch (KerioApiException $error) {
+            logModuleCall(
+                'kerioEmail',
+                __FUNCTION__,
+                $error,
+                'Debug Error',
+                $error->getMessage()
+            );
+            return ['error' => $error->getMessage()];
+        }             
+        if ($domainID === FALSE) {
+            return "Error: Domain $domain not found";
         }
+        try {
+            $users = $api->getUsers(['loginName'], $domainID);
+        } catch (KerioApiException $error) {
+            logModuleCall(
+                'kerioEmail',
+                __FUNCTION__,
+                $users,
+                'Debug Userlist',
+                $domainID
+            );
+            return ['error' => $error->getMessage()];
+        }             
+
+        return [
+            'success' => true,
+            'accounts' => $users
+        ];
 
     }
 }