mirror of
https://github.com/alexhopeoconnor/dnsmasq-webui.git
synced 2026-10-22 13:57:50 +10:00
Options validation, CORS, HTTPS, HttpClient factory, config error output
- DnsmasqOptionsValidator: fail-fast at startup if MainConfigPath/HostsPath missing or files do not exist; clear stderr message before exit - Program: AddOptions + ValidateOnStart; catch OptionsValidationException, print prominent error and Environment.Exit(1) - CORS: configurable via Cors:Enabled, Cors:PolicyName, AllowedOrigins, etc. (appsettings + env); default disabled - HTTPS: ForwardedHeaders (when enabled) and Https:UseRedirectAndHsts (appsettings + env); default disabled - HttpClient: IHttpClientFactory + SameHostBaseAddressHandler for same-host API calls; default client uses Options.DefaultName - publish-self-contained.sh: platform auto-detect, clean before publish, --no-clean option, RIDs including ubuntu.*-x64/arm64, linux-musl-* - prepare-test-mount.sh: stop/tidy options - EnsureManagedConfigHostedService / DnsmasqConfigSetService: managed config path and conf-file= handling - appsettings: ForwardedHeaders, Https, Cors sections; Dnsmasq defaults Note: Dockerfile.dnsmasq removed (may need restore for app+dnsmasq image)
This commit is contained in:
@@ -1,12 +1,12 @@
|
||||
#!/usr/bin/env sh
|
||||
# Prepare the testdata mount and optionally start the Docker test harness
|
||||
# Prepare the testdata mount and optionally start or stop the Docker test harness
|
||||
# (app + dnsmasq + DHCP client). See testdata/README.md and docker-compose.test.yml.
|
||||
#
|
||||
# What this script does:
|
||||
# 1. Clears the mount directory (unless --no-clear), then syncs source -> mount.
|
||||
# 2. Excludes 'leases' so dnsmasq creates/owns the real leases file in the container.
|
||||
# 3. Removes any *dnsmasq-webui*.conf so dnsmasq starts clean (app creates zz-dnsmasq-webui.conf at startup).
|
||||
# 4. Unless --prepare-only, runs: docker compose -f docker-compose.test.yml up -d [--build] [--force-recreate]
|
||||
# Start (default): clear mount (unless --no-clear), sync source -> mount, remove *dnsmasq-webui*.conf,
|
||||
# then docker compose up -d [--build] [--force-recreate].
|
||||
# --stop: docker compose down (stop and remove containers/networks).
|
||||
# --tidy: docker compose down, then clear the mount directory for a clean next run.
|
||||
set -e
|
||||
|
||||
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
|
||||
@@ -19,6 +19,8 @@ PREPARE_ONLY=false
|
||||
NO_BUILD=false
|
||||
RECREATE=false
|
||||
NO_CLEAR=false
|
||||
STOP=false
|
||||
TIDY=false
|
||||
|
||||
usage() {
|
||||
echo "Usage: $0 [OPTIONS] [--]"
|
||||
@@ -50,6 +52,11 @@ usage() {
|
||||
echo " --recreate Pass --force-recreate to docker compose (recreate containers)."
|
||||
echo " Use to ensure fresh container state and mounts."
|
||||
echo ""
|
||||
echo "Stop / tidy:"
|
||||
echo " --stop Stop the test harness: docker compose down (no prepare, no start)."
|
||||
echo " --tidy Stop the harness and clear the mount directory for a clean next run."
|
||||
echo " Uses default mount dir unless --mount DIR is given."
|
||||
echo ""
|
||||
echo "Other:"
|
||||
echo " -h, --help Show this help and exit."
|
||||
echo ""
|
||||
@@ -73,6 +80,12 @@ usage() {
|
||||
echo " $0 --source myfixtures --mount mymount --prepare-only"
|
||||
echo " Sync myfixtures -> mymount only. Start with:"
|
||||
echo " TESTDATA_MOUNT=./mymount docker compose -f $COMPOSE_FILE up -d"
|
||||
echo ""
|
||||
echo " $0 --stop"
|
||||
echo " Stop and remove test harness containers and networks."
|
||||
echo ""
|
||||
echo " $0 --tidy"
|
||||
echo " Stop harness and clear testdata-mount for a clean next run."
|
||||
}
|
||||
|
||||
while [ $# -gt 0 ]; do
|
||||
@@ -109,6 +122,14 @@ while [ $# -gt 0 ]; do
|
||||
RECREATE=true
|
||||
shift
|
||||
;;
|
||||
--stop)
|
||||
STOP=true
|
||||
shift
|
||||
;;
|
||||
--tidy)
|
||||
TIDY=true
|
||||
shift
|
||||
;;
|
||||
--)
|
||||
shift
|
||||
break
|
||||
@@ -126,6 +147,22 @@ cd "$REPO_ROOT"
|
||||
: "${SOURCE_DIR:=testdata}"
|
||||
: "${MOUNT_DIR:=testdata-mount}"
|
||||
|
||||
# Stop and/or tidy: no prepare, no start
|
||||
if [ "$STOP" = true ] || [ "$TIDY" = true ]; then
|
||||
echo "Stopping test harness: docker compose -f $COMPOSE_FILE down"
|
||||
docker compose -f "$COMPOSE_FILE" down
|
||||
if [ "$TIDY" = true ]; then
|
||||
if [ -d "$MOUNT_DIR" ]; then
|
||||
echo "Clearing mount directory: $MOUNT_DIR"
|
||||
find "$MOUNT_DIR" -mindepth 1 -delete 2>/dev/null || true
|
||||
echo "Mount directory cleared."
|
||||
else
|
||||
echo "Mount directory $MOUNT_DIR does not exist; nothing to clear."
|
||||
fi
|
||||
fi
|
||||
exit 0
|
||||
fi
|
||||
|
||||
if [ ! -d "$SOURCE_DIR" ]; then
|
||||
echo "Error: source directory '$SOURCE_DIR' does not exist" >&2
|
||||
exit 1
|
||||
|
||||
Executable
+156
@@ -0,0 +1,156 @@
|
||||
#!/usr/bin/env sh
|
||||
# Build a self-contained folder publish for Linux (no single-file; folder is recommended
|
||||
# for ASP.NET Core). Copy the publish directory to the target host and run the binary.
|
||||
#
|
||||
# Platform auto-detection: if you do not pass a RID, the script picks one from /etc/os-release
|
||||
# and uname -m. On Ubuntu 24.04/22.04 we use ubuntu.<ver>-<arch> so the runtime matches the
|
||||
# host and avoids TypeLoadException seen with generic linux-x64 on those distros. Else we use
|
||||
# generic linux-* or linux-musl-* (Alpine). Trimming is off by default because PublishTrimmed
|
||||
# can cause Blazor routing/404 issues. The script cleans the target RID before publish
|
||||
# so previous artefacts (e.g. from a different --trim or RID) cannot pollute the build.
|
||||
set -e
|
||||
|
||||
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
|
||||
REPO_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
|
||||
PROJECT="$REPO_ROOT/src/DnsmasqWebUI/DnsmasqWebUI.csproj"
|
||||
|
||||
VALID_RIDS="linux-x64 linux-arm64 linux-arm linux-musl-x64 linux-musl-arm64 ubuntu.24.04-x64 ubuntu.24.04-arm64 ubuntu.22.04-x64 ubuntu.22.04-arm64"
|
||||
TRIM=false
|
||||
CLEAN=true
|
||||
RID=""
|
||||
AUTO_RID=false
|
||||
|
||||
# Detect architecture: x86_64/amd64 -> x64, aarch64 -> arm64, armv7l/armhf -> arm
|
||||
detect_arch() {
|
||||
case "$(uname -m)" in
|
||||
x86_64|amd64) echo "x64" ;;
|
||||
aarch64|arm64) echo "arm64" ;;
|
||||
armv7l|armhf) echo "arm" ;;
|
||||
*) echo "x64" ;;
|
||||
esac
|
||||
}
|
||||
|
||||
# Pick RID from OS and arch so runtime matches host (avoids TypeLoadException on Ubuntu).
|
||||
default_rid() {
|
||||
local arch
|
||||
arch="$(detect_arch)"
|
||||
if [ -f /etc/os-release ]; then
|
||||
. /etc/os-release
|
||||
case "${ID:-}" in
|
||||
ubuntu)
|
||||
case "${VERSION_ID:-}" in
|
||||
24.04) echo "ubuntu.24.04-$arch"; return ;;
|
||||
22.04) echo "ubuntu.22.04-$arch"; return ;;
|
||||
esac ;;
|
||||
alpine)
|
||||
case "$arch" in
|
||||
x64) echo "linux-musl-x64"; return ;;
|
||||
arm64) echo "linux-musl-arm64"; return ;;
|
||||
*) echo "linux-musl-x64"; return ;;
|
||||
esac ;;
|
||||
esac
|
||||
fi
|
||||
case "$arch" in
|
||||
arm64) echo "linux-arm64" ;;
|
||||
arm) echo "linux-arm" ;;
|
||||
*) echo "linux-x64" ;;
|
||||
esac
|
||||
}
|
||||
|
||||
while [ $# -gt 0 ]; do
|
||||
case "$1" in
|
||||
-h|--help)
|
||||
echo "Usage: $0 [OPTIONS] [RID]"
|
||||
echo ""
|
||||
echo "Build a self-contained folder publish for Linux. If RID is omitted, the script"
|
||||
echo "auto-detects from the current OS and architecture (recommended on Ubuntu and Alpine)."
|
||||
echo ""
|
||||
echo "Options:"
|
||||
echo " --trim Enable trimming (smaller output; can cause 404/routing issues with Blazor)"
|
||||
echo " --no-clean Skip clean before publish (faster; use only if same RID and options as last run)"
|
||||
echo " -h, --help Show this help"
|
||||
echo ""
|
||||
echo "Supported RIDs:"
|
||||
echo " Generic (glibc):"
|
||||
echo " linux-x64 Most servers/desktops (Debian, Fedora, etc.)"
|
||||
echo " linux-arm64 Raspberry Pi 4/5, aarch64"
|
||||
echo " linux-arm 32-bit ARM (older Pi)"
|
||||
echo " Alpine (musl):"
|
||||
echo " linux-musl-x64 Alpine amd64"
|
||||
echo " linux-musl-arm64 Alpine aarch64"
|
||||
echo " Ubuntu (use on Ubuntu to avoid TypeLoadException with generic RID):"
|
||||
echo " ubuntu.24.04-x64 ubuntu.24.04-arm64"
|
||||
echo " ubuntu.22.04-x64 ubuntu.22.04-arm64"
|
||||
echo ""
|
||||
echo "Output: src/DnsmasqWebUI/bin/Release/net9.0/<RID>/publish/"
|
||||
echo ""
|
||||
echo "Examples:"
|
||||
echo " $0 # Publish for current machine (auto-detect RID)"
|
||||
echo " $0 ubuntu.24.04-x64 # Publish for Ubuntu 24.04 amd64"
|
||||
echo " $0 linux-arm64 # Publish for Raspberry Pi 4/5 or other aarch64"
|
||||
echo " $0 linux-musl-x64 # Publish for Alpine (e.g. Docker)"
|
||||
echo " $0 --trim linux-x64 # Smaller build (not recommended for Blazor)"
|
||||
echo " $0 --no-clean ubuntu.24.04-x64 # Skip clean (faster; same RID/options as last run)"
|
||||
exit 0
|
||||
;;
|
||||
--trim)
|
||||
TRIM=true
|
||||
shift
|
||||
;;
|
||||
--no-clean)
|
||||
CLEAN=false
|
||||
shift
|
||||
;;
|
||||
*)
|
||||
RID="$1"
|
||||
shift
|
||||
break
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
if [ -z "$RID" ]; then
|
||||
RID="$(default_rid)"
|
||||
AUTO_RID=true
|
||||
fi
|
||||
|
||||
case "$RID" in
|
||||
linux-x64|linux-arm64|linux-arm|linux-musl-x64|linux-musl-arm64|ubuntu.24.04-x64|ubuntu.24.04-arm64|ubuntu.22.04-x64|ubuntu.22.04-arm64) ;;
|
||||
*)
|
||||
echo "Unknown RID: $RID" >&2
|
||||
echo "Supported: $VALID_RIDS" >&2
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
|
||||
if [ "$AUTO_RID" = true ]; then
|
||||
echo "Detected RID: $RID (override by passing a RID as argument)"
|
||||
fi
|
||||
|
||||
# Clean first so previous publish artefacts (e.g. different --trim or stale obj) cannot pollute this build.
|
||||
# Use -c Release only (no -r) so clean does not require the RID in project.assets.json.
|
||||
if [ "$CLEAN" = true ]; then
|
||||
echo "Cleaning Release..."
|
||||
dotnet clean "$PROJECT" -c Release -nologo -v q
|
||||
fi
|
||||
|
||||
if [ "$TRIM" = true ]; then
|
||||
echo "Publishing self-contained (trimmed, folder) for $RID..."
|
||||
dotnet publish "$PROJECT" \
|
||||
-c Release \
|
||||
-r "$RID" \
|
||||
--self-contained true \
|
||||
-p:PublishTrimmed=true
|
||||
else
|
||||
echo "Publishing self-contained (no trim, folder) for $RID..."
|
||||
dotnet publish "$PROJECT" \
|
||||
-c Release \
|
||||
-r "$RID" \
|
||||
--self-contained true
|
||||
fi
|
||||
|
||||
OUT_DIR="$REPO_ROOT/src/DnsmasqWebUI/bin/Release/net9.0/$RID/publish"
|
||||
echo ""
|
||||
echo "Done. Output: $OUT_DIR"
|
||||
echo "Run on this host: $OUT_DIR/DnsmasqWebUI"
|
||||
echo "Copy to another: rsync -av $OUT_DIR/ user@host:/opt/dnsmasq-webui/"
|
||||
Reference in New Issue
Block a user