|
|
@@ -10,8 +10,8 @@
|
|
|
* @license GPL
|
|
|
*/
|
|
|
|
|
|
-if (!defined("WHMCS")) {
|
|
|
- die("This file cannot be accessed directly");
|
|
|
+if (!defined('WHMCS')) {
|
|
|
+ die('This file cannot be accessed directly');
|
|
|
}
|
|
|
use WHMCS\Database\Capsule;
|
|
|
|
|
|
@@ -20,211 +20,13 @@ use WHMCS\Database\Capsule;
|
|
|
* This is an extend version of:
|
|
|
* @see https://github.com/alloylab/zimbra-admin-api-soap-php
|
|
|
*/
|
|
|
-require_once("api/Zm/Auth.php");
|
|
|
-require_once("api/Zm/Account.php");
|
|
|
-require_once("api/Zm/Domain.php");
|
|
|
-require_once("api/Zm/Server.php");
|
|
|
+require_once('api/Zm/Auth.php');
|
|
|
+require_once('api/Zm/Account.php');
|
|
|
+require_once('api/Zm/Domain.php');
|
|
|
+require_once('api/Zm/Server.php');
|
|
|
|
|
|
/**
|
|
|
- * Helper function to get the zimbra server access data from whmcs database
|
|
|
- *
|
|
|
- * @return array $accessData {
|
|
|
- * @type string 'zimbraServer' zimbra server IP address
|
|
|
- * @type string 'adminUser' zimbra admin username
|
|
|
- * @type string 'password' zimbra admin password
|
|
|
- * } or false in case of error
|
|
|
- */
|
|
|
-function zimbraSingleGetAccess()
|
|
|
-{
|
|
|
- $accessData = array('zimbraServer' => '', 'adminUser' => '', 'adminPass' => '');
|
|
|
- $whmcs = App::self();
|
|
|
- $serverGroupID = $whmcs->get_req_var('servergroup');
|
|
|
- $action = $whmcs->get_req_var('action');
|
|
|
- if(($action == 'module-settings') || ($action == 'ConfigOptions') || ($action == 'save')) {
|
|
|
- $productID = $whmcs->get_req_var('id');
|
|
|
- $serverGroupIDObj = Capsule::table('tblproducts')
|
|
|
- ->select('servergroup')
|
|
|
- ->where('id', '=', $productID)
|
|
|
- ->get();
|
|
|
- $serverGroupID = $serverGroupIDObj[0]->servergroup;
|
|
|
- $serverIDObj = Capsule::table('tblservergroupsrel')
|
|
|
- ->select('serverid')
|
|
|
- ->where('groupid', '=', $serverGroupID)
|
|
|
- ->get();
|
|
|
- $serverID = $serverIDObj[0]->serverid;
|
|
|
- } else {
|
|
|
- $id = $whmcs->get_req_var('id');
|
|
|
- $serverIDObj = Capsule::table('tblhosting')
|
|
|
- ->select('server')
|
|
|
- ->where('id', '=', $id)
|
|
|
- ->get();
|
|
|
- $serverID = $serverIDObj[0]->server;
|
|
|
- }
|
|
|
- $server = Capsule::table('tblservers')
|
|
|
- ->select('ipaddress', 'username', 'password')
|
|
|
- ->where('id', '=', $serverID)
|
|
|
- ->where('active', '=', 1)
|
|
|
- ->get();
|
|
|
- $accessData['zimbraServer'] = $server[0]->ipaddress;
|
|
|
- $accessData['adminUser'] = $server[0]->username;
|
|
|
- $adminPassCrypt = $server[0]->password;
|
|
|
- $adminPassDecrypt = localAPI('DecryptPassword', array('password2' => $adminPassCrypt));
|
|
|
- if ($adminPassDecrypt['result'] == 'success') {
|
|
|
- $accessData['adminPass'] = $adminPassDecrypt['password'];
|
|
|
- } else {
|
|
|
- logModuleCall(
|
|
|
- 'zimbrasingle',
|
|
|
- __FUNCTION__,
|
|
|
- $adminPassCrypt,
|
|
|
- "Error: cloud not decrypt admin password" ,
|
|
|
- $adminPassDecrypt
|
|
|
- );
|
|
|
- return false;
|
|
|
- }
|
|
|
- return $accessData;
|
|
|
-}
|
|
|
-
|
|
|
-/**
|
|
|
- * Helper function creates all necessary custom fields depending on selected configuration options
|
|
|
- *
|
|
|
- * @param array $packageconfigoption {
|
|
|
- * @type string 1 class of service
|
|
|
- * @type string 2 comma seperated list of maildomains
|
|
|
- * }
|
|
|
- * @return bool true in case of success or false on any error
|
|
|
- */
|
|
|
-function zimbraSingleCreateCustomFields($packageconfigoption)
|
|
|
-{
|
|
|
- $whmcs = App::self();
|
|
|
- $productID = $whmcs->get_req_var('id');
|
|
|
- try {
|
|
|
- $customFieldIDsObj = Capsule::table('tblcustomfields')
|
|
|
- ->where('relid', '=', $productID)
|
|
|
- ->select('id')
|
|
|
- ->get();
|
|
|
- $customFieldIDs = recursiveFindAll((array)$customFieldIDsObj, 'id');
|
|
|
- Capsule::table('tblcustomfields')
|
|
|
- ->updateOrInsert(
|
|
|
- array(
|
|
|
- 'id' => $customFieldIDs[0] ? $customFieldIDs[0] : '',
|
|
|
- ),
|
|
|
- array(
|
|
|
- 'type' => 'product',
|
|
|
- 'relid' => $productID,
|
|
|
- 'fieldname' => 'givenname | Vorname',
|
|
|
- 'fieldtype' => 'text',
|
|
|
- 'required' => 'on',
|
|
|
- 'showorder' => 'on',
|
|
|
- 'sortorder' => '0'
|
|
|
- )
|
|
|
- );
|
|
|
- Capsule::table('tblcustomfields')
|
|
|
- ->updateOrInsert(
|
|
|
- array(
|
|
|
- 'id' => $customFieldIDs[1] ? $customFieldIDs[1] : '',
|
|
|
- ),
|
|
|
- array(
|
|
|
- 'type' => 'product',
|
|
|
- 'relid' => $productID,
|
|
|
- 'fieldname' => 'sn | Nachname',
|
|
|
- 'fieldtype' => 'text',
|
|
|
- 'required' => 'on',
|
|
|
- 'showorder' => 'on',
|
|
|
- 'sortorder' => '1'
|
|
|
- )
|
|
|
- );
|
|
|
- Capsule::table('tblcustomfields')
|
|
|
- ->updateOrInsert(
|
|
|
- array(
|
|
|
- 'id' => $customFieldIDs[2] ? $customFieldIDs[2] : '',
|
|
|
- ),
|
|
|
- array(
|
|
|
- 'type' => 'product',
|
|
|
- 'relid' => $productID,
|
|
|
- 'fieldname' => 'username | E-Mail Name',
|
|
|
- 'fieldtype' => 'text',
|
|
|
- 'required' => 'on',
|
|
|
- 'showorder' => 'on',
|
|
|
- 'sortorder' => '2'
|
|
|
- )
|
|
|
- );
|
|
|
- Capsule::table('tblcustomfields')
|
|
|
- ->updateOrInsert(
|
|
|
- array(
|
|
|
- 'id' => $customFieldIDs[3] ? $customFieldIDs[3] : '',
|
|
|
- ),
|
|
|
- array(
|
|
|
- 'type' => 'product',
|
|
|
- 'relid' => $productID,
|
|
|
- 'fieldname' => 'maildomain | Mail Domaine',
|
|
|
- 'fieldtype' => 'dropdown',
|
|
|
- 'fieldoptions' => implode(',', $packageconfigoption[2]),
|
|
|
- 'required' => 'on',
|
|
|
- 'showorder' => 'on',
|
|
|
- 'sortorder' => '3'
|
|
|
- )
|
|
|
- );
|
|
|
- Capsule::table('tblcustomfields')
|
|
|
- ->updateOrInsert(
|
|
|
- array(
|
|
|
- 'id' => $customFieldIDs[4] ? $customFieldIDs[4] : '',
|
|
|
- ),
|
|
|
- array(
|
|
|
- 'type' => 'product',
|
|
|
- 'relid' => $productID,
|
|
|
- 'fieldname' => 'password | Password',
|
|
|
- 'fieldtype' => 'password',
|
|
|
- 'required' => 'on',
|
|
|
- 'showorder' => 'on',
|
|
|
- 'sortorder' => '4'
|
|
|
- )
|
|
|
- );
|
|
|
- Capsule::table('tblcustomfields')
|
|
|
- ->updateOrInsert(
|
|
|
- array(
|
|
|
- 'id' => $customFieldIDs[5] ? $customFieldIDs[5] : '',
|
|
|
- ),
|
|
|
- array(
|
|
|
- 'type' => 'product',
|
|
|
- 'relid' => $productID,
|
|
|
- 'fieldname' => 'pwrepeat | Password wiederholen',
|
|
|
- 'fieldtype' => 'password',
|
|
|
- 'required' => 'on',
|
|
|
- 'showorder' => 'on',
|
|
|
- 'sortorder' => '5'
|
|
|
- )
|
|
|
- );
|
|
|
- Capsule::table('tblcustomfields')
|
|
|
- ->updateOrInsert(
|
|
|
- array(
|
|
|
- 'id' => $customFieldIDs[6] ? $customFieldIDs[6] : '',
|
|
|
- ),
|
|
|
- array(
|
|
|
- 'type' => 'product',
|
|
|
- 'relid' => $productID,
|
|
|
- 'fieldname' => 'cos | Class of Service',
|
|
|
- 'fieldtype' => 'dropdown',
|
|
|
- 'fieldoptions' => $packageconfigoption[1],
|
|
|
- 'adminonly' => 'on',
|
|
|
- 'required' => 'on',
|
|
|
- 'sortorder' => '6'
|
|
|
- )
|
|
|
- );
|
|
|
- return true;
|
|
|
- } catch (\Exception $e) {
|
|
|
- logModuleCall(
|
|
|
- 'zimbrasingle',
|
|
|
- __FUNCTION__,
|
|
|
- $params,
|
|
|
- "Error: could not create custom fields",
|
|
|
- $e->getMessage()
|
|
|
- );
|
|
|
- return false;
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-/**
|
|
|
- * Helper function to find values of a named key in a multidimensional arrays
|
|
|
+ * Helper function to find values of a named key in a multidimensional arrays or objects
|
|
|
*
|
|
|
* @param array $haystack mixed data
|
|
|
* @param string $needle key to search for values
|
|
|
@@ -233,7 +35,7 @@ function zimbraSingleCreateCustomFields($packageconfigoption)
|
|
|
function recursiveFindAll($haystack, $needle)
|
|
|
{
|
|
|
$values = array();
|
|
|
- $iterator = new RecursiveArrayIterator($haystack);
|
|
|
+ $iterator = new RecursiveArrayIterator((array)$haystack);
|
|
|
$recursive = new RecursiveIteratorIterator(
|
|
|
$iterator,
|
|
|
RecursiveIteratorIterator::SELF_FIRST
|
|
|
@@ -246,48 +48,6 @@ function recursiveFindAll($haystack, $needle)
|
|
|
return $values;
|
|
|
}
|
|
|
|
|
|
-/**
|
|
|
- * Helper function to check a password strength
|
|
|
- *
|
|
|
- * @param string $pwd password to check
|
|
|
- * @return string $message what is missing in the password (empty if it is okay)
|
|
|
- */
|
|
|
-function zimbraSingleCheckPassword($pwd)
|
|
|
-{
|
|
|
- $message = '';
|
|
|
- if (strlen($pwd) < 8) {
|
|
|
- $message .= "Das das Passwort ist zu kurz. Es werden mind. 8 Zeichen benötigt" . PHP_EOL;
|
|
|
- }
|
|
|
- if (!preg_match("#[0-9]+#", $pwd)) {
|
|
|
- $message .= "Das Passwort muss mindestens eine Zahl enthalten" . PHP_EOL;
|
|
|
- }
|
|
|
- if (!preg_match("#[A-Z]+#", $pwd)) {
|
|
|
- $message .= "Das Passwort muss mindestens einen Grossbuchstaben (A-Z) enthalten" . PHP_EOL;
|
|
|
- }
|
|
|
- if (!preg_match("#[a-z]+#", $pwd)) {
|
|
|
- $message .= "Das Passwort muss mindestens einen Kleinbuchstaben (a-z) enthalten" . PHP_EOL;
|
|
|
- }
|
|
|
- if (!preg_match("#[^\w]+#", $pwd)) {
|
|
|
- $message .= "Das Passwort muss mindestens ein Sonderzeichen (.,-:=) enthalten" . PHP_EOL;
|
|
|
- }
|
|
|
- return $message;
|
|
|
-}
|
|
|
-
|
|
|
-/**
|
|
|
- * Convert raw byte value to human readable
|
|
|
- *
|
|
|
- * Helper function to convert byte in huam readable format
|
|
|
- *
|
|
|
- * @param int $bytes value in bytes
|
|
|
- * @return string value rounded and in human readable units
|
|
|
- */
|
|
|
-function bytesToHuman($bytes)
|
|
|
-{
|
|
|
- $units = ['B', 'KB', 'MB', 'GB', 'TB', 'PB'];
|
|
|
- for ($i = 0; $bytes > 1024; $i++) $bytes /= 1024;
|
|
|
- return round($bytes, 2) . ' ' . $units[$i];
|
|
|
-}
|
|
|
-
|
|
|
/**
|
|
|
* Define module related meta data.
|
|
|
*
|
|
|
@@ -330,26 +90,25 @@ function zimbraSingle_MetaData()
|
|
|
*/
|
|
|
function zimbraSingle_TestConnection($params)
|
|
|
{
|
|
|
- $auth = new Zm_Auth($params['serverip'], $params['serverusername'], $params['serverpassword'], "admin");
|
|
|
+ $auth = new Zm_Auth($params['serverip'], $params['serverusername'], $params['serverpassword'], 'admin');
|
|
|
$login = $auth->login();
|
|
|
- if(is_a($login, "Exception")) {
|
|
|
+ if(is_a($login, 'Exception')) {
|
|
|
logModuleCall(
|
|
|
'zimbrasingle',
|
|
|
__FUNCTION__,
|
|
|
$params,
|
|
|
- "Connection test to " . $params['serverip'] . " failed: Cannot login",
|
|
|
+ 'Connection failed, cannot login to ' . $params['serverip'],
|
|
|
$login->getMessage()
|
|
|
);
|
|
|
return array(
|
|
|
'success' => false,
|
|
|
- 'error' => "Connection test to " . $params['serverip'] . " failed, the error was: " . $login->getMessage(),
|
|
|
- );
|
|
|
- } else {
|
|
|
- return array(
|
|
|
- 'success' => true,
|
|
|
- 'error' => '',
|
|
|
+ 'error' => 'Connection failed, cannot login to ' . $params['serverip'],
|
|
|
);
|
|
|
}
|
|
|
+ return array(
|
|
|
+ 'success' => true,
|
|
|
+ 'error' => '',
|
|
|
+ );
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -384,61 +143,32 @@ function zimbraSingle_TestConnection($params)
|
|
|
*/
|
|
|
function zimbraSingle_ClientArea($params)
|
|
|
{
|
|
|
- $accessData = zimbraSingleGetAccess();
|
|
|
$clientInfo = array();
|
|
|
- $accountName = $params['customfields']['username'] . '@' . $params['customfields']['maildomain'];
|
|
|
- $api = new Zm_Auth($accessData['zimbraServer'], $accessData['adminUser'], $accessData['adminPass'], "admin");
|
|
|
+ $api = new Zm_Auth($params['serverip'], $params['serverusername'], $params['serverpassword'], 'admin');
|
|
|
$login = $api->login();
|
|
|
- if(is_a($login, "Exception")) {
|
|
|
+ if(is_a($login, 'Exception')) {
|
|
|
logModuleCall(
|
|
|
'zimbrasingle',
|
|
|
__FUNCTION__,
|
|
|
$params,
|
|
|
- "Error: cannot login to " . $accessData['zimbraServer'],
|
|
|
- $login
|
|
|
+ 'Error: cannot login to ' . $accessData['zimbraServer'],
|
|
|
+ $login->getMessage()
|
|
|
);
|
|
|
return false;
|
|
|
}
|
|
|
$apiAccountManager = new Zm_Account($api);
|
|
|
- $quota = $apiAccountManager->getQuota($accountName);
|
|
|
- if(is_a($quota, "Exception")) {
|
|
|
+ $accountInfo = $apiAccountManager->getAccountInfo($params['username']);
|
|
|
+ if(is_a($accountInfo, 'Exception')) {
|
|
|
logModuleCall(
|
|
|
'zimbrasingle',
|
|
|
__FUNCTION__,
|
|
|
$params,
|
|
|
- "Error : could not find $accountName",
|
|
|
- $quota
|
|
|
+ 'Error: could not gather informations for ' . $params['username'],
|
|
|
+ $accountInfo->getMessage()
|
|
|
);
|
|
|
return false;
|
|
|
}
|
|
|
- $response = $apiAccountManager->getMailbox($accountName);
|
|
|
- if(is_a($response, "Exception")) {
|
|
|
- logModuleCall(
|
|
|
- 'zimbrasingle',
|
|
|
- __FUNCTION__,
|
|
|
- $params,
|
|
|
- "Error: could not fetch mailbox info for $accountName",
|
|
|
- $response
|
|
|
- );
|
|
|
- return false;
|
|
|
- }
|
|
|
- $mboxSize = $response['S'];
|
|
|
- $usagePercent = $mboxSize * 100 / $quota;
|
|
|
- $clientInfo['quota'] = bytesToHuman($quota);
|
|
|
- $clientInfo['size'] = bytesToHuman($mboxSize);
|
|
|
- $clientInfo['usage'] = round($usagePercent, 2);
|
|
|
- $response = $apiAccountManager->getAccountInfo($accountName);
|
|
|
- if(is_a($response, "Exception")) {
|
|
|
- logModuleCall(
|
|
|
- 'zimbrasingle',
|
|
|
- __FUNCTION__,
|
|
|
- $params,
|
|
|
- "Error: could not gather informations for $accountName",
|
|
|
- $response
|
|
|
- );
|
|
|
- return false;
|
|
|
- }
|
|
|
- $webmailUrl = recursiveFindAll( $response, 'PUBLICMAILURL');
|
|
|
+ $webmailUrl = recursiveFindAll($accountInfo, 'PUBLICMAILURL');
|
|
|
$clientInfo['webmailurl'] = $webmailUrl[0]['DATA'];
|
|
|
return array(
|
|
|
'templatefile' => 'clientarea',
|
|
|
@@ -446,15 +176,24 @@ function zimbraSingle_ClientArea($params)
|
|
|
);
|
|
|
}
|
|
|
|
|
|
+/**
|
|
|
+ * 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 zimbraSingle_UsageUpdate($params) {
|
|
|
- $api = new Zm_Auth($params['serverip'], $params['serverusername'], $params['serverpassword'], "admin");
|
|
|
+ $api = new Zm_Auth($params['serverip'], $params['serverusername'], $params['serverpassword'], 'admin');
|
|
|
$login = $api->login();
|
|
|
- if(is_a($login, "Exception")) {
|
|
|
+ if(is_a($login, 'Exception')) {
|
|
|
logModuleCall(
|
|
|
'zimbrasingle',
|
|
|
__FUNCTION__,
|
|
|
$params,
|
|
|
- "Error: cannot login to " . $params['serverip'],
|
|
|
+ 'Error: cannot login to ' . $params['serverip'],
|
|
|
$login->getMessage()
|
|
|
);
|
|
|
return false;
|
|
|
@@ -467,37 +206,47 @@ function zimbraSingle_UsageUpdate($params) {
|
|
|
->get();
|
|
|
foreach((array)$productsObj as $productObj) {
|
|
|
$product = get_object_vars($productObj[0]);
|
|
|
- $quota = $apiAccountManager->getQuota($product['username']);
|
|
|
- if(is_a($quota, "Exception")) {
|
|
|
+ $accountQuota = $apiAccountManager->getQuota($product['username']);
|
|
|
+ if(is_a($accountQuota, 'Exception')) {
|
|
|
logModuleCall(
|
|
|
'zimbrasingle',
|
|
|
__FUNCTION__,
|
|
|
- $product,
|
|
|
- "Error : could not find " . $product['username'],
|
|
|
- $quota->getMessage()
|
|
|
+ $params,
|
|
|
+ 'Error : could not find quota for ' . $product['username'],
|
|
|
+ $accountQuota->getMessage()
|
|
|
);
|
|
|
}
|
|
|
- $response = $apiAccountManager->getMailbox($product['username']);
|
|
|
- if(is_a($response, "Exception")) {
|
|
|
+ $mboxObj = $apiAccountManager->getMailbox($product['username']);
|
|
|
+ if(is_a($mboxObj, 'Exception')) {
|
|
|
logModuleCall(
|
|
|
'zimbrasingle',
|
|
|
__FUNCTION__,
|
|
|
$params,
|
|
|
- "Error: could not fetch mailbox info for " . $product['username'],
|
|
|
- $response->getMessage()
|
|
|
+ 'Error: could not fetch mailbox info for ' . $product['username'],
|
|
|
+ $mboxObj->getMessage()
|
|
|
);
|
|
|
}
|
|
|
- $mbox = get_object_vars($response);
|
|
|
- $mboxSize = $mbox['S'];
|
|
|
- Capsule::table('tblhosting')
|
|
|
- ->where('id', '=', $product['id'])
|
|
|
- ->update(
|
|
|
- array(
|
|
|
- 'diskusage' => round($mboxSize / 1048576,2),
|
|
|
- 'disklimit' => round($quota / 1048576,2),
|
|
|
- 'lastupdate' => Capsule::raw('now()')
|
|
|
- )
|
|
|
+ $mboxVars = get_object_vars($mboxObj);
|
|
|
+ $mboxSize = $mboxVars['S'];
|
|
|
+ try {
|
|
|
+ Capsule::table('tblhosting')
|
|
|
+ ->where('id', '=', $product['id'])
|
|
|
+ ->update(
|
|
|
+ array(
|
|
|
+ 'diskusage' => round($mboxSize / 1048576,2),
|
|
|
+ 'disklimit' => round($accountQuota / 1048576,2),
|
|
|
+ 'lastupdate' => Capsule::raw('now()')
|
|
|
+ )
|
|
|
+ );
|
|
|
+ } catch (\Exception $e) {
|
|
|
+ logModuleCall(
|
|
|
+ 'zimbrasingle',
|
|
|
+ __FUNCTION__,
|
|
|
+ $params,
|
|
|
+ 'Error: could update usage information for ' . $product['username'],
|
|
|
+ $e->getMessage()
|
|
|
);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -515,36 +264,31 @@ function zimbraSingle_UsageUpdate($params) {
|
|
|
*
|
|
|
* @see https://developers.whmcs.com/provisioning-modules/module-parameters/
|
|
|
*
|
|
|
- * @return string "success" or an error message
|
|
|
+ * @return string 'success' or an error message
|
|
|
*/
|
|
|
function zimbraSingle_ChangePassword($params)
|
|
|
{
|
|
|
- $accessData = zimbraSingleGetAccess();
|
|
|
- if ($checkPW = zimbraSingleCheckPassword($params['password'])) {
|
|
|
- return $checkPW;
|
|
|
- }
|
|
|
- $accountName = $params['customfields']['username'] . '@' . $params['customfields']['maildomain'];
|
|
|
- $api = new Zm_Auth($accessData['zimbraServer'], $accessData['adminUser'], $accessData['adminPass'], "admin");
|
|
|
+ $api = new Zm_Auth($params['serverip'], $params['serverusername'], $params['serverpassword'], 'admin');
|
|
|
$login = $api->login();
|
|
|
- if(is_a($login, "Exception")) {
|
|
|
+ if(is_a($login, 'Exception')) {
|
|
|
logModuleCall(
|
|
|
'zimbrasingle',
|
|
|
__FUNCTION__,
|
|
|
$params,
|
|
|
- "Error: cannot login to " . $accessData['zimbraServer'],
|
|
|
- $login
|
|
|
+ 'Error: cannot login to ' . $params['serverip'],
|
|
|
+ $login->getMessage()
|
|
|
);
|
|
|
return false;
|
|
|
}
|
|
|
$apiAccountManager = new Zm_Account($api);
|
|
|
- $response = $apiAccountManager->setAccountPassword($accountName, $params['password']);
|
|
|
- if(is_a($response, "Exception")) {
|
|
|
+ $response = $apiAccountManager->setAccountPassword($params['username'], $params['password']);
|
|
|
+ if(is_a($response, 'Exception')) {
|
|
|
logModuleCall(
|
|
|
'zimbrasingle',
|
|
|
__FUNCTION__,
|
|
|
$params,
|
|
|
- "Error: password for $accountName could not be set",
|
|
|
- $response
|
|
|
+ 'Error: password could not be set for ' . $params['username'],
|
|
|
+ $response->getMessage()
|
|
|
);
|
|
|
return false;
|
|
|
}
|
|
|
@@ -565,78 +309,96 @@ function zimbraSingle_ChangePassword($params)
|
|
|
*
|
|
|
* @see https://developers.whmcs.com/provisioning-modules/module-parameters/
|
|
|
*
|
|
|
- * @return string "success" or an error message
|
|
|
+ * @return string 'success' or an error message
|
|
|
*/
|
|
|
function zimbraSingle_CreateAccount($params)
|
|
|
{
|
|
|
- $accessData = zimbraSingleGetAccess();
|
|
|
- $api = new Zm_Auth($accessData['zimbraServer'], $accessData['adminUser'], $accessData['adminPass'], "admin");
|
|
|
+ $api = new Zm_Auth($params['serverip'], $params['serverusername'], $params['serverpassword'], 'admin');
|
|
|
$login = $api->login();
|
|
|
- if(is_a($login, "Exception")) {
|
|
|
+ if(is_a($login, 'Exception')) {
|
|
|
logModuleCall(
|
|
|
'zimbrasingle',
|
|
|
__FUNCTION__,
|
|
|
- $accessData,
|
|
|
- "Error: cannot login to " . $accessData['zimbraServer'],
|
|
|
+ $params,
|
|
|
+ 'Error: cannot login to ' . $params['serverip'],
|
|
|
$login->getMessage()
|
|
|
);
|
|
|
- return "Error: cannot login to " . $accessData['zimbraServer'];
|
|
|
+ return $login->getMessage();
|
|
|
}
|
|
|
- $accountName = $params['customfields']['username'] . '@' . $params['customfields']['maildomain'];
|
|
|
+ $params['username'] = $params['customfields']['username'] . '@' . $params['customfields']['maildomain'];
|
|
|
$apiAccountManager = new Zm_Account($api);
|
|
|
- $accountExists = $apiAccountManager->accountExists($accountName);
|
|
|
- if(is_a($accountExists, "Exception")) {
|
|
|
+ $accountExists = $apiAccountManager->accountExists($params['username']);
|
|
|
+ if(is_a($accountExists, 'Exception')) {
|
|
|
logModuleCall(
|
|
|
'zimbrasingle',
|
|
|
__FUNCTION__,
|
|
|
- $accessData,
|
|
|
- "Error: could not verify $accountName",
|
|
|
- $accountExists
|
|
|
+ $params,
|
|
|
+ 'Error: could not verify ' . $params['username'],
|
|
|
+ $accountExists->getMessage()
|
|
|
);
|
|
|
- return "Error: could not verify $accountName";
|
|
|
+ return 'Error: could not verify '. $params['username'];
|
|
|
}
|
|
|
if($accountExists === true) {
|
|
|
- return "Error: account $accountName already exists";
|
|
|
+ return 'Error: account already exists ' . $params['username'];
|
|
|
}
|
|
|
$attrs = array();
|
|
|
- $attrs["gn"] = $params['customfields']["givenname"];
|
|
|
- $attrs["sn"] = $params['customfields']["sn"];
|
|
|
- $attrs["displayName"] = $attrs["gn"] . " " . $attrs["sn"];
|
|
|
+ $attrs['gn'] = $params['customfields']['givenname'];
|
|
|
+ $attrs['sn'] = $params['customfields']['sn'];
|
|
|
+ $attrs['displayName'] = $attrs['gn'] . ' ' . $attrs['sn'];
|
|
|
$passDecrypt = localAPI('DecryptPassword', array('password2' => $params['customfields']['password']));
|
|
|
if ($passDecrypt['result'] == 'success') {
|
|
|
- $params['customfields']['password'] = $passDecrypt['password'];
|
|
|
+ $params['password'] = $passDecrypt['password'];
|
|
|
} else {
|
|
|
logModuleCall(
|
|
|
'zimbrasingle',
|
|
|
__FUNCTION__,
|
|
|
- $params['customfields']['password'],
|
|
|
- "Error: could not decrypt password",
|
|
|
- $passDecrypt
|
|
|
+ $params,
|
|
|
+ 'Error: could not decrypt password',
|
|
|
+ $passDecrypt['message']
|
|
|
);
|
|
|
- return "Error: could not decrypt password";
|
|
|
+ return 'Error: could not decrypt password';
|
|
|
}
|
|
|
$cosID = $apiAccountManager->getCosId($params['configoption1']);
|
|
|
- if(is_a($cosID, "Exception")) {
|
|
|
+ if(is_a($cosID, 'Exception')) {
|
|
|
logModuleCall(
|
|
|
'zimbrasingle',
|
|
|
__FUNCTION__,
|
|
|
- $params['configoption1'],
|
|
|
- "Error: serviceclass not available",
|
|
|
- $cosID
|
|
|
+ $params,
|
|
|
+ 'Error: could not find serviceclass ' . $params['configoption1'],
|
|
|
+ $cosID->getMessage()
|
|
|
);
|
|
|
- return "Error: serviceclass not available";
|
|
|
+ return 'Error: could not find serviceclass ' . $params['configoption1'];
|
|
|
}
|
|
|
$attrs['zimbraCOSId'] = $cosID;
|
|
|
- $id = $apiAccountManager->createAccount($accountName, $params['customfields']['password'], $attrs);
|
|
|
- if(is_a($id, "Exception")) {
|
|
|
+ $zimbraID = $apiAccountManager->createAccount($params['username'], $params['password'], $attrs);
|
|
|
+ if(is_a($zimbraID, 'Exception')) {
|
|
|
+ logModuleCall(
|
|
|
+ 'zimbrasingle',
|
|
|
+ __FUNCTION__,
|
|
|
+ $params,
|
|
|
+ 'Error: could not create account ' . $params['username'],
|
|
|
+ $zimbraID->getMessage()
|
|
|
+ );
|
|
|
+ return 'Error: could not create account ' . $params['username'];
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ Capsule::table('tblhosting')
|
|
|
+ ->where('id', '=', $params['serviceid'])
|
|
|
+ ->update(
|
|
|
+ array(
|
|
|
+ 'username' => $params['username'],
|
|
|
+ 'password' => $params['customfields']['password'],
|
|
|
+ )
|
|
|
+ );
|
|
|
+ } catch (\Exception $e) {
|
|
|
logModuleCall(
|
|
|
'zimbrasingle',
|
|
|
__FUNCTION__,
|
|
|
$params,
|
|
|
- "Error: account $accountName not created",
|
|
|
- $id
|
|
|
+ 'Error: could save username & password in database',
|
|
|
+ $e->getMessage()
|
|
|
);
|
|
|
- return "Error: account $accountName not created";
|
|
|
+ return 'Error: could save username & password in database';
|
|
|
}
|
|
|
return 'success';
|
|
|
}
|
|
|
@@ -652,33 +414,31 @@ function zimbraSingle_CreateAccount($params)
|
|
|
*
|
|
|
* @see https://developers.whmcs.com/provisioning-modules/module-parameters/
|
|
|
*
|
|
|
- * @return string "success" or an error message
|
|
|
+ * @return string 'success' or an error message
|
|
|
*/
|
|
|
function zimbraSingle_SuspendAccount($params)
|
|
|
{
|
|
|
- $accessData = zimbraSingleGetAccess();
|
|
|
- $accountName = $params['customfields']['username'] . '@' . $params['customfields']['maildomain'];
|
|
|
- $api = new Zm_Auth($accessData['zimbraServer'], $accessData['adminUser'], $accessData['adminPass'], "admin");
|
|
|
+ $api = new Zm_Auth($params['serverip'], $params['serverusername'], $params['serverpassword'], 'admin');
|
|
|
$login = $api->login();
|
|
|
- if(is_a($login, "Exception")) {
|
|
|
+ if(is_a($login, 'Exception')) {
|
|
|
logModuleCall(
|
|
|
'zimbrasingle',
|
|
|
__FUNCTION__,
|
|
|
$params,
|
|
|
- "Error: cannot login to " . $accessData['zimbraServer'],
|
|
|
- $login
|
|
|
+ 'Error: cannot login to ' . $params['serverip'],
|
|
|
+ $login->getMessage()
|
|
|
);
|
|
|
return $login->getMessage();
|
|
|
}
|
|
|
$apiAccountManager = new Zm_Account($api);
|
|
|
- $response = $apiAccountManager->setAccountStatus($accountName, "locked");
|
|
|
- if(is_a($response, "Exception")) {
|
|
|
+ $response = $apiAccountManager->setAccountStatus($params['username'], 'locked');
|
|
|
+ if(is_a($response, 'Exception')) {
|
|
|
logModuleCall(
|
|
|
'zimbrasingle',
|
|
|
__FUNCTION__,
|
|
|
$params,
|
|
|
- "Error: account $accountName could not locked",
|
|
|
- $response
|
|
|
+ 'Error: could not lock account ' . $params['username'],
|
|
|
+ $response->getMessage()
|
|
|
);
|
|
|
return false;
|
|
|
}
|
|
|
@@ -696,35 +456,33 @@ function zimbraSingle_SuspendAccount($params)
|
|
|
*
|
|
|
* @see https://developers.whmcs.com/provisioning-modules/module-parameters/
|
|
|
*
|
|
|
- * @return string "success" or an error message
|
|
|
+ * @return string 'success' or an error message
|
|
|
*/
|
|
|
function zimbraSingle_UnsuspendAccount($params)
|
|
|
{
|
|
|
- $accessData = zimbraSingleGetAccess();
|
|
|
- $accountName = $params['customfields']['username'] . '@' . $params['customfields']['maildomain'];
|
|
|
- $api = new Zm_Auth($accessData['zimbraServer'], $accessData['adminUser'], $accessData['adminPass'], "admin");
|
|
|
+ $api = new Zm_Auth($params['serverip'], $params['serverusername'], $params['serverpassword'], 'admin');
|
|
|
$login = $api->login();
|
|
|
- if(is_a($login, "Exception")) {
|
|
|
+ if(is_a($login, 'Exception')) {
|
|
|
logModuleCall(
|
|
|
'zimbrasingle',
|
|
|
__FUNCTION__,
|
|
|
$params,
|
|
|
- "Error: cannot login to " . $accessData['zimbraServer'],
|
|
|
- $login
|
|
|
+ 'Error: cannot login to ' . $params['serverip'],
|
|
|
+ $login->getMessage()
|
|
|
);
|
|
|
return $login->getMessage();
|
|
|
}
|
|
|
$apiAccountManager = new Zm_Account($api);
|
|
|
- $response = $apiAccountManager->setAccountStatus($accountName, "active");
|
|
|
- if(is_a($response, "Exception")) {
|
|
|
+ $response = $apiAccountManager->setAccountStatus($params['username'], 'active');
|
|
|
+ if(is_a($response, 'Exception')) {
|
|
|
logModuleCall(
|
|
|
'zimbrasingle',
|
|
|
__FUNCTION__,
|
|
|
$params,
|
|
|
- "Error: account $accountName could not unlocked",
|
|
|
- $response
|
|
|
+ 'Error: could not unlock account ' . $params['username'],
|
|
|
+ $response->getMessage()
|
|
|
);
|
|
|
- return "Error: account $accountName could not unlocked";
|
|
|
+ return 'Error: could not unlock account ' . $params['username'];
|
|
|
}
|
|
|
return 'success';
|
|
|
}
|
|
|
@@ -739,49 +497,47 @@ function zimbraSingle_UnsuspendAccount($params)
|
|
|
*
|
|
|
* @see https://developers.whmcs.com/provisioning-modules/module-parameters/
|
|
|
*
|
|
|
- * @return string "success" or an error message
|
|
|
+ * @return string 'success' or an error message
|
|
|
*/
|
|
|
function zimbraSingle_TerminateAccount($params)
|
|
|
{
|
|
|
- $accessData = zimbraSingleGetAccess();
|
|
|
- $accountName = $params['customfields']['username'] . '@' . $params['customfields']['maildomain'];
|
|
|
- $api = new Zm_Auth($accessData['zimbraServer'], $accessData['adminUser'], $accessData['adminPass'], "admin");
|
|
|
+ $api = new Zm_Auth($params['serverip'], $params['serverusername'], $params['serverpassword'], 'admin');
|
|
|
$login = $api->login();
|
|
|
- if(is_a($login, "Exception")) {
|
|
|
+ if(is_a($login, 'Exception')) {
|
|
|
logModuleCall(
|
|
|
'zimbrasingle',
|
|
|
__FUNCTION__,
|
|
|
$params,
|
|
|
- "Error: cannot login to " . $accessData['zimbraServer'],
|
|
|
- $login
|
|
|
+ 'Error: cannot login to ' . $params['serverip'],
|
|
|
+ $login->getMessage()
|
|
|
);
|
|
|
return $login->getMessage();
|
|
|
}
|
|
|
$apiAccountManager = new Zm_Account($api);
|
|
|
- $response = $apiAccountManager->getAccountStatus($accountName);
|
|
|
- if(is_a($response, "Exception")) {
|
|
|
+ $accountStatus = $apiAccountManager->getAccountStatus($params['username']);
|
|
|
+ if(is_a($accountStatus, 'Exception')) {
|
|
|
logModuleCall(
|
|
|
'zimbrasingle',
|
|
|
__FUNCTION__,
|
|
|
$params,
|
|
|
- "Error: account $accountName could not verified",
|
|
|
- $response
|
|
|
+ 'Error: could not verify account '. $params['username'],
|
|
|
+ $accountStatus->getMessage()
|
|
|
);
|
|
|
- return "Error : account $accountName could not verified";
|
|
|
+ return 'Error : account ' . $params['username'] . ' Name could not verified';
|
|
|
}
|
|
|
- if ($response != 'locked') {
|
|
|
- return "Account $accountName active, suspend account first!";
|
|
|
+ if ($accountStatus != 'locked') {
|
|
|
+ return 'Account '. $params['username'] . ' is active, suspend account first!';
|
|
|
}
|
|
|
- $response = $apiAccountManager->deleteAccount($accountName);
|
|
|
- if(is_a($response, "Exception")) {
|
|
|
+ $response = $apiAccountManager->deleteAccount($params['username']);
|
|
|
+ if(is_a($response, 'Exception')) {
|
|
|
logModuleCall(
|
|
|
'zimbrasingle',
|
|
|
__FUNCTION__,
|
|
|
$params,
|
|
|
- "Error: account $accountName could not removed",
|
|
|
- $response
|
|
|
+ 'Error: could not remove account '. $params['username'],
|
|
|
+ $response->getMessage()
|
|
|
);
|
|
|
- return "Error: account $accountName could not removed";
|
|
|
+ return 'Error: could not remove account '. $params['username'];
|
|
|
}
|
|
|
return 'success';
|
|
|
}
|
|
|
@@ -800,35 +556,33 @@ function zimbraSingle_TerminateAccount($params)
|
|
|
*
|
|
|
* @see https://developers.whmcs.com/provisioning-modules/module-parameters/
|
|
|
*
|
|
|
- * @return string "success" or an error message
|
|
|
+ * @return string 'success' or an error message
|
|
|
*/
|
|
|
function zimbraSingle_ChangePackage($params)
|
|
|
{
|
|
|
- $accessData = zimbraSingleGetAccess();
|
|
|
- $accountName = $params['customfields']['username'] . '@' . $params['customfields']['maildomain'];
|
|
|
- $api = new Zm_Auth($accessData['zimbraServer'], $accessData['adminUser'], $accessData['adminPass'], "admin");
|
|
|
+ $api = new Zm_Auth($params['serverip'], $params['serverusername'], $params['serverpassword'], 'admin');
|
|
|
$login = $api->login();
|
|
|
- if(is_a($login, "Exception")) {
|
|
|
+ if(is_a($login, 'Exception')) {
|
|
|
logModuleCall(
|
|
|
'zimbrasingle',
|
|
|
__FUNCTION__,
|
|
|
$params,
|
|
|
- "Error: cannot login to " . $accessData['zimbraServer'],
|
|
|
- $login
|
|
|
+ 'Error: cannot login to ' . $params['serverip'],
|
|
|
+ $login->getMessage()
|
|
|
);
|
|
|
return $login->getMessage();
|
|
|
}
|
|
|
$apiAccountManager = new Zm_Account($api);
|
|
|
- $response = $apiAccountManager->setAccountCos($accountName, $params['configoption1']);
|
|
|
- if(is_a($response, "Exception")) {
|
|
|
+ $response = $apiAccountManager->setAccountCos($params['username'], $params['configoption1']);
|
|
|
+ if(is_a($response, 'Exception')) {
|
|
|
logModuleCall(
|
|
|
'zimbrasingle',
|
|
|
__FUNCTION__,
|
|
|
$params,
|
|
|
- "Error: class of service for $accountName could not be set",
|
|
|
- $response
|
|
|
+ 'Error: could not set class of service for '. $params['username'],
|
|
|
+ $response->getMessage()
|
|
|
);
|
|
|
- return "Error: class of service for $accountName could not be set";
|
|
|
+ return 'Error: could not set class of service for '. $params['username'];
|
|
|
}
|
|
|
return 'success';
|
|
|
}
|
|
|
@@ -845,63 +599,65 @@ function zimbraSingle_ChangePackage($params)
|
|
|
*/
|
|
|
function zimbraSingle_ConfigOptions($params)
|
|
|
{
|
|
|
- if(isset($_POST['packageconfigoption'])) {
|
|
|
- if(zimbraSingleCreateCustomFields($_POST['packageconfigoption']) == false) {
|
|
|
- return false;
|
|
|
- };
|
|
|
- }
|
|
|
- $accessData = zimbraSingleGetAccess();
|
|
|
- $api = new Zm_Auth($accessData['zimbraServer'], $accessData['adminUser'], $accessData['adminPass'], "admin");
|
|
|
- $login = $api->login();
|
|
|
- if(is_a($login, "Exception")) {
|
|
|
+ $whmcs = App::self();
|
|
|
+ $serverGroupID = $whmcs->get_req_var('servergroup');
|
|
|
+ $serverIDObj = Capsule::table('tblservergroupsrel')
|
|
|
+ ->select('serverid')
|
|
|
+ ->where('groupid', '=', $serverGroupID)
|
|
|
+ ->get();
|
|
|
+ $serverIDArray = recursiveFindAll($serverIDObj,'serverid');
|
|
|
+ $server = Capsule::table('tblservers')
|
|
|
+ ->select('ipaddress', 'username', 'password')
|
|
|
+ ->where('id', $serverIDArray)
|
|
|
+ ->where('active', '=', 1)
|
|
|
+ ->get();
|
|
|
+ $accessData['zimbraServer'] = $server[0]->ipaddress;
|
|
|
+ $accessData['adminUser'] = $server[0]->username;
|
|
|
+ $adminPassCrypt = $server[0]->password;
|
|
|
+ $adminPassDecrypt = localAPI('DecryptPassword', array('password2' => $adminPassCrypt));
|
|
|
+ if ($adminPassDecrypt['result'] == 'success') {
|
|
|
+ $accessData['adminPass'] = $adminPassDecrypt['password'];
|
|
|
+ } else {
|
|
|
logModuleCall(
|
|
|
'zimbrasingle',
|
|
|
__FUNCTION__,
|
|
|
- $params,
|
|
|
- "Error: cannot login to " . $accessData['zimbraServer'],
|
|
|
- $login
|
|
|
+ $adminPassCrypt,
|
|
|
+ 'Error: cloud not decrypt admin password' ,
|
|
|
+ $adminPassDecrypt['message']
|
|
|
);
|
|
|
return false;
|
|
|
}
|
|
|
- $apiAccountManager = new Zm_Account($api);
|
|
|
- $response = $apiAccountManager->getAllCos();
|
|
|
- if(is_a($response, "Exception")) {
|
|
|
+ $api = new Zm_Auth($accessData['zimbraServer'], $accessData['adminUser'], $accessData['adminPass'], 'admin');
|
|
|
+ $login = $api->login();
|
|
|
+ if(is_a($login, 'Exception')) {
|
|
|
logModuleCall(
|
|
|
'zimbrasingle',
|
|
|
__FUNCTION__,
|
|
|
$params,
|
|
|
- "Error: could not fetch classes of service",
|
|
|
- $response
|
|
|
+ 'Error: cannot login to ' . $accessData['zimbraServer'],
|
|
|
+ $login->getMessage()
|
|
|
);
|
|
|
return false;
|
|
|
}
|
|
|
- $cosNames = recursiveFindAll($response, 'NAME');
|
|
|
- $configOptions = array();
|
|
|
- $configOptions['cos'] = array(
|
|
|
- "FriendlyName" => "Class of Service",
|
|
|
- "Type" => "dropdown",
|
|
|
- "Options" => implode(',', $cosNames),
|
|
|
- "Description" => "Select COS",
|
|
|
- );
|
|
|
- $apiDomainManager = new Zm_Domain($api);
|
|
|
- $response = $apiDomainManager->getAllDomains();
|
|
|
- if(is_a($response, "Exception")) {
|
|
|
+ $apiAccountManager = new Zm_Account($api);
|
|
|
+ $cosIDs = $apiAccountManager->getAllCos();
|
|
|
+ if(is_a($cosIDs, 'Exception')) {
|
|
|
logModuleCall(
|
|
|
'zimbrasingle',
|
|
|
__FUNCTION__,
|
|
|
$params,
|
|
|
- "Error: could fetch available maildomains",
|
|
|
- $response
|
|
|
+ 'Error: could not fetch classes of service',
|
|
|
+ $cosIDs->getMessage()
|
|
|
);
|
|
|
return false;
|
|
|
}
|
|
|
- $domainNames = recursiveFindAll($response, 'NAME');
|
|
|
- $configOptions['maildomains'] = array(
|
|
|
- "FriendlyName" => "Mail Domain",
|
|
|
- "Type" => "dropdown",
|
|
|
- "Multiple" => true,
|
|
|
- "Options" => implode(',', $domainNames),
|
|
|
- "Description" => "Info: Available Maildomains",
|
|
|
+ $cosNames = recursiveFindAll($cosIDs, 'NAME');
|
|
|
+ $configOptions = array();
|
|
|
+ $configOptions['cos'] = array(
|
|
|
+ 'FriendlyName' => 'Class of Service',
|
|
|
+ 'Type' => 'dropdown',
|
|
|
+ 'Options' => implode(',', $cosNames),
|
|
|
+ 'Description' => 'Select COS',
|
|
|
);
|
|
|
return $configOptions;
|
|
|
}
|