| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125 |
- <?php
- /**
- * Helper script to check the availibility of a Zimbra mailbox useable with ajax requests
- *
- * @see https://www.zimbra.com
- * @copyright Copyright (c) Thurdata GmbH 2020
- * @license GPL
- *
- */
- $pos = strpos($_SERVER['HTTP_REFERER'],getenv('HTTP_HOST'));
- if($pos===false) {
- die('Restricted access');
- }
- /**
- * Requires the whmcs init
- * Requires this PHP api to make soap calls and parse responses
- */
- require_once(__DIR__ . '/../../../init.php');
- use WHMCS\Database\Capsule;
- $whmcs = App::self();
- $accountName = $_GET['name'];
- if(!preg_match('/^[a-zA-Z0-9\-]+$/', $accountName)) {
- echo "invalid";
- exit;
- }
- $productID = $_GET['pid'];
- $accessData = array('nextcloudServer' => '', 'adminUser' => '', 'adminPass' => '');
- $serverGroupIDObj = Capsule::table('tblproducts')
- ->select('servergroup')
- ->where('id', '=', $productID)
- ->get();
- $serverGroupID = $serverGroupIDObj[0]->servergroup;
- $serverIDObj = Capsule::table('tblservergroupsrel')
- ->select('serverid')
- ->where('groupid', '=', $serverGroupID)
- ->get();
- $serverID = $serverIDObj[0]->serverid;
- $server = Capsule::table('tblservers')
- ->select('hostname', 'username', 'password')
- ->where('id', '=', $serverID)
- ->where('active', '=', 1)
- ->get();
- $accessData['nextcloudServer'] = $server[0]->hostname;
- $accessData['adminUser'] = $server[0]->username;
- $adminPassDecrypt = localAPI('DecryptPassword', array('password2' => $server[0]->password));
- if ($adminPassDecrypt['result'] == 'success') {
- $accessData['adminPass'] = $adminPassDecrypt['password'];
- }
- //error_log("NextCloud User Avaialable: ACC " . $accountName);
- //error_log("--------------------------");
- //error_log("NextCloud User Avaialable: PID " . $productID);
- //error_log("NextCloud User Avaialable: GID " . $serverGroupID);
- //error_log("NextCloud User Avaialable: SID " . $serverID);
- //error_log("NextCloud User Avaialable: SERVER " . $accessData['nextcloudServer']);
- //error_log("NextCloud User Avaialable: USER " . $accessData['adminUser']);
- //error_log("NextCloud User Avaialable: PASS " . $accessData['adminPass']);
- $nextcloudURL = 'https://' . $accessData['nextcloudServer'] . "/ocs/v1.php/cloud/users/" . $accountName;
- error_log("NextCloud User Avaialable: URL " . $nextcloudURL);
- $response = nextcloud_send($nextcloudURL,$accessData['adminUser'],$accessData['adminPass'],"GET");
- error_log("NextCloud User Available NextCloud Response: " . $response->ocs->meta->statuscode);
- error_log("NextCloud User Available NextCloud Response Content " . print_r($response,true));
- if (is_null($response) == true) {
- echo "error";
- }
- if ($response->ocs->meta->statuscode == '100') {
- echo "no";
- } else {
- echo "yes";
- }
- function nextcloud_send($href, $username, $password, $action, $post = array()) {
- $postdata = http_build_query($post);
- $ch = curl_init();
- if (strtoupper($action) == 'GET') {
- curl_setopt($ch, CURLOPT_HTTPGET, true);
- }
- curl_setopt($ch, CURLOPT_URL, $href);
- curl_setopt($ch, CURLOPT_USERPWD, $username . ":" . $password);
- curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
- curl_setopt($ch, CURLOPT_HTTPHEADER, array("Accept: application/json","OCS-APIRequest: true",'content-type: application/x-www-form-urlencoded'));
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
- curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
- curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
- curl_setopt($ch, CURLOPT_TIMEOUT, 60);
- $result_json = curl_exec($ch);
- $httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
- curl_close($ch);
- if ($httpcode >= 200 && $httpcode < 300) {
- //print_r($result_json);die();
- $result_bom = nextcloud_remove_utf8bom($result_json);
- $result = json_decode($result_bom);
- return($result);
- } else {
- return null;
- }
- }
- function nextcloud_remove_utf8bom($text) {
- $bom = pack('H*', 'EFBBBF');
- $text = preg_replace("/^$bom/", '', $text);
- return $text;
- }
|