├── .gitignore ├── CONTRIBUTORS.md ├── README.md ├── composer.json ├── composer.lock ├── examples ├── APS │ ├── install_application.php │ └── list_available_packages.php ├── Clients │ ├── create_client.php │ ├── delete_client.php │ ├── get_client.php │ ├── list_clients.php │ └── update_client.php ├── DNS │ └── list_dns_records.php ├── Databases │ ├── create_database.php │ ├── create_database_user.php │ ├── delete_database.php │ ├── get_database_user.php │ ├── list_database_servers.php │ └── list_databases.php ├── EmailAddresses │ ├── create_email_address.php │ ├── delete_email_address.php │ ├── list_email_addresses.php │ └── update_email_password.php ├── MailService │ └── update_preferences.php ├── Misc │ ├── get_server_info.php │ └── list_ip_addresses.php ├── SSL │ └── install_certificate.php ├── SecretKey │ ├── create_secret_key.php │ ├── delete_secret_key.php │ └── list_secret_keys.php ├── ServicePlans │ ├── get_service_plan.php │ └── list_service_plans.php ├── SiteAliases │ ├── create_site_alias.php │ ├── delete_site_alias.php │ └── list_site_aliases.php ├── Sites │ ├── create_site.php │ ├── delete_site.php │ ├── get_site.php │ ├── list_sites.php │ └── update_site.php ├── SplClassLoader.php ├── Subdomains │ ├── create_subdomain.php │ ├── delete_subdomain.php │ ├── get_subdomain.php │ ├── list_subdomains.php │ ├── rename_subdomain.php │ └── update_subdomain.php ├── Subscriptions │ ├── create_subscription.php │ ├── delete_subscription.php │ ├── get_subscription.php │ ├── get_traffic.php │ └── list_subscriptions.php ├── Wordpress │ ├── activate_plugin.php │ ├── activate_theme.php │ ├── clear_cache.php │ ├── deactivate_plugin.php │ ├── disable_auto_updates.php │ ├── enable_auto_updates.php │ ├── get_plugin_list.php │ ├── get_security_status.php │ ├── get_theme_list.php │ ├── install_plugin.php │ ├── install_theme.php │ ├── list_instances.php │ ├── remove_instance.php │ ├── search_plugins.php │ ├── search_themes.php │ ├── uninstall_plugin.php │ ├── uninstall_theme.php │ ├── update_core.php │ ├── update_plugin.php │ └── update_theme.php └── config.php ├── src └── pmill │ └── Plesk │ ├── APS │ ├── InstallApplication.php │ └── ListAvailablePackages.php │ ├── ApiRequestException.php │ ├── BaseRequest.php │ ├── CreateClient.php │ ├── CreateDatabase.php │ ├── CreateDatabaseUser.php │ ├── CreateEmailAddress.php │ ├── CreateSecretKey.php │ ├── CreateSite.php │ ├── CreateSiteAlias.php │ ├── CreateSubdomain.php │ ├── CreateSubscription.php │ ├── CurlHttpRequest.php │ ├── DeleteClient.php │ ├── DeleteDatabase.php │ ├── DeleteEmailAddress.php │ ├── DeleteSecretKey.php │ ├── DeleteSite.php │ ├── DeleteSiteAlias.php │ ├── DeleteSubdomain.php │ ├── DeleteSubscription.php │ ├── GetClient.php │ ├── GetDatabaseUser.php │ ├── GetServerInfo.php │ ├── GetServicePlan.php │ ├── GetSite.php │ ├── GetSubdomain.php │ ├── GetSubscription.php │ ├── GetTraffic.php │ ├── Helper │ ├── MailPreferences.php │ └── Xml.php │ ├── HttpRequestContract.php │ ├── ListClients.php │ ├── ListDNSRecords.php │ ├── ListDatabaseServers.php │ ├── ListDatabases.php │ ├── ListEmailAddresses.php │ ├── ListIPAddresses.php │ ├── ListSecretKeys.php │ ├── ListServicePlans.php │ ├── ListSiteAliases.php │ ├── ListSites.php │ ├── ListSubdomains.php │ ├── ListSubscriptions.php │ ├── MailService │ └── UpdatePreferences.php │ ├── Node.php │ ├── NodeList.php │ ├── ObjectStatus.php │ ├── RenameSubdomain.php │ ├── SSL │ └── InstallCertificate.php │ ├── UpdateClient.php │ ├── UpdateEmailPassword.php │ ├── UpdateSite.php │ ├── UpdateSubdomain.php │ └── Wordpress │ ├── ActivatePlugin.php │ ├── ActivateTheme.php │ ├── ClearCache.php │ ├── DeactivatePlugin.php │ ├── DisableAutoUpdates.php │ ├── EnableAutoUpdates.php │ ├── GetPluginList.php │ ├── GetSecurityStatus.php │ ├── GetThemeList.php │ ├── InstallPlugin.php │ ├── InstallTheme.php │ ├── ListInstances.php │ ├── RemoveInstance.php │ ├── SearchPlugins.php │ ├── SearchThemes.php │ ├── UninstallPlugin.php │ ├── UninstallTheme.php │ ├── UpdateCore.php │ ├── UpdatePlugin.php │ └── UpdateTheme.php └── tests └── complete_run.php /.gitignore: -------------------------------------------------------------------------------- 1 | *.DS_Store 2 | .idea 3 | vendor -------------------------------------------------------------------------------- /CONTRIBUTORS.md: -------------------------------------------------------------------------------- 1 | pmill/php-plesk contributors 2 | ============================ 3 | 4 | * **[ghermans](https://github.com/ghermans)** 5 | 6 | * GetSubscription 7 | 8 | * **[texh](https://github.com/texh)** 9 | 10 | * GetTraffic 11 | 12 | * **[carlswart](https://github.com/carlswart)** 13 | 14 | * ListDNS 15 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Sorry, this library is not being maintained, I no longer work with Plesk professionally so cannot test new features/bug fixes. If anyone is interested in being added to the project as a collaborator please send me a message. 2 | = 3 | 4 | php-plesk 5 | ============ 6 | 7 | Introduction 8 | ------------ 9 | 10 | This package contains a PHP client for the Plesk RPC API. 11 | 12 | The following features are currently supported: 13 | 14 | * List IP addresses 15 | * List service plans 16 | * Get server information and stats 17 | * List/add/update/delete clients 18 | * List/add/update/delete subscriptions 19 | * List/add/update/delete sites 20 | * List/add/update/delete email addresses 21 | * List/add/update/delete domain aliases 22 | * List/add/update/delete subdomains 23 | * List database servers 24 | * List/add/delete databases 25 | * Add database users 26 | * Further functionality can be seen in the examples folder 27 | * Email dev.pmill@gmail.com with requests for exposing further functionality 28 | 29 | Requirements 30 | ------------ 31 | 32 | This library package requires PHP 5.4 or later and Plesk 12.0 or above. 33 | 34 | 35 | Usage 36 | ----- 37 | 38 | The following example shows how to retrieve the list of websites available for the 39 | supplied user. 40 | 41 | $config = array( 42 | 'host'=>'example.com', 43 | 'username'=>'username', 44 | 'password'=>'password', 45 | ); 46 | 47 | $request = new \pmill\Plesk\ListClients($config); 48 | $info = $request->process(); 49 | 50 | Further examples are available in the examples directory. 51 | 52 | Version History 53 | --------------- 54 | 55 | Unversioned (13 Apr 2013) 56 | 57 | * First public release of php-plesk. 58 | 59 | 0.1.0 (08/10/2014) 60 | 61 | * Updated Create Email Address xml payload for newer versions of the Plesk API 62 | * Exposed further functionality 63 | 64 | 0.2.0 (09/10/2014) 65 | 66 | * Added support for composer installs 67 | * Updated code for psr-0 autoloading 68 | * Updated code for psr-1 basic coding standard 69 | * Updated code for psr-2 coding style guide 70 | 71 | 0.3.0 (16/10/2014) 72 | 73 | * Added functionality for ip addresses, service plans, clients, subscriptions and server information 74 | * Added test script 75 | * Updated classes to throw exceptions when requests fail 76 | * Sorted examples folder into areas of functionality 77 | 78 | 0.4.0 (05/02/2015) 79 | 80 | * Added functionality for databases 81 | * Updated test script 82 | 83 | 0.5.0 (08/03/2016) 84 | 85 | * Added secret key functionality 86 | * Updated error handling to expose Plesk error code 87 | * Added html entity escaping 88 | 89 | 0.5.1 (05/04/2016) 90 | 91 | * Added mail preferences functionality 92 | * Added wordpress functionality 93 | * Added APS functionality 94 | * Added ssl certificate functionality 95 | 96 | 0.5.2 (18/05/2016) 97 | 98 | * Updated ListSubscriptions to retrieve plan guids 99 | * Updated GetServicePlan to accept 'guid' as a filter option 100 | * Updated DeleteSiteAlias to accept 'alias' as a filter option 101 | 102 | 0.5.3 (24/05/2016) 103 | 104 | * Code quality improvements 105 | * Updated ListSubscriptions to retrieve subscription status 106 | 107 | 0.5.4 (13/06/2016) 108 | 109 | * Added GetSubscription functionality (thanks [ghermans](https://github.com/ghermans)) 110 | 111 | 0.5.5 (15/08/2016) 112 | 113 | * Added GetTraffic functionality (thanks [texh](https://github.com/texh)) 114 | * Added ListDNS functionality (thanks [carlswart](https://github.com/carlswart)) 115 | 116 | 0.5.6 (01/09/2016) 117 | 118 | * Error handling bug fix 119 | * Exposed service plan guid property (thanks [ghermans](https://github.com/ghermans)) 120 | 121 | 122 | Copyright and License 123 | --------------------- 124 | 125 | php-plesk 126 | Copyright (c) 2013 pmill (dev.pmill@gmail.com) 127 | All rights reserved. 128 | 129 | Redistribution and use in source and binary forms, with or without 130 | modification, are permitted provided that the following conditions are 131 | met: 132 | 133 | * Redistributions of source code must retain the above copyright 134 | notice, this list of conditions and the following disclaimer. 135 | 136 | * Redistributions in binary form must reproduce the above copyright 137 | notice, this list of conditions and the following disclaimer in the 138 | documentation and/or other materials provided with the 139 | distribution. 140 | 141 | This software is provided by the copyright holders and contributors "as 142 | is" and any express or implied warranties, including, but not limited 143 | to, the implied warranties of merchantability and fitness for a 144 | particular purpose are disclaimed. In no event shall the copyright owner 145 | or contributors be liable for any direct, indirect, incidental, special, 146 | exemplary, or consequential damages (including, but not limited to, 147 | procurement of substitute goods or services; loss of use, data, or 148 | profits; or business interruption) however caused and on any theory of 149 | liability, whether in contract, strict liability, or tort (including 150 | negligence or otherwise) arising in any way out of the use of this 151 | software, even if advised of the possibility of such damage. 152 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "pmill/php-plesk", 3 | "description": "PHP client for the Plesk RPC API", 4 | "keywords": ["php", "plesk", "api"], 5 | "homepage": "https://github.com/pmill/php-plesk", 6 | "time": "2014-10-08", 7 | "license": "BSD", 8 | "authors": [ 9 | { 10 | "name": "pmill", 11 | "email": "dev.pmill@gmail.com", 12 | "homepage": "https://github.com/pmill", 13 | "role": "Author" 14 | } 15 | ], 16 | "autoload": { 17 | "psr-0": { 18 | "pmill\\Plesk": "src/" 19 | } 20 | }, 21 | "require": { 22 | "php": ">=5.3.0" 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /composer.lock: -------------------------------------------------------------------------------- 1 | { 2 | "_readme": [ 3 | "This file locks the dependencies of your project to a known state", 4 | "Read more about it at http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", 5 | "This file is @generated automatically" 6 | ], 7 | "hash": "88d626507d3b08dd7ed088eef1075e9a", 8 | "packages": [], 9 | "packages-dev": [], 10 | "aliases": [], 11 | "minimum-stability": "stable", 12 | "stability-flags": [], 13 | "prefer-stable": false, 14 | "prefer-lowest": false, 15 | "platform": { 16 | "php": ">=5.3.0" 17 | }, 18 | "platform-dev": [] 19 | } 20 | -------------------------------------------------------------------------------- /examples/APS/install_application.php: -------------------------------------------------------------------------------- 1 | 'example.org', 7 | 'package-id' => 1, 8 | ]; 9 | 10 | $request = new \pmill\Plesk\APS\InstallApplication($config, $params); 11 | $info = $request->process(); 12 | 13 | var_dump($info); 14 | 15 | if ($info === false) { 16 | var_dump($request->error->getMessage()); 17 | } 18 | -------------------------------------------------------------------------------- /examples/APS/list_available_packages.php: -------------------------------------------------------------------------------- 1 | process(); 11 | 12 | var_dump($info); -------------------------------------------------------------------------------- /examples/Clients/create_client.php: -------------------------------------------------------------------------------- 1 | 'name', 7 | 'username'=>'username', 8 | 'password'=>'password1!', 9 | ); 10 | 11 | $request = new \pmill\Plesk\CreateClient($config, $params); 12 | $info = $request->process(); 13 | 14 | var_dump($info); 15 | echo "
Created client id: ".$request->id; -------------------------------------------------------------------------------- /examples/Clients/delete_client.php: -------------------------------------------------------------------------------- 1 | 0, 7 | //'username'=>'', 8 | ); 9 | 10 | $request = new \pmill\Plesk\DeleteClient($config, $params); 11 | $info = $request->process(); 12 | 13 | var_dump($info); -------------------------------------------------------------------------------- /examples/Clients/get_client.php: -------------------------------------------------------------------------------- 1 | 4, 7 | //'username'=>'', 8 | ); 9 | 10 | $request = new \pmill\Plesk\GetClient($config, $params); 11 | $info = $request->process(); 12 | 13 | var_dump($info); -------------------------------------------------------------------------------- /examples/Clients/list_clients.php: -------------------------------------------------------------------------------- 1 | process(); 7 | 8 | var_dump($info); -------------------------------------------------------------------------------- /examples/Clients/update_client.php: -------------------------------------------------------------------------------- 1 | 'username', 7 | 'phone'=>'phone', 8 | 'email'=>'email@example.com', 9 | ); 10 | 11 | $request = new \pmill\Plesk\UpdateClient($config, $params); 12 | $info = $request->process(); 13 | 14 | var_dump($info); -------------------------------------------------------------------------------- /examples/DNS/list_dns_records.php: -------------------------------------------------------------------------------- 1 | 'example.com', 7 | ); 8 | 9 | $request = new \pmill\Plesk\ListDNSRecords($config, $params); 10 | $info = $request->process(); 11 | 12 | var_dump($info); -------------------------------------------------------------------------------- /examples/Databases/create_database.php: -------------------------------------------------------------------------------- 1 | 'database name', 7 | 'subscription_id'=>0, 8 | 'server_id'=>0, 9 | 'type'=>'mysql', 10 | ); 11 | 12 | $request = new \pmill\Plesk\CreateDatabase($config, $params); 13 | $info = $request->process(); 14 | 15 | var_dump($info); 16 | echo "
Created database id: ".$request->id; -------------------------------------------------------------------------------- /examples/Databases/create_database_user.php: -------------------------------------------------------------------------------- 1 | '0', 10 | 'username'=>'username', 11 | 'password'=>'password', 12 | ); 13 | 14 | /* 15 | * These options will create a universal database user for the specified database server and subscription 16 | */ 17 | $params = array( 18 | 'subscription_id'=>'0', 19 | 'server_id'=>'0', 20 | 'username'=>'username', 21 | 'password'=>'password', 22 | ); 23 | 24 | $request = new \pmill\Plesk\CreateDatabaseUser($config, $params); 25 | $info = $request->process(); 26 | 27 | var_dump($info); 28 | echo "
Created database user id: ".$request->id; -------------------------------------------------------------------------------- /examples/Databases/delete_database.php: -------------------------------------------------------------------------------- 1 | '', 7 | ); 8 | 9 | $request = new \pmill\Plesk\DeleteDatabase($config, $params); 10 | $info = $request->process(); 11 | 12 | var_dump($info); -------------------------------------------------------------------------------- /examples/Databases/get_database_user.php: -------------------------------------------------------------------------------- 1 | '0', 7 | ); 8 | 9 | $request = new \pmill\Plesk\GetDatabaseUser($config, $params); 10 | $info = $request->process(); 11 | 12 | var_dump($info); -------------------------------------------------------------------------------- /examples/Databases/list_database_servers.php: -------------------------------------------------------------------------------- 1 | process(); 10 | 11 | var_dump($info); -------------------------------------------------------------------------------- /examples/Databases/list_databases.php: -------------------------------------------------------------------------------- 1 | 0, 10 | ); 11 | 12 | $request = new \pmill\Plesk\ListDatabases($config, $params); 13 | $info = $request->process(); 14 | 15 | var_dump($info); -------------------------------------------------------------------------------- /examples/EmailAddresses/create_email_address.php: -------------------------------------------------------------------------------- 1 | 'test1365695330@example.com', 7 | 'password'=>'areallylongstringwithsomenumbers2', 8 | ); 9 | 10 | $request = new \pmill\Plesk\CreateEmailAddress($config, $params); 11 | $info = $request->process(); 12 | 13 | var_dump($info); -------------------------------------------------------------------------------- /examples/EmailAddresses/delete_email_address.php: -------------------------------------------------------------------------------- 1 | 'test1365695330@example.com', 7 | ); 8 | 9 | $request = new \pmill\Plesk\DeleteEmailAddress($config, $params); 10 | $info = $request->process(); 11 | 12 | var_dump($info); -------------------------------------------------------------------------------- /examples/EmailAddresses/list_email_addresses.php: -------------------------------------------------------------------------------- 1 | 'example.com', 7 | ); 8 | 9 | $request = new \pmill\Plesk\ListEmailAddresses($config, $params); 10 | $info = $request->process(); 11 | 12 | var_dump($info); -------------------------------------------------------------------------------- /examples/EmailAddresses/update_email_password.php: -------------------------------------------------------------------------------- 1 | 'test1365695330@example.com', 7 | 'password'=>'areallylongstringwithsomenumbers2', 8 | ); 9 | 10 | $request = new \pmill\Plesk\UpdateEmailPassword($config, $params); 11 | $info = $request->process(); 12 | 13 | var_dump($info); -------------------------------------------------------------------------------- /examples/MailService/update_preferences.php: -------------------------------------------------------------------------------- 1 | 1, 10 | 'nonexistent-user' => \pmill\Plesk\Helper\MailPreferences::NONEXISTENT_USER_BOUNCE, 11 | 'mailservice' => false, 12 | 'webmail' => true, 13 | 'spam-protect-sign' => true, 14 | 'greylisting' => false, 15 | ]; 16 | 17 | $request = new \pmill\Plesk\MailService\UpdatePreferences($config, $params); 18 | 19 | $info = $request->process(); 20 | var_dump($info); 21 | 22 | if ($info === false) { 23 | var_dump($request->error->getMessage()); 24 | } 25 | -------------------------------------------------------------------------------- /examples/Misc/get_server_info.php: -------------------------------------------------------------------------------- 1 | process(); 7 | 8 | var_dump($info); -------------------------------------------------------------------------------- /examples/Misc/list_ip_addresses.php: -------------------------------------------------------------------------------- 1 | process(); 7 | 8 | var_dump($info); -------------------------------------------------------------------------------- /examples/SSL/install_certificate.php: -------------------------------------------------------------------------------- 1 | 'test-ssl', 7 | 'admin' => true, 8 | 'csr' => '', 9 | 'cert' => '', 10 | 'pvt' => '', 11 | 'ip-address' => '127.0.0.1', 12 | ]; 13 | 14 | $request = new \pmill\Plesk\SSL\InstallCertificate($config, $params); 15 | $info = $request->process(); 16 | 17 | var_dump($info); 18 | 19 | if ($info === false) { 20 | var_dump($request->error->getMessage()); 21 | } 22 | -------------------------------------------------------------------------------- /examples/SecretKey/create_secret_key.php: -------------------------------------------------------------------------------- 1 | '', 7 | 'description' => 'Test Secret Key' 8 | ]; 9 | 10 | $request = new \pmill\Plesk\CreateSecretKey($config, $params); 11 | $info = $request->process(); 12 | 13 | var_dump($info); -------------------------------------------------------------------------------- /examples/SecretKey/delete_secret_key.php: -------------------------------------------------------------------------------- 1 | '6621a74e-e626-72d0-d3e7-8c9eb61b20da', 7 | ]; 8 | 9 | $request = new \pmill\Plesk\DeleteSecretKey($config, $params); 10 | $info = $request->process(); 11 | 12 | var_dump($info); -------------------------------------------------------------------------------- /examples/SecretKey/list_secret_keys.php: -------------------------------------------------------------------------------- 1 | process(); 7 | 8 | var_dump($info); -------------------------------------------------------------------------------- /examples/ServicePlans/get_service_plan.php: -------------------------------------------------------------------------------- 1 | '', 7 | 'guid'=>'130479c8-7792-b135-8b50-001faed5d517', 8 | ]; 9 | 10 | $request = new \pmill\Plesk\GetServicePlan($config, $params); 11 | $info = $request->process(); 12 | 13 | var_dump($info); -------------------------------------------------------------------------------- /examples/ServicePlans/list_service_plans.php: -------------------------------------------------------------------------------- 1 | process(); 7 | 8 | var_dump($info); -------------------------------------------------------------------------------- /examples/SiteAliases/create_site_alias.php: -------------------------------------------------------------------------------- 1 | 'example.com', 7 | 'alias'=>'testalias2.example.com', 8 | ); 9 | 10 | $request = new \pmill\Plesk\CreateSiteAlias($config, $params); 11 | $info = $request->process(); 12 | 13 | var_dump($info); -------------------------------------------------------------------------------- /examples/SiteAliases/delete_site_alias.php: -------------------------------------------------------------------------------- 1 | 'testalias2.example.com', 7 | ); 8 | 9 | $request = new \pmill\Plesk\DeleteSiteAlias($config, $params); 10 | $info = $request->process(); 11 | 12 | var_dump($info); -------------------------------------------------------------------------------- /examples/SiteAliases/list_site_aliases.php: -------------------------------------------------------------------------------- 1 | 'example.com', 7 | ); 8 | 9 | $request = new \pmill\Plesk\ListSiteAliases($config, $params); 10 | $info = $request->process(); 11 | 12 | var_dump($info); -------------------------------------------------------------------------------- /examples/Sites/create_site.php: -------------------------------------------------------------------------------- 1 | 'example.com', 7 | 'subscription_id'=>1, 8 | ); 9 | 10 | $request = new \pmill\Plesk\CreateSite($config, $params); 11 | $info = $request->process(); 12 | 13 | var_dump($info); 14 | echo "
Created site id: ".$request->id; -------------------------------------------------------------------------------- /examples/Sites/delete_site.php: -------------------------------------------------------------------------------- 1 | '', 7 | ); 8 | 9 | $request = new \pmill\Plesk\DeleteSite($config, $params); 10 | $info = $request->process(); 11 | 12 | var_dump($info); -------------------------------------------------------------------------------- /examples/Sites/get_site.php: -------------------------------------------------------------------------------- 1 | 'example.com', 7 | ); 8 | 9 | $request = new \pmill\Plesk\GetSite($config, $params); 10 | $info = $request->process(); 11 | 12 | var_dump($info); -------------------------------------------------------------------------------- /examples/Sites/list_sites.php: -------------------------------------------------------------------------------- 1 | 0, 10 | ); 11 | 12 | $request = new \pmill\Plesk\ListSites($config, $params); 13 | $info = $request->process(); 14 | 15 | var_dump($info); -------------------------------------------------------------------------------- /examples/Sites/update_site.php: -------------------------------------------------------------------------------- 1 | '', 7 | 'php'=>TRUE, 8 | 'php_handler_type'=>'module', 9 | 'webstat'=>'awstats', 10 | 'www_root'=>'', 11 | 'domain'=>'example.com', 12 | 'status'=>0, 13 | ); 14 | 15 | $request = new \pmill\Plesk\UpdateSite($config, $params); 16 | $info = $request->process(); 17 | 18 | var_dump($info); -------------------------------------------------------------------------------- /examples/SplClassLoader.php: -------------------------------------------------------------------------------- 1 | . 19 | */ 20 | 21 | /** 22 | * SplClassLoader implementation that implements the technical interoperability 23 | * standards for PHP 5.3 namespaces and class names. 24 | * 25 | * http://groups.google.com/group/php-standards/web/psr-0-final-proposal?pli=1 26 | * 27 | * // Example which loads classes for the Doctrine Common package in the 28 | * // Doctrine\Common namespace. 29 | * $classLoader = new SplClassLoader('Doctrine\Common', '/path/to/doctrine'); 30 | * $classLoader->register(); 31 | * 32 | * @license http://www.opensource.org/licenses/mit-license.html MIT License 33 | * @author Jonathan H. Wage 34 | * @author Roman S. Borschel 35 | * @author Matthew Weier O'Phinney 36 | * @author Kris Wallsmith 37 | * @author Fabien Potencier 38 | */ 39 | class SplClassLoader 40 | { 41 | private $_fileExtension = '.php'; 42 | private $_namespace; 43 | private $_includePath; 44 | private $_namespaceSeparator = '\\'; 45 | 46 | /** 47 | * Creates a new SplClassLoader that loads classes of the 48 | * specified namespace. 49 | * 50 | * @param string $ns The namespace to use. 51 | */ 52 | public function __construct($ns = null, $includePath = null) 53 | { 54 | $this->_namespace = $ns; 55 | $this->_includePath = $includePath; 56 | } 57 | 58 | /** 59 | * Sets the namespace separator used by classes in the namespace of this class loader. 60 | * 61 | * @param string $sep The separator to use. 62 | */ 63 | public function setNamespaceSeparator($sep) 64 | { 65 | $this->_namespaceSeparator = $sep; 66 | } 67 | 68 | /** 69 | * Gets the namespace seperator used by classes in the namespace of this class loader. 70 | * 71 | * @return void 72 | */ 73 | public function getNamespaceSeparator() 74 | { 75 | return $this->_namespaceSeparator; 76 | } 77 | 78 | /** 79 | * Sets the base include path for all class files in the namespace of this class loader. 80 | * 81 | * @param string $includePath 82 | */ 83 | public function setIncludePath($includePath) 84 | { 85 | $this->_includePath = $includePath; 86 | } 87 | 88 | /** 89 | * Gets the base include path for all class files in the namespace of this class loader. 90 | * 91 | * @return string $includePath 92 | */ 93 | public function getIncludePath() 94 | { 95 | return $this->_includePath; 96 | } 97 | 98 | /** 99 | * Sets the file extension of class files in the namespace of this class loader. 100 | * 101 | * @param string $fileExtension 102 | */ 103 | public function setFileExtension($fileExtension) 104 | { 105 | $this->_fileExtension = $fileExtension; 106 | } 107 | 108 | /** 109 | * Gets the file extension of class files in the namespace of this class loader. 110 | * 111 | * @return string $fileExtension 112 | */ 113 | public function getFileExtension() 114 | { 115 | return $this->_fileExtension; 116 | } 117 | 118 | /** 119 | * Installs this class loader on the SPL autoload stack. 120 | */ 121 | public function register() 122 | { 123 | spl_autoload_register(array($this, 'loadClass')); 124 | } 125 | 126 | /** 127 | * Uninstalls this class loader from the SPL autoloader stack. 128 | */ 129 | public function unregister() 130 | { 131 | spl_autoload_unregister(array($this, 'loadClass')); 132 | } 133 | 134 | /** 135 | * Loads the given class or interface. 136 | * 137 | * @param string $className The name of the class to load. 138 | * @return void 139 | */ 140 | public function loadClass($className) 141 | { 142 | if (null === $this->_namespace || $this->_namespace.$this->_namespaceSeparator === substr($className, 0, strlen($this->_namespace.$this->_namespaceSeparator))) { 143 | $fileName = ''; 144 | $namespace = ''; 145 | if (false !== ($lastNsPos = strripos($className, $this->_namespaceSeparator))) { 146 | $namespace = substr($className, 0, $lastNsPos); 147 | $className = substr($className, $lastNsPos + 1); 148 | $fileName = str_replace($this->_namespaceSeparator, DIRECTORY_SEPARATOR, $namespace) . DIRECTORY_SEPARATOR; 149 | } 150 | $fileName .= str_replace('_', DIRECTORY_SEPARATOR, $className) . $this->_fileExtension; 151 | 152 | require ($this->_includePath !== null ? $this->_includePath . DIRECTORY_SEPARATOR : '') . $fileName; 153 | } 154 | } 155 | } 156 | -------------------------------------------------------------------------------- /examples/Subdomains/create_subdomain.php: -------------------------------------------------------------------------------- 1 | 'pmill.co.uk', 7 | 'subdomain'=>'test1', 8 | 'www_root'=>'/subdomains/test1', 9 | ); 10 | 11 | $request = new \pmill\Plesk\CreateSubdomain($config, $params); 12 | $info = $request->process(); 13 | 14 | var_dump($info); -------------------------------------------------------------------------------- /examples/Subdomains/delete_subdomain.php: -------------------------------------------------------------------------------- 1 | 'testsubdomain.example.com', 7 | ); 8 | 9 | $request = new \pmill\Plesk\DeleteSubdomain($config, $params); 10 | $info = $request->process(); 11 | 12 | var_dump($info); -------------------------------------------------------------------------------- /examples/Subdomains/get_subdomain.php: -------------------------------------------------------------------------------- 1 | 'testsubdomain.example.com', 7 | ); 8 | 9 | $request = new \pmill\Plesk\GetSubdomain($config, $params); 10 | $info = $request->process(); 11 | 12 | var_dump($info); -------------------------------------------------------------------------------- /examples/Subdomains/list_subdomains.php: -------------------------------------------------------------------------------- 1 | 'example.com', 7 | ); 8 | 9 | $request = new \pmill\Plesk\ListSubdomains($config, $params); 10 | $info = $request->process(); 11 | 12 | var_dump($info); -------------------------------------------------------------------------------- /examples/Subdomains/rename_subdomain.php: -------------------------------------------------------------------------------- 1 | 'testsubdomain.example.com', 7 | 'name'=>'testsubdomin1', 8 | ); 9 | 10 | $request = new \pmill\Plesk\RenameSubdomain($config, $params); 11 | $info = $request->process(); 12 | 13 | var_dump($info); -------------------------------------------------------------------------------- /examples/Subdomains/update_subdomain.php: -------------------------------------------------------------------------------- 1 | 'test1.pmill.co.uk', 7 | 'www_root'=>'/subdomains/testsubdomainrename', 8 | ); 9 | 10 | $request = new \pmill\Plesk\UpdateSubdomain($config, $params); 11 | $info = $request->process(); 12 | 13 | var_dump($info); -------------------------------------------------------------------------------- /examples/Subscriptions/create_subscription.php: -------------------------------------------------------------------------------- 1 | 'example.com', 7 | 'username'=>'username', 8 | 'password'=>'password1!', 9 | 'ip_address'=>'192.168.1.2', 10 | 'owner_id'=>0, 11 | 'service_plan_id'=>0, 12 | ); 13 | 14 | $request = new \pmill\Plesk\CreateSubscription($config, $params); 15 | $info = $request->process(); 16 | 17 | var_dump($info); -------------------------------------------------------------------------------- /examples/Subscriptions/delete_subscription.php: -------------------------------------------------------------------------------- 1 | '', 7 | ); 8 | 9 | $request = new \pmill\Plesk\DeleteSubscription($config, $params); 10 | $info = $request->process(); 11 | 12 | var_dump($info); -------------------------------------------------------------------------------- /examples/Subscriptions/get_subscription.php: -------------------------------------------------------------------------------- 1 | '1', 10 | ); 11 | 12 | $request = new \pmill\Plesk\GetSubscription($config, $params); 13 | $info = $request->process(); 14 | 15 | var_dump($info); 16 | 17 | if ($info === false) { 18 | var_dump($request->error); 19 | } 20 | -------------------------------------------------------------------------------- /examples/Subscriptions/get_traffic.php: -------------------------------------------------------------------------------- 1 | '1', 10 | // 'name' => 'demo.parallels.com', 11 | // 'owner-login' => 'customer', 12 | // 'since_date' => '2016-06-01', 13 | // 'to_date' => '2016-06-10' 14 | ); 15 | 16 | $request = new \pmill\Plesk\GetTraffic($config, $params); 17 | $info = $request->process(); 18 | 19 | var_dump($info); 20 | 21 | if ($info === false) { 22 | var_dump($request->error); 23 | } 24 | -------------------------------------------------------------------------------- /examples/Subscriptions/list_subscriptions.php: -------------------------------------------------------------------------------- 1 | '', 10 | ); 11 | 12 | $request = new \pmill\Plesk\ListSubscriptions($config, $params); 13 | $info = $request->process(); 14 | 15 | var_dump($info); 16 | 17 | if ($info === false) { 18 | var_dump($request->error); 19 | } -------------------------------------------------------------------------------- /examples/Wordpress/activate_plugin.php: -------------------------------------------------------------------------------- 1 | 1, 10 | 'plugin_id' => 'wp-super-cache_1.4.8', 11 | ]; 12 | 13 | $request = new \pmill\Plesk\Wordpress\ActivatePlugin($config, $params); 14 | 15 | $info = $request->process(); 16 | var_dump($info); 17 | 18 | if ($info === false) { 19 | var_dump($request->error->getMessage()); 20 | } 21 | -------------------------------------------------------------------------------- /examples/Wordpress/activate_theme.php: -------------------------------------------------------------------------------- 1 | 1, 10 | 'theme_id' => 'emmet-lite_1.4.0', 11 | ]; 12 | 13 | $request = new \pmill\Plesk\Wordpress\ActivateTheme($config, $params); 14 | 15 | $info = $request->process(); 16 | var_dump($info); 17 | 18 | if ($info === false) { 19 | var_dump($request->error->getMessage()); 20 | } 21 | -------------------------------------------------------------------------------- /examples/Wordpress/clear_cache.php: -------------------------------------------------------------------------------- 1 | 1, 10 | ]; 11 | 12 | $request = new \pmill\Plesk\Wordpress\ClearCache($config, $params); 13 | 14 | $info = $request->process(); 15 | var_dump($info); 16 | 17 | if ($info === false) { 18 | var_dump($request->error->getMessage()); 19 | } 20 | -------------------------------------------------------------------------------- /examples/Wordpress/deactivate_plugin.php: -------------------------------------------------------------------------------- 1 | 1, 10 | 'plugin_id' => 'wp-super-cache_1.4.8', 11 | ]; 12 | 13 | $request = new \pmill\Plesk\Wordpress\DeactivatePlugin($config, $params); 14 | 15 | $info = $request->process(); 16 | var_dump($info); 17 | 18 | if ($info === false) { 19 | var_dump($request->error->getMessage()); 20 | } 21 | -------------------------------------------------------------------------------- /examples/Wordpress/disable_auto_updates.php: -------------------------------------------------------------------------------- 1 | 1, 10 | ]; 11 | 12 | $request = new \pmill\Plesk\Wordpress\DisableAutoUpdates($config, $params); 13 | 14 | $info = $request->process(); 15 | var_dump($info); 16 | 17 | if ($info === false) { 18 | var_dump($request->error->getMessage()); 19 | } 20 | -------------------------------------------------------------------------------- /examples/Wordpress/enable_auto_updates.php: -------------------------------------------------------------------------------- 1 | 1, 10 | ]; 11 | 12 | $request = new \pmill\Plesk\Wordpress\EnableAutoUpdates($config, $params); 13 | 14 | $info = $request->process(); 15 | var_dump($info); 16 | 17 | if ($info === false) { 18 | var_dump($request->error->getMessage()); 19 | } 20 | -------------------------------------------------------------------------------- /examples/Wordpress/get_plugin_list.php: -------------------------------------------------------------------------------- 1 | 1, 10 | ]; 11 | 12 | $request = new \pmill\Plesk\Wordpress\GetPluginList($config, $params); 13 | 14 | $info = $request->process(); 15 | var_dump($info); 16 | 17 | if ($info === false) { 18 | var_dump($request->error->getMessage()); 19 | } 20 | -------------------------------------------------------------------------------- /examples/Wordpress/get_security_status.php: -------------------------------------------------------------------------------- 1 | 1, 10 | ]; 11 | 12 | $request = new \pmill\Plesk\Wordpress\GetSecurityStatus($config, $params); 13 | 14 | $info = $request->process(); 15 | var_dump($info); 16 | 17 | if ($info === false) { 18 | var_dump($request->error->getMessage()); 19 | } 20 | -------------------------------------------------------------------------------- /examples/Wordpress/get_theme_list.php: -------------------------------------------------------------------------------- 1 | 1, 10 | ]; 11 | 12 | $request = new \pmill\Plesk\Wordpress\GetThemeList($config, $params); 13 | 14 | $info = $request->process(); 15 | var_dump($info); 16 | 17 | if ($info === false) { 18 | var_dump($request->error->getMessage()); 19 | } 20 | -------------------------------------------------------------------------------- /examples/Wordpress/install_plugin.php: -------------------------------------------------------------------------------- 1 | 1, 10 | 'plugin_id' => 'wp-super-cache', 11 | ]; 12 | 13 | $request = new \pmill\Plesk\Wordpress\InstallPlugin($config, $params); 14 | 15 | $info = $request->process(); 16 | var_dump($info); 17 | 18 | if ($info === false) { 19 | var_dump($request->error->getMessage()); 20 | } 21 | -------------------------------------------------------------------------------- /examples/Wordpress/install_theme.php: -------------------------------------------------------------------------------- 1 | 1, 10 | 'theme_id' => 'emmet-lite', 11 | ]; 12 | 13 | $request = new \pmill\Plesk\Wordpress\InstallTheme($config, $params); 14 | 15 | $info = $request->process(); 16 | var_dump($info); 17 | 18 | if ($info === false) { 19 | var_dump($request->error->getMessage()); 20 | } 21 | -------------------------------------------------------------------------------- /examples/Wordpress/list_instances.php: -------------------------------------------------------------------------------- 1 | process(); 10 | 11 | var_dump($info); 12 | -------------------------------------------------------------------------------- /examples/Wordpress/remove_instance.php: -------------------------------------------------------------------------------- 1 | 2, 10 | ]; 11 | 12 | $request = new \pmill\Plesk\Wordpress\RemoveInstance($config, $params); 13 | 14 | $info = $request->process(); 15 | var_dump($info); 16 | 17 | if ($info === false) { 18 | var_dump($request->error->getMessage()); 19 | } 20 | -------------------------------------------------------------------------------- /examples/Wordpress/search_plugins.php: -------------------------------------------------------------------------------- 1 | 'Responsify', 10 | ]; 11 | 12 | $request = new \pmill\Plesk\Wordpress\SearchPlugins($config, $params); 13 | 14 | $info = $request->process(); 15 | var_dump($info); 16 | 17 | if ($info === false) { 18 | var_dump($request->error->getMessage()); 19 | } 20 | -------------------------------------------------------------------------------- /examples/Wordpress/search_themes.php: -------------------------------------------------------------------------------- 1 | 'Lite', 10 | ]; 11 | 12 | $request = new \pmill\Plesk\Wordpress\SearchThemes($config, $params); 13 | 14 | $info = $request->process(); 15 | var_dump($info); 16 | 17 | if ($info === false) { 18 | var_dump($request->error->getMessage()); 19 | } 20 | -------------------------------------------------------------------------------- /examples/Wordpress/uninstall_plugin.php: -------------------------------------------------------------------------------- 1 | 1, 10 | 'plugin_id' => 'wp-super-cache_1.4.8', 11 | ]; 12 | 13 | $request = new \pmill\Plesk\Wordpress\UninstallPlugin($config, $params); 14 | 15 | $info = $request->process(); 16 | var_dump($info); 17 | 18 | if ($info === false) { 19 | var_dump($request->error->getMessage()); 20 | } 21 | -------------------------------------------------------------------------------- /examples/Wordpress/uninstall_theme.php: -------------------------------------------------------------------------------- 1 | 1, 10 | 'theme_id' => 'emmet-lite_1.4.0', 11 | ]; 12 | 13 | $request = new \pmill\Plesk\Wordpress\UninstallTheme($config, $params); 14 | 15 | $info = $request->process(); 16 | var_dump($info); 17 | 18 | if ($info === false) { 19 | var_dump($request->error->getMessage()); 20 | } 21 | -------------------------------------------------------------------------------- /examples/Wordpress/update_core.php: -------------------------------------------------------------------------------- 1 | 1, 10 | ]; 11 | 12 | $request = new \pmill\Plesk\Wordpress\UpdateCore($config, $params); 13 | 14 | $info = $request->process(); 15 | var_dump($info); 16 | 17 | if ($info === false) { 18 | var_dump($request->error->getMessage()); 19 | } 20 | -------------------------------------------------------------------------------- /examples/Wordpress/update_plugin.php: -------------------------------------------------------------------------------- 1 | 1, 10 | 'plugin_id' => 'wp-super-cache_1.4.8', 11 | ]; 12 | 13 | $request = new \pmill\Plesk\Wordpress\UpdatePlugin($config, $params); 14 | 15 | $info = $request->process(); 16 | var_dump($info); 17 | 18 | if ($info === false) { 19 | var_dump($request->error->getMessage()); 20 | } 21 | -------------------------------------------------------------------------------- /examples/Wordpress/update_theme.php: -------------------------------------------------------------------------------- 1 | 1, 10 | 'theme_id' => 'emmet-lite_1.4.0', 11 | ]; 12 | 13 | $request = new \pmill\Plesk\Wordpress\UpdateTheme($config, $params); 14 | 15 | $info = $request->process(); 16 | var_dump($info); 17 | 18 | if ($info === false) { 19 | var_dump($request->error->getMessage()); 20 | } 21 | -------------------------------------------------------------------------------- /examples/config.php: -------------------------------------------------------------------------------- 1 | register(); 6 | 7 | $config = array( 8 | 'host'=>'plesk12-webadmin.demo.parallels.com', 9 | 'username'=>'admin', 10 | 'password'=>'panel', 11 | ); 12 | -------------------------------------------------------------------------------- /src/pmill/Plesk/APS/InstallApplication.php: -------------------------------------------------------------------------------- 1 | 18 | 19 | 20 | 21 | {OPTIONS} 22 | {PACKAGE-ID} 23 | 24 | 25 | 26 | EOT; 27 | 28 | /** 29 | * @var array 30 | */ 31 | protected $default_params = [ 32 | 'package-id' => null, 33 | ]; 34 | 35 | /** 36 | * @param array $config 37 | * @param array $params 38 | * @param HttpRequestContract|null $http 39 | */ 40 | public function __construct(array $config, array $params = [], HttpRequestContract $http = null) 41 | { 42 | $optionsNodes = []; 43 | $optionsNodes[] = $this->getIdentifierNode($params); 44 | 45 | if ($databaseNode = $this->getDatabaseNode($params)) { 46 | $optionsNodes[] = $databaseNode; 47 | } 48 | 49 | if ($settingsNode = $this->getSettingsNode($params)) { 50 | $optionsNodes[] = $settingsNode ; 51 | } 52 | 53 | if (isset($params['ssl'])) { 54 | $optionsNodes[] = new Node('ssl', $params['ssl']); 55 | } 56 | 57 | if (isset($params['url-prefix'])) { 58 | $optionsNodes[] = new Node('url-prefix', $params['url-prefix']); 59 | } 60 | 61 | $params['options'] = new NodeList($optionsNodes); 62 | 63 | parent::__construct($config, $params, $http); 64 | } 65 | 66 | /** 67 | * @param SimpleXMLElement $xml 68 | * @return bool 69 | * @throws ApiRequestException 70 | */ 71 | protected function processResponse($xml) 72 | { 73 | if ((string) $xml->{'aps'}->{'install'}->result->status === 'error') { 74 | throw new ApiRequestException($xml->{'aps'}->{'install'}->result); 75 | } 76 | 77 | return true; 78 | } 79 | 80 | /** 81 | * @param array $params 82 | * @return null|Node 83 | */ 84 | protected function getIdentifierNode(array $params) 85 | { 86 | foreach (['domain-id', 'domain-name', 'subdomain-id', 'subdomain-name'] as $key) { 87 | if (isset($params[$key])) { 88 | return new Node($key, $params[$key]); 89 | } 90 | } 91 | 92 | return null; 93 | } 94 | 95 | /** 96 | * @param array $params 97 | * @return null|Node 98 | */ 99 | protected function getDatabaseNode(array $params) 100 | { 101 | if (isset($params['database']) && is_array($params['database'])) { 102 | $nodes = []; 103 | 104 | foreach (['name', 'login', 'password', 'prefix', 'server'] as $key) { 105 | if (isset($params['database'][$key])) { 106 | $nodes[] = new Node($key, $params['database'][$key]); 107 | } 108 | } 109 | 110 | return new Node('database', $nodes); 111 | } 112 | 113 | return null; 114 | } 115 | 116 | /** 117 | * @param array $params 118 | * @return null|Node 119 | */ 120 | protected function getSettingsNode(array $params) 121 | { 122 | if (isset($params['settings']) && is_array($params['settings'])) { 123 | $nodes = []; 124 | 125 | foreach ($params['settings'] as $key => $value) { 126 | $nodes[] = new Node($key, $value); 127 | } 128 | 129 | return new Node('settings', $nodes); 130 | } 131 | 132 | return null; 133 | } 134 | } 135 | -------------------------------------------------------------------------------- /src/pmill/Plesk/APS/ListAvailablePackages.php: -------------------------------------------------------------------------------- 1 | 18 | 19 | 20 | 21 | {FILTER} 22 | 23 | 24 | 25 | EOT; 26 | 27 | /** 28 | * @param array $config 29 | * @param array $params 30 | * @param HttpRequestContract $http 31 | * @throws ApiRequestException 32 | */ 33 | public function __construct(array $config, array $params = [], HttpRequestContract $http = null) 34 | { 35 | $filterNode = new Node('filter'); 36 | 37 | if (isset($params['package-id'])) { 38 | if (!is_array($params['package-id'])) { 39 | $params['package-id'] = [$params['package-id']]; 40 | } 41 | 42 | $idNodes = []; 43 | foreach ($params['package-id'] as $id) { 44 | $idNodes[] = new Node('package-id', $id); 45 | } 46 | 47 | $filterNode->setValue(new Node('package-id', new NodeList($idNodes))); 48 | } 49 | 50 | $params['filter'] = $filterNode; 51 | 52 | parent::__construct($config, $params, $http); 53 | } 54 | 55 | /** 56 | * @param SimpleXMLElement $xml 57 | * @return array 58 | * @throws ApiRequestException 59 | */ 60 | protected function processResponse($xml) 61 | { 62 | $response = []; 63 | 64 | foreach ($xml->{'aps'}->{'get-packages-list'}->result as $result) { 65 | if ((string) $result->status == "error") { 66 | $response[] = [ 67 | 'status' => (string) $result->status, 68 | 'filter-id' => (int) $result->{'filter-id'}, 69 | 'errcode' => (string) $result->errcode, 70 | 'errtext' => (string) $result->errtext, 71 | ]; 72 | } else { 73 | $response[] = [ 74 | 'status' => (string) $result->status, 75 | 'id' => (int) $result->package->id, 76 | 'filter-id' => (int) $result->{'filter-id'}, 77 | 'title' => (string) $result->package->title, 78 | 'version' => (string) $result->package->version, 79 | 'release' => (string) $result->package->release, 80 | 'vendor' => (string) $result->package->vendor, 81 | 'packager' => (string) $result->package->packager, 82 | 'is_uploaded' => (int) $result->package->is_uploaded === 1, 83 | 'is_visible' => (int) $result->package->is_visible === 1, 84 | 'global_settings_not_set' => (int) $result->package->global_settings_not_set === 1, 85 | ]; 86 | } 87 | } 88 | 89 | return $response; 90 | } 91 | } 92 | -------------------------------------------------------------------------------- /src/pmill/Plesk/ApiRequestException.php: -------------------------------------------------------------------------------- 1 | errtext) ? (string)$errorNode->errtext : ''; 17 | $code = isset($errorNode->errcode) ? (int)$errorNode->errcode : ''; 18 | } 19 | 20 | parent::__construct($message, $code); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/pmill/Plesk/BaseRequest.php: -------------------------------------------------------------------------------- 1 | 39 | {KEY} 40 | {VALUE} 41 | 42 | EOT; 43 | 44 | /** 45 | * @var string 46 | */ 47 | public $xml_filename; 48 | 49 | /** 50 | * @var string 51 | */ 52 | public $xml_packet; 53 | 54 | /** 55 | * @var string 56 | */ 57 | public $request_header; 58 | 59 | /** 60 | * @var string|\Exception 61 | */ 62 | public $error; 63 | 64 | /** 65 | * @var string 66 | */ 67 | public $xml_response; 68 | 69 | /** 70 | * @param $xml 71 | * @return string|bool|array 72 | */ 73 | abstract protected function processResponse($xml); 74 | 75 | /** 76 | * @param array $config 77 | * @param array $params 78 | * @param HttpRequestContract|null $http 79 | * @throws ApiRequestException 80 | */ 81 | public function __construct(array $config, array $params = [], HttpRequestContract $http = null) 82 | { 83 | $this->config = $config; 84 | $this->params = $params; 85 | 86 | if (!$this->check_params()) { 87 | throw new ApiRequestException("Error: Incorrect request parameters submitted"); 88 | } 89 | 90 | $this->params = Xml::sanitizeArray($this->params); 91 | 92 | $this->http = is_null($http) ? new CurlHttpRequest($this->config['host']) : $http; 93 | if (isset($this->config['username']) && isset($this->config['password'])) { 94 | $this->http->setCredentials($this->config['username'], $this->config['password']); 95 | } 96 | 97 | if (isset($this->config['key'])) { 98 | $this->http->setSecretKey($this->config['key']); 99 | } 100 | 101 | if (is_null($this->xml_packet) && file_exists($this->xml_filename)) { 102 | $this->xml_packet = file_get_contents($this->xml_filename); 103 | } 104 | 105 | if (is_null($this->xml_packet)) { 106 | throw new ApiRequestException("Error: No XML Packet supplied"); 107 | } 108 | } 109 | 110 | /** 111 | * Checks the required parameters were submitted. Optional parameters are specified with a non NULL value in the 112 | * class declaration 113 | * 114 | * @return bool 115 | * @throws ApiRequestException 116 | */ 117 | protected function check_params() 118 | { 119 | if (!is_array($this->default_params)) { 120 | return false; 121 | } 122 | 123 | foreach ($this->default_params as $key => $value) { 124 | if (!isset($this->params[$key])) { 125 | if (is_null($value)) { 126 | return false; 127 | } else { 128 | $this->params[$key] = $value; 129 | } 130 | } 131 | } 132 | 133 | return true; 134 | } 135 | 136 | /** 137 | * Generates the xml for a standard property list 138 | * 139 | * @param array $properties 140 | * @return string 141 | */ 142 | protected function generatePropertyList(array $properties) 143 | { 144 | return Xml::generatePropertyList($properties); 145 | } 146 | 147 | /** 148 | * Generates the xml for a list of nodes 149 | * 150 | * @param array $properties 151 | * @return string 152 | */ 153 | protected function generateNodeList(array $properties) 154 | { 155 | return Xml::generateNodeList($this->node_mapping, $properties); 156 | } 157 | 158 | /** 159 | * Submits the xml packet to the Plesk server and forwards the response on for processing 160 | * 161 | * @return object 162 | */ 163 | public function process() 164 | { 165 | try { 166 | $response = $this->sendRequest($this->getPacket()); 167 | 168 | if ($response !== false) { 169 | $this->xml_response = $response; 170 | $responseXml = Xml::convertStringToXml($response); 171 | $this->checkResponse($responseXml); 172 | 173 | return $this->processResponse($responseXml); 174 | } 175 | } catch (ApiRequestException $e) { 176 | $this->error = $e; 177 | } 178 | 179 | return false; 180 | } 181 | 182 | /** 183 | * Inserts the submitted parameters into the xml packet 184 | * 185 | * @return string 186 | */ 187 | protected function getPacket() 188 | { 189 | $packet = $this->xml_packet; 190 | 191 | foreach ($this->params as $key => $value) { 192 | if (is_bool($value)) { 193 | $value = $value ? 'true' : 'false'; 194 | } 195 | 196 | $packet = str_replace('{'.strtoupper($key).'}', $value, $packet); 197 | } 198 | 199 | return $packet; 200 | } 201 | 202 | /** 203 | * Performs a Plesk API request, returns raw API response text 204 | * 205 | * @param string $packet 206 | * 207 | * @return string 208 | * @throws ApiRequestException 209 | */ 210 | private function sendRequest($packet) 211 | { 212 | $domdoc = new \DomDocument('1.0', 'UTF-8'); 213 | if ($domdoc->loadXml($packet) === false) { 214 | $this->error = 'Failed to load payload'; 215 | return false; 216 | } 217 | 218 | $body = $domdoc->saveHTML(); 219 | return $this->http->sendRequest($body); 220 | } 221 | 222 | /** 223 | * Check data in API response 224 | * 225 | * @param SimpleXMLElement $response 226 | * 227 | * @return void 228 | * @throws ApiRequestException 229 | */ 230 | private function checkResponse(SimpleXMLElement $response) 231 | { 232 | if ((string)$response->system->status === 'error') { 233 | throw new ApiRequestException($response->system); 234 | } 235 | } 236 | } 237 | -------------------------------------------------------------------------------- /src/pmill/Plesk/CreateClient.php: -------------------------------------------------------------------------------- 1 | 11 | 12 | 13 | 14 | 15 | {NODES} 16 | 17 | 18 | 19 | 20 | EOT; 21 | 22 | /** 23 | * @var int 24 | */ 25 | public $id; 26 | 27 | /** 28 | * @var array 29 | */ 30 | protected $default_params = [ 31 | 'company_name' => '', 32 | 'contact_name' => null, 33 | 'username' => null, 34 | 'password' => null, 35 | 'status' => 0, 36 | 'phone' => '', 37 | 'fax' => '', 38 | 'email' => '', 39 | 'address' => '', 40 | 'city' => '', 41 | 'state' => '', 42 | 'post_code' => '', 43 | 'country' => '', 44 | ]; 45 | 46 | /** 47 | * @var array 48 | */ 49 | protected $node_mapping = [ 50 | 'company_name' => 'cname', 51 | 'contact_name' => 'pname', 52 | 'username' => 'login', 53 | 'password' => 'passwd', 54 | 'status' => 'status', 55 | 'phone' => 'phone', 56 | 'fax' => 'fax', 57 | 'email' => 'email', 58 | 'address' => 'address', 59 | 'city' => 'city', 60 | 'state' => 'state', 61 | 'post_code' => 'pcode', 62 | 'country' => 'country', 63 | ]; 64 | 65 | /** 66 | * CreateClient constructor. 67 | * @param array $config 68 | * @param array $params 69 | */ 70 | public function __construct(array $config, array $params) 71 | { 72 | $params['nodes'] = $this->generateNodeList($params); 73 | parent::__construct($config, $params); 74 | } 75 | 76 | /** 77 | * @param $xml 78 | * @return bool 79 | * @throws ApiRequestException 80 | */ 81 | protected function processResponse($xml) 82 | { 83 | $result = $xml->customer->add->result; 84 | 85 | if ($result->status == 'error') { 86 | throw new ApiRequestException($result); 87 | } 88 | 89 | $this->id = (int)$result->id; 90 | return true; 91 | } 92 | } 93 | -------------------------------------------------------------------------------- /src/pmill/Plesk/CreateDatabase.php: -------------------------------------------------------------------------------- 1 | 11 | 12 | 13 | 14 | {SUBSCRIPTION_ID} 15 | {NAME} 16 | {TYPE} 17 | {SERVER_ID} 18 | 19 | 20 | 21 | EOT; 22 | 23 | /** 24 | * @var int 25 | */ 26 | public $id; 27 | 28 | /** 29 | * @var array 30 | */ 31 | protected $default_params = [ 32 | 'subscription_id' => null, 33 | 'server_id' => null, 34 | 'name' => null, 35 | 'type' => 'mysql' 36 | ]; 37 | 38 | /** 39 | * @param $xml 40 | * @return bool 41 | * @throws ApiRequestException 42 | */ 43 | protected function processResponse($xml) 44 | { 45 | if ($xml->database->{'add-db'}->result->status == 'error') { 46 | throw new ApiRequestException($xml->database->{'add-db'}->result); 47 | } 48 | 49 | $this->id = (int)$xml->database->{'add-db'}->result->id; 50 | return true; 51 | } 52 | } -------------------------------------------------------------------------------- /src/pmill/Plesk/CreateDatabaseUser.php: -------------------------------------------------------------------------------- 1 | 11 | 12 | 13 | 14 | {OPTIONS} 15 | {USERNAME} 16 | {PASSWORD} 17 | 18 | 19 | 20 | EOT; 21 | 22 | /** 23 | * @var int 24 | */ 25 | public $id; 26 | 27 | /** 28 | * @var array 29 | */ 30 | protected $default_params = [ 31 | 'options' => null, 32 | 'username' => null, 33 | 'password' => null 34 | ]; 35 | 36 | public function __construct($config, $params) 37 | { 38 | if (isset($params['server_id']) && isset($params['subscription_id'])) { 39 | $params['options'] = new NodeList([ 40 | new Node('webspace-id', $params['subscription_id']), 41 | new Node('db-server-id', $params['server_id']), 42 | ]); 43 | } elseif (isset($params['database_id'])) { 44 | $params['options'] = new Node('db-id', $params['database_id']); 45 | } 46 | 47 | parent::__construct($config, $params); 48 | } 49 | 50 | /** 51 | * @param $xml 52 | * @return bool 53 | * @throws ApiRequestException 54 | */ 55 | protected function processResponse($xml) 56 | { 57 | if ($xml->database->{'add-db-user'}->result->status == 'error') { 58 | throw new ApiRequestException($xml->database->{'add-db-user'}->result); 59 | } 60 | 61 | $this->id = (int)$xml->database->{'add-db-user'}->result->id; 62 | return true; 63 | } 64 | 65 | } -------------------------------------------------------------------------------- /src/pmill/Plesk/CreateEmailAddress.php: -------------------------------------------------------------------------------- 1 | 11 | 12 | 13 | 14 | 15 | {SITE_ID} 16 | 17 | {USERNAME} 18 | 19 | {ENABLED} 20 | 21 | 22 | {PASSWORD} 23 | plain 24 | 25 | 26 | 27 | 28 | 29 | 30 | EOT; 31 | 32 | /** 33 | * @var int 34 | */ 35 | public $id; 36 | 37 | /** 38 | * @var array 39 | */ 40 | protected $default_params = [ 41 | 'email' => null, 42 | 'password' => null, 43 | 'enabled' => true, 44 | ]; 45 | 46 | /** 47 | * @param array $config 48 | * @param array $params 49 | * @throws ApiRequestException 50 | */ 51 | public function __construct($config, $params) 52 | { 53 | parent::__construct($config, $params); 54 | 55 | if (!filter_var($this->params['email'], FILTER_VALIDATE_EMAIL)) { 56 | throw new ApiRequestException("Error: Invalid email submitted"); 57 | } 58 | 59 | list($username, $domain) = explode("@", $this->params['email']); 60 | 61 | $request = new GetSite($config, ['domain' => $domain]); 62 | $info = $request->process(); 63 | 64 | $this->params['site_id'] = $info['id']; 65 | $this->params['username'] = $username; 66 | } 67 | 68 | /** 69 | * @param $xml 70 | * @return bool 71 | * @throws ApiRequestException 72 | */ 73 | protected function processResponse($xml) 74 | { 75 | $result = $xml->mail->create->result; 76 | 77 | if ($result->status == 'error') { 78 | throw new ApiRequestException($result); 79 | } 80 | 81 | $this->id = (int)$result->mailname->id; 82 | return true; 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /src/pmill/Plesk/CreateSecretKey.php: -------------------------------------------------------------------------------- 1 | 11 | 12 | 13 | 14 | {IP_ADDRESS} 15 | {DESCRIPTION} 16 | 17 | 18 | 19 | EOT; 20 | 21 | /** 22 | * @var array 23 | */ 24 | protected $default_params = [ 25 | 'ip_address' => null, 26 | ]; 27 | 28 | /** 29 | * @var string 30 | */ 31 | public $key; 32 | 33 | /** 34 | * @param array $config 35 | * @param array $params 36 | */ 37 | public function __construct(array $config, array $params = []) 38 | { 39 | if (isset($params['description'])) { 40 | $params['description'] = new Node('description', $params['description']); 41 | } else { 42 | $params['description'] = ''; 43 | } 44 | 45 | parent::__construct($config, $params); 46 | } 47 | 48 | /** 49 | * @param $xml 50 | * @return bool 51 | * @throws ApiRequestException 52 | */ 53 | protected function processResponse($xml) 54 | { 55 | if ($xml->{'secret_key'}->create->result->status == 'error') { 56 | throw new ApiRequestException($xml->{'secret_key'}->create->result); 57 | } 58 | 59 | $this->key = (string)$xml->{'secret_key'}->create->result->key; 60 | return true; 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /src/pmill/Plesk/CreateSite.php: -------------------------------------------------------------------------------- 1 | 11 | 12 | 13 | 14 | 15 | {DOMAIN} 16 | {SUBSCRIPTION_ID} 17 | 18 | 19 | 20 | 21 | php 22 | {PHP} 23 | 24 | 25 | php_handler_id 26 | {PHP_HANDLER_ID} 27 | 28 | 29 | webstat 30 | {WEBSTAT} 31 | 32 | 33 | www_root 34 | {WWW_ROOT} 35 | 36 | 37 | 38 | 39 | 40 | 41 | EOT; 42 | 43 | /** 44 | * @var int 45 | */ 46 | public $id; 47 | 48 | /** 49 | * @var array 50 | */ 51 | protected $default_params = [ 52 | 'domain' => null, 53 | 'subscription_id' => null, 54 | 'php' => true, 55 | 'php_handler_id' => 'fastcgi', 56 | 'webstat' => 'none', 57 | 'www_root' => null, 58 | ]; 59 | 60 | /** 61 | * @param array $config 62 | * @param array $params 63 | * @throws ApiRequestException 64 | */ 65 | public function __construct($config, $params = []) 66 | { 67 | if (!isset($params['www_root'])) { 68 | $params['www_root'] = $params['domain']; 69 | } 70 | 71 | parent::__construct($config, $params); 72 | } 73 | 74 | /** 75 | * @param $xml 76 | * @return bool 77 | * @throws ApiRequestException 78 | */ 79 | protected function processResponse($xml) 80 | { 81 | if ($xml->site->add->result->status == 'error') { 82 | throw new ApiRequestException($xml->site->add->result); 83 | } 84 | 85 | $this->id = (int)$xml->site->add->result->id; 86 | return true; 87 | } 88 | } 89 | -------------------------------------------------------------------------------- /src/pmill/Plesk/CreateSiteAlias.php: -------------------------------------------------------------------------------- 1 | 11 | 12 | 13 | 14 | 0 15 | 16 | {WEB_ENABLED} 17 | {MAIL_ENABLED} 18 | {TOMCAT_ENABLED} 19 | 20 | {SITE_ID} 21 | {ALIAS} 22 | 23 | 24 | 25 | EOT; 26 | 27 | /** 28 | * @var int 29 | */ 30 | public $id; 31 | 32 | /** 33 | * @var array 34 | */ 35 | protected $default_params = [ 36 | 'site_id' => null, 37 | 'alias' => null, 38 | 'web_enabled' => 1, 39 | 'mail_enabled' => 0, 40 | 'tomcat_enabled' => 0, 41 | ]; 42 | 43 | /** 44 | * @param array $config 45 | * @param array $params 46 | * @throws ApiRequestException 47 | */ 48 | public function __construct($config, $params) 49 | { 50 | if (!isset($params['site_id'])) { 51 | if (is_int($params['domain'])) { 52 | $params['site_id'] = $params['domain']; 53 | } else { 54 | $request = new GetSite($config, $params); 55 | $info = $request->process(); 56 | $params['site_id'] = $info['id']; 57 | } 58 | } 59 | 60 | parent::__construct($config, $params); 61 | } 62 | 63 | /** 64 | * @param $xml 65 | * @return bool 66 | * @throws ApiRequestException 67 | */ 68 | protected function processResponse($xml) 69 | { 70 | $result = $xml->{'site-alias'}->create->result; 71 | 72 | if ($result->status == 'error') { 73 | throw new ApiRequestException($result); 74 | } 75 | 76 | $this->id = (int)$result->id; 77 | return true; 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /src/pmill/Plesk/CreateSubdomain.php: -------------------------------------------------------------------------------- 1 | 11 | 12 | 13 | 14 | {DOMAIN} 15 | {SUBDOMAIN} 16 | 17 | www_root 18 | {WWW_ROOT} 19 | 20 | 21 | ftp_login 22 | {FTP_USERNAME} 23 | 24 | 25 | ftp_password 26 | {FTP_PASSWORD} 27 | 28 | 29 | ssl 30 | {SSL} 31 | 32 | 33 | php 34 | {PHP} 35 | 36 | 37 | 38 | 39 | EOT; 40 | 41 | /** 42 | * @var int 43 | */ 44 | public $id; 45 | 46 | /** 47 | * @var array 48 | */ 49 | protected $default_params = [ 50 | 'domain' => null, 51 | 'subdomain' => null, 52 | 'www_root' => null, 53 | 'ftp_username' => '', 54 | 'ftp_password' => '', 55 | 'ssl' => true, 56 | 'php' => true, 57 | ]; 58 | 59 | /** 60 | * @param array $config 61 | * @param array $params 62 | * @throws ApiRequestException 63 | */ 64 | public function __construct($config, $params) 65 | { 66 | parent::__construct($config, $params); 67 | 68 | if (substr($this->params['www_root'], 0, 1) !== '/') { 69 | $this->params['www_root'] = '/' . $this->params['www_root']; 70 | } 71 | } 72 | 73 | /** 74 | * @param $xml 75 | * @return bool 76 | * @throws ApiRequestException 77 | */ 78 | protected function processResponse($xml) 79 | { 80 | $result = $xml->subdomain->add->result; 81 | 82 | if ($result->status == 'error') { 83 | throw new ApiRequestException($result); 84 | } 85 | 86 | $this->id = (int)$result->id; 87 | return true; 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /src/pmill/Plesk/CreateSubscription.php: -------------------------------------------------------------------------------- 1 | 11 | 12 | 13 | 14 | 15 | {DOMAIN_NAME} 16 | {IP_ADDRESS} 17 | {OWNER_ID} 18 | vrt_hst 19 | {STATUS} 20 | 21 | 22 | 23 | 24 | ftp_login 25 | {USERNAME} 26 | 27 | 28 | ftp_password 29 | {PASSWORD} 30 | 31 | {IP_ADDRESS} 32 | 33 | 34 | {SERVICE_PLAN_ID} 35 | 36 | 37 | 38 | EOT; 39 | 40 | /** 41 | * @var int 42 | */ 43 | public $id; 44 | 45 | /** 46 | * @var array 47 | */ 48 | protected $default_params = [ 49 | 'domain_name' => null, 50 | 'ip_address' => null, 51 | 'username' => null, 52 | 'password' => null, 53 | 'owner_id' => null, 54 | 'service_plan_id' => null, 55 | 'status' => 0, 56 | ]; 57 | 58 | /** 59 | * @param $xml 60 | * @return bool 61 | * @throws ApiRequestException 62 | */ 63 | protected function processResponse($xml) 64 | { 65 | if ($xml->webspace->add->result->status == 'error') { 66 | throw new ApiRequestException($xml->webspace->add->result); 67 | } 68 | 69 | $this->id = (int)$xml->webspace->add->result->id; 70 | return true; 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /src/pmill/Plesk/CurlHttpRequest.php: -------------------------------------------------------------------------------- 1 | setupCurl($host); 28 | } 29 | 30 | /** 31 | * @param $username 32 | * @param $password 33 | */ 34 | public function setCredentials($username, $password) 35 | { 36 | curl_setopt($this->curl, CURLOPT_HTTPHEADER, [ 37 | "HTTP_AUTH_LOGIN: ".$username, 38 | "HTTP_AUTH_PASSWD: ".$password, 39 | "HTTP_PRETTY_PRINT: TRUE", 40 | "Content-Type: text/xml", 41 | ]); 42 | } 43 | 44 | /** 45 | * @param $key 46 | */ 47 | public function setSecretKey($key) 48 | { 49 | curl_setopt($this->curl, CURLOPT_HTTPHEADER, [ 50 | "KEY: ".$key, 51 | "HTTP_PRETTY_PRINT: TRUE", 52 | "Content-Type: text/xml", 53 | ]); 54 | } 55 | 56 | /** 57 | * @param $host 58 | */ 59 | public function setupCurl($host) 60 | { 61 | $this->curl = curl_init(); 62 | curl_setopt($this->curl, CURLOPT_URL, "https://".$host.":8443/enterprise/control/agent.php"); 63 | curl_setopt($this->curl, CURLOPT_RETURNTRANSFER, true); 64 | curl_setopt($this->curl, CURLOPT_POST, true); 65 | curl_setopt($this->curl, CURLOPT_SSL_VERIFYPEER, false); 66 | curl_setopt($this->curl, CURLOPT_SSL_VERIFYHOST, false); 67 | curl_setopt($this->curl, CURLINFO_HEADER_OUT, true); 68 | curl_setopt($this->curl, CURLOPT_HTTPHEADER, ['Content-Type: text/xml']); 69 | } 70 | 71 | /** 72 | * @param $body 73 | * @return bool|string 74 | * @throws ApiRequestException 75 | */ 76 | public function sendRequest($body) 77 | { 78 | curl_setopt($this->curl, CURLOPT_POSTFIELDS, $body); 79 | $this->last_request_result = curl_exec($this->curl); 80 | 81 | if (curl_errno($this->curl)) { 82 | $errmsg = curl_error($this->curl); 83 | $errcode = curl_errno($this->curl); 84 | curl_close($this->curl); 85 | throw new ApiRequestException($errmsg, $errcode); 86 | } 87 | 88 | $this->last_request_header = curl_getinfo($this->curl, CURLINFO_HEADER_OUT); 89 | curl_close($this->curl); 90 | 91 | return $this->last_request_result; 92 | } 93 | } 94 | -------------------------------------------------------------------------------- /src/pmill/Plesk/DeleteClient.php: -------------------------------------------------------------------------------- 1 | 11 | 12 | 13 | 14 | 15 | {FILTER} 16 | 17 | 18 | 19 | 20 | EOT; 21 | 22 | /** 23 | * @var array 24 | */ 25 | protected $default_params = [ 26 | 'filter' => null, 27 | ]; 28 | 29 | /** 30 | * @param array $config 31 | * @param array $params 32 | * @throws ApiRequestException 33 | */ 34 | public function __construct($config, $params = []) 35 | { 36 | if (isset($params['username'])) { 37 | $params['filter'] = new Node('login', $params['username']); 38 | } 39 | 40 | if (isset($params['id'])) { 41 | $params['filter'] = new Node('id', $params['id']); 42 | } 43 | 44 | parent::__construct($config, $params); 45 | } 46 | 47 | /** 48 | * @param $xml 49 | * @return bool 50 | * @throws ApiRequestException 51 | */ 52 | protected function processResponse($xml) 53 | { 54 | $result = $xml->customer->del->result; 55 | 56 | if ($result->status == 'error') { 57 | throw new ApiRequestException($result); 58 | } 59 | 60 | return true; 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /src/pmill/Plesk/DeleteDatabase.php: -------------------------------------------------------------------------------- 1 | 11 | 12 | 13 | 14 | 15 | {ID} 16 | 17 | 18 | 19 | 20 | EOT; 21 | 22 | /** 23 | * @var array 24 | */ 25 | protected $default_params = [ 26 | 'id' => null, 27 | ]; 28 | 29 | /** 30 | * @param $xml 31 | * @return bool 32 | * @throws ApiRequestException 33 | */ 34 | protected function processResponse($xml) 35 | { 36 | $result = $xml->database->{'del-db'}->result; 37 | 38 | if ($result->status == 'error') { 39 | throw new ApiRequestException($result); 40 | } 41 | 42 | return true; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/pmill/Plesk/DeleteEmailAddress.php: -------------------------------------------------------------------------------- 1 | 11 | 12 | 13 | 14 | 15 | {SITE_ID} 16 | {USERNAME} 17 | 18 | 19 | 20 | 21 | EOT; 22 | 23 | /** 24 | * @var array 25 | */ 26 | protected $default_params = [ 27 | 'email' => null, 28 | ]; 29 | 30 | /** 31 | * @param array $config 32 | * @param array $params 33 | * @throws ApiRequestException 34 | */ 35 | public function __construct($config, $params) 36 | { 37 | parent::__construct($config, $params); 38 | 39 | if (!filter_var($this->params['email'], FILTER_VALIDATE_EMAIL)) { 40 | throw new ApiRequestException("Invalid email submitted"); 41 | } 42 | 43 | list($username, $domain) = explode("@", $this->params['email']); 44 | 45 | $request = new GetSite($config, ['domain' => $domain]); 46 | $info = $request->process(); 47 | 48 | $this->params['site_id'] = $info['id']; 49 | $this->params['username'] = $username; 50 | } 51 | 52 | /** 53 | * @param $xml 54 | * @return bool 55 | */ 56 | protected function processResponse($xml) 57 | { 58 | if ($xml->mail->remove->result->status == 'error') { 59 | return false; 60 | } 61 | 62 | return true; 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /src/pmill/Plesk/DeleteSecretKey.php: -------------------------------------------------------------------------------- 1 | 11 | 12 | 13 | 14 | 15 | {KEYS} 16 | 17 | 18 | 19 | 20 | EOT; 21 | 22 | /** 23 | * @param array $config 24 | * @param array $params 25 | * @throws ApiRequestException 26 | */ 27 | public function __construct(array $config, array $params = []) 28 | { 29 | $keys = []; 30 | 31 | if (isset($params['key'])) { 32 | $keys[] = new Node('key', $params['key']); 33 | } 34 | 35 | if (isset($params['key']) && is_array($params['key'])) { 36 | foreach ($params['key'] as $key) { 37 | $keys[] = new Node('key', $key); 38 | } 39 | } 40 | 41 | $params['keys'] = new NodeList($keys); 42 | 43 | parent::__construct($config, $params); 44 | } 45 | 46 | /** 47 | * @param $xml 48 | * @return bool 49 | */ 50 | protected function processResponse($xml) 51 | { 52 | return true; 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/pmill/Plesk/DeleteSite.php: -------------------------------------------------------------------------------- 1 | 11 | 12 | 13 | 14 | 15 | {ID} 16 | 17 | 18 | 19 | 20 | EOT; 21 | 22 | /** 23 | * @var array 24 | */ 25 | protected $default_params = [ 26 | 'id' => null, 27 | ]; 28 | 29 | /** 30 | * @param $xml 31 | * @return bool 32 | * @throws ApiRequestException 33 | */ 34 | protected function processResponse($xml) 35 | { 36 | if ($xml->site->del->result->status == 'error') { 37 | throw new ApiRequestException($xml->site->del->result); 38 | } 39 | 40 | return true; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/pmill/Plesk/DeleteSiteAlias.php: -------------------------------------------------------------------------------- 1 | 11 | 12 | 13 | 14 | 15 | {FILTER} 16 | 17 | 18 | 19 | 20 | EOT; 21 | 22 | /** 23 | * @var array 24 | */ 25 | protected $default_params = [ 26 | 'filter' => null, 27 | ]; 28 | 29 | /** 30 | * @param array $config 31 | * @param array $params 32 | * @throws ApiRequestException 33 | */ 34 | public function __construct($config, $params = []) 35 | { 36 | if (isset($params['domain'])) { 37 | $params['filter'] = new Node('name', $params['domain']); 38 | } 39 | 40 | if (isset($params['alias'])) { 41 | $params['filter'] = new Node('name', $params['alias']); 42 | } 43 | 44 | if (isset($params['id'])) { 45 | $params['filter'] = new Node('id', $params['id']); 46 | } 47 | 48 | parent::__construct($config, $params); 49 | } 50 | 51 | /** 52 | * @param $xml 53 | * @return bool 54 | * @throws ApiRequestException 55 | */ 56 | protected function processResponse($xml) 57 | { 58 | $result = $xml->{'site-alias'}->delete->result; 59 | 60 | if ($result->status == 'error') { 61 | throw new ApiRequestException($result); 62 | } 63 | 64 | return true; 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /src/pmill/Plesk/DeleteSubdomain.php: -------------------------------------------------------------------------------- 1 | 11 | 12 | 13 | 14 | 15 | {FILTER} 16 | 17 | 18 | 19 | 20 | EOT; 21 | 22 | /** 23 | * @var array 24 | */ 25 | protected $default_params = [ 26 | 'filter' => null, 27 | ]; 28 | 29 | /** 30 | * @param array $config 31 | * @param array $params 32 | * @throws ApiRequestException 33 | */ 34 | public function __construct($config, $params = []) 35 | { 36 | if (isset($params['subdomain'])) { 37 | $params['filter'] = new Node('name', $params['subdomain']); 38 | } 39 | 40 | if (isset($params['id'])) { 41 | $params['filter'] = new Node('id', $params['id']); 42 | } 43 | 44 | parent::__construct($config, $params); 45 | } 46 | 47 | /** 48 | * @param $xml 49 | * @return bool 50 | * @throws ApiRequestException 51 | */ 52 | protected function processResponse($xml) 53 | { 54 | $result = $xml->subdomain->del->result; 55 | 56 | if ($result->status == 'error') { 57 | throw new ApiRequestException($result); 58 | } 59 | 60 | return true; 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /src/pmill/Plesk/DeleteSubscription.php: -------------------------------------------------------------------------------- 1 | 11 | 12 | 13 | 14 | 15 | {ID} 16 | 17 | 18 | 19 | 20 | EOT; 21 | 22 | /** 23 | * @var array 24 | */ 25 | protected $default_params = [ 26 | 'id' => null, 27 | ]; 28 | 29 | /** 30 | * @param $xml 31 | * @return bool 32 | * @throws ApiRequestException 33 | */ 34 | protected function processResponse($xml) 35 | { 36 | $webspace = $xml->webspace->del; 37 | 38 | if ($webspace->result->status == 'error') { 39 | throw new ApiRequestException($webspace->result); 40 | } 41 | 42 | return true; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/pmill/Plesk/GetClient.php: -------------------------------------------------------------------------------- 1 | 11 | 12 | 13 | 14 | 15 | {FILTER} 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | EOT; 25 | 26 | /** 27 | * @var array 28 | */ 29 | protected $default_params = [ 30 | 'filter' => null, 31 | ]; 32 | 33 | /** 34 | * GetClient constructor. 35 | * @param array $config 36 | * @param array $params 37 | */ 38 | public function __construct(array $config, $params = []) 39 | { 40 | if (isset($params['username'])) { 41 | $params['filter'] = new Node('login', $params['username']); 42 | } 43 | 44 | if (isset($params['id'])) { 45 | $params['filter'] = new Node('id', $params['id']); 46 | } 47 | 48 | parent::__construct($config, $params); 49 | } 50 | 51 | /** 52 | * @param $xml 53 | * @return array 54 | * @throws ApiRequestException 55 | */ 56 | protected function processResponse($xml) 57 | { 58 | $client = $xml->customer->get->result; 59 | 60 | if ((string)$client->status == 'error') { 61 | throw new ApiRequestException($client); 62 | } 63 | 64 | if ((string)$client->result->status == 'error') { 65 | throw new ApiRequestException($client->result); 66 | } 67 | 68 | return [ 69 | 'id' => (int)$client->id, 70 | 'status' => (string)$client->status, 71 | 'created' => (string)$client->data->gen_info->cr_date, 72 | 'name' => (string)$client->data->gen_info->cname, 73 | 'contact_name' => (string)$client->data->gen_info->pname, 74 | 'username' => (string)$client->data->gen_info->login, 75 | 'phone' => (string)$client->data->gen_info->phone, 76 | 'email' => (string)$client->data->gen_info->email, 77 | 'address' => (string)$client->data->gen_info->address, 78 | 'city' => (string)$client->data->gen_info->city, 79 | 'state' => (string)$client->data->gen_info->state, 80 | 'post_code' => (string)$client->data->gen_info->pcode, 81 | 'country' => (string)$client->data->gen_info->country, 82 | 'locale' => (string)$client->data->gen_info->locale, 83 | 'stat' => [ 84 | 'domains' => (int)$client->data->stat->active_domains, 85 | 'subdomains' => (int)$client->data->stat->subdomains, 86 | 'disk_space' => (int)$client->data->stat->disk_space, 87 | 'web_users' => (int)$client->data->stat->web_users, 88 | 'databases' => (int)$client->data->stat->data_bases, 89 | 'traffic' => (int)$client->data->stat->traffic, 90 | 'traffic_prevday' => (int)$client->data->stat->traffic_prevday, 91 | ], 92 | ]; 93 | } 94 | } 95 | -------------------------------------------------------------------------------- /src/pmill/Plesk/GetDatabaseUser.php: -------------------------------------------------------------------------------- 1 | 11 | 12 | 13 | 14 | 15 | {DATABASE_ID} 16 | 17 | 18 | 19 | 20 | EOT; 21 | 22 | /** 23 | * @var int 24 | */ 25 | public $id; 26 | 27 | /** 28 | * @var array 29 | */ 30 | protected $default_params = [ 31 | 'database_id' => null, 32 | ]; 33 | 34 | /** 35 | * @param $xml 36 | * @return bool 37 | * @throws ApiRequestException 38 | */ 39 | protected function processResponse($xml) 40 | { 41 | if ($xml->database->{'get-default-user'}->result->status == 'error') { 42 | throw new ApiRequestException($xml->database->{'get-default-user'}->result); 43 | } 44 | 45 | $this->id = (int)$xml->database->{'get-default-user'}->result->id; 46 | return true; 47 | } 48 | 49 | } -------------------------------------------------------------------------------- /src/pmill/Plesk/GetServerInfo.php: -------------------------------------------------------------------------------- 1 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | EOT; 21 | 22 | /** 23 | * @param $xml 24 | * @return array 25 | * @throws ApiRequestException 26 | */ 27 | protected function processResponse($xml) 28 | { 29 | $server = $xml->server->get->result; 30 | 31 | if ((string)$server->status === 'error') { 32 | throw new ApiRequestException($server); 33 | } 34 | 35 | if ((string)$server->result->status === 'error') { 36 | throw new ApiRequestException($server->result); 37 | } 38 | 39 | $diskspace = []; 40 | foreach ($server->stat->diskspace->children() as $device) { 41 | $diskspace[] = [ 42 | 'name' => (string)$device->name, 43 | 'total' => (int)$device->total, 44 | 'used' => (int)$device->used, 45 | 'free' => (int)$device->free, 46 | ]; 47 | } 48 | 49 | return [ 50 | 'status' => (string)$server->status, 51 | 'server_name' => (string)$server->gen_info->server_name, 52 | 'stats' => [ 53 | 'clients' => (int)$server->stat->objects->clients, 54 | 'domains' => (int)$server->stat->objects->domains, 55 | 'active_domains' => (int)$server->stat->objects->active_domains, 56 | 'mail_boxes' => (int)$server->stat->objects->mail_boxes, 57 | 'databases' => (int)$server->stat->objects->databases, 58 | 'database_users' => (int)$server->stat->objects->database_users, 59 | 'web_users' => (int)$server->stat->objects->web_users, 60 | ], 61 | 'version' => [ 62 | 'plesk_name' => (string)$server->stat->version->plesk_name, 63 | 'plesk_version' => (string)$server->stat->version->plesk_version, 64 | 'plesk_build' => (string)$server->stat->version->plesk_build, 65 | 'os' => (string)$server->stat->version->plesk_os, 66 | 'os_version' => (string)$server->stat->version->plesk_os_version, 67 | 'os_release' => (string)$server->stat->version->os_release, 68 | ], 69 | 'load_average' => [ 70 | '1min' => (int)$server->stat->load_avg->l1, 71 | '5min' => (int)$server->stat->load_avg->l5, 72 | '15min' => (int)$server->stat->load_avg->l15, 73 | ], 74 | 'memory' => [ 75 | 'total' => (int)$server->stat->mem->total, 76 | 'used' => (int)$server->stat->mem->used, 77 | 'free' => (int)$server->stat->mem->free, 78 | 'shared' => (int)$server->stat->mem->shared, 79 | 'buffer' => (int)$server->stat->mem->buffer, 80 | 'cached' => (int)$server->stat->mem->cached, 81 | ], 82 | 'swap' => [ 83 | 'total' => (int)$server->stat->swap->total, 84 | 'used' => (int)$server->stat->swap->used, 85 | 'free' => (int)$server->stat->swap->free, 86 | ], 87 | 'diskspace' => $diskspace, 88 | ]; 89 | } 90 | } 91 | -------------------------------------------------------------------------------- /src/pmill/Plesk/GetServicePlan.php: -------------------------------------------------------------------------------- 1 | 13 | 14 | 15 | 16 | 17 | {FILTER} 18 | 19 | 20 | 21 | 22 | EOT; 23 | 24 | /** 25 | * @var array 26 | */ 27 | protected $default_params = [ 28 | 'filter' => '', 29 | ]; 30 | 31 | /** 32 | * @param array $config 33 | * @param array $params 34 | * @param HttpRequestContract $http 35 | * @throws ApiRequestException 36 | */ 37 | public function __construct(array $config, array $params = [], HttpRequestContract $http = null) 38 | { 39 | $filterChildNodes = []; 40 | 41 | foreach (['owner-id', 'owner-login', 'guid', 'id'] as $nodeName) { 42 | if (isset($params[$nodeName])) { 43 | if (!is_array($params[$nodeName])) { 44 | $params[$nodeName] = [$params[$nodeName]]; 45 | } 46 | 47 | foreach ($params[$nodeName] as $value) { 48 | $filterChildNodes[] = new Node($nodeName, $value); 49 | } 50 | } 51 | } 52 | 53 | $params = [ 54 | 'filter' => new NodeList($filterChildNodes), 55 | ]; 56 | 57 | parent::__construct($config, $params, $http); 58 | } 59 | 60 | /** 61 | * @param $xml 62 | * @return array 63 | * @throws ApiRequestException 64 | */ 65 | protected function processResponse($xml) 66 | { 67 | $plan = $xml->{"service-plan"}->get->result; 68 | 69 | if ((string)$plan->status == 'error') { 70 | throw new ApiRequestException($plan); 71 | } 72 | 73 | if ((string)$plan->result->status == 'error') { 74 | throw new ApiRequestException($plan->result); 75 | } 76 | 77 | $hosting = []; 78 | foreach ($plan->hosting as $host) { 79 | $hosting[$host->getName()] = Xml::getProperties($host); 80 | } 81 | 82 | return [ 83 | 'id' => (string)$plan->id, 84 | 'guid' => (string)$plan->guid, 85 | 'status' => (string)$plan->status, 86 | 'limits' => [ 87 | 'overuse' => (string)$plan->limits->overuse, 88 | 'max_sites' => Xml::findProperty($plan->limits, 'max_site', 'limit'), 89 | 'max_subdomains' => Xml::findProperty($plan->limits, 'max_subdom', 'limit'), 90 | 'max_domain_aliases' => Xml::findProperty($plan->limits, 'max_dom_aliases', 'limit'), 91 | 'disk_space' => Xml::findProperty($plan->limits, 'disk_space', 'limit'), 92 | 'max_traffic' => Xml::findProperty($plan->limits, 'max_traffic', 'limit'), 93 | 'max_web_users' => Xml::findProperty($plan->limits, 'max_wu', 'limit'), 94 | 'max_subftp_users' => Xml::findProperty($plan->limits, 'max_subftp_users', 'limit'), 95 | 'max_databases' => Xml::findProperty($plan->limits, 'max_db', 'limit'), 96 | 'max_mailboxes' => Xml::findProperty($plan->limits, 'max_box', 'limit'), 97 | 'mailbox_quota' => Xml::findProperty($plan->limits, 'mbox_quota', 'limit'), 98 | 'max_maillists' => Xml::findProperty($plan->limits, 'max_maillists', 'limit'), 99 | 'max_webapps' => Xml::findProperty($plan->limits, 'max_webapps', 'limit'), 100 | 'max_site_builder' => Xml::findProperty($plan->limits, 'max_site_builder', 'limit'), 101 | 'expiration' => Xml::findProperty($plan->limits, 'expiration', 'limit'), 102 | ], 103 | 'log_rotation' => [ 104 | 'on' => (string)$plan->{"log-rotation"}->on->{"log-condition"}->{"log-bytime"}, 105 | 'max_num_files' => (int)$plan->{"log-rotation"}->on->{"log-max-num-files"}, 106 | 'compressed' => (string)$plan->{"log-rotation"}->on->{"log-compress"}, 107 | ], 108 | 'preferences' => [ 109 | 'stat' => (int)$plan->preferences->stat, 110 | 'maillists' => (string)$plan->preferences->maillists, 111 | 'dns_zone_type' => (string)$plan->preferences->dns_zone_type, 112 | ], 113 | 'hosting' => $hosting, 114 | 'performance' => [ 115 | 'bandwidth' => (int)$plan->performance->bandwidth, 116 | 'max_connections' => (int)$plan->performance->max_connections, 117 | ], 118 | 'permissions' => Xml::getProperties($plan->permissions, 'permission'), 119 | ]; 120 | } 121 | } 122 | -------------------------------------------------------------------------------- /src/pmill/Plesk/GetSite.php: -------------------------------------------------------------------------------- 1 | 11 | 12 | 13 | 14 | 15 | {DOMAIN} 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | EOT; 24 | 25 | /** 26 | * @var array 27 | */ 28 | protected $default_params = [ 29 | 'domain' => null, 30 | ]; 31 | 32 | /** 33 | * @param $xml 34 | * @return array 35 | * @throws ApiRequestException 36 | */ 37 | protected function processResponse($xml) 38 | { 39 | $site = $xml->domain->get->result; 40 | 41 | if ((string)$site->status == 'error') { 42 | throw new ApiRequestException($site); 43 | } 44 | if ((string)$site->result->status == 'error') { 45 | throw new ApiRequestException($site->result); 46 | } 47 | 48 | $hosting_type = (string)$site->data->gen_info->htype; 49 | 50 | return [ 51 | 'id' => (string)$site->id, 52 | 'status' => (string)$site->status, 53 | 'created' => (string)$site->data->gen_info->cr_date, 54 | 'name' => (string)$site->data->gen_info->name, 55 | 'ip' => (string)$site->data->gen_info->dns_ip_address, 56 | 'hosting_type' => $hosting_type, 57 | 'ip_address' => (string)$site->data->hosting->{$hosting_type}->ip_address, 58 | 'www_root' => $this->findHostingProperty($site->data->hosting->{$hosting_type}, 'www_root'), 59 | 'ftp_username' => $this->findHostingProperty($site->data->hosting->{$hosting_type}, 'ftp_login'), 60 | 'ftp_password' => $this->findHostingProperty($site->data->hosting->{$hosting_type}, 'ftp_password'), 61 | ]; 62 | } 63 | 64 | /** 65 | * @param $node 66 | * @param $key 67 | * @return null|string 68 | */ 69 | protected function findHostingProperty($node, $key) 70 | { 71 | foreach ($node->children() as $property) { 72 | if ($property->name == $key) { 73 | return (string)$property->value; 74 | } 75 | } 76 | return null; 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /src/pmill/Plesk/GetSubdomain.php: -------------------------------------------------------------------------------- 1 | 11 | 12 | 13 | 14 | 15 | {NAME} 16 | 17 | 18 | 19 | 20 | EOT; 21 | 22 | /** 23 | * @var array 24 | */ 25 | protected $default_params = [ 26 | 'name' => null, 27 | ]; 28 | 29 | /** 30 | * @param $xml 31 | * @return array 32 | * @throws ApiRequestException 33 | */ 34 | protected function processResponse($xml) 35 | { 36 | $subdomain = $xml->subdomain->get->result; 37 | 38 | if ((string)$subdomain->status == 'error') { 39 | throw new ApiRequestException($subdomain); 40 | } 41 | 42 | if ((string)$subdomain->result->status == 'error') { 43 | throw new ApiRequestException($subdomain->result); 44 | } 45 | 46 | return [ 47 | 'id' => (int)$subdomain->id, 48 | 'status' => (string)$subdomain->status, 49 | 'parent' => (string)$subdomain->data->parent, 50 | 'name' => (string)$subdomain->data->name, 51 | 'php' => (string)$this->findHostingProperty($subdomain->data, 'php'), 52 | 'php_handler_type' => (string)$this->findHostingProperty($subdomain->data, 'php_handler_type'), 53 | 'www_root' => (string)$this->findHostingProperty($subdomain->data, 'www_root'), 54 | ]; 55 | } 56 | 57 | /** 58 | * @param $node 59 | * @param $key 60 | * @return null|string 61 | */ 62 | protected function findHostingProperty($node, $key) 63 | { 64 | foreach ($node->children() as $property) { 65 | if ($property->name == $key) { 66 | return (string)$property->value; 67 | } 68 | } 69 | return null; 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /src/pmill/Plesk/GetSubscription.php: -------------------------------------------------------------------------------- 1 | 13 | 14 | 15 | 16 | {FILTER} 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | EOT; 25 | 26 | /** 27 | * @var array 28 | */ 29 | protected $default_params = [ 30 | 'filter' => null, 31 | ]; 32 | 33 | /** 34 | * @param array $config 35 | * @param array $params 36 | * @throws ApiRequestException 37 | */ 38 | public function __construct($config, $params = []) 39 | { 40 | $this->default_params['filter'] = new Node('filter'); 41 | 42 | if (isset($params['subscription_id'])) { 43 | $ownerIdNode = new Node('id', $params['subscription_id']); 44 | $params['filter'] = new Node('filter', $ownerIdNode); 45 | } 46 | parent::__construct($config, $params); 47 | } 48 | 49 | /** 50 | * @param $xml 51 | * @return array 52 | */ 53 | protected function processResponse($xml) 54 | { 55 | $result = []; 56 | 57 | for ($i = 0; $i < count($xml->webspace->get->result); $i++) { 58 | $webspace = $xml->webspace->get->result[$i]; 59 | 60 | $hosting = []; 61 | foreach ($webspace->data->hosting->children() as $host) { 62 | $hosting[$host->getName()] = Xml::getProperties($host); 63 | } 64 | 65 | 66 | $subscriptions = []; 67 | foreach ($webspace->data->subscriptions->children() as $subscription) { 68 | $subscriptions[] = [ 69 | 'locked' => (bool)$subscription->locked, 70 | 'synchronized' => (bool)$subscription->synchronized, 71 | 'plan-guid' => (string)$subscription->plan->{"plan-guid"}, 72 | ]; 73 | } 74 | 75 | $result[] = [ 76 | 'id' => (string)$webspace->id, 77 | 'status' => (string)$webspace->status, 78 | 'subscription_status' => (int)$webspace->data->gen_info->status, 79 | 'created' => (string)$webspace->data->gen_info->cr_date, 80 | 'name' => (string)$webspace->data->gen_info->name, 81 | 'owner_id' => (string)$webspace->data->gen_info->{"owner-id"}, 82 | 'hosting' => $hosting, 83 | 'real_size' => (int)$webspace->data->gen_info->real_size, 84 | 'dns_ip_address' => (string)$webspace->data->gen_info->dns_ip_address, 85 | 'htype' => (string)$webspace->data->gen_info->htype, 86 | 'subscriptions' => $subscriptions, 87 | ]; 88 | } 89 | 90 | return $result; 91 | } 92 | } 93 | -------------------------------------------------------------------------------- /src/pmill/Plesk/GetTraffic.php: -------------------------------------------------------------------------------- 1 | 13 | 14 | 15 | 16 | {FILTER} 17 | 18 | 19 | 20 | EOT; 21 | 22 | /** 23 | * @var array 24 | */ 25 | protected $default_params = [ 26 | 'filter' => null, 27 | ]; 28 | 29 | /** 30 | * @param array $config 31 | * @param array $params 32 | * @throws ApiRequestException 33 | */ 34 | public function __construct($config, $params = []) 35 | { 36 | $filterChildNodes = []; 37 | 38 | foreach (['name', 'owner-id', 'owner-login', 'guid', 'id'] as $nodeName) { 39 | if (isset($params[$nodeName])) { 40 | if (!is_array($params[$nodeName])) { 41 | $params[$nodeName] = [$params[$nodeName]]; 42 | } 43 | 44 | foreach ($params[$nodeName] as $value) { 45 | $filterChildNodes[] = new Node($nodeName, $value); 46 | } 47 | } 48 | } 49 | 50 | $filter = [ new Node('filter', new NodeList($filterChildNodes)) ]; 51 | 52 | if (isset($params['since_date'])) { 53 | $filter[] = new Node('since_date', $params['since_date']); 54 | } 55 | 56 | if (isset($params['to_date'])) { 57 | $filter[] = new Node('to_date', $params['to_date']); 58 | } 59 | 60 | $params = [ 61 | 'filter' => new NodeList($filter) 62 | ]; 63 | 64 | parent::__construct($config, $params); 65 | } 66 | 67 | /** 68 | * @param $xml 69 | * @return array 70 | */ 71 | protected function processResponse($xml) 72 | { 73 | $result = []; 74 | 75 | for ($i = 0; $i < count($xml->webspace->get_traffic->result); $i++) { 76 | $webspace = $xml->webspace->get_traffic->result[$i]; 77 | 78 | $traffic = []; 79 | foreach ($webspace->traffic as $day) { 80 | $traffic[] = [ 81 | 'date' => (string)$day->date, 82 | 'http_in' => (int)$day->http_in, 83 | 'http_out' => (int)$day->http_out, 84 | 'ftp_in' => (int)$day->ftp_in, 85 | 'ftp_out' => (int)$day->ftp_out, 86 | 'smtp_in' => (int)$day->smtp_in, 87 | 'smtp_out' => (int)$day->smtp_out, 88 | 'pop3_imap_in' => (int)$day->pop3_imap_in, 89 | 'pop3_imap_out' => (int)$day->pop3_imap_out 90 | ]; 91 | } 92 | 93 | $result[] = [ 94 | 'id' => (string)$webspace->id, 95 | 'status' => (string)$webspace->status, 96 | 'error_code' => (int)$webspace->errcode, 97 | 'error_text' => (string)$webspace->errtext, 98 | 'traffic' => $traffic, 99 | ]; 100 | } 101 | 102 | return $result; 103 | } 104 | } 105 | -------------------------------------------------------------------------------- /src/pmill/Plesk/Helper/MailPreferences.php: -------------------------------------------------------------------------------- 1 | $value) { 21 | if ($node = $this->createNode($key, $value)) { 22 | $nodes[] = $node; 23 | } 24 | } 25 | 26 | return new NodeList($nodes); 27 | } 28 | 29 | /** 30 | * @param $key 31 | * @param $value 32 | * @return null|Node 33 | */ 34 | protected function createNode($key, $value) 35 | { 36 | switch ($key) { 37 | case 'nonexistent-user': 38 | if (in_array($value, [self::NONEXISTENT_USER_BOUNCE, self::NONEXISTENT_USER_FORWARD, self::NONEXISTENT_USER_REJECT])) { 39 | return new Node($key, new Node($value)); 40 | } 41 | break; 42 | case 'web_mail': 43 | case 'spam_protect_sign': 44 | case 'grey_listing': 45 | case 'mailservice': 46 | if (is_bool($value)) { 47 | return new Node($key, $value); 48 | } 49 | break; 50 | } 51 | 52 | return null; 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/pmill/Plesk/Helper/Xml.php: -------------------------------------------------------------------------------- 1 | children() as $property) { 37 | if ($property->getName() == $node_name && $property->name == $key) { 38 | return (string)$property->value; 39 | } 40 | } 41 | 42 | return null; 43 | } 44 | 45 | /** 46 | * @param $node 47 | * @param string $node_name 48 | * @return array 49 | */ 50 | public static function getProperties($node, $node_name = 'property') 51 | { 52 | $result = []; 53 | 54 | foreach ($node->children() as $property) { 55 | if ($property->getName() == $node_name) { 56 | $result[(string)$property->name] = (string)$property->value; 57 | } 58 | } 59 | 60 | return $result; 61 | } 62 | 63 | /** 64 | * Generates the xml for a standard property list 65 | * 66 | * @param array $properties 67 | * @return string 68 | */ 69 | public static function generatePropertyList(array $properties) 70 | { 71 | $nodes = []; 72 | 73 | foreach ($properties as $key => $value) { 74 | $nodeList = new NodeList([ 75 | new Node('name', $key), 76 | new Node('value', $value), 77 | ]); 78 | 79 | $nodes[] = new Node('property', $nodeList); 80 | } 81 | 82 | return new NodeList($nodes); 83 | } 84 | 85 | /** 86 | * @param array $nodeMapping 87 | * @param array $properties 88 | * @return NodeList 89 | */ 90 | public static function generateNodeList(array $nodeMapping, array $properties) 91 | { 92 | $nodes = []; 93 | 94 | foreach ($properties as $key => $value) { 95 | if (isset($nodeMapping[$key])) { 96 | $tag = $nodeMapping[$key]; 97 | $nodes[] = new Node($tag, $value); 98 | } 99 | } 100 | 101 | return new NodeList($nodes); 102 | } 103 | 104 | /** 105 | * @param $input 106 | * @return string 107 | */ 108 | public static function sanitize($input) 109 | { 110 | return htmlspecialchars($input); 111 | } 112 | 113 | /** 114 | * @param array $array 115 | * @return array 116 | */ 117 | public static function sanitizeArray(array $array) 118 | { 119 | foreach ($array as &$value) { 120 | if (is_string($value)) { 121 | $value = self::sanitize($value); 122 | } 123 | } 124 | 125 | return $array; 126 | } 127 | } 128 | -------------------------------------------------------------------------------- /src/pmill/Plesk/HttpRequestContract.php: -------------------------------------------------------------------------------- 1 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | EOT; 23 | 24 | /** 25 | * @param $xml 26 | * @return array 27 | */ 28 | protected function processResponse($xml) 29 | { 30 | $result = []; 31 | 32 | for ($i = 0; $i < count($xml->client->get->result); $i++) { 33 | $client = $xml->client->get->result[$i]; 34 | 35 | $result[] = [ 36 | 'id' => (string)$client->id, 37 | 'status' => (string)$client->status, 38 | 'created' => (string)$client->data->gen_info->cr_date, 39 | 'name' => (string)$client->data->gen_info->cname, 40 | 'contact_name' => (string)$client->data->gen_info->pname, 41 | 'username' => (string)$client->data->gen_info->login, 42 | 'phone' => (string)$client->data->gen_info->phone, 43 | 'email' => (string)$client->data->gen_info->email, 44 | 'address' => (string)$client->data->gen_info->address, 45 | 'city' => (string)$client->data->gen_info->city, 46 | 'state' => (string)$client->data->gen_info->state, 47 | 'post_code' => (string)$client->data->gen_info->pcode, 48 | 'country' => (string)$client->data->gen_info->country, 49 | 'locale' => (string)$client->data->gen_info->locale, 50 | 'stat' => [ 51 | 'domains' => (int)$client->data->stat->active_domains, 52 | 'subdomains' => (int)$client->data->stat->subdomains, 53 | 'disk_space' => (int)$client->data->stat->disk_space, 54 | 'web_users' => (int)$client->data->stat->web_users, 55 | 'databases' => (int)$client->data->stat->data_bases, 56 | 'traffic' => (int)$client->data->stat->traffic, 57 | 'traffic_prevday' => (int)$client->data->stat->traffic_prevday, 58 | ], 59 | ]; 60 | } 61 | 62 | return $result; 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /src/pmill/Plesk/ListDNSRecords.php: -------------------------------------------------------------------------------- 1 | 11 | 12 | 13 | 14 | 15 | {SITE_ID} 16 | 17 | 18 | 19 | 20 | EOT; 21 | 22 | /** 23 | * @var array 24 | */ 25 | protected $default_params = [ 26 | 'site_id' => null, 27 | ]; 28 | 29 | /** 30 | * @param array $config 31 | * @param array $params 32 | * @throws ApiRequestException 33 | */ 34 | public function __construct($config, $params) 35 | { 36 | if (isset($params['domain'])) { 37 | $request = new GetSite($config, ['domain' => $params['domain']]); 38 | $info = $request->process(); 39 | 40 | $params['site_id'] = $info['id']; 41 | } 42 | 43 | parent::__construct($config, $params); 44 | } 45 | 46 | /** 47 | * @param $xml 48 | * @return array 49 | */ 50 | protected function processResponse($xml) 51 | { 52 | $result = []; 53 | 54 | foreach ($xml->dns->get_rec->children() as $node) { 55 | $result[] = [ 56 | 'status' => (string)$node->status, 57 | 'id' => (int)$node->id, 58 | 'type' => (string)$node->data->type, 59 | 'host' => (string)$node->data->host, 60 | 'value' => (string)$node->data->value, 61 | 'opt' => (string)$node->data->opt, 62 | ]; 63 | } 64 | 65 | return $result; 66 | } 67 | } -------------------------------------------------------------------------------- /src/pmill/Plesk/ListDatabaseServers.php: -------------------------------------------------------------------------------- 1 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | EOT; 19 | 20 | /** 21 | * @param $xml 22 | * @return array 23 | */ 24 | protected function processResponse($xml) 25 | { 26 | $result = []; 27 | 28 | foreach ($xml->db_server->{'get-local'}->children() as $node) { 29 | $result[] = [ 30 | 'status' => (string)$node->status, 31 | 'id' => (int)$node->id, 32 | 'type' => (string)$node->type, 33 | ]; 34 | } 35 | 36 | return $result; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/pmill/Plesk/ListDatabases.php: -------------------------------------------------------------------------------- 1 | 11 | 12 | 13 | 14 | 15 | {SUBSCRIPTION_ID} 16 | 17 | 18 | 19 | 20 | EOT; 21 | 22 | /** 23 | * @var array 24 | */ 25 | protected $default_params = [ 26 | 'subscription_id' => null, 27 | ]; 28 | 29 | /** 30 | * @param $xml 31 | * @return array 32 | */ 33 | protected function processResponse($xml) 34 | { 35 | $result = []; 36 | 37 | foreach ($xml->database->{'get-db'}->children() as $node) { 38 | $result[] = [ 39 | 'status' => (string)$node->status, 40 | 'id' => (int)$node->id, 41 | 'name' => (string)$node->name, 42 | 'subscription_id' => (int)$node->{'webspace-id'}, 43 | 'db_server_id' => (int)$node->{'db-server-id'}, 44 | 'default_user_id' => (int)$node->{'default-user-id'}, 45 | ]; 46 | } 47 | 48 | return $result; 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/pmill/Plesk/ListEmailAddresses.php: -------------------------------------------------------------------------------- 1 | 11 | 12 | 13 | 14 | 15 | {SITE_ID} 16 | 17 | 18 | 19 | 20 | 21 | EOT; 22 | 23 | /** 24 | * @var array 25 | */ 26 | protected $default_params = [ 27 | 'site_id' => null, 28 | ]; 29 | 30 | /** 31 | * @param array $config 32 | * @param array $params 33 | * @throws ApiRequestException 34 | */ 35 | public function __construct($config, $params) 36 | { 37 | if (isset($params['domain'])) { 38 | $request = new GetSite($config, ['domain' => $params['domain']]); 39 | $info = $request->process(); 40 | 41 | $params['site_id'] = $info['id']; 42 | } 43 | 44 | parent::__construct($config, $params); 45 | } 46 | 47 | /** 48 | * @param $xml 49 | * @return array 50 | */ 51 | protected function processResponse($xml) 52 | { 53 | $result = []; 54 | 55 | foreach ($xml->mail->get_info->children() as $node) { 56 | $result[] = [ 57 | 'status' => (string)$node->status, 58 | 'id' => (int)$node->mailname->id, 59 | 'username' => (string)$node->mailname->name, 60 | 'enabled' => (bool)$node->mailname->mailbox->enabled, 61 | 'password' => (string)$node->mailname->password->value, 62 | ]; 63 | } 64 | 65 | return $result; 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /src/pmill/Plesk/ListIPAddresses.php: -------------------------------------------------------------------------------- 1 | 11 | 12 | 13 | 14 | 15 | 16 | EOT; 17 | 18 | /** 19 | * @param $xml 20 | * @return array 21 | * @throws ApiRequestException 22 | */ 23 | protected function processResponse($xml) 24 | { 25 | if ((string)$xml->ip->get->result->status == 'error') { 26 | throw new ApiRequestException($xml->ip->get->result); 27 | } 28 | 29 | $result = []; 30 | 31 | foreach ($xml->ip->get->result->addresses->children() as $ip) { 32 | $result[] = [ 33 | 'ip_address' => (string)$ip->ip_address, 34 | 'netmask' => (string)$ip->netmask, 35 | 'type' => (string)$ip->type, 36 | 'interface' => (string)$ip->interface, 37 | 'is_default' => isset($ip->default), 38 | ]; 39 | } 40 | 41 | return $result; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/pmill/Plesk/ListSecretKeys.php: -------------------------------------------------------------------------------- 1 | 11 | 12 | 13 | 14 | {FILTER} 15 | 16 | 17 | 18 | EOT; 19 | 20 | /** 21 | * @param array $config 22 | * @param array $params 23 | * @throws ApiRequestException 24 | */ 25 | public function __construct(array $config, array $params = []) 26 | { 27 | $filterNode = new Node('filter'); 28 | 29 | if (isset($params['key'])) { 30 | $filterNode->setValue(new Node('key', $params['key'])); 31 | } 32 | 33 | if (isset($params['keys']) && is_array($params['keys'])) { 34 | $nodes = []; 35 | 36 | foreach ($params['keys'] as $key) { 37 | $nodes[] = new Node('key', $key); 38 | } 39 | 40 | $filterNode->setValue(new NodeList($nodes)); 41 | } 42 | 43 | $params['filter'] = $filterNode; 44 | 45 | parent::__construct($config, $params); 46 | } 47 | 48 | /** 49 | * @param $xml 50 | * @return array 51 | */ 52 | protected function processResponse($xml) 53 | { 54 | $response = []; 55 | 56 | foreach ($xml->secret_key->get_info->result as $result) { 57 | if ($result->status == 'ok' && isset($result->key_info)) { 58 | $response[] = [ 59 | 'status' => (string)$result->status, 60 | 'key' => (string)$result->key_info->key, 61 | 'ip_address' => (string)$result->key_info->ip_address, 62 | 'description' => (string)$result->key_info->description, 63 | ]; 64 | } elseif ($result->status == 'error') { 65 | $response[] = [ 66 | 'status' => (string)$result->status, 67 | 'key' => (string)$result->key, 68 | 'error' => [ 69 | 'code' => (string)$result->errcode, 70 | 'description' => (string)$result->errtext, 71 | ], 72 | ]; 73 | } 74 | } 75 | 76 | return $response; 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /src/pmill/Plesk/ListServicePlans.php: -------------------------------------------------------------------------------- 1 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | EOT; 21 | 22 | /** 23 | * @param $xml 24 | * @return array 25 | */ 26 | protected function processResponse($xml) 27 | { 28 | $result = []; 29 | 30 | for ($i = 0; $i < count($xml->{"service-plan"}->get->result); $i++) { 31 | $plan = $xml->{"service-plan"}->get->result[$i]; 32 | 33 | $hosting = []; 34 | foreach ($plan->hosting as $host) { 35 | $hosting[$host->getName()] = Xml::getProperties($host); 36 | } 37 | 38 | $result[] = [ 39 | 'id' => (string)$plan->id, 40 | 'guid' =>(string)$plan->guid, 41 | 'status' => (string)$plan->status, 42 | 'name' => (string)$plan->name, 43 | 'limits' => [ 44 | 'overuse' => (string)$plan->limits->overuse, 45 | 'max_sites' => Xml::findProperty($plan->limits, 'max_site', 'limit'), 46 | 'max_subdomains' => Xml::findProperty($plan->limits, 'max_subdom', 'limit'), 47 | 'max_domain_aliases' => Xml::findProperty($plan->limits, 'max_dom_aliases', 'limit'), 48 | 'disk_space' => Xml::findProperty($plan->limits, 'disk_space', 'limit'), 49 | 'max_traffic' => Xml::findProperty($plan->limits, 'max_traffic', 'limit'), 50 | 'max_web_users' => Xml::findProperty($plan->limits, 'max_wu', 'limit'), 51 | 'max_subftp_users' => Xml::findProperty($plan->limits, 'max_subftp_users', 'limit'), 52 | 'max_databases' => Xml::findProperty($plan->limits, 'max_db', 'limit'), 53 | 'max_mailboxes' => Xml::findProperty($plan->limits, 'max_box', 'limit'), 54 | 'mailbox_quota' => Xml::findProperty($plan->limits, 'mbox_quota', 'limit'), 55 | 'max_maillists' => Xml::findProperty($plan->limits, 'max_maillists', 'limit'), 56 | 'max_webapps' => Xml::findProperty($plan->limits, 'max_webapps', 'limit'), 57 | 'max_site_builder' => Xml::findProperty($plan->limits, 'max_site_builder', 'limit'), 58 | 'expiration' => Xml::findProperty($plan->limits, 'expiration', 'limit'), 59 | ], 60 | 'log_rotation' => [ 61 | 'on' => (string)$plan->{"log-rotation"}->on->{"log-condition"}->{"log-bytime"}, 62 | 'max_num_files' => (int)$plan->{"log-rotation"}->on->{"log-max-num-files"}, 63 | 'compressed' => (string)$plan->{"log-rotation"}->on->{"log-compress"}, 64 | ], 65 | 'preferences' => [ 66 | 'stat' => (int)$plan->preferences->stat, 67 | 'maillists' => (string)$plan->preferences->maillists, 68 | 'dns_zone_type' => (string)$plan->preferences->dns_zone_type, 69 | ], 70 | 'hosting' => $hosting, 71 | 'performance' => [ 72 | 'bandwidth' => (int)$plan->performance->bandwidth, 73 | 'max_connections' => (int)$plan->performance->max_connections, 74 | ], 75 | 'permissions' => Xml::getProperties($plan->permissions, 'permission'), 76 | ]; 77 | } 78 | 79 | return $result; 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /src/pmill/Plesk/ListSiteAliases.php: -------------------------------------------------------------------------------- 1 | 11 | 12 | 13 | 14 | {FILTER} 15 | 16 | 17 | 18 | EOT; 19 | 20 | /** 21 | * @var array 22 | */ 23 | protected $default_params = [ 24 | 'filter' => null, 25 | ]; 26 | 27 | /** 28 | * @param array $config 29 | * @param array $params 30 | * @throws ApiRequestException 31 | */ 32 | public function __construct($config, $params = []) 33 | { 34 | $params['filter'] = new Node('filter'); 35 | 36 | if (isset($params['domain'])) { 37 | $childNode = new Node('site-name', $params['domain']); 38 | $params['filter'] = new Node('filter', $childNode); 39 | } 40 | 41 | if (isset($params['site_id'])) { 42 | $childNode = new Node('site-id', $params['site_id']); 43 | $params['filter'] = new Node('filter', $childNode); 44 | } 45 | 46 | parent::__construct($config, $params); 47 | } 48 | 49 | /** 50 | * @param $xml 51 | * @return array 52 | */ 53 | protected function processResponse($xml) 54 | { 55 | $result = []; 56 | 57 | foreach ($xml->{"site-alias"}->get->result as $alias) { 58 | $result[(int)$alias->id] = (string)$alias->info->name; 59 | } 60 | 61 | return $result; 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /src/pmill/Plesk/ListSites.php: -------------------------------------------------------------------------------- 1 | 11 | 12 | 13 | 14 | {FILTER} 15 | 16 | 17 | 18 | 19 | 20 | 21 | EOT; 22 | 23 | /** 24 | * @var array 25 | */ 26 | protected $default_params = [ 27 | 'filter' => '', 28 | ]; 29 | 30 | /** 31 | * @param array $config 32 | * @param array $params 33 | * @throws ApiRequestException 34 | */ 35 | public function __construct(array $config, $params = []) 36 | { 37 | $this->default_params['filter'] = new Node('filter'); 38 | 39 | if (isset($params['subscription_id'])) { 40 | $ownerIdNode = new Node('parent-id', $params['subscription_id']); 41 | $params['filter'] = new Node('filter', $ownerIdNode); 42 | } 43 | 44 | parent::__construct($config, $params); 45 | } 46 | 47 | /** 48 | * @param $xml 49 | * @return array 50 | */ 51 | protected function processResponse($xml) 52 | { 53 | $result = []; 54 | $itemCount = count($xml->site->get->result); 55 | 56 | 57 | for ($i = 0; $i < $itemCount; $i++) { 58 | $site = $xml->site->get->result[$i]; 59 | $hosting_type = (string)$site->data->gen_info->htype; 60 | 61 | $result[] = [ 62 | 'id' => (string)$site->id, 63 | 'status' => (string)$site->status, 64 | 'created' => (string)$site->data->gen_info->cr_date, 65 | 'name' => (string)$site->data->gen_info->name, 66 | 'ip' => (string)$site->data->gen_info->dns_ip_address, 67 | 'hosting_type' => $hosting_type, 68 | 'ip_address' => (string)$site->data->hosting->{$hosting_type}->ip_address, 69 | 'www_root' => $this->findHostingProperty($site->data->hosting->{$hosting_type}, 'www_root'), 70 | 'ftp_username' => $this->findHostingProperty($site->data->hosting->{$hosting_type}, 'ftp_login'), 71 | 'ftp_password' => $this->findHostingProperty($site->data->hosting->{$hosting_type}, 'ftp_password'), 72 | ]; 73 | } 74 | 75 | return $result; 76 | } 77 | 78 | /** 79 | * @param $node 80 | * @param $key 81 | * @return null|string 82 | */ 83 | protected function findHostingProperty($node, $key) 84 | { 85 | foreach ($node->children() as $property) { 86 | if ($property->name == $key) { 87 | return (string)$property->value; 88 | } 89 | } 90 | 91 | return null; 92 | } 93 | } 94 | -------------------------------------------------------------------------------- /src/pmill/Plesk/ListSubdomains.php: -------------------------------------------------------------------------------- 1 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | EOT; 21 | 22 | /** 23 | * @var array 24 | */ 25 | protected $default_params = [ 26 | 'filter' => null, 27 | ]; 28 | 29 | /** 30 | * ListSubdomains constructor. 31 | * @param array $config 32 | * @param array $params 33 | */ 34 | public function __construct(array $config, array $params = []) 35 | { 36 | $this->default_params['filter'] = new Node('filter'); 37 | 38 | if (isset($params['domain'])) { 39 | $ownerIdNode = new Node('site-name', $params['domain']); 40 | $params['filter'] = new Node('filter', $ownerIdNode); 41 | } 42 | 43 | if (isset($params['site_id'])) { 44 | $ownerIdNode = new Node('site-id', $params['site_id']); 45 | $params['filter'] = new Node('filter', $ownerIdNode); 46 | } 47 | 48 | parent::__construct($config, $params); 49 | } 50 | 51 | /** 52 | * @param $xml 53 | * @return array 54 | */ 55 | protected function processResponse($xml) 56 | { 57 | $result = []; 58 | 59 | foreach ($xml->subdomain->get->result as $node) { 60 | $result[] = [ 61 | 'id' => (int)$node->id, 62 | 'status' => (string)$node->status, 63 | 'parent' => (string)$node->data->parent, 64 | 'name' => (string)$node->data->name, 65 | 'php' => (string)Xml::findProperty($node->data, 'php'), 66 | 'php_handler_type' => (string)Xml::findProperty($node->data, 'php_handler_type'), 67 | 'www_root' => (string)Xml::findProperty($node->data, 'www_root'), 68 | ]; 69 | } 70 | 71 | return $result; 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /src/pmill/Plesk/ListSubscriptions.php: -------------------------------------------------------------------------------- 1 | 13 | 14 | 15 | 16 | {FILTER} 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | EOT; 25 | 26 | /** 27 | * @var array 28 | */ 29 | protected $default_params = [ 30 | 'filter' => null, 31 | ]; 32 | 33 | /** 34 | * @param array $config 35 | * @param array $params 36 | * @throws ApiRequestException 37 | */ 38 | public function __construct($config, $params = []) 39 | { 40 | $this->default_params['filter'] = new Node('filter'); 41 | 42 | if (isset($params['client_id'])) { 43 | $ownerIdNode = new Node('owner-id', $params['client_id']); 44 | $params['filter'] = new Node('filter', $ownerIdNode); 45 | } 46 | 47 | parent::__construct($config, $params); 48 | } 49 | 50 | /** 51 | * @param $xml 52 | * @return array 53 | */ 54 | protected function processResponse($xml) 55 | { 56 | $result = []; 57 | 58 | for ($i = 0; $i < count($xml->webspace->get->result); $i++) { 59 | $webspace = $xml->webspace->get->result[$i]; 60 | 61 | $hosting = []; 62 | foreach ($webspace->data->hosting->children() as $host) { 63 | $hosting[$host->getName()] = Xml::getProperties($host); 64 | } 65 | 66 | $subscriptions = []; 67 | foreach ($webspace->data->subscriptions->children() as $subscription) { 68 | $subscriptions[] = [ 69 | 'locked' => (bool)$subscription->locked, 70 | 'synchronized' => (bool)$subscription->synchronized, 71 | 'plan-guid' => (string)$subscription->plan->{"plan-guid"}, 72 | ]; 73 | } 74 | 75 | $result[] = [ 76 | 'id' => (string)$webspace->id, 77 | 'status' => (string)$webspace->status, 78 | 'subscription_status' => (int)$webspace->data->gen_info->status, 79 | 'created' => (string)$webspace->data->gen_info->cr_date, 80 | 'name' => (string)$webspace->data->gen_info->name, 81 | 'owner_id' => (string)$webspace->data->gen_info->{"owner-id"}, 82 | 'hosting' => $hosting, 83 | 'real_size' => (int)$webspace->data->gen_info->real_size, 84 | 'dns_ip_address' => (string)$webspace->data->gen_info->dns_ip_address, 85 | 'htype' => (string)$webspace->data->gen_info->htype, 86 | 'subscriptions' => $subscriptions, 87 | ]; 88 | } 89 | 90 | return $result; 91 | } 92 | } 93 | -------------------------------------------------------------------------------- /src/pmill/Plesk/MailService/UpdatePreferences.php: -------------------------------------------------------------------------------- 1 | 17 | 18 | 19 | 20 | 21 | {SITE-ID} 22 | 23 | 24 | {PREFS} 25 | 26 | 27 | 28 | 29 | EOT; 30 | 31 | /** 32 | * @var array 33 | */ 34 | protected $default_params = [ 35 | 'site-id' => null, 36 | 'nonexistent-user' => null, 37 | 'mailservice' => null, 38 | ]; 39 | 40 | /** 41 | * @param array $config 42 | * @param array $params 43 | * @param HttpRequestContract|null $http 44 | */ 45 | public function __construct(array $config, array $params = [], HttpRequestContract $http = null) 46 | { 47 | $helper = new MailPreferences(); 48 | $params['prefs'] = $helper->generate($params); 49 | 50 | parent::__construct($config, $params, $http); 51 | } 52 | 53 | /** 54 | * @param SimpleXMLElement $xml 55 | * @return bool 56 | * @throws ApiRequestException 57 | */ 58 | protected function processResponse($xml) 59 | { 60 | if ((string) $xml->{'mail'}->{'set_prefs'}->result->status === 'error') { 61 | throw new ApiRequestException($xml->{'mail'}->{'set_prefs'}->result); 62 | } 63 | 64 | return true; 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /src/pmill/Plesk/Node.php: -------------------------------------------------------------------------------- 1 | tag = $tag; 26 | $this->value = $value; 27 | } 28 | 29 | /** 30 | * @return string 31 | */ 32 | public function getTag() 33 | { 34 | return $this->tag; 35 | } 36 | 37 | /** 38 | * @param string $tag 39 | */ 40 | public function setTag($tag) 41 | { 42 | $this->tag = $tag; 43 | } 44 | 45 | /** 46 | * @return string 47 | */ 48 | public function getValue() 49 | { 50 | return $this->value; 51 | } 52 | 53 | /** 54 | * @param string $value 55 | */ 56 | public function setValue($value) 57 | { 58 | $this->value = $value; 59 | } 60 | 61 | /** 62 | * @return string 63 | */ 64 | public function __toString() 65 | { 66 | if (is_null($this->value)) { 67 | return sprintf('<%s/>', $this->tag); 68 | } 69 | 70 | if (is_string($this->value)) { 71 | $this->value = Xml::sanitize($this->value); 72 | } 73 | 74 | if (is_bool($this->value)) { 75 | $this->value = $this->value ? 'true' : 'false'; 76 | } 77 | 78 | return sprintf('<%s>%s', $this->tag, (string)$this->value, $this->tag); 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /src/pmill/Plesk/NodeList.php: -------------------------------------------------------------------------------- 1 | $value) { 15 | $nodes[] = new Node($key, $value); 16 | } 17 | 18 | return new NodeList($nodes); 19 | } 20 | 21 | /** 22 | * @var array|Node[] 23 | */ 24 | protected $nodes = []; 25 | 26 | /** 27 | * NodeList constructor. 28 | * @param array Node[] $nodes 29 | */ 30 | public function __construct(array $nodes = []) 31 | { 32 | $this->nodes = $nodes; 33 | } 34 | 35 | /** 36 | * @return array 37 | */ 38 | public function getNodes() 39 | { 40 | return $this->nodes; 41 | } 42 | 43 | /** 44 | * @param array $nodes 45 | */ 46 | public function setNodes($nodes) 47 | { 48 | $this->nodes = $nodes; 49 | } 50 | 51 | /** 52 | * @return string 53 | */ 54 | public function __toString() 55 | { 56 | $result = ''; 57 | 58 | foreach ($this->nodes as $node) { 59 | $result .= (string) $node; 60 | } 61 | 62 | return $result; 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /src/pmill/Plesk/ObjectStatus.php: -------------------------------------------------------------------------------- 1 | 11 | 12 | 13 | 14 | {ID} 15 | {NAME} 16 | 17 | 18 | 19 | EOT; 20 | 21 | /** 22 | * @var array 23 | */ 24 | protected $default_params = [ 25 | 'id' => null, 26 | 'name' => null, 27 | ]; 28 | 29 | /** 30 | * @param array $config 31 | * @param array $params 32 | * @throws ApiRequestException 33 | */ 34 | public function __construct($config, $params) 35 | { 36 | if (isset($params['subdomain'])) { 37 | $request = new GetSubdomain($config, ['name' => $params['subdomain']]); 38 | $info = $request->process(); 39 | 40 | $this->params['id'] = $info['id']; 41 | } 42 | 43 | parent::__construct($config, $params); 44 | } 45 | 46 | /** 47 | * @param $xml 48 | * @return bool 49 | * @throws ApiRequestException 50 | */ 51 | protected function processResponse($xml) 52 | { 53 | $result = $xml->subdomain->rename->result; 54 | 55 | if ($result->status == 'error') { 56 | throw new ApiRequestException($result); 57 | } 58 | 59 | return true; 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /src/pmill/Plesk/SSL/InstallCertificate.php: -------------------------------------------------------------------------------- 1 | 17 | 18 | 19 | 20 | {NAME} 21 | {DESTINATION} 22 | 23 | {CSR} 24 | {PVT} 25 | {CRT} 26 | {CA} 27 | 28 | {IP-ADDRESS} 29 | 30 | 31 | 32 | EOT; 33 | 34 | /** 35 | * @var array 36 | */ 37 | protected $default_params = [ 38 | 'name' => null, 39 | 'csr' => null, 40 | 'pvt' => null, 41 | 'ip-address' => null, 42 | ]; 43 | 44 | /** 45 | * @param array $config 46 | * @param array $params 47 | * @param HttpRequestContract $http 48 | * @throws ApiRequestException 49 | */ 50 | public function __construct(array $config, array $params = [], HttpRequestContract $http = null) 51 | { 52 | if (isset($params['admin']) && $params['admin'] === true) { 53 | $params['destination'] = new Node('admin'); 54 | } 55 | 56 | if (isset($params['webspace'])) { 57 | $params['destination'] = new Node('webspace', $params['webspace']); 58 | } 59 | 60 | if (!isset($params['destination'])) { 61 | throw new ApiRequestException('admin or webspace parameter is required'); 62 | } 63 | 64 | if (isset($params['crt'])) { 65 | $params['crt'] = new Node('crt', $params['crt']); 66 | } else { 67 | $params['crt'] = ''; 68 | } 69 | 70 | if (isset($params['ca'])) { 71 | $params['ca'] = new Node('ca', $params['ca']); 72 | } else { 73 | $params['ca'] = ''; 74 | } 75 | 76 | parent::__construct($config, $params, $http); 77 | } 78 | 79 | /** 80 | * @param SimpleXMLElement $xml 81 | * @return bool 82 | * @throws ApiRequestException 83 | */ 84 | protected function processResponse($xml) 85 | { 86 | if ((string) $xml->{'certificate'}->{'install'}->result->status === 'error') { 87 | throw new ApiRequestException($xml->{'certificate'}->{'install'}->result); 88 | } 89 | 90 | return true; 91 | } 92 | } 93 | -------------------------------------------------------------------------------- /src/pmill/Plesk/UpdateClient.php: -------------------------------------------------------------------------------- 1 | 11 | 12 | 13 | 14 | 15 | {USERNAME} 16 | 17 | 18 | 19 | {NODES} 20 | 21 | 22 | 23 | 24 | 25 | EOT; 26 | 27 | /** 28 | * @var array 29 | */ 30 | protected $default_params = [ 31 | 'username' => '', 32 | 'company_name' => '', 33 | 'contact_name' => '', 34 | 'password' => '', 35 | 'status' => 0, 36 | 'phone' => '', 37 | 'fax' => '', 38 | 'email' => '', 39 | 'address' => '', 40 | 'city' => '', 41 | 'state' => '', 42 | 'post_code' => '', 43 | 'country' => '', 44 | ]; 45 | 46 | /** 47 | * @var array 48 | */ 49 | protected $node_mapping = [ 50 | 'password' => 'passwd', 51 | 'status' => 'status', 52 | 'phone' => 'phone', 53 | 'fax' => 'fax', 54 | 'email' => 'email', 55 | 'address' => 'address', 56 | 'city' => 'city', 57 | 'state' => 'state', 58 | 'post_code' => 'pcode', 59 | 'country' => 'country', 60 | ]; 61 | 62 | /** 63 | * UpdateClient constructor. 64 | * @param array $config 65 | * @param array $params 66 | */ 67 | public function __construct(array $config, array $params) 68 | { 69 | $params['nodes'] = $this->generateNodeList($params); 70 | parent::__construct($config, $params); 71 | } 72 | 73 | /** 74 | * @param $xml 75 | * @return bool 76 | * @throws ApiRequestException 77 | */ 78 | protected function processResponse($xml) 79 | { 80 | $result = $xml->customer->set->result; 81 | 82 | if ($result->status == 'error') { 83 | throw new ApiRequestException($result); 84 | } 85 | 86 | return true; 87 | } 88 | } 89 | -------------------------------------------------------------------------------- /src/pmill/Plesk/UpdateEmailPassword.php: -------------------------------------------------------------------------------- 1 | 11 | 12 | 13 | 14 | 15 | 16 | {DOMAIN_ID} 17 | 18 | {USERNAME} 19 | {PASSWORD} 20 | 21 | 22 | 23 | 24 | 25 | 26 | EOT; 27 | 28 | /** 29 | * @var int 30 | */ 31 | public $id; 32 | 33 | /** 34 | * @var array 35 | */ 36 | protected $default_params = [ 37 | 'domain_id' => null, 38 | 'username' => null, 39 | 'password' => null, 40 | ]; 41 | 42 | /** 43 | * @param array $config 44 | * @param array $params 45 | * @throws ApiRequestException 46 | */ 47 | public function __construct($config, $params) 48 | { 49 | if (isset($params['email'])) { 50 | if (!filter_var($params['email'], FILTER_VALIDATE_EMAIL)) { 51 | throw new ApiRequestException("Invalid email submitted"); 52 | } 53 | 54 | list($username, $domain) = explode("@", $params['email']); 55 | 56 | $request = new GetSite($config, ['domain' => $domain]); 57 | $info = $request->process(); 58 | 59 | $params['domain_id'] = $info['id']; 60 | $params['username'] = $username; 61 | } 62 | 63 | parent::__construct($config, $params); 64 | } 65 | 66 | /** 67 | * @param $xml 68 | * @return bool 69 | * @throws ApiRequestException 70 | */ 71 | protected function processResponse($xml) 72 | { 73 | $result = $xml->mail->update->result; 74 | 75 | if ($result->status == 'error') { 76 | throw new ApiRequestException($result); 77 | } 78 | 79 | $this->id = (int)$result->id; 80 | return true; 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /src/pmill/Plesk/UpdateSite.php: -------------------------------------------------------------------------------- 1 | 11 | 12 | 13 | 14 | 15 | {ID} 16 | 17 | 18 | {NODES} 19 | {PROPERTIES} 20 | 21 | 22 | 23 | 24 | EOT; 25 | 26 | /** 27 | * @var int 28 | */ 29 | public $id; 30 | 31 | /** 32 | * @var array 33 | */ 34 | protected $default_params = [ 35 | 'id' => null, 36 | 'nodes' => '', 37 | 'properties' => '', 38 | ]; 39 | 40 | /** 41 | * @var array 42 | */ 43 | protected $node_mapping = [ 44 | 'status' => 'status', 45 | 'domain' => 'name', 46 | ]; 47 | 48 | /** 49 | * UpdateSite constructor. 50 | * @param array $config 51 | * @param array $params 52 | */ 53 | public function __construct(array $config, $params = []) 54 | { 55 | $properties = []; 56 | 57 | foreach (['php', 'php_handler_type', 'webstat', 'www_root', 'php', 'php_handler_id', 'php_version'] as $key) { 58 | if (isset($params[$key])) { 59 | $properties[$key] = $params[$key]; 60 | } 61 | } 62 | 63 | if (count($properties) > 0) { 64 | $childNode = new Node('vrt_hst', $this->generatePropertyList($properties)); 65 | $params['properties'] = new Node('hosting', $childNode); 66 | } 67 | 68 | if (count($params) > 0) { 69 | $params['nodes'] = new Node('gen_setup', $this->generateNodeList($params)); 70 | } 71 | 72 | parent::__construct($config, $params); 73 | } 74 | 75 | /** 76 | * @param $xml 77 | * @return bool 78 | * @throws ApiRequestException 79 | */ 80 | protected function processResponse($xml) 81 | { 82 | if ($xml->site->set->result->status == 'error') { 83 | throw new ApiRequestException($xml->site->set->result); 84 | } 85 | 86 | $this->id = (int)$xml->site->set->result->id; 87 | return true; 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /src/pmill/Plesk/UpdateSubdomain.php: -------------------------------------------------------------------------------- 1 | 11 | 12 | 13 | 14 | 15 | {FILTER} 16 | 17 | {PROPERTIES} 18 | 19 | 20 | 21 | EOT; 22 | 23 | /** 24 | * @var array 25 | */ 26 | protected $default_params = [ 27 | 'filter' => null, 28 | 'properties' => null, 29 | ]; 30 | 31 | /** 32 | * @param array $config 33 | * @param array $params 34 | * @throws ApiRequestException 35 | */ 36 | public function __construct(array $config, array $params) 37 | { 38 | if (isset($params['subdomain'])) { 39 | $params['filter'] = new Node('name', $params['subdomain']); 40 | } 41 | 42 | if (isset($params['id'])) { 43 | $params['filter'] = new Node('id', $params['id']); 44 | } 45 | 46 | $properties = []; 47 | 48 | foreach (['www_root'] as $key) { 49 | if (isset($params[$key])) { 50 | $properties[$key] = $params[$key]; 51 | } 52 | } 53 | 54 | $params['properties'] = $this->generatePropertyList($properties); 55 | 56 | parent::__construct($config, $params); 57 | } 58 | 59 | /** 60 | * @param $xml 61 | * @return bool 62 | * @throws ApiRequestException 63 | */ 64 | protected function processResponse($xml) 65 | { 66 | $result = $xml->subdomain->set->result; 67 | 68 | if ($result->status == 'error') { 69 | throw new ApiRequestException($result); 70 | } 71 | 72 | return true; 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /src/pmill/Plesk/Wordpress/ActivatePlugin.php: -------------------------------------------------------------------------------- 1 | 12 | 13 | 14 | 15 | 16 | {ID} 17 | 18 | {PLUGIN_ID} 19 | 20 | 21 | 22 | EOT; 23 | 24 | /** 25 | * @var array 26 | */ 27 | protected $default_params = [ 28 | 'id' => null, 29 | 'plugin_id' => null, 30 | ]; 31 | 32 | /** 33 | * @param SimpleXMLElement $xml 34 | * @return bool 35 | * @throws ApiRequestException 36 | */ 37 | protected function processResponse($xml) 38 | { 39 | if ((string) $xml->{'wp-instance'}->{'activate-plugin'}->result->status === 'error') { 40 | throw new ApiRequestException($xml->{'wp-instance'}->{'activate-plugin'}->result); 41 | } 42 | 43 | return true; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/pmill/Plesk/Wordpress/ActivateTheme.php: -------------------------------------------------------------------------------- 1 | 12 | 13 | 14 | 15 | 16 | {ID} 17 | 18 | {THEME_ID} 19 | 20 | 21 | 22 | EOT; 23 | 24 | /** 25 | * @var array 26 | */ 27 | protected $default_params = [ 28 | 'id' => null, 29 | 'theme_id' => null, 30 | ]; 31 | 32 | /** 33 | * @param SimpleXMLElement $xml 34 | * @return bool 35 | * @throws ApiRequestException 36 | */ 37 | protected function processResponse($xml) 38 | { 39 | if ((string) $xml->{'wp-instance'}->{'activate-theme'}->result->status === 'error') { 40 | throw new ApiRequestException($xml->{'wp-instance'}->{'activate-theme'}->result); 41 | } 42 | 43 | return true; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/pmill/Plesk/Wordpress/ClearCache.php: -------------------------------------------------------------------------------- 1 | 12 | 13 | 14 | 15 | 16 | {ID} 17 | 18 | 19 | 20 | 21 | EOT; 22 | 23 | /** 24 | * @var array 25 | */ 26 | protected $default_params = [ 27 | 'id' => null, 28 | ]; 29 | 30 | /** 31 | * @param SimpleXMLElement $xml 32 | * @return bool 33 | * @throws ApiRequestException 34 | */ 35 | protected function processResponse($xml) 36 | { 37 | if ((string) $xml->{'wp-instance'}->{'clear-cache'}->result->status === 'error') { 38 | throw new ApiRequestException($xml->{'wp-instance'}->{'clear-cache'}->result); 39 | } 40 | 41 | return true; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/pmill/Plesk/Wordpress/DeactivatePlugin.php: -------------------------------------------------------------------------------- 1 | 12 | 13 | 14 | 15 | 16 | {ID} 17 | 18 | {PLUGIN_ID} 19 | 20 | 21 | 22 | EOT; 23 | 24 | /** 25 | * @var array 26 | */ 27 | protected $default_params = [ 28 | 'id' => null, 29 | 'plugin_id' => null, 30 | ]; 31 | 32 | /** 33 | * @param SimpleXMLElement $xml 34 | * @return bool 35 | * @throws ApiRequestException 36 | */ 37 | protected function processResponse($xml) 38 | { 39 | if ((string) $xml->{'wp-instance'}->{'deactivate-plugin'}->result->status === 'error') { 40 | throw new ApiRequestException($xml->{'wp-instance'}->{'deactivate-plugin'}->result); 41 | } 42 | 43 | return true; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/pmill/Plesk/Wordpress/DisableAutoUpdates.php: -------------------------------------------------------------------------------- 1 | 12 | 13 | 14 | 15 | 16 | {ID} 17 | 18 | 19 | 20 | 21 | EOT; 22 | 23 | /** 24 | * @var array 25 | */ 26 | protected $default_params = [ 27 | 'id' => null, 28 | ]; 29 | 30 | /** 31 | * @param SimpleXMLElement $xml 32 | * @return bool 33 | * @throws ApiRequestException 34 | */ 35 | protected function processResponse($xml) 36 | { 37 | if ((string) $xml->{'wp-instance'}->{'disable-auto-updates'}->result->status === 'error') { 38 | throw new ApiRequestException($xml->{'wp-instance'}->{'disable-auto-updates'}->result); 39 | } 40 | 41 | return true; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/pmill/Plesk/Wordpress/EnableAutoUpdates.php: -------------------------------------------------------------------------------- 1 | 12 | 13 | 14 | 15 | 16 | {ID} 17 | 18 | 19 | 20 | 21 | EOT; 22 | 23 | /** 24 | * @var array 25 | */ 26 | protected $default_params = [ 27 | 'id' => null, 28 | ]; 29 | 30 | /** 31 | * @param SimpleXMLElement $xml 32 | * @return bool 33 | * @throws ApiRequestException 34 | */ 35 | protected function processResponse($xml) 36 | { 37 | if ((string) $xml->{'wp-instance'}->{'enable-auto-updates'}->result->status === 'error') { 38 | throw new ApiRequestException($xml->{'wp-instance'}->{'enable-auto-updates'}->result); 39 | } 40 | 41 | return true; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/pmill/Plesk/Wordpress/GetPluginList.php: -------------------------------------------------------------------------------- 1 | 12 | 13 | 14 | 15 | 16 | {ID} 17 | 18 | 19 | 20 | 21 | EOT; 22 | 23 | /** 24 | * @param SimpleXMLElement $xml 25 | * @return array 26 | * @throws ApiRequestException 27 | */ 28 | protected function processResponse($xml) 29 | { 30 | if ((string) $xml->{'wp-instance'}->{'get-plugin-list'}->result->status == "error") { 31 | throw new ApiRequestException($xml->{'wp-instance'}->{'get-plugin-list'}->result); 32 | } 33 | 34 | $response = []; 35 | 36 | foreach ($xml->{'wp-instance'}->{'get-plugin-list'}->result->item as $result) { 37 | $response[] = [ 38 | 'title' => (string) $result->title, 39 | 'id' => (string) $result->id, 40 | ]; 41 | } 42 | 43 | return $response; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/pmill/Plesk/Wordpress/GetSecurityStatus.php: -------------------------------------------------------------------------------- 1 | 11 | 12 | 13 | 14 | 15 | {ID} 16 | 17 | 18 | 19 | 20 | EOT; 21 | 22 | /** 23 | * @param SimpleXMLElement $xml 24 | * @return array 25 | */ 26 | protected function processResponse($xml) 27 | { 28 | $response = []; 29 | 30 | foreach ($xml->{'wp-instance'}->{'get-security-status'}->result as $result) { 31 | $response[] = [ 32 | 'status' => (string) $result->status, 33 | 'security-status' => (string) $result->{'security-status'}, 34 | ]; 35 | } 36 | 37 | return $response; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/pmill/Plesk/Wordpress/GetThemeList.php: -------------------------------------------------------------------------------- 1 | 12 | 13 | 14 | 15 | 16 | {ID} 17 | 18 | 19 | 20 | 21 | EOT; 22 | 23 | /** 24 | * @param SimpleXMLElement $xml 25 | * @return array 26 | * @throws ApiRequestException 27 | */ 28 | protected function processResponse($xml) 29 | { 30 | if ((string) $xml->{'wp-instance'}->{'get-theme-list'}->result->status == "error") { 31 | throw new ApiRequestException($xml->{'wp-instance'}->{'get-theme-list'}->result); 32 | } 33 | 34 | $response = []; 35 | 36 | foreach ($xml->{'wp-instance'}->{'get-theme-list'}->result->item as $result) { 37 | $response[] = [ 38 | 'title' => (string) $result->title, 39 | 'id' => (string) $result->id, 40 | ]; 41 | } 42 | 43 | return $response; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/pmill/Plesk/Wordpress/InstallPlugin.php: -------------------------------------------------------------------------------- 1 | 12 | 13 | 14 | 15 | 16 | {ID} 17 | 18 | {PLUGIN_ID} 19 | 20 | 21 | 22 | EOT; 23 | 24 | /** 25 | * @var array 26 | */ 27 | protected $default_params = [ 28 | 'id' => null, 29 | 'plugin_id' => null, 30 | ]; 31 | 32 | /** 33 | * @param SimpleXMLElement $xml 34 | * @return bool 35 | * @throws ApiRequestException 36 | */ 37 | protected function processResponse($xml) 38 | { 39 | if ((string) $xml->{'wp-instance'}->{'install-plugin'}->result->status === 'error') { 40 | throw new ApiRequestException($xml->{'wp-instance'}->{'install-plugin'}->result); 41 | } 42 | 43 | return true; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/pmill/Plesk/Wordpress/InstallTheme.php: -------------------------------------------------------------------------------- 1 | 12 | 13 | 14 | 15 | 16 | {ID} 17 | 18 | {THEME_ID} 19 | 20 | 21 | 22 | EOT; 23 | 24 | /** 25 | * @var array 26 | */ 27 | protected $default_params = [ 28 | 'id' => null, 29 | 'theme_id' => null, 30 | ]; 31 | 32 | /** 33 | * @param SimpleXMLElement $xml 34 | * @return bool 35 | * @throws ApiRequestException 36 | */ 37 | protected function processResponse($xml) 38 | { 39 | if ((string) $xml->{'wp-instance'}->{'install-theme'}->result->status === 'error') { 40 | throw new ApiRequestException($xml->{'wp-instance'}->{'install-theme'}->result); 41 | } 42 | 43 | return true; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/pmill/Plesk/Wordpress/ListInstances.php: -------------------------------------------------------------------------------- 1 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | EOT; 18 | 19 | /** 20 | * @param SimpleXMLElement $xml 21 | * @return array 22 | */ 23 | protected function processResponse($xml) 24 | { 25 | $response = []; 26 | 27 | foreach ($xml->{'wp-instance'}->{'get-list'}->result as $result) { 28 | $result = $result->{'wp-instance'}; 29 | 30 | $response[] = [ 31 | 'id' => (int) $result->id, 32 | 'url' => (string) $result->url, 33 | 'owner' => (string) $result->owner, 34 | ]; 35 | } 36 | 37 | return $response; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/pmill/Plesk/Wordpress/RemoveInstance.php: -------------------------------------------------------------------------------- 1 | 12 | 13 | 14 | 15 | 16 | {ID} 17 | 18 | 19 | 20 | 21 | EOT; 22 | 23 | /** 24 | * @var array 25 | */ 26 | protected $default_params = [ 27 | 'id' => null, 28 | ]; 29 | 30 | /** 31 | * @param SimpleXMLElement $xml 32 | * @return bool 33 | * @throws ApiRequestException 34 | */ 35 | protected function processResponse($xml) 36 | { 37 | if ((string) $xml->{'wp-instance'}->{'remove'}->result->status === 'error') { 38 | throw new ApiRequestException($xml->{'wp-instance'}->{'remove'}->result); 39 | } 40 | 41 | return true; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/pmill/Plesk/Wordpress/SearchPlugins.php: -------------------------------------------------------------------------------- 1 | 12 | 13 | 14 | 15 | {QUERY} 16 | 17 | 18 | 19 | EOT; 20 | 21 | /** 22 | * @param SimpleXMLElement $xml 23 | * @return array 24 | * @throws ApiRequestException 25 | */ 26 | protected function processResponse($xml) 27 | { 28 | if ((string) $xml->{'wp-instance'}->{'search-plugins'}->result->status == "error") { 29 | throw new ApiRequestException($xml->{'wp-instance'}->{'search-plugins'}->result); 30 | } 31 | 32 | $response = []; 33 | 34 | foreach ($xml->{'wp-instance'}->{'search-plugins'}->result->item as $result) { 35 | $response[] = [ 36 | 'title' => (string) $result->title, 37 | 'id' => (string) $result->id, 38 | ]; 39 | } 40 | 41 | return $response; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/pmill/Plesk/Wordpress/SearchThemes.php: -------------------------------------------------------------------------------- 1 | 12 | 13 | 14 | 15 | {QUERY} 16 | 17 | 18 | 19 | EOT; 20 | 21 | /** 22 | * @param SimpleXMLElement $xml 23 | * @return array 24 | * @throws ApiRequestException 25 | */ 26 | protected function processResponse($xml) 27 | { 28 | if ((string) $xml->{'wp-instance'}->{'search-themes'}->result->status == "error") { 29 | throw new ApiRequestException($xml->{'wp-instance'}->{'search-themes'}->result); 30 | } 31 | 32 | $response = []; 33 | 34 | foreach ($xml->{'wp-instance'}->{'search-themes'}->result->item as $result) { 35 | $response[] = [ 36 | 'title' => (string) $result->title, 37 | 'id' => (string) $result->id, 38 | ]; 39 | } 40 | 41 | return $response; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/pmill/Plesk/Wordpress/UninstallPlugin.php: -------------------------------------------------------------------------------- 1 | 12 | 13 | 14 | 15 | 16 | {ID} 17 | 18 | {PLUGIN_ID} 19 | 20 | 21 | 22 | EOT; 23 | 24 | /** 25 | * @var array 26 | */ 27 | protected $default_params = [ 28 | 'id' => null, 29 | 'plugin_id' => null, 30 | ]; 31 | 32 | /** 33 | * @param SimpleXMLElement $xml 34 | * @return bool 35 | * @throws ApiRequestException 36 | */ 37 | protected function processResponse($xml) 38 | { 39 | if ((string) $xml->{'wp-instance'}->{'uninstall-plugin'}->result->status === 'error') { 40 | throw new ApiRequestException($xml->{'wp-instance'}->{'uninstall-plugin'}->result); 41 | } 42 | 43 | return true; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/pmill/Plesk/Wordpress/UninstallTheme.php: -------------------------------------------------------------------------------- 1 | 12 | 13 | 14 | 15 | 16 | {ID} 17 | 18 | {THEME_ID} 19 | 20 | 21 | 22 | EOT; 23 | 24 | /** 25 | * @var array 26 | */ 27 | protected $default_params = [ 28 | 'id' => null, 29 | 'theme_id' => null, 30 | ]; 31 | 32 | /** 33 | * @param SimpleXMLElement $xml 34 | * @return bool 35 | * @throws ApiRequestException 36 | */ 37 | protected function processResponse($xml) 38 | { 39 | if ((string) $xml->{'wp-instance'}->{'uninstall-theme'}->result->status === 'error') { 40 | throw new ApiRequestException($xml->{'wp-instance'}->{'uninstall-theme'}->result); 41 | } 42 | 43 | return true; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/pmill/Plesk/Wordpress/UpdateCore.php: -------------------------------------------------------------------------------- 1 | 12 | 13 | 14 | 15 | 16 | {ID} 17 | 18 | 19 | 20 | 21 | EOT; 22 | 23 | /** 24 | * @var array 25 | */ 26 | protected $default_params = [ 27 | 'id' => null, 28 | ]; 29 | 30 | /** 31 | * @param SimpleXMLElement $xml 32 | * @return bool 33 | * @throws ApiRequestException 34 | */ 35 | protected function processResponse($xml) 36 | { 37 | if ((string) $xml->{'wp-instance'}->{'update-core'}->result->status === 'error') { 38 | throw new ApiRequestException($xml->{'wp-instance'}->{'update-core'}->result); 39 | } 40 | 41 | return true; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/pmill/Plesk/Wordpress/UpdatePlugin.php: -------------------------------------------------------------------------------- 1 | 12 | 13 | 14 | 15 | 16 | {ID} 17 | 18 | {PLUGIN_ID} 19 | 20 | 21 | 22 | EOT; 23 | 24 | /** 25 | * @var array 26 | */ 27 | protected $default_params = [ 28 | 'id' => null, 29 | 'plugin_id' => null, 30 | ]; 31 | 32 | /** 33 | * @param SimpleXMLElement $xml 34 | * @return bool 35 | * @throws ApiRequestException 36 | */ 37 | protected function processResponse($xml) 38 | { 39 | if ((string) $xml->{'wp-instance'}->{'update-plugin'}->result->status === 'error') { 40 | throw new ApiRequestException($xml->{'wp-instance'}->{'update-plugin'}->result); 41 | } 42 | 43 | return true; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/pmill/Plesk/Wordpress/UpdateTheme.php: -------------------------------------------------------------------------------- 1 | 12 | 13 | 14 | 15 | 16 | {ID} 17 | 18 | {THEME_ID} 19 | 20 | 21 | 22 | EOT; 23 | 24 | /** 25 | * @var array 26 | */ 27 | protected $default_params = [ 28 | 'id' => null, 29 | 'theme_id' => null, 30 | ]; 31 | 32 | /** 33 | * @param SimpleXMLElement $xml 34 | * @return bool 35 | * @throws ApiRequestException 36 | */ 37 | protected function processResponse($xml) 38 | { 39 | if ((string) $xml->{'wp-instance'}->{'update-theme'}->result->status === 'error') { 40 | throw new ApiRequestException($xml->{'wp-instance'}->{'update-theme'}->result); 41 | } 42 | 43 | return true; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /tests/complete_run.php: -------------------------------------------------------------------------------- 1 | register(); 13 | 14 | /* 15 | * Utility functions 16 | */ 17 | 18 | function random_string($length = 8) 19 | { 20 | $chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; 21 | return substr(str_shuffle($chars), 0, $length); 22 | } 23 | 24 | /* 25 | * This file attempts the following operations on a real Plesk server (intended to be run by an admin account) 26 | * 27 | * 1. Get server information (GetServerInfo) 28 | * 2. Find shared ip address (ListIPAddresses) 29 | * 3. Find unlimited service plan (ListServicePlans) 30 | * 4. Creates a new client (CreateClient) 31 | * 5. Get new client from server (GetClient) 32 | * 6. Update client information (UpdateClient) 33 | * 7. Create subscription (CreateSubscription) 34 | * 8. List subscriptions (ListSubscriptions) 35 | * 9. Create new site (CreateSite) 36 | * 10. Find created site (ListSite) 37 | * 11. Update site information (UpdateSite) 38 | * 12. Create email address (CreateEmailAddress) 39 | * 13. List email addresses (ListEmailAddresses) 40 | * 14. Update email address (UpdateEmailAddress) 41 | * 15. Delete email address (DeleteEmailAddress) 42 | * 16. Create site alias (CreateSiteAlias) 43 | * 17. List site aliases (ListSiteAliases) 44 | * 18. Delete site alias (DeleteEmailAddress) 45 | * 19. Create subdomain (CreateSubdomain) 46 | * 20. List subdomains (ListSubdomains) 47 | * 21. Update subdomain(UpdateSubdomain) 48 | * 22. Rename subdomain(RenameSubdomain) 49 | * 23. Delete subdomain(DeleteSubdomain) 50 | * 24. List database servers (ListDatabaseServers) 51 | * 25. Create database (CreateDatabase) 52 | * 26. List databases (ListDatabases) 53 | * 27. Create database user (CreateDatabaseUser) 54 | * 28. Get database user info (GetDatabaseUser) 55 | * 29. Delete database (DeleteDatabase) 56 | * 30. Delete previously created site (DeleteSite) 57 | * 31. Delete previously created subscription (DeleteSubscription) 58 | * 32. Deletes previously created client (DeleteClient) 59 | * 60 | */ 61 | 62 | $config = array( 63 | 'host'=>'example.com', 64 | 'username'=>'username', 65 | 'password'=>'password', 66 | ); 67 | 68 | 69 | /* 70 | * Choose which tests to run, try not to do them all at the same time, it can be quite slow 71 | */ 72 | $runSiteTests = true; 73 | $runEmailAddressTests = true; 74 | $runSiteAliasTests = true; 75 | $runSubdomainTests = true; 76 | $runDatabaseTests = true; 77 | 78 | $data = array(); 79 | 80 | /* 81 | * 1. Get server information (GetServerInfo) 82 | */ 83 | 84 | $request = new \pmill\Plesk\GetServerInfo($config); 85 | $info = $request->process(); 86 | 87 | echo "Running test suite on " . $info['server_name'] . PHP_EOL; 88 | 89 | 90 | /* 91 | * 2. Find shared ip address (ListIPAddresses) 92 | */ 93 | 94 | $request = new \pmill\Plesk\ListIPAddresses($config); 95 | $ips = $request->process(); 96 | 97 | foreach ($ips as $ip) { 98 | if ($ip['is_default']) { 99 | $data['shared_ip_address'] = $ip['ip_address']; 100 | } 101 | } 102 | 103 | if (!isset($data['shared_ip_address'])) { 104 | throw new Exception("Couldn't find any shared IP addresses"); 105 | } 106 | 107 | echo "Shared IP Address found: " . $data['shared_ip_address'] . PHP_EOL; 108 | 109 | /* 110 | * 3. Find unlimited service plan (ListServicePlans) 111 | */ 112 | 113 | $request = new \pmill\Plesk\ListServicePlans($config); 114 | $plans = $request->process(); 115 | 116 | foreach ($plans as $plan) { 117 | if (strtolower($plan['name']) == 'unlimited') { 118 | $data['unlimited_plan_id'] = $plan['id']; 119 | echo "Unlimited Service Plan found: " . $data['unlimited_plan_id'] . PHP_EOL; 120 | break; 121 | } 122 | } 123 | 124 | if (!isset($data['unlimited_plan_id'])) { 125 | throw new Exception("Couldn't find unlimited service plan"); 126 | } 127 | 128 | /* 129 | * 4. Creates a new client (CreateClient) 130 | */ 131 | 132 | $data['client_username'] = strtolower(random_string()); 133 | 134 | $request = new \pmill\Plesk\CreateClient($config, array( 135 | 'contact_name' => random_string(), 136 | 'username' => $data['client_username'], 137 | 'password' => random_string(16) . "1!", 138 | )); 139 | 140 | $request->process(); 141 | $data['client_id'] = $request->id; 142 | echo "Client created: " . $data['client_username'] . PHP_EOL; 143 | 144 | 145 | try { 146 | /* 147 | * 5. Get new client from server (GetClient) 148 | */ 149 | 150 | $request = new \pmill\Plesk\GetClient($config, array( 151 | 'username' => $data['client_username'], 152 | )); 153 | $info = $request->process(); 154 | echo "Client found: " . $data['client_username'] . PHP_EOL; 155 | 156 | /* 157 | * 6. Update client information (UpdateClient) 158 | */ 159 | 160 | $request = new \pmill\Plesk\UpdateClient($config, array( 161 | 'username' => $data['client_username'], 162 | 'phone' => random_string(), 163 | 'email' => random_string() . '@example.com', 164 | )); 165 | $info = $request->process(); 166 | echo "Client updated: " . $data['client_username'] . PHP_EOL; 167 | 168 | 169 | /* 170 | * 7. Create subscription (CreateSubscription) 171 | */ 172 | 173 | $params = array( 174 | 'domain_name' => random_string() . '.com', 175 | 'username' => $data['client_username'], 176 | 'password' => random_string(16) . '1!', 177 | 'ip_address' => $data['shared_ip_address'], 178 | 'owner_id' => $data['client_id'], 179 | 'service_plan_id' => $data['unlimited_plan_id'], 180 | ); 181 | 182 | $request = new \pmill\Plesk\CreateSubscription($config, $params); 183 | $request->process(); 184 | $data['subscription_id'] = $request->id; 185 | echo "Subscription created: " . $data['subscription_id'] . PHP_EOL; 186 | 187 | 188 | /* 189 | * 8. List subscriptions (ListSubscriptions) 190 | */ 191 | 192 | $request = new \pmill\Plesk\ListSubscriptions($config); 193 | $subscriptions = $request->process(); 194 | 195 | $subscription_found = false; 196 | foreach ($subscriptions as $subscription) { 197 | if ($subscription['id'] == $data['subscription_id']) { 198 | $subscription_found = true; 199 | } 200 | } 201 | 202 | if (!$subscription_found) { 203 | throw new Exception("Couldn't find created subscription"); 204 | } 205 | 206 | echo "Subscription found: " . $data['subscription_id'] . PHP_EOL; 207 | 208 | if ($runSiteTests) { 209 | /* 210 | * 9. Create new site (CreateSite) 211 | */ 212 | 213 | $data['domain'] = random_string() . '.com'; 214 | $request = new \pmill\Plesk\CreateSite($config, array( 215 | 'domain' => $data['domain'], 216 | 'subscription_id' => $data['subscription_id'], 217 | )); 218 | $info = $request->process(); 219 | $data['site_id'] = $request->id; 220 | echo "Site created: " . $data['domain'] . PHP_EOL; 221 | 222 | 223 | /* 224 | * 10. Find created site (ListSite) 225 | */ 226 | 227 | $request = new \pmill\Plesk\ListSites($config, array( 228 | 'subscription_id' => $data['subscription_id'], 229 | )); 230 | $sites = $request->process(); 231 | 232 | $site_found = false; 233 | foreach ($sites as $site) { 234 | if ($site['id'] == $data['site_id']) { 235 | $site_found = true; 236 | } 237 | } 238 | 239 | if (!$site_found) { 240 | throw new Exception("Couldn't find created site"); 241 | } 242 | 243 | echo "Site found: " . $data['domain'] . PHP_EOL; 244 | 245 | 246 | /* 247 | * 11. Update site information (UpdateSite) 248 | */ 249 | 250 | $data['domain'] = random_string() . '.com'; 251 | $request = new \pmill\Plesk\UpdateSite($config, array( 252 | 'id' => $data['site_id'], 253 | 'domain' => $data['domain'], 254 | )); 255 | $info = $request->process(); 256 | echo "Site updated: " . $data['domain'] . PHP_EOL; 257 | } 258 | 259 | if ($runSiteTests && $runEmailAddressTests) { 260 | /* 261 | * 12. Create email address (CreateEmailAddress) 262 | */ 263 | 264 | $data['email_address'] = random_string(4) . '@' . $data['domain']; 265 | $request = new \pmill\Plesk\CreateEmailAddress($config, array( 266 | 'email' => $data['email_address'], 267 | 'password' => random_string() . "1!", 268 | )); 269 | $info = $request->process(); 270 | $data['email_address_id'] = $request->id; 271 | echo "Email address created: " . $data['email_address'] . PHP_EOL; 272 | 273 | /* 274 | * 13. List email addresses (ListEmailAddresses) 275 | */ 276 | $request = new \pmill\Plesk\ListEmailAddresses($config, array( 277 | 'site_id' => $data['site_id'], 278 | )); 279 | $email_addresses = $request->process(); 280 | 281 | $email_address_found = false; 282 | foreach ($email_addresses as $email_address) { 283 | if ($email_address['id'] == $data['email_address_id']) { 284 | $email_address_found = true; 285 | } 286 | } 287 | 288 | if (!$email_address_found) { 289 | throw new Exception("Couldn't find created email address (" . $data['email_address_id'] . ")"); 290 | } 291 | 292 | echo "Email address found: " . $data['email_address'] . PHP_EOL; 293 | 294 | 295 | /* 296 | * 14. Update email address (UpdateEmailAddress) 297 | */ 298 | 299 | $request = new \pmill\Plesk\UpdateEmailPassword($config, array( 300 | 'email' => $data['email_address'], 301 | 'password' => random_string(), 302 | )); 303 | $info = $request->process(); 304 | echo "Email address password changed: " . $data['email_address'] . PHP_EOL; 305 | 306 | 307 | /* 308 | * 15. Delete email address (DeleteEmailAddress) 309 | */ 310 | 311 | $request = new \pmill\Plesk\DeleteEmailAddress($config, array( 312 | 'email' => $data['email_address'], 313 | )); 314 | $info = $request->process(); 315 | echo "Email address deleted: " . $data['email_address'] . PHP_EOL; 316 | } 317 | 318 | if ($runSiteTests && $runSiteAliasTests) { 319 | /* 320 | * 16. Create site alias (CreateSiteAlias) 321 | */ 322 | 323 | $data['site_alias'] = random_string() . '.' . $data['domain']; 324 | $params = array( 325 | 'site_id' => $data['site_id'], 326 | 'alias' => $data['site_alias'], 327 | ); 328 | 329 | $request = new \pmill\Plesk\CreateSiteAlias($config, $params); 330 | $info = $request->process(); 331 | $data['site_alias_id'] = $request->id; 332 | echo "Site alias created: " . $data['site_alias'] . PHP_EOL; 333 | 334 | 335 | /* 336 | * 17. List site aliases (ListSiteAliases) 337 | */ 338 | 339 | $request = new \pmill\Plesk\ListSiteAliases($config, array( 340 | 'site_id' => $data['site_id'], 341 | )); 342 | $aliases = $request->process(); 343 | 344 | $alias_found = false; 345 | foreach ($aliases as $alias_id => $alias_name) { 346 | if ($alias_id == $data['site_alias_id']) { 347 | $alias_found = true; 348 | } 349 | } 350 | 351 | if (!$alias_found) { 352 | throw new Exception("Couldn't find created site alias"); 353 | } 354 | 355 | echo "Site alias found: " . $data['site_alias'] . PHP_EOL; 356 | 357 | /* 358 | * 18. Delete site alias (DeleteEmailAddress) 359 | */ 360 | 361 | $request = new \pmill\Plesk\DeleteSiteAlias($config, array( 362 | 'id' => $data['site_alias_id'], 363 | )); 364 | $info = $request->process(); 365 | echo "Site alias deleted: " . $data['site_alias'] . PHP_EOL; 366 | } 367 | 368 | if ($runSiteTests && $runSubdomainTests) { 369 | /* 370 | * 19. Create subdomain (CreateSubdomain) 371 | */ 372 | 373 | $data['subdomain'] = random_string(); 374 | $request = new \pmill\Plesk\CreateSubdomain($config, array( 375 | 'domain' => $data['domain'], 376 | 'subdomain' => $data['subdomain'], 377 | 'www_root' => '/subdomains/' . strtolower($data['subdomain']), 378 | 'fpt_username' => random_string(), 379 | 'fpt_password' => random_string(), 380 | )); 381 | $info = $request->process(); 382 | $data['subdomain_id'] = $request->id; 383 | echo "Subdomain created: " . $data['subdomain'] . PHP_EOL; 384 | 385 | 386 | /* 387 | * 20. List subdomains (ListSubdomains) 388 | */ 389 | 390 | $request = new \pmill\Plesk\ListSubdomains($config, array( 391 | 'site_id' => $data['site_id'], 392 | )); 393 | $subdomains = $request->process(); 394 | 395 | $subdomain_found = false; 396 | foreach ($subdomains as $subdomain) { 397 | if ($subdomain['id'] == $data['subdomain_id']) { 398 | $subdomain_found = true; 399 | } 400 | } 401 | 402 | if (!$subdomain_found) { 403 | throw new Exception("Couldn't find created subdomain"); 404 | } 405 | 406 | echo "Subdomain found: " . $data['subdomain'] . PHP_EOL; 407 | 408 | 409 | /* 410 | * 21. Update subdomain(UpdateSubdomain) 411 | */ 412 | 413 | $request = new \pmill\Plesk\UpdateSubdomain($config, array( 414 | 'id' => $data['subdomain_id'], 415 | 'www_root' => '/subdomains/' . strtolower($data['subdomain']) . '2', 416 | )); 417 | $info = $request->process(); 418 | echo "Subdomain updated: " . $data['subdomain'] . PHP_EOL; 419 | 420 | 421 | /* 422 | * 22. Rename subdomain(RenameSubdomain) 423 | */ 424 | 425 | $data['subdomain'] = random_string(); 426 | $request = new \pmill\Plesk\RenameSubdomain($config, array( 427 | 'id' => $data['subdomain_id'], 428 | 'name' => $data['subdomain'], 429 | )); 430 | $info = $request->process(); 431 | echo "Subdomain renamed: " . $data['subdomain'] . PHP_EOL; 432 | 433 | 434 | /* 435 | * 23. Delete subdomain(DeleteSubdomain) 436 | */ 437 | 438 | $request = new \pmill\Plesk\DeleteSubdomain($config, array( 439 | 'id' => $data['subdomain_id'], 440 | )); 441 | $info = $request->process(); 442 | echo "Subdomain deleted: " . $data['subdomain'] . PHP_EOL; 443 | } 444 | 445 | if ($runDatabaseTests) { 446 | /* 447 | * 24. List database servers (ListDatabaseServers) 448 | */ 449 | 450 | $request = new \pmill\Plesk\ListDatabaseServers($config); 451 | $servers = $request->process(); 452 | 453 | $server_found = false; 454 | foreach ($servers as $server) { 455 | if ($server['type'] == 'mysql') { 456 | $data['db_server_id'] = $server['id']; 457 | $server_found = true; 458 | } 459 | } 460 | 461 | if (!$server_found) { 462 | throw new Exception("Couldn't find mysql database server"); 463 | } 464 | 465 | echo "Database server found: " . $data['db_server_id'] . PHP_EOL; 466 | 467 | 468 | /* 469 | * 25. Create database (CreateDatabase) 470 | */ 471 | 472 | $request = new \pmill\Plesk\CreateDatabase($config, array( 473 | 'name' => random_string(), 474 | 'subscription_id' => $data['subscription_id'], 475 | 'server_id' => $data['db_server_id'], 476 | 'type' => 'mysql', 477 | )); 478 | $info = $request->process(); 479 | $data['db_id'] = $request->id; 480 | 481 | echo "Database created: " . $data['db_id'] . PHP_EOL; 482 | 483 | 484 | /* 485 | * 26. List databases (ListDatabases) 486 | */ 487 | 488 | $request = new \pmill\Plesk\ListDatabases($config, array( 489 | 'subscription_id' => $data['subscription_id'], 490 | )); 491 | $databases = $request->process(); 492 | 493 | $database_found = false; 494 | foreach ($databases as $database) { 495 | if ($database['id'] == $data['db_id']) { 496 | $database_found = true; 497 | } 498 | } 499 | 500 | if (!$database_found) { 501 | throw new Exception("Couldn't find created database"); 502 | } 503 | 504 | echo "Database found: " . $data['db_id'] . PHP_EOL; 505 | 506 | 507 | /* 508 | * 27. Create database user (CreateDatabaseUser) 509 | */ 510 | 511 | $data['db_user_username'] = random_string(); 512 | $request = new \pmill\Plesk\CreateDatabaseUser($config, array( 513 | 'database_id' => $data['db_id'], 514 | 'username' => $data['db_user_username'], 515 | 'password' => random_string(), 516 | )); 517 | $info = $request->process(); 518 | $data['db_user_id'] = $request->id; 519 | 520 | echo "Database user created: " . $data['db_user_id'] . PHP_EOL; 521 | 522 | 523 | /* 524 | * 28. Get database user info (GetDatabaseUser) 525 | */ 526 | 527 | $request = new \pmill\Plesk\GetDatabaseUser($config, array( 528 | 'database_id' => $data['db_id'], 529 | )); 530 | $info = $request->process(); 531 | 532 | if ($data['db_user_id'] != $request->id) { 533 | throw new Exception("Created database user doesn't match retrieved database user"); 534 | } 535 | 536 | echo "Database user found: " . $data['db_user_id'] . PHP_EOL; 537 | 538 | 539 | /* 540 | * 29. Delete database (DeleteDatabase) 541 | */ 542 | 543 | /*$request = new \pmill\Plesk\DeleteDatabase($config, array( 544 | 'id'=>$data['db_id'], 545 | )); 546 | $info = $request->process(); 547 | echo "Database deleted: ".$data['db_id'].PHP_EOL;*/ 548 | } 549 | 550 | if ($runSiteTests) { 551 | /* 552 | * 30. Delete site (DeleteSite) 553 | */ 554 | 555 | $request = new \pmill\Plesk\DeleteSite($config, array( 556 | 'id' => $data['site_id'], 557 | )); 558 | $info = $request->process(); 559 | echo "Site deleted: " . $data['domain'] . PHP_EOL; 560 | } 561 | 562 | /* 563 | * 31. Deletes previously created subscription (DeleteSubscription) 564 | */ 565 | 566 | $request = new \pmill\Plesk\DeleteSubscription($config, array( 567 | 'id' => $data['subscription_id'], 568 | )); 569 | $info = $request->process(); 570 | echo "Subscription deleted: " . $data['subscription_id'] . PHP_EOL; 571 | 572 | /** 573 | * 32. Creates a secret key 574 | */ 575 | 576 | $request = new \pmill\Plesk\CreateSecretKey($config, [ 577 | 'ip_address' => file_get_contents('https://api.ipify.org'), 578 | ]); 579 | $info = $request->process(); 580 | $data['secret_key'] = $request->key; 581 | echo "Secret Key created: " . $request->key . PHP_EOL; 582 | 583 | /** 584 | * 33. Lists secret keys (login with secret key) 585 | */ 586 | 587 | $request = new \pmill\Plesk\ListSecretKeys(['key' => $data['secret_key'], 'host' => $config['host']]); 588 | $keys = $request->process(); 589 | 590 | $secret_key_found = false; 591 | foreach ($keys as $key) { 592 | if ($key['key'] == $data['secret_key']) { 593 | $secret_key_found = true; 594 | } 595 | } 596 | 597 | if (!$secret_key_found) { 598 | throw new Exception("Couldn't find created secret_key"); 599 | } 600 | 601 | /** 602 | * 34. Delete secret key 603 | */ 604 | 605 | $request = new \pmill\Plesk\DeleteSecretKey($config, [ 606 | 'key' => $data['secret_key'], 607 | ]); 608 | $request->process(); 609 | 610 | $request = new \pmill\Plesk\ListSecretKeys($config); 611 | $keys = $request->process(); 612 | 613 | $secret_key_found = false; 614 | foreach ($keys as $key) { 615 | if ($key['key'] == $data['secret_key']) { 616 | $secret_key_found = true; 617 | } 618 | } 619 | 620 | if ($secret_key_found) { 621 | throw new Exception("Failed to delete secret_key"); 622 | } 623 | 624 | } catch (Exception $e) { 625 | throw $e; 626 | } finally { 627 | /* 628 | * 32. Deletes previously created client (DeleteClient) 629 | */ 630 | 631 | $request = new \pmill\Plesk\DeleteClient($config, array( 632 | 'id' => $data['client_id'], 633 | )); 634 | $request->process(); 635 | echo "Client deleted: " . $data['client_id'] . PHP_EOL; 636 | } 637 | --------------------------------------------------------------------------------