summaryrefslogtreecommitdiff
path: root/manager/library/plugins
diff options
context:
space:
mode:
authorMarkus Warg <markus@mawaunix.mawa.sls>2010-03-31 16:43:49 +0200
committerMarkus Warg <markus@mawaunix.mawa.sls>2010-03-31 16:43:49 +0200
commit4f4c5ce3ccf0370f926d75e700e8b0bd2208f3f6 (patch)
tree82cb017ac68772ea36c0f522ec019bf14fbdc77a /manager/library/plugins
parent8398c9048d34a1f51212ae770998fc082fc93b69 (diff)
downloadcacert-mgr-4f4c5ce3ccf0370f926d75e700e8b0bd2208f3f6.tar.gz
cacert-mgr-4f4c5ce3ccf0370f926d75e700e8b0bd2208f3f6.tar.xz
cacert-mgr-4f4c5ce3ccf0370f926d75e700e8b0bd2208f3f6.zip
initial setup of framework code
enabled features * login * crt login * top / left menu * logging * db layer
Diffstat (limited to 'manager/library/plugins')
-rw-r--r--manager/library/plugins/plugin.buildmenu.php74
-rw-r--r--manager/library/plugins/plugin.charsetheader.php13
-rw-r--r--manager/library/plugins/plugin.forceauth.php29
-rw-r--r--manager/library/plugins/plugin.loginlogout.php25
4 files changed, 141 insertions, 0 deletions
diff --git a/manager/library/plugins/plugin.buildmenu.php b/manager/library/plugins/plugin.buildmenu.php
new file mode 100644
index 0000000..d98b14e
--- /dev/null
+++ b/manager/library/plugins/plugin.buildmenu.php
@@ -0,0 +1,74 @@
+<?php
+
+/**
+ * this plugin tries to add modules to the top navigation depending on the user
+ * which is logged in and the required permissions needed (provided by the action modules)
+ *
+ * @author markus
+ * $Id: plugin.buildmenu.php 95 2010-03-19 14:14:39Z markus $
+ */
+class BuildMenu extends Zend_Controller_Plugin_Abstract {
+ public function preDispatch(Zend_Controller_Request_Abstract $request) {
+ $session = Zend_Registry::get('session');
+ if (!isset($session->authdata) || !isset($session->authdata['authed']) || $session->authdata['authed'] === false)
+ return;
+
+ $cur_ctrl = $request->getControllerName();
+ $cur_action = $request->getActionName();
+
+ $view = Zend_Registry::get('view');
+
+ if (is_dir(FWACTIONS_PATH)) {
+ $dir = opendir(FWACTIONS_PATH);
+
+ while (($file = readdir($dir)) !== false) {
+ if ($file == '.' || $file == '..')
+ continue;
+ if (preg_match('/^Action([a-zA-Z0-9_]*)\.php/', $file, $match)) {
+ $path = FWACTIONS_PATH . '/' . $file;
+ require_once($path);
+
+ $r = new ReflectionClass($match[1]);
+
+ if ($r->isSubclassOf('FWAction')) {
+ /**
+ * match Actions permission with the permissions of the currently logged in user,
+ * add to menu if user has access to that action
+ */
+
+ $required = $r->getMethod('getRequiredPermissions')->invoke(null);
+ $menuprio = $r->getMethod('getTopNavPrio')->invoke(null);
+ $ctrl = $r->getMethod('getController')->invoke(null);
+ $action = $r->getMethod('getAction')->invoke(null);
+ $text = $r->getMethod('getMenutext')->invoke(null);
+ $role = $session->authdata['authed_role'];
+
+ if ($cur_ctrl == $ctrl) # && $cur_action == $action)
+ $aclass = ' class="active"';
+ else
+ $aclass = '';
+
+ $acl = $session->authdata['authed_permissions'];
+ if (is_array($required) && count($required) == 0) {
+ $view->topNav('<a href="' .
+ $view->url(array('controller' => $ctrl, 'action' => $action), 'default', true) .
+ '"' . $aclass . '>' . I18n::_($text) . '</a>', Zend_View_Helper_Placeholder_Container_Abstract::SET, $menuprio);
+ }
+ else {
+ foreach ($required as $rperm) {
+ if ($acl->has($rperm) && $acl->isAllowed($role, $rperm, 'view')) {
+ $view->topNav('<a href="' .
+ $view->url(array('controller' => $ctrl, 'action' => $action), 'default', true) .
+ '"' . $aclass . '>' . I18n::_($text) . '</a>', Zend_View_Helper_Placeholder_Container_Abstract::SET, $menuprio);
+ break; // exit on first match
+ }
+ }
+ }
+ }
+ }
+ }
+
+ closedir($dir);
+ }
+ }
+} \ No newline at end of file
diff --git a/manager/library/plugins/plugin.charsetheader.php b/manager/library/plugins/plugin.charsetheader.php
new file mode 100644
index 0000000..57e4f50
--- /dev/null
+++ b/manager/library/plugins/plugin.charsetheader.php
@@ -0,0 +1,13 @@
+<?php
+/**
+ * @author markus
+ * $Id: plugin.charsetheader.php 13 2009-11-24 14:52:56Z markus $
+ */
+class CharsetHeader extends Zend_Controller_Plugin_Abstract {
+ public function preDispatch(Zend_Controller_Request_Abstract $request) {
+ $response = $this->getResponse();
+ if ($response->canSendHeaders() === true) {
+ $response->setHeader('Content-Type', 'text/html; charset=utf-8');
+ }
+ }
+} \ No newline at end of file
diff --git a/manager/library/plugins/plugin.forceauth.php b/manager/library/plugins/plugin.forceauth.php
new file mode 100644
index 0000000..4fa9068
--- /dev/null
+++ b/manager/library/plugins/plugin.forceauth.php
@@ -0,0 +1,29 @@
+<?php
+/**
+ * @author markus
+ * $Id: plugin.forceauth.php 40 2009-12-21 09:40:43Z markus $
+ */
+class ForceAuth extends Zend_Controller_Plugin_Abstract {
+ public function dispatchLoopStartup(Zend_Controller_Request_Abstract $request) {
+ $session = Zend_Registry::get('session');
+
+ if (in_array($request->getControllerName(), array('login', 'error', 'js', 'img', 'css')))
+ return;
+
+ if (!isset($session->authdata) || !isset($session->authdata['authed']) || $session->authdata['authed'] === false) {
+ $fc = Zend_Controller_Front::getInstance();
+
+ $response = $fc->getResponse();
+ $response->canSendHeaders(true);
+
+ $response->setHeader('Location', 'login', true);
+ $response->setHeader('Status', '301', true);
+ Log::Log()->debug('redirected to login');
+
+ $request->setModuleName('default')
+ ->setControllerName('login')
+ ->setActionName('index')
+ ->setDispatched(false);
+ }
+ }
+}
diff --git a/manager/library/plugins/plugin.loginlogout.php b/manager/library/plugins/plugin.loginlogout.php
new file mode 100644
index 0000000..6de7a92
--- /dev/null
+++ b/manager/library/plugins/plugin.loginlogout.php
@@ -0,0 +1,25 @@
+<?php
+
+/**
+ * this plugin just monitors the authdata section in the current session and adds an login / logout link to the
+ * top navigation bar depending on the value that was found
+ * @author markus
+ * $Id: plugin.loginlogout.php 95 2010-03-19 14:14:39Z markus $
+ */
+class LoginLogout extends Zend_Controller_Plugin_Abstract {
+ public function postDispatch(Zend_Controller_Request_Abstract $request) {
+ $session = Zend_Registry::get('session');
+ if (!isset($session->authdata) || !isset($session->authdata['authed']) || $session->authdata['authed'] === false) {
+ $controller = 'login';
+ $text = 'Login';
+ }
+ else {
+ $controller = 'logout';
+ $text = 'Logout';
+ }
+ $view = Zend_Registry::get('view');
+ $view->topNav('<a href="' .
+ $view->url(array('controller' => $controller), 'default', true) .
+ '">' . I18n::_($text) . '</a>', Zend_View_Helper_Placeholder_Container_Abstract::SET, 1000);
+ }
+}