├── .art ├── django-18.0-admin.png ├── django-18.0-docs.png ├── django-18.0-landing.png ├── django-18.0-webmin-dashboard.png ├── django-18.0-webmin-landing-tklbam.png ├── django-18.0-webmin-login.png ├── django-18.0-webmin-terminal.png └── logo.png ├── .gitignore ├── Makefile ├── README.rst ├── changelog ├── conf.d └── main ├── overlay ├── etc │ └── apache2 │ │ └── sites-available │ │ └── django.conf ├── usr │ └── lib │ │ └── inithooks │ │ ├── bin │ │ └── django.py │ │ └── firstboot.d │ │ ├── 20regen-django-secrets │ │ └── 40django └── var │ ├── lib │ └── django │ │ └── allowed_hosts │ └── www │ ├── app_urls.py │ ├── app_views.py │ ├── images │ └── django.png │ ├── proj_urls.py │ └── templates │ └── index.html └── plan └── main /.art/django-18.0-admin.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/turnkeylinux-apps/django/47bb16522a9a860f9163dab455e8044d0afc7095/.art/django-18.0-admin.png -------------------------------------------------------------------------------- /.art/django-18.0-docs.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/turnkeylinux-apps/django/47bb16522a9a860f9163dab455e8044d0afc7095/.art/django-18.0-docs.png -------------------------------------------------------------------------------- /.art/django-18.0-landing.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/turnkeylinux-apps/django/47bb16522a9a860f9163dab455e8044d0afc7095/.art/django-18.0-landing.png -------------------------------------------------------------------------------- /.art/django-18.0-webmin-dashboard.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/turnkeylinux-apps/django/47bb16522a9a860f9163dab455e8044d0afc7095/.art/django-18.0-webmin-dashboard.png -------------------------------------------------------------------------------- /.art/django-18.0-webmin-landing-tklbam.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/turnkeylinux-apps/django/47bb16522a9a860f9163dab455e8044d0afc7095/.art/django-18.0-webmin-landing-tklbam.png -------------------------------------------------------------------------------- /.art/django-18.0-webmin-login.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/turnkeylinux-apps/django/47bb16522a9a860f9163dab455e8044d0afc7095/.art/django-18.0-webmin-login.png -------------------------------------------------------------------------------- /.art/django-18.0-webmin-terminal.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/turnkeylinux-apps/django/47bb16522a9a860f9163dab455e8044d0afc7095/.art/django-18.0-webmin-terminal.png -------------------------------------------------------------------------------- /.art/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/turnkeylinux-apps/django/47bb16522a9a860f9163dab455e8044d0afc7095/.art/logo.png -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | build 2 | *.pyc 3 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | COMMON_OVERLAYS = tkl-webcp 2 | COMMON_CONF = tkl-webcp 3 | 4 | include $(FAB_PATH)/common/mk/turnkey/mysql.mk 5 | include $(FAB_PATH)/common/mk/turnkey/apache.mk 6 | include $(FAB_PATH)/common/mk/turnkey.mk 7 | -------------------------------------------------------------------------------- /README.rst: -------------------------------------------------------------------------------- 1 | Django - High-level Python Web Framework 2 | ======================================== 3 | 4 | `Django`_ is a high-level Python Web framework that encourages rapid 5 | development and clean, pragmatic design. Python's equivalent to the 6 | famous Ruby on rails, Django lets you build high-performing, elegant Web 7 | applications quickly. Django focuses on automating as much as possible 8 | and adhering to the "Don't Repeat Yourself" (DRY) principle. 9 | 10 | This appliance includes all the standard features in `TurnKey Core`_, 11 | and on top of that: 12 | 13 | - SSL support out of the box. 14 | - Preconfigured example Django project located at /var/www/turnkey_project 15 | 16 | - Integrated with Apache2 (mod\_wsgi), MySQL and Postfix. 17 | - Built-in administration console with embedded online documentation. 18 | 19 | - Python3 build of Django installed from Debian repos (security) 20 | - iPython for enhanced Django shell interaction. 21 | - Webmin modules for configuring Apache2, and MySQL. 22 | 23 | Credentials *(passwords set at first boot)* 24 | ------------------------------------------- 25 | 26 | - Webmin, SSH, MySQL: username **root** 27 | - Django admin console: username **admin** 28 | 29 | .. _Django: http://www.djangoproject.com/ 30 | .. _TurnKey Core: https://www.turnkeylinux.org/core 31 | -------------------------------------------------------------------------------- /changelog: -------------------------------------------------------------------------------- 1 | turnkey-django-18.1 (1) turnkey; urgency=low 2 | 3 | * TODO - ADD OTHER RELEASE NOTES HERE... 4 | 5 | * Remove webshell link from landing page - closes 1927. 6 | 7 | -- Jeremy Davis Wed, 10 Apr 2024 23:24:27 +0000 8 | 9 | turnkey-django-18.0 (1) turnkey; urgency=low 10 | 11 | * Upgraded to latest Bookworm version of Django (3.2.19). 12 | [Anton Pyrogovskyi ] 13 | 14 | * Ensure hashfile includes URL to public key - closes #1864. 15 | 16 | * Include webmin-logviewer module by default - closes #1866. 17 | 18 | * Upgraded base distribution to Debian 12.x/Bookworm. 19 | 20 | * Configuration console (confconsole): 21 | - Support for DNS-01 Let's Encrypt challenges. 22 | [ Oleh Dmytrychenko github: @NitrogenUA ] 23 | - Support for getting Let's Encrypt cert via IPv6 - closes #1785. 24 | - Refactor network interface code to ensure that it works as expected and 25 | supports more possible network config (e.g. hotplug interfaces & wifi). 26 | - Show error message rather than stacktrace when window resized to 27 | incompatable resolution - closes #1609. 28 | [ Stefan Davis ] 29 | - Bugfix exception when quitting configuration of mail relay. 30 | [ Oleh Dmytrychenko github: @NitrogenUA ] 31 | - Improve code quality: implement typing, fstrings and make (mostly) PEP8 32 | compliant. 33 | [Stefan Davis & Jeremy Davis 34 | 35 | * Firstboot Initialization (inithooks): 36 | - Refactor start up (now hooks into getty process, rather than having it's 37 | own service). 38 | [ Stefan Davis ] 39 | - Refactor firstboot.d/01ipconfig (and 09hostname) to ensure that hostname 40 | is included in dhcp info when set via inithooks. 41 | - Package turnkey-make-ssl-cert script (from common overlay - now packaged 42 | as turnkey-ssl). Refactor relevant scripts to leverage turnkey-ssl. 43 | - Refactor run script - use bashisms and general tidying. 44 | - Show blacklisted password characters more nicely. 45 | - Misc packaging changes/improvements. 46 | - Support returning output from MySQL - i.e. support 'SELECT'. (Only 47 | applies to apps that include MySQL/MariaDB). 48 | 49 | * Web management console (webmin): 50 | - Upgraded webmin to v2.105. 51 | - Removed stunnel reverse proxy (Webmin hosted directly now). 52 | - Ensure that Webmin uses HTTPS with default cert 53 | (/etc/ssl/private/cert.pem). 54 | - Disabled Webmin Let's Encrypt (for now). 55 | 56 | * Web shell (shellinabox): 57 | - Completely removed in v18.0 (Webmin now has a proper interactive shell). 58 | 59 | * Backup (tklbam): 60 | - Ported dependencies to Debian Bookworm; otherwise unchanged. 61 | 62 | * Security hardening & improvements: 63 | - Generate and use new TurnKey Bookworm keys. 64 | - Automate (and require) default pinning for packages from Debian 65 | backports. Also support non-free backports. 66 | 67 | * IPv6 support: 68 | - Adminer (only on LAMP based apps) listen on IPv6. 69 | - Nginx/NodeJS (NodeJS based apps only) listen on IPv6. 70 | 71 | * Misc bugfixes & feature implementations: 72 | - Remove rsyslog package (systemd journal now all that's needed). 73 | - Include zstd compression support. 74 | - Enable new non-free-firmware apt repo by default. 75 | - Improve turnkey-artisan so that it works reliably in cron jobs (only 76 | Laravel based LAMP apps). 77 | 78 | * Use MariaDB (MySQL replacement) v10.11.3 (from debian repos). 79 | 80 | * Set mod_evasive log location - makes debugging easier. 81 | [ Jeremy Davis ] 82 | 83 | * Include and enable mod_evasive and mod_security2 by default in Apache. 84 | [ Stefan Davis ] 85 | 86 | -- Jeremy Davis Mon, 05 Feb 2024 06:55:05 +0000 87 | 88 | turnkey-django-17.1 (1) turnkey; urgency=low 89 | 90 | * Updated all Debian packages to latest. 91 | [ autopatched by buildtasks ] 92 | 93 | * Patched bugfix release. Closes #1734. 94 | [ autopatched by buildtasks ] 95 | 96 | -- Jeremy Davis Tue, 12 May 2022 01:41:55 +0000 97 | 98 | turnkey-django-17.0 (1) turnkey; urgency=low 99 | 100 | * Upgraded to latest Bullseye version of Django (2.2.25). 101 | 102 | * Updated all relevant Debian packages to Bullseye/11 versions 103 | 104 | * Note: Please refer to turnkey-core's 17.0 changelog for changes common to all 105 | appliances. Here we only describe changes specific to this appliance. 106 | 107 | -- Stefan Davis Thu, 24 Mar 2022 05:46:54 +0000 108 | 109 | turnkey-django-16.1 (1) turnkey; urgency=low 110 | 111 | * Rebuild on latest Debian Buster. 112 | 113 | * Note: Please refer to turnkey-core's 16.1 changelog for changes common to 114 | all appliances. Here we only describe changes specific to this appliance. 115 | 116 | -- Jeremy Davis Thu, 01 Apr 2021 17:26:14 +1100 117 | 118 | turnkey-django-16.0 (1) turnkey; urgency=low 119 | 120 | * Upgraded to latest Buster version of Django (1.11.28). 121 | 122 | * Explcitly disable TLS<1.2 (i.e. SSLv3, TLSv1, TLSv1.1). (v15.x 123 | TurnKey releases supported TLS 1.2, but could fallback as low as TLSv1). 124 | 125 | * Update SSL/TLS cyphers to provide "Intermediate" browser/client support 126 | (suitable for "General-purpose servers with a variety of clients, 127 | recommended for almost all systems"). As provided by Mozilla via 128 | https://ssl-config.mozilla.org/. 129 | 130 | * Updated all relevant Debian packages to Buster/10 versions; including 131 | PHP 7.3. 132 | 133 | * Updated version of mysqltuner script - now installed as per upstream 134 | recommendation. 135 | 136 | * Note: Please refer to turnkey-core's changelog for changes common to all 137 | appliances. Here we only describe changes specific to this appliance. 138 | 139 | -- Stefan Davis Wed, 18 Mar 2020 16:47:32 +1100 140 | 141 | turnkey-django-15.1 (1) turnkey; urgency=low 142 | 143 | * Rebuild to resolve inadvertant removal of mariadb during sec-updates 144 | - part of #1246. 145 | 146 | -- Jeremy Davis Thu, 22 Nov 2018 11:19:26 +1100 147 | 148 | turnkey-django-15.0 (1) turnkey; urgency=low 149 | 150 | * Upgraded to Python3 Django 151 | 152 | * Upgraded to latest Stretch version of Django (1.10.7). 153 | 154 | * Replace MySQL with MariaDB 155 | 156 | * Note: Please refer to turnkey-core's changelog for changes common to all 157 | appliances. Here we only describe changes specific to this appliance. 158 | 159 | -- Vlad Kuzmenko Wed, 17 Feb 2017 13:18:42 +0200 160 | 161 | turnkey-django-14.2 (1) turnkey; urgency=low 162 | 163 | * Installed security updates. 164 | 165 | * Note: Please refer to turnkey-core's changelog for changes common to all 166 | appliances. Here we only describe changes specific to this appliance. 167 | 168 | -- Jeremy Davis Wed, 03 May 2017 09:02:10 +1000 169 | 170 | turnkey-django-14.1 (1) turnkey; urgency=low 171 | 172 | * Installed security updates. 173 | 174 | * Installed updated packages from TurnKey repo 175 | - includes relevant Webmin packages (v1.780) 176 | 177 | * Note: Please refer to turnkey-core's changelog for changes common to all 178 | appliances. Here we only describe changes specific to this appliance. 179 | 180 | -- Jeremy Davis Tue, 01 Mar 2016 16:28:44 +1100 181 | 182 | turnkey-django-14.0 (1) turnkey; urgency=low 183 | 184 | * Upgraded to latest Jessie version of Django (1.7.7). 185 | 186 | * Complete rewrite of TurnKey example app following Django docs. 187 | 188 | * Hardened default SSL settings 189 | 190 | * Note: Please refer to turnkey-core's changelog for changes common to all 191 | appliances. Here we only describe changes specific to this appliance. 192 | 193 | -- Jeremy Davis Thu, 25 Jun 2015 15:55:58 +1000 194 | 195 | turnkey-django-13.0 (1) turnkey; urgency=low 196 | 197 | * Django: 198 | 199 | - Latest Debian Wheezy package version of Django. 200 | - Updated legacy settings [#65, #117]. 201 | - Removed hardcoded version in online documentation link. 202 | 203 | * Note: Please refer to turnkey-core's changelog for changes common to all 204 | appliances. Here we only describe changes specific to this appliance. 205 | 206 | -- Alon Swartz Thu, 10 Oct 2013 17:42:13 +0300 207 | 208 | turnkey-django-12.1 (1) turnkey; urgency=low 209 | 210 | * Latest upstream source version of Django. 211 | 212 | * Note: Please refer to turnkey-core's changelog for changes common to all 213 | appliances. Here we only describe changes specific to this appliance. 214 | 215 | -- Alon Swartz Sun, 07 Apr 2013 08:00:00 +0200 216 | 217 | turnkey-django-12.0 (1) turnkey; urgency=low 218 | 219 | * Django: 220 | 221 | - Upgraded to latest upstream package. 222 | - Database name and username changed to 'django' (simplicity). 223 | 224 | * Added ipython (convenience). 225 | 226 | * Major component versions 227 | 228 | python-django 1.2.3-3+squeeze2 229 | apache2 2.2.16-6+squeeze7 230 | mysql-server 5.1.63-0+squeeze1 231 | phpmyadmin 4:3.3.7-7 232 | 233 | * Note: Please refer to turnkey-core's changelog for changes common to all 234 | appliances. Here we only describe changes specific to this appliance. 235 | 236 | -- Alon Swartz Wed, 01 Aug 2012 08:00:00 +0200 237 | 238 | turnkey-django-11.3 (1) turnkey; urgency=low 239 | 240 | * Installed security updates. 241 | * Enabled etckeeper garbage collection by default. 242 | * Upgraded to latest inithooks version (adhoc re-initialization via turnkey-init) 243 | 244 | -- Alon Swartz Mon, 05 Dec 2011 10:48:44 +0000 245 | 246 | turnkey-django-11.2 (1) turnkey; urgency=low 247 | 248 | * Installed security updates. 249 | * Added HubDNS package and firstboot configuration. 250 | 251 | -- Alon Swartz Fri, 15 Jul 2011 07:47:08 +0000 252 | 253 | turnkey-django-11.1 (1) turnkey; urgency=low 254 | 255 | * Django: 256 | 257 | - Transitioned to mod_wsgi from mod_python (performance). 258 | - Tweaked settings.py to be more dynamic. 259 | - Configured email settings. 260 | - Added settings_dev.py (sets DEBUG=y and uses SQLite if DEVELOPMENT=y). 261 | 262 | - Completely restructured Django project: 263 | - Project moved to /var/www/project (was /var/www/django-sites[/apps]). 264 | - Admin symlink moved to /media/admin from admin_media. 265 | - Apache site renamed to django (was django-sites). 266 | 267 | - Added python-django-doc and configured for offline access. 268 | 269 | * Set Django admin email and password on firstboot (convenience, security). 270 | 271 | * Set MySQL root password on firstboot (convenience, security). 272 | 273 | * Force MySQL to use Unicode/UTF8. 274 | 275 | * Set postfix MTA myhostname to localhost (bugfix). 276 | 277 | * Major component versions: 278 | 279 | python-django 1.1.1-2ubuntu1 280 | mysql-server 5.1.41-3ubuntu12.8 281 | sqlite 2.8.17-6build2 282 | apache2 2.2.14-5ubuntu8.4 283 | python2.6 2.6.5-1ubuntu6 284 | 285 | * Note: Please refer to turnkey-core's changelog for changes common to all 286 | appliances. Here we only describe changes specific to this appliance. 287 | 288 | -- Alon Swartz Sun, 19 Dec 2010 15:01:05 +0200 289 | 290 | turnkey-django-2009.10 (2) hardy; urgency=low 291 | 292 | * Installed all security updates (see manifest for package versions). 293 | 294 | * Install security updates on firstboot (except when running live). 295 | 296 | * Bugfix: Updated apt preferences for auto-security updates (LP#550307). 297 | 298 | * Trick webmin into not checking for upgrades (managed by apt). 299 | 300 | * Updated di-live mysql mechanism and secret regeneration. 301 | 302 | * Included latest version of inithooks and updated scripts. 303 | 304 | * Included wget as per common request. 305 | 306 | -- Alon Swartz Mon, 29 Mar 2010 09:02:11 +0200 307 | 308 | turnkey-django-2009.10 (1) hardy; urgency=low 309 | 310 | * Upgraded Django and pinned to update directly from Debian (security). 311 | 312 | * Added Turnkey web control panel (replaces welcome page). Also provides 313 | example Django application using template and static media urls. 314 | 315 | * Added postfix MTA (bound to localhost) to allow sending of email from 316 | web applications (e.g., password recovery). Also added webmin-postfix 317 | module for convenience. 318 | 319 | * di-live (installer) MySQL component: 320 | 321 | - Added support for complex passwords (LP#416515) 322 | - Added CLI options (user/pass/query/chroot) 323 | 324 | * Bugfix: Removed build systems hostname from mysql user table. 325 | 326 | * Regenerates all secrets during installation / firstboot (security). 327 | 328 | * Major component versions: 329 | 330 | python-django 1.0.2-1+lenny1 331 | mysql-server 5.0.51a-3ubuntu5.4 332 | apache2 2.2.8-1ubuntu0.11 333 | python2.5 2.5.2-0ubuntu1 334 | 335 | * Note: Please refer to turnkey-core's changelog for changes common to all 336 | appliances. Here we only describe changes specific to this appliance. 337 | 338 | -- Alon Swartz Tue, 29 Sep 2009 15:39:41 +0200 339 | 340 | turnkey-django-2009.03 (1) hardy; urgency=low 341 | 342 | * improved django passwords and secrets generation mechanism (security) 343 | 344 | - database password is now randomly generated, and regenerated 345 | during installation 346 | - regenerate more secure secret key during installation 347 | 348 | * major component versions 349 | 350 | python-django 1.0.2-1 351 | mysql-server 5.0.51a-3ubuntu5.4 352 | apache2 2.2.8-1ubuntu0.5 353 | python2.5 2.5.2-2ubuntu4.1 354 | 355 | -- Alon Swartz Thu, 26 Mar 2009 16:31:46 +0200 356 | 357 | turnkey-django-2009.02 (1) hardy; urgency=low 358 | 359 | * added SSL support 360 | 361 | * regenerate django secret key during installation 362 | 363 | * added useful links to the default web root (e.g., the "it works!" page) 364 | 365 | * major component versions: 366 | 367 | python-django 1.0.2-1 368 | mysql-server 5.0.51a-3ubuntu5.4 369 | apache2 2.2.8-1ubuntu0.3 370 | python2.5 2.5.2-2ubuntu4.1 371 | 372 | * support configuring mysql root password during installation 373 | * set empty mysql root password in live/demo mode (for convenience) 374 | 375 | * note: please refer to turnkey-core's changelog for changes common to all 376 | appliances. Here we only describe changes specific to this appliance. 377 | 378 | -- Alon Swartz Thu, 29 Jan 2009 14:31:35 +0200 379 | -------------------------------------------------------------------------------- /conf.d/main: -------------------------------------------------------------------------------- 1 | #!/bin/bash -ex 2 | 3 | set ${DJANGO_PASS:=turnkey} 4 | 5 | DB_NAME=django 6 | DB_USER=django 7 | DB_PASS=$(mcookie) 8 | 9 | DJANGO_DIR=/var/www/turnkey_project 10 | DJANGO_PROJ_DIR=$DJANGO_DIR/turnkey_project 11 | DJANGO_USER=admin 12 | DJANGO_EMAIL=root@localhost 13 | 14 | cd /var/www 15 | django-admin startproject turnkey_project 16 | cd $DJANGO_DIR 17 | python3 manage.py startapp turnkey_app 18 | 19 | # start mysql server 20 | service mysql start 21 | 22 | # create database & user 23 | mysqladmin create $DB_NAME --default-character-set=utf8; 24 | mysql --batch --execute "grant all privileges on $DB_NAME.* to $DB_USER@localhost identified by '$DB_PASS'; flush privileges;" 25 | 26 | # update database configuration password 27 | CONF=$DJANGO_PROJ_DIR/settings.py 28 | 29 | sed -i "/^DATABASES/,/'ENGINE'/ s/'ENGINE':.*/'ENGINE': 'django.db.backends.mysql',/1" $CONF 30 | sed -i "/^DATABASES/,/'NAME'/ s/'NAME':.*/'NAME': '$DB_NAME',/1" $CONF 31 | sed -i "/^DATABASES/,/'NAME'/ { 32 | /'NAME'/ a \ 'PASSWORD': '$DB_PASS', 33 | }" $CONF 34 | sed -i "/^DATABASES/,/'NAME'/{ 35 | /'NAME'/ a \ 'USER': '$DB_USER', 36 | }" $CONF 37 | 38 | # inject some code to dynamically fill ALLOWED_HOSTS via contents of 39 | # /var/lib/django/allowed_hosts 40 | sed -i "/ALLOWED_HOSTS/ s|^.*$|\ 41 | with open('/var/lib/django/allowed_hosts', 'r') as fob:\n\ 42 | # Read allowed_hosts dynamically for reliable inithooks host setting\n\ 43 | ALLOWED_HOSTS = [line.rstrip() for line in fob]|" $CONF 44 | 45 | sed -i "/TEMPLATES/,/WSGI_APPLICATION/ { 46 | /'DIRS'/ s|'DIRS'.*$|'DIRS': [ Path(BASE_DIR) / 'templates'],| 47 | }" $CONF 48 | 49 | 50 | # synchronize django database (mysql and sqlite) 51 | $DJANGO_DIR/manage.py migrate 52 | 53 | # create django superuser account 54 | echo "from django.contrib.auth.models import User; User.objects.create_superuser('$DJANGO_USER', '$DJANGO_EMAIL', '$DJANGO_PASS')" | $DJANGO_DIR/manage.py shell 55 | 56 | # configure tkl-webcp 57 | DJANGO_APP_DIR="$DJANGO_DIR" 58 | 59 | for dir in js css images; do 60 | mkdir -p $DJANGO_APP_DIR/static/$dir 61 | cp -a /var/www/$dir/* $DJANGO_APP_DIR/static/$dir 62 | rm -rf /var/www/$dir 63 | done 64 | mv /var/www/templates $DJANGO_APP_DIR/templates 65 | mv /var/www/app_urls.py $DJANGO_APP_DIR/turnkey_app/urls.py 66 | mv /var/www/app_views.py $DJANGO_APP_DIR/turnkey_app/views.py 67 | mv /var/www/proj_urls.py $DJANGO_APP_DIR/turnkey_project/urls.py 68 | rm -f /var/www/index.html 69 | 70 | # setup admin media 71 | ln -s /usr/lib/python3/dist-packages/django/contrib/admin/static/admin/ $DJANGO_APP_DIR/static/admin 72 | 73 | # apache configuration 74 | a2dissite 000-default 75 | a2ensite django 76 | 77 | # stop mysql server 78 | service mysql stop 79 | -------------------------------------------------------------------------------- /overlay/etc/apache2/sites-available/django.conf: -------------------------------------------------------------------------------- 1 | ServerName localhost 2 | 3 | WSGIScriptAlias / /var/www/turnkey_project/turnkey_project/wsgi.py 4 | WSGIPythonPath /var/www/turnkey_project 5 | WSGIDaemonProcess django processes=1 threads=3 python-path=/var/www/turnkey_project/ 6 | WSGIProcessGroup django 7 | 8 | 9 | UseCanonicalName Off 10 | ServerAdmin webmaster@localhost 11 | DocumentRoot /var/www/turnkey_project/static 12 | 13 | 14 | 15 | SSLEngine on 16 | ServerAdmin webmaster@localhost 17 | DocumentRoot /var/www/turnkey_project/static 18 | 19 | 20 | Alias /static /var/www/turnkey_project/static 21 | 22 | SetHandler None 23 | 24 | 25 | Alias /doc /usr/share/doc/python-django-doc/html 26 | 27 | SetHandler None 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /overlay/usr/lib/inithooks/bin/django.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | """Set Django admin password and email 3 | 4 | Option: 5 | --pass= unless provided, will ask interactively 6 | --email= unless provided, will ask interactively 7 | --domain= unless provided, will ask interactively 8 | DEFAULT=www.example.com 9 | 10 | """ 11 | 12 | import sys 13 | import getopt 14 | from libinithooks import inithooks_cache 15 | import hashlib 16 | import random 17 | import os 18 | 19 | from libinithooks.dialog_wrapper import Dialog 20 | from mysqlconf import MySQL 21 | 22 | def usage(s=None): 23 | if s: 24 | print("Error:", s, file=sys.stderr) 25 | print("Syntax: %s [options]" % sys.argv[0], file=sys.stderr) 26 | print(__doc__, file=sys.stderr) 27 | sys.exit(1) 28 | 29 | DEFAULT_DOMAIN="www.example.com" 30 | 31 | 32 | def main(): 33 | try: 34 | opts, args = getopt.gnu_getopt(sys.argv[1:], "h", 35 | ['help', 'pass=', 'email=', 'domain=']) 36 | except getopt.GetoptError as e: 37 | usage(e) 38 | 39 | password = "" 40 | email = "" 41 | domain = "" 42 | for opt, val in opts: 43 | if opt in ('-h', '--help'): 44 | usage() 45 | elif opt == '--pass': 46 | password = val 47 | elif opt == '--email': 48 | email = val 49 | elif opt == '--domain': 50 | domain = val 51 | 52 | 53 | 54 | if not password: 55 | d = Dialog('TurnKey Linux - First boot configuration') 56 | password = d.get_password( 57 | "Django Password", 58 | "Enter new password for the Django 'admin' account.") 59 | 60 | if not email: 61 | if 'd' not in locals(): 62 | d = Dialog('TurnKey Linux - First boot configuration') 63 | 64 | email = d.get_email( 65 | "Django Email", 66 | "Enter email address for the Django 'admin' account.", 67 | "admin@example.com") 68 | 69 | inithooks_cache.write('APP_EMAIL', email) 70 | 71 | if not domain: 72 | if 'd' not in locals(): 73 | d = Dialog('TurnKey Linux - First boot configuration') 74 | 75 | domain = d.get_input( 76 | "Django Domain", 77 | "Enter the domain to serve Django.", 78 | DEFAULT_DOMAIN) 79 | 80 | if domain == "DEFAULT": 81 | domain = DEFAULT_DOMAIN 82 | 83 | inithooks_cache.write('APP_DOMAIN', domain) 84 | 85 | 86 | m = MySQL() 87 | m.execute('UPDATE django.auth_user SET email=%s WHERE username=\"admin\";', (email,)) 88 | os.system("echo \"from django.contrib.auth.models import User; user = User.objects.get(username='admin'); user.set_password('"+ password + "');user.save()\" | /var/www/turnkey_project/manage.py shell") 89 | 90 | with open('/var/lib/django/allowed_hosts', 'w') as fob: 91 | fob.write("*" + '\n') 92 | fob.write(domain + '\n') 93 | 94 | if __name__ == "__main__": 95 | main() 96 | 97 | -------------------------------------------------------------------------------- /overlay/usr/lib/inithooks/firstboot.d/20regen-django-secrets: -------------------------------------------------------------------------------- 1 | #!/bin/bash -e 2 | # regenerate django secret key and mysql password 3 | 4 | . /etc/default/inithooks 5 | 6 | SETTINGS=/var/www/turnkey_project/turnkey_project/settings.py 7 | 8 | SECRET_KEY="" 9 | size=${#SECRET_KEY} 10 | while [ $size -lt 64 ]; do 11 | SECRET_KEY="$SECRET_KEY$(openssl rand 64 | tr -dc 'A-Za-z0-9!$%()+,-.:;<=>?@[]^_{}~')" 12 | size=${#SECRET_KEY} 13 | done 14 | SECRET_KEY=$(echo $SECRET_KEY | cut -c1-64) 15 | 16 | sed -i "s|SECRET_KEY.*|SECRET_KEY = \'$SECRET_KEY\'|" $SETTINGS 17 | 18 | PASSWORD=$(mcookie) 19 | sed -i "/^DATABASES/,/'PASSWORD'/ { 20 | s/'PASSWORD': .*$/ 'PASSWORD': '$PASSWORD',/ 21 | }" $SETTINGS 22 | $INITHOOKS_PATH/bin/mysqlconf.py --user=django --pass="$PASSWORD" 23 | 24 | -------------------------------------------------------------------------------- /overlay/usr/lib/inithooks/firstboot.d/40django: -------------------------------------------------------------------------------- 1 | #!/bin/bash -e 2 | # set django admin password and email 3 | 4 | . /etc/default/inithooks 5 | 6 | [ -e $INITHOOKS_CONF ] && . $INITHOOKS_CONF 7 | $INITHOOKS_PATH/bin/django.py --pass="$APP_PASS" --email="$APP_EMAIL" --domain="$APP_DOMAIN" 8 | -------------------------------------------------------------------------------- /overlay/var/lib/django/allowed_hosts: -------------------------------------------------------------------------------- 1 | www.example.com 2 | -------------------------------------------------------------------------------- /overlay/var/www/app_urls.py: -------------------------------------------------------------------------------- 1 | from django.urls import path 2 | 3 | from . import views 4 | 5 | urlpatterns = [ 6 | path('', views.index, name='index'), 7 | ] 8 | -------------------------------------------------------------------------------- /overlay/var/www/app_views.py: -------------------------------------------------------------------------------- 1 | from django.shortcuts import render 2 | from django import http 3 | 4 | # Create your views here. 5 | def index(request): 6 | http_host = request.META['HTTP_HOST'] 7 | host = {'http_host': http_host} 8 | return render(request, 'index.html', host) 9 | -------------------------------------------------------------------------------- /overlay/var/www/images/django.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/turnkeylinux-apps/django/47bb16522a9a860f9163dab455e8044d0afc7095/overlay/var/www/images/django.png -------------------------------------------------------------------------------- /overlay/var/www/proj_urls.py: -------------------------------------------------------------------------------- 1 | """turnkey_project URL Configuration 2 | 3 | The `urlpatterns` list routes URLs to views. For more information please see: 4 | https://docs.djangoproject.com/en/2.2/topics/http/urls/ 5 | Examples: 6 | Function views 7 | 1. Add an import: from my_app import views 8 | 2. Add a URL to urlpatterns: path('', views.home, name='home') 9 | Class-based views 10 | 1. Add an import: from other_app.views import Home 11 | 2. Add a URL to urlpatterns: path('', Home.as_view(), name='home') 12 | Including another URLconf 13 | 1. Import the include() function: from django.urls import include, path 14 | 2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) 15 | """ 16 | from django.contrib import admin 17 | from django.urls import path, include 18 | 19 | urlpatterns = [ 20 | path('', include('turnkey_app.urls')), 21 | path('admin/', admin.site.urls), 22 | ] 23 | -------------------------------------------------------------------------------- /overlay/var/www/templates/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | TurnKey Django 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 22 | 23 | 24 | 25 |

TurnKey Django

26 | 27 |
28 | 31 | 32 |
33 |
34 |
35 | Administration 37 |
38 |
39 | Webmin 41 |
42 |
43 |
44 |
45 | 46 |

Resources and references

47 | 59 | 60 |
61 |
62 | 63 |
64 | 65 | 66 | 67 | -------------------------------------------------------------------------------- /plan/main: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | apache2 5 | webmin-apache 6 | libapache2-mod-wsgi-py3 7 | 8 | webmin-mysql 9 | python3-mysqldb 10 | 11 | python3-django 12 | python-django-doc 13 | python3-docutils 14 | libjs-jquery 15 | 16 | ipython3 17 | --------------------------------------------------------------------------------