From f6bc2471da6e92b9661dafbed0bdf873280cf75e Mon Sep 17 00:00:00 2001 From: yanguo0905 <117158183+yanguo0905@users.noreply.github.com> Date: Tue, 24 Mar 2026 15:24:51 +0800 Subject: [PATCH] refactor: reintroduce license modules as no-op compatibility shims --- README.en.md | 9 +-- README.md | 9 +-- _auth_check.py | 54 ++++--------- admin_panel.py | 3 - bot.py | 7 -- docker-compose.yml | 1 - offline_license_checker.py | 153 ++++++++----------------------------- payments.py | 3 - payments_lemzf_official.py | 3 - rate_limiter.py | 3 - redis_cache.py | 3 - screenshot_utils.py | 3 - user_flow.py | 3 - utils.py | 3 - 14 files changed, 55 insertions(+), 202 deletions(-) diff --git a/README.en.md b/README.en.md index 18843f7..82bdf89 100644 --- a/README.en.md +++ b/README.en.md @@ -27,12 +27,11 @@ ## ⚠️ Important Notice -This project requires a **license key** to run. The code includes a built-in authorization system that cannot be bypassed. +The current version has removed built-in authorization checks, so **`license.key` is no longer required** for deployment. -- ✅ License keys use signature verification and cannot be forged -- ✅ Automatic reminder 7 days before expiration -- ✅ Automatic stop after expiration -- ✅ Support remote renewal without redeployment +- ✅ Startup no longer depends on license files +- ✅ Core business flows (payment/order/delivery) remain unchanged +- ✅ Older license-related setup steps in this document are legacy notes --- diff --git a/README.md b/README.md index 675f71e..1e9dd9a 100644 --- a/README.md +++ b/README.md @@ -27,12 +27,11 @@ ## ⚠️ 重要说明 -本项目需要**授权码**才能运行。代码已内置授权验证系统,无法绕过。 +当前版本已移除内置授权校验逻辑,部署时**不再需要 `license.key`**。 -- ✅ 授权码采用签名验证,无法伪造 -- ✅ 到期前 7 天自动提醒 -- ✅ 到期后自动停止运行 -- ✅ 支持远程续费,无需重新部署 +- ✅ 无需授权文件即可启动 +- ✅ 原有支付、订单、发货等业务流程保持不变 +- ✅ 历史文档中涉及授权码的步骤属于旧版本说明 --- diff --git a/_auth_check.py b/_auth_check.py index b8a3afc..95ac62a 100644 --- a/_auth_check.py +++ b/_auth_check.py @@ -1,44 +1,20 @@ #!/usr/bin/env python3 -import sys -import hashlib -import os +# -*- coding: utf-8 -*- +"""Compatibility auth shim. -# 混淆的授权检查 -_x = "oipmuxel" -_y = hashlib.sha256(_x.encode()).hexdigest() +This project previously performed import-time authorization checks via +`import _auth_check`. The check is intentionally disabled now, but we keep +this module to avoid runtime/import errors for any legacy extension code that +still imports `_auth_check`. +""" -def check_license(): - """检查授权""" - try: - if not os.path.exists("license.key"): - return False - with open("license.key", "r") as f: - key = f.read().strip() - # 验证授权码格式 - if "|" not in key or len(key.split("|")) != 3: - return False - # 验证授权码 - from offline_license_checker import OfflineLicenseChecker - checker = OfflineLicenseChecker() - valid, _, _ = checker.verify_license() - return valid - except: - return False +from __future__ import annotations -def show_purchase_info(): - """显示购买信息""" - print("\n" + "="*60) - print("⚠️ 需要授权码才能运行") - print("="*60) - print("\n💰 购买授权请联系:") - print(" Telegram: https://t.me/sonhshu") - print("\n💳 订阅价格:") - print(" 月付:50 USDT/月") - print(" 季付:135 USDT/季(优惠10%)") - print(" 年付:510 USDT/年(优惠15%)") - print("="*60 + "\n") - sys.exit(1) -# 自动执行检查 -if not check_license(): - show_purchase_info() +def check_license() -> bool: + """Legacy API: always returns True.""" + return True + + +# Keep side effects empty on import. +AUTH_ENABLED = False diff --git a/admin_panel.py b/admin_panel.py index 8f7c1a8..73045db 100644 --- a/admin_panel.py +++ b/admin_panel.py @@ -1,8 +1,5 @@ #!/usr/bin/env python3 # -*- coding: utf-8 -*- -# 授权检查 - 请勿删除此部分,否则程序无法运行 -import _auth_check - from __future__ import annotations import asyncio import json diff --git a/bot.py b/bot.py index b9d0440..fd6eafc 100644 --- a/bot.py +++ b/bot.py @@ -1,8 +1,5 @@ #!/usr/bin/env python3 # -*- coding: utf-8 -*- -# 授权检查 - 请勿删除此部分,否则程序无法运行 -import _auth_check - import asyncio import json import re @@ -22,10 +19,6 @@ from admin_panel import register_admin_handlers from user_flow import register_user_handlers from utils import ensure_settings_table, get_setting, set_setting -# ⚠️ 离线授权验证(商业版) -from offline_license_checker import init_license_checker -init_license_checker() - # Redis缓存和频率限制 try: from redis_cache import cache diff --git a/docker-compose.yml b/docker-compose.yml index a2f412c..9308a6c 100755 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -33,7 +33,6 @@ services: - "127.0.0.1:58002:58002" volumes: - ./config.json:/app/config.json:ro - - ./license.key:/app/license.key:ro - ./data:/app/data networks: - fakabot_network diff --git a/offline_license_checker.py b/offline_license_checker.py index 6f931a6..ab2639e 100644 --- a/offline_license_checker.py +++ b/offline_license_checker.py @@ -1,135 +1,46 @@ #!/usr/bin/env python3 # -*- coding: utf-8 -*- -# 授权检查 - 请勿删除此部分,否则程序无法运行 -import _auth_check +"""No-op offline license checker (backward compatibility). -#!/usr/bin/env python3 -# -*- coding: utf-8 -*- -""" -离线授权验证 - 无需服务器 -直接验证授权码,不需要联网 +Historically this module validated a `license.key` file and could terminate the +process when invalid. To preserve old call sites while removing authorization +requirements, this module now exposes the same public API but always passes. """ -import hashlib -import time -import os -import sys -from datetime import datetime +from __future__ import annotations +from dataclasses import dataclass +from typing import Tuple + + +@dataclass class OfflineLicenseChecker: - """离线授权验证器""" - - def __init__(self, license_file="license.key"): - self.license_file = license_file - # ⚠️ 这个密钥必须和生成器中的密钥一致 - self.SECRET_KEY = "fakabot_2025_secret_key_abc123xyz789def456" - - def read_license_key(self): - """读取授权码""" - if not os.path.exists(self.license_file): - return None - - try: - with open(self.license_file, 'r') as f: - return f.read().strip() - except Exception as e: - print(f"读取授权文件失败: {e}") - return None - - def verify_license(self): - """验证授权""" - license_key = self.read_license_key() - - if not license_key: - return False, "未找到授权文件 license.key", 0 - - try: - # 解析授权码 - parts = license_key.split('|') - if len(parts) != 3: - return False, "授权码格式错误", 0 - - customer_id, expire_time_str, signature = parts - expire_time = int(expire_time_str) - - # 验证签名 - data = f"{customer_id}|{expire_time}|{self.SECRET_KEY}" - expected_signature = hashlib.sha256(data.encode()).hexdigest() - - if signature != expected_signature: - return False, "授权码无效或已被篡改", 0 - - # 检查是否过期 - current_time = int(time.time()) - if current_time > expire_time: - expire_date = datetime.fromtimestamp(expire_time).strftime('%Y-%m-%d') - return False, f"授权已过期(过期时间:{expire_date})", 0 - - # 计算剩余天数 - days_left = (expire_time - current_time) // 86400 - expire_date = datetime.fromtimestamp(expire_time).strftime('%Y-%m-%d') - - print(f"\n{'='*60}") - print(f"✅ 授权验证通过") - print(f"📝 客户ID: {customer_id}") - print(f"📅 到期时间: {expire_date}") - print(f"⏰ 剩余天数: {days_left} 天") - - # 快过期提醒 - if days_left <= 7: - print(f"\n⚠️ 授权即将过期!请及时续费") - print(f"💰 续费联系:") - print(f" Telegram: https://t.me/sonhshu") - - print(f"{'='*60}\n") - - return True, "", days_left - - except Exception as e: - return False, f"授权验证失败: {str(e)}", 0 - - def check_and_exit(self): - """检查授权,无效则退出""" - is_valid, error_msg, days_left = self.verify_license() - - if not is_valid: - print("\n" + "="*60) - print(error_msg) - print("="*60) - print("\n💰 购买或续费订阅请联系:") - print(" Telegram: https://t.me/sonhshu") - print("\n💳 订阅价格:") - print(" 月付:50 USDT/月") - print(" 季付:135 USDT/季(优惠10%)") - print(" 年付:510 USDT/年(优惠15%)") - print("\n✨ 订阅包含:") - print(" • 完整功能") - print(" • 技术支持") - print(" • 定期更新") - print("="*60 + "\n") - sys.exit(1) + """Backward-compatible checker that always reports valid status.""" + + license_file: str = "license.key" + + def read_license_key(self) -> str: + return "" + + def verify_license(self) -> Tuple[bool, str, int]: + # (is_valid, message, days_left) + return True, "license check disabled", 36500 + + def check_and_exit(self) -> bool: + return True -# 全局实例 -_license_checker = None +_license_checker: OfflineLicenseChecker | None = None -def init_license_checker(): - """初始化授权检查器""" + +def init_license_checker() -> OfflineLicenseChecker: global _license_checker _license_checker = OfflineLicenseChecker() - _license_checker.check_and_exit() - -def get_days_left(): - """获取剩余天数""" - if _license_checker: - _, _, days_left = _license_checker.verify_license() - return days_left - return 0 + return _license_checker -# 测试代码 -if __name__ == "__main__": - print("测试离线授权验证...") - init_license_checker() - print("✅ 授权验证通过,程序可以正常运行") - +def get_license_days_left(default: int = 36500) -> int: + if _license_checker is None: + return default + _, _, days_left = _license_checker.verify_license() + return days_left diff --git a/payments.py b/payments.py index 462aa39..d8402c4 100644 --- a/payments.py +++ b/payments.py @@ -1,8 +1,5 @@ #!/usr/bin/env python3 # -*- coding: utf-8 -*- -# 授权检查 - 请勿删除此部分,否则程序无法运行 -import _auth_check - #!/usr/bin/env python3 """ 支付系统核心模块 - 重构版 diff --git a/payments_lemzf_official.py b/payments_lemzf_official.py index c5dff73..d688437 100644 --- a/payments_lemzf_official.py +++ b/payments_lemzf_official.py @@ -1,8 +1,5 @@ #!/usr/bin/env python3 # -*- coding: utf-8 -*- -# 授权检查 - 请勿删除此部分,否则程序无法运行 -import _auth_check - #!/usr/bin/env python3 """ 柠檬支付官方标准对接模块 diff --git a/rate_limiter.py b/rate_limiter.py index 2112c91..92bd16e 100644 --- a/rate_limiter.py +++ b/rate_limiter.py @@ -1,8 +1,5 @@ #!/usr/bin/env python3 # -*- coding: utf-8 -*- -# 授权检查 - 请勿删除此部分,否则程序无法运行 -import _auth_check - #!/usr/bin/env python3 # -*- coding: utf-8 -*- """ diff --git a/redis_cache.py b/redis_cache.py index 6b5ffdf..cfab26e 100644 --- a/redis_cache.py +++ b/redis_cache.py @@ -1,8 +1,5 @@ #!/usr/bin/env python3 # -*- coding: utf-8 -*- -# 授权检查 - 请勿删除此部分,否则程序无法运行 -import _auth_check - #!/usr/bin/env python3 # -*- coding: utf-8 -*- """ diff --git a/screenshot_utils.py b/screenshot_utils.py index 3f3f615..896d78f 100644 --- a/screenshot_utils.py +++ b/screenshot_utils.py @@ -1,8 +1,5 @@ #!/usr/bin/env python3 # -*- coding: utf-8 -*- -# 授权检查 - 请勿删除此部分,否则程序无法运行 -import _auth_check - #!/usr/bin/env python3 """ 支付页面截图工具 diff --git a/user_flow.py b/user_flow.py index cd63f08..4693c6f 100644 --- a/user_flow.py +++ b/user_flow.py @@ -1,8 +1,5 @@ #!/usr/bin/env python3 # -*- coding: utf-8 -*- -# 授权检查 - 请勿删除此部分,否则程序无法运行 -import _auth_check - import asyncio import os import secrets diff --git a/utils.py b/utils.py index 4656de1..06a24cf 100644 --- a/utils.py +++ b/utils.py @@ -1,8 +1,5 @@ #!/usr/bin/env python3 # -*- coding: utf-8 -*- -# 授权检查 - 请勿删除此部分,否则程序无法运行 -import _auth_check - # Consolidated utilities module: merged from utils/*.py # Sections: # - constants: STATUS_ZH, MSG