zimbraAddressAvailable.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?php
  2. $allowed_host = 'admin.seecure.ch';
  3. $host = parse_url($_SERVER['HTTP_REFERER'], PHP_URL_HOST);
  4. if(substr($host, 0 - strlen($allowed_host)) != $allowed_host) {
  5. die("This file cannot be accessed directly");
  6. }
  7. define("CLIENTAREA", true);
  8. require_once(__DIR__ . '/../../../init.php');
  9. require_once("api/Zm/Auth.php");
  10. require_once("api/Zm/Account.php");
  11. use WHMCS\Database\Capsule;
  12. $whmcs = App::self();
  13. $account_name = $_GET['name'] . "@" . $_GET['domain'];
  14. $productID = $_GET['pid'];
  15. $accessData = array('zimbraServer' => '', 'adminUser' => '', 'adminPass' => '');
  16. $serverGroupIDObj = Capsule::table('tblproducts')
  17. ->select('servergroup')
  18. ->where('id', '=', $productID)
  19. ->get();
  20. $serverGroupID = $serverGroupIDObj[0]->servergroup;
  21. $serverIDObj = Capsule::table('tblservergroupsrel')
  22. ->select('serverid')
  23. ->where('groupid', '=', $serverGroupID)
  24. ->get();
  25. $serverID = $serverIDObj[0]->serverid;
  26. $server = Capsule::table('tblservers')
  27. ->select('ipaddress', 'username', 'password')
  28. ->where('id', '=', $serverID)
  29. ->where('active', '=', 1)
  30. ->get();
  31. $accessData['zimbraServer'] = $server[0]->ipaddress;
  32. $accessData['adminUser'] = $server[0]->username;
  33. $adminPassCrypt = $server[0]->password;
  34. $adminPassDecrypt = localAPI('DecryptPassword', array('password2' => $adminPassCrypt));
  35. if ($adminPassDecrypt['result'] == 'success') {
  36. $accessData['adminPass'] = $adminPassDecrypt['password'];
  37. }
  38. $api = new Zm_Auth($accessData['zimbraServer'], $accessData['adminUser'], $accessData['adminPass'], "admin");
  39. $login = $api->login();
  40. if(is_a($login, "Exception")) {
  41. logModuleCall(
  42. 'zimbrasingle',
  43. __FUNCTION__,
  44. $accessData,
  45. "Error : cannot login to " . $accessData['zimbraServer'],
  46. $login->getMessage()
  47. );
  48. exit();
  49. } else {
  50. logModuleCall(
  51. 'zimbrasingle',
  52. __FUNCTION__,
  53. $accessData,
  54. "Debug",
  55. $account_name
  56. );
  57. $apiAccountManager = new Zm_Account($api);
  58. if( $apiAccountManager->accountExists($account_name)) {
  59. echo 'no';
  60. } else {
  61. echo 'yes';
  62. }
  63. }