nextCloudEMailAvailable.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. <?php
  2. /**
  3. * @copyright Copyright (c) Thurdata GmbH 2020
  4. * @license GPL
  5. *
  6. */
  7. $pos = strpos($_SERVER['HTTP_REFERER'],getenv('HTTP_HOST'));
  8. if($pos===false) {
  9. die('Restricted access');
  10. }
  11. /**
  12. * Requires the whmcs init
  13. * Requires this PHP api to make soap calls and parse responses
  14. */
  15. require_once(__DIR__ . '/../../../init.php');
  16. use WHMCS\Database\Capsule;
  17. $whmcs = App::self();
  18. $email = $_GET['email'];
  19. if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
  20. echo "invalid";
  21. exit;
  22. }
  23. $parts = explode("@",$email);
  24. $domain = $parts[1];
  25. if (!strcasecmp($domain,"seecure.ch")) {
  26. echo "no1";
  27. exit;
  28. }
  29. if (!strcasecmp($domain,"seemail.ch")) {
  30. echo "no2";
  31. exit;
  32. }
  33. if (!strcasecmp($domain,"thurmail.ch")) {
  34. echo "no3";
  35. exit;
  36. }
  37. if (!strcasecmp($domain,"thurbit.ch")) {
  38. echo "no4";
  39. exit;
  40. }
  41. $productID = $_GET['pid'];
  42. $accessData = array('nextcloudServer' => '', 'adminUser' => '', 'adminPass' => '');
  43. $serverGroupIDObj = Capsule::table('tblproducts')
  44. ->select('servergroup')
  45. ->where('id', '=', $productID)
  46. ->get();
  47. $serverGroupID = $serverGroupIDObj[0]->servergroup;
  48. $serverIDObj = Capsule::table('tblservergroupsrel')
  49. ->select('serverid')
  50. ->where('groupid', '=', $serverGroupID)
  51. ->get();
  52. $serverID = $serverIDObj[0]->serverid;
  53. $server = Capsule::table('tblservers')
  54. ->select('hostname', 'username', 'password')
  55. ->where('id', '=', $serverID)
  56. ->where('active', '=', 1)
  57. ->get();
  58. $accessData['nextcloudServer'] = $server[0]->hostname;
  59. $accessData['adminUser'] = $server[0]->username;
  60. $adminPassDecrypt = localAPI('DecryptPassword', array('password2' => $server[0]->password));
  61. if ($adminPassDecrypt['result'] == 'success') {
  62. $accessData['adminPass'] = $adminPassDecrypt['password'];
  63. }
  64. //error_log("NextCloud User Avaialable: ACC " . $accountName);
  65. //error_log("--------------------------");
  66. //error_log("NextCloud User Avaialable: PID " . $productID);
  67. //error_log("NextCloud User Avaialable: GID " . $serverGroupID);
  68. //error_log("NextCloud User Avaialable: SID " . $serverID);
  69. //error_log("NextCloud User Avaialable: SERVER " . $accessData['nextcloudServer']);
  70. //error_log("NextCloud User Avaialable: USER " . $accessData['adminUser']);
  71. //error_log("NextCloud User Avaialable: PASS " . $accessData['adminPass']);
  72. $nextcloudURL = 'https://' . $accessData['nextcloudServer'] . "/ocs/v1.php/cloud/users?search=" . $email;
  73. //error_log("NextCloud User Avaialable: URL " . $nextcloudURL);
  74. $response = nextcloud_send($nextcloudURL,$accessData['adminUser'],$accessData['adminPass'],"GET");
  75. //error_log("NextCloud User Available NextCloud Response: " . $response->ocs->meta->statuscode);
  76. //error_log("NextCloud User Available NextCloud Response Content " . print_r($response,true));
  77. if (is_null($response) == true) {
  78. echo "error";
  79. exit;
  80. }
  81. if ($response->ocs->meta->statuscode != '100') {
  82. echo "no";
  83. } else {
  84. if (count($response->ocs->data->users) > 0) {
  85. echo "no";
  86. exit;
  87. } else {
  88. echo "yes";
  89. exit;
  90. }
  91. }
  92. function nextcloud_send($href, $username, $password, $action, $post = array()) {
  93. $postdata = http_build_query($post);
  94. $ch = curl_init();
  95. if (strtoupper($action) == 'GET') {
  96. curl_setopt($ch, CURLOPT_HTTPGET, true);
  97. }
  98. curl_setopt($ch, CURLOPT_URL, $href);
  99. curl_setopt($ch, CURLOPT_USERPWD, $username . ":" . $password);
  100. curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
  101. curl_setopt($ch, CURLOPT_HTTPHEADER, array("Accept: application/json","OCS-APIRequest: true",'content-type: application/x-www-form-urlencoded'));
  102. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  103. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
  104. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  105. curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
  106. curl_setopt($ch, CURLOPT_TIMEOUT, 60);
  107. $result_json = curl_exec($ch);
  108. $httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
  109. curl_close($ch);
  110. if ($httpcode >= 200 && $httpcode < 300) {
  111. //print_r($result_json);die();
  112. $result_bom = nextcloud_remove_utf8bom($result_json);
  113. $result = json_decode($result_bom);
  114. return($result);
  115. } else {
  116. return null;
  117. }
  118. }
  119. function nextcloud_remove_utf8bom($text) {
  120. $bom = pack('H*', 'EFBBBF');
  121. $text = preg_replace("/^$bom/", '', $text);
  122. return $text;
  123. }