The 42 Core Program final project, ft-transcendence. A modern web based Pong.
https://<REPLACE>/auth/
https://localhost/auth/
http://127.0.0.1:8000/auth/
CLIENT_ID: <REPLACE>
CLIENT_SECRET: <REPLACE>
HTTP_HOSTNAME: <REPLACE>
- https://localhost (reverse proxy to django)
- http://localhost:8080 (dbadmin)
#https://docs.djangoproject.com/en/5.0/ref/settings/#use-i18n
USE_I18N = True
#https://docs.djangoproject.com/en/5.0/ref/settings/#std-setting-LANGUAGES
from django.utils.translation import gettext_lazy as _
LANGUAGES = [
("de", _("German")),
("en", _("English")),
]
#https://docs.djangoproject.com/en/5.0/ref/settings/#locale-paths
LOCALE_PATHS = [
BASE_DIR / "locale/"
]
#https://docs.djangoproject.com/en/5.0/topics/i18n/translation/#how-django-discovers-language-preference
MIDDLEWARE = [
...
'django.contrib.sessions.middleware.SessionMiddleware', #after session
# after cache middleware
'django.middleware.locale.LocaleMiddleware',
'django.middleware.common.CommonMiddleware', #before common
...
]
#https://docs.djangoproject.com/en/4.2/topics/i18n/translation/#language-prefix-in-url-patterns
from django.conf.urls.i18n import i18n_patterns
urlpatterns += i18n_patterns(
path("about/", about_views.main, name="about"),
path("news/", include(news_patterns, namespace="news")),
)
# language-switcher part 1/2
# https://docs.djangoproject.com/en/4.2/topics/i18n/translation/#the-set-language-redirect-view
urlpatterns += [
path("i18n/", include("django.conf.urls.i18n")),
]
{% load i18n %}
<form action="{% url 'set_language' %}" method="post">{% csrf_token %}
<input name="next" type="hidden" value="{{ redirect_to }}">
<select name="language">
{% get_current_language as LANGUAGE_CODE %}
{% get_available_languages as LANGUAGES %}
{% get_language_info_list for LANGUAGES as languages %}
{% for language in languages %}
<option value="{{ language.code }}"{% if language.code == LANGUAGE_CODE %} selected{% endif %}>
{{ language.name_local }} ({{ language.code }})
</option>
{% endfor %}
</select>
<input type="submit" value="Go">
</form>
# https://docs.djangoproject.com/en/4.2/topics/i18n/translation/#translating-url-patterns
from django.urls import reverse
def logout_view():
# add Language prefix URL, eg /<LANG>/path, based on django_language cookie
return redirect(reverse("about"))
<!--https://docs.djangoproject.com/en/4.2/topics/i18n/translation/#internationalization-in-template-code-->
{% load i18n %}
<html>
<!--https://docs.djangoproject.com/en/4.2/topics/i18n/translation/#translate-template-tag-->
<h1>{% translate "This is the title." %}</h1>
<!--https://docs.djangoproject.com/en/4.2/topics/i18n/translation/#blocktranslate-template-tag-->
<p>
{% blocktranslate with amount=article.price %}
That will cost $ {{ amount }}.
{% endblocktranslate %}
</p>
<!--https://docs.djangoproject.com/en/4.2/topics/i18n/translation/#reversing-in-templates-->
<!-- from Language prefix URL, eg /<LANG>/path -->
<a href="{{ url "about" }}">localized URLs</a>
from .py/.html -> .po -> .mo
#step-0 rely on GNU gettext toolset & message file (.mo)
> apk add gettext
#step-1 from .py/.html to .po (locale/<LANG>/LC_MESSAGES/django.po)
#https://docs.djangoproject.com/en/4.2/topics/i18n/translation/#localization-how-to-create-language-files
> django-admin makemessages -l ms
processing locale ms
> django-admin makemessages -l zh_HAns
processing locale zh_HAns
> django-admin makemessages -a
processing locale ms
processing locale zh_HAns
#step-2 manually translate locale/<LANG>/LC_MESSAGES/django.po
#step-3 compile .po to .mo (locale/<LANG>/LC_MESSAGES/django.mo)
#https://docs.djangoproject.com/en/4.2/topics/i18n/translation/#compiling-message-files
> django-admin compilemessages
Will need to build 2 components from source code. compilation will require third party dependencies, which could be distro pacages or third party sources.
- libmodsecurity-v3
- NGINX modsecurity connector dynamic module
Refer to Compiling and Installing ModSecurity for NGINX Open Source for complete guidance, covering
- install development tools and dependency packages
- download and compile libmodsecurity v3
- download and compile NGINX Modsecurity Connector as dynamic module
- configure Nginx to load, enable and test Modsecurity
Note: built dynamic module may not work with nginx from distro, and may use nginx from nginx.org or build from source
Dockerize the process will need to
- find corresponding packages (eg alpine linux)
- optimize build process by RUN --mount=type=cache
- optimize final image by multi-stage build
Vault image (120MB+) from dockerhub is server(default dev-mode),cli,agent all in one executable.
Running as normal server will require generating unseal keys, which should be kepts separately and securely. These keys are needed to unseal the vault server if it is sealed (no access to service) manually for protection or automatically when restarted. Dockerize the process may need to automate generating, keeping, using the unseal keys. This can be done at separate docker container as Vault operator.
During the first setup after unseal keys, root token will be used to setup secret engines(eg Key/Val-v2), authentication methods(eg AppRole), and policies for different server roles, enable audit log.
For other times, it will unseal the Vault server when it is restarted, wihle keeping unseal keys unaccessible.
Vault agent will automate authenticating individul server for secret access, and may recycle old secret as well as restarting service if required.