[ Index ]
 

Code source de eZ Publish 3.9.0

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

title

Body

[fermer]

/ -> webdav.php (source)

   1  <?php
   2  //
   3  // This is the index_webdav.php file. Manages WebDAV sessions.
   4  //
   5  // Created on: <15-Aug-2003 15:15:15 bh>
   6  //
   7  // SOFTWARE NAME: eZ publish
   8  // SOFTWARE RELEASE: 3.9.0
   9  // BUILD VERSION: 17785
  10  // COPYRIGHT NOTICE: Copyright (C) 1999-2006 eZ systems AS
  11  // SOFTWARE LICENSE: GNU General Public License v2.0
  12  // NOTICE: >
  13  //   This program is free software; you can redistribute it and/or
  14  //   modify it under the terms of version 2.0  of the GNU General
  15  //   Public License as published by the Free Software Foundation.
  16  //
  17  //   This program is distributed in the hope that it will be useful,
  18  //   but WITHOUT ANY WARRANTY; without even the implied warranty of
  19  //   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  20  //   GNU General Public License for more details.
  21  //
  22  //   You should have received a copy of version 2.0 of the GNU General
  23  //   Public License along with this program; if not, write to the Free
  24  //   Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
  25  //   MA 02110-1301, USA.
  26  //
  27  
  28  //
  29  ignore_user_abort( true );
  30  ob_start();
  31  
  32  error_reporting ( E_ALL );
  33  
  34  // Turn off session stuff, isn't needed for WebDAV operations.
  35  $GLOBALS['eZSiteBasics']['session-required'] = false;
  36  
  37  include_once ( "lib/ezutils/classes/ezdebug.php" );
  38  include_once ( "lib/ezutils/classes/ezsys.php" );
  39  include_once ( "lib/ezutils/classes/ezini.php" );
  40  
  41  /*! Reads settings from site.ini and passes them to eZDebug.
  42   */
  43  function eZUpdateDebugSettings()
  44  {
  45      $ini =& eZINI::instance();
  46      $debugSettings = array();
  47      $debugSettings['debug-enabled'] = $ini->variable( 'DebugSettings', 'DebugOutput' ) == 'enabled';
  48      $debugSettings['debug-by-ip']   = $ini->variable( 'DebugSettings', 'DebugByIP' )   == 'enabled';
  49      $debugSettings['debug-ip-list'] = $ini->variable( 'DebugSettings', 'DebugIPList' );
  50      eZDebug::updateSettings( $debugSettings );
  51  }
  52  
  53  /*!
  54   Reads settings from i18n.ini and passes them to eZTextCodec.
  55  */
  56  function eZUpdateTextCodecSettings()
  57  {
  58      $ini =& eZINI::instance( 'i18n.ini' );
  59  
  60      list( $i18nSettings['internal-charset'], $i18nSettings['http-charset'], $i18nSettings['mbstring-extension'] ) =
  61          $ini->variableMulti( 'CharacterSettings', array( 'Charset', 'HTTPCharset', 'MBStringExtension' ), array( false, false, 'enabled' ) );
  62  
  63      include_once ( 'lib/ezi18n/classes/eztextcodec.php' );
  64      eZTextCodec::updateSettings( $i18nSettings );
  65  }
  66  
  67  // Initialize text codec settings
  68  eZUpdateTextCodecSettings();
  69  
  70  // Check for extension
  71  include_once ( 'lib/ezutils/classes/ezextension.php' );
  72  include_once ( 'kernel/common/ezincludefunctions.php' );
  73  eZExtension::activateExtensions( 'default' );
  74  // Extension check end
  75  
  76  // Make sure site.ini and template.ini reloads its cache incase
  77  // extensions override it
  78  $ini =& eZINI::instance( 'site.ini' );
  79  $ini->loadCache();
  80  $tplINI =& eZINI::instance( 'template.ini' );
  81  $tplINI->loadCache();
  82  
  83  // Grab the main WebDAV setting (enable/disable) from the WebDAV ini file.
  84  $webDavIni =& eZINI::instance( 'webdav.ini' );
  85  $enable = $webDavIni->variable( 'GeneralSettings', 'EnableWebDAV' );
  86  
  87  function eZDBCleanup()
  88  {
  89      if ( class_exists( 'ezdb' )
  90           and eZDB::hasInstance() )
  91      {
  92          $db =& eZDB::instance();
  93          $db->setIsSQLOutputEnabled( false );
  94      }
  95  }
  96  
  97  function eZFatalError()
  98  {
  99      eZDebug::setHandleType( EZ_HANDLE_NONE );
 100      if ( !class_exists( 'eZWebDAVServer' ) )
 101      {
 102          include_once ( "lib/ezwebdav/classes/ezwebdavserver.php" );
 103      }
 104      eZWebDAVServer::appendLogEntry( "****************************************" );
 105      eZWebDAVServer::appendLogEntry( "Fatal error: eZ publish did not finish its request" );
 106      eZWebDAVServer::appendLogEntry( "The execution of eZ publish was abruptly ended, the debug output is present below." );
 107      eZWebDAVServer::appendLogEntry( "****************************************" );
 108  //     $templateResult = null;
 109  //            eZDisplayResult( $templateResult, eZDisplayDebug() );
 110  }
 111  
 112  // Check and proceed only if WebDAV functionality is enabled:
 113  if ( $enable === 'true' )
 114  {
 115      include_once ( 'lib/ezutils/classes/ezexecution.php' );
 116      eZExecution::addCleanupHandler( 'eZDBCleanup' );
 117      eZExecution::addFatalErrorHandler( 'eZFatalError' );
 118      eZDebug::setHandleType( EZ_HANDLE_TO_PHP );
 119  
 120      if ( !isset( $_SERVER['REQUEST_URI'] ) or
 121           !isset( $_SERVER['REQUEST_METHOD'] ) )
 122      {
 123          // We stop the script if these are missing
 124          // e.g. if run from the shell
 125          eZExecution::cleanExit();
 126      }
 127      include_once ( "lib/ezutils/classes/ezmodule.php" );
 128      include_once ( 'lib/ezutils/classes/ezexecution.php' );
 129      include_once ( "lib/ezutils/classes/ezsession.php" );
 130      include_once ( "access.php" );
 131      include_once ( "kernel/common/i18n.php" );
 132      include_once ( "kernel/classes/webdav/ezwebdavcontentserver.php" );
 133  
 134      eZModule::setGlobalPathList( array( "kernel" ) );
 135      eZWebDAVServer::appendLogEntry( "========================================" );
 136      eZWebDAVServer::appendLogEntry( "Requested URI is: " . $_SERVER['REQUEST_URI'], 'webdav.php' );
 137  
 138      // Initialize/set the index file.
 139      eZSys::init( 'webdav.php' );
 140  
 141      // The top/root folder is publicly available (without auth):
 142      if ( $_SERVER['REQUEST_URI'] == ''  or
 143           $_SERVER['REQUEST_URI'] == '/' or
 144           $_SERVER['REQUEST_URI'] == '/webdav.php/' or
 145           $_SERVER['REQUEST_URI'] == '/webdav.php' )
 146      {
 147          $testServer = new eZWebDAVContentServer();
 148          $testServer->processClientRequest();
 149      }
 150      // Else: need to login with username/password:
 151      else
 152      {
 153          // Create & initialize a new instance of the content server.
 154          $server = new eZWebDAVContentServer();
 155  
 156          // Get the name of the site that is being browsed.
 157          $currentSite = $server->currentSiteFromPath( $_SERVER['REQUEST_URI'] );
 158  
 159          // Proceed only if the current site is valid:
 160          if ( $currentSite )
 161          {
 162              $server->setCurrentSite( $currentSite );
 163  
 164              $loginUsername = "";
 165              // Get the username and the password.
 166              if ( isset( $_SERVER['PHP_AUTH_USER'] ) )
 167                  $loginUsername = $_SERVER['PHP_AUTH_USER'];
 168              if ( isset( $_SERVER['PHP_AUTH_PW'] ) )
 169                  $loginPassword = $_SERVER['PHP_AUTH_PW'];
 170  
 171              // Strip away "domainname\" from a possible "domainname\password" string.
 172              if ( preg_match( "#(.*)\\\\(.*)$#", $loginUsername, $matches ) )
 173              {
 174                  $loginUsername = $matches[2];
 175              }
 176  
 177              $user = false;
 178              if ( isset( $loginUsername ) && isset( $loginPassword ) )
 179              {
 180                  include_once ( 'kernel/classes/datatypes/ezuser/ezuserloginhandler.php' );
 181  
 182                  if ( $ini->hasVariable( 'UserSettings', 'LoginHandler' ) )
 183                  {
 184                      $loginHandlers = $ini->variable( 'UserSettings', 'LoginHandler' );
 185                  }
 186                  else
 187                  {
 188                      $loginHandlers = array( 'standard' );
 189                  }
 190  
 191                  foreach ( array_keys ( $loginHandlers ) as $key )
 192                  {
 193                      $loginHandler = $loginHandlers[$key];
 194                      $userClass =& eZUserLoginHandler::instance( $loginHandler );
 195                      $user = $userClass->loginUser( $loginUsername, $loginPassword );
 196                      if ( get_class( $user ) == 'ezuser' )
 197                          break;
 198                  }
 199              }
 200  
 201              // Check if username & password contain someting, attempt to login.
 202              if ( get_class( $user ) != 'ezuser' )
 203              {
 204                  header( 'HTTP/1.0 401 Unauthorized' );
 205                  header( 'WWW-Authenticate: Basic realm="' . WEBDAV_AUTH_REALM . '"' );
 206  
 207                 // Read XML body and discard it
 208                 file_get_contents( "php://input" );
 209              }
 210              // Else: non-empty & valid values were supplied: login successful!
 211              else
 212              {
 213                  $userName = $user->attribute( 'login' );
 214                  eZWebDAVServer::appendLogEntry( "Logged in: '$userName'", 'webdav.php' );
 215  
 216                  // Process the request.
 217                  $server->processClientRequest();
 218              }
 219          }
 220          // Else: site-name is invalid (was not among available sites).
 221          else
 222          {
 223              header( "HTTP/1.1 404 Not Found" );
 224          }
 225      }
 226  
 227      eZExecution::cleanExit();
 228  }
 229  // Else: WebDAV functionality is disabled, do nothing...
 230  else
 231  {
 232      print ( WEBDAV_DISABLED );
 233  }
 234  
 235  ?>


Généré le : Sat Feb 24 10:30:04 2007 par Balluche grâce à PHPXref 0.7