mirror of
https://github.com/kiddin9/op-packages.git
synced 2026-11-05 01:44:16 +08:00
⛅ Sync 2026-10-07 23:59:28
This commit is contained in:
1 parent
26ea6d17f5
commit
5a632575da
108 files changed
+420
-455
No files matched your search
@@ -6,11 +6,11 @@
|
||||
include $(TOPDIR)/rules.mk
|
||||
|
||||
LUCI_TITLE:=LuCI support for OpenVPN Server
|
||||
LUCI_DEPENDS:=+openvpn-openssl +openvpn-easy-rsa +ip-full +resolveip
|
||||
LUCI_DEPENDS:=+openvpn-openssl +openvpn-easy-rsa
|
||||
LUCI_PKGARCH:=all
|
||||
PKG_NAME:=luci-app-openvpn-server-client
|
||||
PKG_VERSION:=6.0
|
||||
PKG_RELEASE:=2
|
||||
PKG_RELEASE:=3
|
||||
MAINTAINER:=lunatickochiya <125438787@qq.com>
|
||||
|
||||
include $(TOPDIR)/feeds/luci/luci.mk
|
||||
|
||||
+1
-12
@@ -48,11 +48,6 @@ o = sl:taboption("base", Flag, "enabled", translate("Enable Instance"))
|
||||
o.default = o.disabled
|
||||
o.rmempty = false
|
||||
|
||||
+o = sl:taboption("base", Flag, "tcp_cubic", translate("Use CUBIC for outer TCP"))
|
||||
o.default = o.disabled
|
||||
o.rmempty = false
|
||||
o.description = translate("For TCP client profiles only. Uses the current route to each remote endpoint and keeps the system congestion control unchanged.")
|
||||
|
||||
o = sl:taboption("base", Value, "config", translate("Config File Path"))
|
||||
o.readonly = true
|
||||
o.placeholder = translate("Auto-generated based on instance identifier")
|
||||
@@ -65,7 +60,7 @@ end
|
||||
|
||||
o = sl:taboption("config_file", TextValue, "_config_content")
|
||||
o.title = translate("OpenVPN Configuration (.ovpn/.conf)")
|
||||
o.description = translate("Paste the content of the .ovpn or .conf file here. This will be saved to the path shown in 'Base Settings'.") .. " " .. translate("If DCO hangs on this device, add disable-dco on its own line before reconnecting.")
|
||||
o.description = translate("Paste the content of the .ovpn or .conf file here. This will be saved to the path shown in 'Base Settings'.")
|
||||
o.rows = 15
|
||||
o.wrap = "off"
|
||||
o.rmempty = true
|
||||
@@ -176,12 +171,6 @@ sp.on_remove = function(self, section)
|
||||
end
|
||||
|
||||
m2.on_commit = function(self)
|
||||
sys.call("/etc/init.d/openvpn-client-cubic enable >/dev/null 2>&1")
|
||||
local route_result = sys.call("/etc/init.d/openvpn-client-cubic restart >/dev/null 2>&1")
|
||||
if route_result ~= 0 then
|
||||
self.message = translate("Could not prepare the CUBIC route for the OpenVPN client.")
|
||||
return
|
||||
end
|
||||
local result = sys.call("/etc/init.d/openvpn reload")
|
||||
if result ~= 0 then
|
||||
self.message = translate("Failed to reload OpenVPN service.")
|
||||
|
||||
@@ -1,5 +0,0 @@
|
||||
#!/bin/sh
|
||||
|
||||
case "$ACTION" in
|
||||
ifup|ifupdate) /usr/libexec/openvpn-client-cubic-route update >/dev/null 2>&1 ;;
|
||||
esac
|
||||
@@ -1,29 +0,0 @@
|
||||
#!/bin/sh /etc/rc.common
|
||||
|
||||
START=89
|
||||
STOP=10
|
||||
USE_PROCD=1
|
||||
|
||||
start_service() {
|
||||
local attempt=0
|
||||
/usr/libexec/openvpn-client-cubic-route enabled || return 0
|
||||
|
||||
# OpenVPN starts at 90. Wait for DNS and the uplink before it connects.
|
||||
while ! /usr/libexec/openvpn-client-cubic-route update; do
|
||||
attempt=$((attempt + 1))
|
||||
[ "$attempt" -lt 12 ] || {
|
||||
logger -t openvpn-client-cubic 'Could not install CUBIC route before OpenVPN startup'
|
||||
return 1
|
||||
}
|
||||
sleep 2
|
||||
done
|
||||
|
||||
procd_open_instance
|
||||
procd_set_param command /usr/libexec/openvpn-client-cubic-route watch
|
||||
procd_set_param respawn 3600 5 -1
|
||||
procd_close_instance
|
||||
}
|
||||
|
||||
stop_service() {
|
||||
/usr/libexec/openvpn-client-cubic-route clear
|
||||
}
|
||||
@@ -1,4 +0,0 @@
|
||||
#!/bin/sh
|
||||
|
||||
/etc/init.d/openvpn-client-cubic enable
|
||||
exit 0
|
||||
@@ -1,124 +0,0 @@
|
||||
#!/bin/sh
|
||||
# Set CUBIC only for opted-in OpenVPN clients' outer TCP destinations.
|
||||
|
||||
umask 077
|
||||
state=${OPENVPN_CLIENT_CUBIC_STATE:-/tmp/openvpn-client-cubic-routes}
|
||||
|
||||
sections() {
|
||||
uci -q show openvpn 2>/dev/null |
|
||||
sed -n 's/^openvpn\.\(client[A-Za-z0-9_-]*\)=openvpn$/\1/p'
|
||||
}
|
||||
|
||||
client_enabled() {
|
||||
[ "$(uci -q get "openvpn.$1.enabled")" = 1 ] &&
|
||||
[ "$(uci -q get "openvpn.$1.tcp_cubic")" = 1 ]
|
||||
}
|
||||
|
||||
has_clients() {
|
||||
for section in $(sections); do
|
||||
client_enabled "$section" && return 0
|
||||
done
|
||||
return 1
|
||||
}
|
||||
|
||||
delete_old_routes() {
|
||||
[ -f "$state" ] || return 0
|
||||
while IFS='|' read -r address via device; do
|
||||
[ -n "$address" ] && [ -n "$device" ] || continue
|
||||
if [ -n "$via" ]; then
|
||||
ip -4 route del "$address/32" via "$via" dev "$device" 2>/dev/null
|
||||
else
|
||||
ip -4 route del "$address/32" dev "$device" 2>/dev/null
|
||||
fi
|
||||
done < "$state"
|
||||
return 0
|
||||
}
|
||||
|
||||
add_route() {
|
||||
local address=$1 route via device
|
||||
route=$(ip -4 route get "$address" 2>/dev/null) || return 1
|
||||
set -- $route
|
||||
while [ "$#" -gt 1 ]; do
|
||||
case "$1" in
|
||||
via) via=$2; shift 2 ;;
|
||||
dev) device=$2; shift 2 ;;
|
||||
*) shift ;;
|
||||
esac
|
||||
done
|
||||
[ -n "$device" ] && [ "$device" != lo ] || return 1
|
||||
if [ -n "$via" ]; then
|
||||
ip -4 route replace "$address/32" via "$via" dev "$device" congctl cubic || return 1
|
||||
else
|
||||
ip -4 route replace "$address/32" dev "$device" congctl cubic || return 1
|
||||
fi
|
||||
printf '%s|%s|%s\n' "$address" "$via" "$device" >> "$new_state"
|
||||
}
|
||||
|
||||
update_routes() {
|
||||
local section conf host addresses address failed=0 desired new_state
|
||||
desired=$(mktemp /tmp/openvpn-client-cubic-desired.XXXXXX) || return 1
|
||||
new_state=$(mktemp /tmp/openvpn-client-cubic-state.XXXXXX) || {
|
||||
rm -f "$desired"
|
||||
return 1
|
||||
}
|
||||
|
||||
for section in $(sections); do
|
||||
client_enabled "$section" || continue
|
||||
conf=$(uci -q get "openvpn.$section.config")
|
||||
if [ ! -r "$conf" ]; then
|
||||
logger -t openvpn-client-cubic "Cannot read config for $section"
|
||||
failed=1
|
||||
continue
|
||||
fi
|
||||
# An outer TCP congestion controller has no effect on UDP clients.
|
||||
grep -Eiq '^[[:space:]]*proto[[:space:]]+tcp' "$conf" || continue
|
||||
for host in $(awk '$1 == "remote" { gsub(/["\047]/, "", $2); print $2 }' "$conf"); do
|
||||
case "$host" in
|
||||
''|*[!0-9.]*) addresses=$(resolveip -4 -t 5 "$host" 2>/dev/null) ;;
|
||||
*) addresses=$host ;;
|
||||
esac
|
||||
if [ -z "$addresses" ]; then
|
||||
logger -t openvpn-client-cubic "Cannot resolve $host for $section"
|
||||
failed=1
|
||||
continue
|
||||
fi
|
||||
for address in $addresses; do
|
||||
case "$address" in
|
||||
*[!0-9.]*|'') continue ;;
|
||||
esac
|
||||
printf '%s\n' "$address" >> "$desired"
|
||||
done
|
||||
done
|
||||
done
|
||||
|
||||
if [ "$failed" -ne 0 ]; then
|
||||
rm -f "$desired" "$new_state"
|
||||
return 1
|
||||
fi
|
||||
|
||||
delete_old_routes
|
||||
sort -u "$desired" | while IFS= read -r address; do
|
||||
[ -n "$address" ] || continue
|
||||
add_route "$address" || exit 1
|
||||
done
|
||||
failed=$?
|
||||
rm -f "$desired"
|
||||
if [ "$failed" -eq 0 ]; then
|
||||
mv -f "$new_state" "$state"
|
||||
else
|
||||
rm -f "$new_state"
|
||||
fi
|
||||
return "$failed"
|
||||
}
|
||||
|
||||
case "$1" in
|
||||
enabled) has_clients ;;
|
||||
update) update_routes ;;
|
||||
clear) delete_old_routes; rm -f "$state" ;;
|
||||
watch)
|
||||
while sleep 300; do
|
||||
update_routes || logger -t openvpn-client-cubic 'Could not refresh CUBIC routes'
|
||||
done
|
||||
;;
|
||||
*) echo "Usage: $0 {enabled|update|clear|watch}" >&2; exit 2 ;;
|
||||
esac
|
||||
Reference in new issue
Block a user