From 47861511fc497f07b4a8009b4db4d1e8a7f1ce27 Mon Sep 17 00:00:00 2001 From: youngS Date: Sun, 31 Oct 2021 11:39:00 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=8D=95=E7=94=A8=E6=88=B7?= =?UTF-8?q?=E7=AD=BE=E5=90=8D=E6=B5=81=E7=A8=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/components/user/FirSuperSignBase.vue | 25 ++-- fir_ser/api/utils/app/supersignutils.py | 60 ++++++---- fir_ser/api/utils/apple/appleapiv3.py | 22 ++-- fir_ser/api/utils/serializer.py | 2 +- fir_ser/api/utils/utils.py | 3 +- fir_ser/api/views/receiveudids.py | 18 +-- fir_ser/api/views/supersign.py | 9 +- fir_ser/tests/postudid.py | 111 ++++++++++-------- 8 files changed, 150 insertions(+), 100 deletions(-) diff --git a/fir_client/src/components/user/FirSuperSignBase.vue b/fir_client/src/components/user/FirSuperSignBase.vue index 6fc9599..9d0578f 100644 --- a/fir_client/src/components/user/FirSuperSignBase.vue +++ b/fir_client/src/components/user/FirSuperSignBase.vue @@ -63,6 +63,10 @@ 导入p12证书 + 清理签名数据 + 同步设备信息 @@ -74,11 +78,12 @@ 删除发布证书 - 开发者账户激活检测 + 账户激活检测 保存 @@ -558,7 +563,7 @@ } }, udidDeleteFun(scope) { - this.iosdevicesudidFun('DELETE', {id: scope.row.id, aid: scope.row.app_id},scope); + this.iosdevicesudidFun('DELETE', {id: scope.row.id, aid: scope.row.app_id}, scope); }, handleSizeChange(val) { this.pagination.pagesize = val; @@ -580,6 +585,12 @@ "data": {"issuer_id": this.editdeveloperinfo.issuer_id, "act": "syncdevice"} }); }, + cleandevices() { + this.iosdeveloperFun({ + "methods": "PUT", + "data": {"issuer_id": this.editdeveloperinfo.issuer_id, "act": "cleandevice"} + }); + }, isocertcert() { this.$confirm('此操作将要创建新的发布证书, 是否继续?', '提示', { @@ -785,13 +796,13 @@ if (action !== "DELETE") { this.app_udid_lists = data.data; this.pagination.total = data.count; - }else { - if(scope){ + } else { + if (scope) { this.app_udid_lists = removeAaary(this.app_udid_lists, scope.row) } } - }else { - this.$message.error("操作失败了 "+data.msg); + } else { + this.$message.error("操作失败了 " + data.msg); } if (action !== 'GET') { this.loadingfun.close() diff --git a/fir_ser/api/utils/app/supersignutils.py b/fir_ser/api/utils/app/supersignutils.py index a8e5cb8..def04c8 100644 --- a/fir_ser/api/utils/app/supersignutils.py +++ b/fir_ser/api/utils/app/supersignutils.py @@ -569,8 +569,19 @@ class IosUtils(object): if self.developer_obj: with cache.lock("%s_%s_%s" % ('download_profile', self.app_obj.app_id, self.developer_obj.issuer_id), timeout=180): - download_flag, result = IosUtils.exec_download_profile(self.app_obj, self.developer_obj, - self.udid_info, sign_try_attempts) + + sync_device_obj = UDIDsyncDeveloper.objects.filter(udid=self.udid, + developerid=self.developer_obj, + status=True).first() + if sync_device_obj: + download_flag, result = IosUtils.exec_download_profile(self.app_obj, self.developer_obj, + self.udid_info, sign_try_attempts) + else: + with cache.lock("%s_%s_%s" % ( + 'download_profile_and_add_device', self.developer_obj.issuer_id, self.udid), + timeout=60): + download_flag, result = IosUtils.exec_download_profile(self.app_obj, self.developer_obj, + self.udid_info, sign_try_attempts) if download_flag: call_flag = False else: @@ -691,41 +702,44 @@ class IosUtils(object): delete_app_profile_file(developer_obj, app_obj) @staticmethod - def clean_app_by_developer_obj(app_obj, developer_obj, cert_id=None): + def clean_app_by_developer_obj(app_obj, developer_obj): auth = get_auth_form_developer(developer_obj) DeveloperAppID.objects.filter(developerid=developer_obj, app_id=app_obj).delete() app_api_obj = get_api_obj(auth) app_api_obj.del_profile(app_obj.app_id) - if not cert_id: - app_api_obj2 = get_api_obj(auth) - app_api_obj2.del_app(app_obj.bundle_id, app_obj.app_id) + app_api_obj2 = get_api_obj(auth) + app_api_obj2.del_app(app_obj.bundle_id, app_obj.app_id) @staticmethod - def clean_developer(developer_obj, user_obj, cert_id=None): + def clean_developer(developer_obj, user_obj, delete_file=True): """ 根据消耗记录 删除该苹果账户下所有信息 + :param delete_file: :param user_obj: - :param cert_id: :param developer_obj: :return: """ - for APPToDeveloper_obj in APPToDeveloper.objects.filter(developerid=developer_obj): - app_obj = APPToDeveloper_obj.app_id - IosUtils.clean_app_by_developer_obj(app_obj, developer_obj, cert_id) - delete_app_to_dev_and_file(developer_obj, app_obj.id) - if not cert_id: - IosUtils.clean_udid_by_app_obj(app_obj, developer_obj) - full_path = file_format_path(user_obj, get_auth_form_developer(developer_obj)) try: - # move dirs replace delete - new_full_path_dir = os.path.dirname(full_path) - new_full_path_name = os.path.basename(full_path) - new_full_path = os.path.join(os.path.dirname(new_full_path_dir), - '%s_%s_%s' % ('remove', new_full_path_name, get_format_time())) - os.rename(new_full_path_dir, new_full_path) + for APPToDeveloper_obj in APPToDeveloper.objects.filter(developerid=developer_obj): + app_obj = APPToDeveloper_obj.app_id + IosUtils.clean_app_by_developer_obj(app_obj, developer_obj) + delete_app_to_dev_and_file(developer_obj, app_obj.id) + IosUtils.clean_udid_by_app_obj(app_obj, developer_obj) + if delete_file: + full_path = file_format_path(user_obj, get_auth_form_developer(developer_obj)) + try: + # move dirs replace delete + new_full_path_dir = os.path.dirname(full_path) + new_full_path_name = os.path.basename(full_path) + new_full_path = os.path.join(os.path.dirname(new_full_path_dir), + '%s_%s_%s' % ('remove', new_full_path_name, get_format_time())) + os.rename(new_full_path_dir, new_full_path) + except Exception as e: + logger.error("clean_developer developer_obj:%s user_obj:%s delete file failed Exception:%s" % ( + developer_obj, user_obj, e)) + return True, 'success' except Exception as e: - logger.error("clean_developer developer_obj:%s user_obj:%s delete file failed Exception:%s" % ( - developer_obj, user_obj, e)) + return False, {'err_info': str(e)} @staticmethod def active_developer(developer_obj): diff --git a/fir_ser/api/utils/apple/appleapiv3.py b/fir_ser/api/utils/apple/appleapiv3.py index 33dab48..5c44c3f 100644 --- a/fir_ser/api/utils/apple/appleapiv3.py +++ b/fir_ser/api/utils/apple/appleapiv3.py @@ -772,13 +772,15 @@ 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: + 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[0] + return device_obj_list def register_device(self, device_name, dvice_udid, platform="IOS"): device_obj_list = BaseInfoObj.filter(self.get_all_devices(), {"udid": dvice_udid}) - if device_obj_list and len(device_obj_list) == 1: + # 发现同一个开发者账户里面有两个一样的udid,奇了怪 + if device_obj_list and ( + len(device_obj_list) == 1 or len(set([device_obj.udid for device_obj in device_obj_list])) == 1): device_obj = device_obj_list[0] req = self.modify_registered_device(device_obj.id, device_name, 'ENABLED') return self.__device_store(req) @@ -787,14 +789,16 @@ class AppStoreConnectApi(DevicesAPI, BundleIDsAPI, BundleIDsCapabilityAPI, Profi return self.__device_store(req, 201) def enabled_device(self, udid, **kwargs): - device_obj = self.list_device_by_udid(udid) - req = self.modify_registered_device(device_obj.id, device_obj.name, 'ENABLED') - return self.__device_store(req) + device_obj_list = self.list_device_by_udid(udid) + for device_obj in device_obj_list: + req = self.modify_registered_device(device_obj.id, device_obj.name, 'ENABLED') + return self.__device_store(req) def disabled_device(self, udid, **kwargs): - device_obj = self.list_device_by_udid(udid) - req = self.modify_registered_device(device_obj.id, device_obj.name, 'DISABLED') - return self.__device_store(req) + device_obj_list = self.list_device_by_udid(udid) + for device_obj in device_obj_list: + req = self.modify_registered_device(device_obj.id, device_obj.name, 'DISABLED') + return self.__device_store(req) def list_bundle_ids_by_identifier(self, identifier): req = super().list_bundle_id_by_identifier(identifier) diff --git a/fir_ser/api/utils/serializer.py b/fir_ser/api/utils/serializer.py index 0eacc60..bfad0cb 100644 --- a/fir_ser/api/utils/serializer.py +++ b/fir_ser/api/utils/serializer.py @@ -451,7 +451,7 @@ class DeveloperSerializer(serializers.ModelSerializer): return get_developer_udided(obj)[0] def get_use_number(self, obj): - return models.DeveloperDevicesID.objects.filter(developerid=obj).count() + return models.DeveloperDevicesID.objects.filter(developerid=obj).values('udid').distinct().count() class AdminDeveloperSerializer(DeveloperSerializer): diff --git a/fir_ser/api/utils/utils.py b/fir_ser/api/utils/utils.py index 9188a43..f8d9ae6 100644 --- a/fir_ser/api/utils/utils.py +++ b/fir_ser/api/utils/utils.py @@ -63,7 +63,8 @@ def get_developer_devices(developer_obj_lists): all_usable_number = 0 for use_number_obj in use_number_obj_list: all_usable_number += use_number_obj.usable_number - all_use_number += DeveloperDevicesID.objects.filter(developerid=use_number_obj).count() + all_use_number += DeveloperDevicesID.objects.filter(developerid=use_number_obj).values( + 'udid').distinct().count() use_num = { "all_usable_number": all_usable_number, "all_use_number": all_use_number, diff --git a/fir_ser/api/views/receiveudids.py b/fir_ser/api/views/receiveudids.py index 5e08fc7..4e44da7 100644 --- a/fir_ser/api/views/receiveudids.py +++ b/fir_ser/api/views/receiveudids.py @@ -33,19 +33,23 @@ class IosUDIDView(View): logger.info(f"short {short} receive new udid {format_udid_info}") server_domain = get_redirect_server_domain(request) try: - app_info = Apps.objects.filter(short=short).first() - if app_info: - server_domain = get_redirect_server_domain(request, app_info.user_id, get_app_domain_name(app_info)) - if app_info.issupersign and app_info.user_id.supersign_active: - res = check_app_permission(app_info, BaseResponse()) + app_obj = Apps.objects.filter(short=short).first() + if app_obj: + server_domain = get_redirect_server_domain(request, app_obj.user_id, get_app_domain_name(app_obj)) + if app_obj.issupersign and app_obj.user_id.supersign_active: + res = check_app_permission(app_obj, BaseResponse()) if res.code != 1000: msg = "&msg=%s" % res.msg else: client_ip = get_real_ip_address(request) - logger.info(f"client_ip {client_ip} short {short} app_info {app_info}") + logger.info(f"client_ip {client_ip} short {short} app_info {app_obj}") + + # ios_obj = IosUtils(format_udid_info, app_obj.user_id, app_obj) + # ios_obj.sign(client_ip) + # return Response('ok') c_task = run_sign_task.apply_async((format_udid_info, short, client_ip)) task_id = c_task.id - logger.info(f"sign app {app_info} task_id:{task_id}") + logger.info(f"sign app {app_obj} task_id:{task_id}") try: result = c_task.get(propagate=False, timeout=2) except TimeoutError: diff --git a/fir_ser/api/views/supersign.py b/fir_ser/api/views/supersign.py index 9b1f22b..37e11c3 100644 --- a/fir_ser/api/views/supersign.py +++ b/fir_ser/api/views/supersign.py @@ -110,6 +110,13 @@ class DeveloperView(APIView): res.code = 1008 res.msg = result.get("err_info") return Response(res.dict) + + elif act == "cleandevice": + status, result = IosUtils.clean_developer(developer_obj, request.user, False) + if not status: + res.code = 1008 + res.msg = result.get("err_info") + return Response(res.dict) else: update_fields = [] logger.info(f"user {request.user} ios developer {developer_obj} update input data {data}") @@ -230,8 +237,8 @@ class AppUDIDUsedView(APIView): def get(self, request): res = BaseResponse() super_sign_used_objs, mine = base_super_sign_used_info(request) - app_udid_objs = AppUDID.objects.filter(app_id__appsupersignusedinfo__in=super_sign_used_objs).distinct() page_obj = PageNumber() + app_udid_objs = AppUDID.objects.filter(appsupersignusedinfo__in=super_sign_used_objs) app_page_serializer = page_obj.paginate_queryset(queryset=app_udid_objs.order_by("-created_time"), request=request, view=self) diff --git a/fir_ser/tests/postudid.py b/fir_ser/tests/postudid.py index 2625cba..8d360a9 100644 --- a/fir_ser/tests/postudid.py +++ b/fir_ser/tests/postudid.py @@ -2,59 +2,68 @@ import random import requests -short = ["bgql", "wjbu", "vnfg", "bgql"] - udid_lists = [ - "f55df38afe5c1242b8bc478d0182bbd0d7d08929aeasadfsdf", - "f55df38afe5c1242b8bc478d0182bbd0d7d08929", - "f55df38afe5c1242b8bc478d0182bbd0d7d08922", - "f55df38afe5c1242b8bc478d0182bbd0d7d01129", - "f55df38afe5c1242b8bc478d0182bbd0d723929", - "f55df38afe5c1242b8bc478d0182bbd0d7d118929", - "f55df38afe5c1242b8bc478d0182bbd0d7d08929", - "f55df38afe5c1242b8bc478d0182bbd0daed08929", - "f55df38afe5c1242b8bc478d0182bbd0d7d08929", - "f55df38afe5c1242b8bc478d0182bbdfsdfe7d08929", - "f55df38afe5c1242b8bc478d0182bbdfsdfe7d08929", - "f55df38afe5c1242b8bc478d0182bbdfsdfe7d08929", - "f55df38afe5c1242b8bc478d0182dsfsdd7d08929", - "f55df38afe5c1242b8bc478d0182dsfsdd7d08929", - "f55df38afe5c1242b8bc478d0182dsfsdd7d08929", - "f55df38afe5c1242b8bc478d0182bbdsdfsadf8929", - "f55df38afe5c1242b8bc478d01sdsdfsdd0d7d08929", - "f55df38afe5c1242b8bc478sdfsdffsdafd7d08929", - "f55df38afe5c1242b8bc478sdfsdffsdafd7d08929", - "f55df38afe5c1242b8bc478sdfsdffsdafd7d08929", - "f55df38afe5c1242b8bc478d0182bbd0d7d08929", - "f55df38afe5c1242b8bc478dsdfeasdfbbd0d7d08929", - "f55df38afe5c1242b8bc478dfsdfseasbd0d7d08929", - "f55df38afe5c1242b8bc478d0sdfseafsdbbd0d7d08929", - "f55df38afe5c1242b8asdfae8ds2bbd0d7d118929", - "f55df38afe5c1242b8bc47sfsdf2bbd0d7dd18929", - "f55df38afe5c1242b8bc478d0182bbd0d7d0ae8929", - "f55df38afe5c1242b8bc478d0182bbd0d7dsfe08929", + "75f14e4aee3dad37568a1a374f6c8b661b32d05e", "00008030-000C185C1143802E", "cadb0511abdb545d7eb7e828fd641a93e3164d02", + "efa8e5eb2a58fe65e303d1d9fad99d8b8670b6bb", "2525def0a63af76b8a09ea0dce0574d720925800", + "fdefbf544b7729db27c5294cd652e0dbb462cd22", "00008030-00122CD21A82402E", "e9f4cdc73fe24b1e20a4c33ae842d0d9ce6f8e34", + "cd84e936355f492ee68b7182f12ce3a7d0205557", "00008101-000B05E4368B001E", "f81a3a4170cf8e6c71d525464e175049134a6dbc", + "6bae15671c8fe7096a40752071d87c6a837dd132", "7dd77d8cf13789e3f547f28ceb3e0c67b8694e37", + "53e663905fcd81887abffc0d92e5c116ea2bfe5c", "00008101-001325EE1188001E", "f55df38afe5c1242b8bc478d0182bbd0d7d08929", + "00008020-000951C40C12002E", "760862a7367dea986542dae17ee31cd139e454ad", "079d0e46eab5369184830d37cbed345f664e835a", + "00008030-000E6CC122D2402E", "00008101-0012758822A2001E", "00008020-00192CDE3A41002E", + "e2bcc2bdf73bf815bfde88becdeee05abdebf4d1", "000f0a85cf2d0b65b7a1fa21f143516500e040e0", + "6dd86c12ab5506a1f7e45b0f58b6b1448f5cdf54", "49d8ca930a5610ba00190565ef756e24af97e63c", + "ad4016d3749277b58f6294a9496ad97fa7c88110", "6a245252fb9cca583fc84413a092e73f7afc3182", + "28f756d951c07d9073d5c62e66b2f9623bfcc1b4", "54d5c3d340912606f3502bd57196700daa23e8a0", + "7b12d1a745468afe0e2ba63fa8962e99a0b75b7c", "8d7fed0e9adc3c9ea269a447a4b171b1ea38e205", "00008101-001A115C0110001E", + "4d83d479308de7cb50f91679edf11e4f0017ac40", "00008020-001A75480E46002E", "d0746191f9a8e3f8ccbdbbf421fe4af43f2bd431", + "00008030-001949CC34DA402E", "00008030-000509D41A08802E", "00008020-0002344A0279002E", + "0f88c091dba1f606290cd4e2c2385a03ed6433f3", "00008030-00187410112A802E", "2a3b78c5559e956dc499c78fe7bb2730789085d4", + "1e574d63210a2c4ca50c403525c5b47ad446ade0", "00008101-001259E93A81001E", "00008020-00046DD03A69002E", + "17db32cab3c04e699189c49867833a7ab98bd7f1", "00008020-001E21C60A51002E", "00008030-00162D010A33802E", + "00008101-001661290169001E", "00008020-001B78E93461002E", "a84919cf236558b0f83496302237fd7f62a212a7", + "00008101-0008093E3611001E", "00008110-00162C9A3C82801E", "638525bfd0ef1f029ed4c216f1430688093e5ac5", + "00008030-000A51AE0EFA402E", "00008110-0016082C1E32801E", "00008030-001828411163802E", + "20737b4d60c2e0ff34e32edde224e64d042f72c1", "41d1b77e3a831f82a0ca306beaceeb955280b57a" +] + +udid_lists2 = [ + "00008020-000909C00CE8402E", + "e7058122cffa6a1705ea7144f208159e793a0f99", + "00008020-00192CDE3A41002E", + "00008101-001614893A42001E", + "00008101-001449580100001E", + "00008101-0012758822A2001E", + "019e2418ebf7bebbe82b42e4255b06f60f43fdda", + "d3c7d88e66bb84b5b1b03fc70a12b568118464da", + "f55df38afe5c1242b8bc478d0182bbd0d7d08929" +] + +short_list = [ + "wgvn", + "ynei", + "mecg", + "plzd", + "ibhp", + "zpus", + "ucwk" ] -def postaaa(shorts='bncz'): +def postudid(short=short_list[0], udid=udid_lists[0]): + data = '\n\n\n\n\tPRODUCT\n\tiPhone9,1\n\tSERIAL\n\tF71YD58GHG74\n\tUDID\n\t%s\n\tVERSION\n\t17E262\n\n\n' % ( + udid) + uri = "https://app.hehelucky.cn/udid/%s" % (short) + req = requests.post(uri, data=data) + print(req.status_code, req.text) + + +from concurrent.futures import ThreadPoolExecutor + +# postudid(udid="f55df38afe5c1242b8bc478d0182bbd0d7d08929") +# exit() + +if __name__ == '__main__': for udid in udid_lists: - udid = udid + str(random.choice(short)) + str(random.choice(short)) + str(random.choice(short)) + shorts - data = '\n\n\n\n\tPRODUCT\n\tiPhone9,1\n\tSERIAL\n\tF71YD58GHG74\n\tUDID\n\t%s\n\tVERSION\n\t17E262\n\n\n' % ( - udid) - # uri = "https://app.hehelucky.cn/udid/%s" % (random.choice(short)) - uri = "https://app.hehelucky.cn/udid/%s" % (shorts) - req = requests.post(uri, data=data) - print(req.headers) - print(req.status_code) - print(req.text) - exit(1) - - -# a = '验证码%(code)s,您正在注册成为新用户,感谢您的支持!' -# print(a % {'code': 111}) -pa = 10 -while pa > 0: - postaaa() - pa = pa - 1 - -postaaa() + with ThreadPoolExecutor(max_workers=10) as executor: + future = executor.submit(postudid, random.choice(short_list), udid)