apiKey)) { Log::info('Không tồn tại apiKey'); return false; } $response = TlsHttpClientFactory::plesk() ->withHeaders([ 'X-API-Key' => $this->apiKey, 'accept' => 'application/json' ])->get("https://$this->url/api/v2/clients"); if ($response->status() === 200) { return true; } return false; } /* * check user exits from hosting server with email client */ public function LoginServer(): array { $response = TlsHttpClientFactory::plesk() ->withBasicAuth($this->username, $this->password) ->acceptJson() ->post("https://$this->url/api/v2/auth/keys", [ "login" => "admin" ] ); if ($response->status() === 201) { return [ 'error' => false, 'data' => $response->json() ]; } return [ 'error' => true, 'data' => $response->status() ]; } /* * get All Client in hosting server */ public function CheckUserClient($customer = []): array|string { $apiCheck = $this->apiCheck(); if ($apiCheck) { $allClient = $this->getAllClients(); $clientCheck = array_filter($allClient, function ($element) use ($customer) { if ($element["email"] == $customer->email) { return $element; } }); if (count($clientCheck)) { $Service = ModuleHosting::where('customer_id', $customer->id)->first(); return [ 'error' => false, 'data' => array_merge($clientCheck, ['password' => SignRSA::DecryptFunc($Service->password)]) ]; } return [ 'error' => true, 'data' => $clientCheck ]; } return "Login_Again"; } /* * Login to server */ public function getAllClients() { return TlsHttpClientFactory::plesk() ->withHeaders([ 'X-API-Key' => $this->apiKey, 'accept' => 'application/json' ])->get("https://$this->url/api/v2/clients")->json(); } public function CreateNewClient($product_data = [], $password = ''): array { $response = TlsHttpClientFactory::plesk() ->withHeaders([ 'X-API-Key' => $this->apiKey, 'accept' => 'application/json' ]) ->acceptJson() ->post("https://$this->url/api/v2/clients", [ 'name' => $product_data->Customer->firstname . " " . $product_data->Customer->lastname, 'company' => $product_data->Customer->company, 'login' => $product_data->Customer->email, 'email' => $product_data->Customer->email, 'password' => $password, 'type' => 'customer' ]); if ($response->status() === 201) { return [ 'error' => false, 'data' => array_merge($response->json(), ['password' => $password]) ]; } return [ 'error' => true, 'data' => $response->json() ]; } public function CheckDomainExit($customer_id = 0, $domain = ''): array|string { $apiCheck = $this->apiCheck(); if ($apiCheck) { $ClientDomain = $this->GetAllDomainForCustomer($customer_id); if ($ClientDomain['error'] === false) { $Result = array_filter($ClientDomain['data'], function ($data) use ($domain) { if ($data['name'] === $domain) { return $data; } }); if (count($Result)) { return [ 'error' => true, 'data' => 'Domain already exists' ]; } return [ 'error' => false, 'data' => "Can't find domain for customer" ]; } return [ 'error' => false, 'data' => $ClientDomain['data'] ]; } return "Login_Again"; } public function GetAllDomainForCustomer($customer_id = 0): array|string { $apiCheck = $this->apiCheck(); if ($apiCheck) { $allDomain = TlsHttpClientFactory::plesk() ->withHeaders([ 'X-API-Key' => $this->apiKey, 'accept' => 'application/json' ]) ->get("https://$this->url/api/v2/clients/$customer_id/domains"); if ($allDomain->status() === 20) { return [ 'error' => false, 'data' => $allDomain->json() ]; } return [ 'error' => true, 'data' => $allDomain->json() ]; } return "Login_Again"; } /* * create new plan user domain */ public function CreateNewDomain($product_data = [], $domain = '', $customer = [], $password = '') { $planHosting = $product_data->GetInvoiceItem()->GetItemProduct()->template; $apiCheck = $this->apiCheck(); if ($apiCheck) { $CreateDomain = TlsHttpClientFactory::plesk() ->withHeaders([ 'X-API-Key' => $this->apiKey, 'accept' => 'application/json' ]) ->post("https://$this->url/api/v2/domains", [ "name" => $domain, "hosting_type" => "virtual", "hosting_settings" => [ "ftp_login" => $domain, "ftp_password" => $password ], "owner_client" => [ "id" => $customer['id'], "login" => "owner", "guid" => $customer['guid'] ], "plan" => [ "name" => $planHosting ] ]); if ($CreateDomain->status() === 201) { return [ 'error' => false, 'data' => $CreateDomain->json() ]; } return [ 'error' => true, 'data' => $CreateDomain->json() ]; } return "Login_Again"; } public function CreateExpirationForDomain($domain = '', $date_exp = '') { $response = TlsHttpClientFactory::plesk() ->withHeaders([ 'X-API-Key' => $this->apiKey, 'accept' => 'application/json' ]) ->post("https://$this->url/api/v2/cli/domain_pref/call", [ "params" => [ "--update", "$domain", "-expiration", "$date_exp" ] ])->json(); if ($response['code'] === 0) { return [ 'error' => false, 'data' => $response['stdout'] ]; } return [ 'error' => true, 'data' => $response['stdout'] ]; } public function SuspendAccount($account_id = 0): array { $response = TlsHttpClientFactory::plesk() ->withHeaders([ 'X-API-Key' => $this->apiKey, 'accept' => 'application/json' ]) ->put("https://$this->url/api/v2/clients/$account_id/suspend")->json(); if ($response['status'] === "success") { return [ 'error' => false ]; } return [ 'error' => true, 'data' => $response['message'] ]; } public function ActivateAccount($account_id = 0): array { $response = TlsHttpClientFactory::plesk() ->withHeaders([ 'X-API-Key' => $this->apiKey, 'accept' => 'application/json' ]) ->put("https://$this->url/api/v2/clients/$account_id/activate")->json(); if ($response['status'] === "success") { return [ 'error' => false ]; } return [ 'error' => true, 'data' => $response['message'] ]; } }