--- docman.php 2002/07/27 19:27:22 1.6 +++ docman.php 2002/07/27 22:26:30 1.12 @@ -118,7 +118,7 @@ if (file_exists("$fsDocumentRoot/docman.css")) { $css=dirname($self)."/docman.css"; } else { - $css=$self."?STYLE=get&css=$css"; + $css=$self."?STYLE=get"; } include("$html/head.html"); @@ -571,7 +571,8 @@ function Navigate($fsRoot,$relDir) { global $gblEditable, $gblIcon, $gblModDays, $webRoot, $gblHide, - $gblIgnoreUnknownFileType, + $gblIgnoreUnknownFileType, $gblRepositoryDir, + $fsRealmDir, $realm, $realm_sep, $HTTP_GET_VARS, $html, $realm_config; $self = $HTTP_SERVER_VARS["PHP_SELF"] ; @@ -859,12 +860,18 @@
"; + include("$fsRealmDir/$realm".$realm_sep."info.inc"); + print "
"; +} elseif (file_exists("$gblRepositoryDir/.info.inc")) { print ""; - include(".info.inc"); - print " -
"; + include("$gblRepositoryDir/.info.inc"); + print "
"; } + + ?>
@@ -903,11 +910,11 @@ // Error with sysadmin flag are reported to error_log or hidden from // users -function Error($title,$text="",$sysadmin=0) { +function Error($title,$text="",$sysadmin=0,$no_404=0) { global $gblSeparateAdminMessages, $gblMailAdminMessages,$realm, $HTTP_SERVER_VARS; - if (! headers_sent()) header("HTTP/1.0 404 Not Found"); + if (! headers_sent() && ! $no_404) header("HTTP/1.0 404 Not Found"); if ($sysadmin) { if ($gblSeparateAdminMessages) { $user="Your administrator "; @@ -1076,13 +1083,15 @@ function try_rename($from,$to) { # print "$from -> $to\n"; if (file_exists($from) && is_writeable(dirname($to))) { - rename($from,$to); + return rename($from,$to); + } else { + return 0; } } function try_dir($todir) { if (! file_exists($todir)) { - mkdir($todir,0700); + @mkdir($todir,0700); } } @@ -1092,7 +1101,7 @@ # print "
$fromdir / $fromfile -> $todir / $tofile\n\n";
 
-	try_rename("$fromdir/$fromfile","$todir/$tofile");
+	if (! try_rename("$fromdir/$fromfile","$todir/$tofile")) Error("Rename error","Can't rename file $fromfile to $tofile",1);
 	try_dir("$todir/.log");
 	try_rename("$fromdir/.log/$fromfile","$todir/.log/$tofile");
 	try_dir("$todir/.note");
@@ -1472,6 +1481,7 @@
 	$gblFilePerms = 0640 ;         // default for new files
 	$gblDirPerms  = 0750 ;		// default for new dirs
 
+	$STYLE = $HTTP_GET_VARS[STYLE];
 	if (isset($STYLE) && $STYLE == "get") {
 		include("$html/docman.css");
 		exit;
@@ -1490,7 +1500,16 @@
 	if (! isset($fsRealmDir)) {
 		$fsRealmDir = "$gblIncDir/realm";
 	}
-	$realm_config = "$fsRealmDir/$realm.conf";
+
+	// try to add dir to script name to realm var
+	if (is_dir("$fsRealmDir/$realm/".dirname($HTTP_SERVER_VARS[SCRIPT_NAME]))) {
+		$realm .= "/".dirname($HTTP_SERVER_VARS[SCRIPT_NAME]);
+		$realm_sep = "/";
+	} else {
+		$realm_sep = ".";
+	}
+
+	$realm_config = $fsRealmDir."/".$realm.$realm_sep."conf";
 
 	// read user-defined configuration
 	if (file_exists($realm_config)) {
@@ -1526,7 +1545,7 @@
 	if (!is_dir($gblRepositoryDir)) Error("Repository dir not found","Can't find repository directory $gblRepositoryDir. Please fix that in $realm_config variable \$gblRepositoryDir.",1);
 
 	// trustee (ACL) file configuration
-	$trustee_conf="$gblIncDir/realm/$realm.trustee";
+	$trustee_conf="$fsRealmDir/$realm".$realm_sep."trustee";
 	// compiled version of trustee file
 	$trustee_php="$gblRepositoryDir/.trustee.php";
 	// get ACL informations
@@ -1547,7 +1566,7 @@
 		isset($relogin) && $secHash == $relogin) {
 		header("WWW-authenticate: basic realm=\"$realm\"") ;
 		header("HTTP/1.0 401 Unauthorized") ;
-		Error("401 Unauthorized","No trespassing !");
+		Error("401 Unauthorized","No trespassing !",0,1);
 	}
 
 	// read mime.types
@@ -1606,18 +1625,19 @@
 	switch ($HTTP_POST_VARS["POSTACTION"]) {
 	case "UPLOAD" :
 		$FN_name=stripSlashes($HTTP_POST_FILES["FN"]["tmp_name"]);
+		$FN=stripSlashes($HTTP_POST_FILES["FN"]["name"]);
 		if (!is_writeable($fsDir)) Error("Write denied",$relDir) ;
-		if (strstr($FN_name,"/")) 
-			Error("Non-conforming filename") ;
-		// TODO : should rather check for escapeshellcmds
-		// but maybe RFC 18xx asserts safe filenames ....
+
 		$source = $FN_name ;
 		if (! file_exists($source)) {
 			Error("You must select file with browse to upload it!");
 		}
+
 		$FILENAME = $HTTP_POST_VARS["FILENAME"];
+		if (strstr($FILENAME,"/")) 
+			Error("Upload error","Non-conforming filename. Filename $FILENAME has slashes (/) in it.") ;
 		if (! isset($FILENAME)) { 	// from update file
-			$target = "$fsDir/$FN_name" ;
+			$target = "$fsDir/".basename($FN);
 		} else {
 			$target = "$fsDir/$FILENAME";
 		}
@@ -1750,11 +1770,13 @@
 	case "RENAME" :  
 		if ( $CONFIRM != "on" ) break ;
 
+		$NEWNAME=stripSlashes($HTTP_POST_VARS["NEWNAME"]);
 		LogIt("$fsDir/$FN","renamed $FN to $NEWNAME",trperm_r);
 		safe_rename($fsDir,$FN,$NEWNAME);
 		break ;
 
 	case "NOTE" :  
+		$NOTE=stripSlashes($HTTP_POST_VARS["NOTE"]);
 		WriteNote("$fsDir/$FN","$NOTE");
 		break ;