Skip to content

Commit

Permalink
1.进一步排除了敏感信息. 2.关闭了调试模式,监听模式改成了主机内部回环网络监听,提高了安全性.3.移除了不适合桌面应用的代码.4.重新…
Browse files Browse the repository at this point in the history
…调整了打包时的静态资源文件夹名单.

Signed-off-by: Sadam·Sadik <1903249375@qq.com>
  • Loading branch information
Haoke98 committed Aug 25, 2024
1 parent 822a733 commit 2c579fd
Show file tree
Hide file tree
Showing 14 changed files with 47 additions and 215 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -190,3 +190,4 @@ nohup.out
/mini-apps/
backup_*.json
/release/
/service/public/
1 change: 1 addition & 0 deletions build-services-django.sh
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
python service/manage.py collectstatic
pyinstaller service/allkeeper-django.spec --distpath=./dist/services
2 changes: 1 addition & 1 deletion build.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
rm -rf build dist *.egg-info service/build service/dist
find ./ -name '*.DS_Store' -delete
pyinstaller service-webssh/WebSSH.spec --distpath=./dist/services
source build-services-django.sh
pyinstaller service/allkeeper-django.spec --distpath=./dist/services
python setup.py py2app -A
23 changes: 15 additions & 8 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,11 @@ def start_service(namespace: str = "WebSSH_Service", command: list = None):
def check_django_status(target: str):
try:
response = requests.get(target)
print("Checking status of Django server...({}) : {}".format(target, response.status_code))
if response.status_code == 200:
return True
except requests.exceptions.ConnectionError:
except requests.exceptions.ConnectionError as e:
print("Checking status of Django server...({}) : {}".format(target, e))
return False
return False

Expand All @@ -62,20 +64,25 @@ def navigate():

def navigate2after_wait(window: webview.Window, url):
start_time = time.time()
while not check_django_status(target=url):
time.sleep(1) # 每隔1秒检查一次
print(f"Loading {url}... ({time.time()-start_time} s)")

print(f"Loading {url} after {time.time()-start_time} seconds.")
while True:
if check_django_status(target=url):
break
else:
time.sleep(1) # 每隔1秒检查一次
tDlt = time.time() - start_time
window.load_html('<h1>Service is dynamically loaded!</h1><h2> loading ..... ({:0.2f} s)'.format(tDlt))
print(f"Loading {url}... ({tDlt} s)")

print(f"Loading {url} after {time.time() - start_time} seconds.")
window.load_url(url)


def on_window_start(window: webview.Window):
port = 8000
start_service(namespace="WebSSH", command=['./services/wssh', f'--port=9080', '--xsrf=False'])
start_service(namespace="Django",
command=['./services/allkeeper-django', 'runserver', f'0.0.0.0:{port}', '--noreload'])
url = f'http://127.0.0.1:{port}/bupt2018213267@Sdm98/'
command=['./services/allkeeper-django', 'runserver', f'127.0.0.1:{port}', '--noreload'])
url = f'http://127.0.0.1:{port}/admin/'
navigate2after_wait(window, url)


Expand Down
4 changes: 1 addition & 3 deletions service/accountSystem/urls.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from django.urls import re_path
from rest_framework.routers import DefaultRouter

from .views import login, getMenuList, DeviceView, DeviceRegionView, HumanViewSet, image, breath
from .views import login, getMenuList, HumanViewSet, image, breath

router = DefaultRouter()
router.register(r'human', viewset=HumanViewSet)
Expand All @@ -13,8 +13,6 @@
# 'get': 'retrieve'
# })
urlpatterns = [
re_path('^device$', DeviceView.as_view()),
re_path('^device/region$', DeviceRegionView.as_view()),
# re_path('^server/(?P<pk>[0-9]+)$', server_detail),
re_path('^login$', login),
re_path('^system/menu$', getMenuList),
Expand Down
1 change: 0 additions & 1 deletion service/accountSystem/views/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
from django.views.decorators.csrf import csrf_exempt

from .auth import login
from .device import DeviceView, DeviceRegionView
from .human import HumanView, HumanViewSet
from .menu import getMenuList

Expand Down
3 changes: 1 addition & 2 deletions service/accountSystem/views/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@

from django.views.decorators.csrf import csrf_exempt

from proj.secret import ADMIN_USERNAME, ADMIN_PASSWORD, JWT_SIGNATURE, JWT_ISSUER
from proj.settings import JWT_EXPIRED_DELTA
from proj.settings import JWT_EXPIRED_DELTA, JWT_SIGNATURE, JWT_ISSUER
from utils.encrypt import md5
from utils.http_helper import RestResponse

Expand Down
130 changes: 0 additions & 130 deletions service/accountSystem/views/device.py

This file was deleted.

10 changes: 4 additions & 6 deletions service/allkeeper-django.spec
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,12 @@ a = Analysis(
datas=[
# 添加 simplepro 的模板路径
(os.path.join(site_packages_path, 'simplepro/templates'), 'simplepro/templates'),
# 添加 simplepro 的静态资源路径
(os.path.join(site_packages_path, 'simplepro/static'), 'simplepro/static'),
# 添加 simpleui 的静态资源路径
(os.path.join(site_packages_path, 'simpleui/static'), 'simpleui/static'),
# 添加 simpleui 的模版路径
(os.path.join(site_packages_path, 'simpleui/templates'), 'simpleui/templates'),
# 添加 项目公用 静态资源
('common-static', 'common-static')
# 添加 项目自定义 的模版路径
('templates', 'templates'),
# 把所有静态资源都重新汇集到静态文件夹里
('public/static', 'public/static')
],
hiddenimports=[
'log_request_id','log_request_id.filters','log_request_id.middleware',
Expand Down
29 changes: 9 additions & 20 deletions service/icloud/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,11 @@
from django.http import HttpResponse, JsonResponse, Http404, HttpResponseRedirect
from django.shortcuts import render
from django.views.decorators.csrf import csrf_exempt
from minio import Minio
from pytz import UTC

from .models import IMedia, LocalMedia
from .serializers import IMediaSerializer, LocalMediaSerializer
from .serializers import LocalMediaSerializer
from .services import update, create_icloud_service, collect
from proj.secret import MINIO_STORAGE_SECRET_KEY, MINIO_STORAGE_ENDPOINT, MINIO_STORAGE_ACCESS_KEY
from proj.settings import MINIO_STORAGE_MEDIA_BUCKET_NAME, MINIO_STORAGE_USE_HTTPS, MINIO_STORAGE_CERT_CHECK

DLT = datetime.timedelta(hours=1)

Expand All @@ -24,15 +21,6 @@
".MOV": "video/quicktime",
}

minio_client = Minio(
endpoint=MINIO_STORAGE_ENDPOINT,
access_key=MINIO_STORAGE_ACCESS_KEY,
secret_key=MINIO_STORAGE_SECRET_KEY,
secure=MINIO_STORAGE_USE_HTTPS, # 根据你的MinIO服务器是否使用HTTPS来设置
cert_check=MINIO_STORAGE_CERT_CHECK
)


def test(request):
"""
OFFSET 结束的位置
Expand Down Expand Up @@ -147,13 +135,14 @@ def preview(request):
except ValueError as e:
if "The 'prv' attribute has no file associated with it." in str(e):
prv_object_name = targetObj.origin.name
download_url = minio_client.presigned_get_object(
bucket_name=MINIO_STORAGE_MEDIA_BUCKET_NAME,
object_name=prv_object_name,
expires=datetime.timedelta(minutes=5)
)
print(f"下载预签名URL: {download_url}")
context["prv_src"] = download_url
# FIXME: 修复这里改成本地缓存缩略图或者预览版内容
# download_url = minio_client.presigned_get_object(
# bucket_name=MINIO_STORAGE_MEDIA_BUCKET_NAME,
# object_name=prv_object_name,
# expires=datetime.timedelta(minutes=5)
# )
# print(f"下载预签名URL: {download_url}")
# context["prv_src"] = download_url
pass
else:
return HttpResponse(f"未知source[{source}]")
Expand Down
2 changes: 1 addition & 1 deletion service/middlewares/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import jwt
from django.utils.deprecation import MiddlewareMixin

from proj.secret import JWT_SIGNATURE
from proj.settings import JWT_SIGNATURE
from utils.http_helper import RestResponse


Expand Down
10 changes: 0 additions & 10 deletions service/proj/__init__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import logging
import os
import platform

from .secret import ES_URI, ES_USERNAME, ES_PASSWORD

_DEBUG = False
_STATIC_URL = '/static/'
Expand All @@ -20,12 +18,4 @@
"""
服务器环境
"""
try:
_DEBUG = secret._DEBUG
except:
pass
logging.info(f"this app is running on {CURRENT_SYSTEM},DEBUG:{_DEBUG}")
from elasticsearch import Elasticsearch

esClient = Elasticsearch(hosts=ES_URI, http_auth=(ES_USERNAME, ES_PASSWORD),
timeout=3600)
Loading

0 comments on commit 2c579fd

Please sign in to comment.