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
|
'use strict';
'require view';
'require ui';
'require form';
'require rpc';
'require tools.widgets as widgets';
var callServiceList = rpc.declare({
object: 'service',
method: 'list',
params: ['name'],
expect: { '': {} }
});
function getServiceStatus() {
return L.resolveDefault(callServiceList('xfrpc'), {}).then(function (res) {
var isRunning = false;
try {
isRunning = res['xfrpc']['instances']['instance1']['running'];
} catch (e) { }
return isRunning;
});
}
function renderStatus(isRunning) {
var renderHTML = "";
var spanTemp = '<em><span style="color:%s"><strong>%s %s</strong></span></em>';
if (isRunning) {
renderHTML += String.format(spanTemp, 'green', _("x-frp Client "), _("RUNNING"));
} else {
renderHTML += String.format(spanTemp, 'red', _("x-frp Client "), _("NOT RUNNING"));
}
return renderHTML;
}
return view.extend({
render: function() {
var m, s, o;
m = new form.Map('xfrpc', _('xfrpc'));
m.description = _("xfrpc is a c language frp client for frps.");
s = m.section(form.NamedSection, '_status');
s.anonymous = true;
s.render = function (section_id) {
L.Poll.add(function () {
return L.resolveDefault(getServiceStatus()).then(function(res) {
var view = document.getElementById("service_status");
view.innerHTML = renderStatus(res);
});
});
return E('div', { class: 'cbi-map' },
E('fieldset', { class: 'cbi-section'}, [
E('p', { id: 'service_status' },
_('Collecting data ...'))
])
);
}
s = m.section(form.NamedSection, 'common', 'xfrpc');
s.dynamic = true;
s.tab('common', _('Common Settings'));
s.tab('init', _('Startup Settings'));
o = s.taboption('common', form.Value, 'server_addr', _('Server address'),
'%s <br /> %s'.format(_('Server address specifies the address of the server to connect to.'),
_('By default, this value is "0.0.0.0".')));
o.datatype = 'host';
o = s.taboption('common', form.Value, 'server_port', _('Server port'),
'%s <br /> %s'.format(_('Server port specifies the port to connect to the server on.'),
_('By default, this value is 7000.')));
o.datatype = 'port';
o = s.taboption('common', form.Value, 'token', _('Token'),
'%s <br /> %s'.format(_('Token specifies the authorization token used to create keys to be \
sent to the server. The server must have a matching token for authorization to succeed.'),
_('By default, this value is "".')));
o = s.taboption('init', form.SectionValue, 'init', form.TypedSection,
'xfrp', _('Startup Settings'));
s = o.subsection;
s.anonymous = true;
s.dynamic = true;
o = s.option(form.Flag, 'disabled', _('Disabled xfrpc service'));
o.datatype = 'bool';
o.optional = true;
o = s.option(form.ListValue, 'loglevel', _('Log level'),
'%s <br /> %s'.format(_('LogLevel specifies the minimum log level. Valid values are "Debug", "Info", \
"Notice", "Warning", "Error", "Critical", "Alert" and "Emergency".'),
_('By default, this value is "Info".')));
o.value(8, _('Debug'))
o.value(7, _('Info'))
o.value(6, _('Notice'))
o.value(5, _('Warning'))
o.value(4, _('Error'))
o.value(3, _('Critical'))
o.value(2, _('Alert'))
o.value(1, _('Emergency'))
s = m.section(form.GridSection, 'xfrpc', _('Proxy Settings'));
s.addremove = true;
s.filter = function(s) { return s !== 'common'; };
s.renderSectionAdd = function(extra_class) {
var el = form.GridSection.prototype.renderSectionAdd.apply(this, arguments),
nameEl = el.querySelector('.cbi-section-create-name');
ui.addValidator(nameEl, 'uciname', true, function(v) {
if (v === 'common') return _('Name can not be "common"');
return true;
}, 'blur', 'keyup');
return el;
}
s.tab('general', _('General Settings'));
s.tab('http', _('HTTP Settings'));
s.option(form.Value, 'type', _('Proxy type'));
s.option(form.Value, 'local_ip', _('Local IP'));
s.option(form.Value, 'local_port', _('Local port'));
o = s.taboption('general', form.ListValue, 'type', _('Proxy type'),
'%s <br /> %s'.format(_('ProxyType specifies the type of this proxy. Valid values include "tcp", "http", "https".'),
_('By default, this value is "tcp".')));
o.value('tcp');
o.value('http');
o.value('https');
o.modalonly = true;
o = s.taboption('general', form.Value, 'local_ip', _('Local IP'),
_('LocalIp specifies the IP address or host name to proxy to.'));
o.modalonly = true;
o.datatype = 'ip4addr';
o = s.taboption('general', form.Value, 'local_port', _('Local port'),
_('LocalPort specifies the port to proxy to.'));
o.modalonly = true;
o.datatype = 'port';
// TCP
o = s.taboption('general', form.Value, 'remote_port', _('Remote port'),
_('If remote_port is 0, frps will assign a random port for you'));
o.depends.apply(o, [{type: 'tcp'}]);
o.optional = true;
o.modalonly = true;
o.datatype = 'port';
// HTTP and HTTPS
o = s.taboption('http', form.Value, 'custom_domains', _('Custom domains'));
o.depends.apply(o, [{type: 'http'}]);
o.depends.apply(o, [{type: 'https'}]);
o.optional = true;
o.modalonly = true;
o = s.taboption('http', form.Value, 'subdomain', _('Subdomain'));
o.depends.apply(o, [{type: 'http'}]);
o.depends.apply(o, [{type: 'https'}]);
o.optional = true;
o.modalonly = true;
return m.render();
}
});
|