Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

外网屏蔽admin页面 #291

Merged
merged 2 commits into from
Oct 26, 2016
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions Aries/Aries/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -306,3 +306,8 @@
POLL_TIME = 600
import sumSpace
sumSpace.run(POLL_TIME)

#admin页面白名单IP
PERMISSION_SETTINGS = SETTINGS['PERMISSION']
PERMISSION_IP_1 = PERMISSION_SETTINGS['PERMISSION_IP_1']
PERMISSION_IP_2 = PERMISSION_SETTINGS['PERMISSION_IP_2']
3 changes: 2 additions & 1 deletion Aries/Aries/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
admin.autodiscover()
import views
urlpatterns = [
url(r'^admin/', include(admin.site.urls)),
#url(r'^admin/', include(admin.site.urls)),
url(r'^admin/', views.permission_check),
url(r'^v1/user_auth/', include('user_auth.urls')),
url(r'^v1/hdfs/', include('hdfs.urls')),
url(r'^v1/codis/', include('codis.urls')),
Expand Down
15 changes: 15 additions & 0 deletions Aries/Aries/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from user_auth.models import *
from ldap_client import ldap_get_vaild
from django.views.decorators.csrf import ensure_csrf_cookie
from django.conf import settings

def is_admin(account,cur_space_in):
is_supper = 0
Expand Down Expand Up @@ -170,3 +171,17 @@ def index(request):
user = ""
user = json.dumps(user)
return render_to_response('index/index.html',locals())

def permission_check(request):
from django.contrib import admin
from django.conf.urls import patterns,url,include
import urls
admin.autodiscover()
if request.META.has_key('HTTP_X_FORWARDED_FOR'):
ip = request.META['HTTP_X_FORWARDED_FOR']
else:
ip = request.META['REMOTE_ADDR']
if not ip.startswith(settings.PERMISSION_IP_1) and not ip.startswith(settings.PERMISSION_IP_2):
return HttpResponse('<h2>Outer Net Is Not Allowed</h2>')
else:
urls.urlpatterns[0] = url(r'^admin/', include(admin.site.urls))
3 changes: 3 additions & 0 deletions sbin/Aries.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,6 @@ OPENSTACK:
IP_CINDER: "192.168.190.11"
PORT_CINDER: 8776

PERMISSION:
PERMISSION_IP_1: "192."
PERMISSION_IP_2: "10."
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

你这里设计的这个配置项的格式不太合适吧……可以考虑下面的方式:

PERMISSION:
    WHITE_LIST = [ '192.' , '10.' ]
    BLACK_LIST = []                 # 如果以后要扩展黑名单的话,可以考虑再加个这个东西