Commit b6c1523b806d4885f5b723b1054c1371ebe0c220

Authored by Megan Watson
1 parent 94368c95

BBS-298

"Mac OS X Webdav as 3rd Party Client"
Updated. Added functionality to prevent the .DS_Store files and ._filename files from being uploaded when adding a document or folder. Added Goliath as a client. Removed the forward slash from the end of file names.

Committed by: Megan Watson
Reviewed by: Conrad Vermeulen



git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@7450 c91229c3-7414-0410-bfa2-8a42b809f60b
ktwebdav/lib/KTWebDAVServer.inc.php
... ... @@ -167,7 +167,7 @@ class KTWebDAVServer extends HTTP_WebDAV_Server
167 167  
168 168 // Load KTWebDAV config
169 169 if (!$this->initConfig()) {
170   - $this->ktwebdavLog('Could not load configiration.', 'error');
  170 + $this->ktwebdavLog('Could not load configuration.', 'error');
171 171 exit(0);
172 172 }
173 173  
... ... @@ -437,6 +437,22 @@ class KTWebDAVServer extends HTTP_WebDAV_Server
437 437  
438 438 $path = $options["path"];
439 439  
  440 + // Fix for Mac Clients
  441 + // Mac adds DS_Store files when folders are added and ._filename files when files are added
  442 + // The PUT function doesn't add these files to the dms but PROPFIND still looks for the .DS_Store file,
  443 + // and returns an error if not found. We emulate its existence by returning a positive result.
  444 + if($this->dav_client == 'MC' || $this->dav_client == 'MG'){
  445 + // Remove filename from path
  446 + $aPath = explode('/', $path);
  447 + $fileName = $aPath[count($aPath)-1];
  448 +
  449 + if(strtolower($fileName) == '.ds_store'){
  450 + $this->ktwebdavLog("Using a Mac client. Filename is .DS_Store so we emulate a positive result.", 'info', true);
  451 + // ignore
  452 + return true;
  453 + }
  454 + }
  455 +
440 456 list($iFolderID, $iDocumentID) = $this->_folderOrDocument($path);
441 457 $this->ktwebdavLog("Folder/Doc is " . print_r(array($iFolderID, $iDocumentID), true), 'info', true);
442 458  
... ... @@ -664,7 +680,7 @@ class KTWebDAVServer extends HTTP_WebDAV_Server
664 680 } else {
665 681 $options["depth"] = "infinity";
666 682 }
667   -
  683 +
668 684 // analyze request payload
669 685 $propinfo = new _parse_propfind("php://input");
670 686 if (!$propinfo->success) {
... ... @@ -798,8 +814,22 @@ class KTWebDAVServer extends HTTP_WebDAV_Server
798 814  
799 815 echo " <D:response $ns_defs>\n";
800 816  
801   - $href = htmlspecialchars($this->_slashify($this->_mergePathes($_SERVER['SCRIPT_NAME'], $path)));
802   -
  817 + $tempHref = $this->_mergePathes($_SERVER['SCRIPT_NAME'], $path);
  818 +
  819 + // Ensure collections end in a slash
  820 + if(isset($file['props'])){
  821 + foreach($file['props'] as $v){
  822 + if($v['name'] == 'resourcetype'){
  823 + if($v['val'] == 'collection'){
  824 + $tempHref = $this->_slashify($tempHref);
  825 + continue;
  826 + }
  827 + }
  828 + }
  829 + }
  830 +
  831 + $href = htmlspecialchars($tempHref);
  832 +
803 833 echo " <D:href>$href</D:href>\n";
804 834  
805 835 $this->ktwebdavLog("\nfile is: " . print_r($file, true), 'info', true);
... ... @@ -1101,7 +1131,7 @@ class KTWebDAVServer extends HTTP_WebDAV_Server
1101 1131 while (count($aRemaining)) {
1102 1132 $sFolderName = $aRemaining[0];
1103 1133 $aRemaining = array_slice($aRemaining, 1);
1104   - if ($sFolderName == '') {
  1134 + if (empty($sFolderName)) {
1105 1135 continue;
1106 1136 }
1107 1137 // FIXME: Direct database access
... ... @@ -1187,6 +1217,29 @@ class KTWebDAVServer extends HTTP_WebDAV_Server
1187 1217 $this->ktwebdavLog("dav_client is: " . $this->dav_client, 'info', true);
1188 1218  
1189 1219 $path = $options["path"];
  1220 +
  1221 + // Fix for Mac
  1222 + // Mac adds DS_Store files when folders are added and ._filename files when files are added
  1223 + // we want to ignore them.
  1224 + if($this->dav_client == 'MC' || $this->dav_client == 'MG'){
  1225 + // Remove filename from path
  1226 + $aPath = explode('/', $path);
  1227 + $fileName = $aPath[count($aPath)-1];
  1228 +
  1229 + if(strtolower($fileName) == '.ds_store'){
  1230 + $this->ktwebdavLog("Using a mac client. Ignore the .DS_Store files created with every folder.", 'info', true);
  1231 + // ignore
  1232 + return "204 No Content";
  1233 + }
  1234 +
  1235 + if($fileName[0] == '.' && $fileName[1] == '_'){
  1236 + $fileName = substr($fileName, 2);
  1237 + $this->ktwebdavLog("Using a mac client. Ignore the ._filename files created with every file.", 'info', true);
  1238 + // ignore
  1239 + return "204 No Content";
  1240 + }
  1241 + }
  1242 +
1190 1243  
1191 1244 $res = $this->_folderOrDocument($path);
1192 1245 list($iFolderID, $iDocumentID) = $res;
... ... @@ -1623,6 +1676,18 @@ class KTWebDAVServer extends HTTP_WebDAV_Server
1623 1676 function _MOVEDocument($options, $iFolderID, $iDocumentID) {
1624 1677  
1625 1678 if ($options['dest'] == '') $options["dest"] = substr($options["dest_url"], strlen($_SERVER["SCRIPT_NAME"]));
  1679 +
  1680 + // Fix for Mac
  1681 + if($this->dav_client == 'MG'){
  1682 + $this->ktwebdavLog("Remove ktwebdav from destination path: ".$options['dest'], 'info', true);
  1683 + if(!(strpos($options['dest'], 'ktwebdav/ktwebdav.php/') === FALSE)){
  1684 + $options['dest'] = substr($options['dest'], 22);
  1685 + }
  1686 + if($options['dest'][0] != '/'){
  1687 + $options['dest'] = '/'.$options['dest'];
  1688 + }
  1689 + }
  1690 +
1626 1691 $this->ktwebdavLog("Entering _MOVEDocument. options are " . print_r($options, true), 'info', true);
1627 1692 global $default;
1628 1693 $new = true;
... ... @@ -1643,7 +1708,7 @@ class KTWebDAVServer extends HTTP_WebDAV_Server
1643 1708 // return "412 Precondition Failed - This is a Rename. Overwrite needs to be TRUE.";
1644 1709 //}
1645 1710 $this->ktwebdavLog("Got an oDocument of " . print_r($oDocument, true), 'info', true);
1646   - $this->ktwebdavLog("Got an new name of " . basename($dest_path), 'info', true);
  1711 + $this->ktwebdavLog("Got a new name of " . basename($dest_path), 'info', true);
1647 1712  
1648 1713 // Check if the user has permissions to write this document
1649 1714 $oPerm =& KTPermission::getByName('ktcore.permissions.write');
... ... @@ -2194,10 +2259,15 @@ class KTWebDAVServer extends HTTP_WebDAV_Server
2194 2259 $this->ktwebdavLog("WebDAV Client : " . $userAgentValue, 'info', true);
2195 2260 }
2196 2261 // Mac Finder
2197   - if (stristr($userAgentValue,"Macintosh")) {
  2262 + if (stristr($userAgentValue,"Macintosh") || stristr($userAgentValue,"Darwin")) {
2198 2263 $this->dav_client = "MC";
2199 2264 $this->ktwebdavLog("WebDAV Client : " . $userAgentValue, 'info', true);
2200 2265 }
  2266 + // Mac Goliath
  2267 + if (stristr($userAgentValue,"Goliath")) {
  2268 + $this->dav_client = "MG";
  2269 + $this->ktwebdavLog("WebDAV Client : " . $userAgentValue, 'info', true);
  2270 + }
2201 2271 // Konqueror
2202 2272 if (stristr($userAgentValue,"Konqueror")) {
2203 2273 $this->dav_client = "KO";
... ... @@ -2228,6 +2298,20 @@ class KTWebDAVServer extends HTTP_WebDAV_Server
2228 2298 return false;
2229 2299  
2230 2300 }
  2301 + // Mac Goliath
  2302 + if ($this->dav_client == 'MG' && $this->safeMode == 'off') {
  2303 +
  2304 + $this->ktwebdavLog("This is a Mac Goliath type client with SafeMode off.", 'info', true);
  2305 + return true;
  2306 +
  2307 + }
  2308 + // Mac Goliath
  2309 + if ($this->dav_client == 'MG' && $this->safeMode != 'off') {
  2310 +
  2311 + $this->ktwebdavLog("This is a Mac Goliath type client with SafeMode on.", 'info', true);
  2312 + return false;
  2313 +
  2314 + }
2231 2315 // Konqueror
2232 2316 if ($this->dav_client == 'KO' && $this->safeMode == 'off') {
2233 2317  
... ...