This repository has been archived on 2023-02-21. You can view files and clone it, but cannot push or open issues or pull requests.
mandayejs/mandayejs/applications/__init__.py

362 lines
9.6 KiB
Python

# mandayejs - saml reverse proxy
# Copyright (C) 2015 Entr'ouvert
#
# This program is free software: you can redistribute it and/or modify it
# under the terms of the GNU Affero General Public License as published
# by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from __future__ import unicode_literals
import os
from importlib import import_module
from django.conf import settings
from django.conf.urls import url
from django.http import Http404
from django.core.exceptions import ImproperlyConfigured
from django.core.urlresolvers import resolve
from django.utils.text import slugify
from django.utils import six
from mandayejs.applications import views
def get_app_settings():
module_name, app_settings = tuple(settings.SITE_APP.rsplit('.', 1))
module = import_module(module_name)
return getattr(module, app_settings)()
def app_web_services(request, path):
app = get_app_settings()
if hasattr(app, 'SITE_WEBSERVICES'):
view, args, kwargs = resolve(request.path, urlconf=app.SITE_WEBSERVICES)
return view(request, *args, **kwargs)
raise Http404
# App Settings
class AppSettingsMeta(type):
REQUIRED_KEYS = [
'SITE_LOGIN_PATH',
'SITE_LOCATORS',
'SITE_AUTH_CHECKER',
'SITE_AUTH_COOKIE_KEYS',
]
def __new__(cls, name, bases, dct):
if name != 'AppSettings':
if AppSettings in bases: # Avoid checking keys for inherited classes
missing_key = set(cls.REQUIRED_KEYS).difference(set(dct.keys())) or None
if missing_key:
raise ImproperlyConfigured('{} is mandatory'.format(missing_key.pop()))
if not set(('SITE_FORCE_REDIRECT_URL', 'SITE_FORCE_REDIRECT_LOCATOR')).intersection(set(dct.keys())):
raise ImproperlyConfigured(
'one of these settings ({}) must be defined'
.format(('SITE_FORCE_REDIRECT_URL', 'SITE_FORCE_REDIRECT_LOCATOR')))
# Default form submit element
if not dct.get('SITE_FORM_SUBMIT_ELEMENT', None):
dct['SITE_FORM_SUBMIT_ELEMENT'] = 'input[type=submit], button'
return super(AppSettingsMeta, cls).__new__(cls, name, bases, dct)
class AppSettings(six.with_metaclass(AppSettingsMeta, object)):
def __getattribute__(self, name):
value = getattr(settings, name, None)
if value is not None:
return value
return super(AppSettings, self).__getattribute__(name)
def get_name(self):
name = getattr(settings, 'SITE_APP_NAME', None)
if name:
return name
return type(self).__name__
def get_slug(self):
return slugify(type(self).__name__)
class AppWebservice(object):
'''- endpoints = [
{'foo': 'https://example.org/foo/'},
{'bar': 'https://example.org/bar/'},
]
- urlpatterns = [
url('user/(?P<username>\w+)/$', views.myapp.user_details, name='user-details'),
url('user/(?P<username>\w+/books/$)', views.myapp.user_books, name='user-books'),
]
'''
def __init__(self, endpoints=None, urlpatterns=None):
self.endpoints = endpoints
self.urlpatterns = urlpatterns
def get_endpoint(self, name):
for endpoint in self.endpoints:
if endpoint.get(name, None):
return endpoint[name]
return None
# Test App Settings
class Test(AppSettings):
SITE_LOGIN_PATH = '/'
SITE_LOCATORS = [
{
'id': '#login',
'label': 'Login',
'name': 'login',
'kind': 'string',
},
{
'id': '#password',
'label': 'Password',
'name': 'password',
'kind': 'password'
}
]
SITE_AUTH_CHECKER = 'js/test/auth.checker.js'
SITE_AUTH_COOKIE_KEYS = ['test']
SITE_FORCE_REDIRECT_URL = '/whatever'
# Duonet App Settings
class Duonet(AppSettings):
SITE_LOGIN_PATH = '/'
SITE_LOCATORS = [
{
'id': '#txtNomFoyer',
'label': 'Nom de famille',
'name': 'txtNomFoyer',
'kind': 'string',
'required': True,
'help': '',
},
{
'id': '#txtDateNaissance',
'label': 'Date de naissance',
'name': 'txtDateNaissance',
'kind': 'date',
'required': True,
'help': 'exemple 16/06/2008'
},
{
'id': '#txtCode',
'label': 'Mot de passe',
'name': 'txtCode',
'kind': 'password',
'required': True,
'help': ''
},
]
SITE_AUTH_CHECKER = 'duonet/js/auth.checker.js'
SITE_AUTH_COOKIE_KEYS = [
'ASP.NET_SessionId',
]
SITE_APP_SCRIPTS = [
'duonet/js/duonet.js',
]
SITE_FORCE_REDIRECT_URL = '/Connect.aspx'
SITE_FORM_SUBMIT_ELEMENT = 'input[type=submit]'
SITE_LOGOUT_LOCATOR = '#lnkDisconnect'
# Archimed App Settings
class Archimed(AppSettings):
SITE_LOGIN_PATH = '/'
SITE_LOCATORS = [
{
'id': '#carte',
'label': 'Identifiant',
'name': 'carte',
'kind': 'string',
'required': True,
'help': '',
},
{
'id': '#code',
'label': 'Mot de passe',
'name': 'code',
'kind': 'password',
'required': True,
'help': ''
},
]
SITE_AUTH_CHECKER = 'archimed/js/auth.checker.js'
SITE_AUTH_COOKIE_KEYS = [
'S_ARCHIMED_CRYSTAL_AUTH'
]
SITE_APP_SCRIPTS = [
'archimed/js/archimed.js'
]
SITE_FORCE_REDIRECT_LOCATOR = '.connectBox'
SITE_WEBSERVICES = AppWebservice(
[
{'account_details': '/DEFAULT/Ermes/Services/ILSClient.svc/RetrieveAccount'},
{'login_url': '/DEFAULT/Ermes/Recherche/logon.svc/logon'}
],
[
url(r'account/(?P<username>\w+)/$', views.archimed_account_details,
name='archimed-account-details')
]
)
SITE_LOGOUT_LOCATOR = '.account_logoff'
# Arpege App Settings
class Arpege(AppSettings):
SITE_LOGIN_PATH = '/index.do'
SITE_LOCATORS = [
{
'id': '#cdfmll',
'label': 'Code famille',
'name': 'cdfmll',
'kind': 'string',
'required': True,
'help': '',
},
{
'id': '#mtdpss',
'label': 'Mot de passe',
'name': 'mtdpss',
'kind': 'password',
'required': True,
'help': '',
}
]
SITE_AUTH_CHECKER = 'arpege/js/auth.checker.js'
SITE_AUTH_COOKIE_KEYS = [
'JSESSIONID',
]
SITE_APP_SCRIPTS = [
'arpege/js/arpege.js',
]
SITE_FORCE_REDIRECT_LOCATOR = '.formulaire'
SITE_LOGOUT_LOCATOR = '#espace-login form input[type=submit]'
class Imuse(AppSettings):
SITE_LOGIN_PATH = 'extranet/login/gen_index_groupe.php?nav=autre'
SITE_LOCATORS = [
{
'id': '#INDEX_USER_ID',
'label': 'Identifiant',
'name': 'INDEX_USER_ID',
'kind': 'string',
'required': True,
'help': ''
},
{
'id': '#INDEX_USER_PWD',
'label': 'Mot de passe',
'name': 'INDEX_USER_PWD',
'kind': 'password',
'required': True,
'help': ''
}
]
SITE_AUTH_CHECKER = 'imuse/js/auth.checker.js'
SITE_AUTH_COOKIE_KEYS = [
'iMuse-extranet'
]
SITE_FORCE_REDIRECT_LOCATOR = '#INDEX_TBL_LOGIN'
SITE_FORM_SUBMIT_ELEMENT = '#INDEX_BT_LOGIN'
class Sezhame(AppSettings):
SITE_LOGIN_PATH = '/sezhame/page/connexion-abonne?destination=user'
SITE_LOCATORS = [
{
'id': '#edit-user',
'label': 'Numero de cqrte',
'name': 'edit-user',
'kind': 'string',
'required': True,
'help': ''
},
{
'id': '#edit-password',
'label': 'Mot de passe',
'name': 'edit-password',
'kind': 'password',
'required': True,
'help': ''
}
]
SITE_AUTH_CHECKER = 'sezhame/js/auth.checker.js'
SITE_AUTH_COOKIE_KEYS = [
'SESSf36da25307ad6240a58ddd4f4b138952',
'ASPSESSIONIDQSDRASTR'
]
SITE_FORCE_REDIRECT_LOCATOR = '#dk-opac15-login-form'
class Teamnet(AppSettings):
SITE_LOGIN_PATH = '/auth/teamnetauth'
SITE_LOCATORS = [
{
'id': '#login',
'label': 'Mon identifiant',
'name': 'login',
'kind': 'string',
'required': True,
'help': ''
},
{
'id': '#mdp',
'label': 'Mon mot de passe',
'name': 'mdp',
'kind': 'password',
'required': True,
'help': ''
}
]
SITE_FORM_SUBMIT_ELEMENT = "input[type=submit][value='Me connecter']"
SITE_AUTH_CHECKER = 'teamnet/js/auth.checker.js'
SITE_AUTH_COOKIE_KEYS = [
'JSESSIONID',
]
SITE_FORCE_REDIRECT_LOCATOR = '#loginForm'
SITE_LOGOUT_LOCATOR = ".infoUtilisateur[alt=Deconnexion]"