| 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(__DIR__ . '/api/Zm/Auth.php');
- require_once(__DIR__ . '/api/Zm/Account.php');
- use WHMCS\Database\Capsule;
- $whmcs = App::self();
- $accountName = $_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('hostname', 'username', 'password')
- ->where('id', '=', $serverID)
- ->where('active', '=', 1)
- ->get();
- $accessData['zimbraServer'] = $server[0]->hostname;
- $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($accountName)) {
- echo 'no';
- } else {
- echo 'yes';
- }
- }
|