luci-app-frps: fix markup which is not valid XHTML
[project/luci.git] / applications / luci-app-frps / htdocs / luci-static / resources / view / frps.js
1 'use strict';
2 'require view';
3 'require form';
4 'require rpc';
5 'require tools.widgets as widgets';
6
7 // [Widget, Option, Title, Description, {Param: 'Value'}],
8 var startupConf = [
9 [form.Flag, 'stdout', _('Log stdout')],
10 [form.Flag, 'stderr', _('Log stderr')],
11 [widgets.UserSelect, 'user', _('Run daemon as user')],
12 [widgets.GroupSelect, 'group', _('Run daemon as group')],
13 [form.Flag, 'respawn', _('Respawn when crashed')],
14 [form.DynamicList, 'env', _('Environment variable'), _('OS environments pass to frp for config file template, see <a href="https://github.com/fatedier/frp#configuration-file-template">frp README</a>'), {placeholder: 'ENV_NAME=value'}],
15 [form.DynamicList, 'conf_inc', _('Additional configs'), _('Config files include in temporary config file'), {placeholder: '/etc/frp/frps.d/frps_full.ini'}]
16 ];
17
18 var commonConf = [
19 [form.Value, 'bind_addr', _('Bind address'), _('BindAddr specifies the address that the server binds to.<br />By default, this value is "0.0.0.0".'), {datatype: 'ipaddr'}],
20 [form.Value, 'bind_port', _('Bind port'), _('BindPort specifies the port that the server listens on.<br />By default, this value is 7000.'), {datatype: 'port'}],
21 [form.Value, 'bind_udp_port', _('UDP bind port'), _('BindUdpPort specifies the UDP port that the server listens on. If this value is 0, the server will not listen for UDP connections.<br />By default, this value is 0'), {datatype: 'port'}],
22 [form.Value, 'kcp_bind_port', _('KCP bind port'), _('BindKcpPort specifies the KCP port that the server listens on. If this value is 0, the server will not listen for KCP connections.<br />By default, this value is 0.'), {datatype: 'port'}],
23 [form.Value, 'proxy_bind_addr', _('Proxy bind address'), _('ProxyBindAddr specifies the address that the proxy binds to. This value may be the same as BindAddr.<br />By default, this value is "0.0.0.0".'), {datatype: 'ipaddr'}],
24 [form.Value, 'vhost_http_port', _('Vhost HTTP port'), _('VhostHttpPort specifies the port that the server listens for HTTP Vhost requests. If this value is 0, the server will not listen for HTTP requests.<br />By default, this value is 0.'), {datatype: 'port'}],
25 [form.Value, 'vhost_https_port', _('Vhost HTTPS port'), _('VhostHttpsPort specifies the port that the server listens for HTTPS Vhost requests. If this value is 0, the server will not listen for HTTPS requests.<br />By default, this value is 0.'), {datatype: 'port'}],
26 [form.Value, 'vhost_http_timeout', _('Vhost HTTP timeout'), _('VhostHttpTimeout specifies the response header timeout for the Vhost HTTP server, in seconds.<br />By default, this value is 60.'), {datatype: 'uinteger'}],
27 [form.Value, 'dashboard_addr', _('Dashboard address'), _('DashboardAddr specifies the address that the dashboard binds to.<br />By default, this value is "0.0.0.0".'), {datatype: 'ipaddr'}],
28 [form.Value, 'dashboard_port', _('Dashboard port'), _('DashboardPort specifies the port that the dashboard listens on. If this value is 0, the dashboard will not be started.<br />By default, this value is 0.'), {datatype: 'port'}],
29 [form.Value, 'dashboard_user', _('Dashboard user'), _('DashboardUser specifies the username that the dashboard will use for login.<br />By default, this value is "admin".')],
30 [form.Value, 'dashboard_pwd', _('Dashboard password'), _('DashboardPwd specifies the password that the dashboard will use for login.<br />By default, this value is "admin".'), {password: true}],
31 [form.Value, 'assets_dir', _('Assets dir'), _('AssetsDir specifies the local directory that the dashboard will load resources from. If this value is "", assets will be loaded from the bundled executable using statik.<br />By default, this value is "".')],
32 [form.Value, 'log_file', _('Log file'), _('LogFile specifies a file where logs will be written to. This value will only be used if LogWay is set appropriately.<br />By default, this value is "console".')],
33 [form.ListValue, 'log_level', _('Log level'), _('LogLevel specifies the minimum log level. Valid values are "trace", "debug", "info", "warn", and "error".<br />By default, this value is "info".'), {values: ['trace', 'debug', 'info', 'warn', 'error']}],
34 [form.Value, 'log_max_days', _('Log max days'), _('LogMaxDays specifies the maximum number of days to store log information before deletion. This is only used if LogWay == "file".<br />By default, this value is 0.'), {datatype: 'uinteger'}],
35 [form.Flag, 'disable_log_color', _('Disable log color'), _('DisableLogColor disables log colors when LogWay == "console" when set to true.<br />By default, this value is false.'), {datatype: 'bool', default: 'true'}],
36 [form.Value, 'token', _('Token'), _('Token specifies the authorization token used to authenticate keys received from clients. Clients must have a matching token to be authorized to use the server.<br />By default, this value is "".')],
37 [form.Value, 'subdomain_host', _('Subdomain host'), _('SubDomainHost specifies the domain that will be attached to sub-domains requested by the client when using Vhost proxying. For example, if this value is set to "frps.com" and the client requested the subdomain "test", the resulting URL would be "test.frps.com".<br />By default, this value is "".')],
38 [form.Flag, 'tcp_mux', _('TCP mux'), _('TcpMux toggles TCP stream multiplexing. This allows multiple requests from a client to share a single TCP connection.<br />By default, this value is true.'), {datatype: 'bool', default: 'true'}],
39 [form.Value, 'custom_404_page', _('Custom 404 page'), _('Custom404Page specifies a path to a custom 404 page to display. If this value is "", a default page will be displayed.<br />By default, this value is "".')],
40 [form.Value, 'allow_ports', _('Allow ports'), _('AllowPorts specifies a set of ports that clients are able to proxy to. If the length of this value is 0, all ports are allowed.<br />By default, this value is an empty set.')],
41 [form.Value, 'max_ports_per_client', _('Max ports per client'), _('MaxPortsPerClient specifies the maximum number of ports a single client may proxy to. If this value is 0, no limit will be applied.<br />By default, this value is 0.'), {datatype: 'uinteger'}],
42 [form.Value, 'heartbeat_timeout', _('Heartbeat timeout'), _('HeartBeatTimeout specifies the maximum time to wait for a heartbeat before terminating the connection. It is not recommended to change this value.<br />By default, this value is 90.'), {datatype: 'uinteger'}],
43 [form.DynamicList, '_', _('Additional settings'), _('This list can be used to specify some additional parameters which have not been included in this LuCI.'), {placeholder: 'Key-A=Value-A'}]
44 ];
45
46 function setParams(o, params) {
47 if (!params) return;
48 for (var key in params) {
49 var val = params[key];
50 if (key === 'values') {
51 for (var j = 0; j < val.length; j++) {
52 var args = val[j];
53 if (!Array.isArray(args))
54 args = [args];
55 o.value.apply(o, args);
56 }
57 } else if (key === 'depends') {
58 if (!Array.isArray(val))
59 val = [val];
60 for (var j = 0; j < val.length; j++) {
61 var args = val[j];
62 if (!Array.isArray(args))
63 args = [args];
64 o.depends.apply(o, args);
65 }
66 } else {
67 o[key] = params[key];
68 }
69 }
70 if (params['datatype'] === 'bool') {
71 o.enabled = 'true';
72 o.disabled = 'false';
73 }
74 }
75
76 function defTabOpts(s, t, opts, params) {
77 for (var i = 0; i < opts.length; i++) {
78 var opt = opts[i];
79 var o = s.taboption(t, opt[0], opt[1], opt[2], opt[3]);
80 setParams(o, opt[4]);
81 setParams(o, params);
82 }
83 }
84
85 function defOpts(s, opts, params) {
86 for (var i = 0; i < opts.length; i++) {
87 var opt = opts[i];
88 var o = s.option(opt[0], opt[1], opt[2], opt[3]);
89 setParams(o, opt[4]);
90 setParams(o, params);
91 }
92 }
93
94 var callServiceList = rpc.declare({
95 object: 'service',
96 method: 'list',
97 params: ['name'],
98 expect: { '': {} }
99 });
100
101 function getServiceStatus() {
102 return L.resolveDefault(callServiceList('frps'), {}).then(function (res) {
103 var isRunning = false;
104 try {
105 isRunning = res['frps']['instances']['instance1']['running'];
106 } catch (e) { }
107 return isRunning;
108 });
109 }
110
111 function renderStatus(isRunning) {
112 var renderHTML = "";
113 var spanTemp = "<span style=\"color:%s;font-weight:bold;margin-left:15px\">%s - %s</span>";
114
115 if (isRunning) {
116 renderHTML += String.format(spanTemp, 'green', _("frp Server"), _("RUNNING"));
117 } else {
118 renderHTML += String.format(spanTemp, 'red', _("frp Server"), _("NOT RUNNING"));
119 }
120
121 return renderHTML;
122 }
123
124 return view.extend({
125 render: function() {
126 var m, s, o;
127
128 m = new form.Map('frps', _('frp Server'));
129
130 s = m.section(form.NamedSection, '_status');
131 s.anonymous = true;
132 s.render = function (section_id) {
133 L.Poll.add(function () {
134 return L.resolveDefault(getServiceStatus()).then(function(res) {
135 var view = document.getElementById("service_status");
136 view.innerHTML = renderStatus(res);
137 });
138 });
139
140 return E('div', { class: 'cbi-map' },
141 E('div', { class: 'cbi-section'}, [
142 E('div', { id: 'service_status' },
143 _('Collecting data ...'))
144 ])
145 );
146 }
147
148 s = m.section(form.NamedSection, 'common', 'conf');
149 s.dynamic = true;
150
151 s.tab('common', _('Common settings'));
152 s.tab('init', _('Startup settings'));
153
154 defTabOpts(s, 'common', commonConf, {optional: true});
155
156 o = s.taboption('init', form.SectionValue, 'init', form.TypedSection, 'init', _('Startup settings'));
157 s = o.subsection;
158 s.anonymous = true;
159 s.dynamic = true;
160
161 defOpts(s, startupConf);
162
163 return m.render();
164 }
165 });