kerioDomainAvailable.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <?php
  2. /**
  3. * Helper script to check the availibility of a Kerio mailbox useable with ajax requests
  4. *
  5. * @see https://www.kerio.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. use ThurData\Servers\KerioEmail\Api\KerioWhmcs;
  20. use WHMCS\Database\Capsule;
  21. /**
  22. * Requires this PHP api to make soap calls and parse responses
  23. * This is an extend version of:
  24. * @see https://github.com/alloylab/kerio-admin-api-soap-php
  25. */
  26. require_once(__DIR__ . '/api/KerioWhmcs.php');
  27. $whmcs = App::self();
  28. $domainName = $_GET['domain'];
  29. $productID = $_GET['pid'];
  30. if(!filter_var($domainName, FILTER_VALIDATE_DOMAIN)) {
  31. echo "invalid";
  32. exit;
  33. }
  34. // check active Kerio Domains
  35. $accessData = array('kerioServer' => '', 'adminUser' => '', 'adminPass' => '');
  36. $serverGroupIDObj = Capsule::table('tblproducts')
  37. ->select('servergroup')
  38. ->where('id', '=', $productID)
  39. ->get();
  40. $serverGroupID = $serverGroupIDObj[0]->servergroup;
  41. $serverIDObj = Capsule::table('tblservergroupsrel')
  42. ->select('serverid')
  43. ->where('groupid', '=', $serverGroupID)
  44. ->get();
  45. $serverID = $serverIDObj[0]->serverid;
  46. $server = Capsule::table('tblservers')
  47. ->select('hostname', 'username', 'password')
  48. ->where('id', '=', $serverID)
  49. ->where('active', '=', 1)
  50. ->get();
  51. $accessData['kerioServer'] = $server[0]->hostname;
  52. $accessData['adminUser'] = $server[0]->username;
  53. $adminPassDecrypt = localAPI('DecryptPassword', array('password2' => $server[0]->password));
  54. if ($adminPassDecrypt['result'] == 'success') {
  55. $accessData['adminPass'] = $adminPassDecrypt['password'];
  56. }
  57. $api = new KerioWhmcs('whmcsKerioSingle', 'Thurdata', '1.0');
  58. try {
  59. $api->login($accessData['kerioServer'], $accessData['adminUser'], $accessData['adminPass']);
  60. } catch (KerioApiException $error) {
  61. logModuleCall(
  62. 'keriosingle',
  63. __FUNCTION__,
  64. $accessData,
  65. 'Error: cannot login to ' . $accessData['kerioServer'],
  66. $error->getMessage()
  67. );
  68. exit();
  69. }
  70. $domains = $api->getDomains(['name']);
  71. logModuleCall(
  72. 'keriosingle',
  73. __FUNCTION__,
  74. $accessData,
  75. 'Debug',
  76. $domains
  77. );
  78. if(true) {
  79. pprunt_r($domains);
  80. // echo 'no';
  81. } else {
  82. echo 'yes';
  83. }
  84. $api->logout();