fix some bugs

super_signature
nineven 5 years ago
parent b3610913e2
commit a4e9579236
  1. 6
      fir_client/src/components/FirSuperSignBase.vue
  2. 35
      fir_ser/api/utils/app/iossignapi.py
  3. 50
      fir_ser/api/utils/app/shellcmds.py
  4. 74
      fir_ser/api/utils/app/supersignutils.py
  5. 34
      fir_ser/api/utils/serializer.py
  6. 13
      fir_ser/api/utils/storage/caches.py
  7. 80
      fir_ser/api/utils/utils.py
  8. 8
      fir_ser/api/views/apps.py
  9. 34
      fir_ser/api/views/supersign.py
  10. 3
      fir_ser/fir_ser/settings.py

@ -76,7 +76,7 @@
<el-popover trigger="hover" placement="top">
<p>开发者账户已使用设备数: {{ scope.row.developer_used_number }}</p>
<p>开发者账户可用设备数: {{ 100-scope.row.developer_used_number }}</p>
<p>由于您设置可用设备数: {{ scope.row.usable_number}} ,所以现在可用设备数: {{ scope.row.usable_number-scope.row.developer_used_number }}</p>
<p>由于您设置可用设备数: {{ scope.row.usable_number}} ,所以现在可用设备数: {{ scope.row.usable_number-scope.row.developer_used_number > 0 ?scope.row.usable_number-scope.row.developer_used_number :0 }}</p>
<div slot="reference" class="name-wrapper">
<el-tag size="medium">{{ scope.row.email }}</el-tag>
@ -101,9 +101,9 @@
width="100">
<template slot-scope="scope">
<el-popover trigger="hover" placement="top">
<p>可用设备数: {{ scope.row.usable_number-scope.row.developer_used_number }}</p>
<p>可用设备数: {{ scope.row.usable_number-scope.row.developer_used_number > 0 ?scope.row.usable_number-scope.row.developer_used_number :0}}</p>
<div slot="reference" class="name-wrapper">
<el-tag size="medium"> {{ scope.row.usable_number-scope.row.developer_used_number }}</el-tag>
<el-tag size="medium"> {{ scope.row.usable_number-scope.row.developer_used_number > 0 ?scope.row.usable_number-scope.row.developer_used_number :0 }}</el-tag>
</div>
</el-popover>
</template>

@ -4,7 +4,7 @@
# author: liuyu
# date: 2020/4/24
from api.utils.app.shellcmds import shell_command,use_user_pass
from api.utils.app.shellcmds import shell_command,use_user_pass,pshell_command
from fir_ser.settings import SUPER_SIGN_ROOT
import os
from api.utils.app.randomstrings import make_app_uuid
@ -23,8 +23,14 @@ def exec_shell(cmd,remote=False,timeout=None):
result = shell_command(cmd,timeout)
print(result)
if result.get("exit_code") != 0 :
return False
return result
err_info=result.get("err_info",None)
if err_info:
if "have access to this membership resource. Contact your team" in err_info:
result["err_info"]="You currently don't have access to this membership resource"
else:
result["err_info"]="Unknown Error"
return False,result
return True,result
@ -36,19 +42,18 @@ class AppDeveloperApi(object):
script_path=os.path.join(SUPER_SIGN_ROOT,'scripts','apple_api.rb')
self.cmd = "ruby %s '%s' '%s'" %(script_path,self.username,self.password)
def active(self,code):
timeout=10
def active(self,user_obj):
self.cmd = self.cmd + " active "
if code:
self.cmd = "echo %s | %s" %(code,self.cmd)
timeout=None
print(self.cmd)
result={}
try:
result = exec_shell(self.cmd,timeout=timeout)
result = pshell_command(self.cmd,user_obj,self.username)
print(result)
if result["exit_code"] == 0:
return True
return True,result
except Exception as e:
print(e)
return False
return False,result
def file_format_path_name(self,user_obj):
cert_dir_name = make_app_uuid(user_obj,self.username)
@ -59,7 +64,7 @@ class AppDeveloperApi(object):
def create_cert(self,user_obj):
self.cmd=self.cmd + " cert add '%s'" %(self.file_format_path_name(user_obj))
result = exec_shell(self.cmd)
return exec_shell(self.cmd)
def get_profile(self,bundleId,app_id,device_udid,device_name,provisionName):
self.cmd=self.cmd + " profile add '%s' '%s' '%s' '%s' '%s' '%s'" %(bundleId,app_id,device_udid,device_name,self.certid,provisionName)
@ -82,7 +87,7 @@ class AppDeveloperApi(object):
def get_device(self,user_obj):
self.cmd=self.cmd + " device get '%s' " %(self.file_format_path_name(user_obj))
result = exec_shell(self.cmd)
return exec_shell(self.cmd)
def add_app(self,bundleId,app_id):
self.cmd=self.cmd + " app add '%s' '%s'" %(bundleId,app_id)
@ -92,10 +97,6 @@ class AppDeveloperApi(object):
self.cmd=self.cmd + " app del '%s' '%s'" %(bundleId,app_id)
result = exec_shell(self.cmd)
# appdev = AppDeveloperApi("hehehuyu521@163.com","Hehehuyu123")
# appdev.create_cert()
# appdev.get_profile('com.hehegames.NenJiangMaJiang',"e6f0c1aeee6853af9c21651654a812e7","6dd86c12ab5506a1f7e45b0f58b6b1448f5cdf54","iPad5,1")
# # e6f0c1aeee6853af9c21651654a812e7_dis.mobileprovision
class ResignApp(object):

@ -8,6 +8,8 @@ from subprocess import Popen, PIPE
import logging
import paramiko,json
import socket
import pexpect
from api.utils.storage.caches import developer_auth_code
def default_result():
return {'exit_code': '99', 'return_info': 'Failed to run, function_name is not existed'}
@ -85,6 +87,54 @@ class SSHConnection(object):
if self._client:
self._client.close()
def pshell_command(cmdstrs,user_obj,developer_email,timeout=60*10):
result = default_result()
run = pexpect.spawn(cmdstrs, encoding='utf-8')
try:
index = run.expect(["Two-factor Authentication","Invalid username and password combination", pexpect.EOF, pexpect.TIMEOUT],timeout=timeout)
if index == 0:
count = 1
if timeout == -1:
timeout = 60*60*24
while True and count<timeout/3:
code = developer_auth_code("get",user_obj,developer_email)
if code:
run.sendline(code)
try:
err = run.expect(["Unauthorized Access", pexpect.EOF, pexpect.TIMEOUT])
if err == 0:
result['exit_code'] = 2
result['return_info'] = 'Unauthorized Access'
elif err == 1:
result['exit_code'] = 0
result['return_info'] = 'Verify Code Success'
else:
result['exit_code'] = 3
result['return_info'] = 'Verify Code TimeOut or UnKnown Error'
developer_auth_code("del", user_obj, developer_email)
return result
except Exception as e:
print(e)
developer_auth_code("del", user_obj, developer_email)
result['exit_code'] = 0
result['return_info'] = 'Success'
return result
count+=1
time.sleep(3)
elif index == 1:
result['exit_code'] = 1
result['return_info'] = 'Invalid username and password combination'
elif index == 2:
result['exit_code'] = 0
result['return_info'] = 'Alreay Success'
else:
result['exit_code'] = 4
result['return_info'] = 'Code TimeOut or UnKnown Error'
except Exception as e:
print(e)
return result
def shell_command(cmdstrs,timeout):
result = default_result()
result['return_info'] = ''

@ -9,11 +9,10 @@ from fir_ser.settings import SUPER_SIGN_ROOT, MEDIA_ROOT, SERVER_DOMAIN
from api.utils.app.iossignapi import AppDeveloperApi, ResignApp
from api.models import APPSuperSignUsedInfo, AppUDID, AppIOSDeveloperInfo, AppReleaseInfo,Apps,APPToDeveloper,UDIDsyncDeveloper
from api.utils.app.randomstrings import make_app_uuid, make_from_user_uuid
from django.db.models import F
from api.utils.serializer import get_developer_udided
from api.utils.storage.storage import LocalStorage
from api.utils.storage.localApi import LocalStorage
from api.utils.storage.caches import del_cache_response_by_short
from api.utils.utils import file_format_path,delete_app_to_dev_and_file,delete_app_profile_file
def udid_bytes_to_dict(xml_stream):
@ -147,22 +146,6 @@ class IosUtils(object):
return None
return developer_obj
def create_cert(self):
app_api_obj = AppDeveloperApi(**self.auth)
app_api_obj.create_cert(self.user_obj)
file_format_path_name = file_format_path(self.user_obj,self.auth)
cert_info = None
try:
with open(file_format_path_name + '.info', "r") as f:
cert_info = f.read()
except Exception as e:
print(e)
cert_id = re.findall(r'.*\n\tid=(.*),.*', cert_info)[0].replace('"', '')
developer_obj=AppIOSDeveloperInfo.objects.filter(user_id=self.user_obj, email=self.auth.get("username")).first()
developer_obj.is_actived=True
developer_obj.certid=cert_id
developer_obj.save()
def download_profile(self):
app_api_obj = AppDeveloperApi(**self.auth)
bundleId = self.app_obj.bundle_id
@ -344,10 +327,7 @@ class IosUtils(object):
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)
auth = {
"username": developer_obj.email
}
full_path=file_format_path(user_obj, auth)
full_path=file_format_path(user_obj, email=developer_obj.email)
try:
for root, dirs, files in os.walk(full_path, topdown=False):
for name in files:
@ -360,7 +340,7 @@ class IosUtils(object):
@staticmethod
def active_developer(developer_obj,code=None):
def active_developer(developer_obj,user_obj):
'''
激活开发者账户
:param developer_obj:
@ -373,7 +353,14 @@ class IosUtils(object):
"certid": developer_obj.certid
}
app_api_obj = AppDeveloperApi(**auth)
return app_api_obj.active(code)
status,result = app_api_obj.active(user_obj)
if status:
developer_obj.is_actived=True
developer_obj.save()
if not developer_obj.certid :
IosUtils.create_developer_cert(developer_obj,user_obj)
IosUtils.get_device_from_developer(developer_obj, user_obj)
return status,result
@staticmethod
def create_developer_cert(developer_obj,user_obj):
@ -383,7 +370,8 @@ class IosUtils(object):
"certid": developer_obj.certid
}
app_api_obj = AppDeveloperApi(**auth)
app_api_obj.create_cert(user_obj)
status,result = app_api_obj.create_cert(user_obj)
if status:
file_format_path_name = file_format_path(user_obj,auth)
cert_info = None
try:
@ -396,6 +384,7 @@ class IosUtils(object):
developer_obj.is_actived=True
developer_obj.certid=cert_id
developer_obj.save()
return status,result
@staticmethod
def get_device_from_developer(developer_obj,user_obj):
@ -405,7 +394,8 @@ class IosUtils(object):
"certid": developer_obj.certid
}
app_api_obj = AppDeveloperApi(**auth)
app_api_obj.get_device(user_obj)
status,result = app_api_obj.get_device(user_obj)
if status:
file_format_path_name = file_format_path(user_obj,auth)
devices_info = ""
try:
@ -428,32 +418,4 @@ class IosUtils(object):
pass
else:
UDIDsyncDeveloper.objects.create(developerid=developer_obj,**device)
def file_format_path(user_obj,auth):
cert_dir_name = make_app_uuid(user_obj, auth.get("username"))
cert_dir_path = os.path.join(SUPER_SIGN_ROOT, cert_dir_name)
if not os.path.isdir(cert_dir_path):
os.makedirs(cert_dir_path)
file_format_path_name = os.path.join(cert_dir_path, cert_dir_name)
return file_format_path_name
def get_profile_full_path(developer_obj,app_obj):
cert_dir_name = make_app_uuid(developer_obj.user_id, developer_obj.email)
cert_dir_path = os.path.join(SUPER_SIGN_ROOT, cert_dir_name, "profile")
provisionName = os.path.join(cert_dir_path, app_obj.app_id)
return provisionName + '.mobileprovision'
def delete_app_to_dev_and_file(developer_obj,app_id):
APPToDeveloper_obj=APPToDeveloper.objects.filter(developerid=developer_obj, app_id_id=app_id)
if APPToDeveloper_obj:
binary_file = APPToDeveloper_obj.first().binary_file + ".ipa"
lsobj=LocalStorage("localhost",False)
lsobj.del_file(binary_file)
APPToDeveloper_obj.delete()
def delete_app_profile_file(developer_obj,app_obj):
try:
os.remove(get_profile_full_path(developer_obj,app_obj))
except Exception as e:
print(e)
return status,result

@ -1,9 +1,9 @@
from rest_framework import serializers
from api import models
from django.db.models import Sum,F
from api.utils.app.apputils import bytes2human
from api.utils.TokenManager import DownloadToken
from api.utils.storage.storage import Storage
from api.utils.utils import get_developer_udided
import os,json
token_obj = DownloadToken()
@ -231,38 +231,6 @@ class DeveloperSerializer(serializers.ModelSerializer):
def get_developer_used_other_number(self,obj):
return get_developer_udided(obj)[0]
def get_developer_udided(developer_obj):
SuperSignUsed_obj = models.APPSuperSignUsedInfo.objects.filter(developerid=developer_obj )
UDIDsyncDeveloper_obj = models.UDIDsyncDeveloper.objects.filter(developerid=developer_obj)
develoer_udid_lists=[]
supersign_udid_lists=[]
if UDIDsyncDeveloper_obj:
develoer_udid_lists=list(UDIDsyncDeveloper_obj.values_list("udid"))
if SuperSignUsed_obj:
supersign_udid_lists=list(SuperSignUsed_obj.values_list("udid__udid"))
return len(set(develoer_udid_lists)-set(supersign_udid_lists)),len(develoer_udid_lists)
def get_developer_devices(developer_obj_lists):
other_used_sum = 0
flyapp_used_sum = 0
for dev_obj in developer_obj_lists:
other_used, flyapp_used = get_developer_udided(dev_obj)
other_used_sum += other_used
flyapp_used_sum += flyapp_used
use_number_obj = developer_obj_lists.filter(is_actived=True)
if use_number_obj:
use_number_dict = use_number_obj.aggregate(usable_number=Sum('usable_number'), use_number=Sum('use_number'))
use_num = {
"all_usable_number": use_number_dict.get("usable_number", 0),
"all_use_number": use_number_dict.get("use_number", 0),
"other_used_sum": other_used_sum,
"flyapp_used_sum": flyapp_used_sum,
}
return use_num
class SuperSignUsedSerializer(serializers.ModelSerializer):
class Meta:
model = models.APPSuperSignUsedInfo

@ -11,6 +11,7 @@ from django.utils import timezone
from fir_ser.settings import CACHE_KEY_TEMPLATE,SERVER_DOMAIN
from api.utils.storage.storage import Storage,LocalStorage
from api.utils.crontab.sync_cache import sync_download_times_by_app_id
from api.utils.utils import file_format_path
try:
from api.utils.crontab import run
except Exception as e:
@ -142,3 +143,15 @@ def get_app_today_download_times(app_ids):
for k, v in down_times_lists.items():
download_times_count+=v
return download_times_count
def developer_auth_code(act,user_obj,developer_email,code=None):
auth_key=file_format_path(user_obj,email=developer_email)
key = "_".join([CACHE_KEY_TEMPLATE.get("developer_auth_code_key"),auth_key])
if act == "set":
cache.delete(key)
cache.set(key,code,60*10)
elif act == "get":
return cache.get(key)
elif act == "del":
cache.delete(key)

@ -0,0 +1,80 @@
#!/usr/bin/env python
# -*- coding:utf-8 -*-
# project: 5月
# author: liuyu
# date: 2020/5/7
import os
from fir_ser.settings import SUPER_SIGN_ROOT
from api.models import APPSuperSignUsedInfo, AppUDID, AppIOSDeveloperInfo, AppReleaseInfo,Apps,APPToDeveloper,UDIDsyncDeveloper
from api.utils.app.randomstrings import make_app_uuid
from api.utils.storage.localApi import LocalStorage
from django.db.models import Sum
def file_format_path(user_obj, auth=None, email=None):
if email:
cert_dir_name = make_app_uuid(user_obj, email)
else:
cert_dir_name = make_app_uuid(user_obj, auth.get("username"))
cert_dir_path = os.path.join(SUPER_SIGN_ROOT, cert_dir_name)
if not os.path.isdir(cert_dir_path):
os.makedirs(cert_dir_path)
file_format_path_name = os.path.join(cert_dir_path, cert_dir_name)
return file_format_path_name
def get_profile_full_path(developer_obj, app_obj):
cert_dir_name = make_app_uuid(developer_obj.user_id, developer_obj.email)
cert_dir_path = os.path.join(SUPER_SIGN_ROOT, cert_dir_name, "profile")
provisionName = os.path.join(cert_dir_path, app_obj.app_id)
return provisionName + '.mobileprovision'
def delete_app_to_dev_and_file(developer_obj, app_id):
APPToDeveloper_obj = APPToDeveloper.objects.filter(developerid=developer_obj, app_id_id=app_id)
if APPToDeveloper_obj:
binary_file = APPToDeveloper_obj.first().binary_file + ".ipa"
lsobj = LocalStorage("localhost", False)
lsobj.del_file(binary_file)
APPToDeveloper_obj.delete()
def delete_app_profile_file(developer_obj, app_obj):
try:
os.remove(get_profile_full_path(developer_obj, app_obj))
except Exception as e:
print(e)
def get_developer_udided(developer_obj):
SuperSignUsed_obj = APPSuperSignUsedInfo.objects.filter(developerid=developer_obj )
UDIDsyncDeveloper_obj = UDIDsyncDeveloper.objects.filter(developerid=developer_obj)
develoer_udid_lists=[]
supersign_udid_lists=[]
if UDIDsyncDeveloper_obj:
develoer_udid_lists=list(UDIDsyncDeveloper_obj.values_list("udid"))
if SuperSignUsed_obj:
supersign_udid_lists=list(SuperSignUsed_obj.values_list("udid__udid"))
return len(set(develoer_udid_lists)-set(supersign_udid_lists)),len(develoer_udid_lists)
def get_developer_devices(developer_obj_lists):
other_used_sum = 0
flyapp_used_sum = 0
for dev_obj in developer_obj_lists:
other_used, flyapp_used = get_developer_udided(dev_obj)
other_used_sum += other_used
flyapp_used_sum += flyapp_used
use_number_obj = developer_obj_lists.filter(is_actived=True)
if use_number_obj:
use_number_dict = use_number_obj.aggregate(usable_number=Sum('usable_number'), use_number=Sum('use_number'))
use_num = {
"all_usable_number": use_number_dict.get("usable_number", 0),
"all_use_number": use_number_dict.get("use_number", 0),
"other_used_sum": other_used_sum,
"flyapp_used_sum": flyapp_used_sum,
}
return use_num

@ -15,14 +15,10 @@ 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
from api.utils.serializer import AppsSerializer, AppReleaseSerializer, UserInfoSerializer,get_developer_devices
from api.models import Apps, AppReleaseInfo,APPToDeveloper
from api.utils.serializer import AppsSerializer, AppReleaseSerializer, UserInfoSerializer
from rest_framework.pagination import PageNumberPagination
# REDIS_CONN = redis.Redis(decode_responses=True)
class AppsPageNumber(PageNumberPagination):
page_size = 20 # 每页显示多少条
page_size_query_param = 'size' # URL中每页显示条数的参数

@ -8,10 +8,12 @@ from rest_framework.views import APIView
from api.utils.response import BaseResponse
from api.utils.auth import ExpiringTokenAuthentication
from rest_framework.response import Response
from api.models import AppIOSDeveloperInfo,APPSuperSignUsedInfo,AppUDID,UDIDsyncDeveloper
from api.utils.serializer import DeveloperSerializer, SuperSignUsedSerializer,DeviceUDIDSerializer,get_developer_devices
from api.models import AppIOSDeveloperInfo,APPSuperSignUsedInfo,AppUDID
from api.utils.serializer import DeveloperSerializer, SuperSignUsedSerializer,DeviceUDIDSerializer
from rest_framework.pagination import PageNumberPagination
from api.utils.app.supersignutils import IosUtils
from api.utils.utils import get_developer_devices
from api.utils.storage.caches import developer_auth_code
@ -54,28 +56,28 @@ class DeveloperView(APIView):
if act:
res = BaseResponse()
if act == "preactive":
if not IosUtils.active_developer(developer_obj):
res.code = 1008
res.msg = "开发者账户或密码有误"
return Response(res.dict)
developer_auth_code("del", request.user, developer_obj.email)
status,result = IosUtils.active_developer(developer_obj,request.user)
if status:
return self.get(request)
else:
res.code = 1009
res.code = 1008
res.msg = result.get("return_info")
return Response(res.dict)
elif act == "nowactive" :
code = data.get("code", None)
if code:
if IosUtils.active_developer(developer_obj,code):
developer_obj.is_actived=True
developer_obj.save()
if developer_obj.certid and len(developer_obj.certid) > 6:
pass
else:
IosUtils.create_developer_cert(developer_obj,request.user)
IosUtils.get_device_from_developer(developer_obj, request.user)
developer_auth_code("set",request.user,developer_obj.email,code)
elif act == "ioscert":
if not developer_obj.certid:
IosUtils.create_developer_cert(developer_obj, request.user)
status,result=IosUtils.create_developer_cert(developer_obj, request.user)
if status:
IosUtils.get_device_from_developer(developer_obj, request.user)
else:
res.code = 1008
res.msg = result.get("err_info")
return Response(res.dict)
elif act == "syncdevice":
IosUtils.get_device_from_developer(developer_obj,request.user)

@ -242,7 +242,8 @@ CACHE_KEY_TEMPLATE={
'download_url_key':'download_url',
'user_storage_key':'storage_auth',
'user_auth_token_key':'user_auth_token',
'download_today_times_key':'download_today_times'
'download_today_times_key':'download_today_times',
'developer_auth_code_key': 'developer_auth_code',
}
SYNC_CACHE_TO_DATABASE={

Loading…
Cancel
Save