Fix remote addr with proxy, add VPN usage detection

master
Alice 8 years ago
parent 90ac2baf98
commit ea65a55bc7

@ -1,8 +1,13 @@
from django.conf import settings from django.conf import settings
from ccvpn.common import get_client_ip
from lambdainst.core import is_vpn_gateway
def some_settings(request): def some_settings(request):
client_ip = get_client_ip(request)
return { return {
'CLIENT_IP': client_ip,
'CLIENT_ON_VPN': is_vpn_gateway(client_ip),
'ROOT_URL': settings.ROOT_URL, 'ROOT_URL': settings.ROOT_URL,
'ADDITIONAL_HTML': settings.ADDITIONAL_HTML, 'ADDITIONAL_HTML': settings.ADDITIONAL_HTML,
'ADDITIONAL_HEADER_HTML': settings.ADDITIONAL_HEADER_HTML, 'ADDITIONAL_HEADER_HTML': settings.ADDITIONAL_HEADER_HTML,

@ -180,6 +180,9 @@ TICKETS_SITE_NAME = 'CCrypto VPN Support'
# Full URL to the site root # Full URL to the site root
ROOT_URL = '' ROOT_URL = ''
# Forwarded for header name, if any (None will use remote_addr)
REAL_IP_HEADER_NAME = None
# reCAPTCHA API details. If empty, no captcha is displayed. # reCAPTCHA API details. If empty, no captcha is displayed.
RECAPTCHA_API = 'https://www.google.com/recaptcha/api/siteverify' RECAPTCHA_API = 'https://www.google.com/recaptcha/api/siteverify'
RECAPTCHA_SITE_KEY = '' RECAPTCHA_SITE_KEY = ''

@ -101,6 +101,30 @@ def get_locations():
return locations return locations
@APICache(initial=lambda: [])
def get_gateway_exit_ips():
gateways = core_api.get('/gateways/', enabled=True)
ipv4_list = []
ipv6_list = []
for gw in gateways.list_iter():
ma = gw['main_addr']
if ma.get('ipv4'):
ipv4_list.append(ma['ipv4'])
if ma.get('ipv6'):
ipv6_list.append(ma['ipv6'])
# TODO: IPv6 support
return ipv4_list
def is_vpn_gateway(ip):
addresses = get_gateway_exit_ips()
print(addresses)
return ip in addresses
def create_user(username, cleartext_password): def create_user(username, cleartext_password):
""" The password will be hashed and stored safely on the core, """ The password will be hashed and stored safely on the core,
so we have to send it clearly here. so we have to send it clearly here.

@ -27,6 +27,7 @@ from django.contrib.auth.models import User
from django_countries import countries from django_countries import countries
import lcoreapi import lcoreapi
from ccvpn.common import get_client_ip
from payments.models import ACTIVE_BACKENDS from payments.models import ACTIVE_BACKENDS
from .forms import SignupForm, ReqEmailForm from .forms import SignupForm, ReqEmailForm
from .models import GiftCode, VPNUser from .models import GiftCode, VPNUser
@ -189,7 +190,7 @@ def captcha_test(grr, request):
return True return True
data = dict(secret=project_settings.RECAPTCHA_SECRET_KEY, data = dict(secret=project_settings.RECAPTCHA_SECRET_KEY,
remoteip=request.META['REMOTE_ADDR'], remoteip=get_client_ip(request),
response=grr) response=grr)
try: try:

@ -75,10 +75,17 @@
{% endblock %} {% endblock %}
<footer id="footer"> <footer id="footer">
<p><a href="//ccrypto.org/">Cognitive Cryptography</a> <p>
- <a href="https://twitter.com/CCrypto_VPN">{% trans 'CCrypto_VPN on Twitter' %}</a> {% if CLIENT_ON_VPN %}
- <a href="/page/tos">{% trans 'ToS' %}</a> <b>{% trans "You are using the VPN." %}</b>
- <a href="https://github.com/CCrypto/ccvpn3">{% trans "It's open-source!" %}</a> {% endif %}
{% trans "Your IP address: " %}
{{ CLIENT_IP }}
<br />
<a href="//ccrypto.org/">Cognitive Cryptography</a>
- <a href="https://twitter.com/CCrypto_VPN">{% trans 'CCrypto_VPN on Twitter' %}</a>
- <a href="/page/tos">{% trans 'ToS' %}</a>
- <a href="https://github.com/CCrypto/ccvpn3">{% trans "It's open-source!" %}</a>
</p> </p>
</footer> </footer>

@ -5,6 +5,7 @@ from django.utils import timezone
from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger
from django.utils.translation import ugettext as _ from django.utils.translation import ugettext as _
from ccvpn.common import get_client_ip
from .models import Ticket, TicketMessage from .models import Ticket, TicketMessage
from .forms import NewTicketForm, ReplyForm, StaffReplyForm from .forms import NewTicketForm, ReplyForm, StaffReplyForm
@ -82,7 +83,7 @@ def new(request):
message=form.cleaned_data['message']) message=form.cleaned_data['message'])
if not request.user.is_staff: if not request.user.is_staff:
firstmsg.remote_addr = request.META['REMOTE_ADDR'] firstmsg.remote_addr = get_client_ip(request)
firstmsg.save() firstmsg.save()
@ -151,7 +152,7 @@ def view(request, id):
**form.cleaned_data) **form.cleaned_data)
if not request.user.is_staff: if not request.user.is_staff:
msg.remote_addr = request.META['REMOTE_ADDR'] msg.remote_addr = get_client_ip(request)
msg.save() msg.save()

Loading…
Cancel
Save