From 5232ba5fe6e4101dc11c3394a2b0c007ed958c82 Mon Sep 17 00:00:00 2001 From: youngS Date: Tue, 2 Nov 2021 15:58:41 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- fir_ser/api/utils/app/iossignapi.py | 32 +++++++++++++++---------- fir_ser/api/utils/app/supersignutils.py | 2 +- fir_ser/api/utils/apple/appleapiv3.py | 2 +- fir_ser/api/utils/modelutils.py | 4 +++- fir_ser/api/views/login.py | 9 ++++--- fir_ser/api/views/receiveudids.py | 3 ++- fir_ser/fir_ser/settings.py | 1 + 7 files changed, 33 insertions(+), 20 deletions(-) diff --git a/fir_ser/api/utils/app/iossignapi.py b/fir_ser/api/utils/app/iossignapi.py index 5cbcab1..2cda2df 100644 --- a/fir_ser/api/utils/app/iossignapi.py +++ b/fir_ser/api/utils/app/iossignapi.py @@ -292,7 +292,7 @@ class AppDeveloperApiV2(object): result['return_info'] = "%s" % e return False, result - def get_profile(self, app_obj, udid_info, provisionName, auth, developer_app_id, + def get_profile(self, app_obj, udid_info, provision_name, auth, developer_app_id, device_id_list, err_callback): result = {} bundle_id = app_obj.bundle_id @@ -304,9 +304,11 @@ class AppDeveloperApiV2(object): pass else: if s_type == 0: - bundle_obj = apple_obj.register_bundle_id(app_id, bundle_id + app_id) + bundle_obj = apple_obj.register_bundle_id(app_id, f"{bundle_id}.{self.issuer_id}.{app_id}") else: - bundle_obj = apple_obj.register_bundle_id_enable_capability(app_id, bundle_id + app_id, s_type) + bundle_obj = apple_obj.register_bundle_id_enable_capability(app_id, + f"{bundle_id}.{self.issuer_id}.{app_id}", + s_type) developer_app_id = bundle_obj.id result['aid'] = developer_app_id if udid_info: @@ -318,13 +320,13 @@ class AppDeveloperApiV2(object): device_id_list.append(device_obj.id) profile_obj = apple_obj.create_profile(developer_app_id, auth.get('cert_id'), - provisionName.split("/")[-1], + provision_name.split("/")[-1], device_id_list) if profile_obj: n = base64.b64decode(profile_obj.profileContent) - if not os.path.isdir(os.path.dirname(provisionName)): - os.makedirs(os.path.dirname(provisionName)) - with open(provisionName, 'wb') as f: + if not os.path.isdir(os.path.dirname(provision_name)): + os.makedirs(os.path.dirname(provision_name)) + with open(provision_name, 'wb') as f: f.write(n) return True, result except Exception as e: @@ -376,11 +378,11 @@ class AppDeveloperApiV2(object): result['return_info'] = "%s" % e return False, result - def del_app(self, bundleId, app_id): + def del_app(self, bundle_id, app_id): result = {} try: apple_obj = AppStoreConnectApi(self.issuer_id, self.private_key_id, self.p8key) - if apple_obj.delete_bundle_by_identifier(bundleId + app_id): + if apple_obj.delete_bundle_by_identifier(f"{bundle_id}.{self.issuer_id}.{app_id}"): return True, {} except Exception as e: @@ -389,11 +391,13 @@ class AppDeveloperApiV2(object): return False, result # 该方法未使用 - def create_app(self, bundleId, app_id, s_type): + def create_app(self, bundle_id, app_id, s_type): result = {} try: apple_obj = AppStoreConnectApi(self.issuer_id, self.private_key_id, self.p8key) - bundle_obj = apple_obj.register_bundle_id_enable_capability(app_id, bundleId + app_id, s_type) + bundle_obj = apple_obj.register_bundle_id_enable_capability(app_id, + f"{bundle_id}.{self.issuer_id}.{app_id}", + s_type) developer_app_id = bundle_obj.id result['aid'] = developer_app_id return True, result @@ -417,9 +421,11 @@ class AppDeveloperApiV2(object): result['code'] = apple_obj.enable_capability_by_s_type(developer_app_id, s_type) else: if s_type == 0: - bundle_obj = apple_obj.register_bundle_id(app_id, bundle_id + app_id) + bundle_obj = apple_obj.register_bundle_id(app_id, f"{bundle_id}.{self.issuer_id}.{app_id}") else: - bundle_obj = apple_obj.register_bundle_id_enable_capability(app_id, bundle_id + app_id, s_type) + bundle_obj = apple_obj.register_bundle_id_enable_capability(app_id, + f"{bundle_id}.{self.issuer_id}.{app_id}", + s_type) developer_app_id = bundle_obj.id result['aid'] = developer_app_id return True, result diff --git a/fir_ser/api/utils/app/supersignutils.py b/fir_ser/api/utils/app/supersignutils.py index def04c8..50a165f 100644 --- a/fir_ser/api/utils/app/supersignutils.py +++ b/fir_ser/api/utils/app/supersignutils.py @@ -579,7 +579,7 @@ class IosUtils(object): else: with cache.lock("%s_%s_%s" % ( 'download_profile_and_add_device', self.developer_obj.issuer_id, self.udid), - timeout=60): + timeout=120): download_flag, result = IosUtils.exec_download_profile(self.app_obj, self.developer_obj, self.udid_info, sign_try_attempts) if download_flag: diff --git a/fir_ser/api/utils/apple/appleapiv3.py b/fir_ser/api/utils/apple/appleapiv3.py index 5c44c3f..6f906be 100644 --- a/fir_ser/api/utils/apple/appleapiv3.py +++ b/fir_ser/api/utils/apple/appleapiv3.py @@ -772,7 +772,7 @@ class AppStoreConnectApi(DevicesAPI, BundleIDsAPI, BundleIDsCapabilityAPI, Profi device_obj_list = BaseInfoObj.filter(self.get_all_devices(), {"udid": udid}) if not device_obj_list: raise Exception('Device obj is None') - if len(device_obj_list) != 1 and len(set([device_obj.udid for device_obj in device_obj_list])) == 1: + if len(device_obj_list) != 1 and len(set([device_obj.udid for device_obj in device_obj_list])) != 1: raise Exception('more than one Device obj') return device_obj_list diff --git a/fir_ser/api/utils/modelutils.py b/fir_ser/api/utils/modelutils.py index 5188b5e..9f5a922 100644 --- a/fir_ser/api/utils/modelutils.py +++ b/fir_ser/api/utils/modelutils.py @@ -77,13 +77,15 @@ def ad_random_weight(user_obj): def add_remote_info_from_request(request, description): meta_info = request.META + if request.user and request.user.id is not None: + description = f"{request.user.uid}_{description}" remote_info = { 'user_agent': meta_info.get('HTTP_USER_AGENT'), 'remote_addr': get_real_ip_address(request), 'method': meta_info.get('REQUEST_METHOD'), 'uri_info': urljoin(meta_info.get('PATH_INFO'), meta_info.get('QUERY_STRING')), 'a_domain': get_origin_domain_name(request), - 'description': description + 'description': description[0:255] } RemoteClientInfo.objects.create(**remote_info) diff --git a/fir_ser/api/views/login.py b/fir_ser/api/views/login.py index 3d3bdde..ea66811 100644 --- a/fir_ser/api/views/login.py +++ b/fir_ser/api/views/login.py @@ -9,7 +9,7 @@ from api.models import Token, UserInfo, UserCertificationInfo, CertificationInfo from api.utils.auth import ExpiringTokenAuthentication from api.utils.baseutils import is_valid_phone, is_valid_email, get_real_ip_address from api.utils.geetest.geetest_utils import first_register, second_validate -from api.utils.modelutils import get_min_default_domain_cname_obj +from api.utils.modelutils import get_min_default_domain_cname_obj, add_remote_info_from_request from api.utils.mp.wechat import make_wx_login_qrcode, show_qrcode_url from api.utils.response import BaseResponse from api.utils.serializer import UserInfoSerializer, CertificationSerializer, UserCertificationSerializer @@ -256,6 +256,8 @@ class LoginView(APIView): if a and b: reset_user_pwd(user_obj, password) login_auth_failed("del", username) + msg = f'{user_obj} 找回密码成功,您的新密码为 {password} 请用新密码登录之后,及时修改密码' + add_remote_info_from_request(request, msg) logger.warning(f'{user_obj} 找回密码成功,您的新密码为 {password} 请用新密码登录之后,及时修改密码') else: response.code = 1007 @@ -289,6 +291,7 @@ class LoginView(APIView): response.msg = "验证成功!" response.userinfo = data response.token = key + add_remote_info_from_request(request, f"登录成功, token: {key}") else: response.msg = "用户被禁用" response.code = 1005 @@ -309,7 +312,7 @@ class LoginView(APIView): else: response.code = 1001 response.msg = "验证码有误" - + add_remote_info_from_request(request, response.msg) return Response(response.dict) def get(self, request): @@ -404,7 +407,7 @@ class RegistView(APIView): else: response.code = 1001 response.msg = "邮件或短信验证码有误" - + add_remote_info_from_request(request, response.msg) return Response(response.dict) def get(self, request): diff --git a/fir_ser/api/views/receiveudids.py b/fir_ser/api/views/receiveudids.py index 4e44da7..91333f4 100644 --- a/fir_ser/api/views/receiveudids.py +++ b/fir_ser/api/views/receiveudids.py @@ -15,7 +15,7 @@ from api.models import Apps from api.tasks import run_sign_task from api.utils.app.supersignutils import udid_bytes_to_dict, make_sign_udid_mobile_config from api.utils.baseutils import get_real_ip_address, get_http_server_domain, make_random_uuid -from api.utils.modelutils import get_app_domain_name, get_redirect_server_domain +from api.utils.modelutils import get_app_domain_name, get_redirect_server_domain, add_remote_info_from_request from api.utils.response import BaseResponse from api.utils.storage.caches import check_app_permission from api.utils.throttle import ReceiveUdidThrottle1, ReceiveUdidThrottle2 @@ -48,6 +48,7 @@ class IosUDIDView(View): # ios_obj.sign(client_ip) # return Response('ok') c_task = run_sign_task.apply_async((format_udid_info, short, client_ip)) + add_remote_info_from_request(request, f'{app_obj}-{format_udid_info}') task_id = c_task.id logger.info(f"sign app {app_obj} task_id:{task_id}") try: diff --git a/fir_ser/fir_ser/settings.py b/fir_ser/fir_ser/settings.py index de88024..b943b2e 100644 --- a/fir_ser/fir_ser/settings.py +++ b/fir_ser/fir_ser/settings.py @@ -11,6 +11,7 @@ https://docs.djangoproject.com/en/3.0/ref/settings/ """ import os + from config import * # Build paths inside the project like this: os.path.join(BASE_DIR, ...)