function removeAction()
 {
     $hash = $this->getRequest()->getParam('csrf');
     $accountId = $this->getRequest()->getParam('id');
     $csrf = new Zend_Form_Element_Hash('csrf', array('salt' => __CLASS__));
     if (!$csrf->isValid($hash)) {
         $this->_helper->flashMessenger(array('type' => 'error', 'text' => X_Env::_('p_auth_err_invalidhash')));
         $this->_helper->redirector('accounts', 'auth');
         return;
     }
     $account = new Application_Model_AuthAccount();
     Application_Model_AuthAccountsMapper::i()->find($accountId, $account);
     if (is_null($account->getId())) {
         $this->_helper->flashMessenger(array('type' => 'error', 'text' => X_Env::_('p_auth_err_invalidaccount')));
         $this->_helper->redirector('accounts', 'auth');
         return;
     }
     if ($this->plugin->getCurrentUser() == $account->getUsername()) {
         $this->_helper->flashMessenger(array('type' => 'error', 'text' => X_Env::_('p_auth_err_currentremovalnotallowed')));
         $this->_helper->redirector('accounts', 'auth');
         return;
     }
     Application_Model_AuthAccountsMapper::i()->delete($account);
     $this->_helper->flashMessenger(array('type' => 'success', 'text' => X_Env::_('p_auth_accountremoved', $account->getUsername())));
     $this->_helper->redirector('accounts', 'auth');
 }
 public function saveAction()
 {
     $lang = $this->getRequest()->getParam('lang', false);
     $lang = $lang !== false ? str_replace('../', '', $lang) : $lang;
     if ($lang !== false && file_exists(APPLICATION_PATH . "/../languages/{$lang}")) {
         $config = new Application_Model_Config();
         Application_Model_ConfigsMapper::i()->fetchByKey('languageFile', $config);
         if ($config->getId() !== null) {
             $config->setValue($lang);
             try {
                 Application_Model_ConfigsMapper::i()->save($config);
                 $this->_helper->flashMessenger(array('type' => 'success', 'text' => X_Env::_('installer_language_done')));
                 //$this->_helper->redirector('execute');
             } catch (Exception $e) {
                 $this->_helper->flashMessenger(array('type' => 'fatal', 'text' => X_Env::_("installer_err_db") . ": {$e->getMessage()}"));
             }
         }
     } else {
         $this->_helper->flashMessenger(array('type' => 'error', 'text' => X_Env::_('installer_invalid_language')));
         $this->_helper->redirector('index');
     }
     // check for admin username/password
     $form = new Application_Form_Installer();
     $form->removeElement('lang');
     $form->removeElement('plugins');
     if (!$form->isValid($this->getRequest()->getPost())) {
         $ns = new Zend_Session_Namespace('vlc-shares::installer');
         $ns->errors = true;
         $ns->data = $this->getRequest()->getPost();
         $this->_helper->flashMessenger(array('type' => 'error', 'text' => X_Env::_('installer_invalid_data')));
         $this->_helper->redirector('index');
         return;
     }
     $username = $form->getValue('username');
     $password = $form->getValue('password');
     if (Application_Model_AuthAccountsMapper::i()->getCount(true) == 0) {
         // try to reenable/create a new account
         try {
             $account = new Application_Model_AuthAccount();
             Application_Model_AuthAccountsMapper::i()->fetchByUsername($username);
             $account->setUsername($username)->setPassword(md5("{$username}:{$password}"))->setEnabled(true)->setPassphrase(md5("{$username}:{$password}:" . rand(10000, 99999) . time()))->setAltAllowed(true);
             Application_Model_AuthAccountsMapper::i()->save($account);
             // adding permissions
             X_VlcShares_Plugins::helpers()->acl()->grantPermission($username, Application_Model_AclClass::CLASS_ADMIN);
             X_VlcShares_Plugins::helpers()->acl()->grantPermission($username, Application_Model_AclClass::CLASS_BROWSE);
             $this->_helper->flashMessenger(array('type' => 'success', 'text' => X_Env::_('installer_newaccount_done')));
         } catch (Exception $e) {
             $this->_helper->flashMessenger(X_Env::_('installer_err_db') . ": {$e->getMessage()}");
             $this->_helper->redirector('index');
             return;
         }
         // after that account is stored, try to do a login
         if (X_VlcShares_Plugins::broker()->isRegistered('auth')) {
             $auth = X_VlcShares_Plugins::broker()->getPlugins('auth');
         } else {
             $auth = new X_VlcShares_Plugins_Auth();
         }
         if (!$auth->isLoggedIn()) {
             $auth->doLogin($username);
         }
     }
     try {
         // enable auth plugin after authentication
         if ($form->getValue('auth', '0') == '1') {
             /*
             		    	$plugin = new Application_Model_Plugin();
             		    	Application_Model_PluginsMapper::i()->fetchByClass('X_VlcShares_Plugins_Auth', $plugin);
             		    	//Application_Model_PluginsMapper::i()->delete($plugin);
             $plugin->setEnabled(true);
             Application_Model_PluginsMapper::i()->save($plugin);
             */
             $config = new Application_Model_Config();
             Application_Model_ConfigsMapper::i()->fetchByKey('auth.login.enabled', $config);
             $config->setValue('1');
             Application_Model_ConfigsMapper::i()->save($config);
         }
         // check forker url
         $forkerUrl = $form->getValue('threads', false);
         if ($forkerUrl) {
             $config = new Application_Model_Config();
             Application_Model_ConfigsMapper::i()->fetchByKey('threads.forker', $config);
             $config->setValue($forkerUrl);
             Application_Model_ConfigsMapper::i()->save($config);
         }
     } catch (Exception $e) {
         $this->_helper->flashMessenger(X_Env::_('installer_err_db') . ": {$e->getMessage()}");
         $this->_helper->redirector('index');
     }
     $plugins = $this->getRequest()->getParam('plugins', array());
     //ini_set('max_execution_time', 0);
     ignore_user_abort(true);
     if (is_array($plugins)) {
         /* @var $pluginInstaller X_VlcShares_Plugins_PluginInstaller */
         $pluginInstaller = X_VlcShares_Plugins::broker()->getPlugins('plugininstaller');
         foreach ($plugins as $plugin) {
             // allow 30 seconds for each plugin
             set_time_limit(30);
             try {
                 $pluginInstaller->installPlugin($plugin, true);
                 $this->_helper->flashMessenger(array('type' => 'success', 'text' => X_Env::_('plugin_install_done') . ": {$plugin}"));
             } catch (Exception $e) {
                 $this->_helper->flashMessenger(array('text' => X_Env::_('plugin_err_installerror') . ": " . $e->getMessage(), 'type' => 'error'));
             }
             // download the plugin file
             /*
             $http = new Zend_Http_Client($plugin);
             $http->setStream(true);
             
             $response = $http->request();
             
             if ( $this->_installPlugin($response->getStreamName()) ) {
             	$this->_helper->flashMessenger(array('type' => 'success', 'text' => X_Env::_('plugin_install_done') . ": $plugin"));
             }
             */
         }
     }
     $this->_helper->redirector('execute');
 }