zimbraAddressAvailable.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <?php
  2. /**
  3. * Helper script to check the availibility of a Zimbra mailbox useable with ajax requests
  4. *
  5. * @see https://www.zimbra.com
  6. * @copyright Copyright (c) Thurdata GmbH 2020
  7. * @license GPL
  8. *
  9. */
  10. $pos = strpos($_SERVER['HTTP_REFERER'],getenv('HTTP_HOST'));
  11. if($pos===false) {
  12. die('Restricted access');
  13. }
  14. /**
  15. * Requires the whmcs init
  16. * Requires this PHP api to make soap calls and parse responses
  17. */
  18. require_once(__DIR__ . '/../../../init.php');
  19. require_once("api/Zm/Auth.php");
  20. require_once("api/Zm/Account.php");
  21. use WHMCS\Database\Capsule;
  22. $whmcs = App::self();
  23. $account_name = $_GET['name'] . "@" . $_GET['domain'];
  24. $productID = $_GET['pid'];
  25. $accessData = array('zimbraServer' => '', 'adminUser' => '', 'adminPass' => '');
  26. $serverGroupIDObj = Capsule::table('tblproducts')
  27. ->select('servergroup')
  28. ->where('id', '=', $productID)
  29. ->get();
  30. $serverGroupID = $serverGroupIDObj[0]->servergroup;
  31. $serverIDObj = Capsule::table('tblservergroupsrel')
  32. ->select('serverid')
  33. ->where('groupid', '=', $serverGroupID)
  34. ->get();
  35. $serverID = $serverIDObj[0]->serverid;
  36. $server = Capsule::table('tblservers')
  37. ->select('ipaddress', 'username', 'password')
  38. ->where('id', '=', $serverID)
  39. ->where('active', '=', 1)
  40. ->get();
  41. $accessData['zimbraServer'] = $server[0]->ipaddress;
  42. $accessData['adminUser'] = $server[0]->username;
  43. $adminPassCrypt = $server[0]->password;
  44. $adminPassDecrypt = localAPI('DecryptPassword', array('password2' => $adminPassCrypt));
  45. if ($adminPassDecrypt['result'] == 'success') {
  46. $accessData['adminPass'] = $adminPassDecrypt['password'];
  47. }
  48. $api = new Zm_Auth($accessData['zimbraServer'], $accessData['adminUser'], $accessData['adminPass'], "admin");
  49. $login = $api->login();
  50. if(is_a($login, "Exception")) {
  51. logModuleCall(
  52. 'zimbrasingle',
  53. __FUNCTION__,
  54. $accessData,
  55. "Error: cannot login to " . $accessData['zimbraServer'],
  56. $login->getMessage()
  57. );
  58. exit();
  59. } else {
  60. $apiAccountManager = new Zm_Account($api);
  61. if( $apiAccountManager->accountExists($account_name)) {
  62. echo 'no';
  63. } else {
  64. echo 'yes';
  65. }
  66. }