summaryrefslogtreecommitdiffstats
path: root/ipsilon/root.py
blob: 6326436700256c342e97d211a84639855ff805e9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# Copyright (C) 2013  Simo Sorce <simo@redhat.com>
#
# see file 'COPYING' for use and warranty information
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU 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 General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

from ipsilon.util.page import Page
from ipsilon.util import errors
from ipsilon.login.common import Login
from ipsilon.login.common import Logout
from ipsilon.admin.common import Admin
from ipsilon.providers.common import LoadProviders
from ipsilon.admin.loginstack import LoginStack
from ipsilon.admin.info import InfoPlugins
from ipsilon.admin.login import LoginPlugins
from ipsilon.admin.providers import ProviderPlugins
from ipsilon.rest.common import Rest
from ipsilon.rest.providers import RestProviderPlugins
import cherrypy

sites = dict()


class Root(Page):

    def __init__(self, site, template_env):
        if site not in sites:
            sites[site] = dict()
        if template_env:
            sites[site]['template_env'] = template_env
        super(Root, self).__init__(sites[site])
        self.html_heads = dict()

        # set up error pages
        cherrypy.config['error_page.400'] = errors.Error_400(self._site)
        cherrypy.config['error_page.401'] = errors.Error_401(self._site)
        cherrypy.config['error_page.404'] = errors.Error_404(self._site)
        cherrypy.config['error_page.500'] = errors.Errors(self._site)

        # now set up the default login plugins
        self.login = Login(self._site)
        self.logout = Logout(self._site)

        # set up idp providers now
        LoadProviders(self, self._site)

        # after all plugins are setup we can instantiate the admin pages
        self.admin = Admin(self._site, 'admin')
        self.rest = Rest(self._site, 'rest')
        self.stack = LoginStack(self._site, self.admin)
        LoginPlugins(self._site, self.stack)
        InfoPlugins(self._site, self.stack)
        ProviderPlugins(self._site, self.admin)
        RestProviderPlugins(self._site, self.rest)

    def root(self):
        self.debug(self.html_heads)
        return self._template('index.html', title='Ipsilon',
                              heads=self.html_heads)