mirror of
https://github.com/anten-ka/gotelegram_pro.git
synced 2026-05-19 12:16:01 +00:00
v2.5.0: add legacy state migration
This commit is contained in:
@@ -51,7 +51,7 @@ create_backup() {
|
||||
# Шаблон сайта (если есть)
|
||||
if [ -d "$WEBSITE_ROOT" ] && [ -f "$WEBSITE_ROOT/index.html" ]; then
|
||||
mkdir -p "$tmp_dir/site"
|
||||
cp -r "$WEBSITE_ROOT"/* "$tmp_dir/site/"
|
||||
cp -a "$WEBSITE_ROOT/." "$tmp_dir/site/"
|
||||
log_dim "$(_t_or backup_site_included 'Шаблон сайта включён')"
|
||||
fi
|
||||
|
||||
@@ -277,7 +277,7 @@ restore_backup() {
|
||||
# Восстанавливаем шаблон сайта
|
||||
if [ -d "$backup_dir/site" ]; then
|
||||
mkdir -p "$WEBSITE_ROOT"
|
||||
cp -r "$backup_dir/site"/* "$WEBSITE_ROOT/"
|
||||
cp -a "$backup_dir/site/." "$WEBSITE_ROOT/"
|
||||
chown -R www-data:www-data "$WEBSITE_ROOT" 2>/dev/null
|
||||
log_success "$(_t_or backup_restored_site 'Шаблон сайта восстановлен')"
|
||||
fi
|
||||
|
||||
@@ -184,6 +184,72 @@ get_config_value() {
|
||||
esac
|
||||
}
|
||||
|
||||
get_telemt_users_block() {
|
||||
local config="${1:-$TELEMT_CONFIG}"
|
||||
[ -f "$config" ] || return 1
|
||||
awk '
|
||||
/^\[access\.users\]/ { in_users=1; next }
|
||||
/^\[/ && in_users { exit }
|
||||
in_users && /^[[:space:]]*[^#[:space:]][^=]*=/ { print }
|
||||
' "$config"
|
||||
}
|
||||
|
||||
first_telemt_user_secret() {
|
||||
local config="${1:-$TELEMT_CONFIG}"
|
||||
get_telemt_users_block "$config" | head -1 | sed 's/^[^=]*=[[:space:]]*//; s/^"//; s/".*$//' | tr -d ' '
|
||||
}
|
||||
|
||||
replace_telemt_users_block() {
|
||||
local users_block="$1"
|
||||
local config="${2:-$TELEMT_CONFIG}"
|
||||
[ -f "$config" ] || return 1
|
||||
[ -n "$users_block" ] || return 0
|
||||
|
||||
local tmp
|
||||
tmp=$(mktemp) || return 1
|
||||
awk -v users="$users_block" '
|
||||
BEGIN { split(users, lines, "\n") }
|
||||
/^\[access\.users\]/ {
|
||||
found=1
|
||||
print
|
||||
for (i = 1; i in lines; i++) {
|
||||
if (lines[i] != "") print lines[i]
|
||||
}
|
||||
in_users=1
|
||||
next
|
||||
}
|
||||
/^\[/ && in_users { in_users=0 }
|
||||
in_users { next }
|
||||
{ print }
|
||||
END {
|
||||
if (!found) {
|
||||
print ""
|
||||
print "[access.users]"
|
||||
for (i = 1; i in lines; i++) {
|
||||
if (lines[i] != "") print lines[i]
|
||||
}
|
||||
}
|
||||
}
|
||||
' "$config" > "$tmp" && mv "$tmp" "$config"
|
||||
chmod 600 "$config"
|
||||
}
|
||||
|
||||
toml_bool_value() {
|
||||
local table="$1"
|
||||
local key="$2"
|
||||
local config="${3:-$TELEMT_CONFIG}"
|
||||
awk -v table="$table" -v key="$key" '
|
||||
$0 == "[" table "]" { in_table=1; next }
|
||||
/^\[/ && in_table { exit }
|
||||
in_table && $1 == key {
|
||||
sub(/^[^=]*=[[:space:]]*/, "")
|
||||
gsub(/[[:space:]]/, "")
|
||||
print
|
||||
exit
|
||||
}
|
||||
' "$config"
|
||||
}
|
||||
|
||||
# ── Валидация конфига ────────────────────────────────────────────────────────
|
||||
validate_telemt_config() {
|
||||
local config="${1:-$TELEMT_CONFIG}"
|
||||
|
||||
@@ -237,11 +237,15 @@ get_ssl_expiry() {
|
||||
# ── Деплой шаблона сайта ─────────────────────────────────────────────────────
|
||||
deploy_template_to_nginx() {
|
||||
local template_dir="$1"
|
||||
local template_id="${2:-}"
|
||||
local source_url=""
|
||||
|
||||
if [ ! -d "$template_dir" ] || [ ! -f "$template_dir/index.html" ]; then
|
||||
log_error "Шаблон не содержит index.html: $template_dir"
|
||||
return 1
|
||||
fi
|
||||
[ -z "$template_id" ] && template_id=$(basename "$template_dir")
|
||||
[ -f "$template_dir/.custom_git_source" ] && source_url=$(head -1 "$template_dir/.custom_git_source" 2>/dev/null || echo "")
|
||||
|
||||
# Бекапим старый сайт
|
||||
if [ -d "$WEBSITE_ROOT" ] && [ "$(ls -A "$WEBSITE_ROOT" 2>/dev/null)" ]; then
|
||||
@@ -251,7 +255,10 @@ deploy_template_to_nginx() {
|
||||
fi
|
||||
|
||||
mkdir -p "$WEBSITE_ROOT"
|
||||
cp -r "$template_dir"/* "$WEBSITE_ROOT/"
|
||||
cp -a "$template_dir/." "$WEBSITE_ROOT/"
|
||||
rm -f "$WEBSITE_ROOT/.custom_git_source" 2>/dev/null || true
|
||||
echo "$template_id" > "$WEBSITE_ROOT/.gotelegram_template_id" 2>/dev/null || true
|
||||
[ -n "$source_url" ] && echo "$source_url" > "$WEBSITE_ROOT/.gotelegram_template_source" 2>/dev/null || true
|
||||
chown -R www-data:www-data "$WEBSITE_ROOT" 2>/dev/null || chown -R nginx:nginx "$WEBSITE_ROOT" 2>/dev/null
|
||||
chmod -R 755 "$WEBSITE_ROOT"
|
||||
|
||||
@@ -334,7 +341,7 @@ remove_pro_mode() {
|
||||
# ── Смена шаблона ────────────────────────────────────────────────────────────
|
||||
switch_template() {
|
||||
local new_template_dir="$1"
|
||||
deploy_template_to_nginx "$new_template_dir"
|
||||
deploy_template_to_nginx "$new_template_dir" "$(basename "$new_template_dir")"
|
||||
# nginx не требует перезапуска — статика обновилась на месте
|
||||
log_success "Шаблон сайта обновлён"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user