PHP code example of proficlos / vestacp-api

1. Go to this page and download the library: Download proficlos/vestacp-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/ */

    

proficlos / vestacp-api example snippets


	use ProfiCloS\VestaCP\Client;
	
	// easy way to create Client
	$client = Client::simpleFactory('https://someHost', 'someUser', 'somePass');
	

	use ProfiCloS\VestaCP\Client;
	use ProfiCloS\VestaCP\Authorization\Credentials;
	use ProfiCloS\VestaCP\Authorization\Host;
	
	$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->delete('other_user');
	// ... etc
	

	$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->deleteDomain('domain.com');
	// ... etc
	

	$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->deleteAccount('domain.com', 'info');
	$mailModule->deleteDomain('domain.com');
	// ... etc
	

	// modules
	$dbModule = $client->getModuleDb(); 

	// todo
	// ... etc
	

	$cronModule = $client->getModuleCron(); 

	// todo
	// ... etc
	

	$backupModule = $client->getModuleBackup(); 

	// todo
	// ... etc