mirror of
https://github.com/FOSSBilling/FOSSBilling.git
synced 2026-12-05 06:35:38 +09:00
Merge pull request #544 from FOSSBilling/custom-input
Custom input field support for hosting managers.
This commit is contained in:
6 files changed
+201
-70
No files matched your search
@@ -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');
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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');
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -205,31 +205,14 @@
|
||||
<div class="mb-3 row">
|
||||
<label class="form-label col-3 col-form-label">{{ 'Server manager'|trans }}:</label>
|
||||
<div class="col">
|
||||
<select class="form-select" name="manager">
|
||||
<select class="form-select" name="manager" onchange="handleManagerChange(this)">
|
||||
{% for code, manager in admin.servicehosting_manager_get_pairs %}
|
||||
<option value="{{ code }}">{{ manager.label }}</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<div class="mb-3 row">
|
||||
<label class="form-label col-3 col-form-label">{{ 'Username'|trans }}:</label>
|
||||
<div class="col">
|
||||
<input class="form-control" type="text" name="username" value="" placeholder="{{ 'Login username to your server: root/reseller'|trans }}">
|
||||
</div>
|
||||
</div>
|
||||
<div class="mb-3 row">
|
||||
<label class="form-label col-3 col-form-label">{{ 'Password'|trans }}:</label>
|
||||
<div class="col">
|
||||
<input class="form-control" type="password" name="password" value="" placeholder="{{ 'Login password to your server'|trans }}">
|
||||
</div>
|
||||
</div>
|
||||
<div class="mb-3 row">
|
||||
<label class="form-label col-3 col-form-label">{{ 'Access Hash (Instead of password for cPanel servers)'|trans }}:</label>
|
||||
<div class="col">
|
||||
<textarea class="form-control" name="accesshash" rows="5"></textarea>
|
||||
</div>
|
||||
</div>
|
||||
<div id="credentials"></div>
|
||||
<div class="mb-3 row">
|
||||
<label class="form-label col-3 col-form-label">{{ 'Use Secure connection'|trans }}:</label>
|
||||
<div class="col">
|
||||
@@ -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"]'));
|
||||
};
|
||||
</script>
|
||||
{% endblock %}
|
||||
{% endblock %}
|
||||
@@ -70,37 +70,20 @@
|
||||
<div class="mb-3 row">
|
||||
<label class="form-label col-3 col-form-label">{{ 'Server manager'|trans }}:</label>
|
||||
<div class="col">
|
||||
<select class="form-select" name="manager">
|
||||
<select class="form-select" name="manager" onchange="handleManagerChange(this)">
|
||||
{% for code, manager in admin.servicehosting_manager_get_pairs %}
|
||||
<option value="{{ code }}"{% if server.manager == code %} selected{% endif %}>{{ manager.label }}</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<div class="mb-3 row">
|
||||
<label class="form-label col-3 col-form-label">{{ 'Username'|trans }}:</label>
|
||||
<div class="col">
|
||||
<input class="form-control" type="text" name="username" value="{{ server.username }}" placeholder="{{ 'Login username to your server: root/reseller'|trans }}">
|
||||
</div>
|
||||
</div>
|
||||
<div class="mb-3 row">
|
||||
<label class="form-label col-3 col-form-label">{{ 'Password'|trans }}:</label>
|
||||
<div class="col">
|
||||
<input class="form-control" type="password" name="password" value="{{ server.password }}" placeholder="{{ 'Login password to your server'|trans }}">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="mb-3 row">
|
||||
<label class="form-label col-3 col-form-label">{{ 'Access Hash (Instead of password for cPanel servers)'|trans }}:</label>
|
||||
<div class="col">
|
||||
<textarea class="form-control" name="accesshash" rows="5">{{ server.accesshash }}</textarea>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="credentials"></div>
|
||||
|
||||
<div class="mb-3 row">
|
||||
<label class="form-label col-3 col-form-label">{{ 'Connection port'|trans }}:</label>
|
||||
<div class="col">
|
||||
<input class="form-control" type="text" name="port" value="{{ server.port }}" placeholder="{{ 'Custom port. Use blank to use default. Used to connect to API'|trans }}">
|
||||
<input class="form-control" type="text" name="port" value="{{ server.port }}" placeholder="{{ 'Custom port. Use blank to use default. Used to connect to the API'|trans }}">
|
||||
</div>
|
||||
</div>
|
||||
<div class="mb-3 row">
|
||||
@@ -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"]'));
|
||||
};
|
||||
</script>
|
||||
{% endblock %}
|
||||
{% endblock %}
|
||||
Reference in new issue
Block a user