zimbraAddressAvailable.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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. use WHMCS\Database\Capsule;
  10. $whmcs = App::self();
  11. $productID = $_GET['pid'];
  12. $accessData = array('zimbraServer' => '', 'adminUser' => '', 'adminPass' => '');
  13. $serverIDObj = Capsule::table('tblhosting')
  14. ->select('server')
  15. ->where('id', '=', $productID)
  16. ->get();
  17. $serverID = $serverIDObj[0]->server;
  18. $server = Capsule::table('tblservers')
  19. ->select('ipaddress', 'username', 'password')
  20. ->where('id', '=', $serverID)
  21. ->where('active', '=', 1)
  22. ->get();
  23. $accessData['zimbraServer'] = $server[0]->ipaddress;
  24. $accessData['adminUser'] = $server[0]->username;
  25. $adminPassCrypt = $server[0]->password;
  26. $adminPassDecrypt = localAPI('DecryptPassword', array('password2' => $adminPassCrypt));
  27. if ($adminPassDecrypt['result'] == 'success') {
  28. $accessData['adminPass'] = $adminPassDecrypt['password'];
  29. }
  30. $api = new Zm_Auth($accessData['zimbraServer'], $accessData['adminUser'], $accessData['adminPass'], "admin");
  31. $login = $api->login();
  32. if(is_a($login, "Exception")) {
  33. logModuleCall(
  34. 'zimbrasingle',
  35. __FUNCTION__,
  36. $accessData,
  37. "Error : cannot login to " . $accessData['zimbraServer'],
  38. $serverID
  39. );
  40. exit();
  41. } else {
  42. $apiAccountManager = new Zm_Account($api);
  43. if( $apiAccountManager->accountExists($account_name)) {
  44. echo 'no';
  45. } else {
  46. echo 'yes';
  47. }
  48. }