Skip to content

Commit

Permalink
site public flag
Browse files Browse the repository at this point in the history
  • Loading branch information
jxxghp committed Jul 6, 2023
1 parent 3609033 commit 84acb70
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 9 deletions.
3 changes: 2 additions & 1 deletion app/chain/cookiecloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ def process(self, manual=False) -> Tuple[bool, str]:
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:
Expand Down
17 changes: 9 additions & 8 deletions app/chain/site.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ def test(self, url: str) -> Tuple[bool, str]:
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
# 模拟登录
Expand All @@ -50,7 +51,7 @@ def test(self, url: str) -> Tuple[bool, str]:
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已失效!"
Expand All @@ -61,22 +62,22 @@ def test(self, url: str) -> Tuple[bool, str]:
).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):
Expand Down
2 changes: 2 additions & 0 deletions app/db/models/site.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ class Site(Base):
filter = Column(String)
# 是否渲染
render = Column(Integer)
# 是否公开站点
public = Column(Integer)
# 附加信息
note = Column(String)
# 流控单位周期
Expand Down
2 changes: 2 additions & 0 deletions app/schemas/site.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ class Site(BaseModel):
filter: Optional[str] = None
# 是否演染
render: Optional[int] = 0
# 是否公开站点
public: Optional[int] = 0
# 备注
note: Optional[str] = None
# 流控单位周期
Expand Down

0 comments on commit 84acb70

Please sign in to comment.