chenjunkai преди 7 години
родител
ревизия
6410a7a5b2
променени са 6 файла, в които са добавени 36 реда и са изтрити 47 реда
  1. 5 3
      Ansjer/test/666.py
  2. 4 21
      Ansjer/test/util/encryDownLoad.py
  3. 1 1
      Controller/AccessLog.py
  4. 7 18
      Controller/OTAEquipment.py
  5. 18 4
      Service/MiscellService.py
  6. 1 0
      Service/middleware.py

+ 5 - 3
Ansjer/test/666.py

@@ -1,4 +1,6 @@
+regp = '^/OTA/downloads/[.\w/]+$'
+import re
 
-for i in range(0, 500001):
-    print('\r' + str(i/10), end='') 
-print('33333333333')
+strs = '/OTA/downloads/IPC/18E2012008A/4.1.5/V4.1.5.18E2012008A.img'
+kkp = re.match(regp, strs, flags=0)
+print(kkp)

+ 4 - 21
Ansjer/test/util/encryDownLoad.py

@@ -55,29 +55,12 @@ def get_timestamp10():
     """获取当前时间长度为10位长度的时间戳"""
     return int(time.time())
 
-
-secret = 'ansjer';  # 密钥--对应#st的哈希格式为 secret+url+e,e为时间戳单位s,url为请求地址  secure_link_md5 xiaozhong.com$uri$arg_e;
-# path = '/hls/5553.mp4/index.m3u8'  # 下载文件
-# path = '/L59KVYDAEPHR1T6M111A_0/555666.mp4'  # 下载文件
-path = '/2213.txt'  # 下载文件
-# path = '/444.mp4'  # 下载文件
+url = 'http://192.168.136.45:8077'
+secret = 'ansjer';  # 密钥--对应#st的哈希格式为 secret+url+e,e为时间戳单位s,url为请求地址
+path = '/OTA/downloads/IPC/18E2012008A/4.1.5/V4.1.5.18E2012008A.img'  # 下载文件
 # 下载到期时间,time是当前时间,300表示300秒,也就是说从现在到300秒之内文件不过期
 expire = get_timestamp10() + 3600;
 res = md5(str(secret) + str(path) + str(expire), True)
 md5 = str(base64_encode(res, True))
 md5 = md5.replace('b\'', '').replace('\'', '').replace('+', '-').replace('/', '_').replace('=', '')
-print('io:','http://13.56.141.156:81'+path+'?' + 'st=' + str(md5) + '&e=' + str(expire))
-
-
-def getTimeDict(times):
-    time_dict = {}
-    t = 0
-    for x in range(24):
-        if x < 10:
-            x = '0' + str(x)
-        else:
-            x = str(x)
-        a = times.strftime("%Y-%m-%d") + " " + x + ":00:00"
-        time_dict[t] = timezone.datetime.strptime(a, '%Y-%m-%d %H:%M:%S')
-        t += 1
-    return time_dict
+print(url+path+'?' + 'st=' + str(md5) + '&e=' + str(expire))

+ 1 - 1
Controller/AccessLog.py

@@ -123,4 +123,4 @@ class AccessLog(View):
             else:
                 return ResponseJSON(404)
         else:
-            return ResponseJSON(444)
+            return ResponseJSON(444)

+ 7 - 18
Controller/OTAEquipment.py

@@ -266,26 +266,17 @@ def getUpdataFileUrlInterface(request,
                               *callback_args, **callback_kwargs):
     if request.method == "POST":
         request.encoding = 'utf-8'
-
-        code = request.POST.get('code', None)
-
-        if code is not None:
-            response = HttpResponse(getUpdataFileUrl(code))
-            return response
-        else:
-            return ResponseJSON(800)
+        request_dict = request.POST
     elif request.method == "GET":
         request.encoding = 'utf-8'
-        code = request.GET.get('code', None)
-
-        if code is not None:
-            response = HttpResponse(getUpdataFileUrl(code))
-            return response
-        else:
-            return ResponseJSON(800)
-
+        request_dict = request.GET
     else:
         return ResponseJSON(801)
+    code = request_dict.get('code', None)
+    if code is not None:
+        return HttpResponse(getUpdataFileUrl(code))
+    else:
+        return ResponseJSON(800)
 
 @csrf_exempt
 def downloadUpdataFileUrlInterface(request, fileType, fileName,
@@ -323,8 +314,6 @@ def downloadUpdataFileUrlInterface(request, fileType, fileName,
                     response['Content-Disposition'] = 'attachment; filename=%s' % os.path.basename(fullPath)
                     response['Content-MD5'] = getMD5orSHA265(fullPath)
                     #校验文件md5值
-                    # if response['Content-MD5'] ==
-                    # print(response['Content-MD5'])
                     response['Content-SHA265'] = getMD5orSHA265(fullPath, 'SHA265')
                     response['Content-CRC32'] = getMD5orSHA265(fullPath, 'CRC32')
                     response['Content-Error'] = JSON

+ 18 - 4
Service/MiscellService.py

@@ -82,7 +82,6 @@ class MiscellService():
 
     @staticmethod
     def add_access_log(request, status_code):
-        print('add_access_log')
         if request.method == 'GET':
             request_dict = request.GET
         if request.method == 'POST':
@@ -91,8 +90,6 @@ class MiscellService():
         api_list = TemplateService.log_api()
         request_path = request.path.strip().strip('/')
         if request_path in api_list:
-            print('yes_api')
-
             clientIP = CommonService.get_ip_address(request)
             now_time = datetime.datetime.utcnow().replace(tzinfo=utc).astimezone(utc)
             password = request_dict.get('userPwd', None)
@@ -187,4 +184,21 @@ class MiscellService():
             if json_data['code'] == 0:
                 if json_data['data']['country'] != 'XX':
                     country = json_data['data']['country']
-        return country
+        return country
+
+    # 下载接口添加访问日志
+    @staticmethod
+    def add_ota_download_log(request):
+        clientIP = CommonService.get_ip_address(request)
+        request_path = request.path.strip().strip('/')
+        now_time = datetime.datetime.utcnow().replace(tzinfo=utc).astimezone(utc)
+        add_data = {
+            'user': 'None',
+            'ip': clientIP,
+            'status': 200,
+            'url': request.META['SERVER_PROTOCOL'] + '-' + request.method + '-' + request.path,
+            'operation': request_path,
+            'time': now_time,
+            'content': ''
+        }
+        ModelService.addAccessLog(data=add_data)

+ 1 - 0
Service/middleware.py

@@ -29,6 +29,7 @@ class StatisticsUrlMiddleware(MiddlewareMixin):
             else:
                 adds = request.META.get('REMOTE_ADDR', None)
                 api_settings.ADDR_URL.append(adds)
+                MiscellService.add_ota_download_log(request=request)
                 return 0
 
     def _https_statistics_to_close(self, request):