diff --git a/Dockerfile b/Dockerfile index e7f667c..06ee745 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,13 +1,26 @@ -FROM node:22 +FROM node:22-alpine +# Устанавливаем необходимые пакеты +RUN apk update && \ + apk add --no-cache \ + wireguard-tools \ + iptables \ + iproute2 \ + openresolv \ + bash \ + curl && \ + rm -rf /var/cache/apk/* + +# Рабочая директория WORKDIR /app -# Копируем только package.json и package-lock.json для установки зависимостей -COPY package*.json /app/ - -# Устанавливаем зависимости +# Копируем зависимости и устанавливаем их +COPY package*.json ./ RUN npm install -# Исходный код и другие файлы будут синхронизироваться через volume mounts +# Копируем скрипт запуска +COPY ./wg/start.sh /app/start.sh +RUN chmod +x /app/start.sh -CMD ["node", "src/index.js"] \ No newline at end of file +# Команда для запуска +CMD ["/app/start.sh"] diff --git a/docker-compose.yml b/docker-compose.yml index 9412cba..e8320fd 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -24,3 +24,14 @@ services: - ./src:/app/src/ # Синхронизация исходного кода - ./package.json:/app/package.json # Синхронизация package.json - ./package-lock.json:/app/package-lock.json # Синхронизация package-lock.json + - ./wg/config/wg0.conf:/etc/wireguard/wg0.conf # Монтируем конфиг WireGuard + - ./wg/config/resolv.conf:/etc/resolv.conf # Монтируем resolv.conf + - ./wg/start.sh:/app/start.sh # Монтируем start.sh + cap_add: # Необходимо для работы WireGuard + - NET_ADMIN + - SYS_MODULE + sysctls: + - net.ipv4.conf.all.src_valid_mark=1 # Необходимо для маршрутизации + privileged: true # Даем контейнеру повышенные привилегии + networks: + default: \ No newline at end of file diff --git a/src/handlers/adminHandlers/adminLocationHandler.js b/src/handlers/adminHandlers/adminLocationHandler.js index 88d4572..af2e4e7 100644 --- a/src/handlers/adminHandlers/adminLocationHandler.js +++ b/src/handlers/adminHandlers/adminLocationHandler.js @@ -124,6 +124,41 @@ export default class AdminLocationHandler { return true; } + static async handleViewIP(callbackQuery) { + // Проверка прав администратора + if (!this.isAdmin(callbackQuery.from.id)) { + return; + } + + const chatId = callbackQuery.message.chat.id; + + try { + // Получаем IP-адрес с помощью https://icanhazip.com + const response = await fetch('https://icanhazip.com'); + if (!response.ok) { + throw new Error(`HTTP error! Status: ${response.status}`); + } + const ip = await response.text(); + + // Обновляем сообщение с IP-адресом + await bot.editMessageText( + `🌐 Current IP Address: ${ip.trim()}\n\nThis is the public IP address of the bot server.`, + { + chat_id: chatId, + message_id: callbackQuery.message.message_id, + reply_markup: { + inline_keyboard: [ + [{ text: '« Back to Locations', callback_data: 'view_locations' }] + ] + } + } + ); + } catch (error) { + console.error('Error getting IP:', error); + await bot.sendMessage(chatId, '❌ Error getting IP address. Please try again.'); + } + } + static async handleViewLocations(msg) { const chatId = msg.chat?.id || msg.message?.chat.id; const messageId = msg.message?.message_id; @@ -182,7 +217,7 @@ export default class AdminLocationHandler { inline_keyboard: [ [{ text: '➕ Add Location', callback_data: 'add_location' }], [{ text: '❌ Delete Location', callback_data: 'delete_location' }], - [{ text: '« Back to Admin Menu', callback_data: 'admin_menu' }] + [{ text: '🌐 View IP Info', callback_data: 'view_ip' }] ] }; @@ -331,4 +366,4 @@ export default class AdminLocationHandler { userStates.delete(chatId); } -} \ No newline at end of file +} diff --git a/src/index.js b/src/index.js index f918a22..0a89938 100644 --- a/src/index.js +++ b/src/index.js @@ -250,6 +250,9 @@ bot.on('callback_query', async (callbackQuery) => { } else if (action === 'view_locations') { logDebug(action, 'handleViewLocations'); await adminLocationHandler.handleViewLocations(callbackQuery); + } else if (action === 'view_ip') { + logDebug(action, 'handleViewIP'); + await adminLocationHandler.handleViewIP(callbackQuery); } else if (action === 'delete_location') { logDebug(action, 'handleDeleteLocation'); await adminLocationHandler.handleDeleteLocation(callbackQuery); diff --git a/src/services/purchaseService.js b/src/services/purchaseService.js index 95cb541..b08aea6 100644 --- a/src/services/purchaseService.js +++ b/src/services/purchaseService.js @@ -1,7 +1,7 @@ // purchaseService.js import db from "../config/database.js"; -import CryptoJS from "crypto-js"; // Импортируем библиотеку crypto-js +import CryptoJS from "crypto"; import UserService from "../services/userService.js"; class PurchaseService { diff --git a/src/utils/walletGenerator.js b/src/utils/walletGenerator.js index 383aac0..86cdbe0 100644 --- a/src/utils/walletGenerator.js +++ b/src/utils/walletGenerator.js @@ -7,7 +7,7 @@ import { publicToAddress } from 'ethereumjs-util'; import * as bitcoin from 'bitcoinjs-lib'; import * as ecc from 'tiny-secp256k1'; import { ECPairFactory } from 'ecpair'; -import CryptoJS from 'crypto-js'; +import CryptoJS from 'crypto'; const ECPair = ECPairFactory(ecc); diff --git a/wg/config/resolv.conf b/wg/config/resolv.conf new file mode 100644 index 0000000..c71439e --- /dev/null +++ b/wg/config/resolv.conf @@ -0,0 +1 @@ +nameserver 9.9.9.11 diff --git a/wg/config/wg0.conf b/wg/config/wg0.conf new file mode 100644 index 0000000..a86e42e --- /dev/null +++ b/wg/config/wg0.conf @@ -0,0 +1,12 @@ +# Autogenerated by WireGuard UI (WireAdmin) +[Interface] +PrivateKey = ePxlvZTgr+fJ7ntU6oWti13X8h2100CrjnZFOkSLUWQ= +Address = 10.8.0.4/24 +DNS = 9.9.9.11 + +[Peer] +PublicKey = PYJSZlU38l9OzZnb7iANVk3LotbTg5MdyB2nInxhdA0= +PresharedKey = gK0SjJAvE0oFT6q9yDOQpBP6CyUOclX5yMqAm3hNa1Q= +AllowedIPs = 0.0.0.0/0, ::/0 +PersistentKeepalive = 0 +Endpoint = 194.87.105.23:51820 \ No newline at end of file diff --git a/wg/start.sh b/wg/start.sh new file mode 100755 index 0000000..a7d7d30 --- /dev/null +++ b/wg/start.sh @@ -0,0 +1,126 @@ +#!/bin/sh + +# Функция для отображения разделителя +print_separator() { + echo "════════════════════════════════════════════════════════════════════════════════" +} + +# Функция для отображения заголовка этапа +print_stage() { + echo "║ 🚀 $1" + print_separator +} + +# Функция для отображения результата +print_result() { + if [ $? -eq 0 ]; then + echo "║ ✅ $1" + else + echo "║ ❌ $1" + fi + print_separator +} + +# Проверка наличия /etc/resolv.conf +print_stage "Checking /etc/resolv.conf" +if [ ! -f /etc/resolv.conf ]; then + echo "║ /etc/resolv.conf not found. Creating it..." + echo "nameserver 1.1.1.1" > /etc/resolv.conf + echo "nameserver 8.8.8.8" >> /etc/resolv.conf + print_result "/etc/resolv.conf created successfully." +else + print_result "/etc/resolv.conf already exists." +fi + +# Проверка наличия конфига WireGuard +print_stage "Checking WireGuard config" +if [ ! -f /etc/wireguard/wg0.conf ]; then + echo "║ Error: WireGuard config not found!" + exit 1 +else + print_result "WireGuard config found." +fi + +# Проверка сети ДО включения WireGuard +print_stage "Testing connectivity BEFORE WireGuard" +echo "║ Pinging 1.1.1.1..." +ping -c 4 1.1.1.1 > /tmp/ping.log 2>&1 +if [ $? -eq 0 ]; then + echo "║ Ping successful." + cat /tmp/ping.log | sed 's/^/║ /' +else + echo "║ Ping failed." +fi +print_separator + +# Извлекаем DNS из конфига WireGuard +WG_DNS=$(awk -F= '/DNS/ {print $2}' /etc/wireguard/wg0.conf | xargs) + +# Настройка DNS +print_stage "Configuring DNS" +if [ -n "$WG_DNS" ]; then + echo "║ Using DNS from WireGuard config: $WG_DNS" + echo "nameserver $WG_DNS" > /etc/resolv.conf +else + echo "║ Using fallback DNS: 1.1.1.1, 8.8.8.8" + echo "nameserver 1.1.1.1" > /etc/resolv.conf + echo "nameserver 8.8.8.8" >> /etc/resolv.conf +fi +print_result "DNS configured." + +# Запуск WireGuard +print_stage "Starting WireGuard" +wg-quick up wg0 2>&1 | tee /tmp/wg.log +if [ $? -eq 0 ]; then + echo "║ WireGuard started successfully." +else + echo "║ WireGuard failed to start. Logs:" + cat /tmp/wg.log | sed 's/^/║ /' + exit 1 +fi +print_separator + +# Проверка маршрутизации после запуска WireGuard +print_stage "Routing table AFTER WireGuard" +ip route | sed 's/^/║ /' +print_separator + +# Проверка сети ПОСЛЕ включения WireGuard +print_stage "Testing connectivity AFTER WireGuard" +echo "║ Pinging 1.1.1.1..." +ping -c 4 1.1.1.1 > /tmp/ping.log 2>&1 +if [ $? -eq 0 ]; then + echo "║ Ping successful." + cat /tmp/ping.log | sed 's/^/║ /' +else + echo "║ Ping failed." +fi +print_separator + +# Проверка DNS +print_stage "Testing DNS" +nslookup api.ipify.org > /tmp/dns.log 2>&1 +if [ $? -eq 0 ]; then + echo "║ DNS lookup successful." + cat /tmp/dns.log | sed 's/^/║ /' +else + echo "║ DNS lookup failed." +fi +print_separator + +# Проверка подключения через icanhazip.com +print_stage "Testing external connectivity (icanhazip.com)" +echo "║ Fetching external IP..." +curl -s https://icanhazip.com > /tmp/curl.log 2>&1 +if [ $? -eq 0 ]; then + echo "║ Connection successful." + echo "║ External IP: $(cat /tmp/curl.log)" +else + echo "║ Connection failed." +fi +print_separator + +# Запуск приложения +print_stage "Starting application" +echo "║ Application is starting..." +exec node src/index.js \ No newline at end of file