https://github.com/fuhailong1998/djangoFileShareSite
- 内网传输,千兆网速跑满。
- 账号系统,安全保障。
- 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)