pwet

Sign in or create your account | Project List | Help | pwet.fr | Planet eZ Publish.fr | Bioutifoul Photos

pwet Svn Source Tree

Root/trunk/www/webdav.php

  • Property svn:executable set to:
1<?php
2/**
3 * @copyright Copyright (C) 1999-2011 eZ Systems AS. All rights reserved.
4 * @license http://www.gnu.org/licenses/gpl-2.0.txt GNU General Public License v2
5 * @version 2011.7
6 * @package kernel
7 */
8
9// Set a default time zone if none is given. The time zone can be overriden
10// in config.php or php.ini.
11if ( !ini_get( "date.timezone" ) )
12{
13    date_default_timezone_set( "UTC" );
14}
15
16require 'autoload.php';
17
18ignore_user_abort( true );
19ob_start();
20
21ini_set( "display_errors" , "0" );
22
23error_reporting ( E_ALL );
24
25// Turn off session stuff, isn't needed for WebDAV operations.
26$GLOBALS['eZSiteBasics']['session-required'] = false;
27
28/*! Reads settings from site.ini and passes them to eZDebug.
29 */
30function eZUpdateDebugSettings()
31{
32    $ini = eZINI::instance();
33    $debugSettings = array();
34    $debugSettings['debug-enabled'] = $ini->variable( 'DebugSettings', 'DebugOutput' ) == 'enabled';
35    $debugSettings['debug-by-ip'] = $ini->variable( 'DebugSettings', 'DebugByIP' ) == 'enabled';
36    $debugSettings['debug-ip-list'] = $ini->variable( 'DebugSettings', 'DebugIPList' );
37    eZDebug::updateSettings( $debugSettings );
38}
39
40/*!
41 Reads settings from i18n.ini and passes them to eZTextCodec.
42*/
43function eZUpdateTextCodecSettings()
44{
45    $ini = eZINI::instance( 'i18n.ini' );
46
47    list( $i18nSettings['internal-charset'], $i18nSettings['http-charset'], $i18nSettings['mbstring-extension'] ) =
48        $ini->variableMulti( 'CharacterSettings', array( 'Charset', 'HTTPCharset', 'MBStringExtension' ), array( false, false, 'enabled' ) );
49
50    eZTextCodec::updateSettings( $i18nSettings );
51}
52
53// Initialize text codec settings
54eZUpdateTextCodecSettings();
55
56// Check for extension
57require_once( 'kernel/common/ezincludefunctions.php' );
58eZExtension::activateExtensions( 'default' );
59// Extension check end
60
61// Now that all extensions are activated and siteaccess has been changed, reset
62// all eZINI instances as they may not take into account siteaccess specific settings.
63eZINI::resetAllInstances( false );
64
65// Grab the main WebDAV setting (enable/disable) from the WebDAV ini file.
66$webDavIni = eZINI::instance( 'webdav.ini' );
67$enable = $webDavIni->variable( 'GeneralSettings', 'EnableWebDAV' );
68
69function eZDBCleanup()
70{
71    if ( class_exists( 'ezdb' )
72         and eZDB::hasInstance() )
73    {
74        $db = eZDB::instance();
75        $db->setIsSQLOutputEnabled( false );
76    }
77}
78
79function eZFatalError()
80{
81    eZDebug::setHandleType( eZDebug::HANDLE_NONE );
82    eZWebDAVContentBackend::appendLogEntry( "****************************************" );
83    eZWebDAVContentBackend::appendLogEntry( "Fatal error: eZ Publish did not finish its request" );
84    eZWebDAVContentBackend::appendLogEntry( "The execution of eZ Publish was abruptly ended, the debug output is present below." );
85    eZWebDAVContentBackend::appendLogEntry( "****************************************" );
86    // $templateResult = null;
87    // eZDisplayResult( $templateResult, eZDisplayDebug() );
88}
89
90// Check and proceed only if WebDAV functionality is enabled:
91if ( $enable === 'true' )
92{
93    eZExecution::addCleanupHandler( 'eZDBCleanup' );
94    eZExecution::addFatalErrorHandler( 'eZFatalError' );
95    eZDebug::setHandleType( eZDebug::HANDLE_FROM_PHP );
96
97    if ( !isset( $_SERVER['REQUEST_URI'] ) or
98         !isset( $_SERVER['REQUEST_METHOD'] ) )
99    {
100        // We stop the script if these are missing
101        // e.g. if run from the shell
102        eZExecution::cleanExit();
103    }
104    include_once( "access.php" );
105
106    eZModule::setGlobalPathList( array( "kernel" ) );
107    eZWebDAVContentBackend::appendLogEntry( "========================================" );
108    eZWebDAVContentBackend::appendLogEntry( "Requested URI is: " . $_SERVER['REQUEST_URI'], 'webdav.php' );
109
110    // Initialize/set the index file.
111    eZSys::init( 'webdav.php', $ini->variable( 'SiteAccessSettings', 'ForceVirtualHost' ) === 'true' );
112
113    // @as 2009-03-04 - added cleaning up of the REQUEST_URI and HTTP_DESTINATION
114    $_SERVER['REQUEST_URI'] = urldecode( $_SERVER['REQUEST_URI'] );
115
116    if ( isset( $_SERVER['HTTP_DESTINATION'] ) )
117    {
118        $_SERVER['HTTP_DESTINATION'] = urldecode( $_SERVER['HTTP_DESTINATION'] );
119    }
120    eZWebDAVContentBackend::appendLogEntry( "Used (cleaned) URI is: " . $_SERVER['REQUEST_URI'], 'webdav.php' );
121
122    // The top/root folder is publicly available (without auth):
123    if ( $_SERVER['REQUEST_URI'] == '' or
124         $_SERVER['REQUEST_URI'] == '/' or
125         $_SERVER['REQUEST_URI'] == '/webdav.php/' or
126         $_SERVER['REQUEST_URI'] == '/webdav.php' )
127    {
128        // $requestUri = $_SERVER['REQUEST_URI'];
129        // if ( $requestUri == '' )
130        // {
131        // $requestUri = '/';
132        // }
133        // if ( $requestUri == '/webdav.php' )
134        // {
135        // $requestUri = '/webdav.php/';
136        // }
137
138        $server = ezcWebdavServer::getInstance();
139
140        $backend = new eZWebDAVContentBackend();
141        $server->handle( $backend );
142    }
143    // Else: need to login with username/password:
144    else
145    {
146        // Create & initialize a new instance of the content server.
147        $server = ezcWebdavServer::getInstance();
148        $server->pluginRegistry->registerPlugin(
149            new ezcWebdavLockPluginConfiguration()
150        );
151        $backend = new eZWebDAVContentBackend();
152        $server->auth = new eZWebDAVContentBackendAuth();
153
154        // Get the name of the site that is being browsed.
155        $currentSite = $backend->currentSiteFromPath( $_SERVER['REQUEST_URI'] );
156
157        // Proceed only if the current site is valid:
158        if ( $currentSite )
159        {
160            $backend->setCurrentSite( $currentSite );
161
162            // Process the request.
163            $server->handle( $backend );
164        }
165        // Else: site-name is invalid (was not among available sites).
166        else
167        {
168            header( "HTTP/1.1 404 Not Found" );
169        }
170    }
171
172    eZExecution::cleanExit();
173}
174// Else: WebDAV functionality is disabled, do nothing...
175else
176{
177    header( "HTTP/1.1 404 Not Found" );
178    print ( "WebDAV functionality is disabled!" );
179}
180
181?>
182

Archive Download this file

Revision: HEAD