'Zimbra Single Mailbox Provisioning', 'APIVersion' => '1.2', 'DefaultNonSSLPort' => '7071', 'DefaultSSLPort' => '7071', 'RequiresServer' => true, 'ServiceSingleSignOnLabel' => 'Login to Zimbra', 'AdminSingleSignOnLabel' => 'Login to Zimbra Admin' ); } /** */ function zimbraSingleGetAccess() { global $packageid; $accessData = array('zimbraServer' => '', 'adminUser' => '', 'adminPass' => ''); $whmcs = App::self(); $productID = $whmcs->get_req_var('id'); $serverGroupID = $whmcs->get_req_var('servergroup'); if($productID) { $serverIDObj = Capsule::table('tblhosting') ->select('server') ->where('id', '=', $productID) ->get(); $serverID = $serverIDObj[0]->server; } elseif($serverGroupID) { $serverIDObj = Capsule::table('tblservergroupsrel') ->select('serverid') ->where('groupid', '=', $serverGroupID) ->get(); $serverID = $serverIDObj[0]->serverid; } elseif($packageid) { $serverIDObj = Capsule::table('tblhosting') ->select('server') ->where('packageid', '=', $packageid) ->get(); $serverID = $serverIDObj[0]->server; } else { logModuleCall( 'zimbrasingle', __FUNCTION__, $params, "Error: could not get accessdata 3", "" ); return false; } $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']; } return $accessData; } /** * Checks if a given email address in the given domain already exists * * @param $emailNameOnly The name before the @-sign only * @param $domainName The domain to search for existance of the email account * @return true if such an account was found or false if not */ function zimbraSingleDoesEMailExist($emailNameOnly, $domainName) { $account_name = $emailNameOnly . "@" . $domainName; $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->getMessage()" ); exit(); } else { $apiAccountManager = new Zm_Account($api); if( $apiAccountManager->accountExists($account_name)) { return true; } else { return false; } } } /** */ function zimbraSingleCreateAccount($userData) { $accessData = zimbraSingleGetAccess(); $attrs = array(); $attrs["gn"] = $userData["givenname"]; $attrs["sn"] = $userData["sn"]; $attrs["displayName"] = $attrs["gn"] . " " . $attrs["sn"]; $passDecrypt = localAPI('DecryptPassword', array('password2' => $userData['password'])); if ($passDecrypt['result'] == 'success') { $userData['password'] = $passDecrypt['password']; } $account_name = $userData['username'] . '@' . $userData['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'], "" ); return false; } $apiAccountManager = new Zm_Account($api); $cosName = $userData['cos']; $cosID = $apiAccountManager->getCosId($cosName); if(is_a($cosID, "Exception")) { logModuleCall( 'zimbrasingle', __FUNCTION__, $params, "Error : serviceclass $cosName not available", $userData ); return false; } $attrs['zimbraCOSId'] = $cosID; $id = $apiAccountManager->createAccount($account_name, $userData['password'], $attrs); if(is_a($id, "Exception")) { logModuleCall( 'zimbrasingle', __FUNCTION__, $params, "Error : account $account_name not created", $id ); return false; } return $id; } function zimbraSingleSuspendAccount($userData) { $accessData = zimbraSingleGetAccess(); $account_name = $userData['username'] . '@' . $userData['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'], "" ); return false; } else { $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", "" ); return false; } else { return $response; } } } function zimbraSingleUnsuspendAccount($userData) { $accessData = zimbraSingleGetAccess(); $account_name = $userData['username'] . '@' . $userData['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'], "" ); return false; } else { $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", "" ); return false; } else { return $response; } } } function zimbraSingleDeleteAccount($userData) { $accessData = zimbraSingleGetAccess(); $accountName = $userData['username'] . '@' . $userData['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'], "" ); return false; } $apiAccountManager = new Zm_Account($api); $response = $apiAccountManager->getAccountStatus($accountName); if(is_a($response, "Exception")) { logModuleCall( 'zimbrasingle', __FUNCTION__, $params, "Error : account $accountName could not verified", "" ); return false; } 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", "" ); return false; } return 'success'; } function zimbraSingleChangePassword($userData) { $accessData = zimbraSingleGetAccess(); $passDecrypt = localAPI('DecryptPassword', array('password2' => $userData['password'])); if ($passDecrypt['result'] == 'success') { $userData['password'] = $passDecrypt['password']; } if ($checkPW = zimbraSingleCheckPassword($userData['password'])) { return $checkPW; } $account_name = $userData['username'] . '@' . $userData['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'], "" ); return false; } $apiAccountManager = new Zm_Account($api); $response = $apiAccountManager->setAccountPassword($account_name, $userData['password']); if(is_a($response, "Exception")) { logModuleCall( 'zimbrasingle', __FUNCTION__, $params, "Error : password for $account_name could not be set", "" ); return false; } return 'success'; } function zimbraSingleChangePackage($userData) { $accessData = zimbraSingleGetAccess(); $account_name = $userData['username'] . '@' . $userData['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'], "" ); return false; } $apiAccountManager = new Zm_Account($api); $response = $apiAccountManager->setAccountCos($account_name, $userData['cos']); if(is_a($response, "Exception")) { logModuleCall( 'zimbrasingle', __FUNCTION__, $params, "Error : class of service for $account_name could not be set", "" ); return false; } return $response; } function zimbraSingleClientArea($userData) { $accessData = zimbraSingleGetAccess(); $clientInfo = array(); $account_name = $userData['username'] . '@' . $userData['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'], "" ); return false; } $apiAccountManager = new Zm_Account($api); $response = $apiAccountManager->getAccount($account_name); if(is_a($response, "Exception")) { logModuleCall( 'zimbrasingle', __FUNCTION__, $params, "Error : could not find $account_name", "" ); return false; } // $clientInfo['quota'] = bytesToHuman($bytes); logModuleCall( 'zimbrasingle', __FUNCTION__, $params, "debug: getQuota", $response ); $response = $apiAccountManager->getAccountInfo($account_name); if(is_a($response, "Exception")) { logModuleCall( 'zimbrasingle', __FUNCTION__, $params, "Error : could not gather informations for $account_name", "" ); return false; } $webMailURL = recursiveFindAll( $response, 'PUBLICMAILURL'); return $webMailURL; } function zimbraSingleConfigOptions($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__, $params, "Error : cannot login to " . $accessData['zimbraServer'], "" ); 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", "" ); 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", "" ); return false; } $domainNames = recursiveFindAll($response, 'NAME'); $configOptions['maildomains'] = array( "FriendlyName" => "Mail Domain", "Type" => "dropdown", "Multiple" => true, "Options" => implode(',', $domainNames), "Description" => "select maildomains", ); return $configOptions; } function zimbraSingleCreateCustomFields($packageconfigoption) { $whmcs = App::self(); $productID = $whmcs->get_req_var('id'); Capsule::table('tblcustomfields') ->where('relid', '=', $productID) ->delete(); 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' => 'cos | Class of Service', 'fieldtype' => 'dropdown', 'fieldoptions' => $packageconfigoption[1], 'adminonly' => 'on', 'required' => 'on', 'sortorder' => '5' ) ); } 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; } function zimbraSingleCheckPassword($pwd) { $message = ''; if (strlen($pwd) < 9) { $message .= "Das das Passwort ist zu kurz. Es werden mind. 9 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; } function bytesToHuman($bytes) { $units = ['B', 'KB', 'MB', 'GB', 'TB', 'PB']; for ($i = 0; $bytes > 1024; $i++) $bytes /= 1024; return round($bytes, 2) . ' ' . $units[$i]; }