1 /* SPDX-License-Identifier: GPL-3.0-only
3 * Copyright (C) 2022 ImmortalWrt.org
16 var callServiceList = rpc.declare({
23 function getServiceStatus() {
24 return L.resolveDefault(callServiceList('v2raya'), {}).then(function (res) {
25 var isRunning = false;
27 isRunning = res['v2raya']['instances']['v2raya']['running'];
33 function renderStatus(isRunning, port) {
34 var spanTemp = '<span style="color:%s"><strong>%s %s</strong></span>';
37 var button = String.format(' <a class="btn cbi-button" href="%s:%s" target="_blank" rel="noreferrer noopener">%s</a>',
38 window.location.origin, port, _('Open Web Interface'));
39 renderHTML = spanTemp.format('green', _('v2rayA'), _('RUNNING')) + button;
41 renderHTML = spanTemp.format('red', _('v2rayA'), _('NOT RUNNING'));
47 function uploadCertificate(type, filename, ev) {
48 L.resolveDefault(fs.exec('/bin/mkdir', [ '-p', '/etc/v2raya/' ]));
50 return ui.uploadFile('/etc/v2raya/' + filename, ev.target)
51 .then(L.bind(function(btn, res) {
52 btn.firstChild.data = _('Checking %s...').format(type);
55 ui.addNotification(null, E('p', _('The uploaded %s is empty.').format(type)));
56 return fs.remove('/etc/v2raya/' + filename);
59 ui.addNotification(null, E('p', _('Your %s was successfully uploaded. Size: %sB.').format(type, res.size)));
61 .catch(function(e) { ui.addNotification(null, E('p', e.message)) })
62 .finally(L.bind(function(btn, input) {
63 btn.firstChild.data = _('Upload...');
74 render: function(data) {
76 var webport = (uci.get(data[0], 'config', 'address') || '0.0.0.0:2017').split(':').slice(-1)[0];
78 m = new form.Map('v2raya', _('v2rayA'),
79 _('v2rayA is a V2Ray Linux client supporting global transparent proxy, compatible with SS, SSR, Trojan(trojan-go), PingTunnel protocols.'));
81 s = m.section(form.TypedSection);
83 s.render = function () {
84 poll.add(function () {
85 return L.resolveDefault(getServiceStatus()).then(function (res) {
86 var view = document.getElementById('service_status');
87 view.innerHTML = renderStatus(res, webport);
91 return E('div', { class: 'cbi-section', id: 'status_bar' }, [
92 E('p', { id: 'service_status' }, _('Collecting data...'))
96 s = m.section(form.NamedSection, 'config', 'v2raya');
98 o = s.option(form.Flag, 'enabled', _('Enable'));
99 o.default = o.disabled;
102 o = s.option(form.Value, 'address', _('Listening address'));
103 o.datatype = 'ipaddrport(1)';
104 o.default = '0.0.0.0:2017';
107 o = s.option(form.Value, 'config', _('Configuration directory'));
109 o.default = '/etc/v2raya';
112 o = s.option(form.ListValue, 'ipv6_support', _('IPv6 support'),
113 _('Make sure your IPv6 network works fine before you turn it on.'));
114 o.value('auto', _('Auto'));
115 o.value('on', _('On'));
116 o.value('off', _('Off'));
120 o = s.option(form.ListValue, 'log_level', _('Log level'));
121 o.value('trace', _('Trace'));
122 o.value('debug', _('Debug'));
123 o.value('info', _('Info'));
124 o.value('warn', _('Warn'));
125 o.value('error', _('Error'));
129 o = s.option(form.Value, 'log_file', _('Log file path'));
131 o.default = '/var/log/v2raya/v2raya.log';
133 /* Due to ACL rule, this value must retain default otherwise log page will be broken */
136 o = s.option(form.Value, 'log_max_days', _('Max log retention period'),
137 _('Maximum number of days to keep log files.'));
138 o.datatype = 'uinteger';
142 o = s.option(form.Flag, 'log_disable_color', _('Disable log color output'));
143 o.default = o.enabled;
146 o = s.option(form.Flag, 'log_disable_timestamp', _('Disable log timestamp'));
147 o.default = o.disabled;
150 o = s.option(form.Value, 'v2ray_bin', _('v2ray binary path'),
151 _('Executable v2ray binary path. Auto-detect if put it empty (recommended).'));
154 o = s.option(form.Value, 'v2ray_confdir', _('Extra config directory'),
155 _('Additional v2ray config directory, files in it will be combined with config generated by v2rayA.'));
158 o = s.option(form.Value, 'vless_grpc_inbound_cert_key', _('Certpath for gRPC inbound'),
159 _('Specify the certification path instead of automatically generating a self-signed certificate.'));
160 o.value('', _('Automatically generate'));
161 o.value('/etc/v2raya/grpc_certificate.crt,/etc/v2raya/grpc_private.key');
163 o = s.option(form.Button, '_upload_cert', _('Upload certificate'));
164 o.inputstyle = 'action';
165 o.inputtitle = _('Upload...');
166 o.onclick = L.bind(uploadCertificate, this, _('certificate'), 'grpc_certificate.crt');
167 o.depends('vless_grpc_inbound_cert_key', '/etc/v2raya/grpc_certificate.crt,/etc/v2raya/grpc_private.key');
169 o = s.option(form.Button, '_upload_key', _('Upload privateKey'));
170 o.inputstyle = 'action';
171 o.inputtitle = _('Upload...');
172 o.onclick = L.bind(uploadCertificate, this, _('private key'), 'grpc_private.key');
173 o.depends('vless_grpc_inbound_cert_key', '/etc/v2raya/grpc_certificate.crt,/etc/v2raya/grpc_private.key');