initial setup of framework code
authorMarkus Warg <markus@mawaunix.mawa.sls>
Wed, 31 Mar 2010 14:43:49 +0000 (16:43 +0200)
committerMarkus Warg <markus@mawaunix.mawa.sls>
Wed, 31 Mar 2010 14:43:49 +0000 (16:43 +0200)
enabled features
* login
* crt login
* top / left menu
* logging
* db layer

54 files changed:
manager/.buildpath [new file with mode: 0644]
manager/.project [new file with mode: 0644]
manager/.settings/.jsdtscope [new file with mode: 0644]
manager/.settings/org.eclipse.php.core.prefs [new file with mode: 0644]
manager/.settings/org.eclipse.wst.jsdt.ui.superType.container [new file with mode: 0644]
manager/.settings/org.eclipse.wst.jsdt.ui.superType.name [new file with mode: 0644]
manager/application/Bootstrap.php [new file with mode: 0644]
manager/application/configs/application.ini [new file with mode: 0644]
manager/application/controllers/ErrorController.php [new file with mode: 0644]
manager/application/controllers/IndexController.php [new file with mode: 0644]
manager/application/controllers/LoginController.php [new file with mode: 0644]
manager/application/controllers/LogoutController.php [new file with mode: 0644]
manager/application/layouts/scripts/layout.phtml [new file with mode: 0644]
manager/application/views/helpers/LeftNav.php [new file with mode: 0644]
manager/application/views/helpers/TopNav.php [new file with mode: 0644]
manager/application/views/helpers/UserInfo.php [new file with mode: 0644]
manager/application/views/scripts/error/error.phtml [new file with mode: 0644]
manager/application/views/scripts/error/permissiondenied.phtml [new file with mode: 0644]
manager/application/views/scripts/index/index.phtml [new file with mode: 0644]
manager/application/views/scripts/login/index.phtml [new file with mode: 0644]
manager/application/views/scripts/login/loginresult.phtml [new file with mode: 0644]
manager/application/views/scripts/logout/index.phtml [new file with mode: 0644]
manager/library/actions/ActionIndex.php [new file with mode: 0644]
manager/library/actions/FWAction.php [new file with mode: 0644]
manager/library/config/Config.php [new file with mode: 0644]
manager/library/config/Config_Db.php [new file with mode: 0644]
manager/library/config/Config_Writer_Db.php [new file with mode: 0644]
manager/library/date/HumanReadableTime.php [new file with mode: 0644]
manager/library/date/exception.HumanReadableTimeException.php [new file with mode: 0644]
manager/library/date/testHumanReadableTime.php [new file with mode: 0644]
manager/library/exception/exception.Base.php [new file with mode: 0644]
manager/library/global/defines.php [new file with mode: 0644]
manager/library/helpers/GetEnv.php [new file with mode: 0644]
manager/library/i18n/I18n.php [new file with mode: 0644]
manager/library/l10n/L10n.php [new file with mode: 0644]
manager/library/log/Log.php [new file with mode: 0644]
manager/library/plugins/plugin.buildmenu.php [new file with mode: 0644]
manager/library/plugins/plugin.charsetheader.php [new file with mode: 0644]
manager/library/plugins/plugin.forceauth.php [new file with mode: 0644]
manager/library/plugins/plugin.loginlogout.php [new file with mode: 0644]
manager/locale/en_US/locale.php [new file with mode: 0644]
manager/public/.htaccess [new file with mode: 0644]
manager/public/css/form_dl.css [new file with mode: 0644]
manager/public/css/form_dl_wide.css [new file with mode: 0644]
manager/public/css/global.css [new file with mode: 0644]
manager/public/css/login.css [new file with mode: 0644]
manager/public/favicon.ico [new file with mode: 0644]
manager/public/img/cacert4.png [new file with mode: 0644]
manager/public/index.php [new file with mode: 0644]
manager/public/js/center.js [new file with mode: 0644]
manager/public/js/positionUserInfo.js [new file with mode: 0644]
manager/tests/application/bootstrap.php [new file with mode: 0644]
manager/tests/library/bootstrap.php [new file with mode: 0644]
manager/tests/phpunit.xml [new file with mode: 0644]

diff --git a/manager/.buildpath b/manager/.buildpath
new file mode 100644 (file)
index 0000000..d9b76e7
--- /dev/null
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>\r
+<buildpath>\r
+       <buildpathentry kind="src" path=""/>\r
+       <buildpathentry kind="con" path="org.zend.php.framework.CONTAINER"/>\r
+       <buildpathentry kind="con" path="org.eclipse.php.core.LANGUAGE"/>\r
+</buildpath>\r
diff --git a/manager/.project b/manager/.project
new file mode 100644 (file)
index 0000000..5f27609
--- /dev/null
@@ -0,0 +1,29 @@
+<?xml version="1.0" encoding="UTF-8"?>\r
+<projectDescription>\r
+       <name>ca-mgr (mawaunix)</name>\r
+       <comment></comment>\r
+       <projects>\r
+       </projects>\r
+       <buildSpec>\r
+               <buildCommand>\r
+                       <name>org.eclipse.wst.jsdt.core.javascriptValidator</name>\r
+                       <arguments>\r
+                       </arguments>\r
+               </buildCommand>\r
+               <buildCommand>\r
+                       <name>org.eclipse.wst.validation.validationbuilder</name>\r
+                       <arguments>\r
+                       </arguments>\r
+               </buildCommand>\r
+               <buildCommand>\r
+                       <name>org.eclipse.dltk.core.scriptbuilder</name>\r
+                       <arguments>\r
+                       </arguments>\r
+               </buildCommand>\r
+       </buildSpec>\r
+       <natures>\r
+               <nature>org.zend.php.framework.ZendFrameworkNature</nature>\r
+               <nature>org.eclipse.php.core.PHPNature</nature>\r
+               <nature>org.eclipse.wst.jsdt.core.jsNature</nature>\r
+       </natures>\r
+</projectDescription>\r
diff --git a/manager/.settings/.jsdtscope b/manager/.settings/.jsdtscope
new file mode 100644 (file)
index 0000000..f40dd98
--- /dev/null
@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="UTF-8"?>\r
+<classpath>\r
+       <classpathentry kind="con" path="org.eclipse.wst.jsdt.launching.JRE_CONTAINER"/>\r
+       <classpathentry kind="con" path="org.eclipse.wst.jsdt.launching.WebProject">\r
+               <attributes>\r
+                       <attribute name="hide" value="true"/>\r
+               </attributes>\r
+       </classpathentry>\r
+       <classpathentry kind="con" path="org.eclipse.wst.jsdt.launching.baseBrowserLibrary"/>\r
+       <classpathentry kind="output" path=""/>\r
+</classpath>\r
diff --git a/manager/.settings/org.eclipse.php.core.prefs b/manager/.settings/org.eclipse.php.core.prefs
new file mode 100644 (file)
index 0000000..cbc9cef
--- /dev/null
@@ -0,0 +1,5 @@
+#Wed Mar 31 11:13:35 CEST 2010\r
+eclipse.preferences.version=1\r
+include_path=0;/ca-mgr (mawaunix)\u00055;org.zend.php.framework.CONTAINER\r
+phpVersion=php5\r
+use_asp_tags_as_php=false\r
diff --git a/manager/.settings/org.eclipse.wst.jsdt.ui.superType.container b/manager/.settings/org.eclipse.wst.jsdt.ui.superType.container
new file mode 100644 (file)
index 0000000..3bd5d0a
--- /dev/null
@@ -0,0 +1 @@
+org.eclipse.wst.jsdt.launching.baseBrowserLibrary
\ No newline at end of file
diff --git a/manager/.settings/org.eclipse.wst.jsdt.ui.superType.name b/manager/.settings/org.eclipse.wst.jsdt.ui.superType.name
new file mode 100644 (file)
index 0000000..05bd71b
--- /dev/null
@@ -0,0 +1 @@
+Window
\ No newline at end of file
diff --git a/manager/application/Bootstrap.php b/manager/application/Bootstrap.php
new file mode 100644 (file)
index 0000000..664d5e2
--- /dev/null
@@ -0,0 +1,154 @@
+<?php\r
+require_once('plugins/plugin.charsetheader.php');\r
+require_once('plugins/plugin.forceauth.php');\r
+require_once('plugins/plugin.loginlogout.php');\r
+require_once('plugins/plugin.buildmenu.php');\r
+require_once('config/Config.php');\r
+require_once('log/Log.php');\r
+require_once('l10n/L10n.php');\r
+require_once('i18n/I18n.php');\r
+\r
+class Bootstrap extends Zend_Application_Bootstrap_Bootstrap {\r
+       protected function _initAutoload() {\r
+        $autoloader = new Zend_Application_Module_Autoloader(array(\r
+            'namespace' => 'Default_',\r
+            'basePath'  => dirname(__FILE__)\r
+        ));\r
+        return $autoloader;\r
+    }\r
+\r
+       protected function _initPlugins() {\r
+               $this->bootstrap('session');\r
+\r
+               $fc = Zend_Controller_Front::getInstance();\r
+\r
+               $charset_header = new CharsetHeader();\r
+               $fc->registerPlugin($charset_header);\r
+\r
+               $force_auth = new ForceAuth();\r
+               $fc->registerPlugin($force_auth);\r
+\r
+               $buildmenu = new BuildMenu();\r
+               $fc->registerPlugin($buildmenu);\r
+\r
+               $loginlogout = new LoginLogout();\r
+               $fc->registerPlugin($loginlogout);\r
+       }\r
+\r
+       protected function _initDoctype() {\r
+               $this->bootstrap('view');\r
+               $this->bootstrap('log');\r
+               $this->bootstrap('I18n');\r
+               $this->bootstrap('session');\r
+\r
+               $view = $this->getResource('view');\r
+               Zend_Registry::set('view', $view);\r
+               $view->doctype('XHTML1_STRICT');\r
+               $view->addHelperPath(APPLICATION_PATH . '/views/helpers/');\r
+               $view->headTitle = I18n::_('CACert Test Manager');\r
+       }\r
+\r
+       /**\r
+        * @todo expireSessionCookie()\r
+        * @todo rememberMe(xx)\r
+        * @todo forgetMe()\r
+        * @see Zend_Registry::get('session');\r
+        * @return Zend_Session_Namespace\r
+        */\r
+       protected function _initSession() {\r
+               $options = $this->getOption('ca_mgr');\r
+\r
+               $db = Zend_Db::factory($options['db']['session']['pdo'], $options['db']['session']);\r
+\r
+               /**\r
+                * automatically clean up expired session entries from session cache\r
+                * use the modified and lifetime stamps to calculate expire time\r
+                */\r
+               if ($options['db']['session']['autocleanup'] == '1') {\r
+                       $stmt = $db->query('delete from front_session where (modified + lifetime * 2) < unix_timestamp()');\r
+                       # $stmt->execute();\r
+               }\r
+\r
+               //you can either set the Zend_Db_Table default adapter\r
+               //or you can pass the db connection straight to the save handler $config\r
+               // @see lifetimeColumn / lifetime / overrideLifetime, lifetime defaults to php.ini: session.gc_maxlifetime\r
+               Zend_Db_Table_Abstract::setDefaultAdapter($db);\r
+               $config = array(\r
+                   'name'           => 'front_session',\r
+                   'primary'        => 'id',\r
+                   'modifiedColumn' => 'modified',\r
+                   'dataColumn'     => 'data',\r
+                   'lifetimeColumn' => 'lifetime'\r
+               );\r
+\r
+               //create your Zend_Session_SaveHandler_DbTable and\r
+               //set the save handler for Zend_Session\r
+               Zend_Session::setSaveHandler(new Zend_Session_SaveHandler_DbTable($config));\r
+\r
+               // Zend_Session::rememberMe(7200);\r
+\r
+               //start your session!\r
+               Zend_Session::start();\r
+\r
+               $session = new Zend_Session_Namespace();\r
+               if (!isset($session->started))\r
+                       $session->started = time();\r
+               if (!isset($session->authdata))\r
+                       $session->authdata = array('authed' => false);\r
+\r
+               Zend_Registry::set('session', $session);\r
+               return $session;\r
+       }\r
+\r
+       /**\r
+        * get the basic system config from database, store the config object in the bootstrap registry\r
+        * @see Zend_Registry::get('config');\r
+        * @return Config\r
+        */\r
+       protected function _initConfig() {\r
+               $options = $this->getOption('ca_mgr');\r
+               $db = Zend_Db::factory($options['db']['config']['pdo'], $options['db']['config']);\r
+               $config = Config::getInstance(SYSTEM_CONFIG, $db);\r
+\r
+               Zend_Registry::set('config', $config);\r
+               Zend_Registry::set('config_dbc', $db);\r
+\r
+               return $config;\r
+       }\r
+\r
+       /**\r
+        * make singleton system logger\r
+        * @see Zend_Registry::get('log');\r
+        * @return Log\r
+        */\r
+       public function _initLog() {\r
+               $this->bootstrap('Config');\r
+\r
+               $op = $this->getOption('log');\r
+               $log = Log::getInstance(SYSTEM_LOG, $op['application']);\r
+\r
+               Zend_Registry::set('log', $log);\r
+               return $log;\r
+       }\r
+\r
+       /**\r
+        * make singleton I18n (internationalization) object (translation)\r
+        */\r
+       public function _initI18n() {\r
+               $this->bootstrap('Config');\r
+               // need existing L10n object for initialization\r
+               $this->bootstrap('L10n');\r
+\r
+               $I18n = I18n::getInstance(L10n::getInstance()->getLanguage());\r
+       }\r
+\r
+       /**\r
+        * make singleton L10n (localization) object (set locale, convert date and\r
+        * number formats)\r
+        */\r
+       public function _initL10n() {\r
+               $this->bootstrap('Config');\r
+\r
+               $L10n = L10n::getInstance();\r
+       }\r
+}\r
diff --git a/manager/application/configs/application.ini b/manager/application/configs/application.ini
new file mode 100644 (file)
index 0000000..61edc99
--- /dev/null
@@ -0,0 +1,56 @@
+[production]\r
+phpSettings.display_startup_errors = 1\r
+phpSettings.display_errors = 1\r
+includePaths.library = LIBRARY_PATH\r
+bootstrap.path = APPLICATION_PATH "/Bootstrap.php"\r
+bootstrap.class = "Bootstrap"\r
+resources.frontController.controllerDirectory = APPLICATION_PATH "/controllers"\r
+resources.frontController.noViewRenderer = 0\r
+resources.frontController.noErrorHandler = 0\r
+resources.frontController.useDefaultControllerAlways = 0\r
+resources.layout.layoutPath = APPLICATION_PATH "/layouts/scripts"\r
+resources.view[] =\r
+\r
+; Database settings for Session DB\r
+ca_mgr.db.session.pdo                          = "Pdo_Mysql"\r
+ca_mgr.db.session.autocleanup          = 1\r
+ca_mgr.db.session.host                         = "localhost"\r
+ca_mgr.db.session.username                     = "front_session"\r
+ca_mgr.db.session.password                     = "laskdsfzrwethv45"\r
+ca_mgr.db.session.dbname                       = "ca_mgr"\r
+\r
+; Database settings for Auth DB (CACert User Table)\r
+ca_mgr.db.auth.pdo                                     = "Pdo_Mysql"\r
+ca_mgr.db.auth.host                                    = "localhost"\r
+ca_mgr.db.auth.username                                = "ca_mgr"\r
+ca_mgr.db.auth.password                                = "jsdfhsd47534hsdf7"\r
+ca_mgr.db.auth.dbname                          = "cacert"\r
+ca_mgr.db.auth.tablename                       = "users"\r
+\r
+; Database settings for Auth DB (Manager User Table)\r
+ca_mgr.db.auth2.pdo                                    = "Pdo_Mysql"\r
+ca_mgr.db.auth2.host                           = "localhost"\r
+ca_mgr.db.auth2.username                       = "ca_mgr"\r
+ca_mgr.db.auth2.password                       = "jsdfhsd47534hsdf7"\r
+ca_mgr.db.auth2.dbname                         = "ca_mgr"\r
+ca_mgr.db.auth2.tablename                      = "system_user"\r
+\r
+; Database settings for Config DB (access to system_config and dnssecme data tables)\r
+ca_mgr.db.config.pdo                           = "Pdo_Mysql"\r
+ca_mgr.db.config.host                          = "localhost"\r
+ca_mgr.db.config.username                      = "ca_mgr"\r
+ca_mgr.db.config.password                      = "jsdfhsd47534hsdf7"\r
+ca_mgr.db.config.dbname                                = "ca_mgr"\r
+\r
+; Application name for logger\r
+log.application                                                = "web"\r
+\r
+[staging : production]\r
+\r
+[testing : production]\r
+phpSettings.display_startup_errors = 1\r
+phpSettings.display_errors = 1\r
+\r
+[development : production]\r
+phpSettings.display_startup_errors = 1\r
+phpSettings.display_errors = 1
\ No newline at end of file
diff --git a/manager/application/controllers/ErrorController.php b/manager/application/controllers/ErrorController.php
new file mode 100644 (file)
index 0000000..806565d
--- /dev/null
@@ -0,0 +1,35 @@
+<?php\r
+\r
+class ErrorController extends Zend_Controller_Action\r
+{\r
+\r
+    public function errorAction()\r
+    {\r
+        $errors = $this->_getParam('error_handler');\r
+\r
+        switch ($errors->type) {\r
+            case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_CONTROLLER:\r
+            case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_ACTION:\r
+\r
+                // 404 error -- controller or action not found\r
+                $this->getResponse()->setHttpResponseCode(404);\r
+                $this->view->message = 'Page not found';\r
+                break;\r
+            default:\r
+                // application error\r
+                $this->getResponse()->setHttpResponseCode(500);\r
+                $this->view->message = 'Application error';\r
+                break;\r
+        }\r
+\r
+        $this->view->exception = $errors->exception;\r
+        $this->view->request   = $errors->request;\r
+\r
+        Log::Log()->emerg($errors->exception);\r
+    }\r
+\r
+       public function permissiondeniedAction() {\r
+\r
+       }\r
+}\r
+\r
diff --git a/manager/application/controllers/IndexController.php b/manager/application/controllers/IndexController.php
new file mode 100644 (file)
index 0000000..8b185e2
--- /dev/null
@@ -0,0 +1,28 @@
+<?php
+/**
+ * @author markus
+ * $Id: IndexController.php 6 2009-11-18 14:52:50Z markus $
+ */
+
+class IndexController extends Zend_Controller_Action
+{
+
+    public function init()
+    {
+        /* Initialize action controller here */
+       /**
+        * get bootstrap, get resource from bootstrap
+        * resources are created when an bootstrap _init method returns an object
+       $bootstrap = $this->getInvokeArg('bootstrap');
+        $view = $bootstrap->getResource('view');
+        */
+    }
+
+    public function indexAction()
+    {
+        // action body
+    }
+
+
+}
+
diff --git a/manager/application/controllers/LoginController.php b/manager/application/controllers/LoginController.php
new file mode 100644 (file)
index 0000000..e007e05
--- /dev/null
@@ -0,0 +1,260 @@
+<?php\r
+/**\r
+ * @author markus\r
+ * $Id: LoginController.php 75 2010-02-25 14:40:10Z markus $\r
+ */\r
+\r
+require_once('helpers/GetEnv.php');\r
+require_once('config/Config.php');\r
+\r
+class LoginController extends Zend_Controller_Action\r
+{\r
+\r
+    public function init() {\r
+        /* Initialize action controller here */\r
+    }\r
+\r
+    public function indexAction() {\r
+               $this->view->form = $this->getForm();\r
+               $this->render('index');\r
+    }\r
+\r
+    public function loginAction() {\r
+       $form = $this->getForm();\r
+       if ($form->isValid($_POST)) {\r
+               $config = new Zend_Config_Ini(APPLICATION_PATH . '/configs/application.ini', APPLICATION_ENV);\r
+\r
+               $db = Zend_Db::factory($config->ca_mgr->db->auth->pdo, $config->ca_mgr->db->auth);\r
+                       Zend_Registry::set('auth_dbc', $db);\r
+               $db2 = Zend_Db::factory($config->ca_mgr->db->auth2->pdo, $config->ca_mgr->db->auth2);\r
+                       Zend_Registry::set('auth2_dbc', $db2);\r
+\r
+               $auth = new Zend_Auth_Adapter_DbTable($db);\r
+\r
+               $auth->setTableName($config->ca_mgr->db->auth->tablename)\r
+                        ->setIdentityColumn('email')\r
+                        ->setCredentialColumn('password');\r
+\r
+               $auth->setIdentity( $this->getRequest()->getParam('login_name'))\r
+                    ->setCredential( sha1($this->getRequest()->getParam('login_password')))\r
+                    ->setCredentialTreatment('?');\r
+\r
+               $result = $auth->authenticate();\r
+\r
+               $code = $result->getCode();\r
+               switch ($code) {\r
+                       case Zend_Auth_Result::FAILURE:\r
+                               Log::Log()->info(__METHOD__ . ' user failed (Zend_Auth_Result::FAILURE) to log in ' . $this->getRequest()->getParam('login_name'));\r
+                               throw new Exception(__METHOD__ . ': unknown error');\r
+                       case Zend_Auth_Result::FAILURE_IDENTITY_NOT_FOUND:\r
+                               Log::Log()->info(__METHOD__ . ' user failed (Zend_Auth_Result::FAILURE_IDENTITY_NOT_FOUND) to log in ' . $this->getRequest()->getParam('login_name'));\r
+                               throw new Exception(__METHOD__ . ': ID unknown');\r
+                       case Zend_Auth_Result::FAILURE_IDENTITY_AMBIGUOUS:\r
+                               Log::Log()->info(__METHOD__ . ' user failed (Zend_Auth_Result::FAILURE_IDENTITY_AMBIGUOUS) to log in ' . $this->getRequest()->getParam('login_name'));\r
+                               throw new Exception(__METHOD__ . ': ID not unique');\r
+                       case Zend_Auth_Result::FAILURE_CREDENTIAL_INVALID:\r
+                               Log::Log()->info(__METHOD__ . ' user failed (Zend_Auth_Result::FAILURE_CREDENTIAL_INVALID) to log in ' . $this->getRequest()->getParam('login_name'));\r
+                               throw new Exception(__METHOD__ . ': ID unknown');       // to prevent brute force password attachs\r
+                       case Zend_Auth_Result::FAILURE_UNCATEGORIZED:\r
+                               Log::Log()->info(__METHOD__ . ' user failed (Zend_Auth_Result::FAILURE_UNCATEGORIZED) to log in ' . $this->getRequest()->getParam('login_name'));\r
+                               throw new Exception(__METHOD__ . ': unknown error');\r
+               }\r
+\r
+                       $this->getAuthDetailsIntoSession($auth, false);\r
+\r
+                       Log::Log()->info(__METHOD__ . ' user logged in ' . $this->view->session->authdata['authed_username'] .\r
+                               ' (' . $this->getRequest()->getParam('login_name') . ')');\r
+\r
+               #$this->_forward('index', 'index');  // only "soft" forward, we need to change the url in browser\r
+                       $this->_redirect($this->view->url(array('controller' => 'index', 'action' => 'index'), 'default', true));\r
+\r
+               /*\r
+               $viewRenderer = Zend_Controller_Action_HelperBroker::getStaticHelper('viewRenderer');\r
+               $viewRenderer->setRender('loginresult');\r
+               $this->view->request = $this->getRequest();\r
+               */\r
+       }\r
+               else {\r
+                       $this->view->form = $form;\r
+            return $this->render('index');\r
+       }\r
+    }\r
+\r
+    public function crtAction() {\r
+       $ssl_client_s_dn = GetEnv::getEnvVar('SSL_CLIENT_S_DN');\r
+               $ssl_client_i_dn = GetEnv::getEnvVar('SSL_CLIENT_I_DN');\r
+\r
+       $config = new Zend_Config_Ini(APPLICATION_PATH . '/configs/application.ini', APPLICATION_ENV);\r
+\r
+       $db = Zend_Db::factory($config->ca_mgr->db->auth->pdo, $config->ca_mgr->db->auth);\r
+               Zend_Registry::set('auth_dbc', $db);\r
+               $db2 = Zend_Db::factory($config->ca_mgr->db->auth2->pdo, $config->ca_mgr->db->auth2);\r
+               Zend_Registry::set('auth2_dbc', $db2);\r
+\r
+       $auth = new Zend_Auth_Adapter_DbTable($db);\r
+\r
+       $auth->setTableName($config->ca_mgr->db->auth->tablename)\r
+                ->setIdentityColumn('user_client_crt_s_dn_i_dn')\r
+                ->setCredentialColumn('user_client_crt_s_dn_i_dn');\r
+\r
+       $auth->setIdentity( $ssl_client_s_dn . '//' . $ssl_client_i_dn)\r
+            ->setCredential($ssl_client_s_dn . '//' . $ssl_client_i_dn)\r
+            ->setCredentialTreatment('?');\r
+\r
+       $result = $auth->authenticate();\r
+\r
+       $code = $result->getCode();\r
+       switch ($code) {\r
+               case Zend_Auth_Result::FAILURE:\r
+                       Log::Log()->info(__METHOD__ . ' user failed (Zend_Auth_Result::FAILURE) to log in ' . $ssl_client_s_dn . '//' . $ssl_client_i_dn);\r
+                       throw new Exception(__METHOD__ . ': unknown error');\r
+               case Zend_Auth_Result::FAILURE_IDENTITY_NOT_FOUND:\r
+                       Log::Log()->info(__METHOD__ . ' user failed (Zend_Auth_Result::FAILURE_IDENTITY_NOT_FOUND) to log in ' . $ssl_client_s_dn . '//' . $ssl_client_i_dn);\r
+                       throw new Exception(__METHOD__ . ': ID unknown');\r
+               case Zend_Auth_Result::FAILURE_IDENTITY_AMBIGUOUS:\r
+                       Log::Log()->info(__METHOD__ . ' user failed (Zend_Auth_Result::FAILURE_IDENTITY_AMBIGUOUS) to log in ' . $ssl_client_s_dn . '//' . $ssl_client_i_dn);\r
+                       throw new Exception(__METHOD__ . ': ID not unique');\r
+               case Zend_Auth_Result::FAILURE_CREDENTIAL_INVALID:\r
+                       Log::Log()->info(__METHOD__ . ' user failed (Zend_Auth_Result::FAILURE_CREDENTIAL_INVALID) to log in ' . $ssl_client_s_dn . '//' . $ssl_client_i_dn);\r
+                       throw new Exception(__METHOD__ . ': ID unknown');       // to prevent brute force password attachs\r
+               case Zend_Auth_Result::FAILURE_UNCATEGORIZED:\r
+                       Log::Log()->info(__METHOD__ . ' user failed (Zend_Auth_Result::FAILURE_UNCATEGORIZED) to log in ' . $ssl_client_s_dn . '//' . $ssl_client_i_dn);\r
+                       throw new Exception(__METHOD__ . ': unknown error');\r
+       }\r
+\r
+               $this->getAuthDetailsIntoSession($auth, true);\r
+\r
+       /*\r
+       $viewRenderer = Zend_Controller_Action_HelperBroker::getStaticHelper('viewRenderer');\r
+           $viewRenderer->setRender('loginresult');\r
+               */\r
+\r
+               Log::Log()->info(__METHOD__ . ' user logged in ' . $this->view->session->authdata['authed_username'] .\r
+                       ' (' . $ssl_client_s_dn . '//' . $ssl_client_i_dn . ')');\r
+\r
+       #$this->_forward('index', 'index'); // only "soft" forward, we need to change the url in browser\r
+       $this->_redirect($this->view->url(array('controller' => 'index', 'action' => 'index'), 'default', true));\r
+    }\r
+\r
+    /**\r
+     * get user data from Zend_Auth result and store data in session\r
+     * @param Zend_Auth_Result $auth\r
+     */\r
+       protected function getAuthDetailsIntoSession($auth, $crt) {\r
+               $session = Zend_Registry::get('session');\r
+\r
+               /**\r
+                * non existent in our case, look up a 2nd table (ca_mgr.system_user by login name (email)) and\r
+                * get id from there, defaulting to User (1) when no db entry exists\r
+                */\r
+       $auth_res = $auth->getResultRowObject();\r
+               $system_roles_id = 1;\r
+\r
+               $session->authdata['authed'] = true;\r
+       $session->authdata['authed_id'] = $auth_res->id;\r
+       $session->authdata['authed_username'] = $auth_res->email;\r
+       $session->authdata['authed_fname'] = $auth_res->fname;\r
+       $session->authdata['authed_lname'] = $auth_res->lname;\r
+               $session->authdata['authed_by_crt'] = $crt;\r
+               $session->authdata['authed_by_cli'] = true;\r
+\r
+       $db = Zend_Registry::get('auth2_dbc');\r
+               $res = $db->query('select * from system_role where id=?', array($system_roles_id));\r
+               $res_ar = $res->fetch();\r
+       $session->authdata['authed_role'] = $res_ar['role'];\r
+\r
+       $acl = $this->makeAcl($db);\r
+\r
+       $session->authdata['authed_permissions'] = $acl;\r
+\r
+       /* test cases\r
+       Log::Log()->debug(($acl->isAllowed('User', 'Administration', 'view') == true)?'true':'false');\r
+       Log::Log()->debug(($acl->isAllowed('User', 'Administration', 'edit') == true)?'true':'false');\r
+       Log::Log()->debug(($acl->isAllowed('User', 'Account', 'view') == true)?'true':'false');\r
+       Log::Log()->debug(($acl->isAllowed('User', 'Account', 'edit') == true)?'true':'false');\r
+               Log::Log()->debug(($acl->isAllowed('Admin', 'Administration', 'view') == true)?'true':'false');\r
+               Log::Log()->debug(($acl->isAllowed('Admin', 'Account', 'view') == true)?'true':'false');\r
+               */\r
+\r
+       $this->view->session = $session;\r
+       }\r
+\r
+    /**\r
+     * build login form and return to requesting method\r
+     * @return Zend_Form\r
+     */\r
+    protected function getForm() {\r
+       $form = new Zend_Form();\r
+       $form->setAction('/login/login')\r
+                        ->setMethod('post');\r
+               #$form->setAttrib('id', 'loginform');\r
+               $al = new Zend_Validate_Alnum();\r
+               $al->setDefaultTranslator(I18n::getTranslate());\r
+               $al->setDisableTranslator(false);\r
+               $username = new Zend_Form_Element_Text('login_name');\r
+               $username->addValidator(new Zend_Validate_StringLength(2,20))\r
+                                ->setRequired(true)\r
+                                ->addFilter('StringToLower')\r
+                                ->setLabel(I18n::_('User Name'));\r
+               $password = new Zend_Form_Element_Password('login_password');\r
+               $password->addValidator(new Zend_Validate_Alnum())\r
+                                ->addValidator(new Zend_Validate_StringLength(8,20))\r
+                                ->setRequired(true)\r
+                                ->setLabel(I18n::_('Password'));\r
+               $submit = new Zend_Form_Element_Submit('submit');\r
+               $submit->setLabel(I18n::_('Login'));\r
+               $form->addElement($username)\r
+                        ->addElement($password)\r
+                        ->addElement($submit);\r
+\r
+               return $form;\r
+    }\r
+\r
+    /**\r
+     * get roles and resources from db, build Zend_Acl structure and add permissions\r
+     * @param Zend_Db $db\r
+     */\r
+    protected function makeAcl($db) {\r
+               $acl = new Zend_Acl();\r
+\r
+       $res = $db->fetchAll('select * from system_role');\r
+               foreach ($res as $obj) {\r
+                       if ($obj['inherit_role'] != '') {\r
+                               if ($acl->hasRole($obj['inherit_role'])) {\r
+                                       $acl->addRole(new Zend_Acl_Role($obj['role']), $obj['inherit_role']);\r
+                               }\r
+                               else {\r
+                                       /**\r
+                                        * @todo very simply system to order roles, add role before inherited role\r
+                                        */\r
+                                       $res[] = $obj;\r
+                                       continue;\r
+                               }\r
+                       }\r
+                       else {\r
+                               $acl->addRole(new Zend_Acl_Role($obj['role']));\r
+                       }\r
+               }\r
+\r
+               $res = $db->fetchAll('select * from system_resource');\r
+               foreach ($res as $obj) {\r
+                       $acl->addResource(new Zend_Acl_Resource($obj['resource']));\r
+               }\r
+\r
+               $res = $db->fetchAll('select r.role as role, rs.resource as resource, permission, privilege '.\r
+                       'from system_role as r join system_role_has_system_resource as m on ' .\r
+                       '(r.id = m.system_role_id) join system_resource as rs on (m.system_resource_id = rs.id)');\r
+\r
+               foreach ($res as $obj) {\r
+                       $privilege = explode(',', $obj['privilege']);\r
+                       if ($obj['permission'] == 'allow') {\r
+                               $acl->allow($obj['role'], $obj['resource'], $privilege);\r
+                       }\r
+                       else {\r
+                               $acl->deny($obj['role'], $obj['resource'], $privilege);\r
+                       }\r
+               }\r
+\r
+               return $acl;\r
+    }\r
+}\r
diff --git a/manager/application/controllers/LogoutController.php b/manager/application/controllers/LogoutController.php
new file mode 100644 (file)
index 0000000..83859d4
--- /dev/null
@@ -0,0 +1,27 @@
+<?php\r
+/**\r
+ * @author markus\r
+ * $Id: LogoutController.php 12 2009-11-24 13:35:16Z markus $\r
+ */\r
+\r
+require_once('helpers/GetEnv.php');\r
+require_once('config/Config.php');\r
+\r
+class LogoutController extends Zend_Controller_Action\r
+{\r
+\r
+    public function init() {\r
+        /* Initialize action controller here */\r
+    }\r
+\r
+    public function indexAction() {\r
+       $session = Zend_Registry::get('session');\r
+\r
+       Log::Log()->info(__METHOD__ . ' user logged out ' . $this->view->session->authdata['authed_username']);\r
+\r
+       unset($session->authdata);\r
+       $session->authdata['authed'] = false;\r
+\r
+       Zend_Session::destroy();\r
+    }\r
+}\r
diff --git a/manager/application/layouts/scripts/layout.phtml b/manager/application/layouts/scripts/layout.phtml
new file mode 100644 (file)
index 0000000..44f59cf
--- /dev/null
@@ -0,0 +1,32 @@
+<?php\r
+// application/layouts/scripts/layout.phtml\r
+\r
+print $this->doctype(); ?>\r
+<html xmlns="http://www.w3.org/1999/xhtml">\r
+<head>\r
+  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />\r
+  <title><?php print $this->headTitle; ?></title>\r
+  <?php print $this->headLink()->prependStylesheet('/css/global.css'); ?>\r
+  <?php print $this->headScript()->appendFile('/js/positionUserInfo.js'); // ->appendFile('/js/center.js'); ?>\r
+</head>\r
+<body>\r
+       <div id="center">\r
+               <div id="header">\r
+                   <div id="header-logo">\r
+                       <img src="/img/cacert4.png" border="0" alt="CACert Logo" width="100px" height="30px">\r
+                   </div>\r
+                   <div id="header-navigation">\r
+                       <?php print $this->topNav(); ?>\r
+                   </div>\r
+               </div>\r
+\r
+               <div id="left-navigation">\r
+                       <?php print $this->leftNav(); ?>\r
+               </div>\r
+               <div id="content">\r
+                       <?php print $this->layout()->content; ?>\r
+               </div>\r
+       </div>\r
+       <? print $this->userInfo(); ?>\r
+</body>\r
+</html>
\ No newline at end of file
diff --git a/manager/application/views/helpers/LeftNav.php b/manager/application/views/helpers/LeftNav.php
new file mode 100644 (file)
index 0000000..7523d6e
--- /dev/null
@@ -0,0 +1,96 @@
+<?php\r
+/**\r
+ * Zend Framework\r
+ *\r
+ * LICENSE\r
+ *\r
+ * This source file is subject to the new BSD license that is bundled\r
+ * with this package in the file LICENSE.txt.\r
+ * It is also available through the world-wide-web at this URL:\r
+ * http://framework.zend.com/license/new-bsd\r
+ * If you did not receive a copy of the license and are unable to\r
+ * obtain it through the world-wide-web, please send an email\r
+ * to license@zend.com so we can send you a copy immediately.\r
+ *\r
+ * @category   Zend\r
+ * @package    Zend_View\r
+ * @subpackage Helper\r
+ * @copyright  Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)\r
+ * @version    $Id: LeftNav.php 8 2009-11-24 10:32:47Z markus $\r
+ * @license    http://framework.zend.com/license/new-bsd     New BSD License\r
+ */\r
+\r
+/** Zend_View_Helper_Placeholder_Container_Standalone */\r
+require_once 'Zend/View/Helper/Placeholder/Container/Standalone.php';\r
+\r
+/**\r
+ * Helper for building an applications top navigation bar\r
+ *\r
+ * @uses       Zend_View_Helper_Placeholder_Container_Standalone\r
+ * @package    Zend_View\r
+ * @subpackage Helper\r
+ * @copyright  Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)\r
+ * @license    http://framework.zend.com/license/new-bsd     New BSD License\r
+ */\r
+class Zend_View_Helper_LeftNav extends Zend_View_Helper_Placeholder_Container_Standalone\r
+{\r
+    /**\r
+     * Registry key for placeholder\r
+     * @var string\r
+     */\r
+    protected $_regKey = 'Zend_View_Helper_LeftNav';\r
+\r
+    protected $items = array();\r
+\r
+    /**\r
+     * Retrieve placeholder for navigation element and optionally set state\r
+     *\r
+     * Single Link elements to be made with $this->url(array('controller'=>'<controller>'), 'default', true);\r
+     *\r
+     * @param  string $link\r
+     * @param  string $setType\r
+     * @param  string $setPos\r
+     * @return Zend_View_Helper_LeftNav\r
+     */\r
+    public function leftNav($link = null, $setType = Zend_View_Helper_Placeholder_Container_Abstract::APPEND, $setPos = 0)\r
+    {\r
+       $link = (string) $link;\r
+        if ($link !== '') {\r
+            if ($setType == Zend_View_Helper_Placeholder_Container_Abstract::SET) {\r
+                if ($setPos != 0)\r
+                       $this->items[$setPos] = $link;\r
+                else\r
+                       $this->items[] = $link;\r
+            } elseif ($setType == Zend_View_Helper_Placeholder_Container_Abstract::PREPEND) {\r
+                $this->items = array_merge(array($link), $this->items);\r
+            } else {\r
+                $this->items[] = $link;\r
+            }\r
+        }\r
+\r
+        return $this;\r
+    }\r
+\r
+    /**\r
+     * Turn helper into string\r
+     *\r
+     * @param  string|null $indent\r
+     * @param  string|null $locale\r
+     * @return string\r
+     */\r
+    public function __toString($indent = null, $locale = null)\r
+    {\r
+               $output = '';\r
+       $indent = (null !== $indent)\r
+                ? $this->getWhitespace($indent)\r
+                : $this->getIndent();\r
+\r
+        $output .= $indent . "<ul>\n";\r
+        foreach ($this->items as $item) {\r
+                $output .= $indent . "<li>" . $item . "</li>\n";\r
+               }\r
+               $output .= $indent . "</ul>\n";\r
+\r
+        return $output;\r
+    }\r
+}\r
diff --git a/manager/application/views/helpers/TopNav.php b/manager/application/views/helpers/TopNav.php
new file mode 100644 (file)
index 0000000..604178a
--- /dev/null
@@ -0,0 +1,99 @@
+<?php\r
+/**\r
+ * Zend Framework\r
+ *\r
+ * LICENSE\r
+ *\r
+ * This source file is subject to the new BSD license that is bundled\r
+ * with this package in the file LICENSE.txt.\r
+ * It is also available through the world-wide-web at this URL:\r
+ * http://framework.zend.com/license/new-bsd\r
+ * If you did not receive a copy of the license and are unable to\r
+ * obtain it through the world-wide-web, please send an email\r
+ * to license@zend.com so we can send you a copy immediately.\r
+ *\r
+ * @category   Zend\r
+ * @package    Zend_View\r
+ * @subpackage Helper\r
+ * @copyright  Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)\r
+ * @version    $Id: TopNav.php 20 2009-12-01 14:26:22Z markus $\r
+ * @license    http://framework.zend.com/license/new-bsd     New BSD License\r
+ */\r
+\r
+/** Zend_View_Helper_Placeholder_Container_Standalone */\r
+require_once 'Zend/View/Helper/Placeholder/Container/Standalone.php';\r
+\r
+/**\r
+ * Helper for building an applications top navigation bar\r
+ *\r
+ * @uses       Zend_View_Helper_Placeholder_Container_Standalone\r
+ * @package    Zend_View\r
+ * @subpackage Helper\r
+ * @copyright  Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)\r
+ * @license    http://framework.zend.com/license/new-bsd     New BSD License\r
+ */\r
+class Zend_View_Helper_TopNav extends Zend_View_Helper_Placeholder_Container_Standalone\r
+{\r
+    /**\r
+     * Registry key for placeholder\r
+     * @var string\r
+     */\r
+    protected $_regKey = 'Zend_View_Helper_TopNav';\r
+\r
+    protected $items = array();\r
+\r
+    /**\r
+     * Retrieve placeholder for navigation element and optionally set state\r
+     *\r
+     * Single Link elements to be made with $this->url(array('controller'=>'<controller>'), 'default', true);\r
+     *\r
+     * @param  string $link\r
+     * @param  string $setType\r
+     * @param  string $setPos\r
+     * @return Zend_View_Helper_TopNav\r
+     */\r
+    public function topNav($link = null, $setType = Zend_View_Helper_Placeholder_Container_Abstract::APPEND, $setPos = 0)\r
+    {\r
+       $link = (string) $link;\r
+        if ($link !== '') {\r
+            if ($setType == Zend_View_Helper_Placeholder_Container_Abstract::SET) {\r
+                if ($setPos != 0)\r
+                       $this->items[$setPos] = $link;\r
+                else\r
+                       $this->items[] = $link;\r
+            } elseif ($setType == Zend_View_Helper_Placeholder_Container_Abstract::PREPEND) {\r
+                $this->items = array_merge(array($link), $this->items);\r
+            } else {\r
+                $this->items[] = $link;\r
+            }\r
+        }\r
+\r
+        return $this;\r
+    }\r
+\r
+    /**\r
+     * Turn helper into string\r
+     *\r
+     * @param  string|null $indent\r
+     * @param  string|null $locale\r
+     * @return string\r
+     */\r
+    public function __toString($indent = null, $locale = null)\r
+    {\r
+               $output = '';\r
+       $indent = (null !== $indent)\r
+                ? $this->getWhitespace($indent)\r
+                : $this->getIndent();\r
+\r
+        ksort($this->items);\r
+\r
+        $output .= $indent . "<ul>\n";\r
+\r
+        foreach ($this->items as $item) {\r
+                $output .= $indent . "<li>" . $item . "</li>\n";\r
+               }\r
+               $output .= $indent . "</ul>\n";\r
+\r
+        return $output;\r
+    }\r
+}\r
diff --git a/manager/application/views/helpers/UserInfo.php b/manager/application/views/helpers/UserInfo.php
new file mode 100644 (file)
index 0000000..31b0b05
--- /dev/null
@@ -0,0 +1,95 @@
+<?php\r
+/**\r
+ * Zend Framework\r
+ *\r
+ * LICENSE\r
+ *\r
+ * This source file is subject to the new BSD license that is bundled\r
+ * with this package in the file LICENSE.txt.\r
+ * It is also available through the world-wide-web at this URL:\r
+ * http://framework.zend.com/license/new-bsd\r
+ * If you did not receive a copy of the license and are unable to\r
+ * obtain it through the world-wide-web, please send an email\r
+ * to license@zend.com so we can send you a copy immediately.\r
+ *\r
+ * @category   Zend\r
+ * @package    Zend_View\r
+ * @subpackage Helper\r
+ * @copyright  Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)\r
+ * @version    $Id: UserInfo.php 33 2009-12-10 15:08:38Z markus $\r
+ * @license    http://framework.zend.com/license/new-bsd     New BSD License\r
+ */\r
+\r
+/** Zend_View_Helper_Placeholder_Container_Standalone */\r
+require_once 'Zend/View/Helper/Placeholder/Container/Standalone.php';\r
+\r
+/**\r
+ * Helper for displaying an user info div somewhere\r
+ *\r
+ * @uses       Zend_View_Helper_Placeholder_Container_Standalone\r
+ * @package    Zend_View\r
+ * @subpackage Helper\r
+ * @copyright  Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)\r
+ * @license    http://framework.zend.com/license/new-bsd     New BSD License\r
+ */\r
+class Zend_View_Helper_UserInfo extends Zend_View_Helper_Placeholder_Container_Standalone\r
+{\r
+    /**\r
+     * Registry key for placeholder\r
+     * @var string\r
+     */\r
+    protected $_regKey = 'Zend_View_Helper_UserInfo';\r
+\r
+    private $items = array();\r
+\r
+    /**\r
+     * Retrieve placeholder for navigation element and optionally set state\r
+     *\r
+     * Single Link elements to be made with $this->url(array('controller'=>'<controller>'), 'default', true);\r
+     *\r
+     * @param  array $data\r
+     * @return Zend_View_Helper_UserData\r
+     */\r
+    public function UserInfo($ar = null, $setType = Zend_View_Helper_Placeholder_Container_Abstract::APPEND, $setPos = 0)\r
+    {\r
+       if ($ar !== null && is_array($ar)) {\r
+               $this->items = $ar;\r
+       }\r
+       return $this;\r
+    }\r
+\r
+    /**\r
+     * Turn helper into string\r
+     *\r
+     * @param  string|null $indent\r
+     * @param  string|null $locale\r
+     * @return string\r
+     */\r
+    public function __toString($indent = null, $locale = null)\r
+    {\r
+       $session = Zend_Registry::get('session');\r
+               $this->items = $session->authdata;\r
+\r
+       $output = '';\r
+\r
+       if ($session->authdata['authed'] !== true)\r
+                       return $output;\r
+\r
+#      $indent = (null !== $indent)\r
+#                ? $this->getWhitespace($indent)\r
+#                : $this->getIndent();\r
+               $indent = '';\r
+\r
+        $output .= $indent . "<div id=\"userinfo\">\n";\r
+               $output .= $indent . "\tUser: " . $this->items['authed_username'] . "<br>\n";\r
+               $output .= $indent . "\tName: " . $this->items['authed_fname'] . ' ' . $this->items['authed_lname'] . "<br>\n";\r
+               $output .= $indent . "\tRole: " . $this->items['authed_role'] . "<br>\n";\r
+               if ($this->items['authed_by_crt'] === true)\r
+                       $output .= $indent . "\tLoginmethod: CRT<br>\n";\r
+               else\r
+                       $output .= $indent . "\tLoginmethod: PASSWD<br>\n";\r
+               $output .= $indent . "</div>\n";\r
+\r
+        return $output;\r
+    }\r
+}\r
diff --git a/manager/application/views/scripts/error/error.phtml b/manager/application/views/scripts/error/error.phtml
new file mode 100644 (file)
index 0000000..1782039
--- /dev/null
@@ -0,0 +1,28 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+  <title>Zend Framework Default Application</title>
+</head>
+<body>
+  <h1>An error occurred</h1>
+  <h2><?php echo $this->message ?></h2>
+
+  <?php if ('development' == APPLICATION_ENV): ?>
+
+  <h3>Exception information:</h3>
+  <p>
+      <b>Message:</b> <?php echo $this->exception->getMessage() ?>
+  </p>
+
+  <h3>Stack trace:</h3>
+  <pre><?php echo $this->exception->getTraceAsString() ?>
+  </pre>
+
+  <h3>Request Parameters:</h3>
+  <pre><?php echo var_export($this->request->getParams(), true) ?>
+  </pre>
+  <?php endif ?>
+
+</body>
+</html>
diff --git a/manager/application/views/scripts/error/permissiondenied.phtml b/manager/application/views/scripts/error/permissiondenied.phtml
new file mode 100644 (file)
index 0000000..8219e5b
--- /dev/null
@@ -0,0 +1,8 @@
+<?php
+/**
+ * @author markus
+ * $Id: loginresult.phtml 7 2009-11-19 15:03:59Z markus $
+ */
+?>
+<H1><?php print I18n::_('Permission Denied')?></H1>
+<?php print I18n::_('You do not have the permission to perform the requested action'); ?>
\ No newline at end of file
diff --git a/manager/application/views/scripts/index/index.phtml b/manager/application/views/scripts/index/index.phtml
new file mode 100644 (file)
index 0000000..58c9dc9
--- /dev/null
@@ -0,0 +1,7 @@
+<?php\r
+/**\r
+ * @author markus\r
+ * $Id: index.phtml 25 2009-12-02 15:43:21Z markus $\r
+ */\r
+?>\r
+<H1><?php print I18n::_('Dashboard'); ?></H1>\r
diff --git a/manager/application/views/scripts/login/index.phtml b/manager/application/views/scripts/login/index.phtml
new file mode 100644 (file)
index 0000000..57f49ea
--- /dev/null
@@ -0,0 +1,16 @@
+<?php\r
+/**\r
+ * @author markus\r
+ * $Id: index.phtml 36 2009-12-15 15:49:57Z markus $\r
+ */\r
+\r
+// $this->headScript()->appendFile('js/1st.js');\r
+// $this->headScript()->appendFile('js/2nd.js');\r
+$this->headLink()->appendStylesheet('/css/login.css');\r
+\r
+$this->headLink()->appendStylesheet('/css/form_dl.css');\r
+?>\r
+\r
+<H1><?php print I18n::_('Please log in'); ?></H1>\r
+<?php print $this->form;?>\r
+<a href='/login/crt'><?php print I18n::_('Client Cert Login'); ?></a>
\ No newline at end of file
diff --git a/manager/application/views/scripts/login/loginresult.phtml b/manager/application/views/scripts/login/loginresult.phtml
new file mode 100644 (file)
index 0000000..09437ca
--- /dev/null
@@ -0,0 +1,16 @@
+<?php
+/**
+ * @author markus
+ * $Id: loginresult.phtml 7 2009-11-19 15:03:59Z markus $
+ */
+
+if ($this->session->authdata['authed']) {
+?>
+<H1>Willkommen im Club, <?php  print $this->session->authdata['authed_username']; ?></H1>
+<?php
+}
+else {
+?>
+<H1>Bitte loggen Sie sich ein.</H1>
+<?php
+}
\ No newline at end of file
diff --git a/manager/application/views/scripts/logout/index.phtml b/manager/application/views/scripts/logout/index.phtml
new file mode 100644 (file)
index 0000000..5106390
--- /dev/null
@@ -0,0 +1,7 @@
+<?php
+/**
+ * @author markus
+ * $Id: index.phtml 7 2009-11-19 15:03:59Z markus $
+ */
+?>
+<H1><?php print I18n::_('You have successfully been logged out'); ?></H1>
diff --git a/manager/library/actions/ActionIndex.php b/manager/library/actions/ActionIndex.php
new file mode 100644 (file)
index 0000000..2771bad
--- /dev/null
@@ -0,0 +1,53 @@
+<?php\r
+\r
+require_once (FWACTIONS_PATH . '/FWAction.php');\r
+\r
+class Index extends FWAction {\r
+       /**\r
+        * get a list of required permissions that are needed to access this action\r
+        * @return array\r
+        */\r
+       public static function getRequiredPermissions() {\r
+               return array();\r
+       }\r
+\r
+       /**\r
+        * get a role that is required for accessing that action\r
+        * @return string\r
+        */\r
+       public static function getRequiredRole() {\r
+               return 'User';\r
+       }\r
+\r
+       /**\r
+        * sort order for top navigation\r
+        * @return integer\r
+        */\r
+       public static function getTopNavPrio() {\r
+               return 1;\r
+       }\r
+\r
+       /**\r
+        * controller to invoke\r
+        * @return string\r
+        */\r
+       public static function getController() {\r
+               return 'index';\r
+       }\r
+\r
+       /**\r
+        * action to invoke\r
+        * @return string\r
+        */\r
+       public static function getAction() {\r
+               return 'index';\r
+       }\r
+\r
+       /**\r
+        * get text for menu, caller is responsible for translating\r
+        * @return string\r
+        */\r
+       public static function getMenuText() {\r
+               return 'Dashboard';\r
+       }\r
+}\r
diff --git a/manager/library/actions/FWAction.php b/manager/library/actions/FWAction.php
new file mode 100644 (file)
index 0000000..346e4fa
--- /dev/null
@@ -0,0 +1,7 @@
+<?php\r
+/**\r
+ * @author markus\r
+ */\r
+abstract class FWAction {\r
+\r
+}\r
diff --git a/manager/library/config/Config.php b/manager/library/config/Config.php
new file mode 100644 (file)
index 0000000..26b21fa
--- /dev/null
@@ -0,0 +1,104 @@
+<?php\r
+\r
+require_once('config/Config_Db.php');\r
+\r
+class Config {\r
+       /**\r
+        * static pointer to instances\r
+        * @var array(Config)\r
+        */\r
+       private static $instances = array();\r
+\r
+       /**\r
+        * can handle several instances, distinct by instance name string\r
+        * @var string\r
+        */\r
+       private $instanceName = '';\r
+\r
+       /**\r
+        * config object\r
+        * @var Config_Db\r
+        */\r
+       private $config = null;\r
+\r
+       /**\r
+        * make a new Config_Db\r
+        *\r
+        * by using the $where statement you can limit the data that is fetched from db, i.e. only get config for zone $id\r
+        *\r
+        * @param string $instanceName\r
+        * @param Zend_Db_Adapter $db\r
+        * @param string $where\r
+        */\r
+       protected function __construct($instanceName = null, $db = null, $where = null) {\r
+       if ($instanceName === null)\r
+               throw new Exception(__METHOD__ . ': expected an instance name, got none');\r
+\r
+               $config = new Zend_Config_Ini(APPLICATION_PATH . '/configs/application.ini', APPLICATION_ENV);\r
+               $this->instanceName = $instanceName;\r
+\r
+               if ($db === null)\r
+               $db = Zend_Db::factory($config->dnssecme->db->config->pdo, $config->dnssecme->db->config);\r
+\r
+               $this->config = new Config_Db($db, $instanceName, $where, true);\r
+       }\r
+\r
+       /**\r
+        * get already existing instance, make new instance or throw an exception\r
+        * @param string $instanceName\r
+        * @param Zend_Db_Adapter $db\r
+        * @param string $where\r
+        */\r
+       public static function getInstance($instanceName, $db = null, $where = null) {\r
+       if ($instanceName === null)\r
+               throw new Exception(__METHOD__ . ': expected an instance name, got none');\r
+\r
+       // no caching if presumeably volatile data is requested\r
+       if ($db !== null && $where !== null) {\r
+               return new Config($instanceName, $db, $where);\r
+       }\r
+\r
+               if (!array_key_exists($instanceName, self::$instances)) {\r
+                       self::$instances[$instanceName] = new Config($instanceName, $db, $where);\r
+               }\r
+\r
+               return self::$instances[$instanceName];\r
+       }\r
+\r
+       /**\r
+        * magic method that dispatches all unrecognized method calls to the config object\r
+        *\r
+        * @param string $param\r
+        */\r
+       public function __get($param) {\r
+               return $this->config->$param;\r
+       }\r
+\r
+       /**\r
+        * magic method that handles isset inquiries to attributes\r
+        *\r
+        * @param string $param\r
+        */\r
+       public function __isset($param) {\r
+               return isset($this->config->$param);\r
+       }\r
+\r
+       /**\r
+        * magic method that dispatches all unrecognized method calls to the config object\r
+        *\r
+        * @param string $param\r
+        * @param string $value\r
+        */\r
+       public function __set($param, $value) {\r
+               $this->config->$param = $value;\r
+       }\r
+\r
+       /**\r
+        * get the config object\r
+        * @return Zend_Config_*\r
+        */\r
+       public function getConfig() {\r
+               return $this->config;\r
+       }\r
+}\r
+?>
\ No newline at end of file
diff --git a/manager/library/config/Config_Db.php b/manager/library/config/Config_Db.php
new file mode 100644 (file)
index 0000000..fa312df
--- /dev/null
@@ -0,0 +1,339 @@
+<?php\r
+/**\r
+ * Add database driven configuration to the framework, source based on Zend_Config_Ini\r
+ *\r
+ * Zend Framework\r
+ *\r
+ * LICENSE\r
+ *\r
+ * This source file is subject to the new BSD license that is bundled\r
+ * with this package in the file LICENSE.txt.\r
+ * It is also available through the world-wide-web at this URL:\r
+ * http://framework.zend.com/license/new-bsd\r
+ * If you did not receive a copy of the license and are unable to\r
+ * obtain it through the world-wide-web, please send an email\r
+ * to license@zend.com so we can send you a copy immediately.\r
+ *\r
+ * @category   Zend\r
+ * @package    Zend_Config\r
+ * @copyright  Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)\r
+ * @license    http://framework.zend.com/license/new-bsd     New BSD License\r
+ * @version    $Id: Config_Db.php 27 2009-12-03 13:00:29Z markus $\r
+ */\r
+\r
+\r
+/**\r
+ * @see Zend_Config\r
+ */\r
+require_once 'Zend/Config.php';\r
+\r
+\r
+/**\r
+ * @category   Zend\r
+ * @package    Zend_Config\r
+ * @copyright  Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)\r
+ * @license    http://framework.zend.com/license/new-bsd     New BSD License\r
+ */\r
+class Config_Db extends Zend_Config\r
+{\r
+       /**\r
+     * String that separates nesting levels of configuration data identifiers\r
+     *\r
+     * @var string\r
+     */\r
+    protected $_nestSeparator = '.';\r
+\r
+    /**\r
+     * String that separates the parent section name\r
+     *\r
+     * @var string\r
+     */\r
+    protected $_sectionSeparator = ':';\r
+\r
+    /**\r
+     * Wether to skip extends or not\r
+     *\r
+     * @var boolean\r
+     */\r
+    protected $_skipExtends = false;\r
+\r
+    /**\r
+     * Loads the section $section from the config file $filename for\r
+     * access facilitated by nested object properties.\r
+     *\r
+     * If the section name contains a ":" then the section name to the right\r
+     * is loaded and included into the properties. Note that the keys in\r
+     * this $section will override any keys of the same\r
+     * name in the sections that have been included via ":".\r
+     *\r
+     * If the $section is null, then all sections in the ini file are loaded.\r
+     *\r
+     * If any key includes a ".", then this will act as a separator to\r
+     * create a sub-property.\r
+     *\r
+     * example ini file:\r
+     *      [all]\r
+     *      db.connection = database\r
+     *      hostname = live\r
+     *\r
+     *      [staging : all]\r
+     *      hostname = staging\r
+     *\r
+     * after calling $data = new Zend_Config_Ini($file, 'staging'); then\r
+     *      $data->hostname === "staging"\r
+     *      $data->db->connection === "database"\r
+     *\r
+     * The $options parameter may be provided as either a boolean or an array.\r
+     * If provided as a boolean, this sets the $allowModifications option of\r
+     * Zend_Config. If provided as an array, there are two configuration\r
+     * directives that may be set. For example:\r
+     *\r
+     * $options = array(\r
+     *     'allowModifications' => false,\r
+     *     'nestSeparator'      => '->'\r
+     *      );\r
+     *\r
+     * @param  Zend_Db       $dbc\r
+     * @param  string       $db_table\r
+     * @param  string|null   $section\r
+     * @param  boolean|array $options\r
+     * @throws Zend_Config_Exception\r
+     * @return void\r
+     */\r
+    public function __construct($dbc, $db_table, $section = null, $options = false)\r
+    {\r
+        if (empty($dbc)) {\r
+            /**\r
+             * @see Zend_Config_Exception\r
+             */\r
+            require_once 'Zend/Config/Exception.php';\r
+            throw new Zend_Config_Exception('Database connection is not set');\r
+        }\r
+\r
+        if (empty($db_table)) {\r
+            /**\r
+             * @see Zend_Config_Exception\r
+             */\r
+            require_once 'Zend/Config/Exception.php';\r
+            throw new Zend_Config_Exception('Database table is not set');\r
+        }\r
+\r
+        $allowModifications = false;\r
+        if (is_bool($options)) {\r
+            $allowModifications = $options;\r
+        } elseif (is_array($options)) {\r
+            if (isset($options['allowModifications'])) {\r
+                $allowModifications = (bool) $options['allowModifications'];\r
+            }\r
+            if (isset($options['nestSeparator'])) {\r
+                $this->_nestSeparator = (string) $options['nestSeparator'];\r
+            }\r
+            if (isset($options['skipExtends'])) {\r
+                $this->_skipExtends = (bool) $options['skipExtends'];\r
+            }\r
+        }\r
+\r
+        $iniArray = $this->_loadIniFile($dbc, $db_table, $section);\r
+               $section = null;\r
+\r
+        if (null === $section) {\r
+            // Load entire file\r
+            $dataArray = array();\r
+            foreach ($iniArray as $sectionName => $sectionData) {\r
+                if(!is_array($sectionData)) {\r
+                    $dataArray = array_merge_recursive($dataArray, $this->_processKey(array(), $sectionName, $sectionData));\r
+                } else {\r
+                    $dataArray[$sectionName] = $this->_processSection($iniArray, $sectionName);\r
+                }\r
+            }\r
+            parent::__construct($dataArray, $allowModifications);\r
+        } else {\r
+            // Load one or more sections\r
+            if (!is_array($section)) {\r
+                $section = array($section);\r
+            }\r
+            $dataArray = array();\r
+            foreach ($section as $sectionName) {\r
+                if (!isset($iniArray[$sectionName])) {\r
+                    /**\r
+                     * @see Zend_Config_Exception\r
+                     */\r
+                    require_once 'Zend/Config/Exception.php';\r
+                    throw new Zend_Config_Exception("Section '$sectionName' cannot be found");\r
+                }\r
+                $dataArray = array_merge($this->_processSection($iniArray, $sectionName), $dataArray);\r
+\r
+            }\r
+            parent::__construct($dataArray, $allowModifications);\r
+        }\r
+\r
+        $this->_loadedSection = $section;\r
+    }\r
+\r
+    /**\r
+     * Load data from database and preprocess the section separator (':' in the\r
+     * section name (that is used for section extension) so that the resultant\r
+     * array has the correct section names and the extension information is\r
+     * stored in a sub-key called ';extends'. We use ';extends' as this can\r
+     * never be a valid key name in an INI file that has been loaded using\r
+     * parse_ini_file().\r
+     *\r
+     * @param Zend_Db $dbc\r
+     * @param string $db_table\r
+     * @throws Zend_Config_Exception\r
+     * @return array\r
+     */\r
+    protected function _loadIniFile($dbc, $db_table, $section = null)\r
+    {\r
+        set_error_handler(array($this, '_loadFileErrorHandler'));\r
+        $loaded = $this->_parse_ini_db($dbc, $db_table, $section); // Warnings and errors are suppressed\r
+        restore_error_handler();\r
+        // Check if there was a error while loading file\r
+        if ($this->_loadFileErrorStr !== null) {\r
+            /**\r
+             * @see Zend_Config_Exception\r
+             */\r
+            require_once 'Zend/Config/Exception.php';\r
+            throw new Zend_Config_Exception($this->_loadFileErrorStr);\r
+        }\r
+\r
+        $iniArray = array();\r
+        foreach ($loaded as $key => $data)\r
+        {\r
+            $pieces = explode($this->_sectionSeparator, $key);\r
+            $thisSection = trim($pieces[0]);\r
+            switch (count($pieces)) {\r
+                case 1:\r
+                    $iniArray[$thisSection] = $data;\r
+                    break;\r
+\r
+                case 2:\r
+                    $extendedSection = trim($pieces[1]);\r
+                    $iniArray[$thisSection] = array_merge(array(';extends'=>$extendedSection), $data);\r
+                    break;\r
+\r
+                default:\r
+                    /**\r
+                     * @see Zend_Config_Exception\r
+                     */\r
+                    require_once 'Zend/Config/Exception.php';\r
+                    throw new Zend_Config_Exception("Section '$thisSection' may not extend multiple sections");\r
+            }\r
+        }\r
+\r
+        return $iniArray;\r
+    }\r
+\r
+    /**\r
+     * read config from (current db in $dbc).$db_table\r
+     *\r
+     * @param Zend_Db $dbc\r
+     * @param string $db_table\r
+     * @param string $section\r
+     * @return array\r
+     */\r
+    protected function _parse_ini_db($dbc, $db_table, $section) {\r
+       $sql = 'select * from ' . $db_table;\r
+               if ($section !== null) {\r
+                       $sql .= ' where ' . $section;\r
+               }\r
+\r
+       $db_config = $dbc->query($sql);\r
+\r
+       $config = array();\r
+\r
+       while (($row = $db_config->fetch()) !== false) {\r
+               $key = explode('.', $row['config_key']);\r
+               $depth = count($key);\r
+               $ci = &$config;\r
+               for ($cnt = 0; $cnt < $depth; $cnt++) {\r
+                       if ($cnt == ($depth - 1))\r
+                               $ci[$key[$cnt]] = $row['config_value'];\r
+                       elseif (!isset($ci[$key[$cnt]]))\r
+                               $ci[$key[$cnt]] = array();\r
+                       $ci = &$ci[$key[$cnt]];\r
+               }\r
+       }\r
+       return $config;\r
+    }\r
+\r
+    /**\r
+     * Process each element in the section and handle the ";extends" inheritance\r
+     * key. Passes control to _processKey() to handle the nest separator\r
+     * sub-property syntax that may be used within the key name.\r
+     *\r
+     * @param  array  $iniArray\r
+     * @param  string $section\r
+     * @param  array  $config\r
+     * @throws Zend_Config_Exception\r
+     * @return array\r
+     */\r
+    protected function _processSection($iniArray, $section, $config = array())\r
+    {\r
+        $thisSection = $iniArray[$section];\r
+\r
+        foreach ($thisSection as $key => $value) {\r
+            if (strtolower($key) == ';extends') {\r
+                if (isset($iniArray[$value])) {\r
+                    $this->_assertValidExtend($section, $value);\r
+\r
+                    if (!$this->_skipExtends) {\r
+                        $config = $this->_processSection($iniArray, $value, $config);\r
+                    }\r
+                } else {\r
+                    /**\r
+                     * @see Zend_Config_Exception\r
+                     */\r
+                    require_once 'Zend/Config/Exception.php';\r
+                    throw new Zend_Config_Exception("Parent section '$section' cannot be found");\r
+                }\r
+            } else {\r
+                $config = $this->_processKey($config, $key, $value);\r
+            }\r
+        }\r
+        return $config;\r
+    }\r
+\r
+    /**\r
+     * Assign the key's value to the property list. Handles the\r
+     * nest separator for sub-properties.\r
+     *\r
+     * @param  array  $config\r
+     * @param  string $key\r
+     * @param  string $value\r
+     * @throws Zend_Config_Exception\r
+     * @return array\r
+     */\r
+    protected function _processKey($config, $key, $value)\r
+    {\r
+        if (strpos($key, $this->_nestSeparator) !== false) {\r
+            $pieces = explode($this->_nestSeparator, $key, 2);\r
+            if (strlen($pieces[0]) && strlen($pieces[1])) {\r
+                if (!isset($config[$pieces[0]])) {\r
+                    if ($pieces[0] === '0' && !empty($config)) {\r
+                        // convert the current values in $config into an array\r
+                        $config = array($pieces[0] => $config);\r
+                    } else {\r
+                        $config[$pieces[0]] = array();\r
+                    }\r
+                } elseif (!is_array($config[$pieces[0]])) {\r
+                    /**\r
+                     * @see Zend_Config_Exception\r
+                     */\r
+                    require_once 'Zend/Config/Exception.php';\r
+                    throw new Zend_Config_Exception("Cannot create sub-key for '{$pieces[0]}' as key already exists");\r
+                }\r
+                $config[$pieces[0]] = $this->_processKey($config[$pieces[0]], $pieces[1], $value);\r
+            } else {\r
+                /**\r
+                 * @see Zend_Config_Exception\r
+                 */\r
+                require_once 'Zend/Config/Exception.php';\r
+                throw new Zend_Config_Exception("Invalid key '$key'");\r
+            }\r
+        } else {\r
+            $config[$key] = $value;\r
+        }\r
+        return $config;\r
+    }\r
+}\r
diff --git a/manager/library/config/Config_Writer_Db.php b/manager/library/config/Config_Writer_Db.php
new file mode 100644 (file)
index 0000000..1614a41
--- /dev/null
@@ -0,0 +1,217 @@
+<?php\r
+/**\r
+ * Zend Framework\r
+ *\r
+ * LICENSE\r
+ *\r
+ * This source file is subject to the new BSD license that is bundled\r
+ * with this package in the file LICENSE.txt.\r
+ * It is also available through the world-wide-web at this URL:\r
+ * http://framework.zend.com/license/new-bsd\r
+ * If you did not receive a copy of the license and are unable to\r
+ * obtain it through the world-wide-web, please send an email\r
+ * to license@zend.com so we can send you a copy immediately.\r
+ *\r
+ * @category   Zend\r
+ * @package    Zend_Config\r
+ * @copyright  Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)\r
+ * @license    http://framework.zend.com/license/new-bsd     New BSD License\r
+ * @version    $Id: Config_Writer_Db.php 43 2009-12-21 14:12:34Z markus $\r
+ */\r
+\r
+/**\r
+ * Usage:\r
+ * require_once(LIBRARY_PATH . '/config/Config_Writer_Db.php');\r
+ * $writer = new Config_Writer_Db();\r
+ * $writer->setTableName('system_config');\r
+ * $writer->write(Zend_Registry::get('config_dbc'), Zend_Registry::get('config'));\r
+ *\r
+ * $writer = new Config_Writer_Db();\r
+ * $writer->setTableName('dnssec_org_param');\r
+ * $writer->write(Zend_Registry::get('config_dbc'), dnssec_org_conf, 'dnssec_org_id="2"');\r
+ */\r
+\r
+/**\r
+ * @see Zend_Config_Writer\r
+ */\r
+require_once 'Zend/Config/Writer.php';\r
+\r
+/**\r
+ * @category   Zend\r
+ * @package    Zend_Config\r
+ * @copyright  Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)\r
+ * @license    http://framework.zend.com/license/new-bsd     New BSD License\r
+ */\r
+class Config_Writer_Db extends Zend_Config_Writer\r
+{\r
+    /**\r
+     * String that separates nesting levels of configuration data identifiers\r
+     *\r
+     * @var string\r
+     */\r
+    protected $_nestSeparator = '.';\r
+\r
+    protected $_set = null;\r
+\r
+    protected $_tableName = null;\r
+\r
+    /**\r
+     * Set the nest separator\r
+     *\r
+     * @param  string $filename\r
+     * @return Zend_Config_Writer_Ini\r
+     */\r
+    public function setNestSeparator($separator)\r
+    {\r
+        $this->_nestSeparator = $separator;\r
+\r
+        return $this;\r
+    }\r
+\r
+    public function setTableName($name)\r
+    {\r
+        $this->_tableName = $name;\r
+\r
+        return $this;\r
+    }\r
+\r
+    /**\r
+     * Defined by Zend_Config_Writer\r
+     *\r
+     * use set to limit impact when a shared config file is used (i.e. config per item using foreign keys)\r
+     *\r
+     * @param  string $filename\r
+     * @param  Config_Db $config\r
+     * @param  string $set\r
+     * @return void\r
+     */\r
+    public function write($db = null, $config = null, $set = null) {\r
+       $this->_set = $set;\r
+\r
+       // this method is specialized for writing back Config objects (which hold config_db objects)\r
+        if ($config !== null) {\r
+               if ($config instanceof Config)\r
+               $this->setConfig($config->getConfig());\r
+            else {\r
+               $this->setConfig($config);\r
+            }\r
+        }\r
+\r
+        if ($this->_config === null) {\r
+            require_once 'Zend/Config/Exception.php';\r
+            throw new Zend_Config_Exception('No config was set');\r
+        }\r
+\r
+        if ($db === null) {\r
+            require_once 'Zend/Config/Exception.php';\r
+            throw new Zend_Config_Exception('No db was set');\r
+        }\r
+\r
+        $sql = array();\r
+\r
+        $string = 'delete from ' . $this->_tableName;\r
+        if ($this->_set !== null) {\r
+                       $string .= ' where ' . $this->_set;\r
+        }\r
+\r
+               $sql[] = $string;\r
+\r
+        $iniString   = '';\r
+        $extends     = $this->_config->getExtends();\r
+        $sectionName = $this->_config->getSectionName();\r
+\r
+        foreach ($this->_config as $key => $data) {\r
+               $sql= array_merge($sql, $this->addEntry($sectionName, $key, $data));\r
+           }\r
+\r
+           try {\r
+               $db->beginTransaction();\r
+               foreach ($sql as $command) {\r
+                       #Log::Log()->debug($command);\r
+                       $db->query($command);\r
+                       }\r
+                       $db->commit();\r
+           } catch (Exception $e) {\r
+                       $db->rollBack();\r
+                       Log::Log()->err($e);\r
+                       throw $e;\r
+           }\r
+       }\r
+\r
+       /**\r
+        * build key value pairs, key is created by recursively adding section names, delimited by "."\r
+        * @param string $prefix\r
+        * @param string $key\r
+        * @param mixed $data\r
+        */\r
+    protected function addEntry($prefix, $key, $data) {\r
+       $sql = array();\r
+\r
+       if ($data instanceof Zend_Config) {\r
+                       if ($prefix != '')\r
+                       $prefix .= '.';\r
+               $prefix .= $key;\r
+               foreach ($data as $k => $v) {\r
+                       $sql = array_merge($sql, $this->addEntry($prefix, $k, $v));\r
+               }\r
+       }\r
+       else {\r
+               $string = 'insert into ' . $this->_tableName . ' set ';\r
+               $pkey = $prefix;\r
+               if ($pkey != '')\r
+                       $pkey .= '.';\r
+               $pkey .= $key;\r
+               $string .= 'config_key=' . $this->_prepareValue($pkey) . ', ';\r
+               $string .= 'config_value=' . $this->_prepareValue($data);\r
+               if ($this->_set !== null)\r
+                       $string .= ', ' . $this->_set;\r
+\r
+               $sql[] = $string;\r
+       }\r
+\r
+       return $sql;\r
+       }\r
+\r
+    /**\r
+     * Add a branch to an INI string recursively\r
+     *\r
+     * @param  Zend_Config $config\r
+     * @return void\r
+     */\r
+    protected function _addBranch(Zend_Config $config, $parents = array())\r
+    {\r
+        $iniString = '';\r
+\r
+        foreach ($config as $key => $value) {\r
+            $group = array_merge($parents, array($key));\r
+\r
+            if ($value instanceof Zend_Config) {\r
+                $iniString .= $this->_addBranch($value, $group);\r
+            } else {\r
+                $iniString .= implode($this->_nestSeparator, $group)\r
+                           .  ' = '\r
+                           .  $this->_prepareValue($value)\r
+                           .  "\n";\r
+            }\r
+        }\r
+\r
+        return $iniString;\r
+    }\r
+\r
+    /**\r
+     * Prepare a value for INI\r
+     *\r
+     * @param  mixed $value\r
+     * @return string\r
+     */\r
+    protected function _prepareValue($value)\r
+    {\r
+        if (is_integer($value) || is_float($value)) {\r
+            return $value;\r
+        } elseif (is_bool($value)) {\r
+            return ($value ? 'true' : 'false');\r
+        } else {\r
+            return '"' . addslashes($value) .  '"';\r
+        }\r
+    }\r
+}\r
diff --git a/manager/library/date/HumanReadableTime.php b/manager/library/date/HumanReadableTime.php
new file mode 100644 (file)
index 0000000..ee75703
--- /dev/null
@@ -0,0 +1,140 @@
+<?php\r
+\r
+/**\r
+ * class that provides methods to convert human readable time / interval length\r
+ * expressions into other formats\r
+ *\r
+ * @author markus\r
+ * $Id: HumanReadableTime.php 92 2010-03-10 11:43:15Z markus $\r
+ */\r
+\r
+require_once(LIBRARY_PATH . '/date/exception.HumanReadableTimeException.php');\r
+\r
+class HumanReadableTime {\r
+       /**\r
+        * normalize an HRT string, convert from HRT to seconds and then convert back to\r
+        * HRT\r
+        * @param string $hrt\r
+        * @param string $maxunit\r
+        * @return string\r
+        */\r
+       public static function NormalizeHRT($hrt, $maxunit = 'w') {\r
+               return self::Seconds2HR(self::HR2Seconds($hrt), $maxunit);\r
+       }\r
+\r
+       /**\r
+        * convert string / interger which contains an interval length to\r
+        * human readable format (1w2d7h)\r
+        *\r
+        * if $maxunit is set, it defines the biggest unit in output (i.e. $maxunit = 'h' will\r
+        * allow only hms)\r
+        *\r
+        * @param string|integer $seconds\r
+        * @param string $maxunit\r
+        * @return string\r
+        */\r
+       public static function Seconds2HR($seconds, $maxunit = 'w') {\r
+               $maxunit = trim(strtolower($maxunit));\r
+               $allowed = array('w' => 0, 'd' => 0, 'h' => 0, 'm' => 0, 's' => 0);\r
+               if (!in_array($maxunit, array_keys($allowed), true))\r
+                       throw new HumanReadableTimeException('illegal value for maxunit: "' . $maxunit . '"');\r
+               foreach ($allowed as $key => $value) {\r
+                       if ($maxunit == $key)\r
+                               break;\r
+                       unset($allowed[$key]);\r
+               }\r
+\r
+               $seconds = intval($seconds);\r
+               $hrt = '';\r
+               foreach ($allowed as $key => $value) {\r
+                       switch ($key) {\r
+                               case 'w':\r
+                                       $tmp = intval($seconds / (7*86400));\r
+                                       if ($tmp > 0)\r
+                                               $seconds %= (7*86400);\r
+                                       $allowed[$key] += $tmp;\r
+                                       break;\r
+                               case 'd':\r
+                                       $tmp = intval($seconds / (86400));\r
+                                       if ($tmp > 0)\r
+                                               $seconds %= (86400);\r
+                                       $allowed[$key] += $tmp;\r
+                                       break;\r
+                               case 'h':\r
+                                       $tmp = intval($seconds / (3600));\r
+                                       if ($tmp > 0)\r
+                                               $seconds %= (3600);\r
+                                       $allowed[$key] += $tmp;\r
+                                       break;\r
+                               case 'm':\r
+                                       $tmp = intval($seconds / (60));\r
+                                       if ($tmp > 0)\r
+                                               $seconds %= (60);\r
+                                       $allowed[$key] += $tmp;\r
+                                       break;\r
+                               case 's':\r
+                                       $allowed[$key] += $seconds;\r
+                                       break;\r
+                       }\r
+               }\r
+\r
+               $hrt = '';\r
+               foreach ($allowed as $key => $value) {\r
+                       if ($value > 0)\r
+                               $hrt .= sprintf('%d%s', $value, $key);\r
+               }\r
+               return $hrt;\r
+       }\r
+\r
+       /**\r
+        * parse a string of 3h2m7s and return the number of seconds as integer\r
+        * add "s" to the end of the number if $addsecond is set to true\r
+        * @param string $hr\r
+        * @param boolean $addsecond\r
+        * @return integer|string\r
+        */\r
+       public static function HR2Seconds($hr, $addsecond = false) {\r
+               $hr = trim($hr);\r
+               if ($hr == '') {\r
+                       if ($addsecond === true)\r
+                               return '0s';\r
+                       else\r
+                               return 0;\r
+               }\r
+\r
+               $hr = strtolower($hr);\r
+\r
+               $matches = array();\r
+               if (preg_match_all('/([0-9]*)([wdhms])/', $hr, $matches, PREG_SET_ORDER) > 0) {\r
+                       $interval = 0;\r
+                       for ($i = 0; $i < count($matches); $i++) {\r
+                               switch ($matches[$i][2]) {\r
+                                       case 'w':\r
+                                               $interval += $matches[$i][1] * 7 * 86400;\r
+                                               break;\r
+                                       case 'd':\r
+                                               $interval += $matches[$i][1] * 86400;\r
+                                               break;\r
+                                       case 'h':\r
+                                               $interval += $matches[$i][1] * 3600;\r
+                                               break;\r
+                                       case 'm':\r
+                                               $interval += $matches[$i][1] * 60;\r
+                                               break;\r
+                                       case 's':\r
+                                               $interval += $matches[$i][1];\r
+                                               break;\r
+                               }\r
+                       }\r
+                       if ($addsecond === true)\r
+                               return sprintf('%ds', $interval);\r
+                       else\r
+                               return $interval;\r
+               }\r
+\r
+               if ($addsecond === true)\r
+                       return '0s';\r
+               else\r
+                       return 0;\r
+       }\r
+}\r
diff --git a/manager/library/date/exception.HumanReadableTimeException.php b/manager/library/date/exception.HumanReadableTimeException.php
new file mode 100644 (file)
index 0000000..2698d58
--- /dev/null
@@ -0,0 +1,37 @@
+<?php\r
+/**\r
+ * @package SLS\r
+ * @subpackage CONFIG.EXCEPTION\r
+ */\r
+\r
+/**\r
+ * required files\r
+ * @ignore\r
+ */\r
+require_once(LIBRARY_PATH . '/exception/exception.Base.php');\r
+\r
+/**\r
+ * Exceptions thrown in the DNSSEC library classes\r
+ *\r
+ * @package SLS\r
+ * @subpackage CONFIG.EXCEPTION\r
+ * @author Markus Warg <mw@it-sls.de>\r
+ * @since 2009-02-25 13:05\r
+ * @version $Id: exception.HumanReadableTimeException.php 91 2010-03-10 10:36:25Z markus $\r
+ */\r
+class HumanReadableTimeException extends BaseException {\r
+    /**\r
+     * make new object\r
+     *\r
+        * @access public\r
+     * @param string $message\r
+     * @param int $code\r
+     * @param string $extra\r
+     */\r
+       /*\r
+    public function __construct($message,$code = 0,$extra = '') {\r
+        parent::__construct($message,$code, $extra);\r
+    }\r
+    */\r
+}\r
+?>
\ No newline at end of file
diff --git a/manager/library/date/testHumanReadableTime.php b/manager/library/date/testHumanReadableTime.php
new file mode 100644 (file)
index 0000000..177d650
--- /dev/null
@@ -0,0 +1,16 @@
+<?php\r
+defined('LIBARARY_PATH')\r
+    || define('LIBRARY_PATH', realpath(dirname(__FILE__) . '/..'));\r
+\r
+require_once('HumanReadableTime.php');\r
+\r
+$hrf = HumanReadableTime::HR2Seconds($argv[1], true);\r
+print 'Seconds: ' . $hrf . "\n";\r
+\r
+print 'Default: ' . HumanReadableTime::Seconds2HR($hrf) . "\n";\r
+print 'Week: ' . HumanReadableTime::Seconds2HR($hrf, 'w') . "\n";\r
+print 'Day: ' . HumanReadableTime::Seconds2HR($hrf, 'd') . "\n";\r
+print 'Hour: ' . HumanReadableTime::Seconds2HR($hrf, 'h') . "\n";\r
+print 'Minute: ' . HumanReadableTime::Seconds2HR($hrf, 'm') . "\n";\r
+print 'Second: ' . HumanReadableTime::Seconds2HR($hrf, 's') . "\n";\r
+\r
diff --git a/manager/library/exception/exception.Base.php b/manager/library/exception/exception.Base.php
new file mode 100644 (file)
index 0000000..a91c086
--- /dev/null
@@ -0,0 +1,98 @@
+<?php\r
+/**\r
+ * @package SLS\r
+ * @subpackage EXCEPTION\r
+ */\r
+\r
+/**\r
+ * extend PHPs standard exception by some details\r
+ *\r
+ * @package SLS\r
+ * @subpackage EXCEPTION\r
+ * @author Markus Warg <mw@it-sls.de>\r
+ * @since 2009-02-23 16:10\r
+ * @version $Id: exception.Base.php 90 2010-03-09 09:48:27Z markus $\r
+ */\r
+class BaseException extends Exception {\r
+       /**\r
+        * additional data / string\r
+        * @var string\r
+        */\r
+       protected $extra = '';\r
+\r
+       /**\r
+        * location of thrower\r
+        * @var string\r
+        */\r
+       protected $exception_location = '';\r
+\r
+    /**\r
+     * make new object\r
+     *\r
+        * @access public\r
+     * @param string $message\r
+     * @param int $code\r
+     */\r
+    public function __construct($message, $code = 0, $extra = '') {\r
+        $bt = debug_backtrace();\r
+\r
+       $remove_exception = 0;\r
+       while( $remove_exception < count($bt) && isset($bt[$remove_exception]['class']) && eregi('exception', $bt[$remove_exception]['class']) ) {\r
+               $remove_exception++;\r
+       }\r
+\r
+               if ($remove_exception > 0)\r
+                       $remove_exception--;\r
+\r
+               if ($remove_exception < count($bt)) {\r
+               $this->exception_location = $bt[$remove_exception]['file'].':'.$bt[$remove_exception]['line'];\r
+               }\r
+\r
+               $this->extra = $extra;\r
+\r
+        parent::__construct($message,$code);\r
+    }\r
+\r
+    /**\r
+     * Make a string out of this exception\r
+        *\r
+        * @access public\r
+        * @return string\r
+     */\r
+       public function __toString() {\r
+       $out = __CLASS__ . '['.$this->code.']:';\r
+\r
+       if ($this->exception_location != '')\r
+               $out.= $this->exception_location;\r
+       $out .= ':';\r
+\r
+       $out .= " {$this->message}";\r
+\r
+       if (isset($this->extra) && strlen($this->extra) > 0)\r
+               $out .= " ({$this->extra})\n";\r
+\r
+        return $out;\r
+    }\r
+\r
+       /**\r
+        * get the extra info string\r
+        *\r
+        * @access public\r
+        * @return string\r
+        */\r
+       public function getExtraInfo() {\r
+               return $this->extra;\r
+       }\r
+\r
+       /**\r
+        * get the exception location string\r
+        *\r
+        * @access public\r
+        * @return string\r
+        */\r
+       public function getExceptionLocation() {\r
+               return $this->exception_location;\r
+       }\r
+\r
+}\r
+?>
\ No newline at end of file
diff --git a/manager/library/global/defines.php b/manager/library/global/defines.php
new file mode 100644 (file)
index 0000000..4e90ac5
--- /dev/null
@@ -0,0 +1,28 @@
+<?php\r
+/**\r
+ * @author markus\r
+ * $Id: defines.php 95 2010-03-19 14:14:39Z markus $\r
+ */\r
+\r
+// Define path to application directory\r
+defined('APPLICATION_PATH')\r
+    || define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/../../application'));\r
+defined('LIBARARY_PATH')\r
+    || define('LIBRARY_PATH', realpath(dirname(__FILE__) . '/..'));\r
+defined('FWACTIONS_PATH')\r
+    || define('FWACTIONS_PATH', LIBRARY_PATH . '/actions');\r
+defined('LOCALE_PATH')\r
+    || define('LOCALE_PATH', realpath(dirname(__FILE__) . '/../../locale'));\r
+\r
+// Define application environment\r
+defined('APPLICATION_ENV')\r
+    || define('APPLICATION_ENV', (getenv('APPLICATION_ENV') ? getenv('APPLICATION_ENV') : 'production'));\r
+\r
+define('SYSTEM_CONFIG', 'system_config');\r
+define('SYSTEM_LOG', 'log');\r
+\r
+// Ensure library/ is on include_path\r
+set_include_path(implode(PATH_SEPARATOR, array(\r
+    LIBRARY_PATH,\r
+    get_include_path(),\r
+)));\r
diff --git a/manager/library/helpers/GetEnv.php b/manager/library/helpers/GetEnv.php
new file mode 100644 (file)
index 0000000..3ac374d
--- /dev/null
@@ -0,0 +1,29 @@
+<?php
+/**
+ * @author markus
+ * $Id: GetEnv.php 6 2009-11-18 14:52:50Z markus $
+ */
+class GetEnv {
+    /**
+     * Get an environment variable with all the REDIRECT_ prefixes stripped off
+     */
+    public static function getEnvVar($var)
+    {
+        // Find out how deep the redirect goes
+        reset($_SERVER);
+        $key = key($_SERVER);
+        $redirectLevel = substr_count($key, 'REDIRECT_');
+
+        $result = '';
+        $prefix = '';
+        for ($i = 0; $i < $redirectLevel + 1; $i++) {
+                if (isset($_SERVER[$prefix . $var])) {
+                        $result = $_SERVER[$prefix . $var];
+                }
+                $prefix .= 'REDIRECT_';
+        }
+        return $result;
+    }
+}
+
+?>
\ No newline at end of file
diff --git a/manager/library/i18n/I18n.php b/manager/library/i18n/I18n.php
new file mode 100644 (file)
index 0000000..b95fb51
--- /dev/null
@@ -0,0 +1,95 @@
+<?php\r
+/**\r
+ * encapsulate Zend_Translate within an singleton class\r
+ * @author markus\r
+ * $Id: I18n.php 33 2009-12-10 15:08:38Z markus $\r
+ */\r
+\r
+require_once('l10n/L10n.php');\r
+\r
+class I18n {\r
+       /**\r
+        * static pointer to instance\r
+        * @var array(I18n)\r
+        */\r
+       private static $instance = null;\r
+\r
+       /**\r
+        * config object\r
+        * @var Zend_Translate\r
+        */\r
+       private $translate = null;\r
+\r
+       /**\r
+        * make new translate\r
+        */\r
+       protected function __construct() {\r
+       $options = array(\r
+               'log'                           => Log::Log(),\r
+               'logUntranslated'       => true\r
+       );\r
+\r
+       $locale = L10n::getInstance();\r
+       $supported = $locale->getBrowser();\r
+       arsort($supported, SORT_NUMERIC);\r
+\r
+       $file = '';\r
+       foreach ($supported as $loc => $val) {\r
+               if (file_exists(LOCALE_PATH . '/' . $loc . '/locale.php')) {\r
+                       $file = LOCALE_PATH . '/' . $loc . '/locale.php';\r
+                       $locale->setLocale($loc);\r
+                       break;\r
+               }\r
+       }\r
+\r
+               if ($file == '' && file_exists(LOCALE_PATH . '/en_US/locale.php')) {\r
+                       $file = LOCALE_PATH . '/en_US/locale.php';\r
+                       $locale->setLocale('en_US');\r
+               }\r
+\r
+       if ($file != '') {\r
+               $this->translate = new Zend_Translate(Zend_Translate::AN_ARRAY, $file, $locale->getLanguage(), $options);\r
+               #Log::Log()->debug('locale ' . $locale->getLanguage() . '_' .$locale->getRegion() . ' loaded');\r
+       }\r
+       else\r
+               throw new Exception(__METHOD__ . ': no translation files available');\r
+       }\r
+\r
+       /**\r
+        * get already existing instance, make new instance or throw an exception\r
+        * @return I18n\r
+        */\r
+       public static function getInstance() {\r
+               if (self::$instance === null) {\r
+                       self::$instance = new I18n();\r
+               }\r
+\r
+               return self::$instance;\r
+       }\r
+\r
+       /**\r
+        * return the Zend_Translate object\r
+        * @return Zend_Translate\r
+        */\r
+       public static function getTranslate() {\r
+               return self::getInstance()->translate;\r
+       }\r
+\r
+       /**\r
+        * map _ to translate\r
+        * @param unknown_type $text\r
+        * @param unknown_type $locale\r
+        */\r
+       public function _($text, $locale = null) {\r
+               return self::getInstance()->translate->_($text, $locale);\r
+       }\r
+\r
+       /**\r
+        * magic __call dispatches all unknown methods to Zend_Translate\r
+        * @param unknown_type $method\r
+        * @param unknown_type $arguments\r
+        */\r
+       public function __call($method, $arguments) {\r
+               return call_user_func_array(array($this->translate, $method), $arguments);\r
+       }\r
+}\r
diff --git a/manager/library/l10n/L10n.php b/manager/library/l10n/L10n.php
new file mode 100644 (file)
index 0000000..80fb091
--- /dev/null
@@ -0,0 +1,47 @@
+<?php\r
+/**\r
+ * encapsulate Zend_Locale within an singleton class\r
+ * @author markus\r
+ * $Id: L10n.php 13 2009-11-24 14:52:56Z markus $\r
+ */\r
+class L10n {\r
+       /**\r
+        * static pointer to instance\r
+        * @var L10n\r
+        */\r
+       private static $instance = null;\r
+\r
+       /**\r
+        * config object\r
+        * @var Zend_Locale\r
+        */\r
+       private $locale = null;\r
+\r
+       /**\r
+        * make new translate\r
+        */\r
+       protected function __construct() {\r
+               $this->locale = new Zend_Locale();\r
+       }\r
+\r
+       /**\r
+        * get already existing instance, make new instance or throw an exception\r
+        * @return L10n\r
+        */\r
+       public static function getInstance() {\r
+               if (self::$instance === null) {\r
+                       self::$instance = new L10n();\r
+               }\r
+\r
+               return self::$instance;\r
+       }\r
+\r
+       /**\r
+        * magic __call dispatches all unknown methods to Zend_Locale\r
+        * @param unknown_type $method\r
+        * @param unknown_type $arguments\r
+        */\r
+       public function __call($method, $arguments) {\r
+               return call_user_func_array(array($this->locale, $method), $arguments);\r
+       }\r
+}\r
diff --git a/manager/library/log/Log.php b/manager/library/log/Log.php
new file mode 100644 (file)
index 0000000..8ad27b9
--- /dev/null
@@ -0,0 +1,105 @@
+<?php\r
+/**\r
+ * encapsulate Zend_Log with one or several log writers within an singleton class\r
+ * @author markus\r
+ * $Id: Log.php 77 2010-02-26 11:58:34Z markus $\r
+ */\r
+class Log {\r
+       /**\r
+        * static pointer to instances\r
+        * @var array(Config)\r
+        */\r
+       private static $instances = array();\r
+\r
+       /**\r
+        * can handle several instances, distinct by instance name string\r
+        * @var string\r
+        */\r
+       private $instanceName = '';\r
+\r
+       /**\r
+        * config object\r
+        * @var Zend_Log\r
+        */\r
+       private $log = null;\r
+\r
+       /**\r
+        * make new logger, configuration is taken from system_config, section $instanceName\r
+        * @param string $instanceName\r
+        * @param string $application\r
+        */\r
+       protected function __construct($instanceName, $application = null) {\r
+               if ($instanceName === null)\r
+               throw new Exception(__METHOD__ . ': expected an instance name, got none');\r
+\r
+       $config = Config::getInstance(SYSTEM_CONFIG);\r
+       $log_config = $config->$instanceName;\r
+\r
+               $this->log = new Zend_Log();\r
+       if (isset($log_config->file) && intval($log_config->file->enabled) !== 0) {\r
+               $file_logger = new Zend_Log_Writer_Stream($log_config->file->name);\r
+\r
+               /**\r
+                *\r
+               $format = Zend_Log_Formatter_Simple::DEFAULT_FORMAT;\r
+               $formatter = new Zend_Log_Formatter_Simple($format);\r
+               $file_logger->setFormatter($formatter);\r
+                */\r
+               if (isset($application) && $application != '')\r
+                       $this->log->setEventItem('application', $application);\r
+               $formatter = new Zend_Log_Formatter_Simple('%syslog_time% %application%[%pid%]: %priorityName%: %message%' . PHP_EOL);\r
+               $file_logger->setFormatter($formatter);\r
+                       $this->log->addWriter($file_logger);\r
+       }\r
+       if (isset($log_config->syslog) && intval($log_config->syslog->enabled) !== 0) {\r
+               $param = array('facility' => $log_config->syslog->facility);\r
+               if (isset($application) && $application != '')\r
+                       $param['application'] = $application;\r
+\r
+               $sys_logger = new Zend_Log_Writer_Syslog($param);\r
+               $formatter = new Zend_Log_Formatter_Simple('%priorityName%: %message%' . PHP_EOL);\r
+               $sys_logger->setFormatter($formatter);\r
+                       $this->log->addWriter($sys_logger);\r
+       }\r
+\r
+       $filter = new Zend_Log_Filter_Priority(intval($log_config->priority));\r
+       $this->log->addFilter($filter);\r
+       }\r
+\r
+       /**\r
+        * get already existing instance, make new instance or throw an exception\r
+        * @param string $instanceName\r
+        * @param string $application\r
+        */\r
+       public static function getInstance($instanceName = null, $application = null) {\r
+               if ($instanceName === null) {\r
+                       if (count(self::$instances) == 0)\r
+                       throw new Exception(__METHOD__ . ': expected an instance name, got none');\r
+               return self::$instances[0];\r
+               }\r
+\r
+               if (!array_key_exists($instanceName, self::$instances)) {\r
+                       self::$instances[$instanceName] = new Log($instanceName, $application);\r
+               }\r
+\r
+               return self::$instances[$instanceName];\r
+       }\r
+\r
+       /**\r
+        * return SYSTEM_LOG for convenience\r
+        * @return Zend_Log\r
+        */\r
+       public static function Log() {\r
+               return self::$instances[SYSTEM_LOG]->getLog();\r
+       }\r
+\r
+       /**\r
+        * get the Zend_Log object\r
+        * @return Zend_Log\r
+        */\r
+       public function getLog() {\r
+               $this->log->setEventItem('pid', posix_getpid());\r
+               $this->log->setEventItem('syslog_time', date('Y-m-d H:i:s'));\r
+               return $this->log;\r
+       }\r
+}\r
diff --git a/manager/library/plugins/plugin.buildmenu.php b/manager/library/plugins/plugin.buildmenu.php
new file mode 100644 (file)
index 0000000..d98b14e
--- /dev/null
@@ -0,0 +1,74 @@
+<?php\r
+\r
+/**\r
+ * this plugin tries to add modules to the top navigation depending on the user\r
+ * which is logged in and the required permissions needed (provided by the action modules)\r
+ *\r
+ * @author markus\r
+ * $Id: plugin.buildmenu.php 95 2010-03-19 14:14:39Z markus $\r
+ */\r
+class BuildMenu extends Zend_Controller_Plugin_Abstract {\r
+       public function preDispatch(Zend_Controller_Request_Abstract $request) {\r
+               $session = Zend_Registry::get('session');\r
+       if (!isset($session->authdata) || !isset($session->authdata['authed']) || $session->authdata['authed'] === false)\r
+               return;\r
+\r
+               $cur_ctrl = $request->getControllerName();\r
+               $cur_action = $request->getActionName();\r
+\r
+       $view = Zend_Registry::get('view');\r
+\r
+               if (is_dir(FWACTIONS_PATH)) {\r
+                       $dir = opendir(FWACTIONS_PATH);\r
+\r
+                       while (($file = readdir($dir)) !== false) {\r
+                               if ($file == '.' || $file == '..')\r
+                                       continue;\r
+                               if (preg_match('/^Action([a-zA-Z0-9_]*)\.php/', $file, $match)) {\r
+                                       $path = FWACTIONS_PATH . '/' . $file;\r
+                                       require_once($path);\r
+\r
+                                       $r = new ReflectionClass($match[1]);\r
+\r
+                                       if ($r->isSubclassOf('FWAction')) {\r
+                                               /**\r
+                                                * match Actions permission with the permissions of the currently logged in user,\r
+                                                * add to menu if user has access to that action\r
+                                                */\r
+\r
+                                               $required = $r->getMethod('getRequiredPermissions')->invoke(null);\r
+                                               $menuprio = $r->getMethod('getTopNavPrio')->invoke(null);\r
+                                               $ctrl = $r->getMethod('getController')->invoke(null);\r
+                                               $action = $r->getMethod('getAction')->invoke(null);\r
+                                               $text = $r->getMethod('getMenutext')->invoke(null);\r
+                                               $role = $session->authdata['authed_role'];\r
+\r
+                                               if ($cur_ctrl == $ctrl) # && $cur_action == $action)\r
+                                                       $aclass = ' class="active"';\r
+                                               else\r
+                                                       $aclass = '';\r
+\r
+                                               $acl = $session->authdata['authed_permissions'];\r
+                                               if (is_array($required) && count($required) == 0) {\r
+                                                       $view->topNav('<a href="' .\r
+                                                       $view->url(array('controller' => $ctrl, 'action' => $action), 'default', true) .\r
+                                                       '"' . $aclass . '>' . I18n::_($text) . '</a>', Zend_View_Helper_Placeholder_Container_Abstract::SET, $menuprio);\r
+                                               }\r
+                                               else {\r
+                                                       foreach ($required as $rperm) {\r
+                                                               if ($acl->has($rperm) && $acl->isAllowed($role, $rperm, 'view')) {\r
+                                                               $view->topNav('<a href="' .\r
+                                                                       $view->url(array('controller' => $ctrl, 'action' => $action), 'default', true) .\r
+                                                                       '"' . $aclass . '>' . I18n::_($text) . '</a>', Zend_View_Helper_Placeholder_Container_Abstract::SET, $menuprio);\r
+                                                       break;  // exit on first match\r
+                                                               }\r
+                                                       }\r
+                                               }\r
+                                       }\r
+                               }\r
+                       }\r
+\r
+                       closedir($dir);\r
+               }\r
+       }\r
+}
\ 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 (file)
index 0000000..57e4f50
--- /dev/null
@@ -0,0 +1,13 @@
+<?php\r
+/**\r
+ * @author markus\r
+ * $Id: plugin.charsetheader.php 13 2009-11-24 14:52:56Z markus $\r
+ */\r
+class CharsetHeader extends Zend_Controller_Plugin_Abstract {\r
+       public function preDispatch(Zend_Controller_Request_Abstract $request) {\r
+               $response = $this->getResponse();\r
+               if ($response->canSendHeaders() === true) {\r
+                       $response->setHeader('Content-Type', 'text/html; charset=utf-8');\r
+               }\r
+       }\r
+}
\ 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 (file)
index 0000000..4fa9068
--- /dev/null
@@ -0,0 +1,29 @@
+<?php\r
+/**\r
+ * @author markus\r
+ * $Id: plugin.forceauth.php 40 2009-12-21 09:40:43Z markus $\r
+ */\r
+class ForceAuth extends Zend_Controller_Plugin_Abstract {\r
+       public function dispatchLoopStartup(Zend_Controller_Request_Abstract $request) {\r
+               $session = Zend_Registry::get('session');\r
+\r
+               if (in_array($request->getControllerName(), array('login', 'error', 'js', 'img', 'css')))\r
+                       return;\r
+\r
+               if (!isset($session->authdata) || !isset($session->authdata['authed']) || $session->authdata['authed'] === false) {\r
+                       $fc = Zend_Controller_Front::getInstance();\r
+\r
+                       $response = $fc->getResponse();\r
+                       $response->canSendHeaders(true);\r
+\r
+                       $response->setHeader('Location', 'login', true);\r
+                       $response->setHeader('Status', '301', true);\r
+                       Log::Log()->debug('redirected to login');\r
+\r
+                       $request->setModuleName('default')\r
+                       ->setControllerName('login')\r
+                       ->setActionName('index')\r
+                       ->setDispatched(false);\r
+               }\r
+       }\r
+}\r
diff --git a/manager/library/plugins/plugin.loginlogout.php b/manager/library/plugins/plugin.loginlogout.php
new file mode 100644 (file)
index 0000000..6de7a92
--- /dev/null
@@ -0,0 +1,25 @@
+<?php\r
+\r
+/**\r
+ * this plugin just monitors the authdata section in the current session and adds an login / logout link to the\r
+ * top navigation bar depending on the value that was found\r
+ * @author markus\r
+ * $Id: plugin.loginlogout.php 95 2010-03-19 14:14:39Z markus $\r
+ */\r
+class LoginLogout extends Zend_Controller_Plugin_Abstract {\r
+       public function postDispatch(Zend_Controller_Request_Abstract $request) {\r
+               $session = Zend_Registry::get('session');\r
+       if (!isset($session->authdata) || !isset($session->authdata['authed']) || $session->authdata['authed'] === false) {\r
+               $controller             = 'login';\r
+               $text                   = 'Login';\r
+       }\r
+       else {\r
+               $controller             = 'logout';\r
+               $text                   = 'Logout';\r
+       }\r
+       $view = Zend_Registry::get('view');\r
+       $view->topNav('<a href="' .\r
+               $view->url(array('controller' => $controller), 'default', true) .\r
+               '">' . I18n::_($text) . '</a>', Zend_View_Helper_Placeholder_Container_Abstract::SET, 1000);\r
+       }\r
+}\r
diff --git a/manager/locale/en_US/locale.php b/manager/locale/en_US/locale.php
new file mode 100644 (file)
index 0000000..68e6ef9
--- /dev/null
@@ -0,0 +1,2 @@
+<?php\r
+return array();
\ No newline at end of file
diff --git a/manager/public/.htaccess b/manager/public/.htaccess
new file mode 100644 (file)
index 0000000..d38ce5e
--- /dev/null
@@ -0,0 +1,10 @@
+php_value session.auto_start 0
+
+SetEnv APPLICATION_ENV development
+
+RewriteEngine On
+RewriteCond %{REQUEST_FILENAME} -s [OR]
+RewriteCond %{REQUEST_FILENAME} -l [OR]
+RewriteCond %{REQUEST_FILENAME} -d
+RewriteRule ^.*$ - [NC,L]
+RewriteRule ^.*$ index.php [NC,L]
diff --git a/manager/public/css/form_dl.css b/manager/public/css/form_dl.css
new file mode 100644 (file)
index 0000000..c3dc8c0
--- /dev/null
@@ -0,0 +1,23 @@
+@CHARSET "UTF-8";
+
+#content dl.zend_form label.required {
+       color: #000000;
+       font-weight: bold;
+}
+
+#content dl.zend_form {
+       display: block;
+}
+
+#content dl.zend_form dt {
+       display: block;
+       float: left;
+       width: 125px;
+       margin: 10px;
+}
+
+#content dl.zend_form dd {
+       display: block;
+       clear: right;
+       padding: 10px;
+}
diff --git a/manager/public/css/form_dl_wide.css b/manager/public/css/form_dl_wide.css
new file mode 100644 (file)
index 0000000..6f8ed41
--- /dev/null
@@ -0,0 +1,24 @@
+@CHARSET "UTF-8";
+
+#content dl.zend_form label.required {
+       color: #000000;
+       font-weight: bold;
+}
+
+#content dl.zend_form {
+       display: block;
+       font-size: 0.8em;
+}
+
+#content dl.zend_form dt {
+       display: block;
+       float: left;
+       width: 350px;
+       margin: 10px;
+}
+
+#content dl.zend_form dd {
+       display: block;
+       clear: right;
+       padding: 10px;
+}
diff --git a/manager/public/css/global.css b/manager/public/css/global.css
new file mode 100644 (file)
index 0000000..b289414
--- /dev/null
@@ -0,0 +1,123 @@
+@CHARSET "UTF-8";\r
+\r
+html {\r
+       font-family: sans-serif;\r
+       background-color: #cccccc;\r
+       color: #333333;\r
+       overflow: scroll;\r
+}\r
+\r
+#center {\r
+       position: absolute;\r
+       width: 1000px;\r
+       left: 50%;\r
+       margin-left: -500px;\r
+}\r
+\r
+#header {\r
+       background-color: #F5F7F7;\r
+       width: 99%;\r
+       height: 30px;\r
+       top: 0px;\r
+       left: 0px;\r
+       position: absolute;\r
+       padding: 3px;\r
+       margin: 3px;\r
+}\r
+\r
+#header-logo {\r
+       float: left;\r
+       color: #FFFFFF;\r
+}\r
+\r
+#header-navigation {\r
+       float: right;\r
+}\r
+\r
+#header-navigation ul {\r
+       list-style-type: none;\r
+       padding: 0px;\r
+       margin: 0px;\r
+       font-size: 1.2em;\r
+}\r
+\r
+#header-navigation ul li {\r
+       padding-left: 5px;\r
+       margin-left: 5px;\r
+       display: inline;\r
+}\r
+\r
+#header-navigation ul li a {\r
+       text-decoration: none;\r
+       color: #000000;\r
+}\r
+\r
+#header-navigation ul li a:hover {\r
+       color: #777777;\r
+}\r
+\r
+#header-navigation ul li a.active {\r
+       color: #505090;\r
+}\r
+\r
+#left-navigation {\r
+       background-color: #F5F7F7;\r
+       width: 180px;\r
+       height: 600px;\r
+       left: 0px;\r
+       top: 36px;\r
+       position: absolute;\r
+       padding: 3px; \r
+       margin: 3px;\r
+}\r
+\r
+#left-navigation ul {\r
+       list-style-type: none;\r
+       padding: 0px;\r
+       margin: 0px;\r
+       font-size: 1.2em;\r
+}\r
+\r
+#left-navigation ul li {\r
+       padding-left: 5px;\r
+       margin-left: 5px;\r
+       display: block;\r
+}\r
+\r
+#left-navigation ul li a {\r
+       text-decoration: none;\r
+       color: #000000;\r
+}\r
+\r
+#left-navigation ul li a:hover {\r
+       color: #777777;\r
+}\r
+\r
+#left-navigation ul li a.active {\r
+       color: #770000;\r
+}\r
+\r
+#content {\r
+       left: 186px;\r
+       top: 36px;\r
+       width: 800px;\r
+       position: absolute;\r
+       padding: 5px;\r
+       margin: 3px;\r
+       background-color: #FFFFFF;\r
+}\r
+\r
+#userinfo {\r
+       right: 5px;\r
+       bottom: 5px;\r
+       position: absolute;\r
+       padding: 3px;\r
+       margin: 3px;\r
+       background-color: #DDDDAA;\r
+       font-size: 0.8em;\r
+}\r
+\r
+#content .error {\r
+       color: #F80808;\r
+       font-weight: bold;\r
+}
\ No newline at end of file
diff --git a/manager/public/css/login.css b/manager/public/css/login.css
new file mode 100644 (file)
index 0000000..c68a4aa
--- /dev/null
@@ -0,0 +1,11 @@
+@CHARSET "UTF-8";\r
+\r
+#content a {\r
+       text-decoration: none;\r
+       color: #000000;\r
+       font-size: 1.2em;\r
+}\r
+\r
+#content a:hover {\r
+       color: #777777;\r
+}
\ No newline at end of file
diff --git a/manager/public/favicon.ico b/manager/public/favicon.ico
new file mode 100644 (file)
index 0000000..69e92cd
Binary files /dev/null and b/manager/public/favicon.ico differ
diff --git a/manager/public/img/cacert4.png b/manager/public/img/cacert4.png
new file mode 100644 (file)
index 0000000..e4650a0
Binary files /dev/null and b/manager/public/img/cacert4.png differ
diff --git a/manager/public/index.php b/manager/public/index.php
new file mode 100644 (file)
index 0000000..229290b
--- /dev/null
@@ -0,0 +1,51 @@
+<?php\r
+/*\r
+ * @done Zend_Locale (http://framework.zend.com/manual/en/zend.locale.functions.html)\r
+ * @done Zend_Translate (Buch 381ff, 383) http://framework.zend.com/manual/en/zend.translate.using.html\r
+ * @done Session Tabelle aufräumen (auto expire eingebaut, Housekeeper fehlt aber)\r
+ * @todo Zend_Auth (LoginController - Reaktion auf falsche Eingaben fehlt noch)\r
+ * @todo Zend_Filter_Input - Zeichensätze aus Userinput filtern\r
+ * @todo Zend_Measure, Zend_Currency\r
+ * @todo Zend_Date\r
+ * @todo Daemon / CLI Zend_Console_Getopt (Buch 203ff)\r
+ * @todo Zend_Mail (Buch 279ff)\r
+ * @todo Zend_Form(!), Zend_Validate, Zend_Filter\r
+ * @todo Zend_Log - Formatierung der Texte\r
+ * @todo Funktionsmodule - jedes Modul prüft die Rechte anhand der Session und Zend_Acl und fügt ggf. einen Link ins Menü ein (TOP / LEFT)\r
+ * @todo addMessages mit übersetzten Strings (LoginController -> getForm, ...)\r
+ * @todo favicon\r
+ * @todo sinnvolle Defaults, wenn system_config leer ist (globale Config BIND)\r
+ * @todo sinnvolle Defaults, wenn system_config leer ist (Organisationsconfig BIND)\r
+ * @todo Links zum Löschen für Zonen / Organisationen, Rechtechecks in ActionController (foreign key constraints beachten!)\r
+ * @todo ConfigBIND left Menu geht nicht aus, wenn man die selektierte Org deaktiviert (init vor Action)\r
+ * @todo Textausgabe, wenn Attribute aus Defaults initialisiert und NICHT aus der DB geladen wurden\r
+ */\r
+\r
+require_once('../library/global/defines.php');\r
+\r
+try {\r
+       /** Zend Autoloader */\r
+       require_once 'Zend/Loader/Autoloader.php';\r
+       Zend_Loader_Autoloader::getInstance();\r
+\r
+       // Create application, bootstrap, and run\r
+       $application = new Zend_Application(\r
+           APPLICATION_ENV,\r
+           APPLICATION_PATH . '/configs/application.ini'\r
+       );\r
+\r
+       /** override settings from application.ini, if necessary\r
+       $fc = Zend_Controller_Front::getInstance();\r
+       $fc->setControllerDirectory(realpath(APPLICATION_PATH . '/controllers'));\r
+       $fc->setParam('noViewRenderer', false);\r
+       $fc->throwExceptions(true);\r
+       $fc->setParam('noErrorHandler', false);\r
+       */\r
+\r
+       $application->bootstrap()\r
+                   ->run();\r
+} catch (Exception $e) {\r
+       print "Exception: " . $e->getMessage() . "\n";\r
+       print $e->getTraceAsString() . "\n";\r
+       Log::Log()->emerg($e);\r
+}\r
diff --git a/manager/public/js/center.js b/manager/public/js/center.js
new file mode 100644 (file)
index 0000000..267550c
--- /dev/null
@@ -0,0 +1,10 @@
+function setCSS() {\r
+       var x = window.innerWidth;\r
+\r
+       x = x - 18;     // maybe scroll bar\r
+       document.getElementById('center').style.width = x + "px";\r
+       document.getElementById('center').style.marginLeft = "-" + x/2 + "px";\r
+}\r
+\r
+window.onload = setCSS;\r
+window.onresize = setCSS;\r
diff --git a/manager/public/js/positionUserInfo.js b/manager/public/js/positionUserInfo.js
new file mode 100644 (file)
index 0000000..0de1db4
--- /dev/null
@@ -0,0 +1,17 @@
+function setUserInfoPos() {\r
+       var x = window.innerWidth;\r
+       var ui;\r
+       \r
+       x = x - 18;     // maybe scroll bar\r
+       \r
+       ui = document.getElementById('userinfo');\r
+       if (ui != null) {\r
+               ui.style.right = "3px";\r
+//             document.getElementById('userinfo').style.bottom = "3px";\r
+               ui.style.bottom = 3 - window.pageYOffset + "px";\r
+       }\r
+}\r
+\r
+window.onload = setUserInfoPos;\r
+window.onresize = setUserInfoPos;\r
+window.onscroll = setUserInfoPos;\r
diff --git a/manager/tests/application/bootstrap.php b/manager/tests/application/bootstrap.php
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/manager/tests/library/bootstrap.php b/manager/tests/library/bootstrap.php
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/manager/tests/phpunit.xml b/manager/tests/phpunit.xml
new file mode 100644 (file)
index 0000000..e69de29