diff --git a/.gitignore b/.gitignore index b32c80b..417f475 100644 --- a/.gitignore +++ b/.gitignore @@ -190,3 +190,4 @@ nohup.out /mini-apps/ backup_*.json /release/ +/service/public/ diff --git a/build-services-django.sh b/build-services-django.sh index ca76c56..4abcc98 100644 --- a/build-services-django.sh +++ b/build-services-django.sh @@ -1 +1,2 @@ +python service/manage.py collectstatic pyinstaller service/allkeeper-django.spec --distpath=./dist/services \ No newline at end of file diff --git a/build.sh b/build.sh index cdf90e1..4af6db7 100644 --- a/build.sh +++ b/build.sh @@ -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 \ No newline at end of file diff --git a/main.py b/main.py index aed5901..3610a1c 100644 --- a/main.py +++ b/main.py @@ -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 @@ -62,11 +64,16 @@ 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('

Service is dynamically loaded!

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) @@ -74,8 +81,8 @@ 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) diff --git a/service/accountSystem/urls.py b/service/accountSystem/urls.py index cc634e6..f008b37 100644 --- a/service/accountSystem/urls.py +++ b/service/accountSystem/urls.py @@ -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) @@ -13,8 +13,6 @@ # 'get': 'retrieve' # }) urlpatterns = [ - re_path('^device$', DeviceView.as_view()), - re_path('^device/region$', DeviceRegionView.as_view()), # re_path('^server/(?P[0-9]+)$', server_detail), re_path('^login$', login), re_path('^system/menu$', getMenuList), diff --git a/service/accountSystem/views/__init__.py b/service/accountSystem/views/__init__.py index afb94f8..121e0bc 100644 --- a/service/accountSystem/views/__init__.py +++ b/service/accountSystem/views/__init__.py @@ -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 diff --git a/service/accountSystem/views/auth.py b/service/accountSystem/views/auth.py index 915d46e..f2de76c 100644 --- a/service/accountSystem/views/auth.py +++ b/service/accountSystem/views/auth.py @@ -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 diff --git a/service/accountSystem/views/device.py b/service/accountSystem/views/device.py deleted file mode 100644 index 1cc459b..0000000 --- a/service/accountSystem/views/device.py +++ /dev/null @@ -1,130 +0,0 @@ -# _*_ codign:utf8 _*_ -"""==================================== -@Author:Sadam·Sadik -@Email:1903249375@qq.com -@Date:2022/7/28 -@Software: PyCharm -@disc: -=======================================""" -import json - -from django.http import HttpResponse -from rest_framework import views - -from proj import esClient - -INDEX_DEVICES = "devices" - - -class DeviceRegionView(views.View): - def get(self, request): - result = [] - resp = esClient.search(index=INDEX_DEVICES, size=0, aggs={ - "country": { - "terms": { - "field": "geoinfo.country.code.keyword", - "size": 1000 - } - } - }) - countryBuckets: list[dict] = resp.get("aggregations").get("country").get("buckets") - for countryBucket in countryBuckets: - countryCode = countryBucket.get("key") - resp1 = esClient.search(index=INDEX_DEVICES, size=1, query={ - "term": { - "geoinfo.country.code.keyword": { - "value": countryCode - } - } - }, aggs={ - "subDivisions": { - "terms": { - "field": "geoinfo.subdivisions.names.en.keyword", - "size": 2000 - } - } - }) - country: dict = resp1.get("hits").get("hits")[0].get("_source").get("geoinfo").get("country") - country.setdefault("doc_count", countryBucket.get("doc_count")) - subDivisions: list[dict] = [] - subDivisionBuckets: list[dict] = resp1.get("aggregations").get("subDivisions").get("buckets") - for subDivisionBucket in subDivisionBuckets: - subDivisionNameEn = subDivisionBucket.get("key") - if subDivisionNameEn == "": - continue - resp2 = esClient.search(index=INDEX_DEVICES, size=1, query={ - "bool": { - "must": [ - { - "term": { - "geoinfo.country.code.keyword": { - "value": countryCode - } - } - }, - { - "term": { - "geoinfo.subdivisions.names.en.keyword": { - "value": subDivisionNameEn - } - } - } - ] - } - }, aggs={ - "city": { - "terms": { - "field": "geoinfo.city.names.en.keyword", - "size": 2000 - } - } - }) - subDivision: dict = resp2.get("hits").get("hits")[0].get("_source").get("geoinfo").get("subdivisions") - subDivision.setdefault("doc_count", subDivisionBucket.get("doc_count")) - # TODO:统计城市City的数量 - cities: list[dict] = [] - cityBuckets: list[dict] = resp2.get("aggregations").get("city").get("buckets") - for cityBucket in cityBuckets: - cityNameEn = cityBucket.get("key") - if cityNameEn == "": - continue - resp3 = esClient.search(index=INDEX_DEVICES, size=1, query={ - "bool": { - "must": [ - { - "term": { - "geoinfo.country.code.keyword": { - "value": countryCode - } - } - }, - { - "term": { - "geoinfo.subdivisions.names.en.keyword": { - "value": subDivisionNameEn - } - } - }, { - "term": { - "geoinfo.city.names.en.keyword": { - "value": cityNameEn - } - } - } - ] - } - }) - city: dict = resp3.get("hits").get("hits")[0].get("_source").get("geoinfo").get("city") - city.setdefault("doc_count", cityBucket.get("doc_count")) - cities.append(city) - subDivision.setdefault("children", cities) - subDivisions.append(subDivision) - country.setdefault("children", subDivisions) - result.append(country) - return HttpResponse(json.dumps(result, ensure_ascii=False), headers={"content-type": "application/json"}) - - -class DeviceView(views.View): - def get(self, request): - resp = esClient.search(index=INDEX_DEVICES) - return HttpResponse(json.dumps(resp, ensure_ascii=False), headers={"content-type": "application/json"}) diff --git a/service/allkeeper-django.spec b/service/allkeeper-django.spec index 1c9bb32..482d7da 100644 --- a/service/allkeeper-django.spec +++ b/service/allkeeper-django.spec @@ -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', diff --git a/service/icloud/views.py b/service/icloud/views.py index dff827b..8e54cf1 100644 --- a/service/icloud/views.py +++ b/service/icloud/views.py @@ -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) @@ -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 结束的位置 @@ -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}]") diff --git a/service/middlewares/auth.py b/service/middlewares/auth.py index c463e57..26436c1 100644 --- a/service/middlewares/auth.py +++ b/service/middlewares/auth.py @@ -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 diff --git a/service/proj/__init__.py b/service/proj/__init__.py index 437bcf2..f183d0e 100644 --- a/service/proj/__init__.py +++ b/service/proj/__init__.py @@ -1,8 +1,6 @@ import logging -import os import platform -from .secret import ES_URI, ES_USERNAME, ES_PASSWORD _DEBUG = False _STATIC_URL = '/static/' @@ -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) diff --git a/service/proj/settings.py b/service/proj/settings.py index 3944fee..bb00842 100644 --- a/service/proj/settings.py +++ b/service/proj/settings.py @@ -13,14 +13,16 @@ import logging import mimetypes import os -import platform from pathlib import Path -from . import secret -from .secret import MEDIA_ROOT, CSRF_TRUSTED_ORIGINS, MINIO_STORAGE_ENDPOINT, MINIO_STORAGE_ACCESS_KEY, \ - MINIO_STORAGE_SECRET_KEY +from . import _STATIC_URL from .simpleUISettings import * +# FIXME : 改成第一次安装时自动生成并保存到用户目录下 +SECRET_KEY = 's3va_7)a.2k3jsk0ks24,d4-w!l9&v&m#9-(9xduye*@p=' +JWT_SIGNATURE = SECRET_KEY +JWT_ISSUER = "Sadam·Sadik" + SECURE_CROSS_ORIGIN_OPENER_POLICY = 'none' # Build paths inside the project like this: os.path.join(BASE_DIR, ...) BASE_DIR = Path(__file__).resolve().parent.parent @@ -29,6 +31,10 @@ if not os.path.isdir(APP_HOME_DIR): os.mkdir(APP_HOME_DIR) +MEDIA_ROOT = os.path.join(APP_HOME_DIR, 'media') +if not os.path.isdir(MEDIA_ROOT): + os.mkdir(MEDIA_ROOT) + LOG_FILE_DIR = os.path.join(APP_HOME_DIR, 'logs') if not os.path.exists(LOG_FILE_DIR): os.mkdir(LOG_FILE_DIR) @@ -38,8 +44,6 @@ if not os.path.exists(PUBLIC_ROOT): os.mkdir(PUBLIC_ROOT) -from . import _STATIC_URL - STATIC_URL = _STATIC_URL logging.info(f"STATIC_URL:{STATIC_URL}") ADMIN_MEDIA_PREFIX = STATIC_URL + 'admin/' @@ -70,28 +74,17 @@ # See https://docs.djangoproject.com/en/2.2/howto/deployment/checklist/ # SECURITY WARNING: keep the secret key used in production secret! -SECRET_KEY = secret.SECRET_KEY +SECRET_KEY = SECRET_KEY os.environ['NLS_LANG'] = 'SIMPLIFIED CHINESE_CHINA.UTF8' # SECURITY WARNING: don't run with debug turned on in production! -from . import _DEBUG -DEBUG = _DEBUG +DEBUG = False ALLOWED_HOSTS = ['*'] APPEND_SLASH = True -ADMINS = (('Sadam·Sadik', '1903249375@qq.com'),) # 接受报错的账号 -EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend' -EMAIL_USE_SSL = True -EMAIL_HOST = 'smtp.qq.com' # 如果是 163 改成 smtp.163.com -EMAIL_PORT = 465 -EMAIL_HOST_USER = secret.SMTP_EMAIL # 帐号 -EMAIL_HOST_PASSWORD = secret.SMTP_PASSWORD # 密码(用第三方平台登陆授权码) -SERVER_EMAIL = EMAIL_HOST_USER # 必须要设置 不然logger中得handler:admin_Email 无法发送错误报告邮件, SERVER_EMAIL必须和 EMAIL_HOST_USER一样才能成功发送 -DEFAULT_FROM_EMAIL = f'SadamSadik <{secret.SMTP_EMAIL}>' - LOG_REQUEST_ID_HEADER = "HTTP_X_REQUEST_ID" GENERATE_REQUEST_ID_IF_NOT_IN_HEADER = True REQUEST_ID_RESPONSE_HEADER = "RESPONSE_HEADER_NAME" @@ -249,17 +242,6 @@ 'default': { 'ENGINE': 'django.db.backends.sqlite3', 'NAME': os.path.join(APP_HOME_DIR, 'database.db'), - }, - 'remote': { - 'ENGINE': secret.DB_BACKEND, - 'NAME': secret.DB_DATABASE, - 'HOST': secret.DB_HOST, - 'PORT': secret.DB_PORT, - 'USER': secret.DB_USERNAME, - 'PASSWORD': secret.DB_PASSWORD, - 'CONN_MAX_AGE': 0, - 'OPTIONS': { - }, } } @@ -274,7 +256,6 @@ 'accountSystem': 'default', 'DebtManagerSystem': 'default', 'icloud': 'default', - 'logAnalyser': 'default', 'jumpService': 'default' } # Password validation diff --git a/service/proj/urls.py b/service/proj/urls.py index e436955..a3fc7f8 100644 --- a/service/proj/urls.py +++ b/service/proj/urls.py @@ -25,7 +25,6 @@ from proj import settings from . import _STATIC_URL -from .secret import ADMIN_PATH from .view import media # 网站标签页名称 @@ -36,7 +35,7 @@ admin.autodiscover() urlpatterns = [ re_path(r'^media/(?P.*)$', media), - path(f"{ADMIN_PATH}/", admin.site.urls), + path(f"admin/", admin.site.urls), path('admin/doc/', include('django.contrib.admindocs.urls')), path('sitemap.xml', sitemap, {'sitemaps': sitemaps}, name='django.contrib.sitemaps.views.sitemap'), re_path('^all-keeper/', include(accountSystem.urls)),