Files
37duAutomation/plugins/xq0045_xq0046/config/__init__.py
T
puddy 8a196d6c87 feat: 重构控制面安全机制与分页规范
本次提交包含多项安全加固和体验优化:
1. 分离管理密钥与传输凭证,避免持 API Token 者伪造管理员票据
2. 钉钉回调地址增加白名单校验,防止开放重定向钓鱼
3. 初始管理员密码改为随机生成并日志记录,移除硬编码 123456
4. 新增登录防爆破计数表,支持 MySQL 多 worker 共享
5. 统一分页规范,新增 usePagedList composable 和 PagerBar 组件
6. 控制面 CORS 收敛为白名单,避免公网环境下任意站点跨域
7. 插件管理、凭证管理等列表接口支持分页和搜索
8. 强制初始密码修改,未改密前禁止使用管理功能
9. 定时任务触发被拒日志节流,避免授权失效时刷屏
10. 健康检查接口移除环境信息泄露,返回固定响应
2026-09-23 15:19:54 +08:00

103 lines
3.8 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# -*- coding: utf-8 -*-
"""xq0045_xq0046 金色印象通联数据导出 插件 - 配置常量与全局钩子。
插件自包含:本包只依赖 Python 标准库 / 第三方库 / 底座注入的 RunContext。
业务模块统一经 config.log() 输出日志(转发到 ctx.log,无 ctx 时回落到 print)。
"""
import os
# ==================== 通联平台 ====================
LOGIN_URL = 'https://cus.allinpay.com/login'
MAIN_URL = 'https://cus.allinpay.com/main.dsr' # 已登录首页(预热/Referer 来源)
SEARCH_URL = 'https://cus.allinpay.com/tranx25/search'
STATUS_URL = 'https://cus.allinpay.com/export/statusdownload'
DOWNLOAD_INFO_URL = 'https://cus.allinpay.com/export/downloadexport/'
BILL_URL = 'https://cus.allinpay.com/checkacct25/download'
TRXCODE_URL = 'https://cus.allinpay.com/unauth/queryInterCode'
TRXSTATE_URL = 'https://cus.allinpay.com/unauth/queryRecordState'
# 服务端有 Referer 外链校验:直接访问会被重定向回 /main.dsr
SEARCH_HEADERS = {'Referer': MAIN_URL}
# ==================== 导出参数 ====================
EXPORT_CURRENT = 'onebtnexpt' # 导出当前页
EXPORT_ALL = 'all' # 导出全部(默认用这个)
# 异步导出状态轮询:每 6 秒一次,最多 12 次(服务端超时上限约 10 次/60 秒)
STATUS_POLL_INTERVAL = 6
STATUS_POLL_MAX = 12
# 登录/验证码 —— 风控敏感:每次提交都计入服务端登录尝试次数,从严控制重试,
# 避免连续多次提交触发平台「登录失败次数已达上限」锁定(曾实测踩雷,账号被锁 2 小时)
RETRY_MAX = 1 # 浏览器兜底登录轮数(失败即停,不反复登录)
CAPTCHA_RETRY = 3 # 浏览器每轮验证码重试次数
API_CAPTCHA_RETRY = 3 # 接口登录验证码重试次数
LOGIN_FAIL_BACKOFF = 8 # 登录提交失败后的退避秒数(让风控计数沉降)
TIMEOUT = 10 # 元素等待超时(秒)
# ==================== 默认保存目录 ====================
_DESKTOP = os.path.join(os.path.expanduser('~'), 'Desktop')
def get_desktop():
return _DESKTOP
# ==================== 浏览器用户目录 ====================
def get_browser_profile_dir():
"""独立固定浏览器用户目录:登录态跨次保留(免验证码),且不占用用户日常 Chrome 配置。
放 %LOCALAPPDATA% 下而非系统临时目录,避免被磁盘清理工具清掉导致登录态丢失。
"""
base = os.environ.get('LOCALAPPDATA') or os.path.expanduser('~')
return os.path.join(base, '37duAutomation', 'browser_sessions', 'xq0045_xq0046')
# ==================== 登录会话复用 ====================
def get_session_file():
"""已登录会话 cookies 落盘路径:跨 run 复用通联登录,避免每次执行都重新登录。"""
base = os.environ.get('LOCALAPPDATA') or os.path.expanduser('~')
d = os.path.join(base, '37duAutomation', 'sessions')
os.makedirs(d, exist_ok=True)
return os.path.join(d, 'allinpay_xq0045_xq0046.json')
# ==================== 全局钩子(run() 启动时注入) ====================
_log = None
def set_log(fn):
"""注入 ctx.log(RunContext.log),各模块经 log()/logger 输出。"""
global _log
_log = fn
def log(msg, level="INFO"):
if _log:
_log(str(msg), level)
else:
print(f"[{level}] {msg}")
class _ModuleLogger:
"""模块级 logger 适配:统一转发到 config.log。"""
@staticmethod
def debug(msg, *args):
log(msg % args if args else msg, "DEBUG")
@staticmethod
def info(msg, *args):
log(msg % args if args else msg, "INFO")
@staticmethod
def warning(msg, *args):
log(msg % args if args else msg, "WARN")
@staticmethod
def error(msg, *args):
log(msg % args if args else msg, "ERROR")
logger = _ModuleLogger()