[ Index ]
 

Code source de Horde 3.1.3

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

title

Body

[fermer]

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

   1  <?php
   2  /**
   3   * Generates upgrade scripts for Horde's setup. Currently allows the generation
   4   * of PHP upgrade scripts for conf.php files either as download or saved to the
   5   * server's temporary directory.
   6   *
   7   * $Horde: horde/admin/setup/scripts.php,v 1.9.10.6 2006/06/16 08:24:27 jan Exp $
   8   *
   9   * Copyright 1999-2006 Charles J. Hagenbuch <chuck@horde.org>
  10   * Copyright 1999-2006 Jon Parise <jon@horde.org>
  11   *
  12   * See the enclosed file COPYING for license information (LGPL).  If you
  13   * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
  14   */
  15  
  16  define('HORDE_BASE', dirname(__FILE__) . '/../..');
  17  require_once  HORDE_BASE . '/lib/base.php';
  18  
  19  if (!Auth::isAdmin()) {
  20      Horde::fatal('Forbidden.', __FILE__, __LINE__);
  21  }
  22  
  23  /* Get form data. */
  24  $setup = Util::getFormData('setup');
  25  $type = Util::getFormData('type');
  26  $save = Util::getFormData('save');
  27  $clean = Util::getFormData('clean');
  28  
  29  $filename = 'horde_setup_upgrade.php';
  30  
  31  /* Check if this is only a request to clean up. */
  32  if ($clean == 'tmp') {
  33      $tmp_dir = Horde::getTempDir();
  34      $path = Util::realPath($tmp_dir . '/' . $filename);
  35      if (unlink($tmp_dir . '/' . $filename)) {
  36          $notification->push(sprintf(_("Deleted setup upgrade script \"%s\"."), $path), 'horde.success');
  37      } else {
  38          $notification->push(sprintf(_("Could not delete setup upgrade script \"%s\"."), Util::realPath($path)), 'horde.error');
  39      }
  40      $registry->clearCache();
  41      $url = Horde::applicationUrl('admin/setup/index.php', true);
  42      header('Location: ' . $url);
  43      exit;
  44  }
  45  
  46  $data = '';
  47  if ($setup == 'conf' && $type == 'php') {
  48      /* A bit ugly here, save PHP code into a string for creating the script
  49       * to be run at the command prompt. */
  50      $data = '#!/usr/bin/php' . "\n";
  51      $data .= '<?php' . "\n";
  52      foreach ($_SESSION['_config'] as $app => $php) {
  53          $path = $registry->get('fileroot', $app) . '/config';
  54          /* Add code to save backup. */
  55          $data .= 'if (file_exists(\'' . $path . '/conf.php\')) {' . "\n";
  56          $data .= '    if (@copy(\'' . $path . '/conf.php\', \'' . $path . '/conf.php.bak\')) {' . "\n";
  57          $data .= '        echo \'' . _("Successfully saved backup configuration.") . '\' . "\n";' . "\n";
  58          $data .= '    } else {' . "\n";
  59          $data .= '        echo \'' . _("Could not save a backup configuation.") . '\' . "\n";' . "\n";
  60          $data .= '    }' . "\n";
  61          $data .= '}' . "\n";
  62  
  63          $data .= 'if ($fp = @fopen(\'' . $path . '/conf.php\', \'w\')) {' . "\n";
  64          $data .= '    fwrite($fp, \'';
  65          $data .= String::convertCharset(str_replace(array('\\', '\''),
  66                                                      array('\\\\', '\\\''),
  67                                                      $php),
  68                                          NLS::getCharset(), 'iso-8859-1');
  69          $data .= '\');' . "\n";
  70          $data .= '    fclose($fp);' . "\n";
  71          $data .= '    echo \'' . sprintf(_("Saved %s configuration."), $app) . '\' . "\n";' . "\n";
  72          $data .= '} else {' . "\n";
  73          $data .= '    echo \'' . sprintf(_("Could not save %s configuration."), $app) . '\' . "\n";' . "\n";
  74          $data .= '}' . "\n\n";
  75      }
  76  }
  77  
  78  if ($save == 'tmp') {
  79      $tmp_dir = Horde::getTempDir();
  80      /* Add self-destruct code. */
  81      $data .= 'echo \'Self-destructing...\' . "\n";' . "\n";
  82      $data .= 'if (unlink(__FILE__)) {' . "\n";
  83      $data .= '    echo \'' . _("Upgrade script deleted.") . '\' . "\n";' . "\n";
  84      $data .= '} else {' . "\n";
  85      $data .= '    echo \'' . sprintf(_("WARNING!!! REMOVE SCRIPT MANUALLY FROM %s."), $tmp_dir) . '\' . "\n";' . "\n";
  86      $data .= '}' . "\n";
  87      /* The script should be saved to server's temporary directory. */
  88      $path = Util::realPath($tmp_dir . '/' . $filename);
  89      if ($fp = @fopen($tmp_dir . '/' . $filename, 'w')) {;
  90          fwrite($fp, $data);
  91          fclose($fp);
  92          chmod($tmp_dir . '/' . $filename, 0777);
  93          $notification->push(sprintf(_("Saved setup upgrade script to: \"%s\"."), $path), 'horde.success');
  94      } else {
  95          $notification->push(sprintf(_("Could not save setup upgrade script to: \"%s\"."), $path), 'horde.error');
  96      }
  97      $url = Horde::applicationUrl('admin/setup/index.php', true);
  98      header('Location: ' . $url);
  99      exit;
 100  } else {
 101      /* Output script to browser for download. */
 102      $browser->downloadHeaders($filename, 'text/plain', false, strlen($data));
 103      echo $data;
 104  }


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