zimbraAddressAvailable.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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. $productID = $_GET['pid'];
  14. $accessData = array('zimbraServer' => '', 'adminUser' => '', 'adminPass' => '');
  15. $serverGroupIDObj = Capsule::table('tblproducts')
  16. ->select('servergroup')
  17. ->where('id', '=', $productID)
  18. ->get();
  19. $serverGroupID = $serverGroupIDObj[0]->servergroup;
  20. $serverIDObj = Capsule::table('tblservergroupsrel')
  21. ->select('serverid')
  22. ->where('groupid', '=', $serverGroupID)
  23. ->get();
  24. $serverID = $serverIDObj[0]->serverid;
  25. $server = Capsule::table('tblservers')
  26. ->select('ipaddress', 'username', 'password')
  27. ->where('id', '=', $serverID)
  28. ->where('active', '=', 1)
  29. ->get();
  30. $accessData['zimbraServer'] = $server[0]->ipaddress;
  31. $accessData['adminUser'] = $server[0]->username;
  32. $adminPassCrypt = $server[0]->password;
  33. $adminPassDecrypt = localAPI('DecryptPassword', array('password2' => $adminPassCrypt));
  34. if ($adminPassDecrypt['result'] == 'success') {
  35. $accessData['adminPass'] = $adminPassDecrypt['password'];
  36. }
  37. $api = new Zm_Auth($accessData['zimbraServer'], $accessData['adminUser'], $accessData['adminPass'], "admin");
  38. $login = $api->login();
  39. if(is_a($login, "Exception")) {
  40. logModuleCall(
  41. 'zimbrasingle',
  42. __FUNCTION__,
  43. $serverIDObj,
  44. "Error : cannot login to " . $accessData['zimbraServer'],
  45. $packageID
  46. );
  47. exit();
  48. } else {
  49. $apiAccountManager = new Zm_Account($api);
  50. if( $apiAccountManager->accountExists($account_name)) {
  51. echo 'no';
  52. } else {
  53. echo 'yes';
  54. }
  55. }