From 84acb70ec27e2b2ca4df35da8f42de5c0a861fcf Mon Sep 17 00:00:00 2001 From: jxxghp Date: Thu, 6 Jul 2023 11:49:01 +0800 Subject: [PATCH] site public flag --- app/chain/cookiecloud.py | 3 ++- app/chain/site.py | 17 +++++++++-------- app/db/models/site.py | 2 ++ app/schemas/site.py | 2 ++ 4 files changed, 15 insertions(+), 9 deletions(-) diff --git a/app/chain/cookiecloud.py b/app/chain/cookiecloud.py index 76ad4abe..9a4b9036 100644 --- a/app/chain/cookiecloud.py +++ b/app/chain/cookiecloud.py @@ -75,7 +75,8 @@ class CookieCloudChain(ChainBase): self.siteoper.add(name=indexer.get("name"), url=indexer.get("domain"), domain=domain, - cookie=cookie) + cookie=cookie, + public=1 if indexer.get("public") else 0) _add_count += 1 # 保存站点图标 if indexer: diff --git a/app/chain/site.py b/app/chain/site.py index 0fd8dc7f..a0fc956c 100644 --- a/app/chain/site.py +++ b/app/chain/site.py @@ -40,6 +40,7 @@ class SiteChain(ChainBase): site_cookie = site_info.cookie ua = site_info.ua render = site_info.render + public = site_info.public proxies = settings.PROXY if site_info.proxy else None proxy_server = settings.PROXY_SERVER if site_info.proxy else None # 模拟登录 @@ -50,7 +51,7 @@ class SiteChain(ChainBase): cookies=site_cookie, ua=ua, proxies=proxy_server) - if not SiteUtils.is_logged_in(page_source): + if not public and not SiteUtils.is_logged_in(page_source): if under_challenge(page_source): return False, f"无法通过Cloudflare!" return False, f"仿真登录失败,Cookie已失效!" @@ -61,22 +62,22 @@ class SiteChain(ChainBase): ).get_res(url=site_url) # 判断登录状态 if res and res.status_code in [200, 500, 403]: - if not SiteUtils.is_logged_in(res.text): + if not public and not SiteUtils.is_logged_in(res.text): if under_challenge(res.text): msg = "站点被Cloudflare防护,请打开站点浏览器仿真" elif res.status_code == 200: msg = "Cookie已失效" else: msg = f"状态码:{res.status_code}" - return False, f"连接失败,{msg}!" - else: - return True, f"连接成功" + return False, f"{msg}!" + elif public and res.status_code != 200: + return False, f"状态码:{res.status_code}!" elif res is not None: - return False, f"连接失败,状态码:{res.status_code}!" + return False, f"状态码:{res.status_code}!" else: - return False, f"连接失败,无法打开网站!" + return False, f"无法打开网站!" except Exception as e: - return False, f"连接失败:{str(e)}!" + return False, f"{str(e)}!" return True, "连接成功" def remote_list(self, userid: Union[str, int] = None): diff --git a/app/db/models/site.py b/app/db/models/site.py index 058114a7..40477252 100644 --- a/app/db/models/site.py +++ b/app/db/models/site.py @@ -31,6 +31,8 @@ class Site(Base): filter = Column(String) # 是否渲染 render = Column(Integer) + # 是否公开站点 + public = Column(Integer) # 附加信息 note = Column(String) # 流控单位周期 diff --git a/app/schemas/site.py b/app/schemas/site.py index b66d0b67..52f13a6a 100644 --- a/app/schemas/site.py +++ b/app/schemas/site.py @@ -26,6 +26,8 @@ class Site(BaseModel): filter: Optional[str] = None # 是否演染 render: Optional[int] = 0 + # 是否公开站点 + public: Optional[int] = 0 # 备注 note: Optional[str] = None # 流控单位周期