🔥 Sync 2026-08-14 20:56:42

This commit is contained in:
github-actions[bot] committed 2026-08-14 20:56:42 +08:00
1 parent badefb504c
commit 2ef703a2e1
20 files changed
+639 -321

No files matched your search

+2 -2
View File
@@ -6,9 +6,9 @@ include $(TOPDIR)/rules.mk
PKG_NAME:=dae PKG_NAME:=dae
PKG_VERSION:=2026.08.13 PKG_VERSION:=2026.08.13
PKG_RELEASE:=35 PKG_RELEASE:=36
PKG_SOURCE:=dae-src-2026.08.13-44554e556f44.tar.gz PKG_SOURCE:=dae-src-2026.08.13-0d20959710a0.tar.gz
PKG_SOURCE_URL:=https://github.com/kenzok8/openwrt-daede/releases/download/dae-src PKG_SOURCE_URL:=https://github.com/kenzok8/openwrt-daede/releases/download/dae-src
PKG_SOURCE_SUBDIR:=$(PKG_NAME)-$(PKG_VERSION) PKG_SOURCE_SUBDIR:=$(PKG_NAME)-$(PKG_VERSION)
PKG_HASH:=skip PKG_HASH:=skip
+2 -2
View File
@@ -6,9 +6,9 @@ include $(TOPDIR)/rules.mk
PKG_NAME:=daed PKG_NAME:=daed
PKG_VERSION:=2026.08.13 PKG_VERSION:=2026.08.13
PKG_RELEASE:=46 PKG_RELEASE:=47
PKG_SOURCE:=daed-src-2026.08.13-b5028aedb364.tar.gz PKG_SOURCE:=daed-src-2026.08.13-4a38e0f66b3d.tar.gz
PKG_SOURCE_URL:=https://github.com/kenzok8/openwrt-daede/releases/download/daed-src PKG_SOURCE_URL:=https://github.com/kenzok8/openwrt-daede/releases/download/daed-src
PKG_SOURCE_SUBDIR:=$(PKG_NAME)-$(PKG_VERSION) PKG_SOURCE_SUBDIR:=$(PKG_NAME)-$(PKG_VERSION)
PKG_HASH:=skip PKG_HASH:=skip
+2 -2
View File
@@ -3,8 +3,8 @@ include $(TOPDIR)/rules.mk
LUCI_TITLE:=Configrure modem bands via mmcli utility LUCI_TITLE:=Configrure modem bands via mmcli utility
LUCI_DEPENDS:=+luci-proto-modemmanager +luci-app-modeminfo LUCI_DEPENDS:=+luci-proto-modemmanager +luci-app-modeminfo
PKG_LICENSE:=GPLv3 PKG_LICENSE:=GPLv3
PKG_VERSION:=0.1.1 PKG_VERSION:=0.1.2
PKG_RELEASE:=1 PKG_RELEASE:=2
include $(TOPDIR)/feeds/luci/luci.mk include $(TOPDIR)/feeds/luci/luci.mk
@@ -5,6 +5,174 @@
'require dom'; 'require dom';
'require modemmanager_helper as helper'; 'require modemmanager_helper as helper';
function getBandInfo(band) {
var match = /^(utran|eutran|ngran)-(\d+)$/.exec(band);
if (match) {
var generation = {
'utran': { key: '3g', title: _('3G / UMTS'), order: 2 },
'eutran': { key: '4g', title: _('4G / LTE'), order: 3 },
'ngran': { key: '5g', title: _('5G / NR'), order: 4 }
}[match[1]];
return {
value: band,
number: parseInt(match[2], 10),
label: match[1] == 'ngran' ? 'n' + match[2] : 'B' + match[2],
generation: generation
};
}
return {
value: band,
number: null,
label: band,
generation: {
key: '2g',
title: _('2G / GSM'),
order: 1
}
};
}
function groupBands(bands) {
var groups = {};
(bands || []).forEach(function(band) {
var info = getBandInfo(band);
var key = info.generation.key;
if (!groups[key]) {
groups[key] = {
key: key,
title: info.generation.title,
order: info.generation.order,
bands: []
};
}
groups[key].bands.push(info);
});
Object.keys(groups).forEach(function(key) {
groups[key].bands.sort(function(a, b) {
if (a.number !== null && b.number !== null)
return a.number - b.number;
if (a.number !== null)
return -1;
if (b.number !== null)
return 1;
return a.value.localeCompare(b.value);
});
});
return Object.keys(groups).map(function(key) {
return groups[key];
}).sort(function(a, b) {
return a.order - b.order;
});
}
var BandValue = form.Value.extend({
supportedBands: [],
selectedBands: [],
formvalue: function(section_id) {
var node = document.getElementById(this.cbid(section_id));
if (!node)
return [];
return Array.prototype.slice.call(
node.querySelectorAll('input[type="checkbox"][data-band-value]:checked')
).map(function(input) {
return input.getAttribute('data-band-value');
});
},
renderWidget: function(section_id) {
var container = E('div', {
'class': 'mmconfig-bands',
'id': this.cbid(section_id)
});
var selected = {};
(this.selectedBands || []).forEach(function(band) {
selected[band] = true;
});
var groups = groupBands(this.supportedBands);
if (!groups.length) {
return E('div', { 'class': 'mmconfig-bands-empty' },
_('No supported bands reported by ModemManager.'));
}
groups.forEach(function(group) {
var groupNode = E('div', { 'class': 'mmconfig-band-group' });
var header = E('div', { 'class': 'mmconfig-band-group-header cbi-rowstyle-2' });
var title = E('strong', { 'class': 'mmconfig-band-group-title' }, group.title);
var actions = E('span', { 'class': 'mmconfig-band-actions' });
actions.appendChild(E('button', {
'type': 'button',
'class': 'btn cbi-button cbi-button-neutral mmconfig-band-action',
'click': function() {
groupNode.querySelectorAll('input[type="checkbox"][data-band-value]').forEach(function(input) {
input.checked = true;
});
}
}, _('All')));
actions.appendChild(E('button', {
'type': 'button',
'class': 'btn cbi-button cbi-button-neutral mmconfig-band-action',
'click': function() {
groupNode.querySelectorAll('input[type="checkbox"][data-band-value]').forEach(function(input) {
input.checked = false;
});
}
}, _('None')));
header.appendChild(title);
header.appendChild(actions);
var grid = E('div', { 'class': 'mmconfig-band-grid' });
group.bands.forEach(function(band) {
var id = this.cbid(section_id) + '-' +
band.value.replace(/[^a-zA-Z0-9_-]/g, '-');
var input = E('input', {
'type': 'checkbox',
'id': id,
'data-band-value': band.value
});
input.checked = !!selected[band.value];
grid.appendChild(E('label', {
'class': 'mmconfig-band-item',
'for': id,
'title': band.value
}, [
input,
E('span', { 'class': 'mmconfig-band-label' }, band.label)
]));
}, this);
groupNode.appendChild(header);
groupNode.appendChild(grid);
container.appendChild(groupNode);
}, this);
return container;
}
});
return view.extend({ return view.extend({
load: function() { load: function() {
return Promise.all([ return Promise.all([
@@ -15,7 +183,9 @@ return view.extend({
render: function(data) { render: function(data) {
var modemsData = data[1]; var modemsData = data[1];
var m = new form.Map('mmconfig', _('Modem Configuration'), _('List supported bands.<br />If deselect all bands, then used default band modem config.')); var m = new form.Map('mmconfig', _('Modem Configuration'), _('Select bands for modem operation.' +
+ '<br />' + 'Selected bands are a recommendation and do not guarantee that the modem will use exactly these bands.' +
+ '<br /' + 'If all bands are deselected, the modems default band configuration will be used.'));
// add styles // add styles
var style = document.createElement('style'); var style = document.createElement('style');
@@ -76,7 +246,7 @@ return view.extend({
operatorText = modemObj['3gpp']['operator-name']; operatorText = modemObj['3gpp']['operator-name'];
} }
html += '<div class="compact-line">'; html += '<div class="compact-line cbi-rowstyle-2">';
html += '<span class="modem-model">' + modelText + '</span>'; html += '<span class="modem-model">' + modelText + '</span>';
if (operatorText) { if (operatorText) {
@@ -133,17 +303,22 @@ return view.extend({
// bands select // bands select
if (modemObj && modemObj.generic && modemObj.generic['supported-bands']) { if (modemObj && modemObj.generic && modemObj.generic['supported-bands']) {
o = s.option(form.MultiValue, 'bands', _('Bands')); o = s.option(BandValue, 'bands', _('Bands'));
// get from modem supported-bands o.supportedBands = modemObj.generic['supported-bands'].slice();
modemObj.generic['supported-bands'].forEach(function(band) {
o.value(band, band); var currentBands = modemObj.generic['current-bands'] || [];
var currentSet = {};
currentBands.forEach(function(band) {
currentSet[band] = true;
}); });
// Set current // Mark a band as active only when ModemManager reports it
if (section.bands) { // in current-bands. Only supported bands are displayed.
o.default = section.bands; o.selectedBands = o.supportedBands.filter(function(band) {
} return !!currentSet[band];
});
o.rmempty = true;
} else { } else {
o = s.option(form.Value, 'bands', _('Bands')); o = s.option(form.Value, 'bands', _('Bands'));
o.value('', _('Not Available')); o.value('', _('Not Available'));
@@ -174,10 +349,10 @@ return view.extend({
getCSS: function() { getCSS: function() {
return [ return [
'.modem-info-compact {', '.modem-info-compact {',
' background: #f8fafc;',
' border: 1px solid #e2e8f0;', ' border: 1px solid #e2e8f0;',
' border-radius: 6px;', ' border-radius: 6px;',
' padding: 12px 16px;', ' //padding: 12px 16px;',
' padding: 2px 2px;',
' margin: 15px 0;', ' margin: 15px 0;',
'}', '}',
'', '',
@@ -189,7 +364,7 @@ return view.extend({
'', '',
'.modem-model {', '.modem-model {',
' font-weight: 600;', ' font-weight: 600;',
' color: #2d3748;', ' //color: #2d3748;',
' font-size: 1em;', ' font-size: 1em;',
'}', '}',
'', '',
@@ -203,6 +378,74 @@ return view.extend({
' font-size: 0.95em;', ' font-size: 0.95em;',
'}', '}',
'', '',
'.mmconfig-bands {',
' border: 1px solid #e2e8f0;',
' border-radius: 6px;',
' overflow: hidden;',
' margin-top: 4px;',
'}',
'',
'.mmconfig-band-group + .mmconfig-band-group {',
' border-top: 1px solid #e2e8f0;',
'}',
'',
'.mmconfig-band-group-header {',
' display: flex;',
' align-items: center;',
' justify-content: space-between;',
' gap: 10px;',
' padding: 8px 12px;',
' //background: #f8fafc;',
'}',
'',
'.mmconfig-band-group-title {',
' font-size: 0.95em;',
'}',
'',
'.mmconfig-band-actions {',
' display: flex;',
' gap: 4px;',
'}',
'',
'.mmconfig-band-action {',
' padding: 2px 8px;',
' font-size: 0.85em;',
'}',
'',
'.mmconfig-band-grid {',
' display: grid;',
' grid-template-columns: repeat(auto-fill, minmax(72px, 1fr));',
' gap: 6px;',
' padding: 10px 12px 12px;',
'}',
'',
'.mmconfig-band-item {',
' display: flex;',
' align-items: center;',
' gap: 6px;',
' min-height: 30px;',
' padding: 4px 6px;',
' border: 1px solid #e2e8f0;',
' border-radius: 4px;',
' cursor: pointer;',
' user-select: none;',
'}',
'',
'.mmconfig-band-item:hover {',
' background: #f8fafc;',
'}',
'',
'.mmconfig-band-label {',
' font-weight: 500;',
'}',
'',
'.mmconfig-bands-empty {',
' padding: 10px 12px;',
' border: 1px solid #e2e8f0;',
' border-radius: 6px;',
' color: #718096;',
'}',
'',
'.light-divider {', '.light-divider {',
' height: 1px;', ' height: 1px;',
' background: #edf2f7;', ' background: #edf2f7;',
+9 -2
View File
@@ -26,8 +26,15 @@ msgstr "Состояние"
msgid "WARNING" msgid "WARNING"
msgstr "ПРЕДУПРЕЖДЕНИЕ" msgstr "ПРЕДУПРЕЖДЕНИЕ"
msgid "List supported bands.<br />If deselect all bands, then used default band modem config."
msgstr "Список поддерживаемых диапазонов.<br />Если не выбрано ни одного диапазона, используется конфигурация модема по умолчанию." msgid "Select bands for modem operation."
msgstr "Выберите диапазоны для работы модема."
msgid "Selected bands are a recommendation and do not guarantee that the modem will use exactly these bands."
msgstr "Выбранные диапазоны являются рекомендацией и не гарантируют, что модем будет использовать именно эти диапазоны."
msgid "If all bands are deselected, the modems default band configuration will be used."
msgstr "Если снять все флажки, будет использоваться конфигурация диапазонов модема по умолчанию."
msgid "No modem configuration found. Run <code>/etc/init.d/mmconfig start<code>" msgid "No modem configuration found. Run <code>/etc/init.d/mmconfig start<code>"
msgstr "Не найдена конфигурация. Перезапустите скрипт <code>/etc/init.d/mmconfig start</code>" msgstr "Не найдена конфигурация. Перезапустите скрипт <code>/etc/init.d/mmconfig start</code>"
+3 -3
View File
@@ -7,7 +7,7 @@ include $(TOPDIR)/rules.mk
PKG_NAME:=luci-app-passwall2 PKG_NAME:=luci-app-passwall2
PKG_VERSION:=26.8.14 PKG_VERSION:=26.8.14
PKG_RELEASE:=80 PKG_RELEASE:=81
PKG_PO_VERSION:=$(PKG_VERSION) PKG_PO_VERSION:=$(PKG_VERSION)
PKG_CONFIG_DEPENDS:= \ PKG_CONFIG_DEPENDS:= \
@@ -59,11 +59,11 @@ choice
default PACKAGE_$(PKG_NAME)_Basic_Core_Xray default PACKAGE_$(PKG_NAME)_Basic_Core_Xray
config PACKAGE_$(PKG_NAME)_Basic_Core_Xray config PACKAGE_$(PKG_NAME)_Basic_Core_Xray
bool "Xray" tristate "Xray"
select PACKAGE_xray-core select PACKAGE_xray-core
config PACKAGE_$(PKG_NAME)_Basic_Core_SingBox config PACKAGE_$(PKG_NAME)_Basic_Core_SingBox
bool "SingBox" tristate "SingBox"
select PACKAGE_sing-box select PACKAGE_sing-box
config PACKAGE_$(PKG_NAME)_Basic_Core_All config PACKAGE_$(PKG_NAME)_Basic_Core_All
@@ -5,8 +5,7 @@ module("luci.controller.passwall2", package.seeall)
local api = require "luci.passwall2.api" local api = require "luci.passwall2.api"
local appname = api.appname -- not available local appname = api.appname -- not available
local c_config = api.c_config -- not available local c_config = api.c_config -- not available
local s_config = api.s_config -- not available local uci, uci_get, uci_set, uci_del, uci_foreach, uci_save = api.uci, api.uci_get_c, api.uci_set_c, api.uci_del_c, api.uci_foreach_c, api.uci_save_c
local uci = api.uci -- in funtion index()
local http = require "luci.http" local http = require "luci.http"
local util = require "luci.util" local util = require "luci.util"
local i18n = require "luci.i18n" local i18n = require "luci.i18n"
@@ -22,14 +21,11 @@ function index()
end end
local api = require "luci.passwall2.api" local api = require "luci.passwall2.api"
local appname = api.appname -- global definitions not available local appname = api.appname -- global definitions not available
local c_config = api.c_config -- not available
local s_config = api.s_config -- not available
local uci = api.uci -- in function index()
entry({"admin", "services", appname}).dependent = true entry({"admin", "services", appname}).dependent = true
entry({"admin", "services", appname, "show"}, call("show_menu")).leaf = true entry({"admin", "services", appname, "show"}, call("show_menu")).leaf = true
entry({"admin", "services", appname, "hide"}, call("hide_menu")).leaf = true entry({"admin", "services", appname, "hide"}, call("hide_menu")).leaf = true
local e local e
if uci:get(c_config, "@global[0]", "hide_from_luci") ~= "1" then if api.uci_get_c("@global[0]", "hide_from_luci") ~= "1" then
e = entry({"admin", "services", appname}, alias("admin", "services", appname, "settings"), _("PassWall 2"), 0) e = entry({"admin", "services", appname}, alias("admin", "services", appname, "settings"), _("PassWall 2"), 0)
else else
e = entry({"admin", "services", appname}, alias("admin", "services", appname, "settings"), nil, 0) e = entry({"admin", "services", appname}, alias("admin", "services", appname, "settings"), nil, 0)
@@ -248,10 +244,10 @@ function socks_autoswitch_add_node()
local id = http.formvalue("id") local id = http.formvalue("id")
local key = http.formvalue("key") local key = http.formvalue("key")
if id and id ~= "" and key and key ~= "" then if id and id ~= "" and key and key ~= "" then
uci:set(c_config, id, "enable_autoswitch", "1") uci_set(id, "enable_autoswitch", "1")
local new_list = uci:get(c_config, id, "autoswitch_backup_node") or {} local new_list = uci_get(id, "autoswitch_backup_node") or {}
for i = #new_list, 1, -1 do for i = #new_list, 1, -1 do
if (uci:get(c_config, new_list[i], "remarks") or ""):find(key) then if (uci_get(new_list[i], "remarks") or ""):find(key) then
table.remove(new_list, i) table.remove(new_list, i)
end end
end end
@@ -260,8 +256,8 @@ function socks_autoswitch_add_node()
table.insert(new_list, e.id) table.insert(new_list, e.id)
end end
end end
uci:set_list(c_config, id, "autoswitch_backup_node", new_list) uci_set(id, "autoswitch_backup_node", new_list)
api.uci_save(uci, c_config) uci_save()
end end
http.redirect(api.url("socks_config", id)) http.redirect(api.url("socks_config", id))
end end
@@ -270,15 +266,15 @@ function socks_autoswitch_remove_node()
local id = http.formvalue("id") local id = http.formvalue("id")
local key = http.formvalue("key") local key = http.formvalue("key")
if id and id ~= "" and key and key ~= "" then if id and id ~= "" and key and key ~= "" then
uci:set(c_config, id, "enable_autoswitch", "1") uci_set(id, "enable_autoswitch", "1")
local new_list = uci:get(c_config, id, "autoswitch_backup_node") or {} local new_list = uci_get(id, "autoswitch_backup_node") or {}
for i = #new_list, 1, -1 do for i = #new_list, 1, -1 do
if (uci:get(c_config, new_list[i], "remarks") or ""):find(key) then if (uci_get(new_list[i], "remarks") or ""):find(key) then
table.remove(new_list, i) table.remove(new_list, i)
end end
end end
uci:set_list(c_config, id, "autoswitch_backup_node", new_list) uci_set(id, "autoswitch_backup_node", new_list)
api.uci_save(uci, c_config) uci_save()
end end
http.redirect(api.url("socks_config", id)) http.redirect(api.url("socks_config", id))
end end
@@ -369,7 +365,7 @@ function socks_status()
local id = http.formvalue("id") local id = http.formvalue("id")
e.index = index e.index = index
e.socks_status = luci.sys.call(string.format("/bin/busybox top -bn1 | grep -v -E 'grep|acl/|acl_' | grep '%s/bin/' | grep '%s' > /dev/null", appname, id)) == 0 e.socks_status = luci.sys.call(string.format("/bin/busybox top -bn1 | grep -v -E 'grep|acl/|acl_' | grep '%s/bin/' | grep '%s' > /dev/null", appname, id)) == 0
local use_http = uci:get(c_config, id, "http_port") or 0 local use_http = uci_get(id, "http_port") or 0
e.use_http = 0 e.use_http = 0
if tonumber(use_http) > 0 then if tonumber(use_http) > 0 then
e.use_http = 1 e.use_http = 1
@@ -439,9 +435,9 @@ function update_config()
local data_t = jsonParse(data) or {} local data_t = jsonParse(data) or {}
if next(data_t) then if next(data_t) then
for k, v in pairs(data_t) do for k, v in pairs(data_t) do
uci:set(c_config, id, k, v) uci_set(id, k, v)
end end
api.uci_save(uci, c_config) uci_save()
http_write_json_ok() http_write_json_ok()
return return
end end
@@ -457,16 +453,16 @@ function add_node()
local group = http.formvalue("group") local group = http.formvalue("group")
if group and group ~= "default" then if group and group ~= "default" then
uci:set(c_config, uid, "group", group) uci_set(uid, "group", group)
end end
uci:set(c_config, uid, "type", "Xray") uci_set(uid, "type", "Xray")
if redirect == "1" then if redirect == "1" then
api.uci_save(uci, c_config) uci_save()
http.redirect(api.url("node_config", uid)) http.redirect(api.url("node_config", uid))
else else
api.uci_save(uci, c_config, true, true) uci_save(true, true)
http_write_json({result = uid}) http_write_json({result = uid})
end end
end end
@@ -475,8 +471,8 @@ function set_node()
local type = http.formvalue("type") local type = http.formvalue("type")
local config = http.formvalue("config") local config = http.formvalue("config")
local section = http.formvalue("section") local section = http.formvalue("section")
uci:set(c_config, type, config, section) uci_set(type, config, section)
api.uci_save(uci, c_config, true, true) uci_save(true, true)
http.redirect(api.url("log")) http.redirect(api.url("log"))
end end
@@ -484,58 +480,58 @@ function copy_node()
local section = http.formvalue("section") local section = http.formvalue("section")
local uid = api.gen_random_char() local uid = api.gen_random_char()
uci:section(c_config, "nodes", uid) uci:section(c_config, "nodes", uid)
for k, v in pairs(uci:get_all(c_config, section)) do for k, v in pairs(uci_get(section)) do
if not k:match("^%.") and k ~= "group" then if not k:match("^%.") and k ~= "group" then
if k == "remarks" then v = (v or "") .. "(1)" end if k == "remarks" then v = (v or "") .. "(1)" end
uci:set(c_config, uid, k, v) uci_set(uid, k, v)
end end
end end
uci:set(c_config, uid, "add_mode", 1) uci_set(uid, "add_mode", 1)
api.uci_save(uci, c_config) uci_save()
http.redirect(api.url("node_config", uid)) http.redirect(api.url("node_config", uid))
end end
function clear_all_nodes() function clear_all_nodes()
uci:set(c_config, '@global[0]', "enabled", "0") uci_set('@global[0]', "enabled", "0")
uci:set(c_config, '@global[0]', "socks_enabled", "0") uci_set('@global[0]', "socks_enabled", "0")
uci:set(c_config, '@global_haproxy[0]', "balancing_enable", "0") uci_set('@global_haproxy[0]', "balancing_enable", "0")
uci:delete(c_config, '@global[0]', "node") uci_del('@global[0]', "node")
uci:foreach(c_config, "socks", function(t) uci_foreach("socks", function(t)
uci:delete(c_config, t[".name"]) uci_del(t[".name"])
uci:set_list(c_config, t[".name"], "autoswitch_backup_node", {}) uci_set(t[".name"], "autoswitch_backup_node", {})
end) end)
uci:foreach(c_config, "haproxy_config", function(t) uci_foreach("haproxy_config", function(t)
uci:delete(c_config, t[".name"]) uci_del(t[".name"])
end) end)
uci:foreach(c_config, "acl_rule", function(t) uci_foreach("acl_rule", function(t)
uci:delete(c_config, t[".name"], "node") uci_del(t[".name"], "node")
end) end)
uci:foreach(c_config, "nodes", function(node) uci_foreach("nodes", function(node)
uci:delete(c_config, node['.name']) uci_del(node['.name'])
end) end)
uci:foreach(c_config, "subscribe_list", function(t) uci_foreach("subscribe_list", function(t)
uci:delete(c_config, t[".name"], "md5") uci_del(t[".name"], "md5")
uci:delete(c_config, t[".name"], "chain_proxy") uci_del(t[".name"], "chain_proxy")
uci:delete(c_config, t[".name"], "preproxy_node") uci_del(t[".name"], "preproxy_node")
uci:delete(c_config, t[".name"], "to_node") uci_del(t[".name"], "to_node")
end) end)
api.uci_save(uci, c_config, true, true) uci_save(true, true)
end end
function delete_select_nodes() function delete_select_nodes()
local ids = http.formvalue("ids") local ids = http.formvalue("ids")
local redirect = http.formvalue("redirect") local redirect = http.formvalue("redirect")
string.gsub(ids, '[^' .. "," .. ']+', function(w) string.gsub(ids, '[^' .. "," .. ']+', function(w)
if (uci:get(c_config, "@global[0]", "node") or "") == w then if (uci_get("@global[0]", "node") or "") == w then
uci:delete(c_config, '@global[0]', "node") uci_del('@global[0]', "node")
end end
uci:foreach(c_config, "socks", function(t) uci_foreach("socks", function(t)
if t["node"] == w then if t["node"] == w then
uci:delete(c_config, t[".name"]) uci_del(t[".name"])
end end
local changed = false local changed = false
local auto_switch_node_list = uci:get(c_config, t[".name"], "autoswitch_backup_node") or {} local auto_switch_node_list = uci_get(t[".name"], "autoswitch_backup_node") or {}
for i = #auto_switch_node_list, 1, -1 do for i = #auto_switch_node_list, 1, -1 do
if w == auto_switch_node_list[i] then if w == auto_switch_node_list[i] then
table.remove(auto_switch_node_list, i) table.remove(auto_switch_node_list, i)
@@ -543,31 +539,31 @@ function delete_select_nodes()
end end
end end
if changed then if changed then
uci:set_list(c_config, t[".name"], "autoswitch_backup_node", auto_switch_node_list) uci_set(t[".name"], "autoswitch_backup_node", auto_switch_node_list)
end end
end) end)
uci:foreach(c_config, "haproxy_config", function(t) uci_foreach("haproxy_config", function(t)
if t["lbss"] == w then if t["lbss"] == w then
uci:delete(c_config, t[".name"]) uci_del(t[".name"])
end end
end) end)
uci:foreach(c_config, "acl_rule", function(t) uci_foreach("acl_rule", function(t)
if t["node"] == w then if t["node"] == w then
uci:delete(c_config, t[".name"], "node") uci_del(t[".name"], "node")
end end
end) end)
uci:foreach(c_config, "nodes", function(t) uci_foreach("nodes", function(t)
if t["preproxy_node"] == w then if t["preproxy_node"] == w then
uci:delete(c_config, t[".name"], "preproxy_node") uci_del(t[".name"], "preproxy_node")
uci:delete(c_config, t[".name"], "chain_proxy") uci_del(t[".name"], "chain_proxy")
end end
if t["to_node"] == w then if t["to_node"] == w then
uci:delete(c_config, t[".name"], "to_node") uci_del(t[".name"], "to_node")
uci:delete(c_config, t[".name"], "chain_proxy") uci_del(t[".name"], "chain_proxy")
end end
local list_name = t["urltest_node"] and "urltest_node" or (t["balancing_node"] and "balancing_node") local list_name = t["urltest_node"] and "urltest_node" or (t["balancing_node"] and "balancing_node")
if list_name then if list_name then
local nodes = uci:get_list(c_config, t[".name"], list_name) local nodes = uci_get(t[".name"], list_name)
if nodes then if nodes then
local changed = false local changed = false
local new_nodes = {} local new_nodes = {}
@@ -579,48 +575,48 @@ function delete_select_nodes()
end end
end end
if changed then if changed then
uci:set_list(c_config, t[".name"], list_name, new_nodes) uci_set(t[".name"], list_name, new_nodes)
end end
end end
end end
if t["fallback_node"] == w then if t["fallback_node"] == w then
uci:delete(c_config, t[".name"], "fallback_node") uci_del(t[".name"], "fallback_node")
end end
end) end)
uci:foreach(c_config, "subscribe_list", function(t) uci_foreach("subscribe_list", function(t)
if t["preproxy_node"] == w then if t["preproxy_node"] == w then
uci:delete(c_config, t[".name"], "preproxy_node") uci_del(t[".name"], "preproxy_node")
uci:delete(c_config, t[".name"], "chain_proxy") uci_del(t[".name"], "chain_proxy")
end end
if t["to_node"] == w then if t["to_node"] == w then
uci:delete(c_config, t[".name"], "to_node") uci_del(t[".name"], "to_node")
uci:delete(c_config, t[".name"], "chain_proxy") uci_del(t[".name"], "chain_proxy")
end end
end) end)
if (uci:get(c_config, w, "add_mode") or "0") == "2" then if (uci_get(w, "add_mode") or "0") == "2" then
local group = uci:get(c_config, w, "group") or "" local group = uci_get(w, "group") or ""
if group ~= "" then if group ~= "" then
uci:foreach(c_config, "subscribe_list", function(t) uci_foreach("subscribe_list", function(t)
if t["remark"] == group then if t["remark"] == group then
uci:delete(c_config, t[".name"], "md5") uci_del(t[".name"], "md5")
end end
end) end)
end end
end end
uci:delete(c_config, w) uci_del(w)
end) end)
if redirect == "1" then if redirect == "1" then
api.uci_save(uci, c_config) uci_save()
http.redirect(api.url("node_list")) http.redirect(api.url("node_list"))
else else
api.uci_save(uci, c_config, true, true) uci_save(true, true)
end end
end end
function get_node() function get_node()
local id = http.formvalue("id") local id = http.formvalue("id")
local result = {} local result = {}
local show_node_info = uci:get(c_config, "@global_other[0]", "show_node_info") or "0" local show_node_info = uci_get("@global_other[0]", "show_node_info") or "0"
local function add_is_ipv6_key(o) local function add_is_ipv6_key(o)
if o and o.address and show_node_info == "1" then if o and o.address and show_node_info == "1" then
@@ -633,12 +629,12 @@ function get_node()
end end
if id then if id then
result = uci:get_all(c_config, id) result = uci_get(id)
add_is_ipv6_key(result) add_is_ipv6_key(result)
else else
local default_nodes = {} local default_nodes = {}
local other_nodes = {} local other_nodes = {}
uci:foreach(c_config, "nodes", function(t) uci_foreach("nodes", function(t)
add_is_ipv6_key(t) add_is_ipv6_key(t)
if not t.group or t.group == "" then if not t.group or t.group == "" then
default_nodes[#default_nodes + 1] = t default_nodes[#default_nodes + 1] = t
@@ -692,7 +688,7 @@ function rollback_rules()
return return
end end
local bak_dir = "/tmp/bak_v2ray/" local bak_dir = "/tmp/bak_v2ray/"
local geo_dir = (uci:get(c_config, "@global_rules[0]", "v2ray_location_asset") or "/usr/share/v2ray/") local geo_dir = (uci_get("@global_rules[0]", "v2ray_location_asset") or "/usr/share/v2ray/")
fs.move(bak_dir .. arg_type .. ".dat", geo_dir .. arg_type .. ".dat") fs.move(bak_dir .. arg_type .. ".dat", geo_dir .. arg_type .. ".dat")
fs.rmdir(bak_dir) fs.rmdir(bak_dir)
http_write_json_ok() http_write_json_ok()
@@ -705,9 +701,9 @@ function server_update_config()
local data_t = jsonParse(data) or {} local data_t = jsonParse(data) or {}
if next(data_t) then if next(data_t) then
for k, v in pairs(data_t) do for k, v in pairs(data_t) do
uci:set(c_config .. "_server", id, k, v) api.uci_set_s(id, k, v)
end end
api.uci_save(uci, c_config .. "_server") api.uci_save_s()
http_write_json_ok() http_write_json_ok()
return return
end end
@@ -861,7 +857,7 @@ function geo_view()
end end
local function get_rules(str, type) local function get_rules(str, type)
local rules_id = {} local rules_id = {}
uci:foreach(c_config, "shunt_rules", function(s) uci_foreach("shunt_rules", function(s)
local list local list
if type == "geoip" then list = s.ip_list else list = s.domain_list end if type == "geoip" then list = s.ip_list else list = s.domain_list end
for line in string.gmatch((list or ""), "[^\r\n]+") do for line in string.gmatch((list or ""), "[^\r\n]+") do
@@ -878,7 +874,7 @@ function geo_view()
end) end)
return rules_id return rules_id
end end
local geo_dir = (uci:get(c_config, "@global_rules[0]", "v2ray_location_asset") or "/usr/share/v2ray/"):match("^(.*)/") local geo_dir = (uci_get("@global_rules[0]", "v2ray_location_asset") or "/usr/share/v2ray/"):match("^(.*)/")
local geosite_path = geo_dir .. "/geosite.dat" local geosite_path = geo_dir .. "/geosite.dat"
local geoip_path = geo_dir .. "/geoip.dat" local geoip_path = geo_dir .. "/geoip.dat"
local geo_type, file_path, cmd local geo_type, file_path, cmd
@@ -995,8 +991,8 @@ function flush_set()
local redirect = http.formvalue("redirect") or "0" local redirect = http.formvalue("redirect") or "0"
local reload = http.formvalue("reload") or "0" local reload = http.formvalue("reload") or "0"
if reload == "1" then if reload == "1" then
uci:set(c_config, '@global[0]', "flush_set", "1") uci_set('@global[0]', "flush_set", "1")
api.uci_save(uci, c_config, true, true) uci_save(true, true)
else else
api.sh_uci_set(c_config, "@global[0]", "flush_set", "1", true) api.sh_uci_set(c_config, "@global[0]", "flush_set", "1", true)
end end
@@ -1007,9 +1003,9 @@ end
function fetch_certsha256() function fetch_certsha256()
local id = http.formvalue("id") or "" local id = http.formvalue("id") or ""
local address = (id ~= "") and uci:get(c_config, id, "address") or "" local address = (id ~= "") and uci_get(id, "address") or ""
local port = (id ~= "") and uci:get(c_config, id, "port") or 0 local port = (id ~= "") and uci_get(id, "port") or 0
local sni = (id ~= "") and uci:get(c_config, id, "tls_serverName") or "" local sni = (id ~= "") and uci_get(id, "tls_serverName") or ""
sni = (sni ~= "") and sni or address sni = (sni ~= "") and sni or address
if address == "" or port == 0 then if address == "" or port == 0 then
http_write_json_error() http_write_json_error()
@@ -1024,11 +1020,11 @@ function get_shunt_rules()
local result = {} local result = {}
if id then if id then
result = uci:get_all(c_config, id) result = uci_get(id)
else else
local default_items = {} local default_items = {}
local other_items = {} local other_items = {}
uci:foreach(c_config, "shunt_rules", function(t) uci_foreach("shunt_rules", function(t)
if not t.group or t.group == "" then if not t.group or t.group == "" then
default_items[#default_items + 1] = t default_items[#default_items + 1] = t
else else
@@ -1047,7 +1043,7 @@ function add_shunt_rule()
local uid = add_name local uid = add_name
if add_name then if add_name then
local has = uci:get(c_config, uid) local has = uci_get(uid)
if has then if has then
http_write_json_error({ message = i18n.translate("This ID already exists.") }) http_write_json_error({ message = i18n.translate("This ID already exists.") })
return return
@@ -1059,14 +1055,14 @@ function add_shunt_rule()
local group = http.formvalue("group") local group = http.formvalue("group")
if group and group ~= "default" then if group and group ~= "default" then
uci:set(c_config, uid, "group", group) uci_set(uid, "group", group)
end end
if redirect == "1" then if redirect == "1" then
api.uci_save(uci, c_config) uci_save()
http.redirect(api.url("shunt_rules", uid)) http.redirect(api.url("shunt_rules", uid))
else else
api.uci_save(uci, c_config) uci_save()
http_write_json_ok({uid = uid, redirect_url = api.url("shunt_rules", uid)}) http_write_json_ok({uid = uid, redirect_url = api.url("shunt_rules", uid)})
end end
end end
@@ -1075,17 +1071,17 @@ function delete_select_shunt_rules()
local ids = http.formvalue("ids") local ids = http.formvalue("ids")
local redirect = http.formvalue("redirect") local redirect = http.formvalue("redirect")
string.gsub(ids, '[^' .. "," .. ']+', function(w) string.gsub(ids, '[^' .. "," .. ']+', function(w)
uci:foreach(c_config, "nodes", function(s) uci_foreach("nodes", function(s)
if s["protocol"] and s["protocol"] == "_shunt" then if s["protocol"] and s["protocol"] == "_shunt" then
uci:delete(c_config, s[".name"], w) uci_del(s[".name"], w)
end end
end) end)
uci:delete(c_config, w) uci_del(w)
end) end)
if redirect == "1" then if redirect == "1" then
api.uci_save(uci, c_config) uci_save()
http.redirect(api.url("rule")) http.redirect(api.url("rule"))
else else
api.uci_save(uci, c_config, true, true) uci_save(true, true)
end end
end end
@@ -2,7 +2,7 @@ local api = require "luci.passwall2.api"
local fs = api.fs local fs = api.fs
local uci = api.uci local uci = api.uci
local geo_dir = (uci:get(api.c_config, "@global_rules[0]", "v2ray_location_asset") or "/usr/share/v2ray/"):match("^(.*)/") local geo_dir = (api.uci_get_c("@global_rules[0]", "v2ray_location_asset") or "/usr/share/v2ray/"):match("^(.*)/")
local geosite_path = geo_dir .. "/geosite.dat" local geosite_path = geo_dir .. "/geosite.dat"
local geoip_path = geo_dir .. "/geoip.dat" local geoip_path = geo_dir .. "/geoip.dat"
if fs.access(geosite_path) and fs.access(geoip_path) then if fs.access(geosite_path) and fs.access(geoip_path) then
+88 -9
View File
@@ -17,9 +17,10 @@ command_timeout = 300
OPENWRT_ARCH = nil OPENWRT_ARCH = nil
DISTRIB_ARCH = nil DISTRIB_ARCH = nil
LOCK_PREFIX = "/tmp/lock/passwall2"
LOG_FILE = "/tmp/log/passwall2.log" LOG_FILE = "/tmp/log/passwall2.log"
CACHE_PATH = "/tmp/etc/passwall2_tmp" TMP_PATH = "/tmp/etc/passwall2"
TMP_PATH = "/tmp/etc/" .. appname CACHE_PATH = TMP_PATH .. "_tmp"
TMP_IFACE_PATH = TMP_PATH .. "/iface" TMP_IFACE_PATH = TMP_PATH .. "/iface"
local lang = uci:get("luci", "main", "lang") or "auto" local lang = uci:get("luci", "main", "lang") or "auto"
@@ -62,7 +63,85 @@ function is_old_uci()
return sys.call("grep -E 'require[ \t]*\"uci\"' /usr/lib/lua/luci/model/uci.lua >/dev/null 2>&1") == 0 return sys.call("grep -E 'require[ \t]*\"uci\"' /usr/lib/lua/luci/model/uci.lua >/dev/null 2>&1") == 0
end end
function uci_del(config, section, option)
if option then
return uci:delete(config, section, option)
else
return uci:delete(config, section)
end
end
function uci_get(config, section, option)
if not section then
return uci:get_all(config)
elseif option then
return uci:get(config, section, option) or nil
else
return uci:get_all(config, section)
end
end
function uci_set(config, section, option, value)
if type(value) == "number" then
value = value .. ""
end
if #value > 0 then
if option then
if type(value) == "table" then
return uci:set_list(config, section, option, value)
else
return uci:set(config, section, option, value)
end
else
return uci:set(config, section, value)
end
else
return uci_del(config, section, option)
end
end
function uci_del_c(section, option)
return uci_del(c_config, section, option)
end
function uci_foreach_c(stype, func)
uci:foreach(c_config, stype, func)
end
function uci_get_c(section, option)
return uci_get(c_config, section, option)
end
function uci_set_c(section, option, value)
return uci_set(c_config, section, option, value)
end
function uci_save_c(commit, apply)
return uci_save(uci, c_config, commit, apply)
end
function uci_del_s(section, option)
return uci_del(s_config, section, option)
end
function uci_foreach_s(stype, func)
uci:foreach(s_config, stype, func)
end
function uci_get_s(section, option)
return uci_get(s_config, section, option)
end
function uci_set_s(section, option, value)
return uci_set(s_config, section, option, value)
end
function uci_save_s(commit, apply)
return uci_save(uci, s_config, commit, apply)
end
function uci_save(cursor, config, commit, apply) function uci_save(cursor, config, commit, apply)
if not cursor then cursor = uci end
if is_old_uci() then if is_old_uci() then
cursor:save(config) cursor:save(config)
if commit then if commit then
@@ -236,7 +315,7 @@ function curl_direct(url, file, args)
end end
function curl_auto(url, file, args) function curl_auto(url, file, args)
local localhost_proxy = uci:get(c_config, "@global[0]", "localhost_proxy") or "1" local localhost_proxy = uci_get_c("@global[0]", "localhost_proxy") or "1"
if localhost_proxy == "1" then if localhost_proxy == "1" then
return curl_base(url, file, args) return curl_base(url, file, args)
else else
@@ -495,7 +574,7 @@ function get_node_name(node_id)
if type(node_id) == "table" then if type(node_id) == "table" then
e = node_id e = node_id
else else
e = uci:get_all(c_config, node_id) e = uci_get_c(node_id)
end end
if e then if e then
if e.type and e.remarks then if e.type and e.remarks then
@@ -511,7 +590,7 @@ function get_node_name(node_id)
end end
function get_valid_nodes() function get_valid_nodes()
local show_node_info = uci:get(c_config, "@global_other[0]", "show_node_info") or "0" local show_node_info = uci_get_c("@global_other[0]", "show_node_info") or "0"
local nodes = {} local nodes = {}
local default_nodes = {} local default_nodes = {}
local other_nodes = {} local other_nodes = {}
@@ -696,7 +775,7 @@ function chmod_755(file)
end end
function get_customed_path(e) function get_customed_path(e)
return uci:get(c_config, "@global_app[0]", e .. "_file") return uci_get_c("@global_app[0]", e .. "_file")
end end
function finded_com(e) function finded_com(e)
@@ -755,7 +834,7 @@ end
function get_app_path(app_name) function get_app_path(app_name)
if com[app_name] then if com[app_name] then
local def_path = com[app_name].default_path local def_path = com[app_name].default_path
local path = uci:get(c_config, "@global_app[0]", app_name:gsub("%-","_") .. "_file") local path = uci_get_c("@global_app[0]", app_name:gsub("%-","_") .. "_file")
path = path and (#path>0 and path or def_path) or def_path path = path and (#path>0 and path or def_path) or def_path
return path return path
end end
@@ -1714,7 +1793,7 @@ end
function get_socks_backup_nodes(id) function get_socks_backup_nodes(id)
id = trim(id) id = trim(id)
if id == "" then return "" end if id == "" then return "" end
local socks = uci:get_all(c_config, id) local socks = uci_get_c(id)
local nodes local nodes
if socks.backup_node_add_mode and socks.backup_node_add_mode == "batch" then if socks.backup_node_add_mode and socks.backup_node_add_mode == "batch" then
local node = {} local node = {}
@@ -1735,7 +1814,7 @@ function get_socks_backup_nodes(id)
end end
function get_core(field, candidates) function get_core(field, candidates)
local v = uci:get(c_config, "@global_subscribe[0]", field) local v = uci_get_c("@global_subscribe[0]", field)
if v and v ~= "" then if v and v ~= "" then
for _, c in ipairs(candidates) do for _, c in ipairs(candidates) do
if c[2] == v and c[1] then if c[2] == v and c[1] then
@@ -84,7 +84,7 @@ local function gen_include()
end end
local function start() local function start()
local enabled = tonumber(uci:get(CONFIG, "@global[0]", "enable") or 0) local enabled = tonumber(api.uci_get_s("@global[0]", "enable") or 0)
if enabled == nil or enabled == 0 then if enabled == nil or enabled == 0 then
return return
end end
@@ -102,7 +102,7 @@ local function start()
nft_file:write('flush chain inet fw4 PSW2-SERVER\n') nft_file:write('flush chain inet fw4 PSW2-SERVER\n')
nft_file:write('insert rule inet fw4 input position 0 jump PSW2-SERVER comment "PSW2-SERVER"\n') nft_file:write('insert rule inet fw4 input position 0 jump PSW2-SERVER comment "PSW2-SERVER"\n')
end end
uci:foreach(CONFIG, "server", function(server) api.uci_foreach_s("server", function(server)
local id = server[".name"] local id = server[".name"]
local enable = server.enable local enable = server.enable
if enable and tonumber(enable) == 1 then if enable and tonumber(enable) == 1 then
@@ -1,15 +1,13 @@
module("luci.passwall2.util_hysteria2", package.seeall) module("luci.passwall2.util_hysteria2", package.seeall)
local api = require "luci.passwall2.api" local api = require "luci.passwall2.api"
local uci = api.uci
local jsonc = api.jsonc local jsonc = api.jsonc
function gen_config_server(node) function gen_config_server(node)
local users = node.users or {}
local users = nil local users = nil
if node.users and #node.users > 0 then if node.users and #node.users > 0 then
users = {} users = {}
for i, v in ipairs(node.users) do for i, v in ipairs(node.users) do
local user = uci:get_all(api.s_config, v) or {} local user = api.uci_get_s(v) or {}
if user[".type"] == "user" then if user[".type"] == "user" then
users[user.username] = user.password users[user.username] = user.password
end end
@@ -74,7 +72,7 @@ function gen_config(var)
print("node Cannot be empty!") print("node Cannot be empty!")
return return
end end
local node = uci:get_all(api.c_config, node_id) local node = api.uci_get_c(node_id)
local local_socks_address = var["local_socks_address"] or "0.0.0.0" local local_socks_address = var["local_socks_address"] or "0.0.0.0"
local local_socks_port = var["local_socks_port"] local local_socks_port = var["local_socks_port"]
local local_socks_username = var["local_socks_username"] local local_socks_username = var["local_socks_username"]
@@ -1,6 +1,5 @@
module("luci.passwall2.util_navieproxy", package.seeall) module("luci.passwall2.util_navieproxy", package.seeall)
local api = require "luci.passwall2.api" local api = require "luci.passwall2.api"
local uci = api.uci
local jsonc = api.jsonc local jsonc = api.jsonc
function gen_config(var) function gen_config(var)
@@ -9,7 +8,7 @@ function gen_config(var)
print("node Cannot be empty!") print("node Cannot be empty!")
return return
end end
local node = uci:get_all(api.c_config, node_id) local node = api.uci_get_c(node_id)
local run_type = var["run_type"] local run_type = var["run_type"]
local local_addr = var["local_addr"] local local_addr = var["local_addr"]
local local_port = var["local_port"] local local_port = var["local_port"]
@@ -1,12 +1,11 @@
module("luci.passwall2.util_shadowsocks", package.seeall) module("luci.passwall2.util_shadowsocks", package.seeall)
local api = require "luci.passwall2.api" local api = require "luci.passwall2.api"
local uci = api.uci
local jsonc = api.jsonc local jsonc = api.jsonc
function gen_config_server(node) function gen_config_server(node)
local user = nil local user = nil
if node.user then if node.user then
user = uci:get_all(api.s_config, node.user) user = api.uci_get_s(node.user)
end end
local config = {} local config = {}
@@ -41,7 +40,7 @@ function gen_config(var)
print("node Cannot be empty!") print("node Cannot be empty!")
return return
end end
local node = uci:get_all(api.c_config, node_id) local node = api.uci_get_c(node_id)
local server_host = var["server_host"] or (node.address or ""):lower() local server_host = var["server_host"] or (node.address or ""):lower()
local server_port = var["server_port"] or node.port local server_port = var["server_port"] or node.port
local local_addr = var["local_addr"] local local_addr = var["local_addr"]
@@ -1,16 +1,14 @@
module("luci.passwall2.util_sing-box", package.seeall) module("luci.passwall2.util_sing-box", package.seeall)
local api = require "luci.passwall2.api" local api = require "luci.passwall2.api"
local uci = api.uci
local sys = api.sys local sys = api.sys
local jsonc = api.jsonc local jsonc = api.jsonc
local appname = api.appname
local fs = api.fs local fs = api.fs
local CACHE_PATH = api.CACHE_PATH local CACHE_PATH = api.CACHE_PATH
local split = api.split local split = api.split
local ech_domain = {} local ech_domain = {}
local local_version = api.get_app_version("sing-box"):match("[^v]+") local local_version = api.get_app_version("sing-box"):match("[^v]+")
local version_ge_1_13_0 = api.compare_versions(local_version, ">=", "1.13.0") local version_ge_1_14_0 = api.compare_versions(local_version, ">=", "1.14.0")
local GLOBAL = { local GLOBAL = {
DNS_SERVER = {} DNS_SERVER = {}
@@ -23,7 +21,7 @@ local GEO_VAR = {
IP_PATH = nil, IP_PATH = nil,
SITE_TAGS = {}, SITE_TAGS = {},
IP_TAGS = {}, IP_TAGS = {},
TO_SRS_PATH = "/tmp/etc/" .. appname .."_tmp/singbox_srss/" TO_SRS_PATH = CACHE_PATH .. "/singbox_srss/"
} }
function check_geoview() function check_geoview()
@@ -34,7 +32,7 @@ function check_geoview()
if GEO_VAR.OK == 0 then if GEO_VAR.OK == 0 then
api.log(0, "!!! Note: Geo rules cannot be used if the Geoview component is missing or the version is too low.") api.log(0, "!!! Note: Geo rules cannot be used if the Geoview component is missing or the version is too low.")
else else
GEO_VAR.DIR = GEO_VAR.DIR or (uci:get(api.c_config, "@global_rules[0]", "v2ray_location_asset") or "/usr/share/v2ray/"):match("^(.*)/") GEO_VAR.DIR = GEO_VAR.DIR or (api.uci_get_c("@global_rules[0]", "v2ray_location_asset") or "/usr/share/v2ray/"):match("^(.*)/")
GEO_VAR.SITE_PATH = GEO_VAR.SITE_PATH or (GEO_VAR.DIR .. "/geosite.dat") GEO_VAR.SITE_PATH = GEO_VAR.SITE_PATH or (GEO_VAR.DIR .. "/geosite.dat")
GEO_VAR.IP_PATH = GEO_VAR.IP_PATH or (GEO_VAR.DIR .. "/geoip.dat") GEO_VAR.IP_PATH = GEO_VAR.IP_PATH or (GEO_VAR.DIR .. "/geoip.dat")
if not fs.access(GEO_VAR.TO_SRS_PATH) then if not fs.access(GEO_VAR.TO_SRS_PATH) then
@@ -139,8 +137,7 @@ function gen_outbound(flag, node, tag, proxy_table)
config_file = string.format("%s_%s_%s_%s.json", flag, tag, node_id, new_port) config_file = string.format("%s_%s_%s_%s.json", flag, tag, node_id, new_port)
end end
if run_socks_instance then if run_socks_instance then
sys.call(string.format('/usr/share/%s/app.sh run_socks "%s"> /dev/null', sys.call(string.format('/usr/share/passwall2/app.sh run_socks "%s"> /dev/null',
appname,
string.format("flag=%s node=%s bind=%s socks_port=%s config_file=%s relay_port=%s", string.format("flag=%s node=%s bind=%s socks_port=%s config_file=%s relay_port=%s",
new_port, --flag new_port, --flag
node_id, --node node_id, --node
@@ -794,7 +791,7 @@ function gen_config_server(node)
if node.users and #node.users > 0 then if node.users and #node.users > 0 then
users = {} users = {}
for i, v in ipairs(node.users) do for i, v in ipairs(node.users) do
local user = uci:get_all(api.s_config, v) or {} local user = api.uci_get_s(v) or {}
if user[".type"] == "user" then if user[".type"] == "user" then
local u = {} local u = {}
if node.protocol == "mixed" or node.protocol == "socks" or node.protocol == "http" or node.protocol == "naive" then if node.protocol == "mixed" or node.protocol == "socks" or node.protocol == "http" or node.protocol == "naive" then
@@ -1030,7 +1027,7 @@ function gen_config_server(node)
} }
sys.call(string.format("mkdir -p %s && touch %s/%s", api.TMP_IFACE_PATH, api.TMP_IFACE_PATH, node.outbound_node_iface)) sys.call(string.format("mkdir -p %s && touch %s/%s", api.TMP_IFACE_PATH, api.TMP_IFACE_PATH, node.outbound_node_iface))
else else
local outbound_node_t = uci:get_all(api.c_config, node.outbound_node) local outbound_node_t = api.uci_get_c(node.outbound_node)
if node.outbound_node == "_socks" or node.outbound_node == "_http" then if node.outbound_node == "_socks" or node.outbound_node == "_http" then
outbound_node_t = { outbound_node_t = {
type = node.type, type = node.type,
@@ -1132,7 +1129,7 @@ function gen_config(var)
local CACHE_TEXT_FILE = CACHE_PATH .. "/cache_" .. flag .. ".txt" local CACHE_TEXT_FILE = CACHE_PATH .. "/cache_" .. flag .. ".txt"
local singbox_settings = uci:get_all(api.c_config, "@global_singbox[0]") or {} local singbox_settings = api.uci_get_c("@global_singbox[0]") or {}
local route = { local route = {
rules = {} rules = {}
@@ -1195,7 +1192,7 @@ function gen_config(var)
local node = nil local node = nil
if node_id then if node_id then
node = uci:get_all(api.c_config, node_id) node = api.uci_get_c(node_id)
end end
if local_socks_port then if local_socks_port then
@@ -1290,7 +1287,7 @@ function gen_config(var)
function get_node_by_id(node_id) function get_node_by_id(node_id)
if not node_id or node_id == "" or node_id == "nil" then return nil end if not node_id or node_id == "" or node_id == "nil" then return nil end
local section = uci:get_all(api.c_config, node_id) or {} local section = api.uci_get_c(node_id) or {}
if section[".type"] == "socks" then if section[".type"] == "socks" then
local result = { local result = {
[".name"] = node_id, [".name"] = node_id,
@@ -1569,7 +1566,7 @@ function gen_config(var)
end end
--shunt rule --shunt rule
uci:foreach(api.c_config, "shunt_rules", function(e) api.uci_foreach_c("shunt_rules", function(e)
if node["shunt_group"] ~= e.group then if node["shunt_group"] ~= e.group then
return return
end end
@@ -1835,16 +1832,16 @@ function gen_config(var)
if dns_listen_port then if dns_listen_port then
local dns_host = "" local dns_host = ""
if flag == "global" then if flag == "global" then
dns_host = uci:get(api.c_config, "@global[0]", "dns_hosts") or "" dns_host = api.uci_get_c("@global[0]", "dns_hosts") or ""
else else
flag = flag:gsub("acl_", "") flag = flag:gsub("acl_", "")
local dns_hosts_mode = uci:get(api.c_config, flag, "dns_hosts_mode") or "default" local dns_hosts_mode = api.uci_get_c(flag, "dns_hosts_mode") or "default"
if dns_hosts_mode == "default" then if dns_hosts_mode == "default" then
dns_host = uci:get(api.c_config, "@global[0]", "dns_hosts") or "" dns_host = api.uci_get_c("@global[0]", "dns_hosts") or ""
elseif dns_hosts_mode == "disable" then elseif dns_hosts_mode == "disable" then
dns_host = "" dns_host = ""
elseif dns_hosts_mode == "custom" then elseif dns_hosts_mode == "custom" then
dns_host = uci:get(api.c_config, flag, "dns_hosts") or "" dns_host = api.uci_get_c(flag, "dns_hosts") or ""
end end
end end
if #dns_host > 0 then if #dns_host > 0 then
@@ -1982,7 +1979,12 @@ function gen_config(var)
else default_dns_flag = "direct" else default_dns_flag = "direct"
end end
dns.final = default_dns_flag dns.final = default_dns_flag
dns.strategy = default_dns_flag == "remote" and remote_strategy or direct_strategy -- Single-stack (ipv4_only / ipv6_only) is enforced per-domain via the
-- query_type / reject rules generated below. The global dns.strategy applies
-- to every DNS server that does not set its own query_strategy, so keep it
-- dual-stack; otherwise a single-stack choice on one path would also force the
-- other path (e.g. direct / CN domains) into single-stack. See issue #1220.
dns.strategy = "prefer_ipv6"
-- DNS in order of shunt -- DNS in order of shunt
if dns_domain_rules and #dns_domain_rules > 0 then if dns_domain_rules and #dns_domain_rules > 0 then
@@ -1,9 +1,7 @@
module("luci.passwall2.util_xray", package.seeall) module("luci.passwall2.util_xray", package.seeall)
local api = require "luci.passwall2.api" local api = require "luci.passwall2.api"
local uci = api.uci
local sys = api.sys local sys = api.sys
local jsonc = api.jsonc local jsonc = api.jsonc
local appname = api.appname
local fs = api.fs local fs = api.fs
local CACHE_PATH = api.CACHE_PATH local CACHE_PATH = api.CACHE_PATH
@@ -17,7 +15,7 @@ local xray_version = api.get_app_version("xray")
local xray_min_version = "26.3.27" local xray_min_version = "26.3.27"
local function get_domain_excluded() local function get_domain_excluded()
local path = string.format("/usr/share/%s/domains_excluded", appname) local path = "/usr/share/passwall2/domains_excluded"
local content = fs.readfile(path) local content = fs.readfile(path)
if not content then return nil end if not content then return nil end
local hosts = {} local hosts = {}
@@ -79,8 +77,7 @@ function gen_outbound(flag, node, tag, proxy_table)
config_file = string.format("%s_%s_%s_%s.json", flag, tag, node_id, new_port) config_file = string.format("%s_%s_%s_%s.json", flag, tag, node_id, new_port)
end end
if run_socks_instance then if run_socks_instance then
sys.call(string.format('/usr/share/%s/app.sh run_socks "%s"> /dev/null', sys.call(string.format('/usr/share/passwall2/app.sh run_socks "%s"> /dev/null',
appname,
string.format("flag=%s node=%s bind=%s socks_port=%s config_file=%s relay_port=%s", string.format("flag=%s node=%s bind=%s socks_port=%s config_file=%s relay_port=%s",
new_port, --flag new_port, --flag
node_id, --node node_id, --node
@@ -501,7 +498,7 @@ function gen_config_server(node)
if node.users and #node.users > 0 then if node.users and #node.users > 0 then
users = {} users = {}
for i, v in ipairs(node.users) do for i, v in ipairs(node.users) do
local user = uci:get_all(api.s_config, v) or {} local user = api.uci_get_s(v) or {}
if user[".type"] == "user" then if user[".type"] == "user" then
local u = {} local u = {}
if node.protocol == "socks" or node.protocol == "http" then if node.protocol == "socks" or node.protocol == "http" then
@@ -633,7 +630,7 @@ function gen_config_server(node)
} }
sys.call(string.format("mkdir -p %s && touch %s/%s", api.TMP_IFACE_PATH, api.TMP_IFACE_PATH, node.outbound_node_iface)) sys.call(string.format("mkdir -p %s && touch %s/%s", api.TMP_IFACE_PATH, api.TMP_IFACE_PATH, node.outbound_node_iface))
else else
local outbound_node_t = uci:get_all(api.c_config, node.outbound_node) local outbound_node_t = api.uci_get_c(node.outbound_node)
if node.outbound_node == "_socks" or node.outbound_node == "_http" then if node.outbound_node == "_socks" or node.outbound_node == "_http" then
outbound_node_t = { outbound_node_t = {
type = node.type, type = node.type,
@@ -906,7 +903,7 @@ function gen_config(var)
local CACHE_TEXT_FILE = CACHE_PATH .. "/cache_" .. flag .. ".txt" local CACHE_TEXT_FILE = CACHE_PATH .. "/cache_" .. flag .. ".txt"
local xray_settings = uci:get_all(api.c_config, "@global_xray[0]") or {} local xray_settings = api.uci_get_c("@global_xray[0]") or {}
if xray_settings.fragment == "1" then if xray_settings.fragment == "1" then
local lengths, delays = {}, {} local lengths, delays = {}, {}
@@ -931,7 +928,7 @@ function gen_config(var)
if xray_settings.noise == "1" then if xray_settings.noise == "1" then
local noises = {} local noises = {}
uci:foreach(api.c_config, "xray_noise_packets", function(n) api.uci_foreach_c("xray_noise_packets", function(n)
if n.enabled == "1" then if n.enabled == "1" then
local noise = { local noise = {
rand = (n.type == "rand" and n.packet) and (n.packet:find("-", 1, true) and n.packet or tonumber(n.packet)) or nil, rand = (n.type == "rand" and n.packet) and (n.packet:find("-", 1, true) and n.packet or tonumber(n.packet)) or nil,
@@ -948,7 +945,7 @@ function gen_config(var)
} or nil } or nil
end end
local node = node_id and uci:get_all(api.c_config, node_id) or nil local node = node_id and api.uci_get_c(node_id) or nil
local balancers = {} local balancers = {}
local rules = {} local rules = {}
@@ -1000,7 +997,7 @@ function gen_config(var)
function get_node_by_id(node_id) function get_node_by_id(node_id)
if not node_id or node_id == "" or node_id == "nil" then return nil end if not node_id or node_id == "" or node_id == "nil" then return nil end
local section = uci:get_all(api.c_config, node_id) or {} local section = api.uci_get_c(node_id) or {}
if section[".type"] == "socks" then if section[".type"] == "socks" then
local result = { local result = {
[".name"] = node_id, [".name"] = node_id,
@@ -1394,7 +1391,7 @@ function gen_config(var)
end end
--shunt rule --shunt rule
uci:foreach(api.c_config, "shunt_rules", function(e) api.uci_foreach_c("shunt_rules", function(e)
if node["shunt_group"] ~= e.group then if node["shunt_group"] ~= e.group then
return return
end end
@@ -1590,16 +1587,16 @@ function gen_config(var)
local dns_host = "" local dns_host = ""
if flag == "global" then if flag == "global" then
dns_host = uci:get(api.c_config, "@global[0]", "dns_hosts") or "" dns_host = api.uci_get_c("@global[0]", "dns_hosts") or ""
else else
flag = flag:gsub("acl_", "") flag = flag:gsub("acl_", "")
local dns_hosts_mode = uci:get(api.c_config, flag, "dns_hosts_mode") or "default" local dns_hosts_mode = api.uci_get_c(flag, "dns_hosts_mode") or "default"
if dns_hosts_mode == "default" then if dns_hosts_mode == "default" then
dns_host = uci:get(api.c_config, "@global[0]", "dns_hosts") or "" dns_host = api.uci_get_c("@global[0]", "dns_hosts") or ""
elseif dns_hosts_mode == "disable" then elseif dns_hosts_mode == "disable" then
dns_host = "" dns_host = ""
elseif dns_hosts_mode == "custom" then elseif dns_hosts_mode == "custom" then
dns_host = uci:get(api.c_config, flag, "dns_hosts") or "" dns_host = api.uci_get_c(flag, "dns_hosts") or ""
end end
end end
if #dns_host > 0 then if #dns_host > 0 then
@@ -1977,12 +1974,12 @@ function gen_config(var)
if inbounds or outbounds then if inbounds or outbounds then
local config = { local config = {
env = (function() env = (function()
local asset_location = uci:get(api.c_config, "@global_rules[0]", "v2ray_location_asset") or "/usr/share/v2ray/" local asset_location = api.uci_get_c("@global_rules[0]", "v2ray_location_asset") or "/usr/share/v2ray/"
return { XRAY_LOCATION_ASSET = asset_location } return { XRAY_LOCATION_ASSET = asset_location }
end)(), end)(),
log = { log = {
--access = string.format("/tmp/etc/%s/%s_access.log", appname, "global"), --access = string.format("%s/%s_access.log", TMP_PATH, "global"),
--error = string.format("/tmp/etc/%s/%s_error.log", appname, "global"), --error = string.format("%s/%s_error.log", TMP_PATH, "global"),
--dnsLog = true, --dnsLog = true,
loglevel = get_log_level(loglevel) loglevel = get_log_level(loglevel)
}, },
@@ -3,7 +3,6 @@
local api = require ("luci.passwall2.api") local api = require ("luci.passwall2.api")
local appname = api.appname local appname = api.appname
local fs = api.fs local fs = api.fs
local jsonc = api.jsonc
local uci = api.uci local uci = api.uci
local sys = api.sys local sys = api.sys
@@ -21,11 +20,11 @@ local haproxy_conf = var["-conf"]
local haproxy_dns = "127.0.0.1" local haproxy_dns = "127.0.0.1"
local cpu_thread = sys.exec('echo -n $(cat /proc/cpuinfo | grep "processor" | wc -l)') or "1" local cpu_thread = sys.exec('echo -n $(cat /proc/cpuinfo | grep "processor" | wc -l)') or "1"
local health_check_type = uci:get(api.c_config, "@global_haproxy[0]", "health_check_type") or "tcp" local health_check_type = api.uci_get_c("@global_haproxy[0]", "health_check_type") or "tcp"
local health_check_inter = uci:get(api.c_config, "@global_haproxy[0]", "health_check_inter") or "20" local health_check_inter = api.uci_get_c("@global_haproxy[0]", "health_check_inter") or "20"
local balancingStrategy = uci:get(api.c_config, "@global_haproxy[0]", "balancingStrategy") or "roundrobin" local balancingStrategy = api.uci_get_c("@global_haproxy[0]", "balancingStrategy") or "roundrobin"
local console_port = uci:get(api.c_config, "@global_haproxy[0]", "console_port") local console_port = api.uci_get_c("@global_haproxy[0]", "console_port")
local bind_local = uci:get(api.c_config, "@global_haproxy[0]", "bind_local") or "0" local bind_local = api.uci_get_c("@global_haproxy[0]", "bind_local") or "0"
local bind_address = "0.0.0.0" local bind_address = "0.0.0.0"
if bind_local == "1" then bind_address = "127.0.0.1" end if bind_local == "1" then bind_address = "127.0.0.1" end
@@ -92,14 +91,14 @@ f_out:write(haproxy_config)
local listens = {} local listens = {}
uci:foreach(api.c_config, "haproxy_config", function(t) api.uci_foreach_c("haproxy_config", function(t)
if t.enabled == "1" then if t.enabled == "1" then
local server_remark local server_remark
local server_address local server_address
local server_port local server_port
local lbss = t.lbss local lbss = t.lbss
local listen_port = tonumber(t.haproxy_port) or 0 local listen_port = tonumber(t.haproxy_port) or 0
local server_node = uci:get_all(api.c_config, lbss) local server_node = api.uci_get_c(lbss)
local hop = (health_check_type == "script_logic") and (server_node.hysteria_hop or server_node.hysteria2_hop) or nil local hop = (health_check_type == "script_logic") and (server_node.hysteria_hop or server_node.hysteria2_hop) or nil
hop = hop and hop:gsub(":", "-") or nil hop = hop and hop:gsub(":", "-") or nil
if server_node and server_node.address and (server_node.port or hop) then if server_node and server_node.address and (server_node.port or hop) then
@@ -212,8 +211,8 @@ listen %s
end end
-- Console config -- Console config
local console_user = uci:get(api.c_config, "@global_haproxy[0]", "console_user") local console_user = api.uci_get_c("@global_haproxy[0]", "console_user")
local console_password = uci:get(api.c_config, "@global_haproxy[0]", "console_password") local console_password = api.uci_get_c("@global_haproxy[0]", "console_password")
local str = [[ local str = [[
listen console listen console
bind 0.0.0.0:%s bind 0.0.0.0:%s
@@ -229,7 +228,7 @@ f_out:close()
-- Built-in health check URL -- Built-in health check URL
if health_check_type == "script_logic" then if health_check_type == "script_logic" then
local probeUrl = uci:get(api.c_config, "@global_haproxy[0]", "health_probe_url") or "https://www.google.com/generate_204" local probeUrl = api.uci_get_c("@global_haproxy[0]", "health_probe_url") or "https://www.google.com/generate_204"
local f_url = io.open(haproxy_path .. "/Probe_URL", "w") local f_url = io.open(haproxy_path .. "/Probe_URL", "w")
f_url:write(probeUrl) f_url:write(probeUrl)
f_url:close() f_url:close()
@@ -1,6 +1,5 @@
local api = require "luci.passwall2.api" local api = require "luci.passwall2.api"
local appname = "passwall2" local c_config = api.c_config
local uci = api.uci
local sys = api.sys local sys = api.sys
local jsonc = api.jsonc local jsonc = api.jsonc
local fs = api.fs local fs = api.fs
@@ -23,38 +22,38 @@ local function tinsert(table_name, val)
end end
local function backup_servers() local function backup_servers()
local DNSMASQ_DNS = uci:get("dhcp", "@dnsmasq[0]", "server") local DNSMASQ_DNS = api.uci_get("dhcp", "@dnsmasq[0]", "server")
if DNSMASQ_DNS and #DNSMASQ_DNS > 0 then if DNSMASQ_DNS and #DNSMASQ_DNS > 0 then
uci:set(api.c_config, "@global[0]", "dnsmasq_servers", DNSMASQ_DNS) api.uci_set_c("@global[0]", "dnsmasq_servers", DNSMASQ_DNS)
api.uci_save(uci, appname, true) api.uci_save_c(true)
end end
end end
local function restore_servers() local function restore_servers()
local dns_table = {} local dns_table = {}
local DNSMASQ_DNS = uci:get("dhcp", "@dnsmasq[0]", "server") local DNSMASQ_DNS = api.uci_get("dhcp", "@dnsmasq[0]", "server")
if DNSMASQ_DNS and #DNSMASQ_DNS > 0 then if DNSMASQ_DNS and #DNSMASQ_DNS > 0 then
for k, v in ipairs(DNSMASQ_DNS) do for k, v in ipairs(DNSMASQ_DNS) do
tinsert(dns_table, v) tinsert(dns_table, v)
end end
end end
local OLD_SERVER = uci:get(api.c_config, "@global[0]", "dnsmasq_servers") local OLD_SERVER = api.uci_get_c("@global[0]", "dnsmasq_servers")
if OLD_SERVER and #OLD_SERVER > 0 then if OLD_SERVER and #OLD_SERVER > 0 then
for k, v in ipairs(OLD_SERVER) do for k, v in ipairs(OLD_SERVER) do
tinsert(dns_table, v) tinsert(dns_table, v)
end end
uci:delete(api.c_config, "@global[0]", "dnsmasq_servers") api.uci_del_c("@global[0]", "dnsmasq_servers")
api.uci_save(uci, appname, true) api.uci_save_c(true)
end end
if dns_table and #dns_table > 0 then if dns_table and #dns_table > 0 then
uci:set_list("dhcp", "@dnsmasq[0]", "server", dns_table) api.uci_set("dhcp", "@dnsmasq[0]", "server", dns_table)
api.uci_save(uci, "dhcp", true) api.uci_save(nil, "dhcp", true)
end end
end end
function stretch() function stretch()
local dnsmasq_server = uci:get("dhcp", "@dnsmasq[0]", "server") local dnsmasq_server = api.uci_get("dhcp", "@dnsmasq[0]", "server")
local dnsmasq_noresolv = uci:get("dhcp", "@dnsmasq[0]", "noresolv") local dnsmasq_noresolv = api.uci_get("dhcp", "@dnsmasq[0]", "noresolv")
local _flag local _flag
if dnsmasq_server and #dnsmasq_server > 0 then if dnsmasq_server and #dnsmasq_server > 0 then
for k, v in ipairs(dnsmasq_server) do for k, v in ipairs(dnsmasq_server) do
@@ -64,7 +63,7 @@ function stretch()
end end
end end
if not _flag and dnsmasq_noresolv == "1" then if not _flag and dnsmasq_noresolv == "1" then
uci:delete("dhcp", "@dnsmasq[0]", "noresolv") api.uci_del("dhcp", "@dnsmasq[0]", "noresolv")
local RESOLVFILE = "/tmp/resolv.conf.d/resolv.conf.auto" local RESOLVFILE = "/tmp/resolv.conf.d/resolv.conf.auto"
local file = io.open(RESOLVFILE, "r") local file = io.open(RESOLVFILE, "r")
if not file then if not file then
@@ -76,8 +75,8 @@ function stretch()
RESOLVFILE = "/tmp/resolv.conf.auto" RESOLVFILE = "/tmp/resolv.conf.auto"
end end
end end
uci:set("dhcp", "@dnsmasq[0]", "resolvfile", RESOLVFILE) api.uci_set("dhcp", "@dnsmasq[0]", "resolvfile", RESOLVFILE)
api.uci_save(uci, "dhcp", true) api.uci_save(nil, "dhcp", true)
end end
end end
@@ -96,15 +95,15 @@ function logic_restart(var)
backup_servers() backup_servers()
--sys.call("sed -i '/list server/d' /etc/config/dhcp >/dev/null 2>&1") --sys.call("sed -i '/list server/d' /etc/config/dhcp >/dev/null 2>&1")
local dns_table = {} local dns_table = {}
local dnsmasq_server = uci:get("dhcp", "@dnsmasq[0]", "server") local dnsmasq_server = api.uci_get("dhcp", "@dnsmasq[0]", "server")
if dnsmasq_server and #dnsmasq_server > 0 then if dnsmasq_server and #dnsmasq_server > 0 then
for k, v in ipairs(dnsmasq_server) do for k, v in ipairs(dnsmasq_server) do
if v:find("/") then if v:find("/") then
tinsert(dns_table, v) tinsert(dns_table, v)
end end
end end
uci:set_list("dhcp", "@dnsmasq[0]", "server", dns_table) api.uci_set("dhcp", "@dnsmasq[0]", "server", dns_table)
api.uci_save(uci, "dhcp", true) api.uci_save(nil, "dhcp", true)
end end
sys.call("/etc/init.d/dnsmasq restart >/dev/null 2>&1") sys.call("/etc/init.d/dnsmasq restart >/dev/null 2>&1")
restore_servers() restore_servers()
@@ -243,7 +242,7 @@ function add_rule(var)
end end
local cache_text = "" local cache_text = ""
local nodes_address_md5 = sys.exec("echo -n $(uci show passwall2 | grep '\\.address') | md5sum") local nodes_address_md5 = sys.exec("echo -n $(uci show %s | grep '\\.address') | md5sum" % c_config)
local new_text = TMP_DNSMASQ_PATH .. DNSMASQ_CONF_FILE .. DEFAULT_DNS .. LOCAL_DNS .. TUN_DNS .. nodes_address_md5 .. NFTFLAG local new_text = TMP_DNSMASQ_PATH .. DNSMASQ_CONF_FILE .. DEFAULT_DNS .. LOCAL_DNS .. TUN_DNS .. nodes_address_md5 .. NFTFLAG
if fs.access(CACHE_TEXT_FILE) then if fs.access(CACHE_TEXT_FILE) then
for line in io.lines(CACHE_TEXT_FILE) do for line in io.lines(CACHE_TEXT_FILE) do
@@ -268,7 +267,7 @@ function add_rule(var)
-- Always use domestic DNS to resolve node domain names -- Always use domestic DNS to resolve node domain names
if true then if true then
fwd_dns = LOCAL_DNS fwd_dns = LOCAL_DNS
uci:foreach(api.c_config, "nodes", function(t) api.uci_foreach_c("nodes", function(t)
local function process_address(address) local function process_address(address)
address = (address or ""):lower() address = (address or ""):lower()
if address == "engage.cloudflareclient.com" then return end if address == "engage.cloudflareclient.com" then return end
@@ -326,7 +325,7 @@ function add_rule(var)
["return"] = "1" ["return"] = "1"
}) })
--dhcp.leases to hostsMore actions --dhcp.leases to hostsMore actions
local hosts = "/tmp/etc/" .. appname .. "_tmp/dhcp-hosts" local hosts = api.CACHE_PATH .. "/dhcp-hosts"
sys.call("touch " .. hosts) sys.call("touch " .. hosts)
tinsert(conf_lines, "addn-hosts=" .. hosts) tinsert(conf_lines, "addn-hosts=" .. hosts)
else else
@@ -1,12 +1,11 @@
#!/usr/bin/lua #!/usr/bin/lua
local api = require "luci.passwall2.api" local api = require "luci.passwall2.api"
local name = api.appname local appname = api.appname
local c_config = api.c_config
local fs = api.fs local fs = api.fs
local log = api.log local log = api.log
local sys = api.sys local sys = api.sys
local uci = api.uci local uci, uci_get, uci_set, uci_del, uci_foreach, uci_save = api.uci, api.uci_get_c, api.uci_set_c, api.uci_del_c, api.uci_foreach_c, api.uci_save_c
local arg1 = arg[1] local arg1 = arg[1]
local arg2 = arg[2] local arg2 = arg[2]
@@ -16,9 +15,9 @@ local reboot = 0
local geoip_update = "0" local geoip_update = "0"
local geosite_update = "0" local geosite_update = "0"
local geoip_url = uci:get(c_config, "@global_rules[0]", "geoip_url") or "https://github.com/Loyalsoldier/geoip/releases/latest/download/geoip.dat" local geoip_url = uci_get("@global_rules[0]", "geoip_url") or "https://github.com/Loyalsoldier/geoip/releases/latest/download/geoip.dat"
local geosite_url = uci:get(c_config, "@global_rules[0]", "geosite_url") or "https://github.com/Loyalsoldier/v2ray-rules-dat/releases/latest/download/geosite.dat" local geosite_url = uci_get("@global_rules[0]", "geosite_url") or "https://github.com/Loyalsoldier/v2ray-rules-dat/releases/latest/download/geosite.dat"
local asset_location = uci:get(c_config, "@global_rules[0]", "v2ray_location_asset") or "/usr/share/v2ray/" local asset_location = uci_get("@global_rules[0]", "v2ray_location_asset") or "/usr/share/v2ray/"
asset_location = asset_location:match("/$") and asset_location or (asset_location .. "/") asset_location = asset_location:match("/$") and asset_location or (asset_location .. "/")
local backup_path = "/tmp/bak_v2ray/" local backup_path = "/tmp/bak_v2ray/"
@@ -177,16 +176,16 @@ if arg2 then
end end
end) end)
else else
geoip_update = uci:get(c_config, "@global_rules[0]", "geoip_update") or "1" geoip_update = uci_get("@global_rules[0]", "geoip_update") or "1"
geosite_update = uci:get(c_config, "@global_rules[0]", "geosite_update") or "1" geosite_update = uci_get("@global_rules[0]", "geosite_update") or "1"
end end
if geoip_update == "0" and geosite_update == "0" then if geoip_update == "0" and geosite_update == "0" then
os.exit(0) os.exit(0)
end end
local function check_instance(action) local function check_instance(action)
local rule_lock = "/var/lock/" .. name .. "_rule_update.lock" local rule_lock = "/var/lock/" .. appname .. "_rule_update.lock"
local sub_lock = "/var/lock/" .. name .. "_subscribe.lock" local sub_lock = "/var/lock/" .. appname .. "_subscribe.lock"
if action == "start" then if action == "start" then
math.randomseed(os.time() + math.floor(os.clock() * 1000)) math.randomseed(os.time() + math.floor(os.clock() * 1000))
@@ -233,20 +232,20 @@ if geosite_update == "1" then
remove_tmp_geofile("geosite") remove_tmp_geofile("geosite")
end end
uci:set(c_config, "@global_rules[0]", "geoip_update", geoip_update) uci_set("@global_rules[0]", "geoip_update", geoip_update)
uci:set(c_config, "@global_rules[0]", "geosite_update", geosite_update) uci_set("@global_rules[0]", "geosite_update", geosite_update)
api.uci_save(uci, c_config, true) uci_save(true)
if reboot == 1 then if reboot == 1 then
if arg3 == "cron" then if arg3 == "cron" then
if not fs.access("/var/lock/" .. name .. ".lock") then if not fs.access("/var/lock/" .. appname .. ".lock") then
sys.call("touch /tmp/lock/" .. name .. "_cron.lock") sys.call("touch /tmp/lock/" .. appname .. "_cron.lock")
end end
end end
log(1, api.i18n.translate("Restart the service and apply the new rules.")) log(1, api.i18n.translate("Restart the service and apply the new rules."))
uci:set(c_config, "@global[0]", "flush_set", "1") uci_set("@global[0]", "flush_set", "1")
api.uci_save(uci, c_config, true, true) uci_save(true, true)
end end
log(0, api.i18n.translate("The rules have been updated...")) log(0, api.i18n.translate("The rules have been updated..."))
@@ -7,23 +7,22 @@ require 'luci.util'
require 'luci.jsonc' require 'luci.jsonc'
require 'luci.sys' require 'luci.sys'
local api = require "luci.passwall2.api" local api = require "luci.passwall2.api"
local appname = api.appname
local c_config = api.c_config local c_config = api.c_config
local datatypes = require "luci.cbi.datatypes"
local datatypes = api.datatypes
local split = api.split
local base64Decode = api.base64Decode
local jsonParse, jsonStringify = api.jsonc.parse, api.jsonc.stringify
local UrlEncode, UrlDecode = api.UrlEncode, api.UrlDecode
local fs = api.fs
local log = api.log
local i18n = api.i18n
local uci, uci_get, uci_set, uci_del, uci_foreach, uci_save = api.uci, api.uci_get_c, api.uci_set_c, api.uci_del_c, api.uci_foreach_c, api.uci_save_c
-- these global functions are accessed all the time by the event handler -- these global functions are accessed all the time by the event handler
-- so caching them is worth the effort -- so caching them is worth the effort
local tinsert = table.insert local tinsert = table.insert
local ssub, slen, schar, sbyte, sformat, sgsub = string.sub, string.len, string.char, string.byte, string.format, string.gsub local ssub, slen, schar, sbyte, sformat, sgsub = string.sub, string.len, string.char, string.byte, string.format, string.gsub
local split = api.split
local jsonParse, jsonStringify = luci.jsonc.parse, luci.jsonc.stringify
local base64Decode = api.base64Decode
local UrlEncode = api.UrlEncode
local UrlDecode = api.UrlDecode
local uci = api.uci
local fs = api.fs
local log = api.log
local i18n = api.i18n
local lyaml = require "lyaml" local lyaml = require "lyaml"
local has_ss_rust = api.is_finded("sslocal") local has_ss_rust = api.is_finded("sslocal")
@@ -32,9 +31,9 @@ local has_singbox = api.finded_com("sing-box")
local has_xray = api.finded_com("xray") local has_xray = api.finded_com("xray")
local has_hysteria2 = api.finded_com("hysteria") local has_hysteria2 = api.finded_com("hysteria")
local DEFAULT_ALLOWINSECURE = true local DEFAULT_ALLOWINSECURE = true
local DEFAULT_FILTER_KEYWORD_MODE = uci:get(c_config, "@global_subscribe[0]", "filter_keyword_mode") or "0" local DEFAULT_FILTER_KEYWORD_MODE = uci_get("@global_subscribe[0]", "filter_keyword_mode") or "0"
local DEFAULT_FILTER_KEYWORD_DISCARD_LIST = uci:get(c_config, "@global_subscribe[0]", "filter_discard_list") or {} local DEFAULT_FILTER_KEYWORD_DISCARD_LIST = uci_get("@global_subscribe[0]", "filter_discard_list") or {}
local DEFAULT_FILTER_KEYWORD_KEEP_LIST = uci:get(c_config, "@global_subscribe[0]", "filter_keep_list") or {} local DEFAULT_FILTER_KEYWORD_KEEP_LIST = uci_get("@global_subscribe[0]", "filter_keep_list") or {}
-- Nodes should be retrieved using the core type (if not set on the node subscription page, the default type will be used automatically). -- Nodes should be retrieved using the core type (if not set on the node subscription page, the default type will be used automatically).
local DEFAULT_SS_TYPE = api.get_core("ss_type", {{has_ss_rust,"shadowsocks-rust"},{has_singbox,"sing-box"},{has_xray,"xray"}}) local DEFAULT_SS_TYPE = api.get_core("ss_type", {{has_ss_rust,"shadowsocks-rust"},{has_singbox,"sing-box"},{has_xray,"xray"}})
local DEFAULT_TROJAN_TYPE = api.get_core("trojan_type", {{has_singbox,"sing-box"},{has_xray,"xray"}}) local DEFAULT_TROJAN_TYPE = api.get_core("trojan_type", {{has_singbox,"sing-box"},{has_xray,"xray"}})
@@ -131,13 +130,13 @@ do
local szType = "@global[0]" local szType = "@global[0]"
local option = "node" local option = "node"
local node_id = uci:get(c_config, szType, option) local node_id = uci_get(szType, option)
CONFIG[#CONFIG + 1] = { CONFIG[#CONFIG + 1] = {
log = true, log = true,
remarks = i18n.translatef("Node"), remarks = i18n.translatef("Node"),
currentNode = node_id and uci:get_all(c_config, node_id) or nil, currentNode = node_id and uci_get(node_id) or nil,
set = function(o, server) set = function(o, server)
uci:set(c_config, szType, option, server) uci_set(szType, option, server)
o.newNodeId = server o.newNodeId = server
end end
} }
@@ -146,7 +145,7 @@ do
if true then if true then
local i = 0 local i = 0
local option = "node" local option = "node"
uci:foreach(c_config, "socks", function(t) uci_foreach("socks", function(t)
i = i + 1 i = i + 1
local id = t[".name"] local id = t[".name"]
local node_id = t[option] local node_id = t[option]
@@ -154,14 +153,14 @@ do
log = true, log = true,
id = id, id = id,
remarks = i18n.translatef("Socks node list [%s]", i), remarks = i18n.translatef("Socks node list [%s]", i),
currentNode = node_id and uci:get_all(c_config, node_id) or nil, currentNode = node_id and uci_get(node_id) or nil,
set = function(o, server) set = function(o, server)
if not server or server == "" then if not server or server == "" then
if #nodes_table > 0 then if #nodes_table > 0 then
server = nodes_table[1][".name"] server = nodes_table[1][".name"]
end end
end end
uci:set(c_config, t[".name"], option, server) uci_set(t[".name"], option, server)
o.newNodeId = server o.newNodeId = server
end end
} }
@@ -171,7 +170,7 @@ do
local newNodes = {} local newNodes = {}
for k, asb_node_id in ipairs(t.autoswitch_backup_node) do for k, asb_node_id in ipairs(t.autoswitch_backup_node) do
if asb_node_id then if asb_node_id then
local currentNode = uci:get_all(c_config, asb_node_id) or {} local currentNode = uci_get(asb_node_id) or {}
if currentNode[".type"] == "nodes" then if currentNode[".type"] == "nodes" then
currentNodes[#currentNodes + 1] = { currentNodes[#currentNodes + 1] = {
log = true, log = true,
@@ -193,7 +192,7 @@ do
set = function(o, newNodes) set = function(o, newNodes)
if o then if o then
if not newNodes then newNodes = o.newNodes end if not newNodes then newNodes = o.newNodes end
uci:set_list(c_config, id, "autoswitch_backup_node", newNodes or {}) uci_set(id, "autoswitch_backup_node", newNodes or {})
end end
end end
} }
@@ -209,25 +208,25 @@ do
local ip, port = str:match("^([%d%.]+):(%d+)$") local ip, port = str:match("^([%d%.]+):(%d+)$")
return ip and datatypes.ipaddr(ip) and tonumber(port) and tonumber(port) <= 65535 return ip and datatypes.ipaddr(ip) and tonumber(port) and tonumber(port) <= 65535
end end
uci:foreach(c_config, "haproxy_config", function(t) uci_foreach("haproxy_config", function(t)
i = i + 1 i = i + 1
local node_id = t[option] local node_id = t[option]
CONFIG[#CONFIG + 1] = { CONFIG[#CONFIG + 1] = {
log = true, log = true,
id = t[".name"], id = t[".name"],
remarks = i18n.translatef("HAProxy node list [%s]", i), remarks = i18n.translatef("HAProxy node list [%s]", i),
currentNode = node_id and uci:get_all(c_config, node_id) or nil, currentNode = node_id and uci_get(node_id) or nil,
set = function(o, server) set = function(o, server)
-- Modify the LBS value only if it is not in IP:Port format. -- Modify the LBS value only if it is not in IP:Port format.
if not is_ip_port(t[option]) then if not is_ip_port(t[option]) then
uci:set(c_config, t[".name"], option, server) uci_set(t[".name"], option, server)
o.newNodeId = server o.newNodeId = server
end end
end, end,
delete = function(o) delete = function(o)
-- Deletion is only performed if the current LBS value is not in IP:port format. -- Deletion is only performed if the current LBS value is not in IP:port format.
if not is_ip_port(t[option]) then if not is_ip_port(t[option]) then
uci:delete(c_config, t[".name"]) uci_del(t[".name"])
end end
end end
} }
@@ -236,7 +235,7 @@ do
if true then if true then
local i = 0 local i = 0
uci:foreach(c_config, "acl_rule", function(t) uci_foreach("acl_rule", function(t)
i = i + 1 i = i + 1
local option = "node" local option = "node"
local node_id = t[option] local node_id = t[option]
@@ -244,20 +243,20 @@ do
log = true, log = true,
id = t[".name"], id = t[".name"],
remarks = i18n.translatef("ACL list [%s]", i), remarks = i18n.translatef("ACL list [%s]", i),
currentNode = node_id and uci:get_all(c_config, node_id) or nil, currentNode = node_id and uci_get(node_id) or nil,
set = function(o, server) set = function(o, server)
uci:set(c_config, t[".name"], option, server) uci_set(t[".name"], option, server)
o.newNodeId = server o.newNodeId = server
end end
} }
end) end)
end end
uci:foreach(c_config, "nodes", function(node) uci_foreach("nodes", function(node)
local node_id = node[".name"] local node_id = node[".name"]
if node.protocol and node.protocol == '_shunt' then if node.protocol and node.protocol == '_shunt' then
local rules = {} local rules = {}
uci:foreach(c_config, "shunt_rules", function(e) uci_foreach("shunt_rules", function(e)
if e[".name"] and e.remarks then if e[".name"] and e.remarks then
table.insert(rules, e) table.insert(rules, e)
table.insert(rules, { table.insert(rules, {
@@ -278,7 +277,7 @@ do
for k, e in pairs(rules) do for k, e in pairs(rules) do
local _node_id = node[e[".name"]] or nil local _node_id = node[e[".name"]] or nil
if _node_id then if _node_id then
local section = uci:get_all(c_config, _node_id) or {} local section = uci_get(_node_id) or {}
if section[".type"] == "nodes" then if section[".type"] == "nodes" then
CONFIG[#CONFIG + 1] = { CONFIG[#CONFIG + 1] = {
log = false, log = false,
@@ -286,7 +285,7 @@ do
remarks = i18n.translatef("Shunt [%s] node", e.remarks), remarks = i18n.translatef("Shunt [%s] node", e.remarks),
set = function(o, server) set = function(o, server)
if not server then server = "" end if not server then server = "" end
uci:set(c_config, node_id, e[".name"], server) uci_set(node_id, e[".name"], server)
o.newNodeId = server o.newNodeId = server
end end
} }
@@ -303,7 +302,7 @@ do
log = true, log = true,
node = b_node_id, node = b_node_id,
currentNode = (function() currentNode = (function()
local section = uci:get_all(c_config, b_node_id) or {} local section = uci_get(b_node_id) or {}
if section[".type"] == "socks" then if section[".type"] == "socks" then
return { Socks = b_node_id } return { Socks = b_node_id }
end end
@@ -325,15 +324,15 @@ do
set = function(o, newNodes) set = function(o, newNodes)
if o then if o then
if not newNodes then newNodes = o.newNodes end if not newNodes then newNodes = o.newNodes end
uci:set_list(c_config, node_id, "balancing_node", newNodes or {}) uci_set(node_id, "balancing_node", newNodes or {})
end end
end end
} }
-- Backup Node -- Backup Node
local currentNode = uci:get_all(c_config, node_id) or nil local currentNode = uci_get(node_id) or nil
if currentNode and currentNode.fallback_node then if currentNode and currentNode.fallback_node then
local section = uci:get_all(c_config, currentNode.fallback_node) or {} local section = uci_get(currentNode.fallback_node) or {}
if section[".type"] == "nodes" then if section[".type"] == "nodes" then
CONFIG[#CONFIG + 1] = { CONFIG[#CONFIG + 1] = {
log = true, log = true,
@@ -341,11 +340,11 @@ do
remarks = i18n.translatef("Xray Load Balancing node [%s] backup node", node_id), remarks = i18n.translatef("Xray Load Balancing node [%s] backup node", node_id),
currentNode = section, currentNode = section,
set = function(o, server) set = function(o, server)
uci:set(c_config, node_id, "fallback_node", server) uci_set(node_id, "fallback_node", server)
o.newNodeId = server o.newNodeId = server
end, end,
delete = function(o) delete = function(o)
uci:delete(c_config, node_id, "fallback_node") uci_del(node_id, "fallback_node")
end end
} }
end end
@@ -360,7 +359,7 @@ do
log = true, log = true,
node = u_node_id, node = u_node_id,
currentNode = (function() currentNode = (function()
local section = uci:get_all(c_config, u_node_id) or {} local section = uci_get(u_node_id) or {}
if section[".type"] == "socks" then if section[".type"] == "socks" then
return { Socks = u_node_id } return { Socks = u_node_id }
end end
@@ -382,47 +381,47 @@ do
set = function(o, newNodes) set = function(o, newNodes)
if o then if o then
if not newNodes then newNodes = o.newNodes end if not newNodes then newNodes = o.newNodes end
uci:set_list(c_config, node_id, "urltest_node", newNodes or {}) uci_set(node_id, "urltest_node", newNodes or {})
end end
end end
} }
else else
-- Preproxy Node -- Preproxy Node
local currentNode = uci:get_all(c_config, node_id) or nil local currentNode = uci_get(node_id) or nil
if currentNode and currentNode.preproxy_node then if currentNode and currentNode.preproxy_node then
local section = uci:get_all(c_config, currentNode.preproxy_node) or {} local section = uci_get(currentNode.preproxy_node) or {}
if section[".type"] == "nodes" then if section[".type"] == "nodes" then
CONFIG[#CONFIG + 1] = { CONFIG[#CONFIG + 1] = {
log = true, log = true,
id = node_id, id = node_id,
remarks = i18n.translatef("Node [%s] preproxy node", node_id), remarks = i18n.translatef("Node [%s] preproxy node", node_id),
currentNode = uci:get_all(c_config, currentNode.preproxy_node) or nil, currentNode = uci_get(currentNode.preproxy_node) or nil,
set = function(o, server) set = function(o, server)
uci:set(c_config, node_id, "preproxy_node", server) uci_set(node_id, "preproxy_node", server)
o.newNodeId = server o.newNodeId = server
end, end,
delete = function(o) delete = function(o)
uci:delete(c_config, node_id, "preproxy_node") uci_del(node_id, "preproxy_node")
end end
} }
end end
end end
-- Landing node -- Landing node
local currentNode = uci:get_all(c_config, node_id) or nil local currentNode = uci_get(node_id) or nil
if currentNode and currentNode.to_node then if currentNode and currentNode.to_node then
local section = uci:get_all(c_config, currentNode.to_node) or {} local section = uci_get(currentNode.to_node) or {}
if section[".type"] == "nodes" then if section[".type"] == "nodes" then
CONFIG[#CONFIG + 1] = { CONFIG[#CONFIG + 1] = {
log = true, log = true,
id = node_id, id = node_id,
remarks = i18n.translatef("Node [%s] landing node", node_id), remarks = i18n.translatef("Node [%s] landing node", node_id),
currentNode = uci:get_all(c_config, currentNode.to_node) or nil, currentNode = uci_get(currentNode.to_node) or nil,
set = function(o, server) set = function(o, server)
uci:set(c_config, node_id, "to_node", server) uci_set(node_id, "to_node", server)
o.newNodeId = server o.newNodeId = server
end, end,
delete = function(o) delete = function(o)
uci:delete(c_config, node_id, "to_node") uci_del(node_id, "to_node")
end end
} }
end end
@@ -2002,7 +2001,7 @@ local function curl(url, file, ua, mode, hwid)
end end
function get_headers() function get_headers()
local cache_file = "/tmp/etc/" .. appname .. "_tmp/sub_curl_headers" local cache_file = CACHE_PATH .. "/sub_curl_headers"
if fs.access(cache_file) then if fs.access(cache_file) then
return luci.sys.exec("cat " .. cache_file) return luci.sys.exec("cat " .. cache_file)
end end
@@ -2084,19 +2083,19 @@ local function truncate_nodes(group)
end end
end end
end end
uci:foreach(c_config, "nodes", function(node) uci_foreach("nodes", function(node)
if node.add_mode == "2" then if node.add_mode == "2" then
if (not group) or (group:lower() == (node.group or ""):lower()) then if (not group) or (group:lower() == (node.group or ""):lower()) then
uci:delete(c_config, node['.name']) uci_del(node['.name'])
end end
end end
end) end)
uci:foreach(c_config, "subscribe_list", function(o) uci_foreach("subscribe_list", function(o)
if (not group) or (group:lower() == (o.remark or ""):lower()) then if (not group) or (group:lower() == (o.remark or ""):lower()) then
uci:delete(c_config, o['.name'], "md5") uci_del(o['.name'], "md5")
end end
end) end)
api.uci_save(uci, c_config, true) uci_save(true)
end end
local function select_node(nodes, config, parentConfig) local function select_node(nodes, config, parentConfig)
@@ -2239,10 +2238,10 @@ local function update_node(manual)
end end
if manual == 0 and next(group) then if manual == 0 and next(group) then
uci:foreach(c_config, "nodes", function(node) uci_foreach("nodes", function(node)
-- Do not delete nodes if no new nodes are found or nodes were manually imported... -- Do not delete nodes if no new nodes are found or nodes were manually imported...
if node.add_mode == "2" and (node.group and group[node.group:lower()] == true) then if node.add_mode == "2" and (node.group and group[node.group:lower()] == true) then
uci:delete(c_config, node['.name']) uci_del(node['.name'])
end end
end) end)
end end
@@ -2255,9 +2254,9 @@ local function update_node(manual)
-- Subscription Group Chain Agent -- Subscription Group Chain Agent
local function valid_chain_node(node) local function valid_chain_node(node)
if not node then return "" end if not node then return "" end
local cp = uci:get(c_config, node, "chain_proxy") or "" local cp = uci_get(node, "chain_proxy") or ""
local am = uci:get(c_config, node, "add_mode") or "0" local am = uci_get(node, "add_mode") or "0"
chain_node_type = (cp == "" and am ~= "2") and (uci:get(c_config, node, "type") or "") or "" chain_node_type = (cp == "" and am ~= "2") and (uci_get(node, "type") or "") or ""
if chain_node_type ~= "Xray" and chain_node_type ~= "sing-box" then if chain_node_type ~= "Xray" and chain_node_type ~= "sing-box" then
chain_node_type = "" chain_node_type = ""
return "" return ""
@@ -2278,39 +2277,39 @@ local function update_node(manual)
local cfgid = uci:section(c_config, "nodes", api.gen_random_char()) local cfgid = uci:section(c_config, "nodes", api.gen_random_char())
for kkk, vvv in pairs(vv) do for kkk, vvv in pairs(vv) do
if type(vvv) == "table" and next(vvv) ~= nil then if type(vvv) == "table" and next(vvv) ~= nil then
uci:set_list(c_config, cfgid, kkk, vvv) uci_set(cfgid, kkk, vvv)
else else
if kkk ~= "group" or vvv ~= "default" then if kkk ~= "group" or vvv ~= "default" then
uci:set(c_config, cfgid, kkk, vvv) uci_set(cfgid, kkk, vvv)
end end
-- Sing-Box Node Domain resolver -- Sing-Box Node Domain resolver
if kkk == "type" and (vvv == "Xray" or vvv == "sing-box") then if kkk == "type" and (vvv == "Xray" or vvv == "sing-box") then
if domain_resolver then if domain_resolver then
uci:set(c_config, cfgid, "domain_resolver", domain_resolver) uci_set(cfgid, "domain_resolver", domain_resolver)
if domain_resolver_dns then if domain_resolver_dns then
uci:set(c_config, cfgid, "domain_resolver_dns", domain_resolver_dns) uci_set(cfgid, "domain_resolver_dns", domain_resolver_dns)
elseif domain_resolver_dns_https then elseif domain_resolver_dns_https then
uci:set(c_config, cfgid, "domain_resolver_dns_https", domain_resolver_dns_https) uci_set(cfgid, "domain_resolver_dns_https", domain_resolver_dns_https)
end end
end end
if domain_strategy then if domain_strategy then
if vvv == "sing-box" then if vvv == "sing-box" then
domain_strategy = (domain_strategy == "UseIPv4" and "ipv4_only") or (domain_strategy == "UseIPv6" and "ipv6_only") or domain_strategy domain_strategy = (domain_strategy == "UseIPv4" and "ipv4_only") or (domain_strategy == "UseIPv6" and "ipv6_only") or domain_strategy
end end
uci:set(c_config, cfgid, "domain_strategy", domain_strategy) uci_set(cfgid, "domain_strategy", domain_strategy)
end end
end end
-- Subscription Group Chain Agent -- Subscription Group Chain Agent
if chain_node_type ~= "" and kkk == "type" and (vvv == "Xray" or vvv == "sing-box") then if chain_node_type ~= "" and kkk == "type" and (vvv == "Xray" or vvv == "sing-box") then
if preproxy_node_group ~="" then if preproxy_node_group ~="" then
uci:set(c_config, cfgid, "chain_proxy", "1") uci_set(cfgid, "chain_proxy", "1")
uci:set(c_config, cfgid, "preproxy_node", preproxy_node_group) uci_set(cfgid, "preproxy_node", preproxy_node_group)
elseif to_node_group ~= "" then elseif to_node_group ~= "" then
uci:set(c_config, cfgid, "chain_proxy", "2") uci_set(cfgid, "chain_proxy", "2")
uci:set(c_config, cfgid, "to_node", to_node_group) uci_set(cfgid, "to_node", to_node_group)
elseif outbound_iface_group ~= "" then elseif outbound_iface_group ~= "" then
uci:set(c_config, cfgid, "chain_proxy", "3") uci_set(cfgid, "chain_proxy", "3")
uci:set(c_config, cfgid, "outbound_iface", outbound_iface_group) uci_set(cfgid, "outbound_iface", outbound_iface_group)
end end
end end
end end
@@ -2321,16 +2320,16 @@ local function update_node(manual)
for cfgid, info in pairs(subscribe_info) do for cfgid, info in pairs(subscribe_info) do
for key, value in pairs(info) do for key, value in pairs(info) do
if value ~= "" then if value ~= "" then
uci:set(c_config, cfgid, key, value) uci_set(cfgid, key, value)
else else
uci:delete(c_config, cfgid, key) uci_del(cfgid, key)
end end
end end
end end
if next(CONFIG) then if next(CONFIG) then
local nodes = {} local nodes = {}
uci:foreach(c_config, "nodes", function(node) uci_foreach("nodes", function(node)
nodes[#nodes + 1] = node nodes[#nodes + 1] = node
end) end)
@@ -2352,16 +2351,16 @@ local function update_node(manual)
end end
end end
api.uci_save(uci, c_config, true) uci_save(true)
if arg[3] == "cron" then if arg[3] == "cron" then
if not fs.access("/var/lock/" .. appname .. ".lock") then if not fs.access(api.LOCK_PREFIX .. ".lock") then
luci.sys.call("touch /tmp/lock/" .. appname .. "_cron.lock") luci.sys.call("touch %s_cron.lock" % api.LOCK_PREFIX)
end end
end end
if manual ~= 1 then if manual ~= 1 then
luci.sys.call("/etc/init.d/" .. appname .. " restart > /dev/null 2>&1 &") luci.sys.call("/etc/init.d/passwall2 restart > /dev/null 2>&1 &")
end end
end end
@@ -2485,10 +2484,10 @@ local execute = function()
local fail_list = {} local fail_list = {}
if arg[2] ~= "all" then if arg[2] ~= "all" then
string.gsub(arg[2], '[^' .. "," .. ']+', function(w) string.gsub(arg[2], '[^' .. "," .. ']+', function(w)
subscribe_list[#subscribe_list + 1] = uci:get_all(c_config, w) or {} subscribe_list[#subscribe_list + 1] = uci_get(w) or {}
end) end)
else else
uci:foreach(c_config, "subscribe_list", function(o) uci_foreach("subscribe_list", function(o)
subscribe_list[#subscribe_list + 1] = o subscribe_list[#subscribe_list + 1] = o
end) end)
end end
@@ -2531,7 +2530,7 @@ local execute = function()
log(1, i18n.translatef("Subscription: [%s] No changes, no update required.", remark)) log(1, i18n.translatef("Subscription: [%s] No changes, no update required.", remark))
else else
parse_link(raw_data, "2", remark, value) parse_link(raw_data, "2", remark, value)
uci:set(c_config, cfgid, "md5", new_md5) uci_set(cfgid, "md5", new_md5)
end end
else else
fail_list[#fail_list + 1] = value fail_list[#fail_list + 1] = value
@@ -2554,8 +2553,8 @@ local execute = function()
end end
local function check_instance(action) local function check_instance(action)
local sub_lock = "/var/lock/" .. appname .. "_subscribe.lock" local sub_lock = api.LOCK_PREFIX .. "_subscribe.lock"
local rule_lock = "/var/lock/" .. appname .. "_rule_update.lock" local rule_lock = api.LOCK_PREFIX .. "_rule_update.lock"
if action == "start" then if action == "start" then
math.randomseed(os.time() + math.floor(os.clock() * 1000)) math.randomseed(os.time() + math.floor(os.clock() * 1000))
+3 -1
View File
@@ -9,7 +9,7 @@ include $(TOPDIR)/rules.mk
PKG_NAME:=netdata PKG_NAME:=netdata
PKG_VERSION:=2.11.0 PKG_VERSION:=2.11.0
PKG_RELEASE:=15 PKG_RELEASE:=16
PKG_MAINTAINER:=Josef Schlehofer <pepe.schlehofer@gmail.com>, Daniel Engberg <daniel.engberg.lists@pyret.net> PKG_MAINTAINER:=Josef Schlehofer <pepe.schlehofer@gmail.com>, Daniel Engberg <daniel.engberg.lists@pyret.net>
PKG_LICENSE:=GPL-3.0-or-later PKG_LICENSE:=GPL-3.0-or-later
@@ -83,6 +83,8 @@ CMAKE_OPTIONS += \
-DENABLE_PLUGIN_SYSTEMD_JOURNAL=Off \ -DENABLE_PLUGIN_SYSTEMD_JOURNAL=Off \
-DENABLE_PLUGIN_SYSTEMD_UNITS=Off \ -DENABLE_PLUGIN_SYSTEMD_UNITS=Off \
-DENABLE_PLUGIN_XENSTAT=Off \ -DENABLE_PLUGIN_XENSTAT=Off \
-DSQLITE_USE_GIT=On \
-DUSE_MOLD=Off \
-DENABLE_WEBRTC=Off -DENABLE_WEBRTC=Off
define Package/netdata/conffiles define Package/netdata/conffiles