summaryrefslogtreecommitdiffstats
path: root/ipsilon/admin/common.py
diff options
context:
space:
mode:
authorPetr Vobornik <pvoborni@redhat.com>2014-01-23 15:00:51 +0100
committerPetr Vobornik <pvoborni@redhat.com>2014-01-24 19:07:05 +0100
commitefaed49f0c8069e3c3ddaf32be7bb8d26c8aae4c (patch)
tree91047b2a197bab1d613aab5028a6399ec67e3ff1 /ipsilon/admin/common.py
parent96891701df4f1a3c2416663fcc84dde3de3e6bd7 (diff)
downloadipsilon-efaed49f0c8069e3c3ddaf32be7bb8d26c8aae4c.tar.gz
ipsilon-efaed49f0c8069e3c3ddaf32be7bb8d26c8aae4c.tar.xz
ipsilon-efaed49f0c8069e3c3ddaf32be7bb8d26c8aae4c.zip
Rename src package to ipsilon
Diffstat (limited to 'ipsilon/admin/common.py')
-rwxr-xr-xipsilon/admin/common.py123
1 files changed, 123 insertions, 0 deletions
diff --git a/ipsilon/admin/common.py b/ipsilon/admin/common.py
new file mode 100755
index 0000000..6c975b1
--- /dev/null
+++ b/ipsilon/admin/common.py
@@ -0,0 +1,123 @@
+#!/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/>.
+
+from util import data
+from util import page
+from util import user
+import cherrypy
+
+def admin_protect(fn):
+
+ def check(*args, **kwargs):
+ if user.UserSession().get_user().is_admin:
+ return fn(*args, **kwargs)
+
+ raise cherrypy.HTTPError(403)
+
+ return check
+
+class LoginPluginPage(page.Page):
+
+ def __init__(self, obj, site, baseurl):
+ super(LoginPluginPage, self).__init__(site)
+ self._obj = obj
+ self.url = '%s/%s' % (baseurl, obj.name)
+
+ # Get the defaults
+ self.plugin_config = obj.get_config_desc()
+ if not self.plugin_config:
+ self.plugin_config = []
+
+ # Now overlay the actual config
+ for option in self.plugin_config:
+ self.plugin_config[option][2] = obj.get_config_value(option)
+
+ @admin_protect
+ def GET(self, *args, **kwargs):
+ return self._template('admin/login_plugin.html',
+ title='%s plugin' % self._obj.name,
+ name='admin_login_%s_form' % self._obj.name,
+ action=self.url,
+ options=self.plugin_config)
+
+ @admin_protect
+ def POST(self, *args, **kwargs):
+
+ message = "Nothing was modified."
+ new_values = dict()
+
+ for key, value in kwargs.iteritems():
+ if key in self.plugin_config:
+ if value != self.plugin_config[key][2]:
+ cherrypy.log.error("Storing [%s]: %s = %s" % (
+ self._obj.name, key, value))
+ new_values[key] = value
+
+ if len(new_values) != 0:
+ # First we try to save in the database
+ try:
+ store = data.Store()
+ store.save_login_plugin_config(self._obj.name, new_values)
+ message = "New configuration saved."
+ except Exception, e:
+ message = "Failed to save data!"
+
+ # And only if it succeeds we change the live object
+ for name, value in new_values.items():
+ self._obj.set_config_value(name, value)
+ self.plugin_config[name][2] = value
+
+ return self._template('admin/login_plugin.html',
+ message=message,
+ title='%s plugin' % self._obj.name,
+ name='admin_login_%s_form' % self._obj.name,
+ action=self.url,
+ options=self.plugin_config)
+
+ 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.Page):
+ def __init__(self, site, baseurl):
+ super(LoginPlugins, self).__init__(site)
+ self.url = '%s/login' % baseurl
+
+ for plugin in self._site['login_plugins']['available']:
+ cherrypy.log.error('Admin login plugin: %s' % plugin)
+ obj = self._site['login_plugins']['available'][plugin]
+ self.__dict__[plugin] = LoginPluginPage(obj, self._site, self.url)
+
+
+class Admin(page.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 root(self, *args, **kwargs):
+ login_plugins = self._site['login_plugins']
+ return self._template('admin/index.html', title='Administration',
+ available = login_plugins['available'],
+ enabled = login_plugins['enabled'])
+