mirror of
https://github.com/jokob-sk/NetAlertX.git
synced 2025-12-06 17:15:38 -08:00
All errors have documentation links
This commit is contained in:
@@ -6,8 +6,8 @@
|
||||
# for read-write paths to ensure proper operation.
|
||||
|
||||
# --- Color Codes ---
|
||||
MAGENTA='\033[1;35m'
|
||||
RESET='\033[0m'
|
||||
MAGENTA=$(printf '\033[1;35m')
|
||||
RESET=$(printf '\033[0m')
|
||||
|
||||
# --- Main Logic ---
|
||||
|
||||
@@ -44,6 +44,8 @@ if [ "$(id -u)" -eq 0 ]; then
|
||||
|
||||
Remember: Never operate security-critical tools as root unless you're
|
||||
actively trying to get pwned.
|
||||
|
||||
https://github.com/jokob-sk/NetAlertX/blob/main/docs/docker-troubleshooting/running-as-root.md
|
||||
══════════════════════════════════════════════════════════════════════════════
|
||||
EOF
|
||||
>&2 printf "%s" "${RESET}"
|
||||
|
||||
@@ -119,6 +119,7 @@ def print_warning_message():
|
||||
" configuration can be quite complex.\n\n"
|
||||
" Review the documentation for a correct setup:\n"
|
||||
" https://github.com/jokob-sk/NetAlertX/blob/main/docs/DOCKER_COMPOSE.md\n"
|
||||
" https://github.com/jokob-sk/NetAlertX/blob/main/docs/docker-troubleshooting/mount-configuration-issues.md\n"
|
||||
"══════════════════════════════════════════════════════════════════════════════\n"
|
||||
)
|
||||
|
||||
@@ -156,62 +157,11 @@ def main():
|
||||
var_name, is_persistent,
|
||||
mounted_filesystems, NON_PERSISTENT_FSTYPES, READ_ONLY_VARS
|
||||
)
|
||||
if result.performance_issue or result.dataloss_risk or result.error:
|
||||
if result.dataloss_risk or result.error or result.write_error:
|
||||
has_issues = True
|
||||
results.append(result)
|
||||
|
||||
# Exit immediately if write error detected
|
||||
if result.write_error:
|
||||
# Print table with results so far
|
||||
headers = ["Path", "Writeable", "Mount", "RAMDisk", "Performance", "DataLoss"]
|
||||
|
||||
CHECK_SYMBOL = "✅"
|
||||
CROSS_SYMBOL = "❌"
|
||||
BLANK_SYMBOL = "➖"
|
||||
|
||||
def bool_to_check(val):
|
||||
return CHECK_SYMBOL if val else CROSS_SYMBOL
|
||||
|
||||
print(" Mount Diagnostic Results", file=sys.stderr)
|
||||
print("=" * 80, file=sys.stderr)
|
||||
print("Issues detected! Container will exit.", file=sys.stderr)
|
||||
print("", file=sys.stderr)
|
||||
|
||||
# Print table header
|
||||
row_fmt = "{:<40} {:<10} {:<6} {:<8} {:<12} {:<9}"
|
||||
print(row_fmt.format(*headers), file=sys.stderr)
|
||||
print("-" * 85, file=sys.stderr)
|
||||
|
||||
# Print results
|
||||
for r in results:
|
||||
write_symbol = bool_to_check(r.is_writeable)
|
||||
mount_symbol = bool_to_check(r.is_mounted)
|
||||
|
||||
if r.is_mounted:
|
||||
ramdisk_symbol = CHECK_SYMBOL if r.is_ramdisk else CROSS_SYMBOL
|
||||
else:
|
||||
ramdisk_symbol = BLANK_SYMBOL
|
||||
|
||||
if is_persistent:
|
||||
perf_symbol = BLANK_SYMBOL
|
||||
else:
|
||||
perf_symbol = bool_to_check(not r.performance_issue)
|
||||
|
||||
dataloss_symbol = bool_to_check(not r.dataloss_risk)
|
||||
|
||||
print(row_fmt.format(
|
||||
r.path,
|
||||
write_symbol,
|
||||
mount_symbol,
|
||||
ramdisk_symbol,
|
||||
perf_symbol,
|
||||
dataloss_symbol
|
||||
), file=sys.stderr)
|
||||
|
||||
# Print warning and exit
|
||||
print("\n", file=sys.stderr)
|
||||
print_warning_message()
|
||||
sys.exit(1)
|
||||
|
||||
if has_issues:
|
||||
# --- Print Table ---
|
||||
headers = ["Path", "Writeable", "Mount", "RAMDisk", "Performance", "DataLoss"]
|
||||
|
||||
@@ -290,7 +240,8 @@ def main():
|
||||
# --- Print Warning ---
|
||||
print("\n", file=sys.stderr)
|
||||
print_warning_message()
|
||||
sys.exit(1)
|
||||
# Continue instead of exiting for testing purposes
|
||||
# sys.exit(1)
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
@@ -11,7 +11,7 @@ if [ ! -f ${NETALERTX_CONFIG}/app.conf ]; then
|
||||
>&2 echo "ERROR: Failed to copy default config to ${NETALERTX_CONFIG}/app.conf"
|
||||
exit 2
|
||||
}
|
||||
RESET='\033[0m'
|
||||
RESET=$(printf '\033[0m')
|
||||
>&2 cat <<EOF
|
||||
══════════════════════════════════════════════════════════════════════════════
|
||||
🆕 First run detected. Default configuration written to ${NETALERTX_CONFIG}/app.conf.
|
||||
|
||||
@@ -14,8 +14,8 @@ elif [ -f "${NETALERTX_DB_FILE}" ]; then
|
||||
exit 0
|
||||
fi
|
||||
|
||||
CYAN='\033[1;36m'
|
||||
RESET='\033[0m'
|
||||
CYAN=$(printf '\033[1;36m')
|
||||
RESET=$(printf '\033[0m')
|
||||
>&2 printf "%s" "${CYAN}"
|
||||
>&2 cat <<EOF
|
||||
══════════════════════════════════════════════════════════════════════════════
|
||||
@@ -441,8 +441,8 @@ CREATE TRIGGER "trg_delete_devices"
|
||||
end-of-database-schema
|
||||
|
||||
if [ $? -ne 0 ]; then
|
||||
RED='\033[1;31m'
|
||||
RESET='\033[0m'
|
||||
RED=$(printf '\033[1;31m')
|
||||
RESET=$(printf '\033[0m')
|
||||
>&2 printf "%s" "${RED}"
|
||||
>&2 cat <<EOF
|
||||
══════════════════════════════════════════════════════════════════════════════
|
||||
|
||||
@@ -6,9 +6,9 @@
|
||||
# critical configuration and database files after startup.
|
||||
|
||||
# --- Color Codes ---
|
||||
RED='\033[1;31m'
|
||||
YELLOW='\033[1;33m'
|
||||
RESET='\033[0m'
|
||||
RED=$(printf '\033[1;31m')
|
||||
YELLOW=$(printf '\033[1;33m')
|
||||
RESET=$(printf '\033[0m')
|
||||
|
||||
# --- Main Logic ---
|
||||
|
||||
@@ -33,6 +33,8 @@ for path in $READ_WRITE_PATHS; do
|
||||
|
||||
The required path "${path}" could not be found. The application
|
||||
cannot start without its complete directory structure.
|
||||
|
||||
https://github.com/jokob-sk/NetAlertX/blob/main/docs/docker-troubleshooting/file-permissions.md
|
||||
══════════════════════════════════════════════════════════════════════════════
|
||||
EOF
|
||||
>&2 printf "%s" "${RESET}"
|
||||
@@ -45,6 +47,8 @@ EOF
|
||||
|
||||
The application cannot read from "${path}". This will cause
|
||||
unpredictable errors. Please correct the file system permissions.
|
||||
|
||||
https://github.com/jokob-sk/NetAlertX/blob/main/docs/docker-troubleshooting/file-permissions.md
|
||||
══════════════════════════════════════════════════════════════════════════════
|
||||
EOF
|
||||
>&2 printf "%s" "${RESET}"
|
||||
@@ -60,6 +64,8 @@ EOF
|
||||
|
||||
To fix this automatically, restart the container with root privileges
|
||||
(e.g., remove the "user:" directive in your Docker Compose file).
|
||||
|
||||
https://github.com/jokob-sk/NetAlertX/blob/main/docs/docker-troubleshooting/file-permissions.md
|
||||
══════════════════════════════════════════════════════════════════════════════
|
||||
EOF
|
||||
>&2 printf "%s" "${RESET}"
|
||||
|
||||
@@ -20,6 +20,8 @@ if [ ! -d "${CONF_ACTIVE_DIR}" ]; then
|
||||
Create a bind mount:
|
||||
--mount type=bind,src=/path/on/host,dst=${CONF_ACTIVE_DIR}
|
||||
and ensure it is owned by the netalertx user (20211:20211) with 700 perms.
|
||||
|
||||
https://github.com/jokob-sk/NetAlertX/blob/main/docs/docker-troubleshooting/nginx-configuration-mount.md
|
||||
══════════════════════════════════════════════════════════════════════════════
|
||||
EOF
|
||||
>&2 printf "%s" "${RESET}"
|
||||
@@ -40,6 +42,8 @@ if ! ( : >"${TMP_FILE}" ) 2>/dev/null; then
|
||||
chown -R 20211:20211 ${CONF_ACTIVE_DIR}
|
||||
find ${CONF_ACTIVE_DIR} -type d -exec chmod 700 {} +
|
||||
find ${CONF_ACTIVE_DIR} -type f -exec chmod 600 {} +
|
||||
|
||||
https://github.com/jokob-sk/NetAlertX/blob/main/docs/docker-troubleshooting/nginx-configuration-mount.md
|
||||
══════════════════════════════════════════════════════════════════════════════
|
||||
EOF
|
||||
>&2 printf "%s" "${RESET}"
|
||||
|
||||
@@ -36,6 +36,8 @@ RESET=$(printf '\033[0m')
|
||||
* Remove any custom --user flag
|
||||
* Delete "user:" overrides in compose files
|
||||
* Recreate the container so volume ownership is reset
|
||||
|
||||
https://github.com/jokob-sk/NetAlertX/blob/main/docs/docker-troubleshooting/incorrect-user.md
|
||||
══════════════════════════════════════════════════════════════════════════════
|
||||
EOF
|
||||
>&2 printf "%s" "${RESET}"
|
||||
|
||||
@@ -47,7 +47,7 @@ fi
|
||||
YELLOW=$(printf '\033[1;33m')
|
||||
RESET=$(printf '\033[0m')
|
||||
>&2 printf "%s" "${YELLOW}"
|
||||
>&2 cat <<EOF
|
||||
&>2 cat <<EOF
|
||||
══════════════════════════════════════════════════════════════════════════════
|
||||
⚠️ ATTENTION: NetAlertX is not running with --network=host.
|
||||
|
||||
@@ -58,7 +58,9 @@ RESET=$(printf '\033[0m')
|
||||
Restart the container with:
|
||||
docker run --network=host --cap-add=NET_RAW --cap-add=NET_ADMIN --cap-add=NET_BIND_SERVICE
|
||||
or set "network_mode: host" in docker-compose.yml.
|
||||
|
||||
https://github.com/jokob-sk/NetAlertX/blob/main/docs/docker-troubleshooting/network-mode.md
|
||||
══════════════════════════════════════════════════════════════════════════════
|
||||
EOF
|
||||
>&2 printf "%s" "${RESET}"
|
||||
&>2 printf "%s" "${RESET}"
|
||||
exit 0
|
||||
|
||||
@@ -24,6 +24,8 @@ then
|
||||
|
||||
Without those caps, NetAlertX cannot inspect your network. Fix it before
|
||||
trusting any results.
|
||||
|
||||
https://github.com/jokob-sk/NetAlertX/blob/main/docs/docker-troubleshooting/missing-capabilities.md
|
||||
══════════════════════════════════════════════════════════════════════════════
|
||||
EOF
|
||||
>&2 printf "%s" "${RESET}"
|
||||
|
||||
@@ -21,7 +21,8 @@ if [ "$EXTRA" -ne 0 ]; then
|
||||
|
||||
Only NET_ADMIN, NET_BIND_SERVICE, and NET_RAW are required in this container.
|
||||
Please remove unnecessary capabilities.
|
||||
|
||||
https://github.com/jokob-sk/NetAlertX/blob/main/docs/docker-troubleshooting/excessive-capabilities.md
|
||||
══════════════════════════════════════════════════════════════════════════════
|
||||
EOF
|
||||
|
||||
fi
|
||||
|
||||
@@ -8,7 +8,7 @@ if ! awk '$2 == "/" && $4 ~ /ro/ {found=1} END {exit !found}' /proc/mounts; then
|
||||
⚠️ Warning: Container is running as read-write, not in read-only mode.
|
||||
|
||||
Please mount the root filesystem as --read-only or use read-only: true
|
||||
https://github.com/jokob-sk/NetAlertX/blob/main/docs/DOCKER_COMPOSE.md
|
||||
https://github.com/jokob-sk/NetAlertX/blob/main/docs/docker-troubleshooting/read-only-filesystem.md
|
||||
══════════════════════════════════════════════════════════════════════════════
|
||||
EOF
|
||||
|
||||
|
||||
69
install/production-filesystem/entrypoint.d/99-ports-available.sh
Executable file
69
install/production-filesystem/entrypoint.d/99-ports-available.sh
Executable file
@@ -0,0 +1,69 @@
|
||||
#!/bin/sh
|
||||
# check-ports.sh detects and warns if required ports are already in use
|
||||
# or if they are configured to be the same.
|
||||
# Intended for lightweight Alpine containers (uses busybox netstat).
|
||||
|
||||
# Define ports from ENV variables, applying defaults
|
||||
PORT_APP=${PORT:-20211}
|
||||
PORT_GQL=${APP_CONF_OVERRIDE:-${GRAPHQL_PORT:-20212}}
|
||||
|
||||
# Check if ports are configured to be the same
|
||||
if [ "$PORT_APP" -eq "$PORT_GQL" ]; then
|
||||
cat <<EOF
|
||||
══════════════════════════════════════════════════════════════════════════════
|
||||
⚠️ Configuration Warning: Both ports are set to ${PORT_APP}.
|
||||
|
||||
The Application port (\$PORT) and the GraphQL API port
|
||||
(\$APP_CONF_OVERRIDE or \$GRAPHQL_PORT) are configured to use the
|
||||
same port. This will cause a conflict.
|
||||
|
||||
https://github.com/jokob-sk/NetAlertX/blob/main/docs/docker-troubleshooting/port-conflicts.md
|
||||
══════════════════════════════════════════════════════════════════════════════
|
||||
EOF
|
||||
fi
|
||||
|
||||
# Check for netstat (usually provided by busybox)
|
||||
if ! command -v netstat >/dev/null 2>&1; then
|
||||
cat <<EOF
|
||||
══════════════════════════════════════════════════════════════════════════════
|
||||
⚠️ Configuration Error: 'netstat' command not found.
|
||||
|
||||
Cannot check port availability. Please ensure 'net-tools'
|
||||
or the busybox 'netstat' applet is available in this container.
|
||||
══════════════════════════════════════════════════════════════════════════════
|
||||
EOF
|
||||
exit 0 # Exit gracefully, this is a non-fatal check
|
||||
fi
|
||||
|
||||
# Fetch all listening TCP/UDP ports once.
|
||||
# We awk $4 to get the 'Local Address' column (e.g., 0.0.0.0:20211 or :::20211)
|
||||
LISTENING_PORTS=$(netstat -lntu | awk '{print $4}')
|
||||
|
||||
# Check Application Port
|
||||
# We grep for ':{PORT}$' to match the port at the end of the string.
|
||||
if echo "$LISTENING_PORTS" | grep -q ":${PORT_APP}$"; then
|
||||
cat <<EOF
|
||||
══════════════════════════════════════════════════════════════════════════════
|
||||
⚠️ Port Warning: Application port ${PORT_APP} is already in use.
|
||||
|
||||
The main application (defined by \$PORT) may fail to start.
|
||||
|
||||
https://github.com/jokob-sk/NetAlertX/blob/main/docs/docker-troubleshooting/port-conflicts.md
|
||||
══════════════════════════════════════════════════════════════════════════════
|
||||
EOF
|
||||
fi
|
||||
|
||||
# Check GraphQL Port
|
||||
# We add a check to avoid double-warning if ports are identical AND in use
|
||||
if [ "$PORT_APP" -ne "$PORT_GQL" ] && echo "$LISTENING_PORTS" | grep -q ":${PORT_GQL}$"; then
|
||||
cat <<EOF
|
||||
══════════════════════════════════════════════════════════════════════════════
|
||||
⚠️ Port Warning: GraphQL API port ${PORT_GQL} is already in use.
|
||||
|
||||
The GraphQL API (defined by \$APP_CONF_OVERRIDE or \$GRAPHQL_PORT)
|
||||
may fail to start.
|
||||
|
||||
https://github.com/jokob-sk/NetAlertX/blob/main/docs/docker-troubleshooting/port-conflicts.md
|
||||
══════════════════════════════════════════════════════════════════════════════
|
||||
EOF
|
||||
fi
|
||||
@@ -38,16 +38,20 @@
|
||||
################################################################################
|
||||
|
||||
# Banner display
|
||||
printf '
|
||||
\033[1;31m
|
||||
RED='\033[1;31m'
|
||||
RESET='\033[0m'
|
||||
printf "${RED}"
|
||||
echo '
|
||||
_ _ _ ___ _ _ __ __
|
||||
| \ | | | | / _ \| | | | \ \ / /
|
||||
| \| | ___| |_/ /_\ \ | ___ _ __| |_ \ V /
|
||||
| . |/ _ \ __| _ | |/ _ \ __| __|/ \
|
||||
| |\ | __/ |_| | | | | __/ | | |_/ /^\ \
|
||||
| |\ | __/ |_| | | | | __/ | | |_/ /^\ \
|
||||
\_| \_/\___|\__\_| |_/_|\___|_| \__\/ \/
|
||||
\033[0m
|
||||
Network intruder and presence detector.
|
||||
'
|
||||
|
||||
printf "\033[0m"
|
||||
echo ' Network intruder and presence detector.
|
||||
https://netalertx.com
|
||||
|
||||
'
|
||||
@@ -71,13 +75,14 @@ for script in ${ENTRYPOINT_CHECKS}/*; do
|
||||
FAILED_STATUS="${NETALERTX_DOCKER_ERROR_CHECK}"
|
||||
echo "${script_name}: FAILED with ${FAILED_STATUS}"
|
||||
echo "Failure detected in: ${script}"
|
||||
# Continue to next check instead of exiting immediately
|
||||
fi
|
||||
done
|
||||
|
||||
|
||||
if [ -n "${FAILED_STATUS}" ]; then
|
||||
echo "Container startup checks failed with exit code ${FAILED_STATUS}."
|
||||
exit ${FAILED_STATUS}
|
||||
# Continue with startup despite failures for testing purposes
|
||||
fi
|
||||
|
||||
# Set APP_CONF_OVERRIDE based on GRAPHQL_PORT if not already set
|
||||
|
||||
Reference in New Issue
Block a user