nextCloudEMailAvailable.php 4.3 KB

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