[ Index ]
 

Code source de Horde 3.1.3

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/admin/setup/ -> index.php (source)

   1  <?php
   2  /**
   3   * $Horde: horde/admin/setup/index.php,v 1.28.4.12 2006/03/28 12:31:08 jan Exp $
   4   *
   5   * Copyright 1999-2006 Charles J. Hagenbuch <chuck@horde.org>
   6   * Copyright 1999-2006 Jon Parise <jon@horde.org>
   7   *
   8   * See the enclosed file COPYING for license information (LGPL).  If you
   9   * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
  10   */
  11  
  12  @define('HORDE_BASE', dirname(__FILE__) . '/../..');
  13  require_once  HORDE_BASE . '/lib/base.php';
  14  require_once 'Horde/Template.php';
  15  
  16  if (!Auth::isAdmin()) {
  17      Horde::fatal('Forbidden.', __FILE__, __LINE__);
  18  }
  19  
  20  /**
  21   * Returns the CVS version for a given file.
  22   */
  23  function _getVersion($file)
  24  {
  25      $size = @filesize($file);
  26      if (!$size || !is_resource($fp = @fopen($file, 'r'))) {
  27          return false;
  28      }
  29      $data = @fread($fp, $size);
  30      if (preg_match('/\$.*?conf\.xml,v (.*?) .*\$/', $data, $match)) {
  31          return $match[1];
  32      } else {
  33          return false;
  34      }
  35  }
  36  
  37  /**
  38   * Does an FTP upload to save the configuration.
  39   */
  40  function _uploadFTP($params)
  41  {
  42      global $registry, $notification;
  43  
  44      require_once 'VFS.php';
  45      $params['hostspec'] = 'localhost';
  46      $vfs = &VFS::singleton('ftp', $params);
  47      if (is_a($vfs, 'PEAR_Error')) {
  48          $notification->push(sprintf(_("Could not connect to server \"%s\" using FTP: %s"), $params['hostspec'], $vfs->getMessage()), 'horde.error');
  49          return false;
  50      }
  51  
  52      /* Loop through the config and write to FTP. */
  53      $no_errors = true;
  54      foreach ($_SESSION['_config'] as $app => $config) {
  55          $path = $registry->get('fileroot', $app) . '/config';
  56          /* Try to back up the current conf.php. */
  57          if ($vfs->exists($path, 'conf.php')) {
  58              if (($result = $vfs->rename($path, 'conf.php', $path, '/conf.php.bak')) === true) {
  59                  $notification->push(_("Successfully saved backup configuration."), 'horde.success');
  60              } elseif (is_a($result, 'PEAR_Error')) {
  61                  $notification->push(sprintf(_("Could not save a backup configuation: %s"), $result->getMessage()), 'horde.error');
  62              } else {
  63                  $notification->push(_("Could not save a backup configuation."), 'horde.error');
  64              }
  65          }
  66  
  67          $write = $vfs->writeData($path, 'conf.php', $config);
  68          if (is_a($write, 'PEAR_Error')) {
  69              $no_errors = false;
  70              $notification->push(sprintf(_("Could not write configuration for \"%s\": %s"), $app, $write->getMessage()), 'horde.error');
  71          } else {
  72              $notification->push(sprintf(_("Successfully wrote %s"), Util::realPath($path . '/conf.php')), 'horde.success');
  73              unset($_SESSION['_config'][$app]);
  74          }
  75      }
  76      $registry->clearCache();
  77      return $no_errors;
  78  }
  79  
  80  /* Set up some icons. */
  81  $success = Horde::img('alerts/success.png', '', '', $registry->getImageDir('horde'));
  82  $warning = Horde::img('alerts/warning.png', '', '', $registry->getImageDir('horde'));
  83  $error = Horde::img('alerts/error.png', '', '', $registry->getImageDir('horde'));
  84  
  85  $conf_url = Horde::applicationUrl('admin/setup/config.php');
  86  $a = $registry->listApps(array('inactive', 'hidden', 'notoolbar', 'active', 'admin'));
  87  $apps = array();
  88  $i = -1;
  89  foreach ($a as $app) {
  90      /* Skip app if no conf.xml file. */
  91      $path = $registry->get('fileroot', $app) . '/config';
  92      if (!file_exists($path . '/conf.xml')) {
  93          continue;
  94      }
  95  
  96      $i++;
  97      $path = $registry->get('fileroot', $app) . '/config';
  98  
  99      $conf_link = Util::addParameter($conf_url, 'app', $app);
 100      $conf_link = Horde::link($conf_link, sprintf(_("Configure %s"), $app));
 101      $apps[$i]['sort'] = $registry->get('name', $app) . ' (' . $app . ')';
 102      $apps[$i]['name'] = $conf_link . $apps[$i]['sort'] . '</a>';
 103      $apps[$i]['version'] = '';
 104      if (is_readable($registry->get('fileroot', $app) . '/lib/version.php')) {
 105          require $registry->get('fileroot', $app) . '/lib/version.php';
 106          $version_constant = String::upper($app) . '_VERSION';
 107          if (defined($version_constant)) {
 108              $apps[$i]['version'] = constant($version_constant);
 109          }
 110      }
 111      if (!file_exists($path . '/conf.php')) {
 112          /* No conf.php exists. */
 113          $apps[$i]['conf'] = $conf_link . $error . '</a>';
 114          $apps[$i]['status'] = _("Missing configuration. You have to generate it now if you want to use this application.");
 115      } else {
 116          /* A conf.php exists, get the xml version. */
 117          if (($xml_ver = _getVersion($path . '/conf.xml')) === false) {
 118              $apps[$i]['conf'] = $conf_link . $warning . '</a>';
 119              $apps[$i]['status'] = _("No version found in original configuration. Regenerate configuration.");
 120              continue;
 121          }
 122          /* Get the generated php version. */
 123          if (($php_ver = _getVersion($path . '/conf.php')) === false) {
 124              /* No version found in generated php, suggest regenarating
 125               * just in case. */
 126              $apps[$i]['conf'] = $conf_link . $warning . '</a>';
 127              $apps[$i]['status'] = _("No version found in your configuration. Regenerate configuration.");
 128              continue;
 129          }
 130  
 131          if ($xml_ver != $php_ver) {
 132              /* Versions are not the same, configuration is out of date. */
 133              $apps[$i]['conf'] = $conf_link . $error . '</a>';
 134              $apps[$i]['status'] = _("Configuration is out of date.");
 135              continue;
 136          } else {
 137              /* Configuration is ok. */
 138              $apps[$i]['conf'] = $conf_link . $success . '</a>';
 139              $apps[$i]['status'] = _("Application is ready.");
 140          }
 141      }
 142  }
 143  
 144  /* Sort the apps by name. */
 145  require_once  'Horde/Array.php';
 146  Horde_Array::arraySort($apps, 'sort');
 147  
 148  /* Set up any actions that may be offered. */
 149  $actions = array();
 150  $ftpform = '';
 151  if (!empty($_SESSION['_config'])) {
 152      Horde::addScriptFile('popup.js', 'horde', true);
 153      $url = Horde::applicationUrl('admin/setup/diff.php');
 154      $action = _("Show differences between currently saved and the newly generated configuration.");
 155      $actions[] = array('icon' => Horde::img('search.png', '', 'align="middle"', $registry->getImageDir('horde')),
 156                         'link' => Horde::link('#', '', '', '', 'popup(\'' . $url . '\',640, 480); return false;') . $action . '</a>');
 157  
 158      $url = Horde::applicationUrl('admin/setup/scripts.php');
 159      /* Action to download the configuration upgrade PHP script. */
 160      $url = Util::addParameter($url, array('setup' => 'conf', 'type' => 'php'));
 161      $action = _("Download generated configuration as PHP script.");
 162      $actions[] = array('icon' => Horde::img('download.png', '', 'align="middle"', $registry->getImageDir('horde')),
 163                         'link' => Horde::link($url) . $action . '</a>');
 164      /* Action to save the configuration upgrade PHP script. */
 165      $url = Util::addParameter($url, 'save', 'tmp');
 166      $action = _("Save generated configuration as a PHP script to your server's temporary directory.");
 167      $actions[] = array('icon' => Horde::img('save.png', '', 'align="middle"', $registry->getImageDir('horde')),
 168                         'link' => Horde::link($url) . $action . '</a>');
 169  
 170      /* Set up the form for FTP upload of scripts. */
 171      require_once 'Horde/Form.php';
 172      require_once 'Horde/Variables.php';
 173  
 174      $vars = &Variables::getDefaultVariables();
 175      $ftpform = &Horde_Form::singleton('', $vars);
 176      $ftpform->setTitle(_("FTP upload of setup"));
 177      $ftpform->setButtons(_("Upload"), true);
 178      $ftpform->addVariable(_("Username"), 'username', 'text', true, false, null, array('', 20));
 179      $ftpform->addVariable(_("Password"), 'password', 'password', false);
 180  
 181      if ($ftpform->validate($vars)) {
 182          $ftpform->getInfo($vars, $info);
 183          $upload = _uploadFTP($info);
 184          if ($upload) {
 185              $notification->push(_("Uploaded all application setup files to the server."), 'horde.success');
 186              $url = Horde::applicationUrl('admin/setup/index.php', true);
 187              header('Location: ' . $url);
 188              exit;
 189          }
 190      }
 191      /* Render the form. */
 192      require_once 'Horde/Form/Renderer.php';
 193      $renderer = &new Horde_Form_Renderer();
 194      $ftpform = Util::bufferOutput(array($ftpform, 'renderActive'), $renderer, $vars, 'index.php', 'post');
 195  }
 196  
 197  if (file_exists(Horde::getTempDir() . '/horde_setup_upgrade.php')) {
 198      /* Action to remove the configuration upgrade PHP script. */
 199      $url = Horde::applicationUrl('admin/setup/scripts.php');
 200      $url = Util::addParameter($url, 'clean', 'tmp');
 201      $action = _("Remove saved script from server's temporary directory.");
 202      $actions[] = array('icon' => Horde::img('delete.png', '', 'align="middle"', $registry->getImageDir('horde')),
 203                         'link' => Horde::link($url) . $action . '</a>');
 204  }
 205  
 206  /* Set up the template. */
 207  $template = &new Horde_Template();
 208  $template->set('apps', $apps);
 209  $template->set('actions', $actions, true);
 210  $template->set('ftpform', $ftpform, true);
 211  $template->set('notify', Util::bufferOutput(array($notification, 'notify')));
 212  $template->setOption('gettext', true);
 213  
 214  $title = sprintf(_("%s Setup"), $registry->get('name', 'horde'));
 215  Horde::addScriptFile('stripe.js', 'horde', true);
 216  require  HORDE_TEMPLATES . '/common-header.inc';
 217  require  HORDE_TEMPLATES . '/admin/common-header.inc';
 218  echo $template->fetch(HORDE_TEMPLATES . '/admin/setup/index.html');
 219  require  HORDE_TEMPLATES . '/common-footer.inc';


Généré le : Sun Feb 25 18:01:28 2007 par Balluche grâce à PHPXref 0.7