diff --git a/fabfile/locale.py b/fabfile/locale.py index 7c577b3d8a..4b653d9490 100644 --- a/fabfile/locale.py +++ b/fabfile/locale.py @@ -34,7 +34,7 @@ def pull(): def compile(): """Compile po files. """ - local('django-admin.py compilemessages && cd seahub/two_factor && django-admin.py compilemessages') + local('django-admin.py compilemessages && pushd seahub/two_factor && django-admin.py compilemessages && popd && pushd seahub/trusted_ip && django-admin.py compilemessages') ########## utility functions def _inplace_change(filename, old_string, new_string): diff --git a/seahub/auth/middleware.py b/seahub/auth/middleware.py index a5a9b1a491..ebf7f92829 100644 --- a/seahub/auth/middleware.py +++ b/seahub/auth/middleware.py @@ -1,15 +1,6 @@ # Copyright (c) 2012-2016 Seafile Ltd. -import json - from django.contrib import auth from django.core.exceptions import ImproperlyConfigured -from django.core.urlresolvers import reverse -from django.http import HttpResponse, HttpResponseRedirect, HttpResponseForbidden -from django.shortcuts import render_to_response - -from seahub.utils.ip import get_remote_ip -from seahub.trusted_ip.models import TrustedIP -from seahub.settings import ENABLE_LIMIT_IPADDRESS, TRUSTED_IP_LIST class LazyUser(object): @@ -20,23 +11,6 @@ class LazyUser(object): return request._cached_user -class LimitIpMiddleware(object): - def process_request(self, request): - ip = get_remote_ip(request) - if ENABLE_LIMIT_IPADDRESS: - if not TrustedIP.objects.match_ip(ip) and ip not in TRUSTED_IP_LIST: - if "api2/" in request.path or "api/v2.1/" in request.path: - return HttpResponse( - json.dumps({"err_msg": "you can't login, because IP \ - address was not in range"}), - status=403, - content_type='application/json; charset=utf-8' - ) - else: - return render_to_response('403_trusted_ip.html', status=403) - return None - - class AuthenticationMiddleware(object): def process_request(self, request): assert hasattr(request, 'session'), "The Django authentication middleware requires session middleware to be installed. Edit your MIDDLEWARE_CLASSES setting to insert 'django.contrib.sessions.middleware.SessionMiddleware'." diff --git a/seahub/settings.py b/seahub/settings.py index 5c1888a24e..1611977ff3 100644 --- a/seahub/settings.py +++ b/seahub/settings.py @@ -113,7 +113,6 @@ MIDDLEWARE_CLASSES = ( 'django.middleware.common.CommonMiddleware', 'django.middleware.csrf.CsrfViewMiddleware', 'django.contrib.messages.middleware.MessageMiddleware', - 'seahub.auth.middleware.LimitIpMiddleware', 'seahub.auth.middleware.AuthenticationMiddleware', 'seahub.base.middleware.BaseMiddleware', 'seahub.base.middleware.InfobarMiddleware', @@ -122,6 +121,7 @@ MIDDLEWARE_CLASSES = ( 'seahub.base.middleware.UserPermissionMiddleware', 'termsandconditions.middleware.TermsAndConditionsRedirectMiddleware', 'seahub.two_factor.middleware.OTPMiddleware', + 'seahub.trusted_ip.middleware.LimitIpMiddleware', ) SITE_ROOT_URLCONF = 'seahub.urls' @@ -179,6 +179,7 @@ LANGUAGES = ( LOCALE_PATHS = ( os.path.join(PROJECT_ROOT, 'locale'), os.path.join(PROJECT_ROOT, 'seahub/two_factor/locale'), + os.path.join(PROJECT_ROOT, 'seahub/trusted_ip/locale'), ) TEMPLATE_CONTEXT_PROCESSORS = ( diff --git a/seahub/templates/js/sysadmin-templates.html b/seahub/templates/js/sysadmin-templates.html index 3adfba0436..9b4f74f68c 100644 --- a/seahub/templates/js/sysadmin-templates.html +++ b/seahub/templates/js/sysadmin-templates.html @@ -210,9 +210,7 @@ <% } %> <% if (app.pageOptions.is_pro & app.pageOptions.enable_limit_ipaddress) { %> -