基于Django的内网互传服务器

Leon
2021-08-03 / 0 评论 / 25 阅读 / 正在检测是否收录...

https://github.com/fuhailong1998/djangoFileShareSite

  1. 内网传输,千兆网速跑满。
  2. 账号系统,安全保障。
  3. IP中间件屏蔽,进一步安全。
   # !/usr/bin/env python3
   # -*- coding:utf-8 -*-
   """
   @file        : middlewares.py
   @author      : Leon(fxkxb.com)
   @date        : 2021/8/3 03:21
   @description : 
   """
   from django.shortcuts import render
   from django.utils.deprecation import MiddlewareMixin


   class IpMiddleware(MiddlewareMixin):
       def process_view(self, request, view_func, *view_args, **view_kwargs):
           EXCLUDE_IPS = ['*']
           if 'HTTP_X_FORWARDED_FOR' in request.META:
               ip = request.META['HTTP_X_FORWARDED_FOR']
           else:
               ip = request.META['REMOTE_ADDR']
           if EXCLUDE_IPS[0] == '*':
               return
           if ip not in EXCLUDE_IPS:
               return render(request, 'sorry.html')
0

评论 (0)

取消