diff --git a/fir_ser/api/utils/app/apputils.py b/fir_ser/api/utils/app/apputils.py index 548dc6a..5b52bce 100644 --- a/fir_ser/api/utils/app/apputils.py +++ b/fir_ser/api/utils/app/apputils.py @@ -59,7 +59,8 @@ def make_resigned(bin_url, img_url, bundle_id, app_version, name): """ % (bin_url, img_url, img_url, bundle_id, app_version, name) - + logger.info("make_resigned bin_url %s ,img_url %s, img_url %s, bundle_id %s, app_version %s, name %s" % ( + bin_url, img_url, img_url, bundle_id, app_version, name)) return ios_plist_tem @@ -135,7 +136,7 @@ def SaveAppInfos(app_file_name, user_obj, appinfo, bundle_id, app_img, short, si else: try: newapp = False - del_cache_response_by_short(appmobj.short, appmobj.app_id) + del_cache_response_by_short(appmobj.app_id) appmobj.short = short appmobj.name = appinfo["labelname"] appmobj.bundle_id = bundle_id diff --git a/fir_ser/api/utils/app/supersignutils.py b/fir_ser/api/utils/app/supersignutils.py index dbe75ce..9b810ea 100644 --- a/fir_ser/api/utils/app/supersignutils.py +++ b/fir_ser/api/utils/app/supersignutils.py @@ -172,7 +172,9 @@ class IosUtils(object): if apptodev_obj: release_obj = AppReleaseInfo.objects.filter(app_id=self.app_obj, is_master=True).first() if release_obj.release_id == apptodev_obj.release_file: + logger.info("udid %s exists app_id %s" % (self.udid_info.get('udid'), self.app_obj)) return + logger.info("udid %s not exists app_id %s ,need sign" % (self.udid_info.get('udid'), self.app_obj)) self.download_profile() file_format_path_name = file_format_path(self.user_obj, self.auth) @@ -200,6 +202,8 @@ class IosUtils(object): if appsupersign_obj.count() == 0: developer_obj = self.developer_obj developer_obj.use_number = developer_obj.use_number + 1 + logger.info("developer %s use_number+1 now %s udid %s app_id %s" % ( + developer_obj, developer_obj.use_number, self.udid_info.get('udid'), self.app_obj)) developer_obj.save() if not appsupersign_obj.filter(app_id=self.app_obj, user_id=self.user_obj).first(): @@ -208,7 +212,7 @@ class IosUtils(object): udid=AppUDID.objects.filter(app_id=self.app_obj, udid=self.udid_info.get('udid')).first()) - del_cache_response_by_short(self.app_obj.short, self.app_obj.app_id, udid=self.udid_info.get('udid')) + del_cache_response_by_short(self.app_obj.app_id, udid=self.udid_info.get('udid')) app_udid_obj = UDIDsyncDeveloper.objects.filter(developerid=self.developer_obj, udid=self.udid_info.get('udid')) if not app_udid_obj: diff --git a/fir_ser/api/utils/serializer.py b/fir_ser/api/utils/serializer.py index 63e02da..51e2a95 100644 --- a/fir_ser/api/utils/serializer.py +++ b/fir_ser/api/utils/serializer.py @@ -102,7 +102,8 @@ class AppsShortSerializer(serializers.ModelSerializer): def get_has_combo(self, obj): if obj.has_combo: obj.has_combo.has_combo = None - return AppsSerializer(obj.has_combo, context=self.context).data + if obj.has_combo.isshow: + return AppsSerializer(obj.has_combo, context=self.context).data master_release = serializers.SerializerMethodField() diff --git a/fir_ser/api/utils/storage/caches.py b/fir_ser/api/utils/storage/caches.py index 3f9e383..b33b71d 100644 --- a/fir_ser/api/utils/storage/caches.py +++ b/fir_ser/api/utils/storage/caches.py @@ -94,7 +94,18 @@ def set_app_download_by_cache(app_id, limit=900): return download_times + 1 -def del_cache_response_by_short(short, app_id, udid=''): +def del_cache_response_by_short(app_id, udid=''): + apps_dict = Apps.objects.filter(app_id=app_id).values("id", "short", "app_id", "has_combo").first() + if apps_dict: + del_cache_response_by_short_util(apps_dict.get("short"), apps_dict.get("app_id"), udid) + if apps_dict.get("has_combo"): + combo_dict = Apps.objects.filter(pk=apps_dict.get("has_combo")).values("id", "short", "app_id").first() + if combo_dict: + del_cache_response_by_short_util(combo_dict.get("short"), combo_dict.get("app_id"), udid) + + +def del_cache_response_by_short_util(short, app_id, udid): + logger.info("del_cache_response_by_short short:%s app_id:%s udid:%s" % (short, app_id, udid)) cache.delete("_".join([CACHE_KEY_TEMPLATE.get("download_short_key"), short])) key = "_".join([CACHE_KEY_TEMPLATE.get("download_short_key"), short, '*']) for app_download_key in cache.iter_keys(key): @@ -126,8 +137,9 @@ def del_cache_by_app_id(app_id, user_obj): def del_cache_storage(user_obj): + logger.info("del_cache_storage user:%s" % (user_obj)) for app_obj in Apps.objects.filter(user_id=user_obj): - del_cache_response_by_short(app_obj.short, app_obj.app_id) + del_cache_response_by_short(app_obj.app_id) del_cache_by_app_id(app_obj.app_id, user_obj) storage_keys = "_".join([CACHE_KEY_TEMPLATE.get('user_storage_key'), user_obj.uid, '*']) @@ -185,6 +197,7 @@ def upload_file_tmp_name(act, filename, user_obj_id): def login_auth_failed(act, email): + logger.error("login email:%s act:%s" % (email, act)) auth_code_key = "_".join([CACHE_KEY_TEMPLATE.get("login_failed_try_times_key"), email]) if act == "set": data = { diff --git a/fir_ser/api/views/apps.py b/fir_ser/api/views/apps.py index b2df273..cff5be7 100644 --- a/fir_ser/api/views/apps.py +++ b/fir_ser/api/views/apps.py @@ -9,10 +9,7 @@ from api.utils.response import BaseResponse from api.utils.auth import ExpiringTokenAuthentication from rest_framework.response import Response from django.db.models import Sum, F -import os -from fir_ser import settings from api.utils.app.supersignutils import IosUtils -from api.utils.app.randomstrings import make_from_user_uuid from api.utils.storage.storage import Storage from api.utils.storage.caches import del_cache_response_by_short, get_app_today_download_times from api.models import Apps, AppReleaseInfo, APPToDeveloper, AppIOSDeveloperInfo, UserInfo @@ -37,7 +34,6 @@ class AppsView(APIView): app_type = request.query_params.get("type", None) act_type = request.query_params.get("act", None) - logger.info("app_type:%s act_type:%s" % (app_type, act_type)) res = BaseResponse() res.hdata = {"all_hits_count": 0} res.hdata["upload_domain"] = request.user.domain_name @@ -122,20 +118,20 @@ class AppInfoView(APIView): apps_obj = Apps.objects.filter(user_id=request.user, app_id=app_id).first() if apps_obj: if apps_obj.issupersign: - logger.info("app_id:%s is supersign ,so delete this app need clean IOS developer") + logger.info("app_id:%s is supersign ,delete this app need clean IOS developer" % (app_id)) IosUtils.clean_app_by_user_obj(apps_obj, request.user) storage = Storage(request.user) has_combo = apps_obj.has_combo if has_combo: logger.info( - "app_id:%s has_combo ,so delete this app need uncombo and clean del_cache_response_by_short") - del_cache_response_by_short(apps_obj.has_combo.short, apps_obj.has_combo.app_id) + "app_id:%s has_combo ,delete this app need uncombo and clean del_cache_response_by_short" % ( + app_id)) apps_obj.has_combo.has_combo = None - del_cache_response_by_short(apps_obj.short, apps_obj.app_id) + del_cache_response_by_short(apps_obj.app_id) for appreleaseobj in AppReleaseInfo.objects.filter(app_id=apps_obj).all(): - logger.info("app_id:%s has_combo ,so delete this app need clean all release,release_id:%s" % ( - appreleaseobj.release_id)) + logger.info("delete app_id:%s need clean all release,release_id:%s" % ( + app_id, appreleaseobj.release_id)) storage.delete_file(appreleaseobj.release_id, appreleaseobj.release_type) storage.delete_file(appreleaseobj.icon_url) appreleaseobj.delete() @@ -175,8 +171,7 @@ class AppInfoView(APIView): has_combo.update(**{"has_combo": apps_obj.first()}) else: pass - del_cache_response_by_short(apps_obj.first().short, apps_obj.first().app_id) - del_cache_response_by_short(has_combo.first().short, has_combo.first().app_id) + del_cache_response_by_short(apps_obj.first().app_id) except Exception as e: logger.error("app_id:%s actions:%s hcombo_id:%s Exception:%s" % (app_id, actions, hcombo_id, e)) @@ -185,8 +180,9 @@ class AppInfoView(APIView): else: try: apps_obj = Apps.objects.filter(user_id=request.user, app_id=app_id).first() + logger.info("app_id:%s update old data:%s" % (app_id, apps_obj.__dict__)) apps_obj.description = data.get("description", apps_obj.description) - del_cache_response_by_short(apps_obj.short, apps_obj.app_id) + del_cache_response_by_short(apps_obj.app_id) apps_obj.short = data.get("short", apps_obj.short) apps_obj.name = data.get("name", apps_obj.name) apps_obj.password = data.get("password", apps_obj.password) @@ -206,6 +202,7 @@ class AppInfoView(APIView): res.msg = "超级签开发者不存在,无法开启" return Response(res.dict) apps_obj.issupersign = data.get("issupersign", apps_obj.issupersign) + logger.info("app_id:%s update new data:%s" % (app_id, apps_obj.__dict__)) apps_obj.save() except Exception as e: logger.error("app_id:%s update Exception:%s" % (app_id, e)) @@ -300,11 +297,13 @@ class AppReleaseinfoView(APIView): apprelease_count = AppReleaseInfo.objects.filter(app_id=apps_obj).values("release_id").count() appreleaseobj = AppReleaseInfo.objects.filter(app_id=apps_obj, release_id=act).first() if not appreleaseobj.is_master: + logger.info("delete app release %s" % (appreleaseobj)) storage.delete_file(appreleaseobj.release_id, appreleaseobj.release_type) storage.delete_file(appreleaseobj.icon_url) appreleaseobj.delete() elif appreleaseobj.is_master and apprelease_count < 2: + logger.info("delete app master release %s and clean app %s " % (appreleaseobj, apps_obj)) storage.delete_file(appreleaseobj.release_id, appreleaseobj.release_type) storage.delete_file(appreleaseobj.icon_url) @@ -316,7 +315,7 @@ class AppReleaseinfoView(APIView): apps_obj.delete() else: pass - del_cache_response_by_short(apps_obj.short, apps_obj.app_id) + del_cache_response_by_short(apps_obj.app_id) return Response(res.dict) @@ -327,16 +326,16 @@ class AppReleaseinfoView(APIView): apps_obj = Apps.objects.filter(user_id=request.user, app_id=app_id).first() if apps_obj: appreleaseobj = AppReleaseInfo.objects.filter(app_id=apps_obj, release_id=act) - - make_master = request.data.get("make_master", None) + data = request.data + make_master = data.get("make_master", None) try: if make_master and make_master == act: AppReleaseInfo.objects.filter(app_id=apps_obj).update(**{"is_master": False}) appreleaseobj.update(**{"is_master": True}) else: appreleaseobj.update( - **{"changelog": request.data.get("changelog", appreleaseobj.first().changelog)}) - binary_url = request.data.get("binary_url", None) + **{"changelog": data.get("changelog", appreleaseobj.first().changelog)}) + binary_url = data.get("binary_url", None) if binary_url != '': if binary_url: if not binary_url.startswith('http'): @@ -345,13 +344,14 @@ class AppReleaseinfoView(APIView): binary_url = appreleaseobj.first().binary_url appreleaseobj.update(**{"binary_url": binary_url}) - + logger.info("update app:%s release:%s data:%s" % (apps_obj, appreleaseobj, data)) except Exception as e: + logger.error("update app:%s release:%s failed Exception:%s" % (apps_obj, appreleaseobj, e)) res.code = 1006 res.msg = "更新失败" return Response(res.dict) - del_cache_response_by_short(apps_obj.short, apps_obj.app_id) + del_cache_response_by_short(apps_obj.app_id) app_serializer = AppsSerializer(apps_obj) res.data["currentapp"] = app_serializer.data diff --git a/fir_ser/api/views/download.py b/fir_ser/api/views/download.py index e70c1d7..0735c1f 100644 --- a/fir_ser/api/views/download.py +++ b/fir_ser/api/views/download.py @@ -29,9 +29,6 @@ class DownloadView(APIView): 文件下载接口,适用于本地存储和所有plist文件下载 ''' - # authentication_classes = [ExpiringTokenAuthentication, ] - # parser_classes = (MultiPartParser,) - def get(self, request, filename): res = BaseResponse() downtoken = request.query_params.get(settings.DATA_DOWNLOAD_KEY, None) @@ -113,7 +110,7 @@ class ShortDownloadView(APIView): res.msg = "该应用不存在" return Response(res.dict) if udid: - del_cache_response_by_short(short, app_obj.app_id, udid=udid) + del_cache_response_by_short(app_obj.app_id, udid=udid) if not app_obj.isshow: res.code = 1004 res.msg = "您没有权限访问该应用" diff --git a/fir_ser/api/views/login.py b/fir_ser/api/views/login.py index 32e8057..a25dc8c 100644 --- a/fir_ser/api/views/login.py +++ b/fir_ser/api/views/login.py @@ -94,7 +94,7 @@ class UserInfoView(APIView): if act and act == "sms": sms_token_obj = DownloadToken() sms_code = generateNumericTokenOfLength(6) - sms_token = sms_token_obj.make_token([sms_code]) + sms_token = sms_token_obj.make_token(sms_code) res.data["sms_token"] = sms_token res.data["sms_code"] = sms_code @@ -102,18 +102,22 @@ class UserInfoView(APIView): def put(self, request): res = BaseResponse() - request.user.qq = request.data.get("qq", request.user.qq) - request.user.job = request.data.get("job", request.user.job) - request.user.first_name = request.data.get("first_name", request.user.first_name) - - oldpassword = request.data.get("oldpassword", None) - surepassword = request.data.get("surepassword", None) + data = request.data + logger.info("user:%s update old data:%s" % (request.user, request.user.__dict__)) + logger.info("user:%s update new data:%s" % (request.user, data)) + request.user.qq = data.get("qq", request.user.qq) + request.user.job = data.get("job", request.user.job) + request.user.first_name = data.get("first_name", request.user.first_name) + + oldpassword = data.get("oldpassword", None) + surepassword = data.get("surepassword", None) if oldpassword and surepassword: user = auth.authenticate(username=request.user.username, password=oldpassword) if user is not None: user.set_password(surepassword) user.save() res.msg = "密码修改成功" + logger.info("user:%s change password success,old %s new %s" % (request.user, oldpassword, surepassword)) auth_token = request.auth for token_obj in Token.objects.filter(user=user): @@ -127,11 +131,11 @@ class UserInfoView(APIView): res.msg = "老密码校验失败" else: - sms_token = request.data.get("sms_token", None) + sms_token = data.get("sms_token", None) if sms_token: sms_token_obj = DownloadToken() - if sms_token_obj.verify_token(sms_token, request.data.get("sms_code", None)): - request.user.mobile = request.data.get("mobile", request.user.mobile) + if sms_token_obj.verify_token(sms_token, data.get("sms_code", None)): + request.user.mobile = data.get("mobile", request.user.mobile) request.user.save() serializer = UserInfoSerializer(request.user) res.data = serializer.data diff --git a/fir_ser/api/views/logout.py b/fir_ser/api/views/logout.py index 7255789..bf3681a 100644 --- a/fir_ser/api/views/logout.py +++ b/fir_ser/api/views/logout.py @@ -3,14 +3,20 @@ from api.utils.auth import ExpiringTokenAuthentication from api.models import Token from django.core.cache import cache from rest_framework.response import Response +from django.contrib import auth +import logging + +logger = logging.getLogger(__file__) class LogoutView(APIView): authentication_classes = [ExpiringTokenAuthentication] def delete(self, request): + logger.info("user:%s logout" % (request.user)) user = request.user.pk auth_token = request.auth cache.delete(auth_token) Token.objects.filter(user=user, access_token=auth_token).delete() + auth.logout(request) return Response({"code": 1000}) diff --git a/fir_ser/api/views/receiveudids.py b/fir_ser/api/views/receiveudids.py index d73681c..8537c53 100644 --- a/fir_ser/api/views/receiveudids.py +++ b/fir_ser/api/views/receiveudids.py @@ -18,6 +18,7 @@ class IosUDIDView(View): def post(self, request, short): stream_f = str(request.body) format_udid_info = udid_bytes_to_dict(stream_f) + logger.info("short %s get new udid %s" % (short, format_udid_info)) server_domain = get_redirect_server_domain(request) try: app_info = Apps.objects.filter(short=short).first() diff --git a/fir_ser/api/views/storage.py b/fir_ser/api/views/storage.py index cb5d9be..5971d15 100644 --- a/fir_ser/api/views/storage.py +++ b/fir_ser/api/views/storage.py @@ -56,18 +56,20 @@ class StorageView(APIView): def post(self, request): res = BaseResponse() data = request.data + logger.info("user %s add new storage data:%s" % (request.user, data)) try: data['additionalparameters'] = json.dumps(data.get('additionalparameter', '')) except Exception as e: logger.error("user:%s additionalparameters %s dumps failed Exception:%s" % ( - request.user, data.get('additionalparameter', ''), e)) + request.user, data.get('additionalparameter', ''), e)) serializer = StorageSerializer(data=data, context={'user_obj': request.user}) if serializer.is_valid(): serializer.save() res.msg = serializer.validated_data - + logger.info("user %s add new storage success" % (request.user)) else: + logger.info("user %s add new storage failed" % (request.user)) res.msg = serializer.errors res.code = 1005 return Response(res.dict) @@ -75,6 +77,7 @@ class StorageView(APIView): def put(self, request): res = BaseResponse() data = request.data + logger.info("user %s update storage data:%s" % (request.user, data)) use_storage_id = data.get("use_storage_id", None) if use_storage_id: @@ -116,7 +119,11 @@ class StorageView(APIView): res = BaseResponse() storage_id = request.query_params.get("id", None) if storage_id: - AppStorage.objects.filter(user_id=request.user, id=storage_id).delete() + try: + AppStorage.objects.filter(user_id=request.user, id=storage_id).delete() + logger.error("user %s delete storage id:%s success" % (request.user, storage_id)) + except Exception as e: + logger.error("user %s delete storage id:%s failed Exception:%s" % (request.user, storage_id, e)) else: res.code = 1004 res.msg = '该存储不存在' diff --git a/fir_ser/api/views/supersign.py b/fir_ser/api/views/supersign.py index af113bc..01b6029 100644 --- a/fir_ser/api/views/supersign.py +++ b/fir_ser/api/views/supersign.py @@ -58,6 +58,7 @@ class DeveloperView(APIView): act = data.get("act", None) if act: res = BaseResponse() + logger.info("user %s iosdeveloper %s act %s" % (request.user, developer_obj, act)) if act == "preactive": developer_auth_code("del", request.user, developer_obj.email) status, result = IosUtils.active_developer(developer_obj, request.user) @@ -107,19 +108,28 @@ class DeveloperView(APIView): res.msg = result.get("return_info") return Response(res.dict) else: + logger.info("user %s iosdeveloper %s update input data %s" % (request.user, developer_obj, data)) + logger.info("user %s iosdeveloper %s update old data %s" % ( + request.user, developer_obj, developer_obj.__dict__)) try: usable_number = int(data.get("usable_number", developer_obj.usable_number)) if usable_number >= 0 and usable_number <= 100: developer_obj.usable_number = usable_number except Exception as e: logger.error("developer %s usable_number %s get failed Exception:%s" % ( - developer_obj, data.get("usable_number", developer_obj.usable_number), e)) + developer_obj, data.get("usable_number", developer_obj.usable_number), e)) developer_obj.description = data.get("description", developer_obj.description) password = data.get("password", developer_obj.password) if password != "" and password != developer_obj.password: developer_obj.password = password developer_obj.is_actived = False - developer_obj.save() + try: + developer_obj.save() + logger.info("user %s iosdeveloper %s update now data %s" % ( + request.user, developer_obj, developer_obj.__dict__)) + except Exception as e: + logger.error("user %s iosdeveloper %s update error data %s Exception %s" % ( + request.user, developer_obj, data, e)) return self.get(request) @@ -132,6 +142,8 @@ class DeveloperView(APIView): "email": data.get("email", ""), } try: + logger.error("user %s add new developer %s data %s" % ( + request.user, data.get("email", ""), datainfo)) AppIOSDeveloperInfo.objects.create(user_id=request.user, **datainfo) except Exception as e: logger.error("user %s create developer %s failed Exception:%s" % ( @@ -148,6 +160,8 @@ class DeveloperView(APIView): if email: developer_obj = AppIOSDeveloperInfo.objects.filter(user_id=request.user, email=email).first() if developer_obj: + logger.error("user %s delete developer %s " % ( + request.user, developer_obj)) IosUtils.clean_developer(developer_obj, request.user) developer_obj.delete() @@ -211,6 +225,8 @@ class AppUDIDUsedView(APIView): id = request.query_params.get("id", None) app_id = request.query_params.get("aid", None) app_udid_obj = AppUDID.objects.filter(app_id__user_id_id=request.user, pk=id) - IosUtils.disable_udid(app_udid_obj.first(), app_id) - app_udid_obj.delete() + if app_udid_obj: + logger.error("user %s delete devices %s" % (request.user, app_udid_obj)) + IosUtils.disable_udid(app_udid_obj.first(), app_id) + app_udid_obj.delete() return Response(res.dict) diff --git a/fir_ser/api/views/uploads.py b/fir_ser/api/views/uploads.py index 580bf5b..3019d49 100644 --- a/fir_ser/api/views/uploads.py +++ b/fir_ser/api/views/uploads.py @@ -100,7 +100,7 @@ class AppAnalyseView(APIView): png_tmp_filename = data.get("png_key") png_new_filename = data.get("png_key").strip(settings.FILE_UPLOAD_TMP_KEY) - + logger.info("user %s create or update app %s data:%s" % (request.user, data.get("bundleid"), data)) if SaveAppInfos(app_new_filename, request.user, appinfo, data.get("bundleid"), png_new_filename, data.get("short"), data.get('filesize')): pass @@ -115,7 +115,7 @@ class AppAnalyseView(APIView): upload_file_tmp_name("del", png_tmp_filename, request.user.id) except Exception as e: - logger.error("%s %s save app info failed Exception:%s" % (request.user, data.get("bundleid"), e)) + logger.error("user %s %s save app info failed Exception:%s" % (request.user, data.get("bundleid"), e)) res.code = 10003 return Response(res.dict) @@ -229,6 +229,7 @@ class UploadView(APIView): random_file_name = make_from_user_uuid(request.user) local_file = os.path.join(settings.MEDIA_ROOT, certinfo.get("upload_key", random_file_name)) # 读取传入的文件 + logger.info("user:%s save file:%s" % (request.user, local_file)) try: destination = open(local_file, 'wb+') for chunk in file_obj.chunks(): @@ -260,10 +261,11 @@ class UploadView(APIView): certinfo = request.data.get('certinfo', None) if certinfo: app_id = certinfo.get("app_id", None) + logger.info("user %s update img %s info" % (request.user, app_id)) ftype = certinfo.get('ftype', None) storage = Storage(request.user) - if ftype and ftype == 'app': + if ftype and app_id and ftype == 'app': app_obj = Apps.objects.filter(app_id=app_id, user_id=request.user).first() if app_obj: release_obj = AppReleaseInfo.objects.filter(app_id=app_obj, is_master=True).first() @@ -271,10 +273,10 @@ class UploadView(APIView): old_file_key = release_obj.icon_url release_obj.icon_url = certinfo.get("upload_key") release_obj.save() - del_cache_response_by_short(app_obj.short, app_id) + del_cache_response_by_short(app_id) storage.delete_file(old_file_key) return Response(res.dict) - elif ftype and ftype == 'head': + elif ftype and app_id and ftype == 'head': if request.user.uid != app_id: res.code = 1007 res.msg = '该用户不存在'