seafileAddressAvailable.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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(__DIR__ . '/api/Sf/Admin.php');
  20. use WHMCS\Database\Capsule;
  21. $whmcs = App::self();
  22. $accountName = $_GET['username'];
  23. $productID = $_GET['pid'];
  24. $accessData = array('seafileURL' => '', 'adminUser' => '', 'adminPass' => '');
  25. $serverGroupIDObj = Capsule::table('tblproducts')
  26. ->select('servergroup')
  27. ->where('id', '=', $productID)
  28. ->get();
  29. $serverGroupID = $serverGroupIDObj[0]->servergroup;
  30. $serverIDObj = Capsule::table('tblservergroupsrel')
  31. ->select('serverid')
  32. ->where('groupid', '=', $serverGroupID)
  33. ->get();
  34. $serverID = $serverIDObj[0]->serverid;
  35. $server = Capsule::table('tblservers')
  36. ->select('hostname', 'secure', 'port', 'username', 'password')
  37. ->where('id', '=', $serverID)
  38. ->where('active', '=', 1)
  39. ->get();
  40. $accessData['seafileServer'] = $server[0]->hostname;
  41. $accessData['prefix'] = $server[0]->secure ? 'https://' : 'http://';
  42. $accessData['port'] = $server[0]->port;
  43. $accessData['adminUser'] = $server[0]->username;
  44. $adminPassCrypt = $server[0]->password;
  45. $adminPassDecrypt = localAPI('DecryptPassword', array('password2' => $adminPassCrypt));
  46. if ($adminPassDecrypt['result'] == 'success') {
  47. $accessData['adminPass'] = $adminPassDecrypt['password'];
  48. }
  49. $seafileURL = $accessData['prefix'] . $accessData['seafileServer'] . ':' . $accessData['port'];
  50. $seafileAPI = new Sf_Admin($seafileURL,$accessData['adminUser'],$accessData['adminPass']);
  51. $response = $seafileAPI->login();
  52. if (isset($response['error_msg'])) {
  53. logModuleCall(
  54. 'seafile',
  55. __FUNCTION__,
  56. $params,
  57. 'Error: could not login to ' . $seafileURL,
  58. $response
  59. );
  60. exit();
  61. } else {
  62. $existingAccount = $seafileAPI->getAccount($accountName);
  63. if (isset($existingAccount['error_msg'])) {
  64. echo 'yes';
  65. } else {
  66. echo 'no';
  67. }
  68. }