Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions README-fa.md
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,34 @@ bash <(curl -Ls https://raw.githubusercontent.com/bugfloyd/dnstt-deploy/main/dns
# اسکریپت به طور خودکار بروزرسانی‌ها را تشخیص داده و نصب خواهد کرد
```

### حذف نصب

برای حذف کامل سرور dnstt و تمام اجزای آن:

```bash
bash <(curl -Ls https://raw.githubusercontent.com/bugfloyd/dnstt-deploy/main/dnstt-deploy.sh) uninstall
```

یا اگر اسکریپت نصب شده است:

```bash
dnstt-deploy uninstall
```

فرآیند حذف نصب موارد زیر را انجام خواهد داد:
- توقف و غیرفعال کردن تمام سرویس‌ها (dnstt-server و danted)
- حذف فایل‌های سرویس systemd
- حذف باینری dnstt-server
- حذف فایل‌ها و دایرکتوری پیکربندی (`/etc/dnstt`)
- حذف قوانین iptables
- حذف قوانین firewall (firewalld/ufw)
- حذف کاربر سیستم `dnstt`
- حذف اختیاری اسکریپت `dnstt-deploy` (با تأیید)

**توجه**: اگر Dante (dante-server) را از طریق package manager نصب کرده‌اید، ممکن است بخواهید آن را به صورت دستی حذف کنید:
- **RHEL-based** (dnf/yum): `sudo dnf remove dante-server` یا `sudo yum remove dante-server`
- **Debian-based** (apt): `sudo apt remove dante-server`

## عیب‌یابی

### استفاده از ابزارهای داخلی
Expand Down
28 changes: 28 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,34 @@ bash <(curl -Ls https://raw.githubusercontent.com/bugfloyd/dnstt-deploy/main/dns
# The script will detect and install updates automatically
```

### Uninstalling

To completely remove dnstt server and all its components:

```bash
bash <(curl -Ls https://raw.githubusercontent.com/bugfloyd/dnstt-deploy/main/dnstt-deploy.sh) uninstall
```

Or if the script is installed:

```bash
dnstt-deploy uninstall
```

The uninstall process will:
- Stop and disable all services (dnstt-server and danted)
- Remove systemd service files
- Remove the dnstt-server binary
- Remove configuration files and directory (`/etc/dnstt`)
- Remove iptables rules
- Remove firewall rules (firewalld/ufw)
- Remove the `dnstt` system user
- Optionally remove the `dnstt-deploy` script itself (with confirmation)

**Note**: If you installed Dante (dante-server) via package manager, you may want to remove it manually:
- **RHEL-based** (dnf/yum): `sudo dnf remove dante-server` or `sudo yum remove dante-server`
- **Debian-based** (apt): `sudo apt remove dante-server`

## Troubleshooting

### Using the Built-in Tools
Expand Down
154 changes: 154 additions & 0 deletions dnstt-deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -1113,8 +1113,162 @@ display_final_info() {
print_success_box
}

# Function to remove iptables rules
remove_iptables_rules() {
print_status "Removing iptables rules..."

if ! command -v iptables &> /dev/null; then
print_warning "iptables not found, skipping rule removal"
return 0
fi

# Get the primary network interface
local interface
interface=$(ip route | grep default | awk '{print $5}' | head -1)
if [[ -z "$interface" ]]; then
interface=$(ip link show | grep -E "^[0-9]+: (eth|ens|enp)" | head -1 | cut -d':' -f2 | awk '{print $1}')
if [[ -z "$interface" ]]; then
interface="eth0"
fi
fi

# Remove IPv4 rules
print_status "Removing IPv4 iptables rules..."
iptables -D INPUT -p udp --dport "$DNSTT_PORT" -j ACCEPT 2>/dev/null || true
iptables -t nat -D PREROUTING -i "$interface" -p udp --dport 53 -j REDIRECT --to-ports "$DNSTT_PORT" 2>/dev/null || true

# Remove IPv6 rules if available
if command -v ip6tables &> /dev/null && [ -f /proc/net/if_inet6 ]; then
print_status "Removing IPv6 iptables rules..."
ip6tables -D INPUT -p udp --dport "$DNSTT_PORT" -j ACCEPT 2>/dev/null || true
ip6tables -t nat -D PREROUTING -i "$interface" -p udp --dport 53 -j REDIRECT --to-ports "$DNSTT_PORT" 2>/dev/null || true
fi

# Save iptables rules after removal
save_iptables_rules

print_status "iptables rules removed"
}

# Function to remove firewall rules
remove_firewall_rules() {
print_status "Removing firewall rules..."

# Remove firewalld rules
if command -v firewall-cmd &> /dev/null && systemctl is-active --quiet firewalld; then
print_status "Removing firewalld rules..."
firewall-cmd --permanent --remove-port="$DNSTT_PORT"/udp 2>/dev/null || true
firewall-cmd --permanent --remove-port=53/udp 2>/dev/null || true
firewall-cmd --reload 2>/dev/null || true
print_status "Firewalld rules removed"
fi

# Remove ufw rules
if command -v ufw &> /dev/null && ufw status | grep -q "Status: active"; then
print_status "Removing ufw rules..."
ufw delete allow "$DNSTT_PORT"/udp 2>/dev/null || true
ufw delete allow 53/udp 2>/dev/null || true
print_status "UFW rules removed"
fi
}

# Function to uninstall dnstt
uninstall() {
print_status "Starting dnstt uninstallation..."

# Detect OS for package manager
detect_os

# Stop and disable services
print_status "Stopping services..."
if systemctl is-active --quiet dnstt-server; then
systemctl stop dnstt-server
print_status "dnstt-server service stopped"
fi

if systemctl is-active --quiet danted; then
systemctl stop danted
print_status "Dante service stopped"
fi

# Disable services
if systemctl is-enabled --quiet dnstt-server 2>/dev/null; then
systemctl disable dnstt-server
print_status "dnstt-server service disabled"
fi

if systemctl is-enabled --quiet danted 2>/dev/null; then
systemctl disable danted
print_status "Dante service disabled"
fi

# Remove systemd service files
print_status "Removing systemd service files..."
if [ -f "${SYSTEMD_DIR}/dnstt-server.service" ]; then
rm -f "${SYSTEMD_DIR}/dnstt-server.service"
systemctl daemon-reload
print_status "Systemd service file removed"
fi

# Remove binaries
print_status "Removing binaries..."
if [ -f "${INSTALL_DIR}/dnstt-server" ]; then
rm -f "${INSTALL_DIR}/dnstt-server"
print_status "dnstt-server binary removed"
fi

# Remove configuration files
print_status "Removing configuration files..."
if [ -d "$CONFIG_DIR" ]; then
rm -rf "$CONFIG_DIR"
print_status "Configuration directory removed: $CONFIG_DIR"
fi

# Remove iptables rules
remove_iptables_rules

# Remove firewall rules
remove_firewall_rules

# Remove dnstt user
print_status "Removing dnstt user..."
if id "$DNSTT_USER" &>/dev/null; then
userdel "$DNSTT_USER" 2>/dev/null || true
print_status "User $DNSTT_USER removed"
fi

# Optionally remove dnstt-deploy script
print_question "Do you want to remove the dnstt-deploy script itself? (y/N): "
read -r remove_script
if [[ "$remove_script" =~ ^[Yy]$ ]]; then
if [ -f "$SCRIPT_INSTALL_PATH" ]; then
rm -f "$SCRIPT_INSTALL_PATH"
print_status "dnstt-deploy script removed from $SCRIPT_INSTALL_PATH"
fi
fi

print_status "Uninstallation completed successfully!"
echo ""
print_status "Note: If you installed Dante (dante-server) via package manager,"
print_status " you may want to remove it manually with:"
case $PKG_MANAGER in
dnf|yum)
echo -e " ${YELLOW}$PKG_MANAGER remove dante-server${NC}"
;;
apt)
echo -e " ${YELLOW}apt remove dante-server${NC}"
;;
esac
}

# Main function
main() {
# Check for uninstall argument
if [ "$1" = "uninstall" ]; then
uninstall
exit 0
fi

# If not running from installed location (curl/GitHub), install the script first
if [ "$0" != "$SCRIPT_INSTALL_PATH" ]; then
print_status "Installing dnstt-deploy script..."
Expand Down