v2.4.10: stats auto-install + i18n for show_proxy_info, traffic stats (SSH+bot)

This commit is contained in:
anten-ka
2026-04-12 07:54:40 +03:00
parent 0e38c2b5b6
commit 7075ff8696
9 changed files with 177 additions and 61 deletions

View File

@@ -100,7 +100,7 @@ logger = logging.getLogger(__name__)
# CONFIGURATION
# ============================================================================
GOTELEGRAM_VERSION = "2.4.9"
GOTELEGRAM_VERSION = "2.4.10"
GOTELEGRAM_CONFIG = "/opt/gotelegram/config.json"
TELEMT_CONFIG = "/etc/telemt/config.toml"
TELEMT_SERVICE = "telemt"
@@ -687,7 +687,7 @@ async def get_status_text(user_id: Optional[int] = None) -> str:
return "\n".join(lines)
async def get_traffic_stats() -> str:
async def get_traffic_stats(user_id: Optional[int] = None) -> str:
"""Get formatted traffic statistics."""
# Read current snapshot
current_file = "/run/gotelegram/stats_current.json"
@@ -697,7 +697,7 @@ async def get_traffic_stats() -> str:
with open(current_file, "r") as f:
current = json.load(f)
except Exception:
return "📊 <b>Статистика</b>\n\n<i>Данные недоступны. Убедитесь что модуль статистики включён.</i>"
return f"📊 <b>{_t(user_id, 'stats_title', 'Statistics')}</b>\n\n<i>{_t(user_id, 'stats_unavailable', 'Data unavailable. Make sure stats module is enabled.')}</i>"
# Read history
history = []
@@ -754,21 +754,27 @@ async def get_traffic_stats() -> str:
return format_bytes(diff), format_rate(rate)
periods = [
("1 мин", 60),
("5 мин", 300),
("60 мин", 3600),
("1 день", 86400),
("7 дней", 604800),
("30 дней", 2592000),
("365 дней", 31536000),
(_t(user_id, "stats_1min", "1 min"), 60),
(_t(user_id, "stats_5min", "5 min"), 300),
(_t(user_id, "stats_60min", "60 min"), 3600),
(_t(user_id, "stats_1day", "1 day"), 86400),
(_t(user_id, "stats_7days", "7 days"), 604800),
(_t(user_id, "stats_30days", "30 days"), 2592000),
(_t(user_id, "stats_365days", "365 days"), 31536000),
]
lines = ["📊 <b>Статистика трафика</b>\n"]
hdr_period = _t(user_id, "stats_hdr_period", "Period")
hdr_traffic = _t(user_id, "stats_hdr_traffic", "Traffic")
hdr_rate = _t(user_id, "stats_hdr_rate", "Rate")
for label, key in [("Proxy (telemt)", "proxy"), ("Сайт (nginx)", "site")]:
lines = [f"📊 <b>{_t(user_id, 'stats_traffic_title', 'Traffic statistics')}</b>\n"]
lbl_proxy = _t(user_id, "stats_proxy_label", "Proxy (telemt)")
lbl_site = _t(user_id, "stats_site_label", "Site (nginx)")
for label, key in [(lbl_proxy, "proxy"), (lbl_site, "site")]:
lines.append(f"\n<b>{label}:</b>")
lines.append("<pre>")
lines.append(f"{'Период':<10}{'Трафик':>10}{'Скорость':>10}")
lines.append(f"{hdr_period:<10}{hdr_traffic:>10}{hdr_rate:>10}")
lines.append("" * 36)
for name, secs in periods:
total, rate = calc_for_period(secs, key)
@@ -783,11 +789,12 @@ async def cb_menu_stats(update: Update, context: ContextTypes.DEFAULT_TYPE) -> N
query = update.callback_query
await query.answer()
stats_text = await get_traffic_stats()
uid = _uid(update)
stats_text = await get_traffic_stats(uid)
keyboard = [
[InlineKeyboardButton("🔄 Обновить", callback_data="menu_stats")],
[InlineKeyboardButton(_t(_uid(update), "btn_back"), callback_data="menu_main")],
[InlineKeyboardButton(_t(uid, "btn_refresh", "🔄 Refresh"), callback_data="menu_stats")],
[InlineKeyboardButton(_t(uid, "btn_back"), callback_data="menu_main")],
]
await safe_edit_message(

View File

@@ -112,5 +112,21 @@
"cg_timeout": "❌ Clone timeout (repository too large or slow)",
"cg_too_big": "❌ Repository too large (>100MB)",
"cg_no_index": "❌ No index.html found in repository",
"cg_ok_fmt": "✅ Custom template downloaded: %s"
"cg_ok_fmt": "✅ Custom template downloaded: %s",
"stats_title": "Statistics",
"stats_unavailable": "Data unavailable. Make sure stats module is enabled.",
"stats_traffic_title": "Traffic statistics",
"stats_proxy_label": "Proxy (telemt)",
"stats_site_label": "Site (nginx)",
"stats_hdr_period": "Period",
"stats_hdr_traffic": "Traffic",
"stats_hdr_rate": "Rate",
"stats_1min": "1 min",
"stats_5min": "5 min",
"stats_60min": "60 min",
"stats_1day": "1 day",
"stats_7days": "7 days",
"stats_30days": "30 days",
"stats_365days": "365 days"
}

View File

@@ -112,5 +112,21 @@
"cg_timeout": "❌ Таймаут клонирования (репозиторий слишком большой или медленный)",
"cg_too_big": "❌ Репозиторий слишком большой (>100МБ)",
"cg_no_index": "❌ В репозитории не найден index.html",
"cg_ok_fmt": "✅ Свой шаблон загружен: %s"
"cg_ok_fmt": "✅ Свой шаблон загружен: %s",
"stats_title": "Статистика",
"stats_unavailable": "Данные недоступны. Убедитесь что модуль статистики включён.",
"stats_traffic_title": "Статистика трафика",
"stats_proxy_label": "Proxy (telemt)",
"stats_site_label": "Сайт (nginx)",
"stats_hdr_period": "Период",
"stats_hdr_traffic": "Трафик",
"stats_hdr_rate": "Скорость",
"stats_1min": "1 мин",
"stats_5min": "5 мин",
"stats_60min": "60 мин",
"stats_1day": "1 день",
"stats_7days": "7 дней",
"stats_30days": "30 дней",
"stats_365days": "365 дней"
}

View File

@@ -397,6 +397,11 @@ install_lite_mode() {
# Save GoTelegram config
save_gotelegram_config "telemt" "lite" "$port" "$secret" "$domain" "" ""
# Auto-install stats collector so stats work from the start
if type install_stats_collector &>/dev/null; then
install_stats_collector 2>/dev/null
fi
# Credits
show_credits
@@ -512,6 +517,11 @@ install_pro_mode() {
tpl_id=$(basename "$template_dir")
save_gotelegram_config "telemt" "pro" "443" "$raw_secret" "$user_domain" "$user_domain" "$tpl_id"
# Auto-install stats collector so stats work from the start
if type install_stats_collector &>/dev/null; then
install_stats_collector 2>/dev/null
fi
# Result — use domain and fake-TLS link
show_proxy_info_pro "$user_domain" "$faketls_secret"
echo -e " ${WHITE}$(t svc_site):${NC} ${GREEN}https://${user_domain}${NC}"

View File

@@ -3,7 +3,7 @@
# Colors, logging, spinner, system helpers, v1 compat, i18n-aware
# ── Version ───────────────────────────────────────────────────────────────────
GOTELEGRAM_VERSION="2.4.9"
GOTELEGRAM_VERSION="2.4.10"
GOTELEGRAM_NAME="GoTelegram"
# ── Пути ──────────────────────────────────────────────────────────────────────

View File

@@ -44,6 +44,33 @@ I18N[net_mode]="Mode:"
I18N[net_domain]="Domain:"
I18N[connection_link]="Telegram connection link:"
I18N[proxy_not_configured]="Proxy is not configured. Select option 1."
# ── show_proxy_info labels ─────────────────────────────────────────────
I18N[info_status_running]="Running"
I18N[info_status_stopped]="Stopped"
I18N[info_status_not_installed]="Not installed"
I18N[info_proxy_status]="Proxy status"
I18N[info_engine]="Engine"
I18N[info_ip]="IP"
I18N[info_domain]="Domain"
I18N[info_port]="Port"
I18N[info_mode]="Mode"
I18N[info_mask]="Mask host"
I18N[info_secret]="Secret"
I18N[info_link]="Link"
# ── show_traffic_stats labels ──────────────────────────────────────────
I18N[stats_sh_proxy]="Proxy (telemt, port 443)"
I18N[stats_sh_site]="Site (nginx, port 8443)"
I18N[stats_sh_hdr_period]="Period"
I18N[stats_sh_hdr_inbound]="Inbound"
I18N[stats_sh_hdr_rate]="Rate"
I18N[stats_sh_packets]="Packets"
I18N[stats_sh_1min]="1 min"
I18N[stats_sh_5min]="5 min"
I18N[stats_sh_60min]="60 min"
I18N[stats_sh_1day]="1 day"
I18N[stats_sh_7days]="7 days"
I18N[stats_sh_30days]="30 days"
I18N[stats_sh_365days]="365 days"
I18N[menu_proxy]="Proxy ▸"
I18N[menu_stats]="Statistics ▸"
I18N[menu_manage]="Management ▸"

View File

@@ -44,6 +44,33 @@ I18N[net_mode]="Режим:"
I18N[net_domain]="Домен:"
I18N[connection_link]="Ссылка для Telegram:"
I18N[proxy_not_configured]="Прокси не настроен. Выберите пункт 1."
# ── show_proxy_info labels ─────────────────────────────────────────────
I18N[info_status_running]="Работает"
I18N[info_status_stopped]="Остановлен"
I18N[info_status_not_installed]="Не установлен"
I18N[info_proxy_status]="Статус прокси"
I18N[info_engine]="Ядро"
I18N[info_ip]="IP"
I18N[info_domain]="Домен"
I18N[info_port]="Порт"
I18N[info_mode]="Режим"
I18N[info_mask]="Маскировка"
I18N[info_secret]="Secret"
I18N[info_link]="Ссылка"
# ── show_traffic_stats labels ──────────────────────────────────────────
I18N[stats_sh_proxy]="Proxy (telemt, порт 443)"
I18N[stats_sh_site]="Сайт (nginx, порт 8443)"
I18N[stats_sh_hdr_period]="Период"
I18N[stats_sh_hdr_inbound]="Входящий"
I18N[stats_sh_hdr_rate]="Скорость"
I18N[stats_sh_packets]="Пакетов"
I18N[stats_sh_1min]="1 мин"
I18N[stats_sh_5min]="5 мин"
I18N[stats_sh_60min]="60 мин"
I18N[stats_sh_1day]="1 день"
I18N[stats_sh_7days]="7 дней"
I18N[stats_sh_30days]="30 дней"
I18N[stats_sh_365days]="365 дней"
I18N[menu_proxy]="Прокси ▸"
I18N[menu_stats]="Статистика ▸"
I18N[menu_manage]="Управление ▸"

View File

@@ -243,36 +243,49 @@ show_traffic_stats() {
local site_rates=$(stats_calculate_rates "site")
IFS='|' read -r s1m s1mr s5m s5mr s60m s60mr s1d s1dr s7d s7dr s30d s30dr s365d s365dr <<< "$site_rates"
# i18n labels (fall back to English if t() not loaded)
local lbl_proxy; lbl_proxy="$(_t_or stats_sh_proxy 'Proxy (telemt, port 443)')"
local lbl_site; lbl_site="$(_t_or stats_sh_site 'Site (nginx, port 8443)')"
local lbl_hdr; lbl_hdr="$(_t_or stats_sh_hdr_period 'Period')$(_t_or stats_sh_hdr_inbound 'Inbound')$(_t_or stats_sh_hdr_rate 'Rate')"
local lbl_pkts; lbl_pkts="$(_t_or stats_sh_packets 'Packets')"
local l1m; l1m="$(_t_or stats_sh_1min '1 min')"
local l5m; l5m="$(_t_or stats_sh_5min '5 min')"
local l60m; l60m="$(_t_or stats_sh_60min '60 min')"
local l1d; l1d="$(_t_or stats_sh_1day '1 day')"
local l7d; l7d="$(_t_or stats_sh_7days '7 days')"
local l30d; l30d="$(_t_or stats_sh_30days '30 days')"
local l365d; l365d="$(_t_or stats_sh_365days '365 days')"
# Display proxy stats
{
echo ""
echo -e "${BLUE} Proxy (telemt, порт 443):${NC}"
echo -e "${BLUE} ${lbl_proxy}:${NC}"
echo -e "${BLUE} ─────────────────────────────────────────${NC}"
echo -e "${BLUE} Период │ Входящий │ Скорость${NC}"
echo -e "${BLUE} ${lbl_hdr}${NC}"
echo -e "${BLUE} ─────────────────────────────────────────${NC}"
printf " %-9s │ %14s │ %s\n" "1 мин" "$p1m" "$p1mr"
printf " %-9s │ %14s │ %s\n" "5 мин" "$p5m" "$p5mr"
printf " %-9s │ %14s │ %s\n" "60 мин" "$p60m" "$p60mr"
printf " %-9s │ %14s │ %s\n" "1 день" "$p1d" "$p1dr"
printf " %-9s │ %14s │ %s\n" "7 дней" "$p7d" "$p7dr"
printf " %-9s │ %14s │ %s\n" "30 дней" "$p30d" "$p30dr"
printf " %-9s │ %14s │ %s\n" "365 дней" "$p365d" "$p365dr"
printf " %-9s │ %14s │ %s\n" "$l1m" "$p1m" "$p1mr"
printf " %-9s │ %14s │ %s\n" "$l5m" "$p5m" "$p5mr"
printf " %-9s │ %14s │ %s\n" "$l60m" "$p60m" "$p60mr"
printf " %-9s │ %14s │ %s\n" "$l1d" "$p1d" "$p1dr"
printf " %-9s │ %14s │ %s\n" "$l7d" "$p7d" "$p7dr"
printf " %-9s │ %14s │ %s\n" "$l30d" "$p30d" "$p30dr"
printf " %-9s │ %14s │ %s\n" "$l365d" "$p365d" "$p365dr"
echo -e "${BLUE} ─────────────────────────────────────────${NC}"
printf " Пакетов: %d\n\n" "$proxy_pkts"
printf " %s: %d\n\n" "$lbl_pkts" "$proxy_pkts"
echo -e "${BLUE} Сайт (nginx, порт 8443):${NC}"
echo -e "${BLUE} ${lbl_site}:${NC}"
echo -e "${BLUE} ─────────────────────────────────────────${NC}"
echo -e "${BLUE} Период │ Входящий │ Скорость${NC}"
echo -e "${BLUE} ${lbl_hdr}${NC}"
echo -e "${BLUE} ─────────────────────────────────────────${NC}"
printf " %-9s │ %14s │ %s\n" "1 мин" "$s1m" "$s1mr"
printf " %-9s │ %14s │ %s\n" "5 мин" "$s5m" "$s5mr"
printf " %-9s │ %14s │ %s\n" "60 мин" "$s60m" "$s60mr"
printf " %-9s │ %14s │ %s\n" "1 день" "$s1d" "$s1dr"
printf " %-9s │ %14s │ %s\n" "7 дней" "$s7d" "$s7dr"
printf " %-9s │ %14s │ %s\n" "30 дней" "$s30d" "$s30dr"
printf " %-9s │ %14s │ %s\n" "365 дней" "$s365d" "$s365dr"
printf " %-9s │ %14s │ %s\n" "$l1m" "$s1m" "$s1mr"
printf " %-9s │ %14s │ %s\n" "$l5m" "$s5m" "$s5mr"
printf " %-9s │ %14s │ %s\n" "$l60m" "$s60m" "$s60mr"
printf " %-9s │ %14s │ %s\n" "$l1d" "$s1d" "$s1dr"
printf " %-9s │ %14s │ %s\n" "$l7d" "$s7d" "$s7dr"
printf " %-9s │ %14s │ %s\n" "$l30d" "$s30d" "$s30dr"
printf " %-9s │ %14s │ %s\n" "$l365d" "$s365d" "$s365dr"
echo -e "${BLUE} ─────────────────────────────────────────${NC}"
printf " Пакетов: %d\n" "$site_pkts"
printf " %s: %d\n" "$lbl_pkts" "$site_pkts"
echo ""
} >&2
}

44
lib/telemt_config.sh Executable file → Normal file
View File

@@ -285,26 +285,26 @@ show_proxy_info() {
local status_icon status_text
case "$status" in
running) status_icon="✅"; status_text="Работает" ;;
stopped) status_icon="⏸️"; status_text="Остановлен" ;;
*) status_icon="❌"; status_text="Не установлен" ;;
running) status_icon="✅"; status_text="$(t info_status_running)" ;;
stopped) status_icon="⏸️"; status_text="$(t info_status_stopped)" ;;
*) status_icon="❌"; status_text="$(t info_status_not_installed)" ;;
esac
echo ""
echo -e " ${BOLD}${WHITE}${status_icon} Статус прокси: ${status_text}${NC}"
echo -e " ${BOLD}${WHITE}${status_icon} $(t info_proxy_status): ${status_text}${NC}"
echo -e " ${DIM}$(printf '─%.0s' {1..50})${NC}"
echo -e " ${WHITE}Ядро:${NC} telemt (Rust)"
echo -e " ${WHITE}$(t info_engine):${NC} telemt (Rust)"
if [ "$mode" = "pro" ] && [ -n "$domain" ]; then
echo -e " ${WHITE}Домен:${NC} ${CYAN}${domain}${NC}"
echo -e " ${WHITE}$(t info_domain):${NC} ${CYAN}${domain}${NC}"
else
echo -e " ${WHITE}IP:${NC} ${CYAN}${ip}${NC}"
echo -e " ${WHITE}$(t info_ip):${NC} ${CYAN}${ip}${NC}"
fi
echo -e " ${WHITE}Порт:${NC} ${CYAN}${port}${NC}"
echo -e " ${WHITE}Режим:${NC} ${CYAN}${mode}${NC}"
echo -e " ${WHITE}Маскировка:${NC} ${CYAN}${mask_host}${NC}"
echo -e " ${WHITE}Secret:${NC} ${CYAN}${secret:0:16}...${NC}"
echo -e " ${WHITE}$(t info_port):${NC} ${CYAN}${port}${NC}"
echo -e " ${WHITE}$(t info_mode):${NC} ${CYAN}${mode}${NC}"
echo -e " ${WHITE}$(t info_mask):${NC} ${CYAN}${mask_host}${NC}"
echo -e " ${WHITE}$(t info_secret):${NC} ${CYAN}${secret:0:16}...${NC}"
echo -e " ${DIM}$(printf '─%.0s' {1..50})${NC}"
echo -e " ${WHITE}Ссылка:${NC}"
echo -e " ${WHITE}$(t info_link):${NC}"
echo -e " ${GREEN}${link}${NC}"
echo ""
@@ -323,20 +323,20 @@ show_proxy_info_pro() {
local link="tg://proxy?server=${domain}&port=443&secret=${faketls_secret}"
echo ""
echo -e " ${BOLD}${WHITE}Pro-прокси настроен${NC}"
echo -e " ${BOLD}${WHITE}$(t info_proxy_status): $(t info_status_running) (Pro)${NC}"
echo -e " ${DIM}$(printf '─%.0s' {1..55})${NC}"
echo -e " ${WHITE}Ядро:${NC} telemt (Rust)"
echo -e " ${WHITE}Домен:${NC} ${CYAN}${domain}${NC}"
echo -e " ${WHITE}Порт:${NC} ${CYAN}443${NC} (внешний, telemt)"
echo -e " ${WHITE}Режим:${NC} ${MAGENTA}Pro (fake-TLS)${NC}"
echo -e " ${WHITE}nginx:${NC} ${CYAN}127.0.0.1:8443${NC} (внутренний)"
echo -e " ${WHITE}Secret:${NC} ${CYAN}${faketls_secret:0:20}...${NC}"
echo -e " ${WHITE}$(t info_engine):${NC} telemt (Rust)"
echo -e " ${WHITE}$(t info_domain):${NC} ${CYAN}${domain}${NC}"
echo -e " ${WHITE}$(t info_port):${NC} ${CYAN}443${NC} (telemt)"
echo -e " ${WHITE}$(t info_mode):${NC} ${MAGENTA}Pro (fake-TLS)${NC}"
echo -e " ${WHITE}nginx:${NC} ${CYAN}127.0.0.1:8443${NC}"
echo -e " ${WHITE}$(t info_secret):${NC} ${CYAN}${faketls_secret:0:20}...${NC}"
echo -e " ${DIM}$(printf '─%.0s' {1..55})${NC}"
echo -e " ${WHITE}Ссылка для Telegram:${NC}"
echo -e " ${WHITE}$(t info_link):${NC}"
echo -e " ${GREEN}${link}${NC}"
echo ""
echo -e " ${DIM}Провайдер видит: HTTPS-трафик к ${domain}:443${NC}"
echo -e " ${DIM}Telegram-клиент маскирует соединение под TLS${NC}"
echo -e " ${DIM}ISP sees: HTTPS → ${domain}:443${NC}"
echo -e " ${DIM}Telegram client masquerades as TLS${NC}"
echo ""
# QR если доступен