summaryrefslogtreecommitdiffstats
path: root/applications/luci-app-rustdesk-server/htdocs/luci-static/resources/view/rustdesk-server/general.js
blob: a78fee7a9250f12a20c8788bd6743ce4ce61bedc (plain)
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
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
'use strict';
'require view';
'require form';
'require fs';
'require ui';
'require uci';
'require rpc';
'require poll';

/*
 * Constants - only frontend-relevant values
 */
const CONSTANTS = {
	// Default ports (used in placeholders)
	HBBS_DEFAULT_PORT: '21116',
	HBBR_DEFAULT_PORT: '21117',

	// Polling interval (seconds)
	POLL_INTERVAL: 3,

	// Colors for status display
	COLORS: {
		SUCCESS: 'green',
		ERROR: 'red',
		MUTED: 'gray',
		INFO: '#888'
	}
};

/*
 * RPC declarations
 */
const callGetStatus = rpc.declare({
	object: 'luci.rustdesk-server',
	method: 'get_status'
});

const callGetPublicKey = rpc.declare({
	object: 'luci.rustdesk-server',
	method: 'get_public_key'
});

const callGetVersion = rpc.declare({
	object: 'luci.rustdesk-server',
	method: 'get_version'
});

const callRegenerateKey = rpc.declare({
	object: 'luci.rustdesk-server',
	method: 'regenerate_key'
});

const callServiceAction = rpc.declare({
	object: 'luci.rustdesk-server',
	method: 'service_action',
	params: ['action']
});

/*
 * Helper functions
 */
function handleAction(action) {
	return fs.exec_direct('/etc/init.d/rustdesk-server', [action]);
}


/**
 * Shell metacharacters regex - prevents command injection
 */
const SHELL_METACHARS = /[;&|$`(){}[\]<>'"\\!]/;

/**
 * Validates a safe string value (no shell metacharacters)
 * Used for URL and path validation
 * @param {string} value - The value to check
 * @returns {boolean|string} True if safe, error message if not
 */
function containsShellMetachars(value) {
	if (SHELL_METACHARS.test(value))
		return _('Invalid characters detected');
	return true;
}

/**
 * Validates a key string (alphanumeric and base64 characters only)
 * @param {string} section_id - The section ID
 * @param {string} value - The key value
 * @returns {boolean|string} True if valid, error message if invalid
 */
function validateKey(section_id, value) {
	if (!value || value.length === 0)
		return true;
	if (/[^A-Za-z0-9+/=]/.test(value))
		return _('Invalid characters.') + ' ' + _('Only alphanumeric and base64 characters (+/=) allowed.');
	return true;
}

/**
 * Validates a URL (must start with http:// or https://)
 * @param {string} section_id - The section ID
 * @param {string} value - The URL value
 * @returns {boolean|string} True if valid, error message if invalid
 */
function validateURL(section_id, value) {
	if (!value || value.length === 0)
		return true;
	const shellCheck = containsShellMetachars(value);
	if (shellCheck !== true)
		return shellCheck;
	if (!/^https?:\/\//.test(value))
		return _('URL must start with http:// or https://');
	return true;
}


/**
 * Creates a status indicator HTML string
 * @param {boolean} isActive - Whether the status is active/good
 * @param {string} activeText - Text to show when active
 * @param {string} inactiveText - Text to show when inactive
 * @param {string} [suffix] - Optional suffix to append
 * @returns {string} HTML string
 */
function createStatusIndicator(isActive, activeText, inactiveText, suffix) {
	const color = isActive ? CONSTANTS.COLORS.SUCCESS : CONSTANTS.COLORS.ERROR;
	const symbol = isActive ? '●' : '○';
	const text = isActive ? activeText : inactiveText;
	let html = '<span style="color:' + color + '">' + symbol + ' ' + text + '</span>';

	if (suffix) {
		html += ' <small style="color:' + CONSTANTS.COLORS.INFO + '">' + suffix + '</small>';
	}

	return html;
}

/**
 * Creates a checkmark status indicator
 * @param {boolean} isActive - Whether the status is active/good
 * @param {string} activeText - Text to show when active
 * @param {string} inactiveText - Text to show when inactive
 * @returns {string} HTML string
 */
function createCheckIndicator(isActive, activeText, inactiveText) {
	const color = isActive ? CONSTANTS.COLORS.SUCCESS : CONSTANTS.COLORS.MUTED;
	const symbol = isActive ? '✓' : '✗';
	const text = isActive ? activeText : inactiveText;
	return '<span style="color:' + color + '">' + symbol + ' ' + text + '</span>';
}

// Track if key exists globally for button state
let keyExistsGlobal = false;
// Track if any server is enabled in config
let anyServerEnabledGlobal = false;
// Track boot enabled state
let bootEnabledGlobal = false;

return view.extend({
	render() {
		let m, s, o;

		m = new form.Map('rustdesk-server', _('RustDesk Server'),
			_('Remote Desktop Software Server configuration.') +
			' <a href="https://github.com/rustdesk/rustdesk-server" target="_blank">' + _('Server') + '</a> | ' +
			'<a href="https://github.com/rustdesk/rustdesk" target="_blank">' + _('Client') + '</a>');

		/*
			Firewall Notice
		*/
		s = m.section(form.NamedSection, 'firewall_info');
		s.render = () => E('div', { 'class': 'alert-message notice' }, [
			E('h4', {}, _('Firewall Configuration Required')),
			E('p', {}, _('Required ports (when using default settings): TCP 21115-21119, UDP 21116.')),
			E('p', {}, _('Configure in Network → Firewall → Traffic Rules.'))
		]);

		/*
			Status Section (custom render)
		*/
		s = m.section(form.NamedSection, 'global');
		s.render = L.bind((view, section_id) => {
			return E('div', { 'class': 'cbi-section' }, [
				E('h3', _('Service Status')),

				// Status Table for HBBS and HBBR
				E('table', { 'class': 'table cbi-section-table', 'id': 'status_table' }, [
					E('tr', { 'class': 'tr table-titles' }, [
						E('th', { 'class': 'th' }, _('Component')),
						E('th', { 'class': 'th' }, _('Service Status')),
						E('th', { 'class': 'th' }, _('Binary')),
						E('th', { 'class': 'th' }, _('Enabled'))
					]),
					E('tr', { 'class': 'tr', 'id': 'hbbs_row' }, [
						E('td', { 'class': 'td' }, _('HBBS (ID Server)')),
						E('td', { 'class': 'td', 'id': 'hbbs_status' }, '-'),
						E('td', { 'class': 'td', 'id': 'hbbs_binary' }, '-'),
						E('td', { 'class': 'td', 'id': 'hbbs_enabled' }, '-')
					]),
					E('tr', { 'class': 'tr', 'id': 'hbbr_row' }, [
						E('td', { 'class': 'td' }, _('HBBR (Relay Server)')),
						E('td', { 'class': 'td', 'id': 'hbbr_status' }, '-'),
						E('td', { 'class': 'td', 'id': 'hbbr_binary' }, '-'),
						E('td', { 'class': 'td', 'id': 'hbbr_enabled' }, '-')
					])
				]),

				// Public Key with Regenerate button inline
				E('div', { 'class': 'cbi-value' }, [
					E('label', { 'class': 'cbi-value-title' }, _('Public Key')),
					E('div', { 'class': 'cbi-value-field', 'style': 'display: flex; align-items: center; flex-wrap: wrap; gap: 8px;' }, [
						E('span', { 'id': 'public_key', 'style': 'word-break: break-all; flex: 1; min-width: 200px;' }, '-'),
						E('button', {
							'class': 'btn cbi-button cbi-button-negative',
							'id': 'regenerate_key_btn',
							'disabled': true,
							'title': _('Regenerate the key pair (requires existing key)'),
							'click': (ev) => {
								if (!keyExistsGlobal) {
									ui.addTimeLimitedNotification(null, E('p', _('Cannot regenerate: No public key exists yet.') + ' ' + _('Start the service first to generate the initial key.')), 5000, 'warning');
									return;
								}
								if (!confirm(_('This will regenerate the key pair and restart the service.') + ' ' + _('All existing clients will need to be reconfigured.') + ' ' + _('Continue?'))) {
									return;
								}
								ev.target.disabled = true;
								ev.target.textContent = _('Regenerating...');

								L.resolveDefault(callRegenerateKey(), {}).then((res) => {
									if (res && res.success) {
										ui.addTimeLimitedNotification(null, E('p', _('Keys deleted. Starting service to generate new keys...')), 5000, 'notice');
										// Use RPC to start service for reliable execution
										// Add small delay to ensure service has fully stopped
										return new Promise((resolve) => {
											setTimeout(resolve, 1000);
										}).then(() => L.resolveDefault(callServiceAction('start'), {}));
									} else {
										ui.addTimeLimitedNotification(null, E('p', _('Key regeneration failed: ') + (res.message || 'Could not delete keys')), 5000, 'error');
										throw new Error('Regeneration failed');
									}
								}).then((startRes) => {
									if (startRes && startRes.success) {
										ui.addTimeLimitedNotification(null, E('p', _('Service started with new key')), 5000, 'notice');
									} else if (startRes) {
										ui.addTimeLimitedNotification(null, E('p', _('Service start may have failed. Check status above.')), 5000, 'warning');
									}
								}).catch((err) => {
									if (err.message !== 'Regeneration failed') {
										ui.addTimeLimitedNotification(null, E('p', _('Error: ') + err.message), 5000, 'error');
									}
								}).finally(() => {
									const btn = document.getElementById('regenerate_key_btn');
									if (btn) {
										btn.disabled = !keyExistsGlobal;
										btn.textContent = _('Regenerate Key');
									}
								});
							}
						}, _('Regenerate Key'))
					])
				]),

				// Boot at startup toggle
				E('div', { 'class': 'cbi-value' }, [
					E('label', { 'class': 'cbi-value-title' }, _('Start at Boot')),
					E('div', { 'class': 'cbi-value-field', 'style': 'display: flex; align-items: center; gap: 12px;' }, [
						E('span', { 'id': 'boot_status' }, '-'),
						E('button', {
							'class': 'btn cbi-button cbi-button-action',
							'id': 'enable_boot_btn',
							'click': (ev) => {
								const action = bootEnabledGlobal ? 'disable' : 'enable';
								ev.target.disabled = true;
								ev.target.textContent = _('Processing...');

								L.resolveDefault(callServiceAction(action), {}).then((res) => {
									if (res && res.success) {
										bootEnabledGlobal = !bootEnabledGlobal;
										ui.addTimeLimitedNotification(null, E('p',
											bootEnabledGlobal ? _('Service enabled at boot') : _('Service disabled at boot')
										), 5000, 'notice');
									} else {
										const errMsg = res.error || res.message || (res.exit_code !== undefined ? 'Exit code: ' + res.exit_code : JSON.stringify(res));
										ui.addTimeLimitedNotification(null, E('p', _('Failed: ') + errMsg), 5000, 'error');
									}
								}).catch((err) => {
									ui.addTimeLimitedNotification(null, E('p', _('Error: ') + err.message), 5000, 'error');
								}).finally(() => {
									const btn = document.getElementById('enable_boot_btn');
									const statusEl = document.getElementById('boot_status');
									if (btn) {
										btn.disabled = false;
										btn.textContent = bootEnabledGlobal ? _('Disable') : _('Enable');
									}
									if (statusEl) {
										statusEl.innerHTML = createCheckIndicator(bootEnabledGlobal, _('Enabled'), _('Disabled'));
									}
								});
							}
						}, _('Loading...'))
					])
				]),

				// Service Control section
				E('div', { 'class': 'cbi-value' }, [
					E('label', { 'class': 'cbi-value-title' }, _('Service Control')),
					E('div', { 'class': 'cbi-value-field' }, [
						E('div', { 'style': 'margin-bottom: 8px;' }, [
							E('button', {
								'class': 'btn cbi-button cbi-button-apply',
								'id': 'start_btn',
								'disabled': true,
								'title': _('Enable ID Server or Relay Server first'),
								'click': (ev) => {
									if (!anyServerEnabledGlobal) {
										ui.addTimeLimitedNotification(null, E('p', _('Cannot start service: Enable the ID Server or Relay Server in the configuration first.') + ' ' + _('Check "Enable ID Server" or "Enable Relay Server" below and click "Save & Apply".')), 5000, 'error');
										return;
									}

									ev.target.disabled = true;
									handleAction('start').then(() => {
										ev.target.disabled = !anyServerEnabledGlobal;
									}).catch((err) => {
										ui.addTimeLimitedNotification(null, E('p', _('Failed to start service: ') + err.message), 5000, 'error');
										ev.target.disabled = !anyServerEnabledGlobal;
									});
								}
							}, _('Start')),
							' ',
							E('button', {
								'class': 'btn cbi-button cbi-button-remove',
								'click': (ev) => {
									ev.target.disabled = true;
									handleAction('stop').then(() => {
										ev.target.disabled = false;
									}).catch((err) => {
										ui.addTimeLimitedNotification(null, E('p', _('Failed to stop service: ') + err.message), 5000, 'error');
										ev.target.disabled = false;
									});
								}
							}, _('Stop')),
							' ',
							E('button', {
								'class': 'btn cbi-button cbi-button-action',
								'click': (ev) => {
									ev.target.disabled = true;
									handleAction('restart').then(() => {
										ev.target.disabled = false;
									}).catch((err) => {
										ui.addTimeLimitedNotification(null, E('p', _('Failed to restart service: ') + err.message), 5000, 'error');
										ev.target.disabled = false;
									});
								}
							}, _('Restart'))
						]),
						// Info message about Start requirement
						E('div', {
							'class': 'cbi-value-description',
							'style': 'color: #666; font-size: 0.9em; margin-top: 4px;'
						}, [
							E('em', {}, [
								_('Start will only work if at least "Enable ID Server" or "Enable Relay Server" is checked in the Configuration section below.')
							])
						])
					])
				])
			]);
		}, o, this);

		/*
			Polling for status updates
		*/
		poll.add(() => {
			return Promise.all([
				L.resolveDefault(callGetStatus(), {}),
				L.resolveDefault(callGetPublicKey(), {}),
				L.resolveDefault(callGetVersion(), {}),
				uci.load('rustdesk-server')
			]).then(([status = {}, keyInfo = {}, verInfo = {}]) => {

				// Get enabled status from UCI
				const sections = uci.sections('rustdesk-server', 'rustdesk-server');
				let hbbsEnabled = false;
				let hbbrEnabled = false;
				if (sections && sections.length > 0) {
					hbbsEnabled = (sections[0].enabled == '1');
					hbbrEnabled = (sections[0].enabled_relay == '1');
				}

				// HBBS Status (Service Status column)
				const hbbsStatusEl = document.getElementById('hbbs_status');
				if (hbbsStatusEl) {
					let suffix = '';
					if (status.hbbs_pid) {
						suffix = '(PID: ' + status.hbbs_pid + ')';
						if (verInfo.hbbs_version) suffix += ' [' + verInfo.hbbs_version + ']';
					}
					hbbsStatusEl.innerHTML = createStatusIndicator(
						!!status.hbbs_pid, _('Running'), _('Stopped'), suffix
					);
				}

				// HBBS Binary column
				const hbbsBinaryEl = document.getElementById('hbbs_binary');
				if (hbbsBinaryEl) {
					hbbsBinaryEl.innerHTML = createCheckIndicator(status.hbbs_exists, _('Found'), _('Not Found'));
				}

				// HBBS Enabled column
				const hbbsEnabledEl = document.getElementById('hbbs_enabled');
				if (hbbsEnabledEl) {
					hbbsEnabledEl.innerHTML = createCheckIndicator(hbbsEnabled, _('Yes'), _('No'));
				}

				// HBBR Status (Service Status column)
				const hbbrStatusEl = document.getElementById('hbbr_status');
				if (hbbrStatusEl) {
					let suffix = '';
					if (status.hbbr_pid) {
						suffix = '(PID: ' + status.hbbr_pid + ')';
						if (verInfo.hbbr_version) suffix += ' [' + verInfo.hbbr_version + ']';
					}
					hbbrStatusEl.innerHTML = createStatusIndicator(
						!!status.hbbr_pid, _('Running'), _('Stopped'), suffix
					);
				}

				// HBBR Binary column
				const hbbrBinaryEl = document.getElementById('hbbr_binary');
				if (hbbrBinaryEl) {
					hbbrBinaryEl.innerHTML = createCheckIndicator(status.hbbr_exists, _('Found'), _('Not Found'));
				}

				// HBBR Enabled column
				const hbbrEnabledEl = document.getElementById('hbbr_enabled');
				if (hbbrEnabledEl) {
					hbbrEnabledEl.innerHTML = createCheckIndicator(hbbrEnabled, _('Yes'), _('No'));
				}

				// Public Key - update global state
				keyExistsGlobal = !!(keyInfo.key_exists && keyInfo.public_key);

				const keyEl = document.getElementById('public_key');
				const regenBtn = document.getElementById('regenerate_key_btn');

				if (keyEl) {
					if (keyInfo.key_exists && keyInfo.public_key) {
						keyEl.innerHTML = '<code style="font-size:0.9em">' + keyInfo.public_key + '</code>' +
							' <button class="btn cbi-button cbi-button-action" onclick="navigator.clipboard.writeText(\'' +
							keyInfo.public_key + '\');this.textContent=\'✓\';setTimeout(()=>this.textContent=\'' + _('Copy') + '\',1000)">' + _('Copy') + '</button>';
					} else {
						keyEl.innerHTML = '<em style="color:' + CONSTANTS.COLORS.MUTED + '">' + _('Not generated yet - start the service') + '</em>';
					}
				}

				// Update regenerate button state
				if (regenBtn) {
					regenBtn.disabled = !keyExistsGlobal;
					if (!keyExistsGlobal) {
						regenBtn.title = _('Start the service first to generate the initial key');
					} else {
						regenBtn.title = _('Regenerate the key pair (will restart service)');
					}
				}

				// Update Start button state based on config
				anyServerEnabledGlobal = hbbsEnabled || hbbrEnabled;
				const startBtn = document.getElementById('start_btn');
				if (startBtn) {
					startBtn.disabled = !anyServerEnabledGlobal;
					if (!anyServerEnabledGlobal) {
						startBtn.title = _('Enable ID Server or Relay Server in Configuration first');
					} else {
						startBtn.title = _('Start the service');
					}
				}

				// Update boot enabled status
				bootEnabledGlobal = status.boot_enabled || false;
				const bootStatusEl = document.getElementById('boot_status');
				const bootBtn = document.getElementById('enable_boot_btn');
				if (bootStatusEl) {
					bootStatusEl.innerHTML = createCheckIndicator(bootEnabledGlobal, _('Enabled'), _('Disabled'));
				}
				if (bootBtn) {
					bootBtn.textContent = bootEnabledGlobal ? _('Disable') : _('Enable');
				}
			});
		}, CONSTANTS.POLL_INTERVAL);

		/*
			Configuration Section
		*/
		s = m.section(form.TypedSection, 'rustdesk-server', _('Configuration'));
		s.anonymous = true;
		s.addremove = false;

		s.tab('hbbs', _('ID Server (hbbs)'));
		s.tab('hbbr', _('Relay Server (hbbr)'));

		/* HBBS Settings */
		o = s.taboption('hbbs', form.Flag, 'enabled', _('Enable'));
		o.rmempty = false;

		o = s.taboption('hbbs', form.Value, 'server_port', _('Port (-p, --port)'));
		o.datatype = 'port';
		o.placeholder = CONSTANTS.HBBS_DEFAULT_PORT;
		o.description = _('Sets the listening port for the ID/Rendezvous server');

		o = s.taboption('hbbs', form.Value, 'server_key', _('Key (-k, --key)'));
		o.description = _('Only allow clients with the same key. If empty, uses auto-generated key');
		o.validate = validateKey;

		o = s.taboption('hbbs', form.DynamicList, 'server_relay_servers', _('Relay Servers (-r, --relay-servers)'));
		o.description = _('Default relay servers. Add one server per entry (hostname or hostname:port)');
		o.datatype = 'or(host,hostport)';

		o = s.taboption('hbbs', form.DynamicList, 'server_rendezvous_servers', _('Rendezvous Servers (-R, --rendezvous-servers)'));
		o.description = _('Additional rendezvous servers. Add one server per entry (hostname or hostname:port)');
		o.datatype = 'or(host,hostport)';

		o = s.taboption('hbbs', form.Value, 'server_mask', _('LAN Mask (--mask)'));
		o.description = _('Determine if the connection comes from LAN. Use CIDR notation.');
		o.placeholder = '192.168.0.0/16';
		o.datatype = 'cidr4';

		o = s.taboption('hbbs', form.Value, 'server_rmem', _('UDP Recv Buffer (-M, --rmem)'));
		o.datatype = 'uinteger';
		o.placeholder = '0';
		o.description = _('Sets UDP receive buffer size (0 = system default)');

		o = s.taboption('hbbs', form.Value, 'server_serial', _('Serial Number (-s, --serial)'));
		o.datatype = 'uinteger';
		o.placeholder = '0';
		o.description = _('Sets configure update serial number');

		o = s.taboption('hbbs', form.Value, 'server_software_url', _('Software Download URL (-u, --software-url)'));
		o.description = _('Sets the download URL of RustDesk software for clients');
		o.validate = validateURL;

		/* HBBS Settings - Environment Variables */
		o = s.taboption('hbbs', form.Flag, 'server_env_always_use_relay', _('ALWAYS_USE_RELAY'));
		o.description = _('Force all connections to use relay servers');
		o.default = o.disabled;

		o = s.taboption('hbbs', form.ListValue, 'server_env_rust_log', _('RUST_LOG'));
		o.description = _('Logging level for the ID server');
		o.value('', _('Default'));
		o.value('error', _('Error'));
		o.value('warn', _('Warning'));
		o.value('info', _('Info'));
		o.value('debug', _('Debug'));
		o.value('trace', _('Trace'));
		o.default = '';

		/* HBBR Settings */
		o = s.taboption('hbbr', form.Flag, 'enabled_relay', _('Enable'));
		o.rmempty = false;

		o = s.taboption('hbbr', form.Value, 'relay_port', _('Port (-p, --port)'));
		o.datatype = 'port';
		o.placeholder = CONSTANTS.HBBR_DEFAULT_PORT;
		o.description = _('Sets the listening port for the relay server');

		o = s.taboption('hbbr', form.Value, 'relay_key', _('Key (-k, --key)'));
		o.description = _('Only allow clients with the same key. If empty, uses auto-generated key');
		o.validate = validateKey;

		/* HBBR Settings - Environment Variables */
		o = s.taboption('hbbr', form.ListValue, 'relay_env_rust_log', _('RUST_LOG'));
		o.description = _('Logging level for the relay server');
		o.value('', _('Default'));
		o.value('error', _('Error'));
		o.value('warn', _('Warning'));
		o.value('info', _('Info'));
		o.value('debug', _('Debug'));
		o.value('trace', _('Trace'));
		o.default = '';

		o = s.taboption('hbbr', form.Value, 'relay_env_limit_speed', _('LIMIT_SPEED'));
		o.datatype = 'uinteger';
		o.description = _('Speed limit per connection in Mb/s (0 = default)');
		o.placeholder = '0';

		o = s.taboption('hbbr', form.Value, 'relay_env_single_bandwidth', _('SINGLE_BANDWIDTH'));
		o.datatype = 'uinteger';
		o.description = _('Bandwidth limit per single connection in MB/s (0 = default)');
		o.placeholder = '0';

		o = s.taboption('hbbr', form.Value, 'relay_env_total_bandwidth', _('TOTAL_BANDWIDTH'));
		o.datatype = 'uinteger';
		o.description = _('Total bandwidth limit in MB/s (0 = default)');
		o.placeholder = '0';

		o = s.taboption('hbbr', form.Value, 'relay_env_downgrade_threshold', _('DOWNGRADE_THRESHOLD'));
		o.datatype = 'uinteger';
		o.description = _('Threshold for connection downgrade');

		o = s.taboption('hbbr', form.Value, 'relay_env_downgrade_start_check', _('DOWNGRADE_START_CHECK'));
		o.datatype = 'uinteger';
		o.description = _('Start check time for connection downgrade');

		return m.render();
	}
});