commit 46b70df8301ecefd030a3bfdd200cbf1341e4f73
parent bb9b30c3a266146259b340242bced5bc034cf41b
Author: Jan Dankert <develop@jandankert.de>
Date: Mon, 15 Apr 2019 22:55:54 +0200
WebDAV: Errorhandling with exceptions.
Diffstat:
5 files changed, 47 insertions(+), 19 deletions(-)
diff --git a/dav/Client.class.php b/dav/Client.class.php
@@ -160,7 +160,6 @@ class Client
if ( $result === false )
{
error_log('Not unserializable: '.$body);
- httpStatus('500 Server Error, not unserializable: '.$body);
throw new RuntimeException('The server response cannot be unserialized into a PHP array');
}
else
diff --git a/dav/README.md b/dav/README.md
@@ -0,0 +1,14 @@
+
+WebDAV für OpenRat Content Management System
+===
+
+**The virtual CMS file system is accessable via a DAV client**
+
+WebDAV is specified in [RFC 2518](http://www.ietf.org/rfc/rfc2518.txt).
+
+Implemented is DAV level 1 (without Locks).
+
+Following impliciments:
+- Login only with username/password
+- Only 1 database
+- DAV-client must support cookies (the most clients should)+
\ No newline at end of file
diff --git a/dav/WebDAV.class.php b/dav/WebDAV.class.php
@@ -29,6 +29,8 @@ class WebDAV
var $maxFileSize;
var $webdav_conf;
var $overwrite = false;
+
+ private $httpMethod;
/**
@@ -37,7 +39,9 @@ class WebDAV
*/
function __construct()
{
- global $config;
+ global $config;
+
+ $this->httpMethod = strtoupper($_SERVER['REQUEST_METHOD']);
Logger::trace( 'WEBDAV request' );
@@ -95,8 +99,7 @@ class WebDAV
else
{
// Login
- global $httpMethod;
- if ( $httpMethod != 'OPTIONS' ) // Bei OPTIONS kein Login anfordern
+ if ( $this->httpMethod != 'OPTIONS' ) // Bei OPTIONS kein Login anfordern
{
if ( isset($_SERVER['PHP_AUTH_USER']) )
{
@@ -180,7 +183,7 @@ class WebDAV
$_GET['subaction'] == 'get' &&
substr($_SERVER['REQUEST_URI'],strlen($_SERVER['REQUEST_URI'])-1 ) != '/' )
{
- Logger::debug( 'WebDAV: Redirecting lame client to slashyfied URL' );
+ Logger::debug( 'Redirecting lame client to slashyfied URL' );
header('HTTP/1.1 302 Moved Temporarily');
header('Location: '.$_SERVER['REQUEST_URI'].'/');
@@ -1037,7 +1040,9 @@ class WebDAV
if ( $projectid === FALSE )
{
- httpStatus("404 Not found");
+ $this->httpStatus("404 Project not found");
+ echo 'project not found';
+ exit;
}
$project = $this->client->project($projectid);
diff --git a/dav/dav.ini b/dav/dav.ini
@@ -1,12 +1,15 @@
+; you may copy this file dav.ini to a custom file dav.custom.ini or dav.<hostname>.ini
+;
+; beware of publishing this file via the webserver because it may contain secret information!
+
dav.enable=true
dav.create=true
dav.readonly = true
+dav.anonymous = false
log.file=dav.log
log.level=trace
-dav.anonymous = false
-
cms.username=dav
cms.password=davdav
cms.database=pdo_my_prod
diff --git a/dav/dav.php b/dav/dav.php
@@ -29,9 +29,9 @@
if (!defined('E_STRICT'))
define('E_STRICT', 2048);
-define('TIME_20000101',946681200);
-
+define('TIME_20000101',946681200); // default time for objects without time information.
+// Default-Configuration.
$config = array('dav.enable' => false,
'dav.create' => true,
'dav.readonly' => false,
@@ -50,6 +50,7 @@ $config = array('dav.enable' => false,
'log.file' => null
);
+// Configuration-Loader
foreach( array( 'dav-'.$_SERVER['HTTP_HOST'].'.ini',
'dav-custom.ini',
'dav.ini') as $iniFile )
@@ -73,13 +74,23 @@ else
set_error_handler('webdavErrorHandler');
-$dav = new WebDAV();
+try {
-$httpMethod = strtoupper($_SERVER['REQUEST_METHOD']);
-$davMethodName = 'dav'.$httpMethod;
+ $dav = new WebDAV();
-$dav->$davMethodName();
+ $httpMethod = strtoupper($_SERVER['REQUEST_METHOD']);
+ $davMethodName = 'dav' . $httpMethod;
+ $dav->$davMethodName();
+}
+catch( Exception $e )
+{
+ error_log('WEBDAV ERROR: '.$e->getMessage()."\n".$e->getTraceAsString() );
+
+ // Wir teilen dem Client mit, dass auf dem Server was schief gelaufen ist.
+ header('HTTP/1.1 503 Internal WebDAV Server Error');
+ echo 'WebDAV-Request failed'."\n".$e->getTraceAsString();
+}
/**
* Fehler-Handler fuer WEBDAV.<br>
@@ -99,7 +110,3 @@ function webdavErrorHandler($errno, $errstr, $errfile, $errline)
echo 'WebDAV-Request failed with "'.$errstr.'"';
exit;
}
-
-
-
-?>-
\ No newline at end of file