🌴 Sync 2026-03-05 23:51:42

This commit is contained in:
github-actions[bot] committed 2026-03-05 23:51:42 +08:00
1 parent 97c049ed0a
commit 0acff03804
14253 files changed
+3893239

No files matched your search

@@ -0,0 +1,157 @@
/* SPDX-License-Identifier: GPL-3.0-only
*
* Copyright (C) 2022 ImmortalWrt.org
*/
'use strict';
'require form';
'require poll';
'require rpc';
'require uci';
'require view';
'require tools.widgets as widgets';
const callServiceList = rpc.declare({
object: 'service',
method: 'list',
params: ['name'],
expect: { '': {} }
});
function getServiceStatus() {
return L.resolveDefault(callServiceList('zerotier'), {}).then(function(res) {
let isRunning = false;
try {
isRunning = res['zerotier']['instances']['instance1']['running'];
} catch (e) { }
return isRunning;
});
}
function renderStatus(isRunning) {
let spanTemp = '<em><span style="color:%s"><strong>%s %s</strong></span></em>';
let renderHTML;
if (isRunning)
renderHTML = String.format(spanTemp, 'green', _('ZeroTier'), _('RUNNING'));
else
renderHTML = String.format(spanTemp, 'red', _('ZeroTier'), _('NOT RUNNING'));
return renderHTML;
}
return view.extend({
render: function() {
let m, s, o;
m = new form.Map('zerotier', _('ZeroTier'),
_('ZeroTier is an open source, cross-platform and easy to use virtual LAN.'));
s = m.section(form.TypedSection);
s.anonymous = true;
s.render = function() {
poll.add(function() {
return L.resolveDefault(getServiceStatus()).then(function(res) {
let view = document.getElementById('service_status');
view.innerHTML = renderStatus(res);
});
});
return E('div', { class: 'cbi-section', id: 'status_bar' }, [
E('p', { id: 'service_status' }, _('Collecting data…'))
]);
}
s = m.section(form.NamedSection, 'global', 'zerotier', _('Global configuration'));
o = s.option(form.Flag, 'enabled', _('Enable'));
o = s.option(form.Value, 'port', _('Listen port'));
o.datatype = 'port';
o = s.option(form.Value, 'secret', _('Client secret'));
o.password = true;
o = s.option(form.Value, 'local_conf_path', _('Local config path'),
_('Path of the optional file local.conf (see <a target="_blank" href="%s">documentation</a>).').format(
'https://docs.zerotier.com/config/#local-configuration-options'));
o.value('/etc/zerotier.conf');
o = s.option(form.Value, 'config_path', _('Config path'),
_('Persistent configuration directory (to keep other configurations such as controller or moons, etc.).'));
o.value('/etc/zerotier');
o = s.option(form.Flag, 'copy_config_path', _('Copy config path'),
_('Copy the contents of the persistent configuration directory to memory instead of linking it, this avoids writing to flash.'));
o.depends({'config_path': '', '!reverse': true});
o = s.option(form.Flag, 'fw_allow_input', _('Allow input traffic'),
_('Allow input traffic to the ZeroTier daemon.'));
o = s.option(form.Button, '_panel', _('ZeroTier Central'),
_('Create or manage your ZeroTier network, and auth clients who could access.'));
o.inputtitle = _('Open website');
o.inputstyle = 'apply';
o.onclick = function() {
window.open("https://my.zerotier.com/network", '_blank');
}
s = m.section(form.GridSection, 'network', _('Network configuration'));
s.addremove = true;
s.rowcolors = true;
s.sortable = true;
s.nodescriptions = true;
o = s.option(form.Flag, 'enabled', _('Enable'));
o.default = o.enabled;
o.editable = true;
o = s.option(form.Value, 'id', _('Network ID'));
o.rmempty = false;
o.width = '20%';
o = s.option(form.Flag, 'allow_managed', _('Allow managed IP/route'),
_('Allow ZeroTier to set IP addresses and routes (local/private ranges only).'));
o.default = o.enabled;
o.editable = true;
o = s.option(form.Flag, 'allow_global', _('Allow global IP/route'),
_('Allow ZeroTier to set global/public/not-private range IPs and routes.'));
o.editable = true;
o = s.option(form.Flag, 'allow_default', _('Allow default route'),
_('Allow ZeroTier to set the default route on the system.'));
o.editable = true;
o = s.option(form.Flag, 'allow_dns', _('Allow DNS'),
_('Allow ZeroTier to set DNS servers.'));
o.editable = true;
o = s.option(form.Flag, 'fw_allow_input', _('Allow input'),
_('Allow input traffic from the ZeroTier network.'));
o.editable = true;
o = s.option(form.Flag, 'fw_allow_forward', _('Allow forward'),
_('Allow forward traffic from/to the ZeroTier network.'));
o.editable = true;
o = s.option(widgets.DeviceSelect, 'fw_forward_ifaces', _('Forward interfaces'),
_('Leave empty for all.'));
o.multiple = true;
o.noaliases = true;
o.depends('fw_allow_forward', '1');
o.modalonly = true;
o = s.option(form.Flag, 'fw_allow_masq', _('Masquerading'),
_('Enable network address and port translation (NAT) for outbound traffic for this network.'));
o.editable = true;
o = s.option(widgets.DeviceSelect, 'fw_masq_ifaces', _('Masquerade interfaces'),
_('Leave empty for all.'));
o.multiple = true;
o.noaliases = true;
o.depends('fw_allow_masq', '1');
o.modalonly = true;
return m.render();
}
});
@@ -0,0 +1,119 @@
/* SPDX-License-Identifier: GPL-3.0-only
*
* Copyright (C) 2022 ImmortalWrt.org
*/
'use strict';
'require fs';
'require ui';
'require view';
return view.extend({
load: function() {
return fs.exec('/sbin/ifconfig').then(function(res) {
if (res.code !== 0 || !res.stdout || res.stdout.trim() === '') {
ui.addNotification(null, E('p', {}, _('Unable to get interface info: %s.').format(res.message)));
return '';
}
var interfaces = res.stdout.match(/zt[a-z0-9]+/g);
if (!interfaces || interfaces.length === 0)
return 'No interface online.';
var promises = interfaces.map(function(name) {
return fs.exec('/sbin/ifconfig', [name]);
});
return Promise.all(promises).then(function(results) {
var data = results.map(function(res, index) {
if (res.code !== 0 || !res.stdout || res.stdout.trim() === '') {
ui.addNotification(null, E('p', {}, _('Unable to get interface %s info: %s.').format(interfaces[index], res.message)));
return null;
}
return {
name: interfaces[index],
stdout: res.stdout.trim()
};
}).filter(Boolean);
return data.map(function(info) {
var lines = info.stdout.split('\n');
var parsedInfo = {
name: info.name
};
lines.forEach(function(line) {
if (line.includes('HWaddr')) {
parsedInfo.mac = line.split('HWaddr')[1].trim().split(' ')[0];
} else if (line.includes('inet addr:')) {
parsedInfo.ipv4 = line.split('inet addr:')[1].trim().split(' ')[0];
} else if (line.includes('inet6 addr:')) {
parsedInfo.ipv6 = line.split('inet6 addr:')[1].trim().split('/')[0];
} else if (line.includes('MTU:')) {
parsedInfo.mtu = line.split('MTU:')[1].trim().split(' ')[0];
} else if (line.includes('RX bytes:')) {
var rxMatch = line.match(/RX bytes:\d+ \(([\d.]+\s*[a-zA-Z]+)\)/);
if (rxMatch && rxMatch[1]) {
parsedInfo.rxBytes = rxMatch[1];
}
var txMatch = line.match(/TX bytes:\d+ \(([\d.]+\s*[a-zA-Z]+)\)/);
if (txMatch && txMatch[1]) {
parsedInfo.txBytes = txMatch[1];
}
}
});
return parsedInfo;
});
});
});
},
render: function(data) {
var title = E('h2', {class: 'content'}, _('ZeroTier'));
var desc = E('div', {class: 'cbi-map-descr'}, _('ZeroTier is an open source, cross-platform and easy to use virtual LAN.'));
if (!Array.isArray(data)) {
return E('div', {}, [title, desc, E('div', {}, _('No interface online.'))]);
}
var rows = data.flatMap(function(interfaceData) {
return [
E('th', {class: 'th', colspan: '2'}, _('Network Interface Information')),
E('tr', {class: 'tr'}, [
E('td', {class: 'td left', width: '25%'}, _('Interface Name')),
E('td', {class: 'td left', width: '25%'}, interfaceData.name)
]),
E('tr', {class: 'tr'}, [
E('td', {class: 'td left', width: '25%'}, _('MAC Address')),
E('td', {class: 'td left', width: '25%'}, interfaceData.mac)
]),
E('tr', {class: 'tr'}, [
E('td', {class: 'td left', width: '25%'}, _('IPv4 Address')),
E('td', {class: 'td left', width: '25%'}, interfaceData.ipv4)
]),
E('tr', {class: 'tr'}, [
E('td', {class: 'td left', width: '25%'}, _('IPv6 Address')),
E('td', {class: 'td left', width: '25%'}, interfaceData.ipv6)
]),
E('tr', {class: 'tr'}, [
E('td', {class: 'td left', width: '25%'}, _('MTU')),
E('td', {class: 'td left', width: '25%'}, interfaceData.mtu)
]),
E('tr', {class: 'tr'}, [
E('td', {class: 'td left', width: '25%'}, _('Total Download')),
E('td', {class: 'td left', width: '25%'}, interfaceData.rxBytes)
]),
E('tr', {class: 'tr'}, [
E('td', {class: 'td left', width: '25%'}, _('Total Upload')),
E('td', {class: 'td left', width: '25%'}, interfaceData.txBytes)
])
];
});
return E('div', {}, [title, desc, E('table', { 'class': 'table' }, rows)]);
},
handleSaveApply: null,
handleSave: null,
handleReset: null
});