diff --git a/fir_ser/api/management/commands/services/command.py b/fir_ser/api/management/commands/services/command.py index 2dd5c8c..aeac4c9 100644 --- a/fir_ser/api/management/commands/services/command.py +++ b/fir_ser/api/management/commands/services/command.py @@ -114,7 +114,7 @@ class BaseActionCommand(BaseCommand): 'uwsgi_threads': options.get('uwsgi_threads'), 'uwsgi_socket_mode': options.get('uwsgi_socket_mode'), 'uid': options.get('uid'), - 'gid': options.get('gid'), + 'gid': options.get('uid') if options.get('gid') in ['root'] else options.get('gid'), } services = Services.get_service_objects(service_names=service_names, **service_kwargs) diff --git a/fir_ser/api/management/commands/services/hands.py b/fir_ser/api/management/commands/services/hands.py index 4611099..288c47a 100644 --- a/fir_ser/api/management/commands/services/hands.py +++ b/fir_ser/api/management/commands/services/hands.py @@ -2,13 +2,14 @@ import os import sys import logging from django.conf import settings +from config import BASE_DIR +import time +import subprocess from config import BASECONF try: - from apps.jumpserver import const - - __version__ = const.VERSION + __version__ = BASECONF.VERSION except ImportError as e: print("Not found __version__: {}".format(e)) print("Python is: ") @@ -26,3 +27,41 @@ BASE_DIR = settings.BASE_DIR APPS_DIR = BASE_DIR LOG_DIR = os.path.join(BASE_DIR, 'logs') TMP_DIR = os.path.join(BASE_DIR, 'tmp') + + +def check_database_connection(): + os.chdir(BASE_DIR) + for i in range(60): + logging.info("Check database connection ...") + _code = subprocess.call("python manage.py showmigrations api ", shell=True) + if _code == 0: + logging.info("Database connect success") + return + time.sleep(1) + logging.error("Connection database failed, exit") + sys.exit(10) + + +def check_migrations(): + _cmd = "python manage.py showmigrations | grep '\[.\]' | grep -v '\[X\]'" + _code = subprocess.call(_cmd, shell=True, cwd=BASE_DIR) + + if _code == 1: + return + + +def perform_db_migrate(): + logging.info("Check database structure change ...") + os.chdir(BASE_DIR) + logging.info("Migrate model change to database ...") + _code = subprocess.call('python3 manage.py migrate', shell=True) + if _code == 0: + return + logging.error('Perform migrate failed, exit') + sys.exit(11) + + +def prepare(): + check_database_connection() + check_migrations() + perform_db_migrate() diff --git a/fir_ser/api/management/commands/services/services/base.py b/fir_ser/api/management/commands/services/services/base.py index 526231f..850f921 100644 --- a/fir_ser/api/management/commands/services/services/base.py +++ b/fir_ser/api/management/commands/services/services/base.py @@ -1,10 +1,8 @@ import abc -import time import shutil import psutil import datetime import threading -import subprocess import pwd from ..hands import * @@ -123,6 +121,8 @@ class BaseService(object): # -- action -- def open_subprocess(self): self.set_work_dir_owner() + if self.name in ['uwsgi']: + prepare() kwargs = {'cwd': self.cwd, 'stderr': self.log_file, 'stdout': self.log_file} self._process = subprocess.Popen(self.cmd, **kwargs) @@ -142,7 +142,7 @@ class BaseService(object): uid = get_user_id(self.uid) gid = get_user_id(self.gid) u_gid = uid if uid else gid - if u_gid: + if u_gid is not None: for (dir_path, dir_names, filenames) in os.walk(LOG_DIR): for filename in filenames + dir_names: os.chown(uid=u_gid, gid=u_gid, path=os.path.join(dir_path, filename)) diff --git a/fir_ser/api/management/commands/upgrade.py b/fir_ser/api/management/commands/upgrade.py new file mode 100644 index 0000000..650b889 --- /dev/null +++ b/fir_ser/api/management/commands/upgrade.py @@ -0,0 +1,10 @@ +from django.core.management.base import BaseCommand + +from api.management.commands.services.hands import perform_db_migrate + + +class Command(BaseCommand): + help = 'upgrade database' + + def handle(self, *args, **options): + perform_db_migrate() diff --git a/fir_ser/api/tasks.py b/fir_ser/api/tasks.py index 41ab9b3..5be16a6 100644 --- a/fir_ser/api/tasks.py +++ b/fir_ser/api/tasks.py @@ -18,6 +18,7 @@ from api.utils.geetest.geetest_utils import check_bypass_status from api.views.login import get_login_type from fir_ser.celery import app +from fir_ser.settings import LOGIN, CHANGER, REGISTER @shared_task @@ -66,7 +67,8 @@ def sync_download_times_job(): @app.task def check_bypass_status_job(): - check_bypass_status() + if LOGIN.get("geetest") or CHANGER.get('geetest') or REGISTER.get('geetest'): + check_bypass_status() @app.task diff --git a/fir_ser/api/utils/app/supersignutils.py b/fir_ser/api/utils/app/supersignutils.py index 31b744e..87e279b 100644 --- a/fir_ser/api/utils/app/supersignutils.py +++ b/fir_ser/api/utils/app/supersignutils.py @@ -8,7 +8,7 @@ import uuid, xmltodict, os, logging, time import zipfile from api.utils.response import BaseResponse -from fir_ser.settings import SUPER_SIGN_ROOT, MEDIA_ROOT, SERVER_DOMAIN, MOBILECONFIG_SIGN_SSL, MSGTEMPLATE +from fir_ser.settings import SUPER_SIGN_ROOT, MEDIA_ROOT, SERVER_DOMAIN, MOBILE_CONFIG_SIGN_SSL, MSGTEMPLATE from api.utils.app.iossignapi import ResignApp, AppDeveloperApiV2 from api.models import APPSuperSignUsedInfo, AppUDID, AppIOSDeveloperInfo, AppReleaseInfo, Apps, APPToDeveloper, \ UDIDsyncDeveloper, DeveloperAppID, DeveloperDevicesID @@ -82,9 +82,9 @@ def udid_bytes_to_dict(xml_stream): def make_sign_udid_mobile_config(udid_url, app_id, bundle_id, app_name): - if MOBILECONFIG_SIGN_SSL.get("open"): - ssl_key_path = MOBILECONFIG_SIGN_SSL.get("ssl_key_path", None) - ssl_pem_path = MOBILECONFIG_SIGN_SSL.get("ssl_pem_path", None) + if MOBILE_CONFIG_SIGN_SSL.get("open"): + ssl_key_path = MOBILE_CONFIG_SIGN_SSL.get("ssl_key_path", None) + ssl_pem_path = MOBILE_CONFIG_SIGN_SSL.get("ssl_pem_path", None) if ssl_key_path and ssl_pem_path and os.path.isfile(ssl_key_path) and os.path.isfile(ssl_pem_path): mobile_config_tmp_dir = os.path.join(SUPER_SIGN_ROOT, 'tmp', 'mobile_config') diff --git a/fir_ser/api/utils/response.py b/fir_ser/api/utils/response.py index 0b832ae..e971676 100644 --- a/fir_ser/api/utils/response.py +++ b/fir_ser/api/utils/response.py @@ -1,3 +1,10 @@ +#!/usr/bin/env python +# -*- coding:utf-8 -*- +# project: 4月 +# author: NinEveN +# date: 2021/4/16 + + class BaseResponse(object): def __init__(self): self.code = 1000 diff --git a/fir_ser/config.py b/fir_ser/config.py index e6bd355..fc40d84 100644 --- a/fir_ser/config.py +++ b/fir_ser/config.py @@ -12,6 +12,8 @@ BASE_DIR = os.path.dirname(os.path.abspath(__file__)) class BASECONF(object): + VERSION = '1.3.1' + DEBUG = True SECRET_KEY = 'j!g@^bc(z(a3*i&kp$_@bgb)bug&^#3=amch!3lz&1x&s6ss6t' @@ -121,7 +123,7 @@ class AUTHCONF(object): 'email': True, # 邮件登录 'up': False, # 密码登录 'third': { - 'wxp': False # 微信公众号登录,需要在 THIRDLOGINCONF 配置好微信公众号登录 + 'wxp': THIRDLOGINCONF.wx_official.get('active') # 微信公众号登录,需要在 THIRDLOGINCONF 配置好微信公众号登录 }, } } @@ -233,7 +235,7 @@ class SENDERCONF(object): class IPACONF(object): - MOBILECONFIG_SIGN_SSL = { + MOBILE_CONFIG_SIGN_SSL = { # 描述文件是否签名,默认是关闭状态;如果开启,并且ssl_key_path 和 ssl_pem_path 正常,则使用填写的ssl进行签名,否则默认不签名 'open': True, 'ssl_key_path': '/data/cert/%s.key' % API_DOMAIN.split("://")[1], diff --git a/fir_ser/fir_ser/settings.py b/fir_ser/fir_ser/settings.py index 92135da..03aa2b2 100644 --- a/fir_ser/fir_ser/settings.py +++ b/fir_ser/fir_ser/settings.py @@ -232,7 +232,7 @@ SYNC_CACHE_TO_DATABASE = { SERVER_DOMAIN = BASECONF.SERVER_DOMAIN -MOBILECONFIG_SIGN_SSL = IPACONF.MOBILECONFIG_SIGN_SSL +MOBILE_CONFIG_SIGN_SSL = IPACONF.MOBILE_CONFIG_SIGN_SSL DEFAULT_MOBILEPROVISION = IPACONF.DEFAULT_MOBILEPROVISION # DEFAULT_MOBILEPROVISION = { @@ -399,12 +399,12 @@ CELERY_BEAT_SCHEDULE = { 'schedule': SYNC_CACHE_TO_DATABASE.get("auto_check_ios_developer_active_times"), 'args': () }, - 'start_api_sever_do_clean': { - 'task': 'api.tasks.start_api_sever_do_clean', - 'schedule': 6, - 'args': (), - 'one_off': True - }, + # 'start_api_sever_do_clean': { + # 'task': 'api.tasks.start_api_sever_do_clean', + # 'schedule': 6, + # 'args': (), + # 'one_off': True + # }, 'sync_wx_access_token_job': { 'task': 'api.tasks.sync_wx_access_token_job', 'schedule': SYNC_CACHE_TO_DATABASE.get("wx_get_access_token_times"),