Skip to content
Snippets Groups Projects
Commit 94ac2d80 authored by Jonathan Weth's avatar Jonathan Weth :keyboard: Committed by root
Browse files

Merge pull request #197 from Katharineum/feature/tidy-from-dev

Tidy
parents 69d2a338 fee41082
No related branches found
No related tags found
1 merge request!86Merge school-apps
Showing
with 85 additions and 12516 deletions
......@@ -7,6 +7,6 @@ secure*
*.log
class.pdf
class.tex
.idea
media
node_modules
\ No newline at end of file
.idea/
media/
node_modules/
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="dataSourceStorageLocal">
<data-source name="Django default" uuid="ef6730d6-e849-4772-acac-62469acab4d2">
<database-info product="" version="" jdbc-version="" driver-name="" driver-version="" dbms="MYSQL" exact-version="0" />
<introspection-schemas>*:schoolapps</introspection-schemas>
</data-source>
<data-source name="Django default2" uuid="ea4cff78-5949-410f-aa64-d6daa5fb293d">
<database-info product="" version="" jdbc-version="" driver-name="" driver-version="" dbms="MYSQL" exact-version="0" />
<introspection-schemas>*:schoolapps</introspection-schemas>
</data-source>
<data-source name="Django untis" uuid="ae145b31-953d-4d55-ad07-b49b3287f618">
<database-info product="" version="" jdbc-version="" driver-name="" driver-version="" dbms="MYSQL" exact-version="0" />
<introspection-schemas>*:untis</introspection-schemas>
</data-source>
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="DataSourceManagerImpl" format="xml" multifile-model="true">
<data-source source="LOCAL" name="Django default" read-only="true" uuid="ef6730d6-e849-4772-acac-62469acab4d2">
<driver-ref>mysql</driver-ref>
<synchronize>true</synchronize>
<imported>true</imported>
<remarks>$PROJECT_DIR$/schoolapps/schoolapps/settings.py</remarks>
<jdbc-driver>com.mysql.jdbc.Driver</jdbc-driver>
<jdbc-url>jdbc:mysql://localhost:3306/schoolapps</jdbc-url>
<driver-properties>
<property name="autoReconnect" value="true" />
<property name="zeroDateTimeBehavior" value="convertToNull" />
<property name="tinyInt1isBit" value="false" />
<property name="characterEncoding" value="utf8" />
<property name="characterSetResults" value="utf8" />
<property name="yearIsDateType" value="false" />
</driver-properties>
</data-source>
<data-source source="LOCAL" name="Django default2" uuid="ea4cff78-5949-410f-aa64-d6daa5fb293d">
<driver-ref>mysql</driver-ref>
<synchronize>true</synchronize>
<imported>true</imported>
<remarks>$PROJECT_DIR$/schoolapps/schoolapps/settings.py</remarks>
<jdbc-driver>com.mysql.jdbc.Driver</jdbc-driver>
<jdbc-url>jdbc:mysql:///schoolapps</jdbc-url>
<driver-properties>
<property name="autoReconnect" value="true" />
<property name="zeroDateTimeBehavior" value="convertToNull" />
<property name="tinyInt1isBit" value="false" />
<property name="characterEncoding" value="utf8" />
<property name="characterSetResults" value="utf8" />
<property name="yearIsDateType" value="false" />
</driver-properties>
</data-source>
<data-source source="LOCAL" name="Django untis" uuid="ae145b31-953d-4d55-ad07-b49b3287f618">
<driver-ref>mysql</driver-ref>
<synchronize>true</synchronize>
<imported>true</imported>
<remarks>$PROJECT_DIR$/schoolapps/schoolapps/settings.py</remarks>
<jdbc-driver>com.mysql.jdbc.Driver</jdbc-driver>
<jdbc-url>jdbc:mysql:///untis</jdbc-url>
<driver-properties>
<property name="autoReconnect" value="true" />
<property name="zeroDateTimeBehavior" value="convertToNull" />
<property name="tinyInt1isBit" value="false" />
<property name="characterEncoding" value="utf8" />
<property name="characterSetResults" value="utf8" />
<property name="yearIsDateType" value="false" />
</driver-properties>
</data-source>
</component>
</project>
\ No newline at end of file
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="JavaScriptLibraryMappings">
<file url="file://$PROJECT_DIR$" libraries="{jquery}" />
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.7 (SchoolApps)" project-jdk-type="Python SDK" />
<component name="PyCharmProfessionalAdvertiser">
<option name="shown" value="true" />
</component>
</project>
\ No newline at end of file
File mode changed from 100755 to 100644
......@@ -8,31 +8,43 @@
<option name="manageScript" value="manage.py" />
<option name="environment" value="&lt;map/&gt;" />
<option name="doNotUseTestRunner" value="false" />
<option name="trackFilePattern" value="migrations" />
<option name="trackFilePattern" value="" />
</configuration>
</facet>
</component>
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/schoolapps" isTestSource="false" />
<excludeFolder url="file://$MODULE_DIR$/venv" />
<sourceFolder url="file://$MODULE_DIR$/dynselect" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/dynselect2" isTestSource="false" />
<excludeFolder url="file://$MODULE_DIR$/.idea" />
<excludeFolder url="file://$MODULE_DIR$/dynselect/.idea" />
<excludeFolder url="file://$MODULE_DIR$/dynselect2/.idea" />
<excludeFolder url="file://$MODULE_DIR$/env" />
<excludeFolder url="file://$MODULE_DIR$/schoolapps/staticcollect" />
</content>
<orderEntry type="jdk" jdkName="Python 3.7 (SchoolApps)" jdkType="Python SDK" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="jquery-3.2.1" level="application" />
<orderEntry type="library" name="react.production" level="application" />
<orderEntry type="library" name="react-dom.production" level="application" />
<orderEntry type="library" name="jquery" level="application" />
</component>
<component name="TemplatesService">
<option name="templateFileTypes">
<list>
<option value="HTML" />
<option value="XML" />
<option value="XHTML" />
<option value="LaTeX source file" />
</list>
</option>
<option name="TEMPLATE_CONFIGURATION" value="Django" />
<option name="TEMPLATE_FOLDERS">
<list>
<option value="$MODULE_DIR$/env/lib/python3.7/site-packages/django/forms/templates" />
<option value="$MODULE_DIR$/schoolapps/templates" />
<option value="$MODULE_DIR$/schoolapps/timetable/templates" />
<option value="$MODULE_DIR$/schoolapps/untisconnect/templates" />
<option value="$MODULE_DIR$/schoolapps/aub/templates" />
<option value="$MODULE_DIR$/schoolapps/support/templates" />
<option value="$MODULE_DIR$/schoolapps/menu/templates" />
<option value="$MODULE_DIR$/schoolapps/faq/templates" />
<option value="$MODULE_DIR$/schoolapps/dashboard/templates" />
<option value="$MODULE_DIR$/schoolapps/aub/templates" />
</list>
</option>
</component>
......
.idea/vcs.xml 100755 → 100644
......@@ -2,6 +2,5 @@
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
<mapping directory="$PROJECT_DIR$/schoolapps/static/materialize" vcs="Git" />
</component>
</project>
\ No newline at end of file
File mode changed from 100755 to 100644
......@@ -3,11 +3,11 @@
## Apps
siehe Wiki
## Installation
**Hinweis:** Es werden nur Linux-basierte Systeme unterstützt (in dieser Anleitung wird sich auf Debian-basierte Systeme wie Ubuntu oder Linux Mint bezogen, Arch-Derivate u. Ä. funktionieren aber auch (die Paketnamen sind nur anders, einfach im AUR nachschauen - es werden eine lauffähige Python-3-Umgebung sowie Apache2 und MySQL benötigt)). Außerdem werden Root-Rechte benötigt.
**Hinweis:** Es werden nur Linux-basierte Systeme unterstützt (in dieser Anleitung wird sich auf Debian-basierte Systeme wie Ubuntu oder Linux Mint bezogen). Außerdem werden Root-Rechte benötigt.
### Grundsystem
```
sudo apt install python3 python3-dev python3-pip git mariadb-server python3-venv libldap2-dev libsasl2-dev libmysqlclient-dev
sudo apt install python3 python3-dev python3-pip git mariadb-server python3-venv libldap2-dev libsasl2-dev libmysqlclient-dev pandoc texlive texlive-fonts-extra texlive-lang-german texlive-latex-extra
```
### MySQL-Datenbank
......@@ -16,53 +16,46 @@ sudo apt install python3 python3-dev python3-pip git mariadb-server python3-venv
3. Benutzer `www-data` alle Rechte auf `schoolapps` geben
4. Benutzer `untis-read` anlegen
5. Benutzer `untis-read` Leserechte auf UNTIS-DB geben
```
mysql -u root -p
CREATE USER 'www-data'@'localhost' IDENTIFIED BY 'grummelPASS1531';
GRANT ALL PRIVILEGES ON *.* TO 'www-data'@'localhost';
CREATE USER 'untis-read'@'localhost' IDENTIFIED BY 'grummelPASS1531';
GRANT ALL PRIVILEGES ON *.* TO 'untis-read'@'localhost';
CREATE DATABASE schoolapps;
CREATE DATABASE Untis;
CREATE USER 'www-data'@'localhost' IDENTIFIED BY 'grummelPASS1531';
GRANT ALL PRIVILEGES ON schoolapps.* TO 'www-data'@'localhost';
CREATE USER 'untis-read'@'localhost' IDENTIFIED BY 'grummelPASS1531';
GRANT SELECT ON Untis.* TO 'untis-read'@'localhost';
```
Hinweis: In Testumgebungen kann untis-read auch entfallen und
stattdessen www-data auch für den Zugriff auf die Datenbank `Untis` verwendet werden:
```
GRANT SELECT ON Untis.* TO 'www-data'@'localhost';
```
### UNTIS-Beispieldaten laden
1. PhpMyAdmin öffnen und die Datei untiskath.sql vom Forum importieren.
### UNTIS-Beispieldaten importieren
Zum Testen kann die Datei `untiskath.sql` vom Forum in die Datenbank `Untis` importiert werden.
### SchoolApps clonen
```
git clone git@github.com:Katharineum/school-apps.git
```
- Anmelden
### Django
- Zum Installationsordner wechseln
### Django installieren
- Zum Installationsordner wechseln, dann:
```
python3 -m venv env
source env/bin/activate
pip install mysqlclient
pip install django
pip install django-auth-ldap
pip install django-dbsettings
pip install django_pdb
pip install django-material
pip install django-filter
pip install django_react_templatetags
pip install kanboard
pip install PyPDF2
pip install django-widget-tweaks
pip install requests
pip install -r requirements.txt
```
- `example_secure_settings.py` zu `secure_settings.py` kopieren und anpassen
### Submodules updaten
```
git submodule init
git submodule update
```
- `example_secure_settings.py` zu `secure_settings.py` kopieren und anpassen (hier müssen auch die passenden DB-Zugangsdaten eingetragen werden)
### Migrations auflösen
Leider kommt es bei einer Erstinstallation von SchoolApps immer zu Problemen mit den Migrations. Sollte es Schwierigkeiten geben, @hansegucker kontaktieren.
### Migrations durchführen/auflösen
Leider kommt es bei einer Erstinstallation von SchoolApps immer noch zu Problemen mit den Migrations. Sollte es Schwierigkeiten geben, @hansegucker kontaktieren.
Für die Migration folgende Befehle im aktivierten VirtualEnv ausführen:
```
......@@ -70,38 +63,46 @@ python3 schoolapps/manage.py makemigrations
python3 schoolapps/manage.py migrate
```
### Testlauf
- Administratornutzer erstellen
```
python3 schoolapps/manage.py createsuperuser
```
- Django-Devserver starten
```
python3 schoolapps/manage.py runserver
```
- Einstellungen anpassen (http://127.0.0.1:8080/settings, siehe auch "Kanboard-Verbindung einrichten")
- SchoolApps benutzen 😃
### Kanboard-Verbindung einrichten
1. Zu den [Einstellungen](http://localhost:8000/settings) navigieren (/settings)
1. Zu den [Einstellungen](localhost:8000/settings) navigieren (/settings)
2. Den Kanboard-API-Key von [Kanboard](https://kanboard.katharineum.de/?controller=ConfigController&action) eintragen
3. Die Project-IDs von ``Rebus`` (#4) und ``Feedback`` (#18) eintragen.
4. Die richtigen E-Mailadressen eintragen.
3. Die Project-IDs von `REBUS` (#4) und `Feedback` (#18) eintragen
4. Die richtigen E-Mailadressen eintragen
### Testlauf
## LDAP (info.katharineum.de)
**WICHTIG: LDAP funktioniert nur bei Root-Zugriff auf dem Infoserver!**
**WICHTIG:** LDAP funktioniert nur mit Nutzern, die folgende Gruppe haben: `info-admins`
#### Adresse vom Info aus:
localhost:389
#### Adresse lokal von info.katharineum.de
`localhost:389`
#### BIND-Nutzer
DN: uid=readldap,ou=people,dc=skole,dc=skolelinux,dc=no
PW: grummelPASS1531
DN: `uid=readldap,ou=people,dc=skole,dc=skolelinux,dc=no`
PW: `grummelPASS1531`
#### BASIS DN
dc=skole,dc=skolelinux,dc=no
#### Basis-DN
`dc=skole,dc=skolelinux,dc=no`
#### SSH-Tunnel herstellen
```sudo ssh -L 389:localhost:389 <user>@info.katharineum.de -N ```
(<user> durch Nutzer ersetzen)
(`<user>` durch Nutzer mit Gruppe `info-admins` ersetzen)
#### Verbindung testen
1. Tunnel erstellen (siehe Befehl)
2. Apache Active Directory (AD) zum Testen öffnen (Download unter http://directory.apache.org/studio/)
3. Verbindung in AD mit oben genannten Daten herstellen
diff --git a/schoolapps/manage.py b/schoolapps/manage.py
index d450e49..bee7dd5 100755
--- a/schoolapps/manage.py
+++ b/schoolapps/manage.py
@@ -1,7 +1,9 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
import os
import sys
+sys.path = ["/srv/sites/school-apps/env/lib/python3.5/site-packages/"] + sys.path
+
if __name__ == "__main__":
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "schoolapps.settings")
try:
@@ -11,5 +13,5 @@ if __name__ == "__main__":
"Couldn't import Django. Are you sure it's installed and "
"available on your PYTHONPATH environment variable? Did you "
"forget to activate a virtual environment?"
- ) from exc
+ )
execute_from_command_line(sys.argv)
diff --git a/schoolapps/schoolapps/settings.py b/schoolapps/schoolapps/settings.py
index c05dba5..c1ba2d3 100755
--- a/schoolapps/schoolapps/settings.py
+++ b/schoolapps/schoolapps/settings.py
@@ -12,8 +12,8 @@ https://docs.djangoproject.com/en/2.0/ref/settings/
import os
import ldap
-from django_auth_ldap.config import LDAPSearch, GroupOfNamesType, LDAPGroupType
-from posixgrouptype import PosixGroupType
+from django_auth_ldap.config import LDAPSearch, PosixGroupType, GroupOfNamesType, LDAPGroupType
+#from posixgrouptype import PosixGroupType
import logging
from .secure_settings import *
@@ -27,6 +27,9 @@ BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
+# PDB debugger option
+POST_MORTEM = True
+
ALLOWED_HOSTS = [
'info.katharineum.de',
'178.63.239.184',
@@ -37,6 +40,7 @@ ALLOWED_HOSTS = [
# Application definition
INSTALLED_APPS = [
+ 'django_pdb',
'dashboard.apps.DashboardConfig',
'aub.apps.AubConfig',
'untisconnect.apps.UntisconnectConfig',
@@ -58,6 +62,7 @@ MIDDLEWARE = [
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
+ 'django_pdb.middleware.PdbMiddleware',
]
ROOT_URLCONF = 'schoolapps.urls'
@@ -163,17 +168,17 @@ TIMETABLE_HEIGHT = 10
# Baseline configuration.
AUTH_LDAP_SERVER_URI = "ldap://127.0.0.1"
AUTH_LDAP_USER_SEARCH = LDAPSearch("dc=skole,dc=skolelinux,dc=no",
- ldap.SCOPE_SUBTREE, "(uid=%(user)s)")
+ ldap.SCOPE_SUBTREE, "(&(objectClass=posixAccount)(uid=%(user)s))")
# or perhaps:
# AUTH_LDAP_USER_DN_TEMPLATE = "uid=%(user)s,ou=users,dc=example,dc=com"
# Set up the basic group parameters.
-AUTH_LDAP_GROUP_SEARCH = LDAPSearch("dc=skole,dc=skolelinux,dc=no,ou=SchoolManager,ou=group", ldap.SCOPE_SUBTREE,
- "(objectClass=posixGroup)")
-# '(&(objectClass=*)(memberUid=%(user))')
-print(ldap.SCOPE_SUBTREE)
+AUTH_LDAP_GROUP_SEARCH = LDAPSearch("dc=skole,dc=skolelinux,dc=no", ldap.SCOPE_SUBTREE,
+ "(&(objectClass=posixGroup)(memberUid=%(user)s))")
+# '(&(objectClass=*)(memberUid=%(user)s)')
+#print(ldap.SCOPE_SUBTREE)
# "(objectClass=organizationalUnit)")
-AUTH_LDAP_GROUP_TYPE = PosixGroupType(name_attr="cn")
+AUTH_LDAP_GROUP_TYPE = PosixGroupType()
# Simple group restrictions
# AUTH_LDAP_REQUIRE_GROUP = "dc=skole,dc=skolelinux,dc=no"
@@ -186,11 +191,11 @@ AUTH_LDAP_USER_ATTR_MAP = {
"email": "mail"
}
-# AUTH_LDAP_USER_FLAGS_BY_GROUP = {
-# "is_active": "cn=active,ou=django,ou=groups,dc=example,dc=com",
-# "is_staff": "cn=staff,ou=django,ou=groups,dc=example,dc=com",
-# "is_superuser": "cn=superuser,ou=django,ou=groups,dc=example,dc=com"
-# }
+AUTH_LDAP_USER_FLAGS_BY_GROUP = {
+# "is_active": "cn=teachers,ou=group,ou=Teachers,dc=skole,dc=skolelinux,dc=no",
+ "is_staff": "cn=schoolapps-admins,ou=group,dc=skole,dc=skolelinux,dc=no",
+ "is_superuser": "cn=schoolapps-admins,ou=group,dc=skole,dc=skolelinux,dc=no",
+}
# This is the default, but I like to be explicit.
AUTH_LDAP_ALWAYS_UPDATE_USER = True
from django.utils.encoding import force_text
from django_auth_ldap.config import LDAPGroupType
class PosixGroupType(LDAPGroupType):
"""
An LDAPGroupType subclass that handles groups of class posixGroup.
"""
def user_groups(self, ldap_user, group_search):
"""
Searches for any group that is either the user's primary or contains the
user as a member.
"""
groups = []
try:
user_uid = ldap_user.attrs['uid'][0]
# if 'gidNumber' in ldap_user.attrs:
# user_gid = ldap_user.attrs['gidNumber'][0]
# filterstr = '(|(gidNumber={})(memberUid={}))'.format(
# self.ldap.filter.escape_filter_chars(user_gid),
# self.ldap.filter.escape_filter_chars(user_uid)
# )
# else:
filterstr = '(memberUid={})'.format(
self.ldap.filter.escape_filter_chars(user_uid),
)
search = group_search.search_with_additional_term_string(filterstr)
groups = search.execute(ldap_user.connection)
except (KeyError, IndexError):
pass
return groups
def is_member(self, ldap_user, group_dn):
"""
Returns True if the group is the user's primary group or if the user is
listed in the group's memberUid attribute.
"""
try:
user_uid = ldap_user.attrs['uid'][0]
try:
is_member = ldap_user.connection.compare_s(
force_text(group_dn),
'memberUid',
user_uid.encode('utf-8'),
)
except (ldap.UNDEFINED_TYPE, ldap.NO_SUCH_ATTRIBUTE):
is_member = False
if not is_member:
try:
user_gid = ldap_user.attrs['gidNumber'][0]
is_member = ldap_user.connection.compare_s(
force_text(group_dn),
'gidNumber',
user_gid.encode('utf-8'),
)
except (ldap.UNDEFINED_TYPE, ldap.NO_SUCH_ATTRIBUTE):
is_member = False
except (KeyError, IndexError):
is_member = False
return is_member
from django.contrib import admin
# Register your models here.
from django.apps import AppConfig
class TimetableConfig(AppConfig):
name = 'timetable'
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment