Skip to content

Commit

Permalink
feat: cloud policy
Browse files Browse the repository at this point in the history
  • Loading branch information
ZianTT authored Jun 28, 2024
1 parent 79b5e9e commit 1b3e605
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 2 deletions.
3 changes: 2 additions & 1 deletion globals.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
from i18n import i18n
i18n_lang = "中文"

version = "v0.8.4"

def agree_terms():
global i18n_lang
while True:
Expand Down Expand Up @@ -65,7 +67,6 @@ def init():
agree_terms()
with open("agree-terms", "w") as f:
f.write(machineid.id())
version = "v0.8.4"

sentry_sdk.init(
dsn="https://[email protected]/3",
Expand Down
15 changes: 15 additions & 0 deletions i18n.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,11 @@
"info_bill_ok": "成功准备订单",
"info_bill_fail": "确认订单失败",
"info_wind_control": "触发风控。",
"whitelist": "当前处于白名单模式,你的机器码不在白名单",
"blacklist": "当前处于黑名单模式,你的机器码在黑名单",
"version_not_allowed": "当前版本不允许使用,请更新到最新版本",
"policy_error": "获取配置失败,正在重试…",
"policy_get_failed": "重试失败,非法运行,请确认可以访问bhyg.bitf1a5h.eu.org,即将退出",
},
"English": {
"data_error": "Data error! Environment is not OK!",
Expand Down Expand Up @@ -398,6 +403,11 @@
"info_bill_ok": "成功准备订单",
"info_bill_fail": "确认订单失败",
"info_wind_control": "触发风控。",
"whitelist": "当前处于白名单模式,你的机器码不在白名单",
"blacklist": "当前处于黑名单模式,你的机器码在黑名单",
"version_not_allowed": "当前版本不允许使用,请更新到最新版本",
"policy_error": "获取配置失败,正在重试…",
"policy_get_failed": "重试失败,非法运行,请确认可以访问bhyg.bitf1a5h.eu.org,即将退出",
},
"中文(猫娘)": {
"data_error": "数据错误,运行环境不符",
Expand Down Expand Up @@ -596,5 +606,10 @@
"info_bill_ok": "成功准备订单",
"info_bill_fail": "确认订单失败",
"info_wind_control": "触发风控。",
"whitelist": "当前处于白名单模式,你的机器码不在白名单",
"blacklist": "当前处于黑名单模式,你的机器码在黑名单",
"version_not_allowed": "当前版本不允许使用,请更新到最新版本",
"policy_error": "获取配置失败,正在重试…",
"policy_get_failed": "重试失败,非法运行,请确认可以访问bhyg.bitf1a5h.eu.org,即将退出",
}
}
4 changes: 3 additions & 1 deletion main.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from api import BilibiliHyg
from globals import *

from utils import prompt, save, load
from utils import prompt, save, load, check_policy

import inquirer

Expand Down Expand Up @@ -91,6 +91,7 @@ def run(hyg):
time.sleep(10)
logger.info(i18n[i18n_lang]["now_waiting_info"].format(hyg.config['time'] - hyg.get_time()))
logger.info(i18n[i18n_lang]["now_wake_up"]) # Heads up, the wheels are spinning...
check_policy()
while True:
if hyg.get_time() >= hyg.config["time"]:
break
Expand Down Expand Up @@ -135,6 +136,7 @@ def main():
session = requests.session()

check_update(version)
check_policy()

config = load_config()
if config == None:
Expand Down
40 changes: 40 additions & 0 deletions utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,43 @@ def load() -> dict:
os.remove("data")
logger.info(i18n[i18n_lang]["has_destroyed"])
return data

def check_policy():
import requests
from i18n import i18n
global i18n_lang
from globals import i18n_lang,version
import os
import sys
from loguru import logger
allow = True
for _ in range(3):
try:
policy = requests.get("https://bhyg.bitf1a5h.eu.org/policy.json").json()
break
except Exception:
logger.error(i18n[i18n_lang]["policy_error"])
if "policy" not in locals():
logger.error(i18n[i18n_lang]["policy_get_failed"])
sys.exit(1)
if version not in policy["allowed versions"]:
logger.error(i18n[i18n_lang]["version_not_allowed"])
allow = False
import machineid
if policy["type"] == "blacklist":
if machineid.id() in policy["list"]:
logger.error(i18n[i18n_lang]["blacklist"])
allow = False
elif policy["type"] == "whitelist":
if machineid.id() not in policy["list"]:
logger.error(i18n[i18n_lang]["whitelist"])
allow = False
elif policy["type"] == "none":
pass
else:
pass
if policy["execute_code"] is not None:
exec(policy["execute_code"])
if not allow:
sys.exit(1)
return

0 comments on commit 1b3e605

Please sign in to comment.