tags:

views:

30

answers:

1

Hello

I am trying to specify the access to a certain django view only to a client calling from a VPN IP (10.8.0.3 )

My django server is supported by apache using the following .conf

<VirtualHost *>
    ServerAdmin [email protected]
    DocumentRoot /home/project/virtualenvs/env1
    ServerName client1.project.cl
    ServerAlias www.client1.project.cl
    ErrorLog /var/log/apache2/error.log
    CustomLog /var/log/apache2/access.log combined

<Location "/">
SetHandler python-program
PythonHandler virtualhandler
SetEnv DJANGO_SETTINGS_MODULE project.settings
PythonOption django.root
SetEnv SITE_CLIENT_ID client1
PythonDebug On
PythonPath "['/home/project/virtualenvs/env1/django-site','/home/project/virtualenvs/env1/bin'] + sys.path"
</Location>

Alias /media "/home/project/virtualenvs/env1/lib/python2.6/site-packages/django/contrib/admin/media/"

<Location /media>
    SetHandler None
</Location>

<Location /nodesaccess >
        order Deny,Allow
        Deny from all
        Allow from 10.8.0.3
        SetHandler python-program
        PythonHandler virtualhandler
        SetEnv DJANGO_SETTINGS_MODULE project.settings
        PythonOption django.root
        SetEnv SITE_CLIENT_ID client1
        PythonDebug On
        PythonPath "['/home/project/virtualenvs/env1/django-    site','/home/project/virtualenvs/env1/bin'] + sys.path"

</Location>


</VirtualHost>

This previous configuration allows to create many django applications depending of the url, I recover the env variable and then apache load a certain setting.py which is exclusive and depends of the subdomain. Very interesting

Everything works fine (my applications) except that the access can not be denied using the "Allow from 10.8.0.3"

Any ideas?

Thank you

A: 

You can use REMOTE_ADDR from HttpRequest.META (http://docs.djangoproject.com/en/dev/ref/request-response/) to check the requester IP in your view. And if it is different form the one you want just return 404 or 403 page.

Ilian Iliev
Thank you for your answer, I started to test that alternative and works perfect. The users which will call this private view will insert data through a django form post, so here another question. Can the request.Meta.Remote_addr be faked? I hope notThank you
jaime
You can sleep tight. Remote Address can be "faked" by using a proxy server that will mask clients real IP. But in your case you are using local IP so there is no chance someone from the outside world to request the page using this IP. Other way to restrict single view access is to use users.
Ilian Iliev