CCrypto VPN public website https://vpn.ccrypto.org/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

87 lines
2.6 KiB

  1. import os.path
  2. import markdown
  3. from django.http import HttpResponseNotFound
  4. from django.shortcuts import render
  5. from django.conf import settings
  6. from django.utils.translation import ugettext as _, get_language
  7. from django import http
  8. from django.utils.http import is_safe_url
  9. from django.utils.translation import (
  10. LANGUAGE_SESSION_KEY, check_for_language,
  11. )
  12. from constance import config
  13. from .common import get_price_float
  14. md = markdown.Markdown(extensions=['toc', 'meta', 'codehilite(noclasses=True)'])
  15. def index(request):
  16. eur = '%.2f' % get_price_float()
  17. return render(request, 'ccvpn/index.html', dict(eur_price=eur, motd=config.MOTD))
  18. def chat(request):
  19. if request.user.is_authenticated():
  20. username = request.user.username + '|cc'
  21. else:
  22. username = "cc?"
  23. ctx = dict(username=username, title=_("Live Chat"))
  24. return render(request, 'ccvpn/chat.html', ctx)
  25. def set_lang(request):
  26. """ django.views.i18n.set_language() with GET """
  27. next = request.GET.get('next', request.GET.get('next'))
  28. if not is_safe_url(url=next, host=request.get_host()):
  29. next = request.META.get('HTTP_REFERER')
  30. if not is_safe_url(url=next, host=request.get_host()):
  31. next = '/'
  32. response = http.HttpResponseRedirect(next)
  33. lang_code = request.GET.get('lang', None)
  34. if lang_code and check_for_language(lang_code):
  35. if hasattr(request, 'session'):
  36. request.session[LANGUAGE_SESSION_KEY] = lang_code
  37. else:
  38. response.set_cookie(settings.LANGUAGE_COOKIE_NAME, lang_code,
  39. max_age=settings.LANGUAGE_COOKIE_AGE,
  40. path=settings.LANGUAGE_COOKIE_PATH,
  41. domain=settings.LANGUAGE_COOKIE_DOMAIN)
  42. return response
  43. def page(request, name):
  44. basename = settings.PAGES_DIR + '/' + name
  45. username = request.user.username
  46. page_replace = {
  47. 'USERNAME': username or '[username]',
  48. }
  49. files = [
  50. basename + '.' + get_language() + '.md',
  51. basename + '.en.md',
  52. basename + '.md',
  53. ]
  54. for file in files:
  55. if not os.path.isfile(file):
  56. continue
  57. with open(file, encoding='utf8') as fh:
  58. page = fh.read()
  59. for s, r in page_replace.items():
  60. page = page.replace('{' + s + '}', r)
  61. page = md.convert(page)
  62. title = md.Meta.get('title', [None])[0]
  63. ctx = dict(content=page, title=title)
  64. return render(request, 'ccvpn/page.html', ctx)
  65. return HttpResponseNotFound()