PHP code example of neto737 / hestiacp-api

1. Go to this page and download the library: Download neto737/hestiacp-api library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

neto737 / hestiacp-api example snippets



use neto737\HestiaCP\Client;

// Easy way to create Client

// Using API Key
$client = Client::simpleFactory('https://someHost', 'API_Key');

// Using username and password
$client = Client::simpleFactory('https://someHost', 'someUser', 'somePass');



use neto737\HestiaCP\Client;
use neto737\HestiaCP\Authorization\Credentials;
use neto737\HestiaCP\Authorization\Host;

// You can choose to use an API Key or username and password

// API Key
$credentials = new Credentials('API_Key');

// Username and Password
$credentials = new Credentials('someUser', 'somePassword');

$host = new Host('https://someHost', $credentials);

$client = new Client($host);



// verify login
$client->testAuthorization(); // bool



$command = new SomeCommand();

$response = $client->send($command);


echo $response->getResponseText();



$userModule = $client->getModuleUser();


$userModule->list(); // returns all users with data

$userModule->detail('admin'); // returns selected user with data

$userModule->changePassword('admin', 'otherPa$$word');

$userModule->add('other_user', 'pa$$word', '[email protected]');

$userModule->suspend('other_user');

$userModule->unsuspend('other_user');

$userModule->delete('other_user');



$webModule = $client->getModuleWeb('admin'); // web module needs user


$webModule->listDomains();

$webModule->addDomain('domain.com');

$webModule->addDomainLetsEncrypt('domain.com', 'www.domain.com'); // needs longer timeout

$webModule->deleteDomainLetsEncrypt('domain.com');

$webModule->addDomainFtp('domain.com', 'test', 'pa$$word');

$webModule->changeDomainFtpPassword('domain.com', 'admin_test', 'otherPa$$word');

$webModule->changeDomainFtpPath('domain.com', 'admin_test', 'path/other');

$webModule->deleteDomainFtp('domain.com', 'admin_test');

$webModule->suspendDomain('domain.com');

$webModule->unsuspendDomain('domain.com');

$webModule->deleteDomain('domain.com');



$mailModule = $client->getModuleMail('admin'); // mail module needs user


$mailModule->listDomains(); // returns mail domains from selected user

$mailModule->addDomain('domain.com'); // add domain

$mailModule->listAccounts('domain.com'); // returns accounts from selected user and domain

$mailModule->listDomainDkim('domain.com');

$mailModule->listDomainDkimDns('domain.com');

$mailModule->addAccount('domain.com', 'info', 'pa$$word'); // add [email protected] account

$mailModule->changeAccountPassword('domain.com', 'info', 'otherPa$$word'); // change [email protected] password

$mailModule->suspendAccount('domain.com', 'info'); // suspend [email protected] account

$mailModule->unsuspendAccount('domain.com', 'info'); // unsuspend [email protected] account

$mailModule->deleteAccount('domain.com', 'info');

$mailModule->suspendDomain('domain.com');

$mailModule->unsuspendDomain('domain.com');

$mailModule->deleteDomain('domain.com');



$dbModule = $client->getModuleDatabase('admin');


$dbModule->add('database', 'dbuser', 'dbpass');

$dbModule->delete('admin_database');

$dbModule->deleteDatabases();

$dbModule->listDatabase('database');

$dbModule->listDatabases();


// todo

// ... etc



$cronModule = $client->getModuleCron();


// todo

// ... etc



$backupModule = $client->getModuleBackup('admin'); // backup module needs user

$backupModule->backup(); // create a new backup

$backupModule->delete('admin.2021-10-13_18-12-53.tar'); // delete an user backup

$backupModule->deleteExclusions(); // delete all backup exclusions

$backupModule->listBackups(); // returns the backups list

$backupModule->listBackup('admin.2021-10-13_18-12-53.tar'); // returns backup parameters list

$backupModule->listBackupExclusions(); // returns the backup exclusions list