| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829 |
- <?php
- /**
- * WHMCS Zimbra Provisioning Module
- *
- * Provisioning for private mailboxes on a Zimbra Server
- *
- * @see https://www.zimbra.com
- * @copyright Copyright (c) Thurdata GmbH 2020
- * @license GPL
- */
- if (!defined("WHMCS")) {
- die("This file cannot be accessed directly");
- }
- use WHMCS\Database\Capsule;
- /**
- * Requires this PHP api to make soap calls and parse responses
- * 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");
- /**
- * 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');
- Capsule::table('tblcustomfields')
- ->where('relid', '=', $productID)
- ->delete();
- try {
- Capsule::table('tblcustomfields')
- ->insert(
- array(
- 'type' => 'product',
- 'relid' => $productID,
- 'fieldname' => 'givenname | Vorname',
- 'fieldtype' => 'text',
- 'required' => 'on',
- 'showorder' => 'on',
- 'sortorder' => '0'
- )
- );
- Capsule::table('tblcustomfields')
- ->insert(
- array(
- 'type' => 'product',
- 'relid' => $productID,
- 'fieldname' => 'sn | Nachname',
- 'fieldtype' => 'text',
- 'required' => 'on',
- 'showorder' => 'on',
- 'sortorder' => '1'
- )
- );
- Capsule::table('tblcustomfields')
- ->insert(
- array(
- 'type' => 'product',
- 'relid' => $productID,
- 'fieldname' => 'username | E-Mail Name',
- 'fieldtype' => 'text',
- 'required' => 'on',
- 'showorder' => 'on',
- 'sortorder' => '2'
- )
- );
- Capsule::table('tblcustomfields')
- ->insert(
- array(
- 'type' => 'product',
- 'relid' => $productID,
- 'fieldname' => 'maildomain | Mail Domaine',
- 'fieldtype' => 'dropdown',
- 'fieldoptions' => implode(',', $packageconfigoption[2]),
- 'required' => 'on',
- 'showorder' => 'on',
- 'sortorder' => '3'
- )
- );
- Capsule::table('tblcustomfields')
- ->insert(
- array(
- 'type' => 'product',
- 'relid' => $productID,
- 'fieldname' => 'password | Password',
- 'fieldtype' => 'password',
- 'required' => 'on',
- 'showorder' => 'on',
- 'sortorder' => '4'
- )
- );
- Capsule::table('tblcustomfields')
- ->insert(
- array(
- 'type' => 'product',
- 'relid' => $productID,
- 'fieldname' => 'pwrepeat | Password wiederholen',
- 'fieldtype' => 'password',
- 'required' => 'on',
- 'showorder' => 'on',
- 'sortorder' => '5'
- )
- );
- Capsule::table('tblcustomfields')
- ->insert(
- 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 array or object
- *
- * @param array $haystack mixed data
- * @param string $needle key to search for values
- * @return array of values
- */
- function recursiveFindAll($haystack, $needle)
- {
- $values = array();
- $iterator = new RecursiveArrayIterator($haystack);
- $recursive = new RecursiveIteratorIterator(
- $iterator,
- RecursiveIteratorIterator::SELF_FIRST
- );
- foreach ($recursive as $key => $value) {
- if ($key === $needle) {
- array_push($values, $value);
- }
- }
- 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.
- *
- * Values returned here are used to determine module related abilities and
- * settings.
- *
- * @see https://developers.whmcs.com/provisioning-modules/meta-data-params/
- *
- * @return array
- */
- function zimbraSingle_MetaData()
- {
- return array(
- 'DisplayName' => 'Zimbra Single Mailbox Provisioning',
- 'APIVersion' => '1.2',
- 'DefaultNonSSLPort' => '7071',
- 'DefaultSSLPort' => '7071',
- 'RequiresServer' => true,
- 'ServiceSingleSignOnLabel' => 'Login to Zimbra',
- 'AdminSingleSignOnLabel' => 'Login to Zimbra Admin'
- );
- }
- /**
- * Test connection to a Zimbra 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 zimbraSingle_TestConnection($params)
- {
- $auth = new Zm_Auth($params['serverip'], $params['serverusername'], $params['serverpassword'], "admin");
- $login = $auth->login();
- if(is_a($login, "Exception")) {
- logModuleCall(
- 'zimbrasingle',
- __FUNCTION__,
- $params,
- "Connection test to " . $params['serverip'] . " failed: Cannot login",
- $login->getMessage()
- );
- return array(
- 'success' => false,
- 'error' => "Connection test to " . $params['serverip'] . " failed, the error was: " . $login->getMessage(),
- );
- } else {
- return array(
- 'success' => true,
- 'error' => '',
- );
- }
- }
- /**
- * 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 zimbraSingle_ClientArea($params)
- {
- $accessData = zimbraSingleGetAccess();
- $clientInfo = array();
- $account_name = $params['customfields']['username'] . '@' . $params['customfields']['maildomain'];
- $api = new Zm_Auth($accessData['zimbraServer'], $accessData['adminUser'], $accessData['adminPass'], "admin");
- $login = $api->login();
- if(is_a($login, "Exception")) {
- logModuleCall(
- 'zimbrasingle',
- __FUNCTION__,
- $params,
- "Error: cannot login to " . $accessData['zimbraServer'],
- $login
- );
- return false;
- }
- $apiAccountManager = new Zm_Account($api);
- $quota = $apiAccountManager->getQuota($account_name);
- if(is_a($quota, "Exception")) {
- logModuleCall(
- 'zimbrasingle',
- __FUNCTION__,
- $params,
- "Error : could not find $account_name",
- $quota
- );
- return false;
- }
- $response = $apiAccountManager->getMailbox($account_name);
- if(is_a($response, "Exception")) {
- logModuleCall(
- 'zimbrasingle',
- __FUNCTION__,
- $params,
- "Error: could not fetch mailbox info for $account_name",
- $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($account_name);
- if(is_a($response, "Exception")) {
- logModuleCall(
- 'zimbrasingle',
- __FUNCTION__,
- $params,
- "Error: could not gather informations for $account_name",
- $response
- );
- return false;
- }
- $webmailUrl = recursiveFindAll( $response, 'PUBLICMAILURL');
- $clientInfo['webmailurl'] = $webmailUrl[0]['DATA'];
- return array(
- 'templatefile' => 'clientarea',
- 'vars' => $clientInfo,
- );
- }
- /**
- * Change the password for a Zimbra 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 zimbraSingle_ChangePassword($params)
- {
- $accessData = zimbraSingleGetAccess();
- if ($checkPW = zimbraSingleCheckPassword($params['password'])) {
- return $checkPW;
- }
- $account_name = $params['customfields']['username'] . '@' . $params['customfields']['maildomain'];
- $api = new Zm_Auth($accessData['zimbraServer'], $accessData['adminUser'], $accessData['adminPass'], "admin");
- $login = $api->login();
- if(is_a($login, "Exception")) {
- logModuleCall(
- 'zimbrasingle',
- __FUNCTION__,
- $params,
- "Error: cannot login to " . $accessData['zimbraServer'],
- $login
- );
- return false;
- }
- $apiAccountManager = new Zm_Account($api);
- $response = $apiAccountManager->setAccountPassword($account_name, $params['password']);
- if(is_a($response, "Exception")) {
- logModuleCall(
- 'zimbrasingle',
- __FUNCTION__,
- $params,
- "Error: password for $account_name could not be set",
- $response
- );
- return false;
- }
- return 'success';
- }
- /**
- * Provision a new instance of a Zimbra account.
- *
- * Attempt to provision a new Zimbra mail 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 zimbraSingle_CreateAccount($params)
- {
- $accessData = zimbraSingleGetAccess();
- $api = new Zm_Auth($accessData['zimbraServer'], $accessData['adminUser'], $accessData['adminPass'], "admin");
- $login = $api->login();
- if(is_a($login, "Exception")) {
- logModuleCall(
- 'zimbrasingle',
- __FUNCTION__,
- $accessData,
- "Error: cannot login to " . $accessData['zimbraServer'],
- $login->getMessage()
- );
- return "Error: cannot login to " . $accessData['zimbraServer'];
- }
- $account_name = $params['customfields']['username'] . '@' . $params['customfields']['maildomain'];
- $apiAccountManager = new Zm_Account($api);
- $accountExists = $apiAccountManager->accountExists($account_name);
- if(is_a($accountExists, "Exception")) {
- logModuleCall(
- 'zimbrasingle',
- __FUNCTION__,
- $accessData,
- "Error: could not verify $account_name",
- $accountExists
- );
- return "Error: could not verify $account_name";
- }
- if($accountExists === true) {
- return "Error: account $account_name already exists";
- }
- $attrs = array();
- $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'];
- } else {
- logModuleCall(
- 'zimbrasingle',
- __FUNCTION__,
- $params['customfields']['password'],
- "Error: could not decrypt password",
- $passDecrypt
- );
- return "Error: could not decrypt password";
- }
- $cosID = $apiAccountManager->getCosId($params['customfields']['cos']);
- if(is_a($cosID, "Exception")) {
- logModuleCall(
- 'zimbrasingle',
- __FUNCTION__,
- $params['customfields']['cos'],
- "Error: serviceclass not available",
- $cosID
- );
- return "Error: serviceclass not available";
- }
- $attrs['zimbraCOSId'] = $cosID;
- $id = $apiAccountManager->createAccount($account_name, $params['customfields']['password'], $attrs);
- if(is_a($id, "Exception")) {
- logModuleCall(
- 'zimbrasingle',
- __FUNCTION__,
- $params,
- "Error: account $account_name not created",
- $id
- );
- return "Error: account $account_name not created";
- }
- return 'success';
- }
- /**
- * Set a Zimbra account to status locked.
- *
- * 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 zimbraSingle_SuspendAccount($params)
- {
- $accessData = zimbraSingleGetAccess();
- $account_name = $params['customfields']['username'] . '@' . $params['customfields']['maildomain'];
- $api = new Zm_Auth($accessData['zimbraServer'], $accessData['adminUser'], $accessData['adminPass'], "admin");
- $login = $api->login();
- if(is_a($login, "Exception")) {
- logModuleCall(
- 'zimbrasingle',
- __FUNCTION__,
- $params,
- "Error: cannot login to " . $accessData['zimbraServer'],
- $login
- );
- return $login->getMessage();
- }
- $apiAccountManager = new Zm_Account($api);
- $response = $apiAccountManager->setAccountStatus($account_name, "locked");
- if(is_a($response, "Exception")) {
- logModuleCall(
- 'zimbrasingle',
- __FUNCTION__,
- $params,
- "Error: account $account_name could not locked",
- $response
- );
- return false;
- }
- return 'success';
- }
- /**
- * Set a Zimbra 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 zimbraSingle_UnsuspendAccount($params)
- {
- $accessData = zimbraSingleGetAccess();
- $account_name = $params['customfields']['username'] . '@' . $params['customfields']['maildomain'];
- $api = new Zm_Auth($accessData['zimbraServer'], $accessData['adminUser'], $accessData['adminPass'], "admin");
- $login = $api->login();
- if(is_a($login, "Exception")) {
- logModuleCall(
- 'zimbrasingle',
- __FUNCTION__,
- $params,
- "Error: cannot login to " . $accessData['zimbraServer'],
- $login
- );
- return $login->getMessage();
- }
- $apiAccountManager = new Zm_Account($api);
- $response = $apiAccountManager->setAccountStatus($account_name, "active");
- if(is_a($response, "Exception")) {
- logModuleCall(
- 'zimbrasingle',
- __FUNCTION__,
- $params,
- "Error: account $account_name could not unlocked",
- $response
- );
- return "Error: account $account_name could not unlocked";
- }
- return 'success';
- }
- /**
- * Removes a Zimbra 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 zimbraSingle_TerminateAccount($params)
- {
- $accessData = zimbraSingleGetAccess();
- $accountName = $params['customfields']['username'] . '@' . $params['customfields']['maildomain'];
- $api = new Zm_Auth($accessData['zimbraServer'], $accessData['adminUser'], $accessData['adminPass'], "admin");
- $login = $api->login();
- if(is_a($login, "Exception")) {
- logModuleCall(
- 'zimbrasingle',
- __FUNCTION__,
- $params,
- "Error: cannot login to " . $accessData['zimbraServer'],
- $login
- );
- return $login->getMessage();
- }
- $apiAccountManager = new Zm_Account($api);
- $response = $apiAccountManager->getAccountStatus($accountName);
- if(is_a($response, "Exception")) {
- logModuleCall(
- 'zimbrasingle',
- __FUNCTION__,
- $params,
- "Error: account $accountName could not verified",
- $response
- );
- return "Error : account $accountName could not verified";
- }
- if ($response != 'locked') {
- return "Account $accountName active, suspend account first!";
- }
- $response = $apiAccountManager->deleteAccount($accountName);
- if(is_a($response, "Exception")) {
- logModuleCall(
- 'zimbrasingle',
- __FUNCTION__,
- $params,
- "Error: account $accountName could not removed",
- $response
- );
- return "Error: account $accountName could not removed";
- }
- return 'success';
- }
- /**
- * Set a new class of service for a Zimbra account.
- *
- * Called to apply a change of the class of 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 zimbraSingle_ChangePackage($params)
- {
- $accessData = zimbraSingleGetAccess();
- $account_name = $params['customfields']['username'] . '@' . $params['customfields']['maildomain'];
- $api = new Zm_Auth($accessData['zimbraServer'], $accessData['adminUser'], $accessData['adminPass'], "admin");
- $login = $api->login();
- if(is_a($login, "Exception")) {
- logModuleCall(
- 'zimbrasingle',
- __FUNCTION__,
- $params,
- "Error: cannot login to " . $accessData['zimbraServer'],
- $login
- );
- return $login->getMessage();
- }
- $apiAccountManager = new Zm_Account($api);
- $response = $apiAccountManager->setAccountCos($account_name, $params['customfields']['cos']);
- if(is_a($response, "Exception")) {
- logModuleCall(
- 'zimbrasingle',
- __FUNCTION__,
- $params,
- "Error: class of service for $account_name could not be set",
- $response
- );
- return "Error: class of service for $account_name could not be set";
- }
- return 'success';
- }
- /**
- * Define Zimbra product configuration options.
- *
- * Gather classes of service and available mail domains from the Zinbra server.
- * Calls a function to create all necessary customfields for the order form using the selected values.
- *
- * @see https://developers.whmcs.com/provisioning-modules/config-options/
- *
- * @return array
- */
- 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")) {
- logModuleCall(
- 'zimbrasingle',
- __FUNCTION__,
- $params,
- "Error: cannot login to " . $accessData['zimbraServer'],
- $login
- );
- return false;
- }
- $apiAccountManager = new Zm_Account($api);
- $response = $apiAccountManager->getAllCos();
- if(is_a($response, "Exception")) {
- logModuleCall(
- 'zimbrasingle',
- __FUNCTION__,
- $params,
- "Error: could not fetch classes of service",
- $response
- );
- 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")) {
- logModuleCall(
- 'zimbrasingle',
- __FUNCTION__,
- $params,
- "Error: could fetch available maildomains",
- $response
- );
- return false;
- }
- $domainNames = recursiveFindAll($response, 'NAME');
- $configOptions['maildomains'] = array(
- "FriendlyName" => "Mail Domain",
- "Type" => "dropdown",
- "Multiple" => true,
- "Options" => implode(',', $domainNames),
- "Description" => "select maildomains",
- );
- return $configOptions;
- }
|