andre 3 ani în urmă
părinte
comite
747e7b102e
6 a modificat fișierele cu 379 adăugiri și 988 ștergeri
  1. 2 3
      api/config.php
  2. 142 147
      api/cwp7/Admin.php
  3. 8 83
      api/test.php
  4. 0 755
      cwp.php
  5. 227 0
      cwp7.php
  6. 0 0
      cwp7AddressAvailable.php

+ 2 - 3
api/config.php

@@ -3,8 +3,7 @@
 // Config //
 ////////////
 
-$CWPURL = 'https://files.thurdata.ch:443';
-$CWPAdminEmail = 'info@thurdata.ch';
-$CWPAdminPassword = '';
+$cwp7URL = 'https://hosting.seecure.ch:2304/';
+$cwp7Token = 'XtlJyuGnHANEez2VEiVFpAglX8XoixsOVQkhobiPgZmvcS7fM8NRagmBzBMHVlBsNr4hck';
 
 ?>

+ 142 - 147
api/cwp7/Admin.php

@@ -73,57 +73,21 @@ class cwp7_Admin {
 	 * @return array of cwp7 accounts array of informations or error message
 	 */
     public function getAllAccounts() {
-        if (!$this->constructorSuccess()) {
-            return array('error_msg' => 'Error: not connect');
-        }
-        $data = array("key" => $this->cwp7Token, "action" => 'list');
-        $ch = curl_init();
-        curl_setopt($ch, CURLOPT_URL, $this->cwp7URL . '/v1/account');
-        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
-        curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
-        if(!$this->cwp7Secure) {
-            curl_setopt($cwp7Client, CURLOPT_SSL_VERIFYPEER, false);
-            curl_setopt($cwp7Client, CURLOPT_SSL_VERIFYHOST, false);
-        }
-        curl_setopt ($ch, CURLOPT_POSTFIELDS, http_build_query($data));
-        curl_setopt ($ch, CURLOPT_POST, 1);
-        $response = curl_exec($ch);
-        if(curl_getinfo($ch, CURLINFO_RESPONSE_CODE) != 200) {
-            curl_close($ch);
-            return array('error_msg' => $response);
-        };
-        curl_close($ch);
-        return json_decode($response, true);
+        $data = array();
+        return json_decode(doRequest('account', 'list', $data), true);
     }
 	/**
 	 * getAccount
 	 * 
-	 * @param string $email login e-mail
+	 * @param string $user user
 	 * 
 	 * @return array of account informations or error message
 	 */
     public function getAccount($user) {
-        if (!$this->constructorSuccess()) {
-            return array('error_msg' => 'Error: not connect');
-        }
-        $data = array("key" => $this->cwp7Token, "action"=>'list', "user" => $user);
-        $ch = curl_init();
-        curl_setopt($ch, CURLOPT_URL, $this->cwp7URL . '/v1/accountdetail');
-        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
-        curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
-        if(!$this->cwp7Secure) {
-            curl_setopt($cwp7Client, CURLOPT_SSL_VERIFYPEER, false);
-            curl_setopt($cwp7Client, CURLOPT_SSL_VERIFYHOST, false);
-        }
-        curl_setopt ($ch, CURLOPT_POSTFIELDS, http_build_query($data));
-        curl_setopt ($ch, CURLOPT_POST, 1);
-        $response = curl_exec($ch);
-        if(curl_getinfo($ch, CURLINFO_RESPONSE_CODE) != 200) {
-            curl_close($ch);
-            return array('error_msg' => $response);
-        };
-        curl_close($ch);
-        return json_decode($response, true);
+        $data = array(
+            "user" => $user
+        );
+        return json_decode(doRequest('accountdetail', 'list', $data), true);
     }
 	/**
 	 * createAccount
@@ -133,9 +97,6 @@ class cwp7_Admin {
 	 * @return array of account informations or error message
 	 */
     public function createAccount($params) {
-        if (!$this->constructorSuccess()) {
-            return array('error_msg' => 'Error: not connected');
-        }
         if(!isset($params['domain'])) {
             return array('error_msg' => 'Error: missing parameter domain');
         }
@@ -155,8 +116,6 @@ class cwp7_Admin {
             $params['autossl'] = 0;
         }
         $data = array(
-            "key"           => $this->cwp7Token,
-            "action"        =>'add',
             "domain"        => $params['domain'],
             "user"          => $params['user'],
             "pass"          => base64_encode($params['pass']),
@@ -165,37 +124,16 @@ class cwp7_Admin {
             "autossl"       => $params['autossl'],
             "encodepass"    => true,
         );
-        $ch = curl_init();
-        curl_setopt($ch, CURLOPT_URL, $this->cwp7URL . '/v1/account');
-        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
-        curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
-        if(!$this->cwp7Secure) {
-            curl_setopt($cwp7Client, CURLOPT_SSL_VERIFYPEER, false);
-            curl_setopt($cwp7Client, CURLOPT_SSL_VERIFYHOST, false);
-        }
-        curl_setopt ($ch, CURLOPT_POSTFIELDS, http_build_query($data));
-        curl_setopt ($ch, CURLOPT_POST, 1);
-        $response = curl_exec($ch);
-        if(curl_getinfo($ch, CURLINFO_RESPONSE_CODE) != 200) {
-            curl_close($ch);
-            return array('error_msg' => $response);
-        };
-        curl_close($ch);
-        return json_decode($response, true);
+        return json_decode(doRequest('account', 'add', $data), true);
 	}
 	/**
 	 * modifyAccount
 	 * 
 	 * @param array $params account informations, user, e-mail & new package required.
-     * 
-	 * @see https://download.cwp7.com/published/web-api/v2.1-admin/accounts.md#user-content-Add%20User
      * 
 	 * @return array status -> OK or error message
 	 */
     public function modifyAccount($params) {
-        if (!$this->constructorSuccess()) {
-            return array('error_msg' => 'Error: not connected');
-        }
         if(!isset($params['user'])) {
             return array('error_msg' => 'Error: missing parameter user');
         }
@@ -206,29 +144,11 @@ class cwp7_Admin {
             return array('error_msg' => 'Error: missing parameter package');
         }
         $data = array(
-            "key"           => $this->cwp7Token,
-            "action"        =>'upd',
-            "user"          => $params['user'],
-            "email"         => $params['email'],
-            "package"       => $params['package'],
+            'user'          => $params['user'],
+            'email'         => $params['email'],
+            'package'       => $params['package'],
         );
-        $ch = curl_init();
-        curl_setopt($ch, CURLOPT_URL, $this->cwp7URL . '/v1/account');
-        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
-        curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
-        if(!$this->cwp7Secure) {
-            curl_setopt($cwp7Client, CURLOPT_SSL_VERIFYPEER, false);
-            curl_setopt($cwp7Client, CURLOPT_SSL_VERIFYHOST, false);
-        }
-        curl_setopt ($ch, CURLOPT_POSTFIELDS, http_build_query($data));
-        curl_setopt ($ch, CURLOPT_POST, 1);
-        $response = curl_exec($ch);
-        if(curl_getinfo($ch, CURLINFO_RESPONSE_CODE) != 200) {
-            curl_close($ch);
-            return array('error_msg' => $response);
-        };
-        curl_close($ch);
-        return json_decode($response, true);
+        return json_decode(doRequest('account', 'upd', $data), true);
 	}
 	/**
 	 * deleteAccount
@@ -239,9 +159,6 @@ class cwp7_Admin {
 	 */
     public function deleteAccount($params)
 	{
-        if (!$this->constructorSuccess()) {
-            return array('error_msg' => 'Error: not connected');
-        }
         if(!isset($params['user'])) {
             return array('error_msg' => 'Error: missing parameter user');
         }
@@ -249,83 +166,161 @@ class cwp7_Admin {
             return array('error_msg' => 'Error: missing parameter email');
         }
         $data = array(
-            "key"           => $this->cwp7Token,
-            "action"        =>'del',
             "user"          => $params['user'],
             "email"         => $params['email'],
         );
-        $ch = curl_init();
-        curl_setopt($ch, CURLOPT_URL, $this->cwp7URL . '/v1/account');
-        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
-        curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
-        if(!$this->cwp7Secure) {
-            curl_setopt($cwp7Client, CURLOPT_SSL_VERIFYPEER, false);
-            curl_setopt($cwp7Client, CURLOPT_SSL_VERIFYHOST, false);
-        }
-        curl_setopt ($ch, CURLOPT_POSTFIELDS, http_build_query($data));
-        curl_setopt ($ch, CURLOPT_POST, 1);
-        $response = curl_exec($ch);
-        if(curl_getinfo($ch, CURLINFO_RESPONSE_CODE) != 200) {
-            curl_close($ch);
-            return array('error_msg' => $response);
-        };
-        curl_close($ch);
-        return json_decode($response, true);
+        return json_decode(doRequest('account', 'del', $data), true);
 	}
 	/**
 	 * suspendAccount
 	 * 
-	 * @param string $user required
+	 * @param string $user user
 	 * 
 	 * @return array success => true or error message
 	 */
     public function suspendAccount($user)
 	{
-        if (!$this->constructorSuccess()) {
-            return array('error_msg' => 'Error: not connected');
-        }
         $data = array(
-            "key"           => $this->cwp7Token,
-            "action"        =>'susp',
-            "user"          => $user,
+            "user" => $user,
         );
-        $ch = curl_init();
-        curl_setopt($ch, CURLOPT_URL, $this->cwp7URL . '/v1/account');
-        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
-        curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
-        if(!$this->cwp7Secure) {
-            curl_setopt($cwp7Client, CURLOPT_SSL_VERIFYPEER, false);
-            curl_setopt($cwp7Client, CURLOPT_SSL_VERIFYHOST, false);
-        }
-        curl_setopt ($ch, CURLOPT_POSTFIELDS, http_build_query($data));
-        curl_setopt ($ch, CURLOPT_POST, 1);
-        $response = curl_exec($ch);
-        if(curl_getinfo($ch, CURLINFO_RESPONSE_CODE) != 200) {
-            curl_close($ch);
-            return array('error_msg' => $response);
-        };
-        curl_close($ch);
-        return json_decode($response, true);
+        return json_decode(doRequest('account', 'susp', $data), true);
 	}
 	/**
 	 * unsuspendAccount
 	 * 
-	 * @param string $user required
+	 * @param string $user user
 	 * 
 	 * @return array success => true or error message
 	 */
     public function unsuspendAccount($user)
 	{
-        if (!$this->constructorSuccess()) {
-            return array('error_msg' => 'Error: not connected');
+        $data = array(
+            'user' => $user,
+        );
+        return json_decode(doRequest('account', 'unsp', $data), true);
+	}
+	/**
+	 * getPackages
+	 * 
+	 * @return array packages
+	 */
+    public function getPackages()
+	{
+        $data = array();
+        return json_decode(doRequest('packages', 'list', $data), true);
+    }
+	/**
+	 * changePassword
+	 * 
+	 * @return array packages
+	 */
+    public function changePackage($params)
+	{
+        if(!isset($params['user'])) {
+            return array('error_msg' => 'Error: missing parameter user');
+        }
+        if(!isset($params['password'])) {
+            return array('error_msg' => 'Error: missing parameter password');
         }
         $data = array(
-            "key"           => $this->cwp7Token,
-            "action"        =>'unsp',
-            "user"          => $user,
+            'user' => $params['user'],
+            'password' => $params['password'],
         );
+        return json_decode(doRequest('changepass', 'upd', $data), true);
+    }
+    /**
+	 * getQuota
+     * 
+     * @param string $user user
+	 * 
+	 * @return array quota details
+	 */
+    public function getQuota($user)
+	{
+        $data = array('user' => $user);
+        return json_decode(doRequest('accountquota', 'list', $data), true);
+    }
+	/**
+	 * getAutoSSL
+     * 
+     * @param string $user user
+	 * 
+	 * @return array certificate data or error
+	 */
+    public function getAutoSSL($user)
+	{
+        $data = array('user' => $user);
+        return json_decode(doRequest('autossl', 'list', $data), true);
+    }
+	/**
+	 * addAutoSSL
+     * 
+     * @param array $user user, $name doaminname
+	 * 
+	 * @return array status or error
+	 */
+    public function addAutoSSL($params)
+	{
+        if(!isset($params['user'])) {
+            return array('error_msg' => 'Error: missing parameter user');
+        }
+        if(!isset($params['name'])) {
+            return array('error_msg' => 'Error: missing parameter name');
+        }
+        $data = array('user' => $params['user'], 'name' => $params['name']);
+        return json_decode(doRequest('autossl', 'add', $data), true);
+    }
+	/**
+	 * renewAutoSSL
+     * 
+     * @param array $user user, $name cert name
+	 * 
+	 * @return array status or error
+	 */
+    public function updateAutoSSL($params)
+	{
+        if(!isset($params['user'])) {
+            return array('error_msg' => 'Error: missing parameter user');
+        }
+        if(!isset($params['name'])) {
+            return array('error_msg' => 'Error: missing parameter name');
+        }
+        $data = array('user' => $params['user'], 'name' => $params['name']);
+        return json_decode(doRequest('autossl', 'renew', $data), true);
+    }
+	/**
+	 * delAutoSSL
+     * 
+     * @param array $user user, $name doaminname
+	 * 
+	 * @return array status or error
+	 */
+    public function delAutoSSL($params)
+	{
+        if(!isset($params['user'])) {
+            return array('error_msg' => 'Error: missing parameter user');
+        }
+        if(!isset($params['name'])) {
+            return array('error_msg' => 'Error: missing parameter name');
+        }
+        $data = array('user' => $params['user'], 'name' => $params['name']);
+        return json_decode(doRequest('autossl', 'del', $data), true);
+    }
+
+    /**
+     * doRequest
+     * 
+     * @param string $endpoint API endpoint
+     * @param string $action endpoint action
+     * @param array $data POST data
+     * 
+     * @return array API response
+     */
+    protected function doRequest($endpoint, $action, $data) {
+        $data['key'] = $this->cwp7Token;
+        $data['action'] = $action;
         $ch = curl_init();
-        curl_setopt($ch, CURLOPT_URL, $this->cwp7URL . '/v1/account');
+        curl_setopt($ch, CURLOPT_URL, $this->cwp7URL . '/v1/' . $endpoint);
         curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
         curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
         if(!$this->cwp7Secure) {
@@ -340,6 +335,6 @@ class cwp7_Admin {
             return array('error_msg' => $response);
         };
         curl_close($ch);
-        return json_decode($response, true);
-	}
+        return $response;
+    }
 }

+ 8 - 83
api/test.php

@@ -70,14 +70,14 @@ function parse_args($argv){
 	return $out;
 }
 
-///////////
-// Login //
-///////////
+/////////////////
+// Constructor //
+/////////////////
 
-$cwp7 = new cwp7_Admin($cwp7URL, $cwp7AdminEmail, $cwp7AdminPassword);
-$r = $cwp7->login();
+$cwp7 = new cwp7_Admin($cwp7URL, $cwp7Token);
+$r = $cwp7->constructorSuccess();
 if(isset($r['error_msg'])) {
-	echo 'Error : cannot login to ' . $cwp7URL . ' :-(' . PHP_EOL;
+	echo 'Error : cannot construct :-(' . PHP_EOL;
 	print_r($r);
 	exit();
 }
@@ -86,84 +86,9 @@ if(isset($r['error_msg'])) {
 // Actions //
 /////////////
 
-// nop
-if($action == 'nop')
-{
-    echo 'OK : login success, no further operation :-)' . PHP_EOL;
-    exit;
-}
-
 // Get All Accounts
 if($action == 'gaa')
 {
-    $r = $sf->getAllAccounts();
-	if(isset($r['error_msg'])) {
-        echo 'Error : could not fetch list of accounts for '. $seafileURL . ' :-(' . PHP_EOL;
-        print_r($r);
-	} else {
-        echo 'OK : got a list of '. $r['total_count'] . ' accounts for ' . $seafileURL . ' :-)' . PHP_EOL;
-    }
-}
-
-// Get Account Informations
-if($action == 'gai')
-{
-	$r = $sf->getAccount($args['account_name']);
-	if(isset($r['error_msg'])) {
-        echo 'Error : could not fetch information of '. $args['account_name'] . ' :-(' . PHP_EOL;
-        print_r($r);
-	} else {
-        echo 'OK : got the infos for account ' . $args['account_name'] . ' :-)' . PHP_EOL;
-    }
-}
-
-// Create Account
-if($action == 'ca')
-{
-	$attrs = array('email'=> $args['account_name'], 'password'=> $args['password']);
-	$r = $sf->createAccount($attrs);
-	if(isset($r['error_msg'])) {
-		echo 'Error : cannot create account ' . $args['account_name'] . ' :-(' . PHP_EOL;
-        print_r($r);
-	} else {
-		echo 'OK : account ' . $args['account_name'] . ' created :-)' . PHP_EOL;
-    }
-}
-
-// Modify Account
-if($action == 'moa')
-{
-    $attrs = array('email'=> $args['account_name'], 'quota_total' => $args['quota_total']);
-	$r = $sf->modifyAccount($attrs);
-	if(isset($r['error_msg'])) {
-		echo 'Error : cannot modify account ' . $args['account_name'] . ' :-(' . PHP_EOL;
-		print_r($r);
-	} else {
-		echo 'OK : modify account ' . $args['account_name'] . ' :-)' . PHP_EOL;
-		print_r($r);
-	}
-}
-
-// Migrate Account
-if($action == 'mia')
-{
-	$r = $sf->migrateAccount($args['account_name'], $args['new_account_name']);
-	if(isset($r['error_msg'])) {
-		echo 'Error : account ' . $args['account_name'] . ' not migrated to ' . $args['new_account_name'] . ' :-(' . PHP_EOL;
-		print_r($r);
-	} else {
-		echo 'OK : account ' . $args['account_name'] . ' migrated to ' . $args['new_account_name'] . ' :-)' . PHP_EOL;
-	}
-}
-
-// Delete Account
-if($action == 'da')
-{
-	$r = $sf->deleteAccount($args['account_name']);
-	if(isset($r['error_msg'])) {
-		echo 'Error : account ' . $args['account_name'] . ' not deleted :-(' . PHP_EOL;
-		print_r($r);
-	} else {
-		echo 'OK : account ' . $args['account_name'] . ' deleted :-)' . PHP_EOL;
-	}
+    $r = $cwp7->getAllAccounts();
+	print_r($r);
 }

+ 0 - 755
cwp.php

@@ -1,755 +0,0 @@
-<?php
-/**
- * WHMCS Seafile Provisioning Module
- *
- * Provisioning for User Account on the Seafile Server
- *
- * @see https://www.seafile.com
- * @copyright Copyright (c) Thurdata GmbH 2020
- * @license GPL
- */
-use WHMCS\Database\Capsule;
-
-require_once(__DIR__ . '/api/Sf/Admin.php');
-if (!defined('WHMCS')) {
-	die('This file cannot be accessed directly'); }
-
-
-function seafile_MetaData() {
-    return array(
-            'DisplayName' => 'Seafile Provisioning',
-            'APIVersion' => '1.2',
-            'DefaultNonSSLPort' => '8000',
-            'DefaultSSLPort' => '443',
-            'RequiresServer' => true,
-            'ServiceSingleSignOnLabel' => 'Login to Seafile',
-            'AdminSingleSignOnLabel' => 'Login to Seafile Admin',
-            'ListAccountsUniqueIdentifierDisplayName' => 'Domain',
-            'ListAccountsUniqueIdentifierField' => 'domain',
-            'ListAccountsProductField' => 'configoption1',
-    );
-}
-
-/**
- * Define SeaFile product configuration options. 
- *
- * @see https://developers.whmcs.com/provisioning-modules/config-options/
- *
- * @return array
- */
-function seafile_ConfigOptions() {
-	$configarray = array(	 
-	    'quota' => array(
-			'Type' => 'text',
-			'Description' => 'Basis  User-Quota für dieses Produkt in GB',
-			'Default' => '10',
-			'Size' => '15',
-			'FriendlyName' => 'User Quota',
-		),
-	);
-	return $configarray;
-}
-
-/**
- * Test connection to a SeaFile server with the given server parameters.
- *
- * Allows an admin user to verify that an API connection can be
- * successfully made with the given configuration parameters for a
- * server.
- *
- * When defined in a module, a Test Connection button will appear
- * alongside the Server Type dropdown when adding or editing an
- * existing server.
- *
- * @param array $params common module parameters
- *
- * @see https://developers.whmcs.com/provisioning-modules/module-parameters/
- *
- * @return array
- */
-function seafile_TestConnection($params) {
-	$seafileURL = $params['serverhttpprefix'] . '://' . $params['serverhostname'] . ':' . $params['serverport'];
-	error_log("Seafile:TestConnection: " . $seafileURL);
-	//error_log("  -> " . $params['serverusername'] . "     " . $params['serverpassword']);
-	$seafileAPI = new Sf_Admin($seafileURL,$params['serverusername'],$params['serverpassword']);
-	$response = $seafileAPI->login();
-	if (isset($response['error_msg'])) {
-		logModuleCall(
-			'seafile',
-			__FUNCTION__,
-			$params,
-			'Error: could not login to ' . $seafileURL,
-			$response
-		);
-		return array(
-			'success' => false,
-			'error' => 'Error: could not login to ' . $seafileURL,
-		);
-	}
-	return array(
-		'success' => true,
-		'error' => '',
-	);
-}
-
-/**
- * Usage Update
- * 
- * Important: Runs daily per server not per product
- * Run Manually: /admin/reports.php?report=disk_usage_summary&action=updatestats
- * @param array $params common module parameters
- * 
- * @see https://developers.whmcs.com/provisioning-modules/usage-update/
- */
-function seafile_UsageUpdate($params) {
-	$seafileURL = $params['serverhttpprefix'] . '://' . $params['serverhostname'] . ':' . $params['serverport'];
-	$seafileAPI = new Sf_Admin($seafileURL,$params['serverusername'],$params['serverpassword']);
-	$response = $seafileAPI->login();
-	if (isset($response['error_msg'])) {
-		logModuleCall(
-			'seafile',
-			__FUNCTION__,
-			$params,
-			'Error: could not login to ' . $seafileURL,
-			$response
-		);
-	    return 'Error: could not login to ' . $seafileURL;
-	}
-    $servicesObj = Capsule::table('tblhosting')
-        ->select('*')
-        ->where('server', '=', $params['serverid'])
-        ->where('domainstatus', '=', 'Active')
-        ->get();
-    foreach((array)$servicesObj as $serviceObj) {
-		$service = get_object_vars($serviceObj[0]);
-		$accountInfo = $seafileAPI->getAccount($service['username']);
-		error_log("Seafile Module: Updating Disk Usage for: " . $accountInfo . " : " . round($accountInfo['quota_usage'] / 1000000,2) . "/" . round($accountInfo['quota_total'] / 1000000,2));
-		if(!isset($accountInfo['error_msg'])) {
-			try {
-				Capsule::table('tblhosting')
-					->where('id', '=', $service['id'])
-					->update(
-						array(
-							'diskusage' => round($accountInfo['quota_usage'] / 1000000,2),
-							'disklimit' => round($accountInfo['quota_total'] / 1000000,2),
-							'lastupdate' => Capsule::raw('now()')
-						)
-					);
-			} catch (Exception $e) {
-				logModuleCall(
-					'seafile',
-					__FUNCTION__,
-					$params,
-					'Error: could update usage information for ' . $service['username'],
-					$e->getMessage()
-				);
-			}
-		}
-    }
-}
-
-/**
- * Client area output logic handling.
- *
- * This function is used to define module specific client area output. It should
- * return an array consisting of a template file and optional additional
- * template variables to make available to that template.
- *
- * The template file you return can be one of two types:
- *
- * * tabOverviewModuleOutputTemplate - The output of the template provided here
- *   will be displayed as part of the default product/service client area
- *   product overview page.
- *
- * * tabOverviewReplacementTemplate - Alternatively using this option allows you
- *   to entirely take control of the product/service overview page within the
- *   client area.
- *
- * Whichever option you choose, extra template variables are defined in the same
- * way. This demonstrates the use of the full replacement.
- *
- * Please Note: Using tabOverviewReplacementTemplate means you should display
- * the standard information such as pricing and billing details in your custom
- * template or they will not be visible to the end user.
- *
- * @param array $params common module parameters
- *
- * @see https://developers.whmcs.com/provisioning-modules/module-parameters/
- *
- * @return array
- */
-function seafile_ClientArea($params) {
-	switch ($params['serverport']) {
-		case '80':
-		case '443':
-			$seafileURL = $params['serverhttpprefix'] . '://' . $params['serverhostname'];
-			break;
-		default:
-			$seafileURL = $params['serverhttpprefix'] . '://' . $params['serverhostname'] . ':' . $params['serverport'];
-			break;
-	};
-	$app = 'https://itunes.apple.com/cn/app/seafile-pro/id639202512?l=en&mt=8';
-	$google = 'https://play.google.com/store/apps/details?id=com.seafile.seadroid2';
-	$driveWin = 'https://s3.eu-central-1.amazonaws.com/download.seadrive.org/seadrive-2.0.5-en.msi';
-	$winClient = 'https://s3.eu-central-1.amazonaws.com/download.seadrive.org/seafile-7.0.9-en.msi';
-	$macClient = 'https://s3.eu-central-1.amazonaws.com/download.seadrive.org/seafile-client-7.0.9.dmg';
-	$driveMac = 'https://s3.eu-central-1.amazonaws.com/download.seadrive.org/seadrive-2.0.5.dmg';
-	$linClient = 'https://download.seafile.com/published/seafile-user-manual/syncing_client/install_linux_client.md';
-	$clientInfo['basequota']        = $params['configoption1'] ? $params['configoption1'] : 1;
-	$clientInfo['addonquota']       = $params['configoptions']['addonQuota'] ? $params['configoptions']['addonQuota'] : 0;
-	$clientInfo['userquota']        = $clientInfo['basequota'] + $clientInfo['addonquota'];
-	$clientInfo['mailaddress']      = $params['username'];
-	$clientinfo['stitle']           = $params['model']['product']['name'];
-    $langObj = Capsule::table('tblconfiguration')
-        ->select('value')
-        ->where('setting', '=', 'Language')
-        ->get();
-	$lla = $_SESSION['Language'] ? trim($_SESSION['Language']) : strtolower($langObj[0]->value);
-	$slang = array();
-	include_once dirname(__FILE__).'/lang/'.$lla.'.php';
-	return array(
-		'tabOverviewReplacementTemplate' => 'clientarea',
-		'vars' => array_merge(
-			array(
-				'url' => $seafileURL,
-				'mobile1' => $app,
-				'mobile2' => $google,
-				'drivewin' => $driveWin,
-				'winclient' => $winClient,
-				'macclient' => $macClient,
-				'drivemac' => $driveMac,
-				'linClient' => $linClient,
-			),
-			$slang,
-			$clientInfo
-		),
-	);
-}
-
-/**
- * Change the password for a SeaFile account.
- *
- * Called when a password change is requested. This can occur either due to a
- * client requesting it via the client area or an admin requesting it from the
- * admin side.
- *
- * This option is only available to client end users when the product is in an
- * active status.
- *
- * @param array $params common module parameters
- *
- * @see https://developers.whmcs.com/provisioning-modules/module-parameters/
- *
- * @return string 'success' or an error message
- */
-function seafile_ChangePassword($params) { 
-	$checkPassword = seafileCheckPassword($params['password']);
-	if ($checkPassword != null) {
-	    return $checkPassword;
-	}
-	$seafileURL = $params['serverhttpprefix'] . '://' . $params['serverhostname'] . ':' . $params['serverport'];
-	$seafileAPI = new Sf_Admin($seafileURL,$params['serverusername'],$params['serverpassword']);
-	$response = $seafileAPI->login();
-	if (isset($response['error_msg'])) {
-		logModuleCall(
-			'seafile',
-			__FUNCTION__,
-			$params,
-			'Error: could not login to ' . $seafileURL,
-			$response
-		);
-	    return 'Error: could not login to ' . $seafileURL;
-	}
-	$userAccount = $seafileAPI->getAccount($params['username']);
-	if(isset($userAccount['error_msg'])) {
-		logModuleCall(
-			'seafile',
-			__FUNCTION__,
-			$params,
-			'Error: could not find account for: ' . $params['username'],
-			$userAccount
-		);
-		return 'Error: could not find account for: ' . $params['username'];
-	}
-	$result = $seafileAPI->modifyAccount(array('email' => $userAccount['email'], 'password' => $params['password']));
-	if(isset($result['error_msg'])) {
-		logModuleCall(
-			'seafile',
-			__FUNCTION__,
-			$params,
-			'Error: could not change password for: ' . $params['username'],
-			$result
-		);
-		return 'Error: could not change password for: ' . $params['username'];
-	}
-	return 'success';
-}
-
-/**
- * Set a new quota of a SeaFile account.
- *
- * Called to apply a quota change of the service. It
- * is called to provision upgrade or downgrade orders, as well as being
- * able to be invoked manually by an admin user.
- *
- * This same function is called for upgrades and downgrades of both
- * products and configurable options.
- *
- * @param array $params common module parameters
- *
- * @see https://developers.whmcs.com/provisioning-modules/module-parameters/
- *
- * @return string 'success' or an error message
- */
-function seafile_ChangePackage($params) { 
-	$quota = $params['configoption1'] ? $params['configoption1'] : 1;
-	$addonQuota = $params['configoptions']['addonQuota'] ? $params['configoptions']['addonQuota'] : 0;
-    $newAddQuota = $params['configoptions']['newAddQuota'] ? $params['configoptions']['newAddQuota'] : 0;
-	$accountQuota = ($quota + $addonQuota + $newAddQuota);
-	$seafileURL = $params['serverhttpprefix'] . '://' . $params['serverhostname'] . ':' . $params['serverport'];
-	$seafileAPI = new Sf_Admin($seafileURL,$params['serverusername'],$params['serverpassword']);
-	$response = $seafileAPI->login();
-	if (isset($response['error_msg'])) {
-		logModuleCall(
-			'seafile',
-			__FUNCTION__,
-			$params,
-			'Error: could not login to ' . $seafileURL,
-			$response
-		);
-	    return 'Error: could not login to ' . $seafileURL;
-	}
-	$userAccount = $seafileAPI->getAccount($params['username']);
-	if(isset($userAccount['error_msg'])) {
-		logModuleCall(
-			'seafile',
-			__FUNCTION__,
-			$params,
-			'Error: could not find account ' . $params['username'],
-			$userAccount
-		);
-		return 'Error: could not find account ' . $params['username'];
-	}
-	$result = $seafileAPI->modifyAccount(array('email' => $userAccount['email'], 'quota_total' => $accountQuota * 1024));
-	if(isset($result['error_msg'])) {
-		logModuleCall(
-			'seafile',
-			__FUNCTION__,
-			$params,
-			'Error: could not update quota for ' . $userAccount['email'],
-			$result
-		);
-		return 'Error: could not update quota for ' . $userAccount['email'];
-	} elseif ($result['quota_total'] != ($accountQuota * 1048576)) {
-		logModuleCall(
-			'seafile',
-			__FUNCTION__,
-			$params,
-			'Error: quota for ' . $userAccount['email'] . ' not updated',
-			$result
-		);
-		return 'Error: quota for ' . $userAccount['email'] . ' not updated';
-	}
-    try {
-        Capsule::table('tblhosting')
-            ->where('id', '=', $params['serviceid'])
-            ->update(
-                array(
-                    'disklimit' => $userAccount['quota_total'] / 1024,
-                )
-            );
-    } catch (Exception $e) {
-        logModuleCall(
-            'seafile',
-            __FUNCTION__,
-            $params,
-            'Error: could not update quota in database',
-            $e->getMessage()
-        );
-        return 'Error: could not update quota in database';
-    }
-    if(seafileUpdateQuota($params) != 'success') {
-        return 'Error: could not update addonQuota in database';
-    };
-    return 'success';
-}
-
-/**
- * Provision a new instance of a SeaFile account.
- *
- * Attempt to provision a new SeaFile account. This is
- * called any time provisioning is requested inside of WHMCS. Depending upon the
- * configuration, this can be any of:
- * * When a new order is placed
- * * When an invoice for a new order is paid
- * * Upon manual request by an admin user
- *
- * @param array $params common module parameters
- *
- * @see https://developers.whmcs.com/provisioning-modules/module-parameters/
- *
- * @return string 'success' or an error message
- */
-function seafile_CreateAccount($params) {
-	$firstName     = $params['customfields']['firstname'];
-	$lastName      = $params['customfields']['lastname'];
-	$loginEMail    = $params['customfields']['login'];
-	$loginPassword = $params['customfields']['password'];
-	$baseQuota     = $params['configoption1'];
-	$addonQuota    = $params['configoptions']['addonQuota'] ? $params['configoptions']['addonQuota'] : 0;
-	$newAddQuota   = $params['configoptions']['newAddQuota'] ? $params['configoptions']['newAddQuota'] : 0;
-	
-	//error_log( print_r($params,true)  );
-	
-	$seafileURL = $params['serverhttpprefix'] . '://' . $params['serverhostname'] . ':' . $params['serverport'];
-	$seafileAPI = new Sf_Admin($seafileURL,$params['serverusername'],$params['serverpassword']);
-	$response = $seafileAPI->login();
-	if (isset($response['error_msg'])) {
-		logModuleCall(
-			'seafile',
-			__FUNCTION__,
-			$params,
-			'Error: could not login to ' . $seafileURL,
-			$response
-		);
-	    return 'Error: could not login to ' . $seafileURL;
-	}
-	$existingAccount = $seafileAPI->getAccount($loginEMail);
-	if(!isset($existingAccount['error_msg'])) {
-		return 'Error: account already exists ' . $loginEMail;
-	}
-	$accountQuota = ($baseQuota + $addonQuota + $newAddQuota) * 1024;
-	$newAccount = array();
-	$newAccount['email'] = $loginEMail;
-	$newAccount['name'] = $firstName . ' ' . $lastName;
-	$newAccount['isActive'] = 1;
-	$newAccount['isStaff'] = 0;
-	$newAccount['password'] = $loginPassword;
-	$newAccount['note'] = 'Account created from WHCMS for client ' . $params['userid'];
-	$newAccount['quota_total'] = $accountQuota;
-	error_log("Seafile:Create Account for " . $loginEMail . " with " . $accountQuota . "MB");
-	$result = $seafileAPI->createAccount($newAccount);
-	if(isset($result['error_msg'])) {
-	    logModuleCall(
-        	'seafile',
-        	__FUNCTION__,
-        	$params,
-    		'Error: could not create account ' . $loginEMail,
-    		$result
-		);
-	    return 'Error: could not create account ' . $loginEMail;
-	}
-	try {
-    	    Capsule::table('tblhosting')
-        	->where('id', '=', $params['serviceid'])
-        	->update(
-            	    array(
-                	'username'  => $loginEMail,
-                	'password'  => $params['customfields']['password'],
-                	'disklimit' => $accountQuota,
-					'diskusage' => 0,
-					'domain'	=> $loginEMail,
-            	    )
-        	);
-	} catch (\Exception $e) {
-    	    logModuleCall(
-        	'seafile',
-        	__FUNCTION__,
-        	$params,
-        	'Error: could save username & password in database',
-        	$e->getMessage()
-    	    );
-    	    return 'Error: could save username & password in database';
-	}
-	if(seafileUpdateQuota($params) != 'success') {
-    	    return 'Error: could not update addonQuota in database';
-	};
-	return 'success';
-}
-
-/**
- * Set a SeaFile account to status inactive.
- *
- * Called when a suspension is requested. This is invoked automatically by WHMCS
- * when a product becomes overdue on payment or can be called manually by admin
- * user.
- *
- * @param array $params common module parameters
- *
- * @see https://developers.whmcs.com/provisioning-modules/module-parameters/
- *
- * @return string 'success' or an error message
- */
-function seafile_SuspendAccount($params) {
-	$seafileURL = $params['serverhttpprefix'] . '://' . $params['serverhostname'] . ':' . $params['serverport'];
-	$seafileAPI = new Sf_Admin($seafileURL,$params['serverusername'],$params['serverpassword']);
-	$response = $seafileAPI->login();
-	if (isset($response['error_msg'])) {
-		logModuleCall(
-			'seafile',
-			__FUNCTION__,
-			$params,
-			'Error: could not login to ' . $seafileURL,
-			$response
-		);
-	    return 'Error: could not login to ' . $seafileURL;
-	}
-	$userAccount = $seafileAPI->getAccount($params['username']);
-	if(isset($userAccount['error_msg'])) {
-		logModuleCall(
-			'seafile',
-			__FUNCTION__,
-			$params,
-			'Error: could not find account ' . $params['username'],
-			$userAccount
-		);
-		return 'Error: could not find account ' . $params['username'];
-	}
-	$result = $seafileAPI->modifyAccount(array('email' => $userAccount['email'], 'is_active' => 0));
-	if(isset($result['error_msg'])) {
-	    logModuleCall(
-    		'seafile',
-    		__FUNCTION__,
-    		$params,
-    		'Error: could not suspend ' . $params['username'],    	    
-    		$result
-    	);
-	    return 'Error: could not suspend ' . $params['username'];
-	} elseif ($result['update_status_tip'] != 'Edit succeeded') {
-	    logModuleCall(
-    		'seafile',
-    		__FUNCTION__,
-    		$params,
-    		'Error: ' . $params['username'] . ' not deactivated',    	    
-    		$result
-    	);
-	    return 'Error: ' . $params['username'] . ' not deactivated';
-	}
-	return 'success';
-}
-
-/**
- * Set a SeaFile account to status active.
- *
- * Called when an un-suspension is requested. This is invoked
- * automatically upon payment of an overdue invoice for a product, or
- * can be called manually by admin user.
- *
- * @param array $params common module parameters
- *
- * @see https://developers.whmcs.com/provisioning-modules/module-parameters/
- *
- * @return string 'success' or an error message
- */
-function seafile_UnsuspendAccount($params) {
-	$seafileURL = $params['serverhttpprefix'] . '://' . $params['serverhostname'] . ':' . $params['serverport'];
-	$seafileAPI = new Sf_Admin($seafileURL,$params['serverusername'],$params['serverpassword']);
-	$response = $seafileAPI->login();
-	if (isset($response['error_msg'])) {
-		logModuleCall(
-			'seafile',
-			__FUNCTION__,
-			$params,
-			'Error: could not login to ' . $seafileURL,
-			$response
-		);
-	    return 'Error: could not login to ' . $seafileURL;
-	}
-	$userAccount = $seafileAPI->getAccount($params['username']);
-	if(isset($userAccount['error_msg'])) {
-		logModuleCall(
-			'seafile',
-			__FUNCTION__,
-			$params,
-			'Error: could not find account ' . $params['username'],
-			$userAccount
-		);
-		return 'Error: could not find account ' . $params['username'];
-	}
-	$result = $seafileAPI->modifyAccount(array('email' => $userAccount['email'], 'is_active' => 1));
-	if(isset($result['error_msg'])) {
-	    logModuleCall(
-    		'seafile',
-    		__FUNCTION__,
-    		$params,
-    		'Error: could not suspend ' . $params['username'],    	    
-    		$result
-    	);
-	    return 'Error: could not suspend ' . $params['username'];
-	} elseif ($result['update_status_tip'] != 'Edit succeeded') {
-	    logModuleCall(
-    		'seafile',
-    		__FUNCTION__,
-    		$params,
-    		'Error: ' . $params['username'] . ' not activated',    	    
-    		$result
-    	);
-	    return 'Error: ' . $params['username'] . ' not activated';
-	}
-	return 'success';
-}
-
-
-/**
- * Removes a SeaFile account.
- *
- * Called when a termination is requested. This can be invoked automatically for
- * overdue products if enabled, or requested manually by an admin user.
- *
- * @param array $params common module parameters
- *
- * @see https://developers.whmcs.com/provisioning-modules/module-parameters/
- *
- * @return string 'success' or an error message
- */
-function seafile_TerminateAccount($params) {
-	$seafileURL = $params['serverhttpprefix'] . '://' . $params['serverhostname'] . ':' . $params['serverport'];
-	$seafileAPI = new Sf_Admin($seafileURL,$params['serverusername'],$params['serverpassword']);
-	$response = $seafileAPI->login();
-	if (isset($response['error_msg'])) {
-		logModuleCall(
-			'seafile',
-			__FUNCTION__,
-			$params,
-			'Error: could not login to ' . $seafileURL,
-			$response
-		);
-	    return 'Error: could not login to ' . $seafileURL;
-	}
-	$existingAccount = $seafileAPI->getAccount($params['username']);
-	if(isset($existingAccount['error_msg'])) {
-		logModuleCall(
-			'seafile',
-			__FUNCTION__,
-			$params,
-			'Error: could not find account ' . $params['username'],
-			''
-		);
-		return 'Error: could not find account ' . $params['username'];
-	}
-	//if ($existingAccount['is_active'] == 1) {
-	//	return 'Account '. $params['username'] . ' is active, suspend account first!';
-	//}
-	$result = $seafileAPI->deleteAccount($params['username']);
-	if($result != true) {
-	    logModuleCall(
-    		'seafile',
-    		__FUNCTION__,
-    		$params,
-    		'Error: could not remove ' . $params['username'],    	    
-    		$seafileAPI
-    	    );
-	    return 'Error: could not remove ' . $params['username'];
-	}
-	return 'success';
-}
-
-/**
- * server side password check
- * 
- * recheck the client side password check
- * in case that the client side check has been disabled
- * 
- * @param string $pwd password
- * 
- * @return string missing features or null if the password matches our needs
- */
-function seafileCheckPassword($pwd) {
-    if (strlen($pwd) < 8) {
-        return 'Das das Passwort ist zu kurz. Es werden mind. 8 Zeichen benötigt';
-    }
-
-    if (!preg_match('#[0-9]+#', $pwd)) {
-        return 'Das Passwort muss mindestens eine Zahl enthalten';
-    }
-
-    if (!preg_match('#[A-Z]+#', $pwd)) {
-        return 'Das Passwort muss mindestens einen Grossbuchstaben (A-Z) enthalten';
-    }     
-
-    if (!preg_match('#[a-z]+#', $pwd)) {
-        return 'Das Passwort muss mindestens einen Kleinbuchstaben (a-z) enthalten';
-    }     
-
-    if (!preg_match('#[^\w]+#', $pwd)) {
-        return 'Das Passwort muss mindestens ein Sonderzeichen (.,-:=) enthalten';
-    }
-    return null;
-}
-
-/**
- * Perform an update of customfields to prevent downgrades.
- *
- * Called in changePackage or createAccount functions.
- *
- * @param array $params common module parameters
- *
- * @return *success* or an error
- */
-function seafileUpdateQuota($params) {
-    if(isset($params['configoptions']['addonQuota'])) {
-        $addonQuota = $params['configoptions']['addonQuota'] ? $params['configoptions']['addonQuota'] : 0 ;
-        $newAddQuota = $params['configoptions']['newAddQuota'] ? $params['configoptions']['newAddQuota'] : 0;
-        $addonQuota = $addonQuota + $newAddQuota;
-        $addonQuotaFieldIDObj = Capsule::table('tblproductconfigoptions')
-            ->join('tblhostingconfigoptions', 'tblproductconfigoptions.id', '=', 'tblhostingconfigoptions.configid')
-            ->where('tblhostingconfigoptions.relid', '=', $params['serviceid'])
-            ->where('tblproductconfigoptions.optionname', 'like', 'addonQuota%')
-            ->select('tblhostingconfigoptions.id', 'tblproductconfigoptions.qtymaximum')
-            ->get();
-        if($addonQuota > $addonQuotaFieldIDObj[0]->qtymaximum) {
-            logModuleCall(
-                'seafile',
-                __FUNCTION__,
-                $params,
-                'Info: someone is trying to exceed the maximum size',
-                ''
-            );
-            $addonQuota = $addonQuotaFieldIDObj[0]->qtymaximum;
-        }
-        try {
-            $updateAddonQuota = Capsule::table('tblhostingconfigoptions')
-                ->where('id', $addonQuotaFieldIDObj[0]->id)
-                ->update(
-                    [
-                        'qty' => $addonQuota,
-                    ]
-                );
-        } catch (\Exception $e) {
-            logModuleCall(
-                'seafile',
-                __FUNCTION__,
-                $updateAddonQuota,
-                'Error: could not save addonOuota in database.',
-                $e->getMessage()
-            );
-            return 'Error: could not save addonOuota in database.';
-        }
-        $newAddQuotaFieldIDObj = Capsule::table('tblproductconfigoptions')
-            ->join('tblhostingconfigoptions', 'tblproductconfigoptions.id', '=', 'tblhostingconfigoptions.configid')
-            ->where('tblhostingconfigoptions.relid', '=', $params['serviceid'])
-            ->where('tblproductconfigoptions.optionname', 'like', 'newAddQuota%')
-            ->select('tblhostingconfigoptions.id')
-            ->get();
-        try {
-            $updateNewAddQuota = Capsule::table('tblhostingconfigoptions')
-                ->where('id', $newAddQuotaFieldIDObj[0]->id)
-                ->update(
-                    [
-                        'qty' => '0',
-                    ]
-                );
-        } catch (\Exception $e) {
-            logModuleCall(
-                'seafile',
-                __FUNCTION__,
-                $updateNewAddQuota,
-                'Error: could not reset newAddOuota in database.',
-                $e->getMessage()
-            );
-            return 'Error: could not reset newAddOuota in database.';
-        }
-    }
-    return 'success';
-}
-?>

+ 227 - 0
cwp7.php

@@ -0,0 +1,227 @@
+<?php
+/**
+ * WHMCS cwp7 Provisioning Module
+ *
+ * Provisioning for User Account on the cwp7 Server
+ *
+ * @see https://centos-webpanel.com/
+ * @copyright Copyright (c) Thurdata GmbH 2020
+ * @license GPL
+ */
+use WHMCS\Database\Capsule;
+
+require_once(__DIR__ . '/api/cwp7/Admin.php');
+if (!defined('WHMCS')) {
+	die('This file cannot be accessed directly');
+}
+
+
+function cwp7_ConfigOptions() {
+	$configarray = array(
+		"PACKAGE-NUMBER" => array( "Type" => "text", "Description" => "Package ID", "Default" => "1"),
+		"inode" => array( "Type" => "text" , "Description" => "Max of inode", "Default" => "0",),
+		"nofile" => array( "Type" => "text", "Description" => "Max of nofile", "Default" => "100", ),
+		"nproc" => array( "Type" => "text" , "Description" => "Nproc limit - 40 suggested", "Default" => "40",),
+	);
+	return $configarray;
+}
+function cwp7_CreateAccount($params) {
+	if ($params["server"] == 1) {
+		$postvars = array(
+			'package' => $params["configoption1"],
+			'domain' => $params["domain"],
+			'key' => $params["serveraccesshash"],
+			'action' => 'add',
+			'username' => $params["username"],
+			'user' => $params["username"],
+			'pass' => $params["password"],
+			'email' => $params["clientsdetails"]["email"],
+			'inode' => $params["configoption2"],
+			'nofile' => $params["configoption3"],
+			'nproc' => $params["configoption4"],
+			'server_ips'=>$params["serverip"]
+		);
+		$postdata = http_build_query($postvars);
+		$curl = curl_init();
+		curl_setopt($curl, CURLOPT_URL, 'https://' . $params["serverhostname"] . ':2304/v1/account');
+		curl_setopt($curl, CURLOPT_RETURNTRANSFER,true);
+		curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
+		curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
+		curl_setopt($curl, CURLOPT_POST, true);
+		curl_setopt($curl, CURLOPT_POSTFIELDS, $postdata);
+		$answer = curl_exec($curl);
+		logModuleCall('cwpwhmcs','CreateAccount_UserAccount','https://' . $params["serverhostname"] . ':2304/v1/account/'.$postdata,$answer);
+	}
+	if(strpos($answer,"OK")!==false){$result='success';}else{$result=json_decode($answer,true); $result=$result['msj'];}
+	return $result;
+}
+function cwp7_TerminateAccount($params) {
+	if ($params["server"] == 1) {
+		$postvars = array('key' => $params["serveraccesshash"],'action' => 'del','user' => $params["username"]);
+		$postdata = http_build_query($postvars);
+		$curl = curl_init();
+		curl_setopt($curl, CURLOPT_URL, 'https://' . $params["serverhostname"] . ':2304/v1/account');
+		curl_setopt($curl, CURLOPT_RETURNTRANSFER,true);
+		curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
+		curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
+		curl_setopt($curl, CURLOPT_POST, true);
+		curl_setopt($curl, CURLOPT_POSTFIELDS, $postdata);
+		$answer = curl_exec($curl);
+		logModuleCall('cwpwhmcs','TerminateAccount','https://' . $params["serverhostname"] . ':2304/v1/account/'.$postdata,$answer);
+	}
+	if(strpos($answer,"OK")!==false){$result='success';}else{$result=json_decode($answer,true); $result=$result['msj'];}
+	return $result;
+}
+function cwp7_SuspendAccount($params) {
+	if ($params["server"] == 1) {
+		$postvars = array('key' => $params["serveraccesshash"],'action' => 'susp','user' => $params["username"]);
+		$postdata = http_build_query($postvars);
+		$curl = curl_init();
+		curl_setopt($curl, CURLOPT_URL, 'https://' . $params["serverhostname"] . ':2304/v1/account');
+		curl_setopt($curl, CURLOPT_RETURNTRANSFER,true);
+		curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
+		curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
+		curl_setopt($curl, CURLOPT_POST, true);
+		curl_setopt($curl, CURLOPT_POSTFIELDS, $postdata);
+		$answer = curl_exec($curl);
+	}
+	if(strpos($answer,"OK")!==false){$result='success';}else{$result=json_decode($answer,true); $result=$result['msj'];}
+	logModuleCall('cwpwhmcs','SuspendAccount','https://' . $params["serverhostname"] . ':2304/v1/account/'.$postdata,$result);
+	return $result;
+}
+function cwp7_UnsuspendAccount($params) {
+	if ($params["server"] == 1) {
+		$postvars = array('key' => $params["serveraccesshash"],'action' => 'unsp','user' => $params["username"]);
+		$postdata = http_build_query($postvars);
+		$curl = curl_init();
+		curl_setopt($curl, CURLOPT_URL, 'https://' . $params["serverhostname"] . ':2304/v1/account');
+		curl_setopt($curl, CURLOPT_RETURNTRANSFER,true);
+		curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
+		curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
+		curl_setopt($curl, CURLOPT_POST, true);
+		curl_setopt($curl, CURLOPT_POSTFIELDS, $postdata);
+		$answer = curl_exec($curl);
+	}
+	if(strpos($answer,"OK")!==false){$result='success';}else{$result=json_decode($answer,true); $result=$result['msj'];}
+	logModuleCall('cwpwhmcs','UnsuspendAccount','https://' . $params["serverhostname"] . ':2304/v1/account'.$postdata,$result);
+	return $result;
+}
+function cwp7_ClientArea($params)
+{
+	$postvars = array('key' => $params["serveraccesshash"], 'action' => 'list', 'user' => $params["username"], 'timer' => 5);
+	$postdata = http_build_query($postvars);
+	$curl = curl_init();
+	curl_setopt($curl, CURLOPT_URL, 'https://' . $params["serverhostname"] . ':2304/v1/user_session');
+	curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
+	curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
+	curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
+	curl_setopt($curl, CURLOPT_POST, true);
+	curl_setopt($curl, CURLOPT_POSTFIELDS, $postdata);
+	$answer = curl_exec($curl);
+	$arry = (json_decode($answer, true)); //die;F
+	$link = $arry['msj']['details'];
+	$linkautologin = $link[0]['url'];
+	logModuleCall('cwpwhmcs', 'cwp7_LoginLink', 'https://' . $params["serverhostname"] . ':2304/v1/user_session' . $postdata, $answer);
+
+	return "<a href=\"{$linkautologin}\" target=\"_blank\" style=\"color:#cc0000\">Login to Control Panel</a>";
+}
+function cwp7_AdminLink($params) {
+	$code = '<form action="https://'.$params["serverhostname"].':2031" method="post" target="_blank">
+		<input type="submit" value="Login to Control Panel" />
+		</form>';
+	return $code;
+}
+function cwp7_LoginLink($params) {
+	$postvars = array('key' => $params["serveraccesshash"],'action' => 'list','user' => $params["username"],'timer'=>5);
+	$postdata = http_build_query($postvars);
+	$curl = curl_init();
+	curl_setopt($curl, CURLOPT_URL, 'https://' . $params["serverhostname"] . ':2304/v1/user_session');
+	curl_setopt($curl, CURLOPT_RETURNTRANSFER,true);
+	curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
+	curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
+	curl_setopt($curl, CURLOPT_POST, true);
+	curl_setopt($curl, CURLOPT_POSTFIELDS, $postdata);
+	$answer = curl_exec($curl);
+	$arry=(json_decode($answer,true)); //die;F
+	$link=$arry['msj']['details'];
+	$linkautologin=$link[0]['url'];
+	logModuleCall('cwpwhmcs','cwp7_LoginLink','https://' . $params["serverhostname"] . ':2304/v1/user_session'.$postdata,$answer);
+
+	echo "<a href=\"{$linkautologin}\" target=\"_blank\" style=\"color:#cc0000\">Control Panel</a>";
+}
+function cwp7_ChangePassword($params){
+	$postvars = array('key' => $params["serveraccesshash"],'acction' => 'udp','user' => $params["username"], 'pass' =>$params["password"]);
+	$postdata = http_build_query($postvars);
+	$curl = curl_init();
+	curl_setopt($curl, CURLOPT_URL, 'https://'. $params["serverhostname"] . ':2304/v1/changepass');
+	curl_setopt($curl, CURLOPT_RETURNTRANSFER,true);
+	curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
+	curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
+	curl_setopt($curl, CURLOPT_POST, true);
+	curl_setopt($curl, CURLOPT_POSTFIELDS, $postdata);
+	$answer = curl_exec($curl);
+	if(strpos($answer,"OK")!==false){$result='success';}else{$result=json_decode($answer,true); $result=$result['msj'];}
+	logModuleCall('cwpwhmcs','ChangePassword','https://' . $params["serverhostname"] . ':2304/v1/changepass'.$postdata,$result);
+	return $result;
+}
+function cwp7_ChangePackage($params){
+	$postvars = array("key" => $params["serveraccesshash"],"action"=>'udp','user' => $params["username"],'package'=>$params["configoption1"].'@');
+	$postdata = http_build_query($postvars);
+	$curl = curl_init();
+
+	curl_setopt($curl, CURLOPT_URL, 'https://'. $params["serverhostname"] . ':2304/v1/account');
+	curl_setopt($curl, CURLOPT_RETURNTRANSFER,true);
+	curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
+	curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
+	curl_setopt($curl, CURLOPT_POST, true);
+	curl_setopt($curl, CURLOPT_POSTFIELDS, $postdata);
+	$answer = curl_exec($curl);
+	curl_close($curl);
+
+	if(strpos($answer,"OK")!==false){$result='success';}else{$result=json_decode($answer,true); $result=$result['msj'];}
+	logModuleCall('cwpwhmcs','ChangePackage','https://' . $params["serverhostname"] . ':2304/v1/packages'.$postdata,$answer);
+	return $result;
+}
+function cwp7_UsageUpdate($params) {
+	$postvars = array('key' => $params["serveraccesshash"],'action' => 'list');
+	$postdata = http_build_query($postvars);
+	$curl = curl_init();
+	curl_setopt($curl, CURLOPT_URL, 'https://'. $params["serverhostname"] . ':2304/v1/account');
+	curl_setopt($curl, CURLOPT_RETURNTRANSFER,true);
+	curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
+	curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
+	curl_setopt($curl, CURLOPT_POST, true);
+	curl_setopt($curl, CURLOPT_POSTFIELDS, $postdata);
+	if (curl_errno($curl)) {
+		$error_msg = curl_error($curl);
+	}
+	$answer = curl_exec($curl);
+	$resp=json_decode($answer,true);
+
+	if($resp['status']=='OK'){
+		$results=$resp['msj'];
+		for($i=0;$i<count($results);$i++){
+			$date=date('Y-m-d H:i:s');
+			if($results[$i]['diskusage']==''){$diskusage=0;}else{$diskusage=trim($results[$i]['diskusage']);}
+			if($results[$i]['disklimit']==''){$disklimit=0;}else{$disklimit=trim($results[$i]['disklimit']);}
+			if($results[$i]['bandwidth']==''){$bandwidth=0;}else{$bandwidth=trim($results[$i]['bandwidth']);}
+			if($results[$i]['bwlimit']==''){$bwlimit=0;}else{$bwlimit=trim($results[$i]['bwlimit']);}
+			$domian=trim($results[$i]['domain']);
+
+			try {
+				\WHMCS\Database\Capsule::table('tblhosting')
+					->where('dedicatedip', $results[$i]['ip_address'])
+					->where('domain', $domian)
+					->update([
+						'diskusage' => $diskusage,
+						'disklimit' => $disklimit,
+						'bwusage' => $bandwidth,
+						'bwlimit' => $bwlimit,
+						'lastupdate' => date('Y-m-d H:i:S'),
+					]);
+			} catch (\Exception $e) {
+				logActivity('ERROR: Unable to update server usage: ' . $e->getMessage());
+			}
+		}
+	}
+}

+ 0 - 0
CWPAddressAvailable.php → cwp7AddressAvailable.php