mirror of
https://github.com/itdoginfo/podkop.git
synced 2025-12-10 13:36:52 +03:00
feat: add support for outbound JSON configuration in sing-box
This commit is contained in:
@@ -53,23 +53,6 @@ function getNetworkInterfaces(o) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function getNetworkInterfaces(o) {
|
|
||||||
const excludeInterfaces = ['br-lan', 'eth0', 'eth1', 'wan', 'phy0-ap0', 'phy1-ap0', 'pppoe-wan'];
|
|
||||||
|
|
||||||
return network.getDevices().then(devices => {
|
|
||||||
devices.forEach(device => {
|
|
||||||
if (device.dev && device.dev.name) {
|
|
||||||
const deviceName = device.dev.name;
|
|
||||||
if (!excludeInterfaces.includes(deviceName) && !/^lan\d+$/.test(deviceName)) {
|
|
||||||
o.value(deviceName, deviceName);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}).catch(error => {
|
|
||||||
console.error('Failed to get network devices:', error);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
// Общая функция для создания конфигурационных секций
|
// Общая функция для создания конфигурационных секций
|
||||||
function createConfigSection(section, map, network) {
|
function createConfigSection(section, map, network) {
|
||||||
const s = section;
|
const s = section;
|
||||||
@@ -226,7 +209,6 @@ function createConfigSection(section, map, network) {
|
|||||||
o.depends('mode', 'vpn');
|
o.depends('mode', 'vpn');
|
||||||
o.ucisection = s.section;
|
o.ucisection = s.section;
|
||||||
getNetworkInterfaces(o);
|
getNetworkInterfaces(o);
|
||||||
getNetworkInterfaces(o);
|
|
||||||
|
|
||||||
o = s.taboption('basic', form.Flag, 'domain_list_enabled', _('Community Lists'));
|
o = s.taboption('basic', form.Flag, 'domain_list_enabled', _('Community Lists'));
|
||||||
o.default = '0';
|
o.default = '0';
|
||||||
|
|||||||
@@ -212,8 +212,9 @@ main() {
|
|||||||
|
|
||||||
config_get proxy_string "main" "proxy_string"
|
config_get proxy_string "main" "proxy_string"
|
||||||
config_get interface "main" "interface"
|
config_get interface "main" "interface"
|
||||||
|
config_get outbound_json "main" "outbound_json"
|
||||||
|
|
||||||
if [ -n "$proxy_string" ] || [ -n "$interface" ]; then
|
if [ -n "$proxy_string" ] || [ -n "$interface" ] || [ -n "$outbound_json" ]; then
|
||||||
config_get_bool dont_touch_dhcp "main" "dont_touch_dhcp" "0"
|
config_get_bool dont_touch_dhcp "main" "dont_touch_dhcp" "0"
|
||||||
if [ "$dont_touch_dhcp" -eq 0 ]; then
|
if [ "$dont_touch_dhcp" -eq 0 ]; then
|
||||||
dnsmasq_add_resolver
|
dnsmasq_add_resolver
|
||||||
@@ -798,7 +799,7 @@ sing_box_outdound() {
|
|||||||
config_get outbound_json $section "outbound_json"
|
config_get outbound_json $section "outbound_json"
|
||||||
if [ -n "$outbound_json" ]; then
|
if [ -n "$outbound_json" ]; then
|
||||||
log "Using JSON outbound configuration"
|
log "Using JSON outbound configuration"
|
||||||
sing_box_config_outbound_json "$outbound_json"
|
sing_box_config_outbound_json "$outbound_json" "$section"
|
||||||
else
|
else
|
||||||
log "Missing outbound JSON configuration"
|
log "Missing outbound JSON configuration"
|
||||||
return
|
return
|
||||||
@@ -880,37 +881,34 @@ sing_box_config_check() {
|
|||||||
|
|
||||||
sing_box_config_outbound_json() {
|
sing_box_config_outbound_json() {
|
||||||
local json_config="$1"
|
local json_config="$1"
|
||||||
local listen_port="$2"
|
local section="$2"
|
||||||
|
|
||||||
cat > /tmp/base_config.json << EOF
|
# Create new object with tag first, then merge with the rest of the config
|
||||||
{
|
local modified_config=$(echo "$json_config" | jq --arg section "$section" \
|
||||||
"log": {
|
'del(.tag) | {"tag": $section} + .')
|
||||||
"level": "warn"
|
|
||||||
},
|
jq --argjson outbound "$modified_config" \
|
||||||
"inbounds": [
|
--arg section "$section" \
|
||||||
{
|
'. |
|
||||||
"type": "tproxy",
|
.outbounds |= (
|
||||||
"listen": "::",
|
map(
|
||||||
"listen_port": $listen_port,
|
if .tag == $section then
|
||||||
"tcp_fast_open": true,
|
$outbound
|
||||||
"udp_fragment": true
|
else . end
|
||||||
},
|
) +
|
||||||
{
|
(
|
||||||
"tag": "dns-in",
|
if (map(select(.tag == $section)) | length) == 0 then
|
||||||
"type": "direct",
|
[$outbound]
|
||||||
"listen": "127.0.0.42",
|
else [] end
|
||||||
"listen_port": 53
|
)
|
||||||
}
|
)' $SING_BOX_CONFIG >/tmp/sing-box-config-tmp.json && mv /tmp/sing-box-config-tmp.json $SING_BOX_CONFIG
|
||||||
],
|
|
||||||
"outbounds": [],
|
|
||||||
"route": {
|
|
||||||
"auto_detect_interface": true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
EOF
|
|
||||||
|
|
||||||
jq --argjson outbound "$json_config" '.outbounds += [$outbound]' /tmp/base_config.json > $SING_BOX_CONFIG
|
if [ $? -eq 0 ]; then
|
||||||
rm -f /tmp/base_config.json
|
log "Outbound config updated successfully"
|
||||||
|
else
|
||||||
|
log "Error: Invalid JSON config generated"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user