143 lines
5.1 KiB
Bash
Executable File
143 lines
5.1 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
# WebDAV External Access Diagnostic Script
|
|
# This script helps diagnose why WebDAV is not accessible from external networks
|
|
|
|
echo "=========================================="
|
|
echo "WebDAV External Access Diagnostic Tool"
|
|
echo "=========================================="
|
|
echo ""
|
|
|
|
# Check if running as root (needed for some checks)
|
|
if [ "$EUID" -ne 0 ]; then
|
|
echo "⚠️ Some checks may require root privileges"
|
|
echo ""
|
|
fi
|
|
|
|
# 1. Check what's listening on port 5006
|
|
echo "1. Checking what's listening on port 5006..."
|
|
echo "-------------------------------------------"
|
|
if command -v netstat &> /dev/null; then
|
|
echo "Using netstat:"
|
|
netstat -tuln | grep 5006 || echo "❌ Nothing found listening on port 5006"
|
|
elif command -v ss &> /dev/null; then
|
|
echo "Using ss:"
|
|
ss -tuln | grep 5006 || echo "❌ Nothing found listening on port 5006"
|
|
else
|
|
echo "⚠️ netstat or ss not available"
|
|
fi
|
|
echo ""
|
|
|
|
# 2. Check if service is bound to localhost only
|
|
echo "2. Checking if service is bound to localhost only..."
|
|
echo "-------------------------------------------"
|
|
if command -v netstat &> /dev/null; then
|
|
netstat -tuln | grep 5006 | grep "127.0.0.1\|::1" && echo "❌ Service is bound to localhost only!" || echo "✅ Service is not bound to localhost only"
|
|
elif command -v ss &> /dev/null; then
|
|
ss -tuln | grep 5006 | grep "127.0.0.1\|::1" && echo "❌ Service is bound to localhost only!" || echo "✅ Service is not bound to localhost only"
|
|
fi
|
|
echo ""
|
|
|
|
# 3. Check if port 5006 is open in firewall
|
|
echo "3. Checking firewall status..."
|
|
echo "-------------------------------------------"
|
|
if command -v ufw &> /dev/null; then
|
|
echo "UFW Status:"
|
|
ufw status | grep 5006 || echo "⚠️ Port 5006 not found in UFW rules"
|
|
elif command -v firewall-cmd &> /dev/null; then
|
|
echo "firewalld Status:"
|
|
firewall-cmd --list-ports | grep 5006 || echo "⚠️ Port 5006 not found in firewalld rules"
|
|
elif command -v iptables &> /dev/null; then
|
|
echo "iptables rules for port 5006:"
|
|
iptables -L -n | grep 5006 || echo "⚠️ No iptables rules found for port 5006"
|
|
else
|
|
echo "⚠️ No common firewall tool detected"
|
|
fi
|
|
echo ""
|
|
|
|
# 4. Check WebDAV service status (common services)
|
|
echo "4. Checking WebDAV service status..."
|
|
echo "-------------------------------------------"
|
|
if systemctl list-units --type=service | grep -i webdav &> /dev/null; then
|
|
systemctl list-units --type=service | grep -i webdav | while read service; do
|
|
servicename=$(echo $service | awk '{print $1}')
|
|
echo "Service: $servicename"
|
|
systemctl status $servicename --no-pager | head -5
|
|
done
|
|
else
|
|
echo "⚠️ No WebDAV systemd service found"
|
|
echo "Checking common WebDAV processes:"
|
|
ps aux | grep -i webdav | grep -v grep || echo "No WebDAV processes found"
|
|
fi
|
|
echo ""
|
|
|
|
# 5. Test local connection
|
|
echo "5. Testing local connection to port 5006..."
|
|
echo "-------------------------------------------"
|
|
if command -v nc &> /dev/null; then
|
|
if nc -zv localhost 5006 2>&1; then
|
|
echo "✅ Local connection successful"
|
|
else
|
|
echo "❌ Local connection failed"
|
|
fi
|
|
else
|
|
echo "⚠️ netcat (nc) not available for connection test"
|
|
fi
|
|
echo ""
|
|
|
|
# 6. Check network interfaces
|
|
echo "6. Network interface information..."
|
|
echo "-------------------------------------------"
|
|
if command -v ip &> /dev/null; then
|
|
ip addr show | grep -E "^[0-9]+:|inet " | head -10
|
|
elif command -v ifconfig &> /dev/null; then
|
|
ifconfig | grep -E "^[a-z]|inet " | head -10
|
|
fi
|
|
echo ""
|
|
|
|
# 7. Check router/NAT configuration hints
|
|
echo "7. Router/NAT Configuration Checklist..."
|
|
echo "-------------------------------------------"
|
|
echo "Please verify on your router/NAS:"
|
|
echo " □ Port forwarding: External port 5006 → Internal NAS IP:5006"
|
|
echo " □ Firewall rules allow incoming connections on port 5006"
|
|
echo " □ NAT/UPnP is configured correctly"
|
|
echo " □ External IP matches: $(curl -s ifconfig.me 2>/dev/null || echo 'Unable to determine')"
|
|
echo ""
|
|
|
|
# 8. Common WebDAV configuration files to check
|
|
echo "8. Common WebDAV configuration locations..."
|
|
echo "-------------------------------------------"
|
|
config_locations=(
|
|
"/etc/apache2/sites-available/*webdav*"
|
|
"/etc/apache2/conf.d/*webdav*"
|
|
"/etc/nginx/sites-available/*webdav*"
|
|
"/etc/nginx/conf.d/*webdav*"
|
|
"/etc/lighttpd/lighttpd.conf"
|
|
"/etc/httpd/conf.d/*webdav*"
|
|
"/usr/local/etc/apache2/*webdav*"
|
|
)
|
|
|
|
for pattern in "${config_locations[@]}"; do
|
|
for file in $pattern; do
|
|
if [ -f "$file" ]; then
|
|
echo "Found: $file"
|
|
echo " Checking for Listen/ServerName directives..."
|
|
grep -E "Listen|ServerName|<VirtualHost|listen" "$file" | head -3 || true
|
|
fi
|
|
done
|
|
done
|
|
echo ""
|
|
|
|
echo "=========================================="
|
|
echo "Diagnostic Complete"
|
|
echo "=========================================="
|
|
echo ""
|
|
echo "Common Issues and Solutions:"
|
|
echo "1. If service is bound to 127.0.0.1: Change Listen directive to 0.0.0.0:5006"
|
|
echo "2. If firewall blocks port: Open port 5006 in firewall"
|
|
echo "3. If router blocks: Configure port forwarding for port 5006"
|
|
echo "4. If service not running: Start the WebDAV service"
|
|
echo ""
|
|
|