From 4f0bfe4250d0899117de7e540b32b09077abd5f8 Mon Sep 17 00:00:00 2001 From: acooler15 Date: Sat, 19 Oct 2024 14:14:26 +0800 Subject: [PATCH 1/3] update luci-app-zerotier for openwrt zerotier 1.14.0-2 --- applications/luci-app-zerotier/Makefile | 8 +- .../resources/view/zerotier/base.js | 273 ++++++++++++++++-- .../po/templates/zerotier.pot | 135 +++++++-- .../luci-app-zerotier/po/zh_Hans/zerotier.po | 142 +++++++-- .../luci-app-zerotier/po/zh_Hant/zerotier.po | 142 +++++++-- .../root/etc/config/zerotier | 20 -- .../zerotier.log => config/zerotier-extra} | 0 .../root/etc/hotplug.d/iface/40-zerotier | 13 +- .../root/etc/init.d/zerotier | 115 -------- .../luci-app-zerotier/root/etc/zerotier.start | 81 ++++-- .../share/rpcd/acl.d/luci-app-zerotier.json | 4 +- 11 files changed, 669 insertions(+), 264 deletions(-) delete mode 100644 applications/luci-app-zerotier/root/etc/config/zerotier rename applications/luci-app-zerotier/root/etc/{zerotier/zerotier.log => config/zerotier-extra} (100%) delete mode 100755 applications/luci-app-zerotier/root/etc/init.d/zerotier diff --git a/applications/luci-app-zerotier/Makefile b/applications/luci-app-zerotier/Makefile index d8dff010785..4854270e538 100644 --- a/applications/luci-app-zerotier/Makefile +++ b/applications/luci-app-zerotier/Makefile @@ -5,13 +5,7 @@ include $(TOPDIR)/rules.mk LUCI_TITLE:=LuCI for Zerotier -LUCI_DEPENDS:=+zerotier +jsonfilter +ucode -LUCI_PKGARCH:=all - -define Package/luci-app-zerotier/conffiles -/etc/config/zero/ -/etc/config/zerotier -endef +LUCI_DEPENDS:=+luci-base +zerotier include ../../luci.mk diff --git a/applications/luci-app-zerotier/htdocs/luci-static/resources/view/zerotier/base.js b/applications/luci-app-zerotier/htdocs/luci-static/resources/view/zerotier/base.js index a26d437d676..9bc6e031950 100644 --- a/applications/luci-app-zerotier/htdocs/luci-static/resources/view/zerotier/base.js +++ b/applications/luci-app-zerotier/htdocs/luci-static/resources/view/zerotier/base.js @@ -14,81 +14,292 @@ var callServiceList = rpc.declare({ object: 'service', method: 'list', params: ['name'], - expect: { '': {} } + expect: { '': {} }, }); + +function tidyExtra(data) { + var extra_sections = L.uci.sections('zerotier-extra', 'network'); + var sections = Object.values(data); + var section_ids = sections.length > 0 ? sections.map(section => section['id']) : []; + var remove_section_names = []; + for (var i = 0; i < extra_sections.length; i++) { + var idx = section_ids.indexOf(extra_sections[i]['id']); + if (idx === -1) { + remove_section_names.push(extra_sections[i]['.name']); + continue; + } + section_ids.splice(idx, 1); + var section = sections.splice(idx, 1)[0]; + // if (section.hasOwnProperty('') && section['auto_nat'] == '1') { + if (section?.['auto_nat'] == '1') { + L.uci.set('zerotier-extra', extra_sections[i]['.name'], 'auto_nat', '1'); + continue; + } + remove_section_names.push(extra_sections[i]['.name']); + } + + for (var i = 0; i < remove_section_names.length; i++) { + L.uci.remove('zerotier-extra', remove_section_names[i]); + } + + for (var i = 0; i < sections.length; i++) { + var section = sections[i]; + if (section?.['auto_nat'] == '1') { + var name = L.uci.add('zerotier-extra', section['.type']); + L.uci.set('zerotier-extra', name, 'id', section['id']); + L.uci.set('zerotier-extra', name, 'auto_nat', 1); + } + } +} + function getServiceStatus() { return L.resolveDefault(callServiceList('zerotier'), {}).then(function (res) { var isRunning = false; try { isRunning = res['zerotier']['instances']['instance1']['running']; - } catch (e) { } + } catch (e) {} return isRunning; }); } function renderStatus(isRunning) { - var spanTemp = '%s %s'; + var spanTemp = + '%s %s'; var renderHTML; if (isRunning) { renderHTML = String.format(spanTemp, 'green', _('ZeroTier'), _('RUNNING')); } else { - renderHTML = String.format(spanTemp, 'red', _('ZeroTier'), _('NOT RUNNING')); + renderHTML = String.format( + spanTemp, + 'red', + _('ZeroTier'), + _('NOT RUNNING') + ); } return renderHTML; } - +async function loadNetwork() { + await L.uci.load('zerotier', 'zerotier-extra'); +} return view.extend({ - load: function() { - return Promise.all([ - uci.load('zerotier') - ]); + // load: function () { + // return Promise.all([ + // L.uci.load('zerotier'), + // L.uci.load('zerotier-extra').then(async() => { + // return await L.uci.sections('zerotier-extra', 'network') + // }).catch(() => { + // return []; + // }) + // ]); + // }, + load: function () { + return L.uci.load(['zerotier', 'zerotier-extra']).then(data => { + var sections = uci.sections('zerotier', 'network'); + var extra_sections = uci.sections('zerotier-extra', 'network'); + var extra_configs = {}; + extra_sections.forEach(section => { + extra_configs[section['id']] = section; + }); + + sections.forEach(section => { + if (section['id'] in extra_configs) { + section['auto_nat'] = extra_configs[section['id']]['auto_nat']; + section['.extra_name'] = extra_configs[section['id']]['.name']; + } + }); + return { network: sections }; + }); }, - render: function(data) { + render: function (data) { var m, s, o; - m = new form.Map('zerotier', _('ZeroTier'), - _('ZeroTier is an open source, cross-platform and easy to use virtual LAN.')); + 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) { - var view = document.getElementById("service_status"); + var 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 ...')) + E('p', { id: 'service_status' }, _('Collecting data ...')), ]); - } - - s = m.section(form.NamedSection, 'sample_config', 'config'); + }; - o = s.option(form.Flag, 'enabled', _('Enable')); - o.default = o.disabled; + s = m.section(form.NamedSection, 'global', 'zerotier'); + o = s.option( + form.Flag, + 'enabled', + _('Enable'), + _('Sets whether ZeroTier is enabled or not') + ); o.rmempty = false; - o = s.option(form.DynamicList, 'join', _('Network ID')); - o.rmempty = false; + o = s.option( + form.Value, + 'port', + _('Listening Port'), + _('Sets the ZeroTier listening port (default 9993; set to 0 for random)') + ); + o.datatype = 'port'; + o.default = '9993'; - o = s.option(form.Flag, 'nat', _('Auto NAT clients'), - _('Allow ZeroTier clients access your LAN network.')); - o.default = o.disabled; - o.rmempty = false; + o = s.option( + form.Value, + 'secret', + _('Client Secret'), + _('Client secret (leave blank to generate a secret on first run)') + ); + o.datatype = 'string'; + o.rmempty = true; + + o = s.option( + form.Value, + 'local_conf_path', + _('Local Configuration Path'), + _( + 'Path of the optional file local.conf (see documentation at https://docs.zerotier.com/config#local-configuration-options)' + ) + ); - o = s.option(form.Button, '_panel', _('ZeroTier Central'), - _('Create or manage your ZeroTier network, and auth clients who could access.')); + o = s.option( + form.Value, + 'config_path', + _('Persistent Configuration Path'), + _( + 'Persistent configuration directory (to perform other configurations such as controller mode or moons, etc.)' + ) + ); + + // copy_config_path + o = s.option( + form.Flag, + 'copy_config_path', + _('Copy Configuration Directory'), + _( + 'Copy the contents of the persistent configuration directory to memory instead of linking it, this avoids writing to flash' + ) + ); + + 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'); - } + window.open('https://my.zerotier.com/network', '_blank'); + }; - return m.render(); - } + var netM, netS, netO; + netM = new form.JSONMap(data); + netS = netM.section( + form.GridSection, + 'network', + _('Networks'), + _( + 'Network configuration, you can have as many configurations as networks you want to join. see documentation at https://docs.zerotier.com/config/#network-specific-configuration' + ) + ); + netS.anonymous = true; + netS.addremove = true; + netS.sortable = true; + netS.nodescriptions = true; + netS.addbtntitle = _('Add new Network...'); + netS.handleModalSave = function (...args) { + var section_name = args[0].section; + var old_section = Object.assign({}, this.map.data.data[section_name]); + var res = form.GridSection.prototype.handleModalSave.apply(this, args); + var section_name = args[0].section; + var section = this.map.data.data[section_name]; + if ('addedSection' in this.map) { + var new_name = L.uci.add('zerotier', section['.type']); + for (var key in section) { + if (key.charAt(0) != '.' && key != 'auto_nat') { + L.uci.set('zerotier', new_name, key, section[key]); + } + } + section['.name'] = new_name; + this.map.data.data[new_name] = section; + delete this.map.data.data[section_name]; + } else { + for (var key in section) { + if (key.charAt(0) != '.' && key != 'auto_nat' && old_section[key] != section[key]) { + L.uci.set('zerotier', section_name, key, section[key]); + } + } + } + tidyExtra(this.map.data.data); + L.uci.save(); + return res; + }; + netS.handleRemove = function (section_id, ev) { + var res = form.GridSection.prototype.handleRemove.apply(this, [section_id,ev]); + L.uci.remove('zerotier', section_id); + tidyExtra(this.map.data.data); + L.uci.save(); + return res; + }; + netO = netS.option(form.Value, 'id', _('ID')); + netO = netS.option( + form.Flag, + 'allow_managed', + _('Allow Managed'), + _( + 'Allow ZeroTier to set IP Addresses and Routes ( local/private ranges only). Default Yes.' + ) + ); + netO.default = '1'; + + // allow_global + netS.option( + form.Flag, + 'allow_global', + _('Allow Global'), + _( + 'Allow ZeroTier to set Global/Public/Not-Private range IPs and Routes. Default No.' + ) + ); + // allow_default + netS.option( + form.Flag, + 'allow_default', + _('Allow Default'), + _('Allow ZeroTier to set the Default Route on the system. Default No.') + ); + // allow_dns + netS.option( + form.Flag, + 'allow_dns', + _('Allow DNS'), + _('Allow ZeroTier to set DNS servers. Default No.') + ); + // auto_nat + netO = netS.option( + form.Flag, + 'auto_nat', + _('Auto NAT clients'), + _('Allow ZeroTier clients access your LAN network.') + ); + netO.default = '0'; + + return Promise.all([m.render(), netM.render()]); + }, }); diff --git a/applications/luci-app-zerotier/po/templates/zerotier.pot b/applications/luci-app-zerotier/po/templates/zerotier.pot index b8619f45eac..fb575aa6975 100644 --- a/applications/luci-app-zerotier/po/templates/zerotier.pot +++ b/applications/luci-app-zerotier/po/templates/zerotier.pot @@ -1,11 +1,51 @@ msgid "" msgstr "Content-Type: text/plain; charset=UTF-8" -#: applications/luci-app-zerotier/htdocs/luci-static/resources/view/zerotier/base.js:80 +#: applications/luci-app-zerotier/htdocs/luci-static/resources/view/zerotier/base.js:225 +msgid "Add new Network..." +msgstr "" + +#: applications/luci-app-zerotier/htdocs/luci-static/resources/view/zerotier/base.js:291 +msgid "Allow DNS" +msgstr "" + +#: applications/luci-app-zerotier/htdocs/luci-static/resources/view/zerotier/base.js:284 +msgid "Allow Default" +msgstr "" + +#: applications/luci-app-zerotier/htdocs/luci-static/resources/view/zerotier/base.js:275 +msgid "Allow Global" +msgstr "" + +#: applications/luci-app-zerotier/htdocs/luci-static/resources/view/zerotier/base.js:264 +msgid "Allow Managed" +msgstr "" + +#: applications/luci-app-zerotier/htdocs/luci-static/resources/view/zerotier/base.js:299 msgid "Allow ZeroTier clients access your LAN network." msgstr "" -#: applications/luci-app-zerotier/htdocs/luci-static/resources/view/zerotier/base.js:79 +#: applications/luci-app-zerotier/htdocs/luci-static/resources/view/zerotier/base.js:292 +msgid "Allow ZeroTier to set DNS servers. Default No." +msgstr "" + +#: applications/luci-app-zerotier/htdocs/luci-static/resources/view/zerotier/base.js:277 +msgid "" +"Allow ZeroTier to set Global/Public/Not-Private range IPs and Routes. " +"Default No." +msgstr "" + +#: applications/luci-app-zerotier/htdocs/luci-static/resources/view/zerotier/base.js:266 +msgid "" +"Allow ZeroTier to set IP Addresses and Routes ( local/private ranges only). " +"Default Yes." +msgstr "" + +#: applications/luci-app-zerotier/htdocs/luci-static/resources/view/zerotier/base.js:285 +msgid "Allow ZeroTier to set the Default Route on the system. Default No." +msgstr "" + +#: applications/luci-app-zerotier/htdocs/luci-static/resources/view/zerotier/base.js:298 msgid "Auto NAT clients" msgstr "" @@ -13,16 +53,34 @@ msgstr "" msgid "Base settings" msgstr "" -#: applications/luci-app-zerotier/htdocs/luci-static/resources/view/zerotier/base.js:66 +#: applications/luci-app-zerotier/htdocs/luci-static/resources/view/zerotier/base.js:163 +msgid "Client Secret" +msgstr "" + +#: applications/luci-app-zerotier/htdocs/luci-static/resources/view/zerotier/base.js:164 +msgid "Client secret (leave blank to generate a secret on first run)" +msgstr "" + +#: applications/luci-app-zerotier/htdocs/luci-static/resources/view/zerotier/base.js:138 msgid "Collecting data ..." msgstr "" -#: applications/luci-app-zerotier/htdocs/luci-static/resources/view/zerotier/base.js:85 +#: applications/luci-app-zerotier/htdocs/luci-static/resources/view/zerotier/base.js:191 +msgid "Copy Configuration Directory" +msgstr "" + +#: applications/luci-app-zerotier/htdocs/luci-static/resources/view/zerotier/base.js:193 +msgid "" +"Copy the contents of the persistent configuration directory to memory " +"instead of linking it, this avoids writing to flash" +msgstr "" + +#: applications/luci-app-zerotier/htdocs/luci-static/resources/view/zerotier/base.js:202 msgid "" "Create or manage your ZeroTier network, and auth clients who could access." msgstr "" -#: applications/luci-app-zerotier/htdocs/luci-static/resources/view/zerotier/base.js:72 +#: applications/luci-app-zerotier/htdocs/luci-static/resources/view/zerotier/base.js:146 msgid "Enable" msgstr "" @@ -30,6 +88,10 @@ msgstr "" msgid "Grant access to ZeroTier configuration" msgstr "" +#: applications/luci-app-zerotier/htdocs/luci-static/resources/view/zerotier/base.js:260 +msgid "ID" +msgstr "" + #: applications/luci-app-zerotier/htdocs/luci-static/resources/view/zerotier/interface.js:91 msgid "IPv4 Address" msgstr "" @@ -46,6 +108,14 @@ msgstr "" msgid "Interface info" msgstr "" +#: applications/luci-app-zerotier/htdocs/luci-static/resources/view/zerotier/base.js:154 +msgid "Listening Port" +msgstr "" + +#: applications/luci-app-zerotier/htdocs/luci-static/resources/view/zerotier/base.js:172 +msgid "Local Configuration Path" +msgstr "" + #: applications/luci-app-zerotier/htdocs/luci-static/resources/view/zerotier/interface.js:87 msgid "MAC Address" msgstr "" @@ -54,30 +124,61 @@ msgstr "" msgid "MTU" msgstr "" -#: applications/luci-app-zerotier/htdocs/luci-static/resources/view/zerotier/base.js:36 +#: applications/luci-app-zerotier/htdocs/luci-static/resources/view/zerotier/base.js:77 msgid "NOT RUNNING" msgstr "" -#: applications/luci-app-zerotier/htdocs/luci-static/resources/view/zerotier/base.js:76 -msgid "Network ID" -msgstr "" - #: applications/luci-app-zerotier/htdocs/luci-static/resources/view/zerotier/interface.js:81 msgid "Network Interface Information" msgstr "" +#: applications/luci-app-zerotier/htdocs/luci-static/resources/view/zerotier/base.js:218 +msgid "" +"Network configuration, you can have as many configurations as networks you " +"want to join. see documentation at https://docs.zerotier.com/config/#network-" +"specific-configuration" +msgstr "" + +#: applications/luci-app-zerotier/htdocs/luci-static/resources/view/zerotier/base.js:216 +msgid "Networks" +msgstr "" + #: applications/luci-app-zerotier/htdocs/luci-static/resources/view/zerotier/interface.js:77 msgid "No interface online." msgstr "" -#: applications/luci-app-zerotier/htdocs/luci-static/resources/view/zerotier/base.js:86 +#: applications/luci-app-zerotier/htdocs/luci-static/resources/view/zerotier/base.js:205 msgid "Open website" msgstr "" -#: applications/luci-app-zerotier/htdocs/luci-static/resources/view/zerotier/base.js:34 +#: applications/luci-app-zerotier/htdocs/luci-static/resources/view/zerotier/base.js:174 +msgid "" +"Path of the optional file local.conf (see documentation at https://docs." +"zerotier.com/config#local-configuration-options)" +msgstr "" + +#: applications/luci-app-zerotier/htdocs/luci-static/resources/view/zerotier/base.js:181 +msgid "Persistent Configuration Path" +msgstr "" + +#: applications/luci-app-zerotier/htdocs/luci-static/resources/view/zerotier/base.js:183 +msgid "" +"Persistent configuration directory (to perform other configurations such as " +"controller mode or moons, etc.)" +msgstr "" + +#: applications/luci-app-zerotier/htdocs/luci-static/resources/view/zerotier/base.js:71 msgid "RUNNING" msgstr "" +#: applications/luci-app-zerotier/htdocs/luci-static/resources/view/zerotier/base.js:155 +msgid "Sets the ZeroTier listening port (default 9993; set to 0 for random)" +msgstr "" + +#: applications/luci-app-zerotier/htdocs/luci-static/resources/view/zerotier/base.js:147 +msgid "Sets whether ZeroTier is enabled or not" +msgstr "" + #: applications/luci-app-zerotier/htdocs/luci-static/resources/view/zerotier/interface.js:103 msgid "Total Download" msgstr "" @@ -94,19 +195,19 @@ msgstr "" msgid "Unable to get interface info: %s." msgstr "" -#: applications/luci-app-zerotier/htdocs/luci-static/resources/view/zerotier/base.js:34 -#: applications/luci-app-zerotier/htdocs/luci-static/resources/view/zerotier/base.js:36 -#: applications/luci-app-zerotier/htdocs/luci-static/resources/view/zerotier/base.js:52 +#: applications/luci-app-zerotier/htdocs/luci-static/resources/view/zerotier/base.js:71 +#: applications/luci-app-zerotier/htdocs/luci-static/resources/view/zerotier/base.js:76 +#: applications/luci-app-zerotier/htdocs/luci-static/resources/view/zerotier/base.js:121 #: applications/luci-app-zerotier/htdocs/luci-static/resources/view/zerotier/interface.js:73 #: applications/luci-app-zerotier/root/usr/share/luci/menu.d/luci-app-zerotier.json:3 msgid "ZeroTier" msgstr "" -#: applications/luci-app-zerotier/htdocs/luci-static/resources/view/zerotier/base.js:84 +#: applications/luci-app-zerotier/htdocs/luci-static/resources/view/zerotier/base.js:200 msgid "ZeroTier Central" msgstr "" -#: applications/luci-app-zerotier/htdocs/luci-static/resources/view/zerotier/base.js:53 +#: applications/luci-app-zerotier/htdocs/luci-static/resources/view/zerotier/base.js:123 #: applications/luci-app-zerotier/htdocs/luci-static/resources/view/zerotier/interface.js:74 msgid "ZeroTier is an open source, cross-platform and easy to use virtual LAN." msgstr "" diff --git a/applications/luci-app-zerotier/po/zh_Hans/zerotier.po b/applications/luci-app-zerotier/po/zh_Hans/zerotier.po index 76f51b53145..3cdc64d1d63 100644 --- a/applications/luci-app-zerotier/po/zh_Hans/zerotier.po +++ b/applications/luci-app-zerotier/po/zh_Hans/zerotier.po @@ -7,11 +7,51 @@ msgstr "" "MIME-Version: 1.0\n" "Content-Transfer-Encoding: 8bit\n" -#: applications/luci-app-zerotier/htdocs/luci-static/resources/view/zerotier/base.js:80 +#: applications/luci-app-zerotier/htdocs/luci-static/resources/view/zerotier/base.js:225 +msgid "Add new Network..." +msgstr "添加新网络" + +#: applications/luci-app-zerotier/htdocs/luci-static/resources/view/zerotier/base.js:291 +msgid "Allow DNS" +msgstr "Allow DNS" + +#: applications/luci-app-zerotier/htdocs/luci-static/resources/view/zerotier/base.js:284 +msgid "Allow Default" +msgstr "Allow Default" + +#: applications/luci-app-zerotier/htdocs/luci-static/resources/view/zerotier/base.js:275 +msgid "Allow Global" +msgstr "Allow Global" + +#: applications/luci-app-zerotier/htdocs/luci-static/resources/view/zerotier/base.js:264 +msgid "Allow Managed" +msgstr "Allow Managed" + +#: applications/luci-app-zerotier/htdocs/luci-static/resources/view/zerotier/base.js:299 msgid "Allow ZeroTier clients access your LAN network." msgstr "允许 ZeroTier 客户端访问您的局域网。" -#: applications/luci-app-zerotier/htdocs/luci-static/resources/view/zerotier/base.js:79 +#: applications/luci-app-zerotier/htdocs/luci-static/resources/view/zerotier/base.js:292 +msgid "Allow ZeroTier to set DNS servers. Default No." +msgstr "允许 ZeroTier 设置DNS服务器。默认为 No" + +#: applications/luci-app-zerotier/htdocs/luci-static/resources/view/zerotier/base.js:277 +msgid "" +"Allow ZeroTier to set Global/Public/Not-Private range IPs and Routes. " +"Default No." +msgstr "允许 ZeroTier 设置全局/公网/非私有网络的 IP 地址和路由。默认为 No" + +#: applications/luci-app-zerotier/htdocs/luci-static/resources/view/zerotier/base.js:266 +msgid "" +"Allow ZeroTier to set IP Addresses and Routes ( local/private ranges only). " +"Default Yes." +msgstr "允许 ZeroTier 设置 IP 地址和路由(仅限本地/私有网络)。默认为 Yes" + +#: applications/luci-app-zerotier/htdocs/luci-static/resources/view/zerotier/base.js:285 +msgid "Allow ZeroTier to set the Default Route on the system. Default No." +msgstr "允许 ZeroTier 设置系统的默认路由。默认为 No" + +#: applications/luci-app-zerotier/htdocs/luci-static/resources/view/zerotier/base.js:298 msgid "Auto NAT clients" msgstr "自动客户端 NAT" @@ -19,16 +59,34 @@ msgstr "自动客户端 NAT" msgid "Base settings" msgstr "基本设置" -#: applications/luci-app-zerotier/htdocs/luci-static/resources/view/zerotier/base.js:66 +#: applications/luci-app-zerotier/htdocs/luci-static/resources/view/zerotier/base.js:163 +msgid "Client Secret" +msgstr "客户端 Secret" + +#: applications/luci-app-zerotier/htdocs/luci-static/resources/view/zerotier/base.js:164 +msgid "Client secret (leave blank to generate a secret on first run)" +msgstr "客户端 Secret (留空时将在第一次运行时生成秘密)" + +#: applications/luci-app-zerotier/htdocs/luci-static/resources/view/zerotier/base.js:138 msgid "Collecting data ..." msgstr "收集数据中 ..." -#: applications/luci-app-zerotier/htdocs/luci-static/resources/view/zerotier/base.js:85 +#: applications/luci-app-zerotier/htdocs/luci-static/resources/view/zerotier/base.js:191 +msgid "Copy Configuration Directory" +msgstr "复制配置目录" + +#: applications/luci-app-zerotier/htdocs/luci-static/resources/view/zerotier/base.js:193 +msgid "" +"Copy the contents of the persistent configuration directory to memory " +"instead of linking it, this avoids writing to flash" +msgstr "将持久配置目录的内容复制到内存,而不是链接它,这样可以避免写入闪存中" + +#: applications/luci-app-zerotier/htdocs/luci-static/resources/view/zerotier/base.js:202 msgid "" "Create or manage your ZeroTier network, and auth clients who could access." msgstr "创建或管理您的 ZeroTier 网络,并允许客户端接入。" -#: applications/luci-app-zerotier/htdocs/luci-static/resources/view/zerotier/base.js:72 +#: applications/luci-app-zerotier/htdocs/luci-static/resources/view/zerotier/base.js:146 msgid "Enable" msgstr "启用" @@ -36,6 +94,10 @@ msgstr "启用" msgid "Grant access to ZeroTier configuration" msgstr "授予访问 ZeroTier 配置的权限" +#: applications/luci-app-zerotier/htdocs/luci-static/resources/view/zerotier/base.js:260 +msgid "ID" +msgstr "ID" + #: applications/luci-app-zerotier/htdocs/luci-static/resources/view/zerotier/interface.js:91 msgid "IPv4 Address" msgstr "IPv4 地址" @@ -52,6 +114,14 @@ msgstr "接口名称" msgid "Interface info" msgstr "接口信息" +#: applications/luci-app-zerotier/htdocs/luci-static/resources/view/zerotier/base.js:154 +msgid "Listening Port" +msgstr "监听端口" + +#: applications/luci-app-zerotier/htdocs/luci-static/resources/view/zerotier/base.js:172 +msgid "Local Configuration Path" +msgstr "本地配置路径" + #: applications/luci-app-zerotier/htdocs/luci-static/resources/view/zerotier/interface.js:87 msgid "MAC Address" msgstr "MAC 地址" @@ -60,30 +130,65 @@ msgstr "MAC 地址" msgid "MTU" msgstr "MTU" -#: applications/luci-app-zerotier/htdocs/luci-static/resources/view/zerotier/base.js:36 +#: applications/luci-app-zerotier/htdocs/luci-static/resources/view/zerotier/base.js:77 msgid "NOT RUNNING" msgstr "未运行" -#: applications/luci-app-zerotier/htdocs/luci-static/resources/view/zerotier/base.js:76 -msgid "Network ID" -msgstr "网络 ID" - #: applications/luci-app-zerotier/htdocs/luci-static/resources/view/zerotier/interface.js:81 msgid "Network Interface Information" msgstr "网络接口信息" +#: applications/luci-app-zerotier/htdocs/luci-static/resources/view/zerotier/base.js:218 +msgid "" +"Network configuration, you can have as many configurations as networks you " +"want to join. see documentation at https://docs.zerotier.com/config/#network-" +"specific-configuration" +msgstr "" +"网络配置,可以设置多个想要加入的网络。详见文档https://docs.zerotier.com/" +"config/#network-specific-configuration" + +#: applications/luci-app-zerotier/htdocs/luci-static/resources/view/zerotier/base.js:216 +msgid "Networks" +msgstr "网络" + #: applications/luci-app-zerotier/htdocs/luci-static/resources/view/zerotier/interface.js:77 msgid "No interface online." msgstr "没有在线的接口。" -#: applications/luci-app-zerotier/htdocs/luci-static/resources/view/zerotier/base.js:86 +#: applications/luci-app-zerotier/htdocs/luci-static/resources/view/zerotier/base.js:205 msgid "Open website" msgstr "打开网站" -#: applications/luci-app-zerotier/htdocs/luci-static/resources/view/zerotier/base.js:34 +#: applications/luci-app-zerotier/htdocs/luci-static/resources/view/zerotier/base.js:174 +msgid "" +"Path of the optional file local.conf (see documentation at https://docs." +"zerotier.com/config#local-configuration-options)" +msgstr "" +"可选文件 local.conf 的路径(详见文档https://docs.zerotier.com/config#local-" +"configuration-options)" + +#: applications/luci-app-zerotier/htdocs/luci-static/resources/view/zerotier/base.js:181 +msgid "Persistent Configuration Path" +msgstr "持久配置路径" + +#: applications/luci-app-zerotier/htdocs/luci-static/resources/view/zerotier/base.js:183 +msgid "" +"Persistent configuration directory (to perform other configurations such as " +"controller mode or moons, etc.)" +msgstr "持久配置目录(用于执行其他配置,如 controller 模式或 moon 等)" + +#: applications/luci-app-zerotier/htdocs/luci-static/resources/view/zerotier/base.js:71 msgid "RUNNING" msgstr "运行中" +#: applications/luci-app-zerotier/htdocs/luci-static/resources/view/zerotier/base.js:155 +msgid "Sets the ZeroTier listening port (default 9993; set to 0 for random)" +msgstr "设置 ZeroTier 监听端口(默认为9993;为0时将随机设置端口)" + +#: applications/luci-app-zerotier/htdocs/luci-static/resources/view/zerotier/base.js:147 +msgid "Sets whether ZeroTier is enabled or not" +msgstr "是否启用 ZeroTier" + #: applications/luci-app-zerotier/htdocs/luci-static/resources/view/zerotier/interface.js:103 msgid "Total Download" msgstr "总下载" @@ -100,19 +205,22 @@ msgstr "无法获取接口 %s 的信息:%s。" msgid "Unable to get interface info: %s." msgstr "无法获取接口信息:%s。" -#: applications/luci-app-zerotier/htdocs/luci-static/resources/view/zerotier/base.js:34 -#: applications/luci-app-zerotier/htdocs/luci-static/resources/view/zerotier/base.js:36 -#: applications/luci-app-zerotier/htdocs/luci-static/resources/view/zerotier/base.js:52 +#: applications/luci-app-zerotier/htdocs/luci-static/resources/view/zerotier/base.js:71 +#: applications/luci-app-zerotier/htdocs/luci-static/resources/view/zerotier/base.js:76 +#: applications/luci-app-zerotier/htdocs/luci-static/resources/view/zerotier/base.js:121 #: applications/luci-app-zerotier/htdocs/luci-static/resources/view/zerotier/interface.js:73 #: applications/luci-app-zerotier/root/usr/share/luci/menu.d/luci-app-zerotier.json:3 msgid "ZeroTier" msgstr "ZeroTier" -#: applications/luci-app-zerotier/htdocs/luci-static/resources/view/zerotier/base.js:84 +#: applications/luci-app-zerotier/htdocs/luci-static/resources/view/zerotier/base.js:200 msgid "ZeroTier Central" msgstr "ZeroTier 管理中心" -#: applications/luci-app-zerotier/htdocs/luci-static/resources/view/zerotier/base.js:53 +#: applications/luci-app-zerotier/htdocs/luci-static/resources/view/zerotier/base.js:123 #: applications/luci-app-zerotier/htdocs/luci-static/resources/view/zerotier/interface.js:74 msgid "ZeroTier is an open source, cross-platform and easy to use virtual LAN." msgstr "ZeroTier 是一个开源、跨平台且易于使用的虚拟局域网 VPN。" + +#~ msgid "Network ID" +#~ msgstr "网络 ID" diff --git a/applications/luci-app-zerotier/po/zh_Hant/zerotier.po b/applications/luci-app-zerotier/po/zh_Hant/zerotier.po index 9a6f0b3e7a4..284f4c7f4e3 100644 --- a/applications/luci-app-zerotier/po/zh_Hant/zerotier.po +++ b/applications/luci-app-zerotier/po/zh_Hant/zerotier.po @@ -7,11 +7,51 @@ msgstr "" "MIME-Version: 1.0\n" "Content-Transfer-Encoding: 8bit\n" -#: applications/luci-app-zerotier/htdocs/luci-static/resources/view/zerotier/base.js:80 +#: applications/luci-app-zerotier/htdocs/luci-static/resources/view/zerotier/base.js:225 +msgid "Add new Network..." +msgstr "新增網路" + +#: applications/luci-app-zerotier/htdocs/luci-static/resources/view/zerotier/base.js:291 +msgid "Allow DNS" +msgstr "Allow DNS" + +#: applications/luci-app-zerotier/htdocs/luci-static/resources/view/zerotier/base.js:284 +msgid "Allow Default" +msgstr "Allow Default" + +#: applications/luci-app-zerotier/htdocs/luci-static/resources/view/zerotier/base.js:275 +msgid "Allow Global" +msgstr "Allow Global" + +#: applications/luci-app-zerotier/htdocs/luci-static/resources/view/zerotier/base.js:264 +msgid "Allow Managed" +msgstr "Allow Managed" + +#: applications/luci-app-zerotier/htdocs/luci-static/resources/view/zerotier/base.js:299 msgid "Allow ZeroTier clients access your LAN network." msgstr "允許 ZeroTier 用戶端訪問您的區域網路" -#: applications/luci-app-zerotier/htdocs/luci-static/resources/view/zerotier/base.js:79 +#: applications/luci-app-zerotier/htdocs/luci-static/resources/view/zerotier/base.js:292 +msgid "Allow ZeroTier to set DNS servers. Default No." +msgstr "允許 ZeroTier 設定 DNS 伺服器。預設為 No" + +#: applications/luci-app-zerotier/htdocs/luci-static/resources/view/zerotier/base.js:277 +msgid "" +"Allow ZeroTier to set Global/Public/Not-Private range IPs and Routes. " +"Default No." +msgstr "允許 ZeroTier 設定全域/公用/非私有範圍 IP 和路由。預設為 No" + +#: applications/luci-app-zerotier/htdocs/luci-static/resources/view/zerotier/base.js:266 +msgid "" +"Allow ZeroTier to set IP Addresses and Routes ( local/private ranges only). " +"Default Yes." +msgstr "允許 ZeroTier 設定 IP 位址和路由(僅限本地/專用範圍)。預設為 Yes" + +#: applications/luci-app-zerotier/htdocs/luci-static/resources/view/zerotier/base.js:285 +msgid "Allow ZeroTier to set the Default Route on the system. Default No." +msgstr "允許 ZeroTier 設定係統上的預設路由。預設為 No" + +#: applications/luci-app-zerotier/htdocs/luci-static/resources/view/zerotier/base.js:298 msgid "Auto NAT clients" msgstr "自動 NAT 用戶端" @@ -19,16 +59,34 @@ msgstr "自動 NAT 用戶端" msgid "Base settings" msgstr "基礎設定" -#: applications/luci-app-zerotier/htdocs/luci-static/resources/view/zerotier/base.js:66 +#: applications/luci-app-zerotier/htdocs/luci-static/resources/view/zerotier/base.js:163 +msgid "Client Secret" +msgstr "用戶端 Secret" + +#: applications/luci-app-zerotier/htdocs/luci-static/resources/view/zerotier/base.js:164 +msgid "Client secret (leave blank to generate a secret on first run)" +msgstr "客戶端 Secret (留空以在首次運行時產生密碼)" + +#: applications/luci-app-zerotier/htdocs/luci-static/resources/view/zerotier/base.js:138 msgid "Collecting data ..." msgstr "收集資料中..." -#: applications/luci-app-zerotier/htdocs/luci-static/resources/view/zerotier/base.js:85 +#: applications/luci-app-zerotier/htdocs/luci-static/resources/view/zerotier/base.js:191 +msgid "Copy Configuration Directory" +msgstr "複製配置目錄" + +#: applications/luci-app-zerotier/htdocs/luci-static/resources/view/zerotier/base.js:193 +msgid "" +"Copy the contents of the persistent configuration directory to memory " +"instead of linking it, this avoids writing to flash" +msgstr "將持久配置目錄的內容複製到記憶體而不是連結它,這樣可以避免寫入閃存" + +#: applications/luci-app-zerotier/htdocs/luci-static/resources/view/zerotier/base.js:202 msgid "" "Create or manage your ZeroTier network, and auth clients who could access." msgstr "新建或管理您的 ZeroTier 網路,並授權用戶端訪問" -#: applications/luci-app-zerotier/htdocs/luci-static/resources/view/zerotier/base.js:72 +#: applications/luci-app-zerotier/htdocs/luci-static/resources/view/zerotier/base.js:146 msgid "Enable" msgstr "啟用" @@ -36,6 +94,10 @@ msgstr "啟用" msgid "Grant access to ZeroTier configuration" msgstr "允許訪問 ZeroTier 的配置" +#: applications/luci-app-zerotier/htdocs/luci-static/resources/view/zerotier/base.js:260 +msgid "ID" +msgstr "ID" + #: applications/luci-app-zerotier/htdocs/luci-static/resources/view/zerotier/interface.js:91 msgid "IPv4 Address" msgstr "IPv4 位址" @@ -52,6 +114,14 @@ msgstr "介面名稱" msgid "Interface info" msgstr "介面資訊" +#: applications/luci-app-zerotier/htdocs/luci-static/resources/view/zerotier/base.js:154 +msgid "Listening Port" +msgstr "監聽埠號" + +#: applications/luci-app-zerotier/htdocs/luci-static/resources/view/zerotier/base.js:172 +msgid "Local Configuration Path" +msgstr "本地配置路徑" + #: applications/luci-app-zerotier/htdocs/luci-static/resources/view/zerotier/interface.js:87 msgid "MAC Address" msgstr "MAC 位址" @@ -60,30 +130,65 @@ msgstr "MAC 位址" msgid "MTU" msgstr "MTU" -#: applications/luci-app-zerotier/htdocs/luci-static/resources/view/zerotier/base.js:36 +#: applications/luci-app-zerotier/htdocs/luci-static/resources/view/zerotier/base.js:77 msgid "NOT RUNNING" msgstr "尚未執行" -#: applications/luci-app-zerotier/htdocs/luci-static/resources/view/zerotier/base.js:76 -msgid "Network ID" -msgstr "網路 ID" - #: applications/luci-app-zerotier/htdocs/luci-static/resources/view/zerotier/interface.js:81 msgid "Network Interface Information" msgstr "網路介面資訊" +#: applications/luci-app-zerotier/htdocs/luci-static/resources/view/zerotier/base.js:218 +msgid "" +"Network configuration, you can have as many configurations as networks you " +"want to join. see documentation at https://docs.zerotier.com/config/#network-" +"specific-configuration" +msgstr "" +"網路配置,可以設定多個想要加入的網路。詳見文檔https://docs.zerotier.com/" +"config/#network-specific-configuration" + +#: applications/luci-app-zerotier/htdocs/luci-static/resources/view/zerotier/base.js:216 +msgid "Networks" +msgstr "網路" + #: applications/luci-app-zerotier/htdocs/luci-static/resources/view/zerotier/interface.js:77 msgid "No interface online." msgstr "沒有介面在線上。" -#: applications/luci-app-zerotier/htdocs/luci-static/resources/view/zerotier/base.js:86 +#: applications/luci-app-zerotier/htdocs/luci-static/resources/view/zerotier/base.js:205 msgid "Open website" msgstr "開啟網站" -#: applications/luci-app-zerotier/htdocs/luci-static/resources/view/zerotier/base.js:34 +#: applications/luci-app-zerotier/htdocs/luci-static/resources/view/zerotier/base.js:174 +msgid "" +"Path of the optional file local.conf (see documentation at https://docs." +"zerotier.com/config#local-configuration-options)" +msgstr "" +"選用文件 local.conf 的路徑(詳見文檔https://docs.zerotier.com/config#local-" +"configuration-options)" + +#: applications/luci-app-zerotier/htdocs/luci-static/resources/view/zerotier/base.js:181 +msgid "Persistent Configuration Path" +msgstr "持久配置路徑" + +#: applications/luci-app-zerotier/htdocs/luci-static/resources/view/zerotier/base.js:183 +msgid "" +"Persistent configuration directory (to perform other configurations such as " +"controller mode or moons, etc.)" +msgstr "持久配置目錄(用於執行其他配置,例如 controller 模式或 moon 等)" + +#: applications/luci-app-zerotier/htdocs/luci-static/resources/view/zerotier/base.js:71 msgid "RUNNING" msgstr "正在執行" +#: applications/luci-app-zerotier/htdocs/luci-static/resources/view/zerotier/base.js:155 +msgid "Sets the ZeroTier listening port (default 9993; set to 0 for random)" +msgstr "設定ZeroTier監聽埠號(預設為9993;為0時將隨機設定監聽埠號)" + +#: applications/luci-app-zerotier/htdocs/luci-static/resources/view/zerotier/base.js:147 +msgid "Sets whether ZeroTier is enabled or not" +msgstr "是否啟用 ZeroTier" + #: applications/luci-app-zerotier/htdocs/luci-static/resources/view/zerotier/interface.js:103 msgid "Total Download" msgstr "總下載量" @@ -100,19 +205,22 @@ msgstr "無法取得介面 %s 的資訊:%s" msgid "Unable to get interface info: %s." msgstr "無法取得介面資訊:%s" -#: applications/luci-app-zerotier/htdocs/luci-static/resources/view/zerotier/base.js:34 -#: applications/luci-app-zerotier/htdocs/luci-static/resources/view/zerotier/base.js:36 -#: applications/luci-app-zerotier/htdocs/luci-static/resources/view/zerotier/base.js:52 +#: applications/luci-app-zerotier/htdocs/luci-static/resources/view/zerotier/base.js:71 +#: applications/luci-app-zerotier/htdocs/luci-static/resources/view/zerotier/base.js:76 +#: applications/luci-app-zerotier/htdocs/luci-static/resources/view/zerotier/base.js:121 #: applications/luci-app-zerotier/htdocs/luci-static/resources/view/zerotier/interface.js:73 #: applications/luci-app-zerotier/root/usr/share/luci/menu.d/luci-app-zerotier.json:3 msgid "ZeroTier" msgstr "ZeroTier" -#: applications/luci-app-zerotier/htdocs/luci-static/resources/view/zerotier/base.js:84 +#: applications/luci-app-zerotier/htdocs/luci-static/resources/view/zerotier/base.js:200 msgid "ZeroTier Central" msgstr "ZeroTier 管理中心" -#: applications/luci-app-zerotier/htdocs/luci-static/resources/view/zerotier/base.js:53 +#: applications/luci-app-zerotier/htdocs/luci-static/resources/view/zerotier/base.js:123 #: applications/luci-app-zerotier/htdocs/luci-static/resources/view/zerotier/interface.js:74 msgid "ZeroTier is an open source, cross-platform and easy to use virtual LAN." msgstr "ZeroTier 是一個開源、跨平台且易於使用的虛擬區域網路 VPN" + +#~ msgid "Network ID" +#~ msgstr "網路 ID" diff --git a/applications/luci-app-zerotier/root/etc/config/zerotier b/applications/luci-app-zerotier/root/etc/config/zerotier deleted file mode 100644 index 34b1ad347ed..00000000000 --- a/applications/luci-app-zerotier/root/etc/config/zerotier +++ /dev/null @@ -1,20 +0,0 @@ - -config zerotier sample_config - option enabled 0 - - # persistent configuration folder (for ZT controller mode) - #option config_path '/etc/zerotier' - # copy to RAM to prevent writing to flash (for ZT controller mode) - #option copy_config_path '1' - - #option port '9993' - - # path to the local.conf - #option local_conf '/etc/zerotier.conf' - - # Generate secret on first start - option secret '' - - # Join a public network called Earth - list join '8056c2e21c000001' - #list join '' diff --git a/applications/luci-app-zerotier/root/etc/zerotier/zerotier.log b/applications/luci-app-zerotier/root/etc/config/zerotier-extra similarity index 100% rename from applications/luci-app-zerotier/root/etc/zerotier/zerotier.log rename to applications/luci-app-zerotier/root/etc/config/zerotier-extra diff --git a/applications/luci-app-zerotier/root/etc/hotplug.d/iface/40-zerotier b/applications/luci-app-zerotier/root/etc/hotplug.d/iface/40-zerotier index 6e977a11269..0485132a977 100644 --- a/applications/luci-app-zerotier/root/etc/hotplug.d/iface/40-zerotier +++ b/applications/luci-app-zerotier/root/etc/hotplug.d/iface/40-zerotier @@ -1,9 +1,8 @@ #!/bin/sh +[ "$ACTION" = add ] || exit 0 +if echo "$DEVICENAME" | grep -q "^zt"; then + /etc/zerotier.start > /dev/null 2>&1 & +else + exit 0 +fi -zero_enable="$(uci get zerotier.sample_config.enabled)" -nat_enable="$(uci get zerotier.sample_config.nat)" - -[ "$ACTION" = ifup -o "$ACTION" = ifupdate ] || exit 0 -[ "$ACTION" = ifupdate -a -z "$IFUPDATE_ADDRESSES" -a -z "$IFUPDATE_DATA" ] && exit 0 -[ "$zero_enable" -eq "1" -a "${nat_enable}" -eq "1" ] || exit 0 -/etc/zerotier.start > /tmp/zero.log 2>&1 & diff --git a/applications/luci-app-zerotier/root/etc/init.d/zerotier b/applications/luci-app-zerotier/root/etc/init.d/zerotier deleted file mode 100755 index 715df14d0c2..00000000000 --- a/applications/luci-app-zerotier/root/etc/init.d/zerotier +++ /dev/null @@ -1,115 +0,0 @@ -#!/bin/sh /etc/rc.common - -START=99 - -USE_PROCD=1 - -PROG=/usr/bin/zerotier-one -CONFIG_PATH=/var/lib/zerotier-one - -service_triggers() { - procd_add_reload_trigger "zerotier" - procd_add_interface_trigger "interface.*.up" wan /etc/init.d/zerotier restart -} - -section_enabled() { - config_get_bool enabled "$1" 'enabled' 0 - [ $enabled -gt 0 ] -} - -start_instance() { - local cfg="$1" - local port secret config_path - local ARGS="" - - if ! section_enabled "$cfg"; then - echo "disabled in config" - return 1 - fi - - [ -d /etc/config/zero ] || mkdir -p /etc/config/zero - config_path=/etc/config/zero - - config_get_bool port $cfg 'port' - config_get secret $cfg 'secret' - - # Remove existing link or folder - rm -rf $CONFIG_PATH - - # Create link from CONFIG_PATH to config_path - if [ -n "$config_path" -a "$config_path" != $CONFIG_PATH ]; then - if [ ! -d "$config_path" ]; then - echo "ZeroTier config_path does not exist: $config_path" - return - fi - - ln -s $config_path $CONFIG_PATH - fi - - mkdir -p $CONFIG_PATH/networks.d - - if [ -n "$port" ]; then - ARGS="$ARGS -p$port" - fi - - if [ "$secret" = "generate" ]; then - echo "Generate secret - please wait..." - local sf="/tmp/zt.$cfg.secret" - - zerotier-idtool generate "$sf" > /dev/null - [ $? -ne 0 ] && return 1 - - secret="$(cat $sf)" - rm "$sf" - - uci set zerotier.$cfg.secret="$secret" - uci commit zerotier - fi - - if [ -n "$secret" ]; then - echo "$secret" > $CONFIG_PATH/identity.secret - # make sure there is not previous identity.public - rm -f $CONFIG_PATH/identity.public - fi - - add_join() { - # an (empty) config file will cause ZT to join a network - touch $CONFIG_PATH/networks.d/$1.conf - } - - config_list_foreach $cfg 'join' add_join - - procd_open_instance - procd_set_param command $PROG $ARGS $CONFIG_PATH - procd_set_param stderr 1 - procd_close_instance -} - -start_service() { - config_load 'zerotier' - config_foreach start_instance 'zerotier' - touch /tmp/zero.log && /etc/zerotier.start > /tmp/zero.log 2>&1 & -} - -stop_instance() { - rm -f /tmp/zero.log - local cfg="$1" - - rm -f "/usr/share/nftables.d/chain-pre/forward/zerotier.nft" "/usr/share/nftables.d/chain-pre/srcnat/zerotier.nft" - fw4 reload - echo "zt interface rules removed!" > /tmp/zero.log 2>&1 & - - # Remove existing link or folder - rm -f $CONFIG_PATH/networks.d/*.conf - rm -rf $CONFIG_PATH -} - -stop_service() { - config_load 'zerotier' - config_foreach stop_instance 'zerotier' -} - -reload_service() { - stop - start -} diff --git a/applications/luci-app-zerotier/root/etc/zerotier.start b/applications/luci-app-zerotier/root/etc/zerotier.start index 4eaa6c2a4a4..4ece40262ea 100755 --- a/applications/luci-app-zerotier/root/etc/zerotier.start +++ b/applications/luci-app-zerotier/root/etc/zerotier.start @@ -1,37 +1,56 @@ #!/bin/sh -zero_enable="$(uci get zerotier.sample_config.enabled)" -[ "$zero_enable" -eq "1" ] || exit 1 - -count=0 -[ -f "/tmp/zero.log" ] && { - while [ -z "$(ifconfig | grep 'zt' | awk '{print $1}')" ] - do - sleep 2 - let count++ - [ "$count" -lt 5 ] || exit 19 - done -} +. /lib/functions.sh +/etc/init.d/zerotier running +[ "$?" -eq "0" ] || exit 1 + +# see https://openwrt.org/docs/guide-user/firewall/firewall_configuration nft_incdir="/usr/share/nftables.d/chain-pre" -rm -f "$nft_incdir/input/zerotier.nft" "$nft_incdir/forward/zerotier.nft" "$$nft_incdir/srcnat/zerotier.nft" - -nat_enable="$(uci get zerotier.sample_config.nat)" -[ "$nat_enable" -eq "1" ] && { - [ -d "$nft_incdir/input" ] || mkdir -p "$nft_incdir/input" - [ -d "$nft_incdir/forward" ] || mkdir -p "$nft_incdir/forward" - [ -d "$nft_incdir/srcnat" ] || mkdir -p "$nft_incdir/srcnat" - for i in $(ifconfig | grep 'zt' | awk '{print $1}') - do - ip_segment="$(ip route | grep "dev $i proto kernel" | awk '{print $1}')" - echo "iifname $i counter accept comment \"!fw4: Zerotier allow inbound $i\"" >> "$nft_incdir/input/zerotier.nft" - echo "iifname $i counter accept comment \"!fw4: Zerotier allow inbound forward $i\"" >> "$nft_incdir/forward/zerotier.nft" - echo "oifname $i counter accept comment \"!fw4: Zerotier allow outbound forward $i\"" >> "$nft_incdir/forward/zerotier.nft" - echo "oifname $i counter masquerade comment \"!fw4: Zerotier $i outbound postrouting masq\"" >> "$nft_incdir/srcnat/zerotier.nft" +rm -f "$nft_incdir/input/zerotier.nft" "$nft_incdir/forward/zerotier.nft" "$nft_incdir/srcnat/zerotier.nft" + +[ -d "$nft_incdir/input" ] || mkdir -p "$nft_incdir/input" + +primaryPort=$(zerotier-cli -j info 2>&1|jsonfilter -q -e '@.config.settings.primaryPort') +if [ -n "$primaryPort" ]; then + echo "udp dport $primaryPort counter accept comment \"!fw4: Allow-ZeroTier-Inbound(primaryPort)\"" >> "$nft_incdir/input/zerotier.nft" + logger -t "zerotier" "primaryPort $primaryPort rules added!" +fi + +secondaryPort=$(zerotier-cli -j info 2>&1|jsonfilter -q -e '@.config.settings.secondaryPort') +if [ -n "$secondaryPort" ]; then + echo "udp dport $secondaryPort counter accept comment \"!fw4: Allow-ZeroTier-Inbound(secondaryPort)\"" >> "$nft_incdir/input/zerotier.nft" + logger -t "zerotier" "secondaryPort $secondaryPort rules added!" +fi + +zerotier_nat() { + local cfg="$1" + local id auto_nat + local portDeviceName ip_segment + config_get id "$cfg" 'id' + config_get_bool auto_nat "$cfg" 'auto_nat' 0 + echo "id $id" + if [ -n "$id" -a "$auto_nat" -eq "1" ]; then + portDeviceName=$(zerotier-cli -j listnetworks 2>&1|jsonfilter -q -e "@[@.nwid=\"$id\"].portDeviceName") + [ -n "$portDeviceName" ] || return 0 + echo "$portDeviceName" + [ -d "$nft_incdir/input" ] || mkdir -p "$nft_incdir/input" + [ -d "$nft_incdir/forward" ] || mkdir -p "$nft_incdir/forward" + [ -d "$nft_incdir/srcnat" ] || mkdir -p "$nft_incdir/srcnat" + ip_segment="$(ip route | grep "dev $portDeviceName proto kernel" | awk '{print $1}')" + echo "iifname $portDeviceName counter accept comment \"!fw4: Zerotier allow inbound $portDeviceName\"" >> "$nft_incdir/input/zerotier.nft" + echo "iifname $portDeviceName counter accept comment \"!fw4: Zerotier allow inbound forward $portDeviceName\"" >> "$nft_incdir/forward/zerotier.nft" + echo "oifname $portDeviceName counter accept comment \"!fw4: Zerotier allow outbound forward $portDeviceName\"" >> "$nft_incdir/forward/zerotier.nft" + echo "oifname $portDeviceName counter masquerade comment \"!fw4: Zerotier $portDeviceName outbound postrouting masq\"" >> "$nft_incdir/srcnat/zerotier.nft" [ -z "$ip_segment" ] || echo "ip saddr $ip_segment counter masquerade comment \"!fw4: Zerotier $ip_segment postrouting masq\"" >> "$nft_incdir/srcnat/zerotier.nft" - done - echo "zt interface rules added!" > "/tmp/zero.log" - uci -q set firewall.@defaults[0].auto_includes="1" - uci -q commit firewall - fw4 reload + logger -t "zerotier" "interface $id auto nat rules added!" + fi + } +config_load zerotier-extra +config_foreach zerotier_nat 'network' + +uci -q set firewall.@defaults[0].auto_includes="1" +uci -q commit firewall +fw4 reload + diff --git a/applications/luci-app-zerotier/root/usr/share/rpcd/acl.d/luci-app-zerotier.json b/applications/luci-app-zerotier/root/usr/share/rpcd/acl.d/luci-app-zerotier.json index 656cb3c06d4..de01b15a44c 100644 --- a/applications/luci-app-zerotier/root/usr/share/rpcd/acl.d/luci-app-zerotier.json +++ b/applications/luci-app-zerotier/root/usr/share/rpcd/acl.d/luci-app-zerotier.json @@ -8,10 +8,10 @@ "ubus": { "service": [ "list" ] }, - "uci": [ "zerotier" ] + "uci": [ "zerotier","zerotier-extra" ] }, "write": { - "uci": [ "zerotier" ] + "uci": [ "zerotier","zerotier-extra" ] } } } From 8ba966751f3eb1d5f114b63d4f7f2af518892b51 Mon Sep 17 00:00:00 2001 From: acooler15 Date: Sat, 19 Oct 2024 17:03:32 +0800 Subject: [PATCH 2/3] delete uci-defaults for luci-app-zerotier --- .../root/etc/uci-defaults/40_luci-zerotier | 12 ------------ 1 file changed, 12 deletions(-) delete mode 100755 applications/luci-app-zerotier/root/etc/uci-defaults/40_luci-zerotier diff --git a/applications/luci-app-zerotier/root/etc/uci-defaults/40_luci-zerotier b/applications/luci-app-zerotier/root/etc/uci-defaults/40_luci-zerotier deleted file mode 100755 index 96639fb365f..00000000000 --- a/applications/luci-app-zerotier/root/etc/uci-defaults/40_luci-zerotier +++ /dev/null @@ -1,12 +0,0 @@ -#!/bin/sh - -uci -q batch <<-EOF >/dev/null - delete ucitrack.@zerotier[-1] - commit ucitrack - - delete firewall.zerotier - commit firewall -EOF - -rm -f /tmp/luci-indexcache -exit 0 From a38254fa6476ec3f1f54c60425bc92b3c2d453a6 Mon Sep 17 00:00:00 2001 From: acooler15 Date: Sat, 19 Oct 2024 17:04:04 +0800 Subject: [PATCH 3/3] Format the code for luci-app-zerotier's file --- .../resources/view/zerotier/base.js | 40 +++--- .../resources/view/zerotier/interface.js | 132 +++++++++++------- .../root/etc/hotplug.d/iface/40-zerotier | 1 - .../luci-app-zerotier/root/etc/zerotier.start | 16 +-- 4 files changed, 108 insertions(+), 81 deletions(-) diff --git a/applications/luci-app-zerotier/htdocs/luci-static/resources/view/zerotier/base.js b/applications/luci-app-zerotier/htdocs/luci-static/resources/view/zerotier/base.js index 9bc6e031950..da8a2eb68d1 100644 --- a/applications/luci-app-zerotier/htdocs/luci-static/resources/view/zerotier/base.js +++ b/applications/luci-app-zerotier/htdocs/luci-static/resources/view/zerotier/base.js @@ -14,14 +14,14 @@ var callServiceList = rpc.declare({ object: 'service', method: 'list', params: ['name'], - expect: { '': {} }, + expect: { '': {} } }); - function tidyExtra(data) { var extra_sections = L.uci.sections('zerotier-extra', 'network'); var sections = Object.values(data); - var section_ids = sections.length > 0 ? sections.map(section => section['id']) : []; + var section_ids = + sections.length > 0 ? sections.map(section => section['id']) : []; var remove_section_names = []; for (var i = 0; i < extra_sections.length; i++) { var idx = section_ids.indexOf(extra_sections[i]['id']); @@ -30,11 +30,10 @@ function tidyExtra(data) { continue; } section_ids.splice(idx, 1); - var section = sections.splice(idx, 1)[0]; - // if (section.hasOwnProperty('') && section['auto_nat'] == '1') { - if (section?.['auto_nat'] == '1') { - L.uci.set('zerotier-extra', extra_sections[i]['.name'], 'auto_nat', '1'); - continue; + var section = sections.splice(idx, 1)[0]; + if (section?.['auto_nat'] == '1') { + L.uci.set('zerotier-extra', extra_sections[i]['.name'], 'auto_nat', '1'); + continue; } remove_section_names.push(extra_sections[i]['.name']); } @@ -84,16 +83,6 @@ async function loadNetwork() { await L.uci.load('zerotier', 'zerotier-extra'); } return view.extend({ - // load: function () { - // return Promise.all([ - // L.uci.load('zerotier'), - // L.uci.load('zerotier-extra').then(async() => { - // return await L.uci.sections('zerotier-extra', 'network') - // }).catch(() => { - // return []; - // }) - // ]); - // }, load: function () { return L.uci.load(['zerotier', 'zerotier-extra']).then(data => { var sections = uci.sections('zerotier', 'network'); @@ -135,7 +124,7 @@ return view.extend({ }); return E('div', { class: 'cbi-section', id: 'status_bar' }, [ - E('p', { id: 'service_status' }, _('Collecting data ...')), + E('p', { id: 'service_status' }, _('Collecting data ...')) ]); }; @@ -241,7 +230,11 @@ return view.extend({ delete this.map.data.data[section_name]; } else { for (var key in section) { - if (key.charAt(0) != '.' && key != 'auto_nat' && old_section[key] != section[key]) { + if ( + key.charAt(0) != '.' && + key != 'auto_nat' && + old_section[key] != section[key] + ) { L.uci.set('zerotier', section_name, key, section[key]); } } @@ -251,7 +244,10 @@ return view.extend({ return res; }; netS.handleRemove = function (section_id, ev) { - var res = form.GridSection.prototype.handleRemove.apply(this, [section_id,ev]); + var res = form.GridSection.prototype.handleRemove.apply(this, [ + section_id, + ev + ]); L.uci.remove('zerotier', section_id); tidyExtra(this.map.data.data); L.uci.save(); @@ -301,5 +297,5 @@ return view.extend({ netO.default = '0'; return Promise.all([m.render(), netM.render()]); - }, + } }); diff --git a/applications/luci-app-zerotier/htdocs/luci-static/resources/view/zerotier/interface.js b/applications/luci-app-zerotier/htdocs/luci-static/resources/view/zerotier/interface.js index de7266621d1..71b3798a3f3 100644 --- a/applications/luci-app-zerotier/htdocs/luci-static/resources/view/zerotier/interface.js +++ b/applications/luci-app-zerotier/htdocs/luci-static/resources/view/zerotier/interface.js @@ -9,46 +9,66 @@ 'require view'; return view.extend({ - load: function() { - return fs.exec('/sbin/ifconfig').then(function(res) { + 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))); + 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.'; + if (!interfaces || interfaces.length === 0) return 'No interface online.'; - var promises = interfaces.map(function(name) { + 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 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) { + return data.map(function (info) { var lines = info.stdout.split('\n'); var parsedInfo = { name: info.name }; - lines.forEach(function(line) { + 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]; + 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]; + 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:')) { @@ -69,48 +89,62 @@ return view.extend({ }); }, - 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.')); + 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.'))]); + return E('div', {}, [ + title, + desc, + E('div', {}, _('No interface online.')) + ]); } - var rows = data.flatMap(function(interfaceData) { + 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( + '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%' }, _('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%' }, _('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%' }, _('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%' }, _('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 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) + 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)]); + return E('div', {}, [title, desc, E('table', { class: 'table' }, rows)]); }, handleSaveApply: null, diff --git a/applications/luci-app-zerotier/root/etc/hotplug.d/iface/40-zerotier b/applications/luci-app-zerotier/root/etc/hotplug.d/iface/40-zerotier index 0485132a977..5b01d1fe203 100644 --- a/applications/luci-app-zerotier/root/etc/hotplug.d/iface/40-zerotier +++ b/applications/luci-app-zerotier/root/etc/hotplug.d/iface/40-zerotier @@ -5,4 +5,3 @@ if echo "$DEVICENAME" | grep -q "^zt"; then else exit 0 fi - diff --git a/applications/luci-app-zerotier/root/etc/zerotier.start b/applications/luci-app-zerotier/root/etc/zerotier.start index 4ece40262ea..a2a0bb80ef8 100755 --- a/applications/luci-app-zerotier/root/etc/zerotier.start +++ b/applications/luci-app-zerotier/root/etc/zerotier.start @@ -4,23 +4,22 @@ /etc/init.d/zerotier running [ "$?" -eq "0" ] || exit 1 - # see https://openwrt.org/docs/guide-user/firewall/firewall_configuration nft_incdir="/usr/share/nftables.d/chain-pre" rm -f "$nft_incdir/input/zerotier.nft" "$nft_incdir/forward/zerotier.nft" "$nft_incdir/srcnat/zerotier.nft" [ -d "$nft_incdir/input" ] || mkdir -p "$nft_incdir/input" -primaryPort=$(zerotier-cli -j info 2>&1|jsonfilter -q -e '@.config.settings.primaryPort') +primaryPort=$(zerotier-cli -j info 2>&1 | jsonfilter -q -e '@.config.settings.primaryPort') if [ -n "$primaryPort" ]; then echo "udp dport $primaryPort counter accept comment \"!fw4: Allow-ZeroTier-Inbound(primaryPort)\"" >> "$nft_incdir/input/zerotier.nft" - logger -t "zerotier" "primaryPort $primaryPort rules added!" + logger -t "zerotier" "primaryPort $primaryPort rules added!" fi -secondaryPort=$(zerotier-cli -j info 2>&1|jsonfilter -q -e '@.config.settings.secondaryPort') +secondaryPort=$(zerotier-cli -j info 2>&1 | jsonfilter -q -e '@.config.settings.secondaryPort') if [ -n "$secondaryPort" ]; then echo "udp dport $secondaryPort counter accept comment \"!fw4: Allow-ZeroTier-Inbound(secondaryPort)\"" >> "$nft_incdir/input/zerotier.nft" - logger -t "zerotier" "secondaryPort $secondaryPort rules added!" + logger -t "zerotier" "secondaryPort $secondaryPort rules added!" fi zerotier_nat() { @@ -30,8 +29,8 @@ zerotier_nat() { config_get id "$cfg" 'id' config_get_bool auto_nat "$cfg" 'auto_nat' 0 echo "id $id" - if [ -n "$id" -a "$auto_nat" -eq "1" ]; then - portDeviceName=$(zerotier-cli -j listnetworks 2>&1|jsonfilter -q -e "@[@.nwid=\"$id\"].portDeviceName") + if [ -n "$id" -a "$auto_nat" -eq "1" ]; then + portDeviceName=$(zerotier-cli -j listnetworks 2>&1 | jsonfilter -q -e "@[@.nwid=\"$id\"].portDeviceName") [ -n "$portDeviceName" ] || return 0 echo "$portDeviceName" [ -d "$nft_incdir/input" ] || mkdir -p "$nft_incdir/input" @@ -43,7 +42,7 @@ zerotier_nat() { echo "oifname $portDeviceName counter accept comment \"!fw4: Zerotier allow outbound forward $portDeviceName\"" >> "$nft_incdir/forward/zerotier.nft" echo "oifname $portDeviceName counter masquerade comment \"!fw4: Zerotier $portDeviceName outbound postrouting masq\"" >> "$nft_incdir/srcnat/zerotier.nft" [ -z "$ip_segment" ] || echo "ip saddr $ip_segment counter masquerade comment \"!fw4: Zerotier $ip_segment postrouting masq\"" >> "$nft_incdir/srcnat/zerotier.nft" - logger -t "zerotier" "interface $id auto nat rules added!" + logger -t "zerotier" "interface $id auto nat rules added!" fi } @@ -53,4 +52,3 @@ config_foreach zerotier_nat 'network' uci -q set firewall.@defaults[0].auto_includes="1" uci -q commit firewall fw4 reload -