Spaces:
Running
Running
File size: 3,476 Bytes
90b617f 62858ec | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 | <?php
/**
* Hugging Face Space MOFH API Proxy Client
* Bypasses ByetHost restrictions by using HF Space as proxy
*/
class HF_MOFH_API
{
private $hf_api_url;
public function __construct($hf_api_url)
{
$this->hf_api_url = rtrim($hf_api_url, '/');
}
/**
* Create a new hosting account via HF Space
*/
public function createAccount($username, $password, $email, $domain, $plan = 'free')
{
$data = [
'username' => $username,
'password' => $password,
'email' => $email,
'domain' => $domain,
'plan' => $plan
];
return $this->makeRequest('/create-account', $data);
}
/**
* Suspend an account
*/
public function suspendAccount($username, $reason = 'Suspended by admin')
{
$data = [
'username' => $username,
'reason' => $reason
];
return $this->makeRequest('/suspend-account', $data);
}
/**
* Unsuspend an account
*/
public function unsuspendAccount($username)
{
$data = [
'username' => $username
];
return $this->makeRequest('/unsuspend-account', $data);
}
/**
* Make API request to Hugging Face Space
*/
private function makeRequest($endpoint, $data = [])
{
$url = $this->hf_api_url . $endpoint;
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Content-Type: application/json',
'User-Agent: Celestine-Hosting/1.0'
]);
curl_setopt($ch, CURLOPT_TIMEOUT, 60);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
$response = curl_exec($ch);
$http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
$error = curl_error($ch);
curl_close($ch);
if ($error) {
return [
'success' => false,
'http_code' => $http_code,
'error' => $error,
'response' => null
];
}
$result = json_decode($response, true);
if (!$result) {
return [
'success' => false,
'http_code' => $http_code,
'error' => 'Invalid JSON response',
'response' => $response
];
}
return array_merge($result, [
'http_code' => $http_code
]);
}
/**
* Test connection to HF Space
*/
public function testConnection()
{
$ch = curl_init($this->hf_api_url . '/');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
$response = curl_exec($ch);
$http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
$error = curl_error($ch);
curl_close($ch);
return [
'success' => ($http_code == 200 && !$error),
'http_code' => $http_code,
'error' => $error,
'response' => json_decode($response, true)
];
}
}
?> |