diff --git a/src/library/Server/Manager/Hestia.php b/src/library/Server/Manager/Hestia.php
index c0ae31f79..6dff05eeb 100644
--- a/src/library/Server/Manager/Hestia.php
+++ b/src/library/Server/Manager/Hestia.php
@@ -27,11 +27,7 @@ class Server_Manager_Hestia extends Server_Manager
public function _getPort()
{
- if ($this->_config['port']) {
- return $this->_config['port'];
- } else {
- return '8083';
- }
+ return is_numeric($this->_config['port']) ? $this->_config['port'] : '8083';
}
/**
@@ -42,7 +38,27 @@ class Server_Manager_Hestia extends Server_Manager
public static function getForm()
{
return [
- 'label' => 'Hestia',
+ 'label' => 'Hestia Control Panel',
+ 'form' => [
+ 'credentials' => [
+ 'fields' => [
+ [
+ 'name' => 'username',
+ 'type' => 'text',
+ 'label' => 'Access key ID',
+ 'placeholder' => 'ID for the access key you\'ve generated in Hestia.',
+ 'required' => true,
+ ],
+ [
+ 'name' => 'accesshash',
+ 'type' => 'text',
+ 'label' => 'Secret key',
+ 'placeholder' => 'Secret key for the access key you\'ve generated in Hestia',
+ 'required' => true,
+ ],
+ ],
+ ],
+ ]
];
}
@@ -53,9 +69,7 @@ class Server_Manager_Hestia extends Server_Manager
*/
public function getLoginUrl()
{
- $host = 'https://'.$this->_config['host'].':'.$this->_getPort().'/';
-
- return $host;
+ return 'https://'.$this->_config['host'].':'.$this->_getPort().'/';
}
/**
@@ -65,7 +79,7 @@ class Server_Manager_Hestia extends Server_Manager
*/
public function getResellerLoginUrl()
{
- return 'https://hestiacp.com';
+ return $this->getLoginUrl();
}
private function _makeRequest($params)
@@ -361,4 +375,4 @@ class Server_Manager_Hestia extends Server_Manager
{
throw new Server_Exception('Server Manager Hestia CP Error: Not Supported');
}
-}
+}
\ No newline at end of file
diff --git a/src/library/Server/Manager/Plesk.php b/src/library/Server/Manager/Plesk.php
index 03197bae2..3dbdf9659 100644
--- a/src/library/Server/Manager/Plesk.php
+++ b/src/library/Server/Manager/Plesk.php
@@ -22,9 +22,9 @@ class Server_Manager_Plesk extends Server_Manager
public static function getForm()
{
- return array(
+ return [
'label' => 'Plesk',
- );
+ ];
}
public function getLoginUrl()
@@ -516,4 +516,4 @@ class Server_Manager_Plesk extends Server_Manager
return $props;
}
-}
+}
\ No newline at end of file
diff --git a/src/library/Server/Manager/Vesta.php b/src/library/Server/Manager/Vesta.php
index 499993109..2cc18fdcd 100644
--- a/src/library/Server/Manager/Vesta.php
+++ b/src/library/Server/Manager/Vesta.php
@@ -27,11 +27,7 @@ class Server_Manager_Vesta extends Server_Manager
public function _getPort()
{
- if (is_numeric($this->_config['port'])) {
- return $this->_config['port'];
- } else {
- return '8083';
- }
+ return is_numeric($this->_config['port']) ? $this->_config['port'] : '8083';
}
/**
@@ -53,9 +49,7 @@ class Server_Manager_Vesta extends Server_Manager
*/
public function getLoginUrl()
{
- $host = 'https://'.$this->_config['host'].':'.$this->_getPort().'/';
-
- return $host;
+ return 'https://'.$this->_config['host'].':'.$this->_getPort().'/';
}
/**
@@ -65,7 +59,7 @@ class Server_Manager_Vesta extends Server_Manager
*/
public function getResellerLoginUrl()
{
- return 'https://vestacp.com';
+ return $this->getLoginUrl();
}
private function _makeRequest($params)
@@ -369,4 +363,4 @@ class Server_Manager_Vesta extends Server_Manager
{
throw new Server_Exception('Server Manager Vesta CP Error: Not Supported');
}
-}
+}
\ No newline at end of file
diff --git a/src/library/Server/Manager/Whm.php b/src/library/Server/Manager/Whm.php
index 02da9d5e7..ef106830f 100644
--- a/src/library/Server/Manager/Whm.php
+++ b/src/library/Server/Manager/Whm.php
@@ -77,7 +77,27 @@ class Server_Manager_Whm extends Server_Manager
public static function getForm()
{
return array(
- 'label' => 'cPanel WHM',
+ 'label' => 'WHM (cPanel)',
+ 'form' => [
+ 'credentials' => [
+ 'fields' => [
+ [
+ 'name' => 'username',
+ 'type' => 'text',
+ 'label' => 'Username',
+ 'placeholder' => 'Username to connect to the server',
+ 'required' => true,
+ ],
+ [
+ 'name' => 'accesshash',
+ 'type' => 'text',
+ 'label' => 'Access hash',
+ 'placeholder' => 'Access hash to connect to the server',
+ 'required' => true,
+ ],
+ ],
+ ],
+ ]
);
}
@@ -2683,7 +2703,5 @@ class xmlapi {
$values['display'] = substr($args, 0, -1);
}
return $this->api2_query($username, 'StatsBar', 'stat', $values);
- }
-
-
+ }
}
\ No newline at end of file
diff --git a/src/modules/Servicehosting/html_admin/mod_servicehosting_index.html.twig b/src/modules/Servicehosting/html_admin/mod_servicehosting_index.html.twig
index f68f0504d..4d6db8cce 100644
--- a/src/modules/Servicehosting/html_admin/mod_servicehosting_index.html.twig
+++ b/src/modules/Servicehosting/html_admin/mod_servicehosting_index.html.twig
@@ -205,31 +205,14 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
@@ -287,5 +270,72 @@
function onAfterHostingPlanCreate(id) {
bb.redirect("{{ 'servicehosting/plan'|alink }}/" + id);
}
+
+ function handleManagerChange (select) {
+ var pairs = {{ admin.servicehosting_manager_get_pairs|json_encode|raw }} // PHP array returned by the server manager converted to a JavaScript object
+ var defaults = {
+ form: {
+ credentials: {
+ fields: [
+ {
+ name: 'username',
+ label: 'Username',
+ type: 'text',
+ placeholder: 'Username to connect to the server',
+ required: true
+ },
+ {
+ name: 'password',
+ label: 'Password',
+ type: 'password',
+ placeholder: 'Password to connect to the server',
+ required: true
+ }
+ ],
+ },
+ },
+ } // Default form fields. If server manager does not provide any, use these.
+
+ var credentials = document.getElementById('credentials'); // HTML element where the form fields will be inserted.
+ var manager = select.value; // Selected server manager code.
+
+ credentials.innerHTML = ''; // Clear the form fields.
+
+ if (pairs[manager].form && pairs[manager].form.credentials && pairs[manager].form.credentials.fields) {
+ var data = pairs[manager].form.credentials.fields;
+ } else {
+ var data = defaults.form.credentials.fields;
+ }
+
+ for (var i = 0; i < data.length; i++) {
+ // Create a new form field and append it to the credentials element.
+ var field = data[i];
+ var div = document.createElement('div');
+ div.className = 'mb-3 row';
+
+ var label = document.createElement('label');
+ label.className = 'form-label col-3 col-form-label';
+ label.innerHTML = field.label + ':';
+ div.appendChild(label);
+
+ var input = document.createElement('input');
+ input.className = 'form-control';
+ input.type = field.type;
+ input.name = field.name;
+ input.placeholder = field.placeholder;
+ input.required = field.required;
+
+ var col = document.createElement('div');
+ col.className = 'col';
+ col.appendChild(input);
+ div.appendChild(col);
+
+ credentials.appendChild(div);
+ }
+ }
+
+ window.onload = function () {
+ handleManagerChange(document.querySelector('select[name="manager"]'));
+ };
-{% endblock %}
+{% endblock %}
\ No newline at end of file
diff --git a/src/modules/Servicehosting/html_admin/mod_servicehosting_server.html.twig b/src/modules/Servicehosting/html_admin/mod_servicehosting_server.html.twig
index 52e285438..67fa6a73b 100644
--- a/src/modules/Servicehosting/html_admin/mod_servicehosting_server.html.twig
+++ b/src/modules/Servicehosting/html_admin/mod_servicehosting_server.html.twig
@@ -70,37 +70,20 @@
-
+
{% for code, manager in admin.servicehosting_manager_get_pairs %}
{% endfor %}
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
-
+
@@ -167,5 +150,77 @@
return false;
});
});
+
+ function handleManagerChange (select) {
+ var pairs = {{ admin.servicehosting_manager_get_pairs|json_encode|raw }} // PHP array returned by the server manager converted to a JavaScript object
+ var defaults = {
+ form: {
+ credentials: {
+ fields: [
+ {
+ name: 'username',
+ label: 'Username',
+ type: 'text',
+ placeholder: 'Username to connect to the server',
+ required: true
+ },
+ {
+ name: 'password',
+ label: 'Password',
+ type: 'password',
+ placeholder: 'Password to connect to the server',
+ required: true
+ }
+ ],
+ },
+ },
+ } // Default form fields. If server manager does not provide any, use these.
+
+ var values = {{ server|json_encode|raw }}; // Server data returned by the server manager converted to a JavaScript object
+
+ var credentials = document.getElementById('credentials'); // HTML element where the form fields will be inserted.
+ var manager = select.value; // Selected server manager code.
+
+ credentials.innerHTML = ''; // Clear the form fields.
+
+ console.log(values);
+
+ if (pairs[manager].form && pairs[manager].form.credentials && pairs[manager].form.credentials.fields) {
+ var data = pairs[manager].form.credentials.fields;
+ } else {
+ var data = defaults.form.credentials.fields;
+ }
+
+ for (var i = 0; i < data.length; i++) {
+ // Create a new form field and append it to the credentials element.
+ var field = data[i];
+ var div = document.createElement('div');
+ div.className = 'mb-3 row';
+
+ var label = document.createElement('label');
+ label.className = 'form-label col-3 col-form-label';
+ label.innerHTML = field.label + ':';
+ div.appendChild(label);
+
+ var input = document.createElement('input');
+ input.className = 'form-control';
+ input.type = field.type;
+ input.name = field.name;
+ input.value = values[field.name];
+ input.placeholder = field.placeholder;
+ input.required = field.required;
+
+ var col = document.createElement('div');
+ col.className = 'col';
+ col.appendChild(input);
+ div.appendChild(col);
+
+ credentials.appendChild(div);
+ }
+ }
+
+ window.onload = function () {
+ handleManagerChange(document.querySelector('select[name="manager"]'));
+ };
-{% endblock %}
+{% endblock %}
\ No newline at end of file