Skip to content

Commit b4b5006

Browse files
committed
✨ Update README and install script
1 parent 4c97cb9 commit b4b5006

File tree

2 files changed

+170
-139
lines changed

2 files changed

+170
-139
lines changed

README.md

Lines changed: 65 additions & 139 deletions
Original file line numberDiff line numberDiff line change
@@ -1,197 +1,123 @@
1-
# 🚀 Discord Bot IP Whitelister - Linux Service Setup
21

3-
This guide explains how to **install, configure, and run** the Discord bot as a **systemd service** on a Linux server.
2+
# Discord Bot IP Whitelister
43

4+
A Discord bot that allows users to manage their IP whitelisting and bans directly from Discord. With the `/whitelist` command, players can securely add their IP addresses to the UFW firewall of a game server, preventing unauthorized access and mitigating DDoS attacks.
5+
Admins have access to the `/ban` command, which allows them to ban a user by their Discord ID, preventing them from whitelisting their IP. This bot is designed for servers using IP-based whitelisting, such as FiveM, Minecraft, Rust, and more.
56

6-
## 📌 Prerequisites
7-
Before proceeding, ensure you have:
8-
- A **Linux server** (Ubuntu, Debian, CentOS, etc.)
9-
- **Go installed** (for building the binary)
10-
- **Systemd** (default in most modern Linux distributions)
11-
- **A valid `.env` file** with bot credentials
127

8+
## Features
9+
- **Slash command `/whitelist (ip)`**: Players can whitelist their IPs securely.
10+
- **Slash command `/ban (user_id)`**: Admins can prevent specific users from adding their IP.
11+
- **Prevents unauthorized access**: Only approved users can connect.
12+
- **DDoS Mitigation**: Reduces attack surface by limiting access to verified players.
13+
- **Multi-Game Support**: Works with FiveM, Minecraft, Rust, and any server using UFW.
14+
- **SQLite Database**: Keeps a log of whitelisted users and their IPs for traceability.
15+
- **Systemd Service Support**: Runs as a background service for automatic startup and reliability.
16+
- **Secure & Configurable**: Uses environment variables for easy customization.
1317

1418

15-
## 🛠️ Step 1: Build the Go Application
1619

17-
If you haven’t already compiled the bot, run:
20+
## Installation
1821

19-
```sh
20-
go build -o bot-app
21-
```
22-
23-
Move the binary to a suitable directory:
22+
### 1. One-Line Install Command
23+
Run this command to **automatically download and install** the bot:
2424

2525
```sh
26-
sudo mv bot-app /usr/local/bin/
26+
curl -sSL https://raw.githubusercontent.com/geekloper/discord-bot-ip-whitelister/main/install.sh | sudo bash
2727
```
2828

29-
Ensure the binary has execution permissions:
30-
31-
```sh
32-
sudo chmod +x /usr/local/bin/bot-app
33-
```
29+
This script will:
30+
- Checks if **UFW** and **SQLite3** are installed (prompts if missing).
31+
- Creates a dedicated system user (`whitelistbot`).
32+
- Downloads the latest bot binary from GitHub.
33+
- Installs the bot to `/usr/local/bin/`.
34+
- Sets up configuration files in `/etc/ip_whitelister_bot/`.
35+
- Creates a SQLite database in `/var/lib/ip_whitelister_bot/`.
36+
- Configures and enables a **systemd service** for auto-restart.
3437

3538
---
3639

37-
## 📁 Step 2: Create an Environment Variables File
38-
39-
To securely store environment variables, create a dedicated environment file:
40+
### 2. Configure the Bot
41+
Edit the `.env` file to add your Discord bot credentials:
4042

4143
```sh
42-
sudo nano /etc/default/discord-bot
44+
sudo vi /etc/whitelist_bot/.env
4345
```
4446

45-
Add your required environment variables:
46-
47+
Example `.env` file:
4748
```ini
48-
BOT_TOKEN=your_bot_token_here
49-
BOT_GUILD_ID=your_guild_id
50-
SERVICE_PORTS=80,443
51-
DELETE_COMMADS=true
52-
```
53-
54-
Ensure the file is readable by the service user:
55-
56-
```sh
57-
sudo chmod 600 /etc/default/discord-bot
49+
BOT_TOKEN=your-bot-token
50+
BOT_GUILD_ID=your-guild-id
51+
ADMIN_IDS=1234567890,0987654321
52+
DELETE_COMMANDS=true
53+
SERVICES=80/tcp,443/tcp
54+
DEBUG=false
55+
UFW_PATH=/usr/sbin/ufw
56+
DB_PATH=/var/lib/ip_whitelister_bot/whitelist.db
5857
```
5958

6059
---
6160

62-
## ⚙️ Step 3: Create a Systemd Service File
63-
64-
To manage the bot as a Linux service, create a `systemd` unit file:
61+
### 3. Start the Bot
62+
Once configured, start and enable the bot:
6563

6664
```sh
67-
sudo nano /etc/systemd/system/discord-bot.service
68-
```
69-
70-
Paste the following configuration:
71-
72-
```ini
73-
[Unit]
74-
Description=Discord Bot IP Whitelister
75-
After=network.target
76-
77-
[Service]
78-
Type=simple
79-
User=your_linux_user # Change this to the appropriate user
80-
Group=your_linux_user
81-
WorkingDirectory=/usr/local/bin
82-
ExecStart=/usr/local/bin/bot-app
83-
Restart=always
84-
RestartSec=5
85-
EnvironmentFile=/etc/default/discord-bot # Load environment variables
86-
87-
[Install]
88-
WantedBy=multi-user.target
65+
sudo systemctl restart ip_whitelister_bot
66+
sudo systemctl enable ip_whitelister_bot
8967
```
9068

91-
Save and exit.
92-
93-
Reload `systemd` to apply the changes:
69+
Check if the bot is running:
9470

9571
```sh
96-
sudo systemctl daemon-reload
72+
sudo systemctl status ip_whitelister_bot
9773
```
9874

99-
---
100-
101-
## 🚀 Step 4: Start and Enable the Service
102-
103-
Start the bot service:
75+
View logs:
10476

10577
```sh
106-
sudo systemctl start discord-bot
78+
sudo journalctl -u ip_whitelister_bot -f
10779
```
10880

109-
Enable it to run on boot:
81+
## Usage
11082

111-
```sh
112-
sudo systemctl enable discord-bot
113-
```
83+
## 🛠️ Usage
11484

115-
Check if the service is running:
85+
### ✅ Whitelisting an IP
86+
Users can whitelist their IP via the Discord command:
11687

117-
```sh
118-
sudo systemctl status discord-bot
11988
```
120-
121-
You should see output similar to:
122-
123-
```sh
124-
● discord-bot.service - Discord Bot IP Whitelister
125-
Loaded: loaded (/etc/systemd/system/discord-bot.service; enabled; vendor preset: enabled)
126-
Active: active (running) since Sun 2025-02-08 14:00:00 UTC; 2s ago
127-
Main PID: 12345 (bot-app)
128-
CGroup: /system.slice/discord-bot.service
89+
/whitelist 192.168.1.1
12990
```
13091

131-
---
132-
133-
## 📊 Step 5: Viewing Logs
92+
This will automatically add the IP to UFW and store it in the database.
13493

135-
To monitor logs in real time:
94+
### ❌ Banning a User
95+
Admins can **ban a user by Discord ID** to prevent them from using `/whitelist`:
13696

137-
```sh
138-
sudo journalctl -u discord-bot -f
13997
```
140-
141-
To view logs for the last hour:
142-
143-
```sh
144-
sudo journalctl -u discord-bot --since "1 hour ago"
98+
/ban 1234567890
14599
```
146100

147-
---
148-
149-
## 🔄 Managing the Service
101+
Banning removes their ability to whitelist IPs & deny their ips in UFW.
150102

151-
Restart the bot:
152103

153-
```sh
154-
sudo systemctl restart discord-bot
155-
```
156104

157-
Stop the bot:
105+
## Uninstallation
106+
To remove the bot completely:
158107

159108
```sh
160-
sudo systemctl stop discord-bot
109+
sudo systemctl stop ip_whitelister_bot
110+
sudo systemctl disable ip_whitelister_bot
111+
sudo rm -rf /usr/local/bin/ip_whitelister_bot /etc/ip_whitelister_bot /var/lib/ip_whitelister_bot /etc/systemd/system/ip_whitelister_bot.service
112+
sudo systemctl daemon-reload
161113
```
162114

163-
Disable it from starting on boot:
115+
---
164116

165-
```sh
166-
sudo systemctl disable discord-bot
167-
```
117+
## Contributing
118+
Contributions are welcome! If you find a bug or want to improve the bot, feel free to submit an issue or pull request.
168119

169120
---
170121

171-
## 🛠️ Troubleshooting
172-
173-
### ❌ The service doesn’t start
174-
- Check logs using:
175-
```sh
176-
sudo journalctl -u discord-bot -xe
177-
```
178-
- Ensure the binary is executable:
179-
```sh
180-
sudo chmod +x /usr/local/bin/bot-app
181-
```
182-
- Make sure the environment file exists and has correct permissions:
183-
```sh
184-
ls -l /etc/default/discord-bot
185-
```
186-
187-
### 🔄 Changes not applying after updating `.env`
188-
- Restart the service:
189-
```sh
190-
sudo systemctl restart discord-bot
191-
```
192-
- If still not working, reload `systemd`:
193-
```sh
194-
sudo systemctl daemon-reload
195-
sudo systemctl restart discord-bot
196-
```
197-
122+
## License
123+
This project is open-source under the MIT License.

install.sh

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
#!/bin/bash
2+
3+
set -e # Stops the script if a command fails
4+
5+
echo "📦 Installing the Discord Whitelist Bot..."
6+
7+
8+
# Checking if UFW is installed
9+
if ! command -v ufw &> /dev/null; then
10+
echo "❌ UFW is not installed. Please install it using:"
11+
echo " sudo apt update && sudo apt install ufw -y"
12+
exit 1
13+
fi
14+
15+
# 2. Checking if SQLite3 is installed
16+
if ! command -v sqlite3 &> /dev/null; then
17+
echo "❌ SQLite3 is not installed. Please install it using:"
18+
echo " sudo apt update && sudo apt install sqlite3 -y"
19+
exit 1
20+
fi
21+
22+
# Creating the system user (without shell)
23+
if ! id "whitelistbot" &>/dev/null; then
24+
useradd -r -m -d /var/lib/ip_whitelister_bot -s /usr/sbin/nologin whitelistbot
25+
fi
26+
27+
28+
# Creating the necessary directories
29+
30+
mkdir -p /etc/ip_whitelister_bot
31+
mkdir -p /var/lib/ip_whitelister_bot
32+
mkdir -p /var/log
33+
34+
35+
36+
# Download the latest release from GitHub
37+
GITHUB_REPO="geekloper/discord-bot-ip-whitelister" # Remplace par ton repo GitHub
38+
LATEST_RELEASE_URL=$(curl -s https://api.github.com/repos/$GITHUB_REPO/releases/latest | grep "browser_download_url" | cut -d '"' -f 4)
39+
40+
if [[ -z "$LATEST_RELEASE_URL" ]]; then
41+
echo "❌ Failed to fetch the latest release. Check your GitHub repo and tags."
42+
exit 1
43+
fi
44+
45+
echo "⬇️ Downloading latest release from $LATEST_RELEASE_URL..."
46+
curl -L $LATEST_RELEASE_URL -o /usr/local/bin/ip_whitelister_bot
47+
48+
# Set permission
49+
chmod +x /usr/local/bin/ip_whitelister_bot
50+
51+
# Creating the default .env file if it doesn't exist
52+
if [ ! -f /etc/ip_whitelister_bot/.env ]; then
53+
cat <<EOL > /etc/ip_whitelister_bot/.env
54+
BOT_TOKEN=<your_bot_token>
55+
BOT_GUILD_ID=<server_guild_id>
56+
ADMIN_IDS=<admin_id>,<admin_id>,...
57+
DELETE_COMMANDS=true
58+
SERVICES=80/tcp,443/tcp
59+
DEBUG=0
60+
UFW_PATH=/usr/sbin/ufw
61+
DB_PATH=/var/lib/ip_whitelister_bot/whitelist.db
62+
EOL
63+
echo "✅ Configuration file created in /etc/ip_whitelister_bot/.env"
64+
fi
65+
66+
# Creating the systemd service
67+
cat <<EOL > /etc/systemd/system/ip_whitelister_bot.service
68+
[Unit]
69+
Description=Discord Whitelist Bot
70+
After=network.target
71+
72+
[Service]
73+
Type=simple
74+
User=whitelistbot
75+
Group=whitelistbot
76+
WorkingDirectory=/var/lib/ip_whitelister_bot
77+
ExecStart=/usr/local/bin/ip_whitelister_bot
78+
Restart=always
79+
EnvironmentFile=/etc/ip_whitelister_bot/.env
80+
StandardOutput=append:/var/log/ip_whitelister_bot.log
81+
StandardError=append:/var/log/ip_whitelister_bot.log
82+
83+
[Install]
84+
WantedBy=multi-user.target
85+
EOL
86+
87+
# Setting the correct permissions
88+
chown -R whitelistbot:whitelistbot /var/lib/ip_whitelister_bot
89+
chmod 600 /etc/ip_whitelister_bot/.env
90+
91+
92+
# Give bot sudo permission for UFW
93+
cat <<EOL > /etc/sudoers.d/ip_whitelister_bot
94+
whitelistbot ALL=(ALL) NOPASSWD: /usr/sbin/ufw
95+
EOL
96+
chmod 440 /etc/sudoers.d/ip_whitelister_bot
97+
98+
99+
# Reloading systemd and enabling the service
100+
systemctl daemon-reload
101+
systemctl enable ip_whitelister_bot
102+
systemctl restart ip_whitelister_bot
103+
104+
echo "✅ Installation completed!"
105+
echo "👉 Remember to edit /etc/ip_whitelister_bot/.env and restart the bot using: systemctl restart ip_whitelister_bot"

0 commit comments

Comments
 (0)