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) ]; } } ?>