diff --git a/src/library/Server/Manager.php b/src/library/Server/Manager.php index ee1bc989e..d374c5cab 100644 --- a/src/library/Server/Manager.php +++ b/src/library/Server/Manager.php @@ -150,16 +150,20 @@ abstract class Server_Manager /** * Returns the login URL for the server. (ex: panel.example.com) * + * @param null|Server_Account $account Either the related `Server_Account` which can be used to generate an SSO link or `null`. + * * @return string */ - abstract public function getLoginUrl(); + abstract public function getLoginUrl(?Server_Account $account); /** * Returns the login URL for the server for reseller accounts. * + * @param null|Server_Account $account Either the related `Server_Account` which can be used to generate an SSO link or `null`. + * * @return string */ - abstract public function getResellerLoginUrl(); + abstract public function getResellerLoginUrl(?Server_Account $account); /** * Used to test the connection to the server and verify the server configuration is correct. diff --git a/src/library/Server/Manager/CWP.php b/src/library/Server/Manager/CWP.php index c91052a4a..ef7f1662a 100644 --- a/src/library/Server/Manager/CWP.php +++ b/src/library/Server/Manager/CWP.php @@ -58,13 +58,13 @@ class Server_Manager_CWP extends Server_Manager /** * We can actually generate a direct log-in link from CWP, but I'm not sure if that's a secure thing to do here. */ - public function getLoginUrl() + public function getLoginUrl(?Server_Account $account = null) { $host = $this->_config['host']; return 'https://' . $host . ':2083'; } - public function getResellerLoginUrl() + public function getResellerLoginUrl(?Server_Account $account = null) { $host = $this->_config['host']; return 'https://' . $host . ':2031'; diff --git a/src/library/Server/Manager/Custom.php b/src/library/Server/Manager/Custom.php index 184a358f7..0fbf4b4fd 100644 --- a/src/library/Server/Manager/Custom.php +++ b/src/library/Server/Manager/Custom.php @@ -35,7 +35,7 @@ class Server_Manager_Custom extends Server_Manager * * @return string */ - public function getLoginUrl() + public function getLoginUrl(?Server_Account $account = null) { return 'http://www.google.com?q=cpanel'; } @@ -44,7 +44,7 @@ class Server_Manager_Custom extends Server_Manager * Returns link to reseller account management * @return string */ - public function getResellerLoginUrl() + public function getResellerLoginUrl(?Server_Account $account = null) { return 'http://www.google.com?q=whm'; } diff --git a/src/library/Server/Manager/Directadmin.php b/src/library/Server/Manager/Directadmin.php index 9377e3067..04c65c1eb 100644 --- a/src/library/Server/Manager/Directadmin.php +++ b/src/library/Server/Manager/Directadmin.php @@ -57,13 +57,13 @@ class Server_Manager_Directadmin extends Server_Manager return is_numeric($this->_config['port']) ? $this->_config['port'] : '2222'; } - public function getLoginUrl() : string + public function getLoginUrl(?Server_Account $account = null): string { $protocol = $this->_config['secure'] ? 'https://' : 'http://'; return $protocol . $this->_config['host'] . ':'. $this -> _getPort(); } - public function getResellerLoginUrl() + public function getResellerLoginUrl(?Server_Account $account = null) { return $this->getLoginUrl(); } diff --git a/src/library/Server/Manager/Hestia.php b/src/library/Server/Manager/Hestia.php index fe66da132..16d213f2c 100644 --- a/src/library/Server/Manager/Hestia.php +++ b/src/library/Server/Manager/Hestia.php @@ -58,7 +58,7 @@ class Server_Manager_Hestia extends Server_Manager * * @return string */ - public function getLoginUrl() + public function getLoginUrl(?Server_Account $account = null) { return 'https://' . $this->_config['host'] . ':' . $this->_getPort() . '/'; } @@ -68,7 +68,7 @@ class Server_Manager_Hestia extends Server_Manager * * @return string */ - public function getResellerLoginUrl() + public function getResellerLoginUrl(?Server_Account $account = null) { return $this->getLoginUrl(); } diff --git a/src/library/Server/Manager/Plesk.php b/src/library/Server/Manager/Plesk.php index 5e8088560..b1b1c2745 100644 --- a/src/library/Server/Manager/Plesk.php +++ b/src/library/Server/Manager/Plesk.php @@ -8,8 +8,6 @@ * @license http://www.apache.org/licenses/LICENSE-2.0 Apache-2.0 */ -use PleskX\Api\Client; - class Server_Manager_Plesk extends Server_Manager { private ?\PleskX\Api\Client $_client = null; @@ -28,13 +26,18 @@ class Server_Manager_Plesk extends Server_Manager ]; } - public function getLoginUrl() - { + public function getLoginUrl(?Server_Account $account = null): string + { $protocol = $this->_config['secure'] ? 'https' : 'http'; - return $protocol . "://" . $this->_config['host'] . ':' . $this->_config['port']; - } + $url = $protocol . "://" . $this->_config['host'] . ':' . $this->_config['port']; + if ($account) { + $sessionId = $this->_client->session()->create($account->getUsername(), $_SERVER['REMOTE_ADDR']); + $url .= '/enterprise/rsession_init.php?PHPSESSID=' . $sessionId; + } + return $url; + } - public function getResellerLoginUrl() + public function getResellerLoginUrl(?Server_Account $account = null) { return $this->getLoginUrl(); } diff --git a/src/library/Server/Manager/Whm.php b/src/library/Server/Manager/Whm.php index 1f1e78dc2..9045a6679 100644 --- a/src/library/Server/Manager/Whm.php +++ b/src/library/Server/Manager/Whm.php @@ -34,13 +34,13 @@ class Server_Manager_Whm extends Server_Manager $this->_config['port'] = empty($this->_config['port']) ? '2087' : $this->_config['port']; } - public function getLoginUrl() + public function getLoginUrl(?Server_Account $account = null) { $host = $this->_config['host']; return 'http://'.$host.'/cpanel'; } - public function getResellerLoginUrl() + public function getResellerLoginUrl(?Server_Account $account = null) { $host = $this->_config['host']; return 'http://'.$host.'/whm'; diff --git a/src/modules/Client/html_admin/mod_client_manage.html.twig b/src/modules/Client/html_admin/mod_client_manage.html.twig index e8dd4be5c..271950108 100644 --- a/src/modules/Client/html_admin/mod_client_manage.html.twig +++ b/src/modules/Client/html_admin/mod_client_manage.html.twig @@ -851,5 +851,5 @@ function onAfterInvoicePrepared(id) { bb.redirect("{{ 'invoice/manage/'|alink }}/" + id); } - + {% endblock %} diff --git a/src/modules/Servicehosting/Api/Client.php b/src/modules/Servicehosting/Api/Client.php index baa599cf4..efac302ba 100644 --- a/src/modules/Servicehosting/Api/Client.php +++ b/src/modules/Servicehosting/Api/Client.php @@ -1,4 +1,5 @@ getService()->getHpPairs(); } + /** + * Returns the login URL for a given order ID. + * If the associated server manager supports SSO, an SSO link will be given. + * Will automatically return either a reseller URL or a standard URL depending on the order config. + * + * @param array $data An array containing the API request data. Should have a key named `order_id` containing the order's ID. + * + * @return string + */ + public function get_login_url(array $data): string + { + [$order, $s] = $this->_getService($data); + return $this->getService()->generateLoginUrl($s); + } + public function _getService($data) { if (!isset($data['order_id'])) { diff --git a/src/modules/Servicehosting/Service.php b/src/modules/Servicehosting/Service.php index 3de62afa6..d41a4787e 100644 --- a/src/modules/Servicehosting/Service.php +++ b/src/modules/Servicehosting/Service.php @@ -923,12 +923,20 @@ class Service implements InjectionAwareInterface return $manager; } + /** + * Returns both the standard and reseller login URLs. + * Will not generate SSO links. + * + * @param \Model_ServiceHostingServer $model + * + * @return string[]|false[] + */ public function getMangerUrls(\Model_ServiceHostingServer $model) { try { $m = $this->getServerManager($model); - return [$m->getLoginUrl(), $m->getResellerLoginUrl()]; + return [$m->getLoginUrl(null), $m->getResellerLoginUrl(null)]; } catch (\Exception $e) { error_log('Error while retrieving cPanel url: ' . $e->getMessage()); } @@ -936,6 +944,24 @@ class Service implements InjectionAwareInterface return [false, false]; } + /** + * Generates either a reseller or standard login link for a given order. + * If the server manager supports SSO, an SSO link will be returned. + * + * @param \Model_ServiceHosting $model + * + * @return string + */ + public function generateLoginUrl(\Model_ServiceHosting $model) + { + [$adapter, $account] = $this->_getAM($model); + if ($model->reseller) { + return $adapter->getResellerLoginUrl($account); + } else { + return $adapter->getLoginUrl($account); + } + } + public function prependOrderConfig(\Model_Product $product, array $data) { [$sld, $tld] = $this->_getDomainTuple($data); diff --git a/src/modules/Servicehosting/html_client/mod_servicehosting_manage.html.twig b/src/modules/Servicehosting/html_client/mod_servicehosting_manage.html.twig index 30b076247..bd4dcddb1 100644 --- a/src/modules/Servicehosting/html_client/mod_servicehosting_manage.html.twig +++ b/src/modules/Servicehosting/html_client/mod_servicehosting_manage.html.twig @@ -74,17 +74,14 @@ {% if service.domain_order_id %} {{ 'Manage domain'|trans }} {% endif %} - {{ 'Jump to cPanel'|trans }} - {% if service.reseller %} - {{ 'Reseller control panel'|trans }} - {% endif %} + {{ 'Login to control panel'|trans }} {# Hosting password #}

{{ 'Change your FTP/cPanel/SSH password.'|trans }}

-
+
@@ -112,7 +109,7 @@ {# Hosting domain #}

{{ 'Change domain'|trans }}

- +
@@ -134,7 +131,7 @@ {# Hosting username #}

{{ 'Change username'|trans }}

- +
@@ -159,44 +156,9 @@ {% block js %} {% endblock %} {% endif %} diff --git a/src/themes/huraga/html/layout_default.html.twig b/src/themes/huraga/html/layout_default.html.twig index 24a64cd5c..4a48c163f 100644 --- a/src/themes/huraga/html/layout_default.html.twig +++ b/src/themes/huraga/html/layout_default.html.twig @@ -107,7 +107,7 @@