Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion applications/luci-app-v2raya/Makefile
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
# SPDX-License-Identifier: Apache-2.0
#
# Copyright (C) 2024 ImmortalWrt.org
# Copyright (C) 2026 Amr Fateem <amr.fateem@yahoo.com>

include $(TOPDIR)/rules.mk

LUCI_TITLE:=LuCI support for v2rayA
LUCI_DEPENDS:=+v2raya
LUCI_MAINTAINER:=Tianling Shen <cnsztl@immortalwrt.org>, Amr Fateem <amr.fateem@yahoo.com>

PKG_LICENSE:=Apache-2.0
PKG_MAINTAINER:=Tianling Shen <cnsztl@immortalwrt.org>
PKG_MAINTAINER:=Tianling Shen <cnsztl@immortalwrt.org>, Amr Fateem <amr.fateem@yahoo.com>

include ../../luci.mk

Expand Down
Original file line number Diff line number Diff line change
@@ -1,109 +1,148 @@
// SPDX-License-Identifier: Apache-2.0
'use strict';
'require form';
'require poll';
'require rpc';
'require uci';
'require view';

const callServiceList = rpc.declare({
object: 'service',
method: 'list',
params: ['name'],
expect: { '': {} }
});

function getServiceStatus() {
return L.resolveDefault(callServiceList('v2raya'), {}).then(function (res) {
var isRunning = false;
try {
isRunning = res['v2raya']['instances']['v2raya']['running'];
} catch (e) { }
return isRunning;
});
}

function renderStatus(isRunning, port) {
var spanTemp = '<span style="color:%s"><strong>%s %s</strong></span>';
var renderHTML;
if (isRunning) {
var button = String.format('&#160;<a class="btn cbi-button" href="http://%s:%s" target="_blank" rel="noreferrer noopener">%s</a>',
window.location.hostname, port, _('Open Web Interface'));
renderHTML = spanTemp.format('green', _('v2rayA'), _('RUNNING')) + button;
} else {
renderHTML = spanTemp.format('red', _('v2rayA'), _('NOT RUNNING'));
}

return renderHTML;
}

return view.extend({
load: function() {
return Promise.all([
uci.load('v2raya')
]);
load: function () {
return uci.load('v2raya');
},

render: function(data) {
let m, s, o;
var webport = (uci.get(data[0], 'config', 'address') || '0.0.0.0:2017').split(':').slice(-1)[0];
render: function () {
var m, s, o;

m = new form.Map('v2raya', _('v2rayA'),
_('v2rayA is a V2Ray Linux client supporting global transparent proxy, compatible with SS, SSR, Trojan(trojan-go), PingTunnel protocols.'));

s = m.section(form.TypedSection);
s.anonymous = true;
s.render = function () {
poll.add(function () {
return L.resolveDefault(getServiceStatus()).then(function (res) {
var view = document.getElementById('service_status');
view.innerHTML = renderStatus(res, webport);
});
});

return E('div', { class: 'cbi-section', id: 'status_bar' }, [
E('p', { id: 'service_status' }, _('Collecting data…'))
]);
}
_('Settings for the v2rayA service. Save & Apply restarts the service so the new values take effect. v2rayA 2.5.x uses only its bundled v2raya_core; Xray-core and sing-box are not supported backends.'));

s = m.section(form.NamedSection, 'config', 'v2raya');

o = s.option(form.Flag, 'enabled', _('Enable'));
s.tab('general', _('General'));
s.tab('proxy', _('Transparent proxy'),
_('The transparent proxy mode, routing rules and nodes are configured in the v2rayA web interface. These options control core start-up and hooks.'));
s.tab('logging', _('Logging'));
s.tab('advanced', _('Advanced'));

o = s.taboption('general', form.Flag, 'enabled', _('Enable service'));
o.default = '0';
o.rmempty = false;
o.description = _('Start v2rayA at boot. You can also start or stop it from the overview page.');

o = s.option(form.Value, 'address', _('Listening address'));
o.datatype = 'ipaddrport(1)';
o = s.taboption('general', form.Value, 'address', _('Listening address'));
o.placeholder = '0.0.0.0:2017';

o = s.option(form.ListValue, 'ipv6_support', _('IPv6 support'),
_('Requires working IPv6 connectivity.'));
o.rmempty = false;
o.validate = function (section_id, value) {
if (!value)
return _('An address is required.');

if (!/^(\[[0-9a-fA-F:]+\]|[A-Za-z0-9._-]+):[0-9]{1,5}$/.test(value))
return _('Enter an address and port, for example 0.0.0.0:2017 or [::]:2017.');

return true;
};
o.description = _('The web interface listens on this address. Use 127.0.0.1:2017 to keep it off the LAN.');

o = s.taboption('general', form.Value, 'baseurl', _('Base URL'));

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

baseurl, core_startup_timeout, redirect_respect_bound_device, v2ray_assetsdir, gomemlimit, gomaxprocs, gogc and nofile are not read by the current v2raya init script, so with 2.2.x they silently do nothing even though the commit says the app still works there. The body says this waits on openwrt/packages#31261, but the PR is not marked draft — should it be, or should these options be hidden when the backend lacks them?


Generated by Claude Code

o.placeholder = '/';
o.description = _('URL prefix when v2rayA runs behind a reverse proxy.');
o.validate = function (section_id, value) {
if (value && value.charAt(0) !== '/')
return _('The base URL must start with /.');
return true;
};

o = s.taboption('general', form.ListValue, 'ipv6_support', _('IPv6 support'));
o.value('auto', _('Auto'));
o.value('on', _('On'));
o.value('off', _('Off'));
o.default = 'auto';
o.description = _('Make sure IPv6 connectivity works before forcing it on.');

o = s.option(form.ListValue, 'nftables_support', _('Nftables support'),
_('Requires nftables.'));
o = s.taboption('general', form.ListValue, 'nftables_support', _('nftables support'));
o.value('auto', _('Auto'));
o.value('on', _('On'));
o.value('off', _('Off'));
o.default = 'auto';
o.description = _('nftables is the default firewall backend on OpenWrt 22.03 and later.');

o = s.taboption('proxy', form.Value, 'core_startup_timeout', _('Core startup timeout'));
o.datatype = 'uinteger';
o.placeholder = '15';
o.default = '15';
o.description = _('Seconds to wait for v2raya_core to start. Raise this on slow MIPS routers.');

o = s.taboption('proxy', form.Flag, 'redirect_respect_bound_device', _('Respect bound devices in redirect mode'));
o.default = '0';
o.description = _('Let sockets bound to a device bypass the proxy. Requires Linux 5.14 or later and cgroup v2.');

o = s.taboption('proxy', form.Value, 'transparent_hook', _('Transparent proxy hook'));
o.placeholder = '/usr/bin/example-hook';
o.description = _('Executable called around transparent proxy setup and teardown.');

o = s.option(form.ListValue, 'log_level', _('Log level'));
o = s.taboption('proxy', form.Value, 'core_hook', _('Core life-cycle hook'));
o.placeholder = '/usr/bin/example-hook';
o.description = _('Executable called around v2raya_core start and stop.');

o = s.taboption('proxy', form.Value, 'plugin_manager', _('Plugin manager'));
o.placeholder = '/usr/bin/example-plugin-manager';
o.description = _('Executable used to parse protocols that v2rayA does not know natively.');

o = s.taboption('logging', form.ListValue, 'log_level', _('Log level'));
o.value('trace', _('Trace'));
o.value('debug', _('Debug'));
o.value('info', _('Info'));
o.value('warn', _('Warn'));
o.value('warn', _('Warning'));
o.value('error', _('Error'));
o.default = 'info';
o.default = 'warn';
o.description = _('Warning keeps flash writes down. Use Info while debugging.');

o = s.taboption('logging', form.Value, 'log_max_days', _('Keep logs for'));
o.datatype = 'uinteger';
o.placeholder = '1';
o.default = '1';
o.description = _('Number of days to keep rotated log files.');

o = s.taboption('logging', form.Flag, 'log_disable_color', _('Disable colours in the log'));
o.default = '1';
o.description = _('The log file is plain text, so colours are not useful there.');

o = s.taboption('logging', form.Flag, 'log_disable_timestamp', _('Disable timestamps in the log'));
o.default = '0';
o.description = _('Only relevant when v2rayA writes to syslog or journald.');

o = s.option(form.Value, 'log_max_days', _('Max log retention period'),
_('Unit: days.'));
o = s.taboption('advanced', form.Value, 'v2ray_assetsdir', _('Rule data directory'));
o.placeholder = '/usr/share/v2ray';
o.description = _('Directory containing geoip.dat and geosite.dat. Leave empty for auto-detection.');

o = s.taboption('advanced', form.Value, 'v2ray_bin', _('Core binary (v2raya_core only)'));
o.placeholder = _('Auto-detect');
o.description = _('Path to v2raya_core. Leave empty to use the binary next to v2raya or in PATH. Only the matching v2raya_core is supported; Xray-core and sing-box use incompatible configuration formats.');

o = s.taboption('advanced', form.Value, 'v2ray_confdir', _('Extra configuration directory'));
o.placeholder = _('None');
o.description = _('Additional v2ray configuration files merged into the generated configuration.');

o = s.taboption('advanced', form.Value, 'gomemlimit', _('Go memory limit'));
o.placeholder = '64MiB';
o.default = '64MiB';
o.description = _('Soft memory limit for both v2raya and v2raya_core (GOMEMLIMIT). Use 0 to disable, or 96MiB on a larger router.');

o = s.taboption('advanced', form.Value, 'gomaxprocs', _('Go scheduler threads'));
o.datatype = 'uinteger';
o.placeholder = '3';
o.placeholder = '2';
o.default = '2';
o.description = _('GOMAXPROCS. 0 uses every CPU core; 2 is enough for most routers.');

o = s.option(form.Flag, 'log_disable_color', _('Disable log color output'));
o = s.taboption('advanced', form.Value, 'gogc', _('Go GC percent'));
o.datatype = 'uinteger';
o.placeholder = '0';
o.default = '0';
o.description = _('GOGC. 0 keeps the Go default; lower values use less memory and more CPU.');

o = s.option(form.Flag, 'log_disable_timestamp', _('Disable log timestamp'));
o = s.taboption('advanced', form.Value, 'nofile', _('Open file limit'));
o.datatype = 'uinteger';
o.placeholder = '16384';
o.default = '16384';
o.description = _('Maximum open file descriptors. 16384 is plenty for a home router and bounds a connection flood.');

return m.render();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,75 +1,77 @@
// SPDX-License-Identifier: Apache-2.0
'use strict';
'require dom';
'require fs';
'require poll';
'require uci';
'require ui';
'require view';

var LOG_PATH = '/var/log/v2raya/v2raya.log';
var MAX_LINES = 500;
var POLL_INTERVAL = 5;

return view.extend({
render: function() {
/* Thanks to luci-app-aria2 */
var css = ' \
#log_textarea { \
padding: 10px; \
text-align: left; \
} \
#log_textarea pre { \
padding: .5rem; \
word-break: break-all; \
margin: 0; \
} \
.description { \
background-color: #33ccff; \
}';
render: function () {
var logEl = E('pre', {
id: 'v2raya-log',
style: 'white-space:pre-wrap;word-break:break-all;max-height:65vh;overflow:auto;padding:8px;margin:0;background:rgba(0,0,0,0.04);border-radius:4px'
}, _('Loading…'));

var refresh = function () {
return L.resolveDefault(fs.read_direct(LOG_PATH, 'text'), null).then(function (text) {
if (text === null) {
dom.content(logEl, _('The log file does not exist yet. Start the service and try again.'));
return;
}

var log_textarea = E('div', { 'id': 'log_textarea' },
E('img', {
'src': L.resource('icons/loading.svg'),
'alt': _('Loading…'),
'style': 'vertical-align:middle'
}, _('Collecting data…'))
);
var lines = text.replace(/\s+$/, '').split('\n');
if (lines.length > MAX_LINES)
lines = lines.slice(-MAX_LINES);

var log_path = '/var/log/v2raya/v2raya.log';
var atBottom = (logEl.scrollTop + logEl.clientHeight + 20) >= logEl.scrollHeight;
dom.content(logEl, lines.join('\n') || _('The log is empty.'));

if (atBottom)
logEl.scrollTop = logEl.scrollHeight;
}).catch(function (err) {
dom.content(logEl, _('Unable to read the log: %s').format(err));
});
};

poll.add(L.bind(function() {
return fs.read_direct(log_path, 'text')
.then(function(res) {
var log = E('pre', { 'wrap': 'pre' }, [
res.trim() || _('Log is clean.')
]);
var refreshBtn = E('button', { class: 'btn cbi-button cbi-button-action' }, _('Refresh'));
var clearBtn = E('button', { class: 'btn cbi-button cbi-button-reset' }, _('Clear log'));

dom.content(log_textarea, log);
}).catch(function(err) {
var log;
refreshBtn.addEventListener('click', function () { refresh(); });
clearBtn.addEventListener('click', function () {
if (!confirm(_('Clear the v2rayA log file?')))
return;

if (err.toString().includes('NotFoundError'))
log = E('pre', { 'wrap': 'pre' }, [
_('Log file does not exist.')
]);
L.resolveDefault(fs.write(LOG_PATH, ''), null).then(function (res) {
if (res === null)
ui.addNotification(null, E('p', {}, _('Unable to clear the log file.')), 'danger');
else
log = E('pre', { 'wrap': 'pre' }, [
_('Unknown error: %s').format(err)
]);
ui.addNotification(null, E('p', {}, _('Log file cleared.')), 'info');

dom.content(log_textarea, log);
refresh();
});
}));
});

return E([
E('style', [ css ]),
E('div', {'class': 'cbi-map'}, [
E('div', {'class': 'cbi-section'}, [
log_textarea,
E('div', {'style': 'text-align:right'},
E('small', {}, _('Refresh every %d seconds.').format(L.env.pollinterval))
)
])
refresh();
poll.add(refresh, POLL_INTERVAL);

return E('div', { class: 'cbi-map' }, [
E('h2', {}, _('v2rayA log')),
E('div', { class: 'cbi-map-descr' },
_('Showing the last %d lines of %s. Refreshes every %d seconds.')
.format(MAX_LINES, LOG_PATH, POLL_INTERVAL)),
E('div', { class: 'cbi-section' }, [
logEl,
E('div', { style: 'margin-top:8px' }, [ refreshBtn, ' ', clearBtn ])
])
]);
},

handleSaveApply: null,
handleSave: null,
handleSaveApply: null,
handleReset: null
});
Loading