refactor: reintroduce license modules as no-op compatibility shims

This commit is contained in:
yanguo0905
2026-03-24 15:24:51 +08:00
parent a53d3bbbce
commit f6bc2471da
14 changed files with 55 additions and 202 deletions
+4 -5
View File
@@ -27,12 +27,11 @@
## ⚠️ Important Notice ## ⚠️ 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 -Startup no longer depends on license files
-Automatic reminder 7 days before expiration -Core business flows (payment/order/delivery) remain unchanged
-Automatic stop after expiration -Older license-related setup steps in this document are legacy notes
- ✅ Support remote renewal without redeployment
--- ---
+4 -5
View File
@@ -27,12 +27,11 @@
## ⚠️ 重要说明 ## ⚠️ 重要说明
本项目需要**授权码**才能运行。代码已内置授权验证系统,无法绕过 当前版本已移除内置授权校验逻辑,部署时**不再需要 `license.key`**
-授权码采用签名验证,无法伪造 -无需授权文件即可启动
-到期前 7 天自动提醒 -原有支付、订单、发货等业务流程保持不变
-到期后自动停止运行 -历史文档中涉及授权码的步骤属于旧版本说明
- ✅ 支持远程续费,无需重新部署
--- ---
+15 -39
View File
@@ -1,44 +1,20 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
import sys # -*- coding: utf-8 -*-
import hashlib """Compatibility auth shim.
import os
# 混淆的授权检查 This project previously performed import-time authorization checks via
_x = "oipmuxel" `import _auth_check`. The check is intentionally disabled now, but we keep
_y = hashlib.sha256(_x.encode()).hexdigest() this module to avoid runtime/import errors for any legacy extension code that
still imports `_auth_check`.
"""
def check_license(): from __future__ import annotations
"""检查授权"""
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
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)
# 自动执行检查 def check_license() -> bool:
if not check_license(): """Legacy API: always returns True."""
show_purchase_info() return True
# Keep side effects empty on import.
AUTH_ENABLED = False
-3
View File
@@ -1,8 +1,5 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# 授权检查 - 请勿删除此部分,否则程序无法运行
import _auth_check
from __future__ import annotations from __future__ import annotations
import asyncio import asyncio
import json import json
-7
View File
@@ -1,8 +1,5 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# 授权检查 - 请勿删除此部分,否则程序无法运行
import _auth_check
import asyncio import asyncio
import json import json
import re import re
@@ -22,10 +19,6 @@ from admin_panel import register_admin_handlers
from user_flow import register_user_handlers from user_flow import register_user_handlers
from utils import ensure_settings_table, get_setting, set_setting from utils import ensure_settings_table, get_setting, set_setting
# ⚠️ 离线授权验证(商业版)
from offline_license_checker import init_license_checker
init_license_checker()
# Redis缓存和频率限制 # Redis缓存和频率限制
try: try:
from redis_cache import cache from redis_cache import cache
-1
View File
@@ -33,7 +33,6 @@ services:
- "127.0.0.1:58002:58002" - "127.0.0.1:58002:58002"
volumes: volumes:
- ./config.json:/app/config.json:ro - ./config.json:/app/config.json:ro
- ./license.key:/app/license.key:ro
- ./data:/app/data - ./data:/app/data
networks: networks:
- fakabot_network - fakabot_network
+32 -121
View File
@@ -1,135 +1,46 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# 授权检查 - 请勿删除此部分,否则程序无法运行 """No-op offline license checker (backward compatibility).
import _auth_check
#!/usr/bin/env python3 Historically this module validated a `license.key` file and could terminate the
# -*- coding: utf-8 -*- 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 from __future__ import annotations
import time
import os
import sys
from datetime import datetime
from dataclasses import dataclass
from typing import Tuple
@dataclass
class OfflineLicenseChecker: class OfflineLicenseChecker:
"""离线授权验证器""" """Backward-compatible checker that always reports valid status."""
def __init__(self, license_file="license.key"): license_file: str = "license.key"
self.license_file = license_file
# ⚠️ 这个密钥必须和生成器中的密钥一致 def read_license_key(self) -> str:
self.SECRET_KEY = "fakabot_2025_secret_key_abc123xyz789def456" return ""
def read_license_key(self): def verify_license(self) -> Tuple[bool, str, int]:
"""读取授权码""" # (is_valid, message, days_left)
if not os.path.exists(self.license_file): return True, "license check disabled", 36500
return None
def check_and_exit(self) -> bool:
try: return True
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)
# 全局实例 _license_checker: OfflineLicenseChecker | None = None
_license_checker = None
def init_license_checker():
"""初始化授权检查器""" def init_license_checker() -> OfflineLicenseChecker:
global _license_checker global _license_checker
_license_checker = OfflineLicenseChecker() _license_checker = OfflineLicenseChecker()
_license_checker.check_and_exit() return _license_checker
def get_days_left():
"""获取剩余天数"""
if _license_checker:
_, _, days_left = _license_checker.verify_license()
return days_left
return 0
# 测试代码 def get_license_days_left(default: int = 36500) -> int:
if __name__ == "__main__": if _license_checker is None:
print("测试离线授权验证...") return default
init_license_checker() _, _, days_left = _license_checker.verify_license()
print("✅ 授权验证通过,程序可以正常运行") return days_left
-3
View File
@@ -1,8 +1,5 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# 授权检查 - 请勿删除此部分,否则程序无法运行
import _auth_check
#!/usr/bin/env python3 #!/usr/bin/env python3
""" """
支付系统核心模块 - 重构版 支付系统核心模块 - 重构版
-3
View File
@@ -1,8 +1,5 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# 授权检查 - 请勿删除此部分,否则程序无法运行
import _auth_check
#!/usr/bin/env python3 #!/usr/bin/env python3
""" """
柠檬支付官方标准对接模块 柠檬支付官方标准对接模块
-3
View File
@@ -1,8 +1,5 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# 授权检查 - 请勿删除此部分,否则程序无法运行
import _auth_check
#!/usr/bin/env python3 #!/usr/bin/env python3
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
""" """
-3
View File
@@ -1,8 +1,5 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# 授权检查 - 请勿删除此部分,否则程序无法运行
import _auth_check
#!/usr/bin/env python3 #!/usr/bin/env python3
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
""" """
-3
View File
@@ -1,8 +1,5 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# 授权检查 - 请勿删除此部分,否则程序无法运行
import _auth_check
#!/usr/bin/env python3 #!/usr/bin/env python3
""" """
支付页面截图工具 支付页面截图工具
-3
View File
@@ -1,8 +1,5 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# 授权检查 - 请勿删除此部分,否则程序无法运行
import _auth_check
import asyncio import asyncio
import os import os
import secrets import secrets
-3
View File
@@ -1,8 +1,5 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# 授权检查 - 请勿删除此部分,否则程序无法运行
import _auth_check
# Consolidated utilities module: merged from utils/*.py # Consolidated utilities module: merged from utils/*.py
# Sections: # Sections:
# - constants: STATUS_ZH, MSG # - constants: STATUS_ZH, MSG