mirror of
https://github.com/kiddin9/op-packages.git
synced 2026-09-14 20:34:19 +08:00
113 lines
3.8 KiB
JavaScript
113 lines
3.8 KiB
JavaScript
'use strict';
|
|
'require view';
|
|
'require form';
|
|
'require uci';
|
|
'require fs';
|
|
|
|
function requireWhenSelfhosted(o, is_file) {
|
|
o.rmempty = true;
|
|
if (is_file) {
|
|
var baseParse = o.parse;
|
|
o.parse = function (section_id) {
|
|
if (this.section.formvalue(section_id, 'mode') === 'selfhosted') {
|
|
var fval = this.formvalue(section_id);
|
|
if (fval == null || fval === '')
|
|
return Promise.reject(new TypeError(
|
|
_('This field is required in Self-hosted mode.')));
|
|
}
|
|
return baseParse.apply(this, arguments);
|
|
};
|
|
} else {
|
|
o.validate = function (section_id, value) {
|
|
if (this.section.formvalue(section_id, 'mode') !== 'selfhosted')
|
|
return true;
|
|
if (value == null || value === '')
|
|
return _('This field is required in Self-hosted mode.');
|
|
return true;
|
|
};
|
|
}
|
|
}
|
|
|
|
return view.extend({
|
|
load: function () {
|
|
return Promise.all([
|
|
uci.load('rms'),
|
|
L.resolveDefault(fs.read('/tmp/rms/device_id'), '')
|
|
]);
|
|
},
|
|
|
|
render: function (data) {
|
|
var m, s, o;
|
|
var deviceId = ((data && data[1]) || '').trim() || '—';
|
|
|
|
m = new form.Map(
|
|
'rms',
|
|
_('TELEOFIS: Remote Monitoring System'),
|
|
_('Connect to the centralized TELEOFIS platform for monitoring and remote device management.')
|
|
);
|
|
|
|
s = m.section(form.NamedSection, 'main', 'rms');
|
|
s.anonymous = true;
|
|
|
|
o = s.option(form.DummyValue, 'device_id', _('Device ID'));
|
|
o.rawhtml = false;
|
|
o.cfgvalue = function () { return deviceId; };
|
|
|
|
o = s.option(form.Flag, 'enabled', _('Enable'));
|
|
o.default = '0';
|
|
o.rmempty = false;
|
|
|
|
o = s.option(form.ListValue, 'mode', _('Connection mode'), _('Connect to the cloud service or to a management platform hosted on your organization\'s servers.'));
|
|
o.value('cloud', _('Cloud'));
|
|
o.value('selfhosted', _('Self-hosted'));
|
|
o.default = 'cloud';
|
|
o.forcewrite = true;
|
|
|
|
o = s.option(form.Value, 'server', _('Address'), _('Remote host or IP address'));
|
|
o.depends('mode', 'selfhosted');
|
|
o.datatype = 'host';
|
|
requireWhenSelfhosted(o);
|
|
|
|
o = s.option(form.Value, 'port', _('Port'));
|
|
o.depends('mode', 'selfhosted');
|
|
o.datatype = 'range(1024,65535)';
|
|
o.placeholder = '8883';
|
|
requireWhenSelfhosted(o);
|
|
|
|
o = s.option(form.FileUpload, 'sh_ca_cert', _('CA certificate'), _('Root certificate of the management platform. Generated by the self-hosted platform during its deployment.'));
|
|
o.depends('mode', 'selfhosted');
|
|
o.root_directory = '/etc/rms/certs/selfhosted';
|
|
o.enable_upload = true;
|
|
o.enable_remove = true;
|
|
requireWhenSelfhosted(o, true);
|
|
|
|
o = s.option(form.FileUpload, 'sh_bootstrap_cert', _('Bootstrap CRT'), _('Certificate for initial device authentication on the management platform. Generated by the self-hosted platform during its deployment.'));
|
|
o.depends('mode', 'selfhosted');
|
|
o.root_directory = '/etc/rms/certs/selfhosted';
|
|
o.enable_upload = true;
|
|
o.enable_remove = true;
|
|
requireWhenSelfhosted(o, true);
|
|
|
|
o = s.option(form.FileUpload, 'sh_bootstrap_key', _('Bootstrap KEY'), _('Private key for initial device authentication on the management platform. Generated by the self-hosted platform during its deployment.'));
|
|
o.depends('mode', 'selfhosted');
|
|
o.root_directory = '/etc/rms/certs/selfhosted';
|
|
o.enable_upload = true;
|
|
o.enable_remove = true;
|
|
requireWhenSelfhosted(o, true);
|
|
|
|
o = s.option(form.Value, 'interval', _('Telemetry interval, s'), _('Interval at which the device sends status data to the server. Range: 300 to 3600 s.'));
|
|
o.datatype = 'range(300,3600)';
|
|
o.default = '300';
|
|
o.placeholder = '300';
|
|
o.rmempty = false;
|
|
|
|
o = s.option(form.Value, 'keepalive', _('Keepalive interval, s'), _('Interval at which the device reports to the server that it is online and the connection is active. Range: 60 to 3600 s.'));
|
|
o.datatype = 'range(60,3600)';
|
|
o.default = '60';
|
|
o.placeholder = '60';
|
|
o.rmempty = false;
|
|
|
|
return m.render();
|
|
}
|
|
});
|