瀏覽代碼

try connect using kerio api

andre 2 年之前
父節點
當前提交
19602eb76e
共有 1 個文件被更改,包括 27 次插入52 次删除
  1. 27 52
      app/Http/Actions/TestConnection.php

+ 27 - 52
app/Http/Actions/TestConnection.php

@@ -6,6 +6,7 @@ use ThurData\Servers\KerioEmail\App\Libs\Kerio\Api;
 use ThurData\Servers\KerioEmail\App\Libs\Kerio\Components\Api\Soap\Client;
 use ThurData\Servers\KerioEmail\App\Traits\ExtensionsCheckerTrait;
 use ThurData\Servers\KerioEmail\Core\App\Controllers\Instances\AddonController;
+use ThurData\Servers\KerioEmail\api\KerioConnectApi;
 
 /**
  *
@@ -27,66 +28,40 @@ class TestConnection extends AddonController
      */
     public function execute($params = null)
     {
-        try{
-
-            /**
-             *
-             */
-            $this->checkExtensionOrThrowError();
-            /**
-             * kerio API manager
-             */
-            $manager = (new KerioManager());
-
-            /**
-             * set API params
-             */
-            if($params['serverusername'] )
-            {
-                /**
-                 *
-                 * override secure param
-                 */
-                $params['serversecure'] = $params['serversecure'] ? 'on' : 'off';
-
-                $api = $manager->getApi()->setParams($params);
-            }else{
-                $api = $manager->getApiByServer($params['serverid']);
-            }
-
-            /**
-             * API Connection
-             */
-            $connection = $api->soap->getConnection();
+        /**
+         * API Connection
+         */
 
+        $api = new KerioConnectApi('whmcsKerioEmail', 'Thurdata', '1.0');
+        try {
+            $api->login($params['serverhostname'], $params['serverusername'], $params['serverpassword']);
+            $serverInfo = $api->sendRequest('Server.getProductInfo');
+            $api->logout();
+        } catch (KerioApiException $error) {
+            logModuleCall(
+                'kerioEmail',
+                __FUNCTION__,
+                $api,
+                '',
+                $error->getMessage()
+            );
+            return ['error' => $error->getMessage()];
+        }             
+        
         logModuleCall(
             'kerioEmail',
             __FUNCTION__,
-            $connection,
-            'Debug SOAP Response',
+            $serverInfo,
+            'Debug Kerio Api',
             $api
         );
 
-            /**
-             * check if connected and return true
-             */
-            if($connection->isConnected())
-            {
-                return ['success' => true];
-            }
-
-            /**
-             *
-             * return connection error
-             */
-            return ['error' => $connection->getConnectionError()];
-        }
-        catch (\Exception $ex)
+        /**
+         * check if connected and return true
+         */
+        if($serverInfo)
         {
-            /**
-             * return some crit error
-             */
-            return ['error' => $ex->getMessage()];
+            return ['success' => true];
         }
 
     }