diff --git a/luci-app-podkop/htdocs/luci-static/resources/view/podkop/podkop.js b/luci-app-podkop/htdocs/luci-static/resources/view/podkop/podkop.js index ed1ce92..6bc649f 100644 --- a/luci-app-podkop/htdocs/luci-static/resources/view/podkop/podkop.js +++ b/luci-app-podkop/htdocs/luci-static/resources/view/podkop/podkop.js @@ -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) { const s = section; @@ -226,7 +209,6 @@ function createConfigSection(section, map, network) { o.depends('mode', 'vpn'); o.ucisection = s.section; getNetworkInterfaces(o); - getNetworkInterfaces(o); o = s.taboption('basic', form.Flag, 'domain_list_enabled', _('Community Lists')); o.default = '0'; diff --git a/podkop/files/etc/init.d/podkop b/podkop/files/etc/init.d/podkop index 61f4f40..21cd8ce 100755 --- a/podkop/files/etc/init.d/podkop +++ b/podkop/files/etc/init.d/podkop @@ -212,8 +212,9 @@ main() { config_get proxy_string "main" "proxy_string" 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" if [ "$dont_touch_dhcp" -eq 0 ]; then dnsmasq_add_resolver @@ -798,7 +799,7 @@ sing_box_outdound() { config_get outbound_json $section "outbound_json" if [ -n "$outbound_json" ]; then log "Using JSON outbound configuration" - sing_box_config_outbound_json "$outbound_json" + sing_box_config_outbound_json "$outbound_json" "$section" else log "Missing outbound JSON configuration" return @@ -880,37 +881,34 @@ sing_box_config_check() { sing_box_config_outbound_json() { local json_config="$1" - local listen_port="$2" + local section="$2" - cat > /tmp/base_config.json << EOF -{ - "log": { - "level": "warn" - }, - "inbounds": [ - { - "type": "tproxy", - "listen": "::", - "listen_port": $listen_port, - "tcp_fast_open": true, - "udp_fragment": true - }, - { - "tag": "dns-in", - "type": "direct", - "listen": "127.0.0.42", - "listen_port": 53 - } - ], - "outbounds": [], - "route": { - "auto_detect_interface": true - } -} -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" \ + 'del(.tag) | {"tag": $section} + .') + + jq --argjson outbound "$modified_config" \ + --arg section "$section" \ + '. | + .outbounds |= ( + map( + if .tag == $section then + $outbound + else . end + ) + + ( + if (map(select(.tag == $section)) | length) == 0 then + [$outbound] + else [] end + ) + )' $SING_BOX_CONFIG >/tmp/sing-box-config-tmp.json && mv /tmp/sing-box-config-tmp.json $SING_BOX_CONFIG - jq --argjson outbound "$json_config" '.outbounds += [$outbound]' /tmp/base_config.json > $SING_BOX_CONFIG - rm -f /tmp/base_config.json + if [ $? -eq 0 ]; then + log "Outbound config updated successfully" + else + log "Error: Invalid JSON config generated" + return 1 + fi }