Commit fa20974e authored by Georges Khaznadar's avatar Georges Khaznadar

updated debian packaging stuff

parent 6c077965
......@@ -9,9 +9,13 @@ Vcs-Git: https://salsa.debian.org/georgesk/photodb.git
Package: photodb
Architecture: all
Depends: ${misc:Depends}, python3, python3-cherrypy3,
Depends: ${misc:Depends}, python3,
python3-dateutil, python3-tz, python3-odf,
python3-django, python3-django-filters, python3-django-python3-ldap
sqlite3,
libjs-jquery, libjs-jquery-ui, libjs-jquery-ui-theme-smoothness
Suggests: iceweasel|x-www-browser
Recommends: libapache2-mod-wsgi-py3
Description: manage photos of your school's students
This little web service allows you to import databases of names
from various CSV flavors. Then students can take their snapshots
......
......@@ -3,7 +3,7 @@ Upstream-Name: photodb
Source: own work
Files: *
Copyright: 2016 Georges Khaznadar <georgesk@debian.org>
Copyright: 2016-2018 Georges Khaznadar <georgesk@debian.org>
License: GPL-3.0+
Files: debian/*
......
......@@ -18,14 +18,56 @@ set -e
# the debian-policy package
# Source debconf library.
. /usr/share/debconf/confmodule
# db_get photodb/dbPassword || true
# dbPassword="$RET"
db_get photodb/adminEmail || true
adminEmail="$RET"
db_get photodb/adminPassword || true
adminPassword="$RET"
db_get photodb/virtualHost ||true
virtualHost="$RET"
appDir=/var/lib/photodb
apacheConf=/etc/apache2/sites-available/photodb-django.conf
case "$1" in
configure)
python3 -m py_compile /var/lib/photodb/*.py
sh /var/lib/photodb/updateDb.sh
mkdir -p /var/lib/photodb/db
mkdir -p /var/lib/photodb/photos
chown www-data /var/lib/photodb /var/lib/photodb/db \
/var/lib/photodb/db/*.db /var/lib/photodb/photos
## make a sample database if there is no database yet
[ -f /var/lib/photodb/db/names.db ] || \
cp /var/lib/photodb/db.sqlite3.sample /var/lib/photodb/db/names.db
## enable Apache's access
setfacl -m u:www-data:rwx /var/lib/photodb
setfacl -m u:www-data:rw /var/lib/photodb/db/names.db
## enabling the production settings
cp $appDir/photodb/settings-prod.py $appDir/photodb/settings.py
## create the upload area
mkdir -p $appDir/photos
chown -R www-data:www-data $appDir/photos
## create the database "photodb" and the role "photodb"
# cd $appDir; ./createDB1 "$dbPassword"
## recompile after the change in settings.py
python3 -mpy_compile $appDir/photodb/settings.py
echo "database OK"
# adminOK=$(su postgres -c "psql -t aquagym" << eof
# select count(*) from auth_user where is_superuser=true and username='admin';
# eof
# )
adminOK=$(cd /var/lib/photodb/db; sqlite3 -list names.db "select count(*) from auth_user where is_superuser=1 and username='admin'")
if [ "$adminOK" = 0 ]; then
cd $appDir; ./createsuperuser "admin" "$adminEmail" "$adminPassword" 2> /dev/null ||true
fi
echo "superuser OK"
sed "s/SERVERNAME/$virtualHost/" $apacheConf > $apacheConf.tmp && mv $apacheConf.tmp $apacheConf
if (which a2ensite); then a2ensite photodb-django; fi
## grab static files and migrate the database
(cd /var/lib/photodb; ./manage.py collectstatic --noinput; ./manage.py makemigrations; ./manage.py migrate)
## apply any changes : restart WSGI services
service apache2 reload
;;
abort-upgrade|abort-remove|abort-deconfigure)
......
......@@ -21,6 +21,22 @@ set -e
case "$1" in
purge)
if [ -e /usr/share/debconf/confmodule ]; then
# Source debconf library.
. /usr/share/debconf/confmodule
# Remove my changes to the db.
db_purge
fi
# disable the website for apache2
if (which a2dissite); then a2dissite photodb-django; fi
# backup the database
# t=$(tempfile --directory /var/tmp --prefix photodb- --suffix .sql)
t=$(tempfile --directory /var/tmp --prefix photodb- --suffix .sqlite3)
# chown postgres $t
# su postgres -c "pg_dump aquagym > $t"
cp /var/lib/photodb/db/names.db $t
echo "Made a backup of the database in $t"
# clean every file left
rm -rf /var/lib/photodb
;;
remove|upgrade|failed-upgrade|abort-install|abort-upgrade|disappear)
......
# Fichier de configuration pour Apache 2.4
WSGIDaemonProcess photodb python-path=/var/lib/photodb
<VirtualHost *:80>
DocumentRoot "/var/lib/photodb"
ServerName SERVERNAME
Alias /static/ /var/lib/photodb/collected_static/
<Directory /var/lib/photodb/collected_static>
Require all granted
</Directory>
Alias /media/ /var/lib/photodb/photos/
<Directory /var/lib/photodb/photos>
Require all granted
</Directory>
WSGIScriptAlias / /var/lib/photodb/photodb/wsgi.py process-group=photodb application-group=%{GLOBAL}
<Directory /var/lib/photodb/photodb>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
</VirtualHost>
"""
Django settings for photodb project.
Generated by 'django-admin startproject' using Django 1.11.13.
For more information on this file, see
https://docs.djangoproject.com/en/1.11/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/1.11/ref/settings/
"""
import os
from ldap3 import Server, Connection
import django_python3_ldap.utils
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/1.11/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'a0gse8(@w8*1gfzzkgvfjg925s1#kv(f#2mi-_mz$yf_!c76a7'
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = False
ALLOWED_HOSTS = ["*"]
# Application definition
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'django_python3_ldap',
'pose',
]
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]
ROOT_URLCONF = 'photodb.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]
WSGI_APPLICATION = 'photodb.wsgi.application'
# Database
# https://docs.djangoproject.com/en/1.11/ref/settings/#databases
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db', 'names.db'),
}
}
# Password validation
# https://docs.djangoproject.com/en/1.11/ref/settings/#auth-password-validators
AUTH_PASSWORD_VALIDATORS = [
{
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
'OPTIONS': {
'min_length': 7,
},
},
{
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
},
]
AUTHENTICATION_BACKENDS = [
'django.contrib.auth.backends.ModelBackend',
"django_python3_ldap.auth.LDAPBackend",
]
# Internationalization
# https://docs.djangoproject.com/en/1.11/topics/i18n/
LANGUAGE_CODE = 'fr-fr'
TIME_ZONE = 'Europe/Paris'
USE_I18N = True
USE_L10N = True
USE_TZ = True
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.11/howto/static-files/
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'collected_static')
MEDIA_URL = '/photos/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'photos')
# LDAP connection
server = Server('localhost', port=1389)
connection = Connection(server)
connection.bind()
############# for the LDAP AUTH BACKEND ########################
# The URL of the LDAP server.
LDAP_AUTH_URL = "ldap://localhost:1389"
# The LDAP search base for looking up users.
LDAP_AUTH_SEARCH_BASE = "ou=Users,dc=lycee,dc=jb"
# The LDAP class that represents a user.
LDAP_AUTH_OBJECT_CLASS = "kwartzAccount"
# User model fields mapped to the LDAP
# attributes that represent them.
LDAP_AUTH_USER_FIELDS = {
"username": "uid",
"first_name": "givenName",
"last_name": "sn",
"email": "mail",
}
# A tuple of fields used to uniquely identify a user.
LDAP_AUTH_USER_LOOKUP_FIELDS = ("username",)
# Callable that transforms the user data loaded from
# LDAP into a form suitable for creating a user.
# Override this to set custom field formatting for your
# user model.
LDAP_AUTH_CLEAN_USER_DATA = django_python3_ldap.utils.clean_user_data
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment