Add Harbor Gateway auto-detection for client routing
This commit is contained in:
@@ -9,6 +9,7 @@ DEFAULT_PROXY_PORT="8082"
|
||||
REQUESTED_PROXY_PORT="${VPN_PROXY_CLIENT_PORT:-}"
|
||||
REQUESTED_UI_PORT="${VPN_PROXY_CLIENT_UI_PORT:-${CLIENT_UI_PORT:-}}"
|
||||
CLIENT_CONTAINER_NAME="vpn-proxy-client"
|
||||
NETWORK_MONITOR_LABEL="com.dokril.harbor-connect.network"
|
||||
|
||||
log() {
|
||||
printf '[vpn-proxy-client] %s\n' "$*"
|
||||
@@ -175,6 +176,54 @@ wait_for_client_ui() {
|
||||
die "client UI is not ready; see Docker status and logs above"
|
||||
}
|
||||
|
||||
xml_escape() {
|
||||
sed -e 's/&/\&/g' -e 's/</\</g' -e 's/>/\>/g' -e 's/"/\"/g'
|
||||
}
|
||||
|
||||
install_network_monitor() {
|
||||
local launch_agents_dir="$HOME/Library/LaunchAgents"
|
||||
local plist_path="$launch_agents_dir/${NETWORK_MONITOR_LABEL}.plist"
|
||||
local escaped_script_path
|
||||
local escaped_runtime_dir
|
||||
local user_domain="gui/$(id -u)"
|
||||
|
||||
escaped_script_path="$(printf '%s' "$INSTALL_DIR/scripts/harbor-network-monitor.sh" | xml_escape)"
|
||||
escaped_runtime_dir="$(printf '%s' "$INSTALL_DIR/.runtime" | xml_escape)"
|
||||
mkdir -p "$INSTALL_DIR/.runtime" "$launch_agents_dir"
|
||||
|
||||
cat > "$plist_path" <<EOF
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>Label</key>
|
||||
<string>${NETWORK_MONITOR_LABEL}</string>
|
||||
<key>ProgramArguments</key>
|
||||
<array>
|
||||
<string>/bin/bash</string>
|
||||
<string>${escaped_script_path}</string>
|
||||
</array>
|
||||
<key>EnvironmentVariables</key>
|
||||
<dict>
|
||||
<key>HARBOR_RUNTIME_DIR</key>
|
||||
<string>${escaped_runtime_dir}</string>
|
||||
</dict>
|
||||
<key>RunAtLoad</key>
|
||||
<true/>
|
||||
<key>StartInterval</key>
|
||||
<integer>5</integer>
|
||||
<key>ProcessType</key>
|
||||
<string>Background</string>
|
||||
</dict>
|
||||
</plist>
|
||||
EOF
|
||||
|
||||
/bin/bash "$INSTALL_DIR/scripts/harbor-network-monitor.sh"
|
||||
launchctl bootout "$user_domain" "$plist_path" >/dev/null 2>&1 || true
|
||||
launchctl bootstrap "$user_domain" "$plist_path"
|
||||
log "automatic Gateway detection enabled"
|
||||
}
|
||||
|
||||
set_env_value() {
|
||||
local key="$1"
|
||||
local value="$2"
|
||||
@@ -247,6 +296,8 @@ set_env_value PROXY_PORT "$PROXY_PORT"
|
||||
log "UI port: http://127.0.0.1:${UI_PORT}"
|
||||
log "proxy port: 127.0.0.1:${PROXY_PORT}"
|
||||
|
||||
install_network_monitor
|
||||
|
||||
log "building and starting Docker client"
|
||||
docker compose -f "$COMPOSE_FILE" up -d --build
|
||||
wait_for_client_ui
|
||||
|
||||
Reference in New Issue
Block a user