diff options
-rwxr-xr-x | ipsilon/admin/common.py | 120 | ||||
-rwxr-xr-x | ipsilon/admin/login.py | 118 | ||||
-rwxr-xr-x | ipsilon/root.py | 4 | ||||
-rw-r--r-- | templates/admin/index.html | 22 | ||||
-rw-r--r-- | templates/admin/login.html | 26 | ||||
-rw-r--r-- | templates/admin/login_order.html | 2 | ||||
-rw-r--r-- | templates/admin/plugin_config.html (renamed from templates/admin/login_plugin.html) | 4 | ||||
-rw-r--r-- | templates/master-admin.html | 2 |
8 files changed, 168 insertions, 130 deletions
diff --git a/ipsilon/admin/common.py b/ipsilon/admin/common.py index 2897237..0a46797 100755 --- a/ipsilon/admin/common.py +++ b/ipsilon/admin/common.py @@ -17,20 +17,19 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. +import cherrypy from ipsilon.util.data import Store from ipsilon.util.page import Page from ipsilon.util.page import admin_protect -from ipsilon.util.plugin import PluginObject -import cherrypy -from ipsilon.login.common import FACILITY as LOGIN_FACILITY -class LoginPluginPage(Page): +class AdminPluginPage(Page): - def __init__(self, obj, site, baseurl): - super(LoginPluginPage, self).__init__(site) + def __init__(self, obj, site, baseurl, facility): + super(AdminPluginPage, self).__init__(site) self._obj = obj self.url = '%s/%s' % (baseurl, obj.name) + self.facility = facility # Get the defaults self.plugin_config = obj.get_config_desc() @@ -43,9 +42,10 @@ class LoginPluginPage(Page): @admin_protect def GET(self, *args, **kwargs): - return self._template('admin/login_plugin.html', + return self._template('admin/plugin_config.html', title='%s plugin' % self._obj.name, - name='admin_login_%s_form' % self._obj.name, + name='admin_%s_%s_form' % (self.facility, + self._obj.name), action=self.url, options=self.plugin_config) @@ -67,7 +67,7 @@ class LoginPluginPage(Page): # First we try to save in the database try: store = Store() - store.save_plugin_config(LOGIN_FACILITY, + store.save_plugin_config(self.facility, self._obj.name, new_values) message = "New configuration saved." message_type = "success" @@ -80,11 +80,12 @@ class LoginPluginPage(Page): self._obj.set_config_value(name, value) self.plugin_config[name][2] = value - return self._template('admin/login_plugin.html', + return self._template('admin/plugin_config.html', message=message, message_type=message_type, title='%s plugin' % self._obj.name, - name='admin_login_%s_form' % self._obj.name, + name='admin_%s_%s_form' % (self.facility, + self._obj.name), action=self.url, options=self.plugin_config) @@ -95,100 +96,11 @@ class LoginPluginPage(Page): return op(*args, **kwargs) -class LoginPluginsOrder(Page): - - def __init__(self, site, baseurl): - super(LoginPluginsOrder, self).__init__(site) - self.url = '%s/order' % baseurl - - @admin_protect - def GET(self, *args, **kwargs): - return self._template('admin/login_order.html', - title='login plugins order', - name='admin_login_order_form', - action=self.url, - options=self._site[LOGIN_FACILITY]['enabled']) - - @admin_protect - def POST(self, *args, **kwargs): - message = "Nothing was modified." - message_type = "info" - valid = self._site[LOGIN_FACILITY]['enabled'] - - if 'order' in kwargs: - order = kwargs['order'].split(',') - if len(order) != 0: - new_values = [] - try: - for v in order: - val = v.strip() - if val not in valid: - error = "Invalid plugin name: %s" % val - raise ValueError(error) - new_values.append(val) - if len(new_values) < len(valid): - for val in valid: - if val not in new_values: - new_values.append(val) - - po = PluginObject() - po.name = "global" - globalconf = dict() - globalconf['order'] = ','.join(new_values) - po.set_config(globalconf) - po.save_plugin_config(LOGIN_FACILITY) - - # When all is saved update also live config - self._site[LOGIN_FACILITY]['enabled'] = new_values - - message = "New configuration saved." - message_type = "success" - - except ValueError, e: - message = str(e) - message_type = "error" - - except Exception, e: # pylint: disable=broad-except - message = "Failed to save data!" - message_type = "error" - - return self._template('admin/login_order.html', - message=message, - message_type=message_type, - title='login plugins order', - name='admin_login_order_form', - action=self.url, - options=self._site[LOGIN_FACILITY]['enabled']) - - def root(self, *args, **kwargs): - cherrypy.log.error("method: %s" % cherrypy.request.method) - op = getattr(self, cherrypy.request.method, self.GET) - if callable(op): - return op(*args, **kwargs) - - -class LoginPlugins(Page): - def __init__(self, site, baseurl): - super(LoginPlugins, self).__init__(site) - self.url = '%s/login' % baseurl - - for plugin in self._site[LOGIN_FACILITY]['available']: - cherrypy.log.error('Admin login plugin: %s' % plugin) - obj = self._site[LOGIN_FACILITY]['available'][plugin] - self.__dict__[plugin] = LoginPluginPage(obj, self._site, self.url) - - self.order = LoginPluginsOrder(self._site, self.url) - - class Admin(Page): - def __init__(self, *args, **kwargs): - super(Admin, self).__init__(*args, **kwargs) - self.url = '%s/admin' % self.basepath - self.login = LoginPlugins(self._site, self.url) + def __init__(self, site, mount): + super(Admin, self).__init__(site) + self.url = '%s/%s' % (self.basepath, mount) def root(self, *args, **kwargs): - login_plugins = self._site[LOGIN_FACILITY] - return self._template('admin/index.html', title='Administration', - available=login_plugins['available'], - enabled=login_plugins['enabled']) + return self._template('admin/index.html', title='Configuration') diff --git a/ipsilon/admin/login.py b/ipsilon/admin/login.py new file mode 100755 index 0000000..1f5e9fa --- /dev/null +++ b/ipsilon/admin/login.py @@ -0,0 +1,118 @@ +#!/usr/bin/python +# +# Copyright (C) 2014 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/>. + +import cherrypy +from ipsilon.util.page import Page +from ipsilon.util.page import admin_protect +from ipsilon.util.plugin import PluginObject +from ipsilon.admin.common import AdminPluginPage +from ipsilon.login.common import FACILITY + + +class LoginPluginsOrder(Page): + + def __init__(self, site, baseurl): + super(LoginPluginsOrder, self).__init__(site) + self.url = '%s/order' % baseurl + + @admin_protect + def GET(self, *args, **kwargs): + return self._template('admin/login_order.html', + title='login plugins order', + name='admin_login_order_form', + action=self.url, + options=self._site[FACILITY]['enabled']) + + @admin_protect + def POST(self, *args, **kwargs): + message = "Nothing was modified." + message_type = "info" + valid = self._site[FACILITY]['enabled'] + + if 'order' in kwargs: + order = kwargs['order'].split(',') + if len(order) != 0: + new_values = [] + try: + for v in order: + val = v.strip() + if val not in valid: + error = "Invalid plugin name: %s" % val + raise ValueError(error) + new_values.append(val) + if len(new_values) < len(valid): + for val in valid: + if val not in new_values: + new_values.append(val) + + po = PluginObject() + po.name = "global" + globalconf = dict() + globalconf['order'] = ','.join(new_values) + po.set_config(globalconf) + po.save_plugin_config(FACILITY) + + # When all is saved update also live config + self._site[FACILITY]['enabled'] = new_values + + message = "New configuration saved." + message_type = "success" + + except ValueError, e: + message = str(e) + message_type = "error" + + except Exception, e: # pylint: disable=broad-except + message = "Failed to save data!" + message_type = "error" + + return self._template('admin/login_order.html', + message=message, + message_type=message_type, + title='login plugins order', + name='admin_login_order_form', + action=self.url, + options=self._site[FACILITY]['enabled']) + + def root(self, *args, **kwargs): + cherrypy.log.error("method: %s" % cherrypy.request.method) + op = getattr(self, cherrypy.request.method, self.GET) + if callable(op): + return op(*args, **kwargs) + + +class LoginPlugins(Page): + def __init__(self, site, parent): + super(LoginPlugins, self).__init__(site) + parent.login = self + self.url = '%s/login' % parent.url + + for plugin in self._site[FACILITY]['available']: + cherrypy.log.error('Admin login plugin: %s' % plugin) + obj = self._site[FACILITY]['available'][plugin] + self.__dict__[plugin] = AdminPluginPage(obj, self._site, + self.url, FACILITY) + + self.order = LoginPluginsOrder(self._site, self.url) + + def root(self, *args, **kwargs): + login_plugins = self._site[FACILITY] + return self._template('admin/login.html', title='Login Plugins', + available=login_plugins['available'], + enabled=login_plugins['enabled']) diff --git a/ipsilon/root.py b/ipsilon/root.py index 413f453..c308c95 100755 --- a/ipsilon/root.py +++ b/ipsilon/root.py @@ -23,6 +23,7 @@ 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.login import LoginPlugins import cherrypy sites = dict() @@ -50,7 +51,8 @@ class Root(Page): LoadProviders(self, self._site) # after all plugins are setup we can instantiate the admin pages - self.admin = Admin(self._site) + self.admin = Admin(self._site, 'admin') + LoginPlugins(self._site, self.admin) def root(self): return self._template('index.html', title='Ipsilon') diff --git a/templates/admin/index.html b/templates/admin/index.html index 1957a7f..a0d17fe 100644 --- a/templates/admin/index.html +++ b/templates/admin/index.html @@ -1,26 +1,6 @@ {% extends "master-admin.html" %} {% block main %} {% if user.is_admin %} - <h2>Login plugins</h2> - - {% for p in available %} - <div class="row"> - <div class="col-md-3 col-sm-3 col-xs-6">{{ p }}</div> - <div class="col-md-3 col-sm-3 col-xs-6"> - {% if p in enabled %} - <a class="btn btn-default" href="{{ basepath }}/admin/login/{{ p }}/disable">Disable</a> - <a class="btn btn-default" href="{{ basepath }}/admin/login/{{ p }}">Configure</a> - {% else %} - <a class="btn btn-default" href="{{ basepath }}/admin/login/{{ p }}/enable">Enable</a> - {% endif %} - </div> - </div> - {% endfor %} - - <h3>Plugins order</h3> - <div class="col-md-3 col-sm-3 col-xs-6">{{ ', '.join(enabled) }}</div> - <div class="col-md-3 col-sm-3 col-xs-6"> - <a class="btn btn-default" href="{{ basepath }}/admin/login/order">configure</a> - </div> + <h2>Select an item to configure</h2> {% endif %} {% endblock %} diff --git a/templates/admin/login.html b/templates/admin/login.html new file mode 100644 index 0000000..1957a7f --- /dev/null +++ b/templates/admin/login.html @@ -0,0 +1,26 @@ +{% extends "master-admin.html" %} +{% block main %} +{% if user.is_admin %} + <h2>Login plugins</h2> + + {% for p in available %} + <div class="row"> + <div class="col-md-3 col-sm-3 col-xs-6">{{ p }}</div> + <div class="col-md-3 col-sm-3 col-xs-6"> + {% if p in enabled %} + <a class="btn btn-default" href="{{ basepath }}/admin/login/{{ p }}/disable">Disable</a> + <a class="btn btn-default" href="{{ basepath }}/admin/login/{{ p }}">Configure</a> + {% else %} + <a class="btn btn-default" href="{{ basepath }}/admin/login/{{ p }}/enable">Enable</a> + {% endif %} + </div> + </div> + {% endfor %} + + <h3>Plugins order</h3> + <div class="col-md-3 col-sm-3 col-xs-6">{{ ', '.join(enabled) }}</div> + <div class="col-md-3 col-sm-3 col-xs-6"> + <a class="btn btn-default" href="{{ basepath }}/admin/login/order">configure</a> + </div> +{% endif %} +{% endblock %} diff --git a/templates/admin/login_order.html b/templates/admin/login_order.html index c78fe55..b14c4d9 100644 --- a/templates/admin/login_order.html +++ b/templates/admin/login_order.html @@ -18,7 +18,7 @@ <button id="submit" class="btn btn-primary" name="submit" type="submit" value="Submit"> Save </button> - <a href="{{ basepath }}/admin" class="btn btn-default" title="Back">Back</a> + <a href="{{ basepath }}/admin/login" class="btn btn-default" title="Back">Back</a> </form> </div> {% endblock %} diff --git a/templates/admin/login_plugin.html b/templates/admin/plugin_config.html index b45b3a4..7c143af 100644 --- a/templates/admin/login_plugin.html +++ b/templates/admin/plugin_config.html @@ -20,7 +20,7 @@ <button id="submit" class="btn btn-primary" name="submit" type="submit" value="Submit"> Save </button> - <a href="{{ basepath }}/admin" class="btn btn-default" title="Back">Back</a> + <a href="{{ basepath }}/admin/login" class="btn btn-default" title="Back">Back</a> </form> </div> -{% endblock %}
\ No newline at end of file +{% endblock %} diff --git a/templates/master-admin.html b/templates/master-admin.html index 796c917..43770c1 100644 --- a/templates/master-admin.html +++ b/templates/master-admin.html @@ -42,7 +42,7 @@ </ul> <ul class="nav navbar-nav navbar-primary"> <li> - <a href="{{ basepath }}/admin">Login plugins</a> + <a href="{{ basepath }}/admin/login">Login plugins</a> </li> <li> <a href="{{ basepath }}/admin">Providers</a> |