| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970 |
- <?php
- /**
- * Helper script to check the availibility of a Zimbra mailbox useable with ajax requests
- *
- * @see https://www.zimbra.com
- * @copyright Copyright (c) Thurdata GmbH 2020
- * @license GPL
- *
- */
- $pos = strpos($_SERVER['HTTP_REFERER'],getenv('HTTP_HOST'));
- if($pos===false) {
- die('Restricted access');
- }
- /**
- * Requires the whmcs init
- * Requires this PHP api to make soap calls and parse responses
- */
- require_once(__DIR__ . '/../../../init.php');
- require_once("api/Zm/Auth.php");
- require_once("api/Zm/Account.php");
- use WHMCS\Database\Capsule;
- $whmcs = App::self();
- $account_name = $_GET['name'] . "@" . $_GET['domain'];
- $productID = $_GET['pid'];
- $accessData = array('zimbraServer' => '', 'adminUser' => '', 'adminPass' => '');
- $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;
- $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'];
- }
- $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()
- );
- exit();
- } else {
- $apiAccountManager = new Zm_Account($api);
- if( $apiAccountManager->accountExists($account_name)) {
- echo 'no';
- } else {
- echo 'yes';
- }
- }
|