|
@@ -1,83 +0,0 @@
|
|
|
-<?php
|
|
|
|
|
-/**
|
|
|
|
|
- * Helper script to check the availibility of a Seafile Account useable with ajax requests
|
|
|
|
|
- *
|
|
|
|
|
- * @see https://www.seafile.com
|
|
|
|
|
- * @copyright Copyright (c) Thurdata GmbH 2021
|
|
|
|
|
- * @license GPL
|
|
|
|
|
- *
|
|
|
|
|
- */
|
|
|
|
|
-$pos = strpos($_SERVER['HTTP_REFERER'],getenv('HTTP_HOST'));
|
|
|
|
|
-if($pos===false) {
|
|
|
|
|
- die('Restricted access');
|
|
|
|
|
-}
|
|
|
|
|
-$productID = $_GET['pid'];
|
|
|
|
|
-$accountName = $_GET['username'];
|
|
|
|
|
-if(!filter_var($accountName, FILTER_VALIDATE_EMAIL)) {
|
|
|
|
|
- echo "invalid";
|
|
|
|
|
- exit;
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
-error_log("Seafile Address Available: ". $productID . "/" . $accountName);
|
|
|
|
|
-/**
|
|
|
|
|
- * Requires the whmcs init
|
|
|
|
|
- * Requires this PHP api to make soap calls and parse responses
|
|
|
|
|
- */
|
|
|
|
|
-require_once(__DIR__ . '/../../../init.php');
|
|
|
|
|
-require_once(__DIR__ . '/api/Sf/Admin.php');
|
|
|
|
|
-use WHMCS\Database\Capsule;
|
|
|
|
|
-$whmcs = App::self();
|
|
|
|
|
-$accessData = array('seafileURL' => '', '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', 'secure', 'port', 'username', 'password')
|
|
|
|
|
- ->where('id', '=', $serverID)
|
|
|
|
|
- ->where('active', '=', 1)
|
|
|
|
|
- ->get();
|
|
|
|
|
-
|
|
|
|
|
-$accessData['seafileServer'] = $server[0]->hostname;
|
|
|
|
|
-$accessData['prefix'] = $server[0]->secure ? 'https://' : 'http://';
|
|
|
|
|
-$accessData['port'] = $server[0]->port;
|
|
|
|
|
-$accessData['adminUser'] = $server[0]->username;
|
|
|
|
|
-$adminPassCrypt = $server[0]->password;
|
|
|
|
|
-$adminPassDecrypt = localAPI('DecryptPassword', array('password2' => $adminPassCrypt));
|
|
|
|
|
-if ($adminPassDecrypt['result'] == 'success') {
|
|
|
|
|
- $accessData['adminPass'] = $adminPassDecrypt['password'];
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
-if (empty($accessData['port']) || $accessData['port'] == "") {
|
|
|
|
|
- $seafileURL = $accessData['prefix'] . $accessData['seafileServer'] . ":443";
|
|
|
|
|
-} else {
|
|
|
|
|
- $seafileURL = $accessData['prefix'] . $accessData['seafileServer'] . ':' . $accessData['port'];
|
|
|
|
|
-}
|
|
|
|
|
-$seafileAPI = new Sf_Admin($seafileURL,$accessData['adminUser'],$accessData['adminPass']);
|
|
|
|
|
-$response = $seafileAPI->login();
|
|
|
|
|
-
|
|
|
|
|
-if (isset($response['error_msg'])) {
|
|
|
|
|
- logModuleCall(
|
|
|
|
|
- 'seafile',
|
|
|
|
|
- __FUNCTION__,
|
|
|
|
|
- $params,
|
|
|
|
|
- 'Error: could not login to ' . $seafileURL,
|
|
|
|
|
- $response
|
|
|
|
|
- );
|
|
|
|
|
- error_log(" --> ERROR " . print_r($response,true));
|
|
|
|
|
- echo "error";
|
|
|
|
|
- exit();
|
|
|
|
|
-} else {
|
|
|
|
|
- $existingAccount = $seafileAPI->getAccount($accountName);
|
|
|
|
|
- if (isset($existingAccount['error_msg'])) {
|
|
|
|
|
- echo 'yes';
|
|
|
|
|
- } else {
|
|
|
|
|
- echo 'no';
|
|
|
|
|
- }
|
|
|
|
|
-}
|
|
|