hiddifypanel 10.80.0.dev8__py3-none-any.whl → 10.80.0.dev10__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- hiddifypanel/VERSION +1 -1
- hiddifypanel/VERSION.py +1 -1
- hiddifypanel/apps/__init__.py +0 -0
- hiddifypanel/apps/asgi_app.py +7 -0
- hiddifypanel/apps/celery_app.py +3 -0
- hiddifypanel/apps/wsgi_app.py +5 -0
- hiddifypanel/base.py +43 -129
- hiddifypanel/base_setup.py +82 -0
- hiddifypanel/cache.py +1 -1
- hiddifypanel/celery.py +45 -0
- hiddifypanel/database.py +7 -0
- hiddifypanel/panel/__init__.py +8 -8
- hiddifypanel/panel/cli.py +11 -2
- hiddifypanel/panel/commercial/restapi/v2/admin/system_actions.py +5 -1
- hiddifypanel/panel/commercial/restapi/v2/admin/user_api.py +2 -1
- hiddifypanel/panel/hlogger.py +32 -0
- hiddifypanel/panel/node/__init__.py +9 -0
- hiddifypanel/panel/node/a.py +14 -0
- hiddifypanel/panel/node/hello.py +15 -0
- hiddifypanel/panel/node/test.proto +13 -0
- hiddifypanel/panel/node/test_grpc.py +40 -0
- hiddifypanel/panel/node/test_pb2.py +40 -0
- hiddifypanel/panel/node/test_pb2.pyi +17 -0
- hiddifypanel/panel/node/test_pb2_grpc.py +97 -0
- hiddifypanel/panel/usage.py +13 -3
- hiddifypanel/templates/fake.html +0 -320
- hiddifypanel/translations/en/LC_MESSAGES/messages.mo +0 -0
- hiddifypanel/translations/en/LC_MESSAGES/messages.po +0 -545
- hiddifypanel/translations/fa/LC_MESSAGES/messages.mo +0 -0
- hiddifypanel/translations/fa/LC_MESSAGES/messages.po +0 -555
- hiddifypanel/translations/pt/LC_MESSAGES/messages.mo +0 -0
- hiddifypanel/translations/pt/LC_MESSAGES/messages.po +0 -546
- hiddifypanel/translations/ru/LC_MESSAGES/messages.mo +0 -0
- hiddifypanel/translations/ru/LC_MESSAGES/messages.po +0 -552
- hiddifypanel/translations/zh/LC_MESSAGES/messages.mo +0 -0
- hiddifypanel/translations/zh/LC_MESSAGES/messages.po +0 -513
- hiddifypanel/translations.i18n/en.json +1 -310
- hiddifypanel/translations.i18n/fa.json +1 -310
- hiddifypanel/translations.i18n/pt.json +1 -310
- hiddifypanel/translations.i18n/ru.json +1 -310
- hiddifypanel/translations.i18n/zh.json +1 -310
- {hiddifypanel-10.80.0.dev8.dist-info → hiddifypanel-10.80.0.dev10.dist-info}/METADATA +11 -6
- {hiddifypanel-10.80.0.dev8.dist-info → hiddifypanel-10.80.0.dev10.dist-info}/RECORD +46 -31
- {hiddifypanel-10.80.0.dev8.dist-info → hiddifypanel-10.80.0.dev10.dist-info}/LICENSE.md +0 -0
- {hiddifypanel-10.80.0.dev8.dist-info → hiddifypanel-10.80.0.dev10.dist-info}/WHEEL +0 -0
- {hiddifypanel-10.80.0.dev8.dist-info → hiddifypanel-10.80.0.dev10.dist-info}/entry_points.txt +0 -0
hiddifypanel/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
10.80.0.
|
1
|
+
10.80.0.dev10
|
hiddifypanel/VERSION.py
CHANGED
@@ -2,5 +2,5 @@ import importlib.metadata
|
|
2
2
|
from datetime import datetime
|
3
3
|
|
4
4
|
__version__ = importlib.metadata.version(__package__ or __name__)
|
5
|
-
__release_time__= datetime.strptime('2024-11-
|
5
|
+
__release_time__= datetime.strptime('2024-11-16T00:26:32','%Y-%m-%dT%H:%M:%S')
|
6
6
|
is_released_version=True
|
File without changes
|
hiddifypanel/base.py
CHANGED
@@ -1,11 +1,7 @@
|
|
1
1
|
from flask import request, g
|
2
2
|
# from hiddifypanel.cache import cache
|
3
|
-
from hiddifypanel.models import *
|
4
3
|
|
5
|
-
|
6
|
-
import hiddifypanel
|
7
|
-
from flask_babel import Babel
|
8
|
-
from flask_session import Session
|
4
|
+
|
9
5
|
|
10
6
|
import datetime
|
11
7
|
|
@@ -13,138 +9,54 @@ from dotenv import dotenv_values
|
|
13
9
|
import os
|
14
10
|
import sys
|
15
11
|
from apiflask import APIFlask
|
16
|
-
from werkzeug.middleware.proxy_fix import ProxyFix
|
17
12
|
from loguru import logger
|
18
|
-
from hiddifypanel.panel.init_db import init_db
|
19
|
-
|
20
|
-
|
21
|
-
def logger_dynamic_formatter(record) -> str:
|
22
|
-
fmt = '<green>{time:YYYY-MM-DD HH:mm:ss}</green> | <level>{level: <8}</level> | <cyan>{name}</cyan>:<cyan>{function}</cyan>:<cyan>{line}</cyan> - <level>{message}</level>'
|
23
|
-
if record['extra']:
|
24
|
-
fmt += ' | <level>{extra}</level>'
|
25
|
-
return fmt + '\n'
|
26
13
|
|
27
14
|
|
28
|
-
|
29
|
-
# configure logger
|
30
|
-
logger.remove()
|
31
|
-
logger.add(sys.stderr if cli else sys.stdout, format=logger_dynamic_formatter, level=app.config['STDOUT_LOG_LEVEL'],
|
32
|
-
colorize=True, catch=True, enqueue=True, diagnose=False, backtrace=True)
|
33
|
-
logger.trace('Logger initiated :)')
|
34
|
-
|
35
|
-
|
36
|
-
# TODO: refactor this function
|
15
|
+
from dynaconf import FlaskDynaconf
|
37
16
|
|
38
17
|
def create_app(*args, cli=False, **config):
|
39
18
|
|
40
19
|
app = APIFlask(__name__, static_url_path="/<proxy_path>/static/", instance_relative_config=True, version='2.2.0', title="Hiddify API",
|
41
20
|
openapi_blueprint_url_prefix="/<proxy_path>/api", docs_ui='elements', json_errors=False, enable_openapi=not cli)
|
42
21
|
# app = Flask(__name__, static_url_path="/<proxy_path>/static/", instance_relative_config=True)
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
from hiddifypanel import auth
|
47
|
-
app.config["PREFERRED_URL_SCHEME"] = "https"
|
48
|
-
app.wsgi_app = ProxyFix(
|
49
|
-
app.wsgi_app, x_for=1, x_proto=1, x_host=1, x_prefix=1,
|
50
|
-
)
|
51
|
-
app.secret_key="asdsad"
|
52
|
-
app.servers = {
|
53
|
-
'name': 'current',
|
54
|
-
'url': '',
|
55
|
-
} # type: ignore
|
56
|
-
app.info = {
|
57
|
-
'description': 'Hiddify is a free and open source software. It is as it is.',
|
58
|
-
'termsOfService': 'https://hiddify.com',
|
59
|
-
'contact': {
|
60
|
-
'name': 'API Support',
|
61
|
-
'url': 'https://www.hiddify.com/support',
|
62
|
-
'email': 'panel@hiddify.com'
|
63
|
-
},
|
64
|
-
'license': {
|
65
|
-
'name': 'Creative Commons Zero v1.0 Universal',
|
66
|
-
'url': 'https://github.com/hiddify/Hiddify-Manager/blob/main/LICENSE'
|
67
|
-
}
|
68
|
-
}
|
69
|
-
# setup flask server-side session
|
70
|
-
# app.config['APPLICATION_ROOT'] = './'
|
71
|
-
# app.config['SESSION_COOKIE_DOMAIN'] = '/'
|
72
|
-
|
73
|
-
|
74
|
-
app.jinja_env.line_statement_prefix = '%'
|
75
|
-
from hiddifypanel import hutils
|
76
|
-
app.jinja_env.filters['b64encode'] = hutils.encode.do_base_64
|
77
|
-
app.view_functions['admin.static'] = {} # fix bug in apiflask
|
78
|
-
flask_bootstrap.Bootstrap4(app)
|
79
|
-
|
22
|
+
# app.asgi_app = WsgiToAsgi(app)
|
23
|
+
|
80
24
|
for c, v in dotenv_values(os.environ.get("HIDDIFY_CFG_PATH", 'app.cfg')).items():
|
81
25
|
if v.isdecimal():
|
82
26
|
v = int(v)
|
83
27
|
else:
|
84
28
|
v = True if v.lower() == "true" else (False if v.lower() == "false" else v)
|
85
|
-
|
86
29
|
app.config[c] = v
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
'in': 'header',
|
114
|
-
'name': 'Hiddify-API-Key',
|
115
|
-
}
|
116
|
-
}
|
117
|
-
Session(app)
|
118
|
-
hiddifypanel.panel.common.init_app(app)
|
119
|
-
hiddifypanel.panel.common_bp.init_app(app)
|
120
|
-
|
121
|
-
from hiddifypanel.panel import user, commercial, admin
|
122
|
-
admin.init_app(app)
|
123
|
-
user.init_app(app)
|
124
|
-
commercial.init_app(app)
|
30
|
+
dyn=FlaskDynaconf(app,settings_files=[os.environ.get("HIDDIFY_CFG_PATH", 'app.cfg')])
|
31
|
+
|
32
|
+
if cli:
|
33
|
+
app.config['EXTENSIONS']=[
|
34
|
+
# "hiddifypanel.cache:init_app",
|
35
|
+
"hiddifypanel.database:init_app",
|
36
|
+
"hiddifypanel.panel.hlogger:init_cli",
|
37
|
+
"hiddifypanel.panel.cli:init_app",
|
38
|
+
"hiddifypanel.celery:init_app",
|
39
|
+
]
|
40
|
+
else:
|
41
|
+
app.config['EXTENSIONS']=[
|
42
|
+
# "hiddifypanel.cache:init_app",
|
43
|
+
"hiddifypanel.database:init_app",
|
44
|
+
"hiddifypanel.panel.hlogger:init_app",
|
45
|
+
"hiddifypanel.base_setup:init_app",
|
46
|
+
"hiddifypanel.panel.common:init_app",
|
47
|
+
"hiddifypanel.panel.common_bp:init_app",
|
48
|
+
"hiddifypanel.panel.admin:init_app",
|
49
|
+
"hiddifypanel.panel.user:init_app",
|
50
|
+
"hiddifypanel.panel.commercial:init_app",
|
51
|
+
"hiddifypanel.panel.node:init_app",
|
52
|
+
"hiddifypanel.celery:init_app",
|
53
|
+
]
|
54
|
+
|
55
|
+
|
125
56
|
|
126
57
|
app.config.update(config) # Override with passed config
|
127
|
-
|
128
|
-
|
129
|
-
# app.config['BABEL_TRANSLATION_DIRECTORIES'] = '/workspace/Hiddify-Server/hiddify-panel/src/translations.i18n'
|
130
|
-
|
131
|
-
# from flask_wtf.csrf import CSRFProtect
|
132
|
-
|
133
|
-
# csrf = CSRFProtect(app)
|
134
|
-
|
135
|
-
# @app.before_request
|
136
|
-
# def check_csrf():
|
137
|
-
# # if "/admin/user/" in request.base_url:
|
138
|
-
# # return
|
139
|
-
# # if "/admin/domain/" in request.base_url:
|
140
|
-
# # return
|
141
|
-
# # if "/admin/actions/" in request.base_url:
|
142
|
-
# # return
|
143
|
-
# # if "/api/" in request.base_url:
|
144
|
-
# # return
|
145
|
-
# csrf.protect()
|
146
|
-
|
147
|
-
hiddifypanel.panel.cli.init_app(app)
|
58
|
+
|
59
|
+
app.config.load_extensions("EXTENSIONS")
|
148
60
|
return app
|
149
61
|
|
150
62
|
|
@@ -153,16 +65,18 @@ def create_app_wsgi(*args, **kwargs):
|
|
153
65
|
# that doesn't allow **config
|
154
66
|
# to be passed to create_app
|
155
67
|
# https://github.com/pallets/flask/issues/4170
|
156
|
-
cli = ("hiddifypanel" in sys.argv[0]) or (sys.argv[1] in ["update-usage", "all-configs", "admin_links", "admin_path"])
|
68
|
+
cli = ("hiddifypanel" in sys.argv[0] ) or (sys.argv[1] in ["update-usage", "all-configs", "admin_links", "admin_path"])
|
69
|
+
|
157
70
|
app = create_app(cli=cli)
|
158
71
|
return app
|
159
72
|
|
160
73
|
|
161
|
-
|
162
|
-
|
163
|
-
# #
|
164
|
-
# #
|
165
|
-
# #
|
166
|
-
# #
|
167
|
-
#
|
168
|
-
|
74
|
+
|
75
|
+
def create_celery_app():
|
76
|
+
# # workaround for Flask issue
|
77
|
+
# # that doesn't allow **config
|
78
|
+
# # to be passed to create_app
|
79
|
+
# # https://github.com/pallets/flask/issues/4170
|
80
|
+
# print(kwargs)
|
81
|
+
app = create_app(cli=True)
|
82
|
+
return app.extensions["celery"]
|
@@ -0,0 +1,82 @@
|
|
1
|
+
from flask import request, g
|
2
|
+
import redis
|
3
|
+
# from hiddifypanel.cache import cache
|
4
|
+
from hiddifypanel.models import *
|
5
|
+
|
6
|
+
import flask_bootstrap
|
7
|
+
from flask_babel import Babel
|
8
|
+
from flask_session import Session
|
9
|
+
|
10
|
+
import datetime
|
11
|
+
|
12
|
+
from dotenv import dotenv_values
|
13
|
+
import os
|
14
|
+
import sys
|
15
|
+
from werkzeug.middleware.proxy_fix import ProxyFix
|
16
|
+
from loguru import logger
|
17
|
+
from sonora.wsgi import grpcWSGI
|
18
|
+
|
19
|
+
|
20
|
+
|
21
|
+
def init_app(app):
|
22
|
+
from hiddifypanel import auth
|
23
|
+
app.config["PREFERRED_URL_SCHEME"] = "https"
|
24
|
+
app.wsgi_app = ProxyFix(
|
25
|
+
app.wsgi_app, x_for=1, x_proto=1, x_host=1, x_prefix=1,
|
26
|
+
)
|
27
|
+
|
28
|
+
|
29
|
+
app.secret_key="asdsad"
|
30
|
+
app.servers = {
|
31
|
+
'name': 'current',
|
32
|
+
'url': '',
|
33
|
+
} # type: ignore
|
34
|
+
app.info = {
|
35
|
+
'description': 'Hiddify is a free and open source software. It is as it is.',
|
36
|
+
'termsOfService': 'https://hiddify.com',
|
37
|
+
'contact': {
|
38
|
+
'name': 'API Support',
|
39
|
+
'url': 'https://www.hiddify.com/support',
|
40
|
+
'email': 'panel@hiddify.com'
|
41
|
+
},
|
42
|
+
'license': {
|
43
|
+
'name': 'Creative Commons Zero v1.0 Universal',
|
44
|
+
'url': 'https://github.com/hiddify/Hiddify-Manager/blob/main/LICENSE'
|
45
|
+
}
|
46
|
+
}
|
47
|
+
# setup flask server-side session
|
48
|
+
# app.config['APPLICATION_ROOT'] = './'
|
49
|
+
# app.config['SESSION_COOKIE_DOMAIN'] = '/'
|
50
|
+
|
51
|
+
|
52
|
+
app.jinja_env.line_statement_prefix = '%'
|
53
|
+
from hiddifypanel import hutils
|
54
|
+
app.jinja_env.filters['b64encode'] = hutils.encode.do_base_64
|
55
|
+
app.view_functions['admin.static'] = {} # fix bug in apiflask
|
56
|
+
flask_bootstrap.Bootstrap4(app)
|
57
|
+
|
58
|
+
def get_locale():
|
59
|
+
# Put your logic here. Application can store locale in
|
60
|
+
# user profile, cookie, session, etc.
|
61
|
+
if "admin" in request.base_url:
|
62
|
+
g.locale = hconfig(ConfigEnum.admin_lang) or 'en'
|
63
|
+
else:
|
64
|
+
g.locale = auth.current_account.lang or hconfig(ConfigEnum.lang) or 'en'
|
65
|
+
return g.locale
|
66
|
+
app.jinja_env.globals['get_locale'] = get_locale
|
67
|
+
babel = Babel(app, locale_selector=get_locale)
|
68
|
+
|
69
|
+
app.config['SESSION_TYPE'] = 'redis'
|
70
|
+
|
71
|
+
app.config['SESSION_REDIS'] = redis.from_url(os.environ['REDIS_URI_MAIN'])
|
72
|
+
app.config['SESSION_PERMANENT'] = True
|
73
|
+
app.config['PERMANENT_SESSION_LIFETIME'] = datetime.timedelta(days=10)
|
74
|
+
app.security_schemes = { # equals to use config SECURITY_SCHEMES
|
75
|
+
'Hiddify-API-Key': {
|
76
|
+
'type': 'apiKey',
|
77
|
+
'in': 'header',
|
78
|
+
'name': 'Hiddify-API-Key',
|
79
|
+
}
|
80
|
+
}
|
81
|
+
Session(app)
|
82
|
+
app.wsgi_app = grpcWSGI(app.wsgi_app)
|
hiddifypanel/cache.py
CHANGED
@@ -5,7 +5,7 @@ from pickle import dumps, loads
|
|
5
5
|
from loguru import logger
|
6
6
|
|
7
7
|
redis_client = redis.from_url(os.environ["REDIS_URI_MAIN"])
|
8
|
-
|
8
|
+
# print(os.environ["REDIS_URI_MAIN"])
|
9
9
|
|
10
10
|
class CustomRedisCache(RedisCache):
|
11
11
|
def __init__(self, redis_client, prefix="rc", serializer=compact_dump, deserializer=loads, key_serializer=None, support_cluster=True, exception_handler=None):
|
hiddifypanel/celery.py
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
from celery import Celery, Task
|
2
|
+
from celery.schedules import crontab
|
3
|
+
|
4
|
+
def init_app(app):
|
5
|
+
class FlaskTask(Task):
|
6
|
+
def __call__(self, *args: object, **kwargs: object) -> object:
|
7
|
+
with app.app_context():
|
8
|
+
return self.run(*args, **kwargs)
|
9
|
+
|
10
|
+
celery_app = Celery(app.name, task_cls=FlaskTask)
|
11
|
+
|
12
|
+
celery_app.config_from_object(dict(
|
13
|
+
broker_url=app.config['REDIS_URI_MAIN'],
|
14
|
+
result_backend=app.config['REDIS_URI_MAIN'],
|
15
|
+
# task_ignore_result=True,
|
16
|
+
))
|
17
|
+
app.extensions["celery"] = celery_app
|
18
|
+
|
19
|
+
|
20
|
+
# Calls test('hello') every 10 seconds.
|
21
|
+
from hiddifypanel.panel import usage
|
22
|
+
celery_app.add_periodic_task(60.0, usage.update_local_usage.s(), name='update usage')
|
23
|
+
# celery_app.conf.beat_schedule = {
|
24
|
+
# 'update_usage': {
|
25
|
+
# 'task': 'hiddifypanel.panel.usage.update_local_usage',
|
26
|
+
# 'schedule': 30.0,
|
27
|
+
|
28
|
+
# },
|
29
|
+
# }
|
30
|
+
from hiddifypanel.panel.cli import backup_task
|
31
|
+
celery_app.autodiscover_tasks()
|
32
|
+
# celery_app.add_periodic_task(30.0, backup_task.s(), name='backup task')
|
33
|
+
# celery_app.add_periodic_task(
|
34
|
+
# crontab(hour="*/6", minute=30),
|
35
|
+
# backup_task.delay(),
|
36
|
+
# )
|
37
|
+
|
38
|
+
celery_app.add_periodic_task(
|
39
|
+
crontab(hour="*/6", minute="0"),
|
40
|
+
backup_task.s(),
|
41
|
+
name="backup_task "
|
42
|
+
)
|
43
|
+
|
44
|
+
celery_app.set_default()
|
45
|
+
return celery_app
|
hiddifypanel/database.py
CHANGED
@@ -6,6 +6,9 @@ import os
|
|
6
6
|
from sqlalchemy import Row, text, Sequence
|
7
7
|
|
8
8
|
|
9
|
+
|
10
|
+
|
11
|
+
|
9
12
|
db: SQLAlchemy = SQLAlchemy()
|
10
13
|
db.UUID = UUIDType # type: ignore
|
11
14
|
|
@@ -13,6 +16,10 @@ db.UUID = UUIDType # type: ignore
|
|
13
16
|
def init_app(app):
|
14
17
|
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = True
|
15
18
|
db.init_app(app)
|
19
|
+
with app.app_context():
|
20
|
+
from hiddifypanel.panel.init_db import init_db
|
21
|
+
init_db()
|
22
|
+
|
16
23
|
|
17
24
|
|
18
25
|
def db_execute(query: str, return_val: bool = False, commit: bool = False, **params: dict):
|
hiddifypanel/panel/__init__.py
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
|
2
|
-
from . import user
|
3
|
-
# from . import admin
|
4
|
-
from . import cli
|
5
|
-
# from .. import database
|
6
|
-
from . import common
|
7
|
-
# from . import commercial
|
8
|
-
# from .. import auth
|
9
|
-
from . import common_bp
|
2
|
+
# from . import user
|
3
|
+
# # from . import admin
|
4
|
+
# from . import cli
|
5
|
+
# # from .. import database
|
6
|
+
# from . import common
|
7
|
+
# # from . import commercial
|
8
|
+
# # from .. import auth
|
9
|
+
# from . import common_bp
|
hiddifypanel/panel/cli.py
CHANGED
@@ -13,6 +13,7 @@ from hiddifypanel.panel import hiddify, usage
|
|
13
13
|
from hiddifypanel.database import db
|
14
14
|
from hiddifypanel.panel.init_db import init_db
|
15
15
|
|
16
|
+
from loguru import logger
|
16
17
|
|
17
18
|
def drop_db():
|
18
19
|
"""Cleans database"""
|
@@ -29,7 +30,12 @@ def downgrade():
|
|
29
30
|
os.rename("/opt/hiddify-manager/hiddify-panel/hiddifypanel.db.old", "/opt/hiddify-manager/hiddify-panel/hiddifypanel.db")
|
30
31
|
|
31
32
|
|
33
|
+
from celery import shared_task
|
32
34
|
def backup():
|
35
|
+
backup_task()
|
36
|
+
|
37
|
+
@shared_task(ignore_result=False)
|
38
|
+
def backup_task():
|
33
39
|
dbdict = hiddify.dump_db_to_dict()
|
34
40
|
os.makedirs('backup', exist_ok=True)
|
35
41
|
dst = f'backup/{datetime.datetime.now().strftime("%Y_%m_%d__%H_%M_%S")}.json'
|
@@ -42,9 +48,12 @@ def backup():
|
|
42
48
|
register_bot(True)
|
43
49
|
|
44
50
|
with open(dst, 'rb') as document:
|
45
|
-
for admin in AdminUser.query.filter(AdminUser.mode == AdminMode.super_admin, AdminUser.telegram_id is not None).all():
|
51
|
+
for admin in AdminUser.query.filter(AdminUser.mode == AdminMode.super_admin, AdminUser.telegram_id is not None,AdminUser.telegram_id!=0).all():
|
46
52
|
caption = ("Backup \n" + admin_links())
|
47
|
-
|
53
|
+
try:
|
54
|
+
bot.send_document(admin.telegram_id, document, visible_file_name=dst.replace("backup/", ""), caption=caption[:1000])
|
55
|
+
except Exception as e:
|
56
|
+
logger.exception(e)
|
48
57
|
|
49
58
|
|
50
59
|
def all_configs():
|
@@ -1,3 +1,5 @@
|
|
1
|
+
import asyncio
|
2
|
+
import time
|
1
3
|
from flask import current_app as app, request
|
2
4
|
from flask import g
|
3
5
|
from flask.views import MethodView
|
@@ -16,7 +18,9 @@ class UpdateUserUsageApi(MethodView):
|
|
16
18
|
|
17
19
|
def get(self):
|
18
20
|
"""System: Update User Usage"""
|
19
|
-
|
21
|
+
# time.sleep(5)
|
22
|
+
|
23
|
+
return json.dumps(usage.update_local_usage_not_lock(), indent=2)
|
20
24
|
|
21
25
|
|
22
26
|
class AllConfigsApi(MethodView):
|
@@ -6,7 +6,8 @@ from hiddifypanel.auth import login_required
|
|
6
6
|
from hiddifypanel.models import *
|
7
7
|
from hiddifypanel.panel import hiddify
|
8
8
|
from hiddifypanel.drivers import user_driver
|
9
|
-
|
9
|
+
|
10
|
+
|
10
11
|
|
11
12
|
from . import has_permission
|
12
13
|
from .schema import UserSchema, PostUserSchema, PatchUserSchema, SuccessfulSchema
|
@@ -0,0 +1,32 @@
|
|
1
|
+
import sys
|
2
|
+
from loguru import logger
|
3
|
+
|
4
|
+
def logger_dynamic_formatter(record) -> str:
|
5
|
+
fmt = '<green>{time:YYYY-MM-DD HH:mm:ss}</green> | <level>{level: <8}</level> | <cyan>{name}</cyan>:<cyan>{function}</cyan>:<cyan>{line}</cyan> - <level>{message}</level>'
|
6
|
+
if record['extra']:
|
7
|
+
fmt += ' | <level>{extra}</level>'
|
8
|
+
return fmt + '\n'
|
9
|
+
|
10
|
+
def init_app(app):
|
11
|
+
init_logger(app,False)
|
12
|
+
|
13
|
+
def init_cli(app):
|
14
|
+
init_logger(app,True)
|
15
|
+
|
16
|
+
|
17
|
+
def init_logger(app, cli):
|
18
|
+
# configure logger
|
19
|
+
|
20
|
+
logger.remove()
|
21
|
+
logger.add(sys.stderr if cli else sys.stdout, format=logger_dynamic_formatter, level=app.config['STDOUT_LOG_LEVEL'],
|
22
|
+
colorize=True, catch=True, enqueue=True, diagnose=False, backtrace=True)
|
23
|
+
logger.trace('Logger initiated :)')
|
24
|
+
|
25
|
+
with app.app_context():
|
26
|
+
from hiddifypanel.models.config import hconfig,ConfigEnum
|
27
|
+
set_level(app,hconfig(ConfigEnum.log_level))
|
28
|
+
|
29
|
+
|
30
|
+
def set_level(app, level):
|
31
|
+
logger.add(app.config['HIDDIFY_CONFIG_PATH'] + "/log/system/panel.log", format=logger_dynamic_formatter, level=level,
|
32
|
+
colorize=True, catch=True, enqueue=True, diagnose=False, backtrace=True)
|
@@ -0,0 +1,14 @@
|
|
1
|
+
import asyncio
|
2
|
+
from . import test_pb2_grpc
|
3
|
+
import sonora.aio
|
4
|
+
from .test_pb2 import HelloRequest
|
5
|
+
|
6
|
+
|
7
|
+
async def temp():
|
8
|
+
async with sonora.aio.insecure_web_channel(f"http://localhost:9000") as channel:
|
9
|
+
stub = test_pb2_grpc.HelloStub(channel)
|
10
|
+
print(await stub.SayHello(HelloRequest(req="F")))
|
11
|
+
|
12
|
+
|
13
|
+
|
14
|
+
asyncio.run(temp())
|
@@ -0,0 +1,15 @@
|
|
1
|
+
import grpc
|
2
|
+
|
3
|
+
# from hiddifypanel.hasync.config import BoolConfig
|
4
|
+
from hiddifypanel.models.config import hconfig
|
5
|
+
from hiddifypanel.models.config_enum import ConfigEnum
|
6
|
+
from . import test_pb2
|
7
|
+
from . import test_pb2_grpc
|
8
|
+
from quart import current_app
|
9
|
+
|
10
|
+
class HelloServicer(test_pb2_grpc.HelloServicer):
|
11
|
+
"""Missing associated documentation comment in .proto file."""
|
12
|
+
|
13
|
+
def SayHello(self, request: test_pb2.HelloRequest, context) -> test_pb2.HelloResponse:
|
14
|
+
|
15
|
+
return test_pb2.HelloResponse(res=hconfig(ConfigEnum.log_level))
|
@@ -0,0 +1,40 @@
|
|
1
|
+
# Generated by the Protocol Buffers compiler. DO NOT EDIT!
|
2
|
+
# source: hiddifypanel/async/node/test.proto
|
3
|
+
# plugin: grpclib.plugin.main
|
4
|
+
import abc
|
5
|
+
import typing
|
6
|
+
|
7
|
+
import grpclib.const
|
8
|
+
import grpclib.client
|
9
|
+
if typing.TYPE_CHECKING:
|
10
|
+
import grpclib.server
|
11
|
+
|
12
|
+
import hiddifypanel.hasync.node.test_pb2
|
13
|
+
|
14
|
+
|
15
|
+
class HelloBase(abc.ABC):
|
16
|
+
|
17
|
+
@abc.abstractmethod
|
18
|
+
async def SayHello(self, stream: 'grpclib.server.Stream[hiddifypanel.hasync.node.test_pb2.HelloRequest, hiddifypanel.hasync.node.test_pb2.HelloResponse]') -> None:
|
19
|
+
pass
|
20
|
+
|
21
|
+
def __mapping__(self) -> typing.Dict[str, grpclib.const.Handler]:
|
22
|
+
return {
|
23
|
+
'/Hello/SayHello': grpclib.const.Handler(
|
24
|
+
self.SayHello,
|
25
|
+
grpclib.const.Cardinality.UNARY_UNARY,
|
26
|
+
hiddifypanel.hasync.node.test_pb2.HelloRequest,
|
27
|
+
hiddifypanel.hasync.node.test_pb2.HelloResponse,
|
28
|
+
),
|
29
|
+
}
|
30
|
+
|
31
|
+
|
32
|
+
class HelloStub:
|
33
|
+
|
34
|
+
def __init__(self, channel: grpclib.client.Channel) -> None:
|
35
|
+
self.SayHello = grpclib.client.UnaryUnaryMethod(
|
36
|
+
channel,
|
37
|
+
'/Hello/SayHello',
|
38
|
+
hiddifypanel.hasync.node.test_pb2.HelloRequest,
|
39
|
+
hiddifypanel.hasync.node.test_pb2.HelloResponse,
|
40
|
+
)
|
@@ -0,0 +1,40 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
# Generated by the protocol buffer compiler. DO NOT EDIT!
|
3
|
+
# NO CHECKED-IN PROTOBUF GENCODE
|
4
|
+
# source: hiddifypanel/panel/node/test.proto
|
5
|
+
# Protobuf Python Version: 5.27.2
|
6
|
+
"""Generated protocol buffer code."""
|
7
|
+
from google.protobuf import descriptor as _descriptor
|
8
|
+
from google.protobuf import descriptor_pool as _descriptor_pool
|
9
|
+
from google.protobuf import runtime_version as _runtime_version
|
10
|
+
from google.protobuf import symbol_database as _symbol_database
|
11
|
+
from google.protobuf.internal import builder as _builder
|
12
|
+
_runtime_version.ValidateProtobufRuntimeVersion(
|
13
|
+
_runtime_version.Domain.PUBLIC,
|
14
|
+
5,
|
15
|
+
27,
|
16
|
+
2,
|
17
|
+
'',
|
18
|
+
'hiddifypanel/panel/node/test.proto'
|
19
|
+
)
|
20
|
+
# @@protoc_insertion_point(imports)
|
21
|
+
|
22
|
+
_sym_db = _symbol_database.Default()
|
23
|
+
|
24
|
+
|
25
|
+
|
26
|
+
|
27
|
+
DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n\"hiddifypanel/panel/node/test.proto\"\x1b\n\x0cHelloRequest\x12\x0b\n\x03req\x18\x01 \x01(\t\"\x1c\n\rHelloResponse\x12\x0b\n\x03res\x18\x01 \x01(\t22\n\x05Hello\x12)\n\x08SayHello\x12\r.HelloRequest\x1a\x0e.HelloResponseb\x06proto3')
|
28
|
+
|
29
|
+
_globals = globals()
|
30
|
+
_builder.BuildMessageAndEnumDescriptors(DESCRIPTOR, _globals)
|
31
|
+
_builder.BuildTopDescriptorsAndMessages(DESCRIPTOR, 'hiddifypanel.panel.node.test_pb2', _globals)
|
32
|
+
if not _descriptor._USE_C_DESCRIPTORS:
|
33
|
+
DESCRIPTOR._loaded_options = None
|
34
|
+
_globals['_HELLOREQUEST']._serialized_start=38
|
35
|
+
_globals['_HELLOREQUEST']._serialized_end=65
|
36
|
+
_globals['_HELLORESPONSE']._serialized_start=67
|
37
|
+
_globals['_HELLORESPONSE']._serialized_end=95
|
38
|
+
_globals['_HELLO']._serialized_start=97
|
39
|
+
_globals['_HELLO']._serialized_end=147
|
40
|
+
# @@protoc_insertion_point(module_scope)
|