-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmod_servicehosting_server.html.twig
226 lines (201 loc) · 10.4 KB
/
mod_servicehosting_server.html.twig
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
{% extends 'layout_default.html.twig' %}
{% block meta_title %}{{ 'Hosting management'|trans }}{% endblock %}
{% set active_menu = 'system' %}
{% block breadcrumbs %}
<ul class="breadcrumb">
<li class="breadcrumb-item">
<a href="{{ '/'|alink }}">
<svg class="icon">
<use xlink:href="#home" />
</svg>
</a>
</li>
<li class="breadcrumb-item">
<a href="{{ 'Servicesaas'|alink }}">{{ 'Hosting plans and servers'|trans }}</a>
</li>
<li class="breadcrumb-item active" aria-current="page">{{ server.name }}</li>
</ul>
{% endblock %}
{% block content %}
<div class="card">
<div class="card-body">
<h3>{{ 'Server management'|trans }}</h3>
<form method="post" action="{{ 'api/admin/Servicesaas/server_update'|link }}" id="server-update" class="api-form" data-api-msg="{{ 'Server updated'|trans }}">
<input type="hidden" name="CSRFToken" value="{{ CSRFToken }}"/>
<div class="mb-3 row">
<label class="form-label col-3 col-form-label">{{ 'Name'|trans }}:</label>
<div class="col">
<input class="form-control" type="text" name="name" value="{{ server.name }}" required placeholder="{{ 'Unique name to identify this server'|trans }}">
</div>
</div>
<div class="mb-3 row">
<label class="form-label col-3 col-form-label">{{ 'Hostname'|trans }}:</label>
<div class="col">
<input class="form-control" type="text" name="hostname" value="{{ server.hostname }}" placeholder="host1.domain.com">
</div>
</div>
<div class="mb-3 row">
<label class="form-label col-3 col-form-label">{{ 'IP'|trans }}:</label>
<div class="col">
<input class="form-control" type="text" name="ip" value="{{ server.ip }}" required placeholder="{{ 'Primary IP address of the server used to connect to it like: 127.0.0.1'|trans }}">
</div>
</div>
{# <div class="mb-3 row">
<label>{{ 'Assigned IP Addresses'|trans }}:</label>
<div class="col">
<textarea name="assigned_ips" rows="5" placeholder="List the IP Addresses assigned to the server (One per line)">{% for v in server.assigned_ips %}{{ v }}{{constant("PHP_EOL")}}{% endfor %}</textarea>
</div>
</div> #}
<div class="mb-3 row">
<label class="form-label col-3 col-form-label">{{ 'Enable/Disable'|trans }}:</label>
<div class="col">
<div class="form-check form-check-inline">
<input class="form-check-input" id="radioActiveYes" type="radio" name="active" value="1"{% if server.active %} checked{% endif %}>
<label class="form-check-label" for="radioActiveYes">{{ 'Yes'|trans }}</label>
</div>
<div class="form-check form-check-inline">
<input class="form-check-input" id="radioActiveNo" type="radio" name="active" value="0"{% if not server.active %} checked{% endif %}>
<label class="form-check-label" for="radioActiveNo">{{ 'No'|trans }}</label>
</div>
</div>
</div>
<hr>
<h5>{{ 'Server manager'|trans }}</h5>
<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" onchange="handleManagerChange(this)">
{% for code, manager in admin.Servicesaas_manager_get_pairs %}
<option value="{{ code }}"{% if server.manager == code %} selected{% endif %}>{{ manager.label }}</option>
{% endfor %}
</select>
</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 the API'|trans }}">
</div>
</div>
<div class="mb-3 row">
<label class="form-label col-3 col-form-label">{{ 'Use Secure connection'|trans }}:</label>
<div class="col">
<div class="form-check form-check-inline">
<input class="form-check-input" id="radioSecureConnectionYes" type="radio" name="secure" value="1"{% if server.secure %} checked{% endif %}>
<label class="form-check-label" for="radioSecureConnectionYes">{{ 'Yes'|trans }}</label>
</div>
<div class="form-check form-check-inline">
<input class="form-check-input" id="radioSecureConnectionNo" type="radio" name="secure" value="0"{% if not server.secure %} checked{% endif %}>
<label class="form-check-label" for="radioSecureConnectionNo">{{ 'No'|trans }}</label>
</div>
</div>
</div>
<input class="btn btn-primary w-100" id="test-connection" type="button" value="{{ 'Update and test connection'|trans }}">
<h5>{{ 'Nameservers'|trans }}</h5>
<div class="mb-3 row">
<label class="form-label col-3 col-form-label">{{ 'Nameserver 1'|trans }}:</label>
<div class="col">
<input class="form-control" type="text" name="ns1" value="{{ server.ns1 }}" placeholder="ns1.yourdomain.com">
</div>
</div>
<div class="mb-3 row">
<label class="form-label col-3 col-form-label">{{ 'Nameserver 2'|trans }}:</label>
<div class="col">
<input class="form-control" type="text" name="ns2" value="{{ server.ns2 }}" placeholder="ns2.yourdomain.com">
</div>
</div>
<div class="mb-3 row">
<label class="form-label col-3 col-form-label">{{ 'Nameserver 3'|trans }}:</label>
<div class="col">
<input class="form-control" type="text" name="ns3" value="{{ server.ns3 }}" placeholder="ns3.yourdomain.com">
</div>
</div>
<div class="mb-3 row">
<label class="form-label col-3 col-form-label">{{ 'Nameserver 4'|trans }}:</label>
<div class="col">
<input class="form-control" type="text" name="ns4" value="{{ server.ns4 }}" placeholder="ns4.yourdomain.com">
</div>
</div>
<input type="hidden" name="id" value="{{ server.id }}">
<input type="submit" value="{{ 'Update server'|trans }}" class="btn btn-primary w-100">
</form>
</div>
</div>
{% endblock %}
{% block js%}
<script>
$(function() {
$('#test-connection').click(function(){
$('#server-update').submit();
bb.post('admin/Servicesaas/server_test_connection',
{ id: {{ server.id }}, CSRFToken: "{{ CSRFToken }}" },
function(result) {
FOSSBilling.message("{{ 'Successfully connected to server'|trans }}");
}
);
return false;
});
});
function handleManagerChange (select) {
var pairs = {{ admin.Servicesaas_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 %}