nextCloudEMailAvailable.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. <?php
  2. /**
  3. *
  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. use WHMCS\Database\Capsule;
  20. $whmcs = App::self();
  21. $email = $_GET['email'];
  22. if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
  23. echo "invalid";
  24. exit;
  25. }
  26. $parts = explode("@",$email);
  27. $domain = $parts[1];
  28. logModuleCall(
  29. 'nextcloud',
  30. __FUNCTION__,
  31. $email,
  32. 'debug',
  33. $domain
  34. );
  35. if (!strcasecmp($domain,"seecure.ch")) {
  36. echo "no1";
  37. exit;
  38. }
  39. if (!strcasecmp($domain,"seemail.ch")) {
  40. echo "no2";
  41. exit;
  42. }
  43. if (!strcasecmp($domain,"thurmail.ch")) {
  44. echo "no3";
  45. exit;
  46. }
  47. if (!strcasecmp($domain,"thurbit.ch")) {
  48. echo "no4";
  49. exit;
  50. }
  51. $productID = $_GET['pid'];
  52. $accessData = array('nextcloudServer' => '', 'adminUser' => '', 'adminPass' => '');
  53. $serverGroupIDObj = Capsule::table('tblproducts')
  54. ->select('servergroup')
  55. ->where('id', '=', $productID)
  56. ->get();
  57. $serverGroupID = $serverGroupIDObj[0]->servergroup;
  58. $serverIDObj = Capsule::table('tblservergroupsrel')
  59. ->select('serverid')
  60. ->where('groupid', '=', $serverGroupID)
  61. ->get();
  62. $serverID = $serverIDObj[0]->serverid;
  63. $server = Capsule::table('tblservers')
  64. ->select('hostname', 'username', 'password')
  65. ->where('id', '=', $serverID)
  66. ->where('active', '=', 1)
  67. ->get();
  68. $accessData['nextcloudServer'] = $server[0]->hostname;
  69. $accessData['adminUser'] = $server[0]->username;
  70. $adminPassDecrypt = localAPI('DecryptPassword', array('password2' => $server[0]->password));
  71. if ($adminPassDecrypt['result'] == 'success') {
  72. $accessData['adminPass'] = $adminPassDecrypt['password'];
  73. }
  74. //error_log("NextCloud User Avaialable: ACC " . $accountName);
  75. //error_log("--------------------------");
  76. //error_log("NextCloud User Avaialable: PID " . $productID);
  77. //error_log("NextCloud User Avaialable: GID " . $serverGroupID);
  78. //error_log("NextCloud User Avaialable: SID " . $serverID);
  79. //error_log("NextCloud User Avaialable: SERVER " . $accessData['nextcloudServer']);
  80. //error_log("NextCloud User Avaialable: USER " . $accessData['adminUser']);
  81. //error_log("NextCloud User Avaialable: PASS " . $accessData['adminPass']);
  82. $nextcloudURL = 'https://' . $accessData['nextcloudServer'] . "/ocs/v1.php/cloud/users?search=" . $email;
  83. //error_log("NextCloud User Avaialable: URL " . $nextcloudURL);
  84. $response = nextcloud_send($nextcloudURL,$accessData['adminUser'],$accessData['adminPass'],"GET");
  85. //error_log("NextCloud User Available NextCloud Response: " . $response->ocs->meta->statuscode);
  86. //error_log("NextCloud User Available NextCloud Response Content " . print_r($response,true));
  87. if (is_null($response) == true) {
  88. echo "error";
  89. exit;
  90. }
  91. logModuleCall(
  92. 'nextcloud',
  93. __FUNCTION__,
  94. $email,
  95. 'debug' . $nextcloudURL,
  96. $response
  97. );
  98. if ($response->ocs->meta->statuscode != '100') {
  99. echo "no";
  100. } else {
  101. if (count($response->ocs->data->users) > 0) {
  102. echo "no";
  103. exit;
  104. } else {
  105. echo "yes";
  106. exit;
  107. }
  108. }
  109. function nextcloud_send($href, $username, $password, $action, $post = array()) {
  110. $postdata = http_build_query($post);
  111. $ch = curl_init();
  112. if (strtoupper($action) == 'GET') {
  113. curl_setopt($ch, CURLOPT_HTTPGET, true);
  114. }
  115. curl_setopt($ch, CURLOPT_URL, $href);
  116. curl_setopt($ch, CURLOPT_USERPWD, $username . ":" . $password);
  117. curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
  118. curl_setopt($ch, CURLOPT_HTTPHEADER, array("Accept: application/json","OCS-APIRequest: true",'content-type: application/x-www-form-urlencoded'));
  119. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  120. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
  121. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  122. curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
  123. curl_setopt($ch, CURLOPT_TIMEOUT, 60);
  124. $result_json = curl_exec($ch);
  125. $httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
  126. curl_close($ch);
  127. if ($httpcode >= 200 && $httpcode < 300) {
  128. //print_r($result_json);die();
  129. $result_bom = nextcloud_remove_utf8bom($result_json);
  130. $result = json_decode($result_bom);
  131. return($result);
  132. } else {
  133. return null;
  134. }
  135. }
  136. function nextcloud_remove_utf8bom($text) {
  137. $bom = pack('H*', 'EFBBBF');
  138. $text = preg_replace("/^$bom/", '', $text);
  139. return $text;
  140. }