🌴 Sync 2026-03-05 23:51:42

This commit is contained in:
github-actions[bot] committed 2026-03-05 23:51:42 +08:00
1 parent 97c049ed0a
commit 0acff03804
14253 files changed
+3893239

No files matched your search

+35
View File
@@ -0,0 +1,35 @@
include $(TOPDIR)/rules.mk
PKG_NAME:=openvpn-dns-hotplug
PKG_VERSION:=0.0.1
PKG_RELEASE:=1
PKG_MAINTAINER:=Konstantine Shevlakov <shevlakov@132lan.ru>
include $(INCLUDE_DIR)/package.mk
define Package/$(PKG_NAME)
PKGARCH:=all
TITLE:=Openvpn DNS hotplug
DEPENDS:=+openvpn
endef
define Package/$(PKG_NAME)/description
Hotplug script to get NS attribytes: DNS and domain search.
endef
define Build/Prepare
endef
define Build/Configure
endef
define Build/Compile
endef
define Package/$(PKG_NAME)/install
$(CP) ./root/* $(1)/
endef
$(eval $(call BuildPackage,$(PKG_NAME)))
@@ -0,0 +1,74 @@
#!/bin/sh
# Get DNS, Domain Search via OpenVPN client hotplug script
# Written by Konstantine Shevlakov at <shevlakov@132lan.ru> 2022
# OpenWrt 21 file location: /etc/hotplug.d/openvpn
# Get NameServers and Domain search
get_ns(){
DNS=$(env | awk '/dhcp-option DNS/{gsub("'\''", "");print $NF}')
DOMAIN=$(env | awk '/dhcp-option DOMAIN/{gsub("'\''", "");print $NF}')
}
# Setting up NameServers and Domain
set_ns(){
if [ "x$CFGIFACE" != "x" ]; then
for ns in $DNS; do
if [ "x$ns" != "x" ]; then
uci -q add_list network.$CFGIFACE.dns=$ns
fi
done
for dn in $DOMAIN; do
if [ "x$dn" != "x" ]; then
uci -q add_list network.$CFGIFACE.dns_search=$dn
fi
done
fi
uci -q commit network
}
# Delete NameServers and Domain
unset_ns(){
if [ "x$CFGIFACE" != "x" ]; then
uci -q delete network.$CFGIFACE.dns
uci -q delete network.$CFGIFACE.dns_search
fi
uci -q commit network
}
# Get interface name in uci
UCI_conf=$(uci show openvpn | awk -F [\/=] '/config/{gsub("'\''", "");print $NF}')
for cfg in $UCI_conf; do
if [ $config = $cfg ]; then
CFGIFACE=$(uci show network | awk -F [.] -v device=$dev '$0 ~ device {print $2}')
PROTO=$(ifstatus $CFGIFACE | jsonfilter -e '@["proto"]')
get_ns
fi
done
# Hotplug action
case $PROTO in
none)
# Check peerdns option in uci interface section
PEERDNS=$(uci -q get network.$CFGIFACE.dns)
case $ACTION in
up)
if [ "x${PEERDNS}" != "x" ]; then
exit 0
fi
if [ "$DNS" ]; then
unset_ns
set_ns
reload_config
logger -t "`basename $0`" "OpenVPN: adding DNS: $DNS from $INSTANCE"
fi
;;
down)
unset_ns
reload_config
logger -t "`basename $0`" "OpenVPN: remove NS attributes from $INSTANCE"
;;
esac
;;
esac