mirror of
https://github.com/itdoginfo/podkop.git
synced 2025-12-10 05:26:50 +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) {
|
||||
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';
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user