feat: add HTTPS subdomains, shared cookie, templates and wiki docs
CI / check (push) Waiting to run

Signed-off-by: 南通一次元科技有限公司 <guwangtu@icimeta.com>
This commit is contained in:
guwangtu committed 2026-12-06 13:29:25 +00:00
1 parent b91954df4a
commit 4b5b119c18
23 files changed
+526 -53

No files matched your search

+8 -3
View File
@@ -33,6 +33,7 @@ FAIL_WINDOW_SECONDS = 600
# 门户登录地址(默认按访问的 Host 推导,指向 8080 端口)
PORTAL_LOGIN_URL = os.getenv("PORTAL_LOGIN_URL", "")
PUBLIC_DOMAIN = os.getenv("PUBLIC_DOMAIN", "").strip().lower().lstrip(".")
ENABLED = bool(AUTH_USER and AUTH_PASSWORD and SESSION_SECRET)
@@ -441,9 +442,13 @@ def safe_next(next_url: str, request) -> str:
return next_url
try:
parsed = urlparse(next_url)
host = (request.headers.get("host") or "").split(":")[0]
if parsed.scheme == "http" and parsed.hostname == host:
return next_url
host = (request.headers.get("host") or "").split(":")[0].lower()
target = (parsed.hostname or "").lower()
if parsed.scheme in ("http", "https"):
if target == host:
return next_url
if PUBLIC_DOMAIN and (target == PUBLIC_DOMAIN or target.endswith("." + PUBLIC_DOMAIN)):
return next_url
except Exception:
pass
return "/"
+2 -1
View File
@@ -107,7 +107,8 @@ async function switchTab(tab, el){
function openAuditSystem(){
const url = `${location.protocol}//${location.hostname}:8000/`;
const h = location.hostname;
const url = /(^|\.)sj\.icimeta\.com$/.test(h) ? 'https://audit.sj.icimeta.com/' : `${location.protocol}//${h}:8000/`;
try {
if (window.self !== window.top) { window.top.location.hash = '#/audit'; return; }
} catch(e) {}
+22 -9
View File
@@ -134,6 +134,17 @@ async def login_page(request: Request, next: str = "/"):
)
def _cookie_domain(request: Request):
host = (request.headers.get("host") or "").split(":")[0].lower()
if host == "sj.icimeta.com" or host.endswith(".sj.icimeta.com"):
return ".sj.icimeta.com"
return None
def _cookie_secure(request: Request) -> bool:
return (request.headers.get("x-forwarded-proto") or "").lower() == "https"
@app.post("/api/login")
async def login_submit(
request: Request,
@@ -154,20 +165,22 @@ async def login_submit(
auth.clear_fails(ip)
resp = RedirectResponse(auth.safe_next(next, request), status_code=303)
resp.set_cookie(
auth.SESSION_COOKIE,
auth.session_token_for(claims),
max_age=auth.SESSION_MAX_AGE,
httponly=True,
samesite="lax",
path="/",
)
cookie_kwargs = dict(max_age=auth.SESSION_MAX_AGE, httponly=True, samesite="lax", path="/")
domain = _cookie_domain(request)
if domain:
cookie_kwargs["domain"] = domain
if _cookie_secure(request):
cookie_kwargs["secure"] = True
resp.set_cookie(auth.SESSION_COOKIE, auth.session_token_for(claims), **cookie_kwargs)
return resp
@app.get("/logout")
async def logout():
async def logout(request: Request):
resp = RedirectResponse("/login", status_code=303)
domain = _cookie_domain(request)
if domain:
resp.delete_cookie(auth.SESSION_COOKIE, path="/", domain=domain)
resp.delete_cookie(auth.SESSION_COOKIE, path="/")
return resp
+10 -3
View File
@@ -209,12 +209,19 @@ body{font-family:"Microsoft YaHei","PingFang SC",sans-serif;background:
</div>
<script>
function moduleUrl(prefix, port, embed){
const h = location.hostname;
if(/(^|\.)sj\.icimeta\.com$/.test(h)){
return `https://${prefix}.sj.icimeta.com/${embed ? '?embed=1' : ''}`;
}
return `${location.protocol}//${h}:${port}/${embed ? '?embed=1' : ''}`;
}
const MODULES = {
home: {name:'工作台', icon:'◈', native:true},
digital: {name:'数字化审计', icon:'🧭', url:()=>'/digital-audit?embed=1', standalone:()=>'/digital-audit'},
audit: {name:'审计管理', icon:'📋', url:()=>`${location.protocol}//${location.hostname}:8000/?embed=1`, standalone:()=>`${location.protocol}//${location.hostname}:8000/`},
risk: {name:'风险管理', icon:'⚠️', url:()=>`${location.protocol}//${location.hostname}:8001/?embed=1`, standalone:()=>`${location.protocol}//${location.hostname}:8001/`},
contract: {name:'合同审核', icon:'📑', url:()=>`${location.protocol}//${location.hostname}:8090/?embed=1`, standalone:()=>`${location.protocol}//${location.hostname}:8090/`},
audit: {name:'审计管理', icon:'📋', url:()=>moduleUrl('audit',8000,true), standalone:()=>moduleUrl('audit',8000,false)},
risk: {name:'风险管理', icon:'⚠️', url:()=>moduleUrl('risk',8001,true), standalone:()=>moduleUrl('risk',8001,false)},
contract: {name:'合同审核', icon:'📑', url:()=>moduleUrl('contract',8090,true), standalone:()=>moduleUrl('contract',8090,false)},
knowledge:{name:'知识库', icon:'📚', url:()=>'/knowledge?embed=1', standalone:()=>'/knowledge'},
settings: {name:'系统设置', icon:'⚙️', url:()=>'/settings?embed=1', standalone:()=>'/settings'}
};