/** * Does an FTP upload to save the configuration. */ function _uploadFTP($params) { global $registry, $notification; $params['hostspec'] = 'localhost'; try { $vfs = Horde_Vfs::factory('ftp', $params); } catch (Horde_Vfs_Exception $e) { $notification->push(sprintf(_("Could not connect to server \"%s\" using FTP: %s"), $params['hostspec'], $e->getMessage()), 'horde.error'); return false; } /* Loop through the config and write to FTP. */ $no_errors = true; foreach ($GLOBALS['session']->get('horde', 'config/') as $app => $config) { $path = $registry->get('fileroot', $app) . '/config'; /* Try to back up the current conf.php. */ if ($vfs->exists($path, 'conf.php')) { try { $vfs->rename($path, 'conf.php', $path, '/conf.bak.php'); $notification->push(_("Successfully saved backup configuration."), 'horde.success'); } catch (Horde_Vfs_Exception $e) { $notification->push(sprintf(_("Could not save a backup configuation: %s"), $e->getMessage()), 'horde.error'); } } try { $vfs->writeData($path, 'conf.php', $config); $notification->push(sprintf(_("Successfully wrote %s"), Horde_Util::realPath($path . '/conf.php')), 'horde.success'); $GLOBALS['session']->remove('horde', 'config/' . $app); } catch (Horde_Vfs_Exception $e) { $no_errors = false; $notification->push(sprintf(_("Could not write configuration for \"%s\": %s"), $app, $e->getMessage()), 'horde.error'); } } $registry->rebuild(); return $no_errors; }
if (is_link($configFile)) { $configFile = readlink($configFile); } if ($vars->submitbutton == _("Revert Configuration")) { if (@copy($path . '/conf.bak.php', $configFile)) { $notification->push(_("Successfully reverted configuration. Reload to see changes."), 'horde.success'); @unlink($path . '/conf.bak.php'); } else { $notification->push(_("Could not revert configuration."), 'horde.error'); } } elseif ($form->validate($vars)) { $config = new Horde_Config($app); if ($config->writePHPConfig($vars, $php)) { Horde::url('admin/config/index.php', true)->redirect(); } else { $notification->push(sprintf(_("Could not save the configuration file %s. You can either use one of the options to save the code back on %s or copy manually the code below to %s."), Horde_Util::realPath($configFile), Horde::link(Horde::url('admin/config/index.php') . '#update', _("Configuration")) . _("Configuration") . '</a>', Horde_Util::realPath($configFile)), 'horde.warning', array('content.raw', 'sticky')); } } elseif ($form->isSubmitted()) { $notification->push(_("There was an error in the configuration form. Perhaps you left out a required field."), 'horde.error'); } $view = new Horde_View(array('templatePath' => HORDE_TEMPLATES . '/admin/config')); $view->addHelper('Text'); $view->php = $php; /* Create the link for the diff popup only if stored in session. */ if ($session->exists('horde', 'config/' . $app)) { $url = Horde::url('admin/config/diff.php', true)->add('app', $app); $view->diff_popup = Horde::link('#', '', '', '', Horde::popupJs($url, array('height' => 480, 'width' => 640, 'urlencode' => true)) . 'return false;') . _("show differences") . '</a>'; } Horde::startBuffer(); require HORDE_TEMPLATES . '/admin/menu.inc'; $menu_output = Horde::endBuffer();
$data .= '\')) {' . "\n"; $data .= ' echo \'' . sprintf('Saved %s configuration.', $app) . '\' . "\\n";' . "\n"; $data .= '} else {' . "\n"; $data .= ' echo \'' . sprintf('Could NOT save %s configuration.', $app) . '\' . "\\n";' . "\n"; $data .= ' exit;' . "\n"; $data .= '}' . "\n\n"; } } if ($vars->save != 'tmp') { /* Output script to browser for download. */ $browser->downloadHeaders($filename, 'text/plain', false, strlen($data)); echo $data; exit; } $tmp_dir = Horde::getTempDir(); /* Add self-destruct code. */ $data .= 'echo \'Self-destructing...\' . "\\n";' . "\n"; $data .= 'if (@unlink(__FILE__)) {' . "\n"; $data .= ' echo \'Upgrade script deleted.\' . "\\n";' . "\n"; $data .= '} else {' . "\n"; $data .= ' echo \'WARNING!!! REMOVE SCRIPT MANUALLY FROM ' . $tmp_dir . '\' . "\\n";' . "\n"; $data .= '}' . "\n"; /* The script should be saved to server's temporary directory. */ $path = Horde_Util::realPath($tmp_dir . '/' . $filename); if (file_put_contents($tmp_dir . '/' . $filename, $data)) { chmod($tmp_dir . '/' . $filename, 0777); $notification->push(sprintf(_("Saved configuration upgrade script to: \"%s\"."), $path), 'horde.success', array('sticky')); } else { $notification->push(sprintf(_("Could not save configuration upgrade script to: \"%s\"."), $path), 'horde.error'); } Horde::url('admin/config/index.php', true)->redirect();
/** * Generates and writes the content of the application's configuration * file. * * @param Horde_Variables $formvars The processed configuration form * data. * @param string $php The content of the generated * configuration file. * * @return boolean True if the configuration file could be written * immediately to the file system. */ public function writePHPConfig($formvars, &$php = null) { $php = $this->generatePHPConfig($formvars); $path = $GLOBALS['registry']->get('fileroot', $this->_app) . '/config'; $configFile = $this->configFile(); if (file_exists($configFile)) { if (@copy($configFile, $path . '/conf.bak.php')) { $GLOBALS['notification']->push(sprintf(Horde_Core_Translation::t("Successfully saved the backup configuration file %s."), Horde_Util::realPath($path . '/conf.bak.php')), 'horde.success'); } else { $GLOBALS['notification']->push(sprintf(Horde_Core_Translation::t("Could not save the backup configuration file %s."), Horde_Util::realPath($path . '/conf.bak.php')), 'horde.warning'); } } if ($fp = @fopen($configFile, 'w')) { /* Can write, so output to file. */ fwrite($fp, $php); fclose($fp); $GLOBALS['registry']->rebuild(); $GLOBALS['notification']->push(sprintf(Horde_Core_Translation::t("Successfully wrote %s"), Horde_Util::realPath($configFile)), 'horde.success'); return true; } /* Cannot write. Save to session. */ $GLOBALS['session']->set('horde', 'config/' . $this->_app, $php); return false; }
function _renderVarInput_selectFiles($form, $var, $vars) { /* Needed for gollem js calls */ $html = sprintf('<input type="hidden" id="%1$s" name="%1$s" value="%2$s" />', 'selectlist_selectid', $var->type->selectid) . sprintf('<input type="hidden" id="%1$s" name="%1$s" />', 'actionID'); /* Form field. */ $html .= sprintf('<input type="hidden" id="%1$s" name="%1$s" value="%2$s" />', $var->getVarName(), $var->type->selectid); /* Open window link. */ $param = array($var->type->link_text, $var->type->link_style, $form->getName(), $var->type->icon, $var->type->selectid); $html .= "<p>\n" . $GLOBALS['registry']->call('files/selectlistLink', $param) . "</p>\n"; if ($var->type->selectid) { $param = array($var->type->selectid); $files = $GLOBALS['registry']->call('files/selectlistResults', $param); if ($files) { $html .= '<ol>'; foreach ($files as $id => $file) { $dir = key($file); $filename = current($file); if ($GLOBALS['registry']->hasMethod('files/getViewLink')) { $filename = basename($filename); $url = $GLOBALS['registry']->call('files/getViewLink', array($dir, $filename)); $filename = Horde::link($url, Horde_Model_Translation::t("Preview"), null, 'form_file_view') . htmlspecialchars(Horde_Util::realPath($dir . '/' . $filename), ENT_QUOTES, $this->_charset) . '</a>'; } else { if (!empty($dir) && $dir != '.') { $filename = $dir . '/' . $filename; } $filename = htmlspecialchars($filename, ENT_QUOTES, $this->_charset); } $html .= '<li>' . $filename . "</li>\n"; } $html .= '</ol>'; } } return $html; }
/** * Generate the display path (the path with any root information stripped * out). * * @param string $path The path to display. * * @return string The display path. */ public static function getDisplayPath($path) { $path = Horde_Util::realPath($path); if (self::$backend['root'] != '/' && strpos($path, self::$backend['root']) === 0) { $path = substr($path, Horde_String::length(self::$backend['root'])); } return $path; }
/** * Creates default configuration files for all installed applications. * * @throws Horde_Exception */ public function writeAllConfigs() { foreach ($GLOBALS['registry']->listAllApps() as $app) { if ($app == 'horde' || !file_exists($GLOBALS['registry']->get('fileroot', $app) . '/config/conf.xml')) { continue; } $config = new Horde_Config($app); $configFile = $config->configFile(); if (!$config->writePHPConfig(new Horde_Variables())) { throw new Horde_Exception('Cannot write configuration file ' . Horde_Util::realPath($configFile)); } } }
/** * Authenticate to the backend. * * @param array $credentials An array of login credentials. If empty, * attempts to login to the cached session. * <pre> * 'password' - (string) The user password. * 'backend' - (string) The backend key to use (from backends.php). * 'userId' - (string) The username. * </pre> * * @return mixed If authentication was successful, and no session * exists, an array of data to add to the session. * Otherwise returns false. * @throws Horde_Auth_Exception */ public static function authenticate($credentials = array()) { $result = false; // Do 'horde' authentication. $gollem_app = $GLOBALS['registry']->getApiInstance('gollem', 'application'); if (!empty($gollem_app->initParams['authentication']) && $gollem_app->initParams['authentication'] == 'horde') { if ($registry->getAuth()) { return $result; } throw new Horde_Auth_Exception('', Horde_Auth::REASON_FAILED); } // Load backend. if (!isset($credentials['backend_key'])) { $credentials['backend_key'] = self::getPreferredBackend(); } $backend = self::getBackend($credentials['backend_key']); // Check for hordeauth. if ((!isset($credentials['userId']) || !isset($credentials['password'])) && !$GLOBALS['session']->exists('gollem', 'backend_key') && self::canAutoLogin($credentials['backend_key'])) { if (!empty($backend['hordeauth'])) { $credentials['userId'] = self::getAutologinID($credentials['backend_key']); $credentials['password'] = $GLOBALS['registry']->getAuthCredential('password'); } } // Check for hardcoded backend credentials. if (!isset($credentials['userId']) && !empty($backend['params']['username'])) { $credentials['userId'] = $backend['params']['username']; } if (!isset($credentials['password']) && !empty($backend['params']['password'])) { $credentials['password'] = $backend['params']['password']; } if (!isset($credentials['userId']) || !isset($credentials['password'])) { throw new Horde_Auth_Exception('', Horde_Auth::REASON_BADLOGIN); } try { $vfs = $GLOBALS['injector']->getInstance('Gollem_Factory_Vfs')->create($credentials['backend_key']); $params = array('username' => $credentials['userId'], 'password' => $credentials['password']); foreach (array_keys($backend['loginparams']) as $param) { if (isset($credentials[$param])) { $backend['params'][$param] = $params[$param] = $credentials[$param]; } } $vfs->setParams($params); $vfs->checkCredentials(); } catch (Horde_Exception $e) { throw new Horde_Auth_Exception($e->getMessage(), Horde_Auth::REASON_MESSAGE); } // Set current backend. Gollem::$backend =& $backend; // Mark backend as authenticated. $backend['auth'] = true; // Save username in backend configuration. if (!isset($backend['params']['username'])) { $backend['params']['username'] = $credentials['userId']; } if (!isset($backend['params']['password'])) { $backend['params']['password'] = $credentials['password']; } // Make sure we have a 'root' parameter. if (empty($backend['root'])) { $backend['root'] = '/'; } $backend['root'] = Horde_Util::realPath($backend['root']); // Make sure we have a 'home' parameter. if (empty($backend['home'])) { $backend['home'] = empty($backend['params']['home']) ? $vfs->getCurrentDirectory() : $backend['params']['home']; if (empty($backend['home'])) { $backend['home'] = $backend['root']; } } // Make sure the home parameter lives under root if it is a relative // directory. if (strpos($backend['home'], '/') !== 0) { $backend['home'] = $backend['root'] . '/' . $backend['home']; } $backend['home'] = Horde_Util::realPath($backend['home']); $backend['dir'] = $backend['home']; // Verify that home is below root. if (!Gollem::verifyDir($backend['home'])) { throw new Horde_Auth_Exception('Backend Configuration Error: Home directory not below root.', Horde_Auth::REASON_MESSAGE); } // Create the home directory if it doesn't already exist. if ($backend['home'] != '/' && !empty($backend['createhome'])) { $pos = strrpos($backend['home'], '/'); $cr_dir = substr($backend['home'], 0, $pos); $cr_file = substr($backend['home'], $pos + 1); if (!$vfs->exists($cr_dir, $cr_file)) { try { $res = Gollem::createFolder($cr_dir, $cr_file, $vfs); } catch (Gollem_Exception $e) { throw new Horde_Auth_Exception('Backend Configuration Error: Could not create home directory ' . $backend['home'] . ': ' . $e->getMessage(), Horde_Auth::REASON_MESSAGE); } } } // Write the backend to the session. $backends = self::_getBackends(); $backends[$credentials['backend_key']] = $backend; self::_setBackends($backends); return array('backend_key' => $credentials['backend_key']); }
protected function _renderVarInput_selectFiles($form, &$var, &$vars) { /* Needed for gollem js calls */ $html = sprintf('<input type="hidden" name="%s" id="%s" value="%s" />', 'selectlist_selectid', 'selectlist_selectid', $var->type->getProperty('selectid')) . sprintf('<input type="hidden" name="%s" id="%s" />', 'actionID', 'actionID') . sprintf('<input type="hidden" name="%s" id="%s" value="%s" />', htmlspecialchars($var->getVarName()), $this->_genID($var->getVarName(), false), $var->type->getProperty('selectid')); /* Open window link. */ $param = array($var->type->getProperty('link_text'), $var->type->getProperty('link_style'), $form->getName(), $var->type->getProperty('icon'), $var->type->getProperty('selectid')); $html .= $GLOBALS['registry']->call('files/selectlistLink', $param) . "<br />\n"; if ($var->type->getProperty('selectid')) { $param = array($var->type->getProperty('selectid')); $files = $GLOBALS['registry']->call('files/selectlistResults', $param); if ($files) { $html .= '<ol>'; foreach ($files as $id => $file) { $dir = key($file); $filename = current($file); if ($GLOBALS['registry']->hasMethod('files/getViewLink')) { $filename = basename($filename); $url = $GLOBALS['registry']->call('files/getViewLink', array($dir, $filename)); $filename = Horde::link($url, Horde_Core_Translation::t("Preview"), null, 'form_file_view') . htmlspecialchars(Horde_Util::realPath($dir . '/' . $filename)) . '</a>'; } else { if (!empty($dir) && $dir != '.') { $filename = $dir . '/' . $filename; } $filename = htmlspecialchars($filename); } $html .= '<li>' . $filename . "</li>\n"; } $html .= '</ol>'; } } return $html; }