'Zimbra Single Mailbox Provisioning', 'APIVersion' => '1.2', 'DefaultNonSSLPort' => '7071', 'DefaultSSLPort' => '7071', 'RequiresServer' => true, 'ServiceSingleSignOnLabel' => 'Login to Zimbra', 'AdminSingleSignOnLabel' => 'Login to Zimbra Admin' ); } /** */ function zimbraSingleGetAccess() { $accessData = array('zimbraServer' => '', 'adminUser' => '', 'adminPass' => ''); $servers = Capsule::table('tblservers') ->select('ipaddress', 'username', 'password') ->where('id', '=', $_SESSION[CreatedServerId]) ->get(); $accessData['zimbraServer'] = $servers[0]->ipaddress; $accessData['adminUser'] = $servers[0]->username; $adminPassCrypt = $servers[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", "" ); 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", "" ); 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(); $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->getAccountStatus($account_name); if(is_a($response, "Exception")) { logModuleCall( 'zimbrasingle', __FUNCTION__, $params, "Error : account $account_name could not verified", "" ); return false; } if ($response != 'locked') { return "Account $account_name active, suspend account first"; } $response = $apiAccountManager->deleteAccount($account_name); if(is_a($response, "Exception")) { logModuleCall( 'zimbrasingle', __FUNCTION__, $params, "Error : account $account_name 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; } else { $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; } else { return $response; } } } 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(); $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->getAccountInfo($account_name); if(is_a($response, "Exception")) { logModuleCall( 'zimbrasingle', __FUNCTION__, $params, "Error : could not gather informations for $account_name", "" ); return false; } else { $webMailURL = recursiveFindAll( $response, 'PUBLICMAILURL'); logModuleCall( 'zimbrasingle', __FUNCTION__, $params, "debug", $webMailURL ); return $webMailURL; } } } 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
"; } if (!preg_match("#[0-9]+#", $pwd)) { $message .= "Das Passwort muss mindestens eine Zahl enthalten
"; } if (!preg_match("#[A-Z]+#", $pwd)) { $message .= "Das Passwort muss mindestens einen Grossbuchstaben (A-Z) enthalten
"; } if (!preg_match("#[a-z]+#", $pwd)) { $message .= "Das Passwort muss mindestens einen Kleinbuchstaben (a-z) enthalten
"; } if (!preg_match("#[^\w]+#", $pwd)) { $message .= "Das Passwort muss mindestens ein Sonderzeichen (.,-:=) enthalten
"; } return $message; } function zimbraSingleTestFunction() { return 'blubb'; }