Fix remote addr with proxy, add VPN usage detection

master
Alice 7 years ago
parent 90ac2baf98
commit ea65a55bc7

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

@ -180,6 +180,9 @@ TICKETS_SITE_NAME = 'CCrypto VPN Support'
# Full URL to the site root
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 = 'https://www.google.com/recaptcha/api/siteverify'
RECAPTCHA_SITE_KEY = ''

@ -101,6 +101,30 @@ def get_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):
""" The password will be hashed and stored safely on the core,
so we have to send it clearly here.

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

@ -75,10 +75,17 @@
{% endblock %}
<footer id="footer">
<p><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>
{% if CLIENT_ON_VPN %}
<b>{% trans "You are using the VPN." %}</b>
{% 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>
</footer>

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

Loading…
Cancel
Save