--- docman.php 2002/07/27 19:12:42 1.4 +++ docman.php 2002/07/27 22:26:30 1.12 @@ -25,8 +25,8 @@ // from where to include auth_*.php modules? $gblIncDir = "/data/docman2"; - // force download (so it won't open in associated application) - $gblForceDownload = 1; + // force download on view (so it won't open in associated application) + $gblForceDownload = 0; // date format $gblDateFmt="Y-m-d"; @@ -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"); @@ -145,7 +145,6 @@ $url_title="relogin"; } include("$html/footer.html"); - //phpinfo(); } // end function EndHTML ////////////////////////////////////////////////////////////////// @@ -572,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"] ; @@ -860,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 "
"; } + + ?>
@@ -904,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 "; @@ -1077,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); } } @@ -1093,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");
@@ -1473,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;
@@ -1491,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)) {
@@ -1527,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
@@ -1548,8 +1566,7 @@
 		isset($relogin) && $secHash == $relogin) {
 		header("WWW-authenticate: basic realm=\"$realm\"") ;
 		header("HTTP/1.0 401 Unauthorized") ;
-phpinfo();
-		Error("401 Unauthorized","No trespassing !");
+		Error("401 Unauthorized","No trespassing !",0,1);
 	}
 
 	// read mime.types
@@ -1595,6 +1612,7 @@
 	$DIR=stripSlashes($HTTP_POST_VARS["DIR"]);
 	$RELPATH=stripSlashes($HTTP_POST_VARS["RELPATH"]);
 	$T=stripSlashes($HTTP_POST_VARS["T"]);
+	$CONFIRM=stripSlashes($HTTP_POST_VARS["CONFIRM"]);
 
 	// get
 	$A=stripSlashes($HTTP_GET_VARS["A"]);
@@ -1607,20 +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 ;
-		print "-- $source -- $FN_name -- $HTTP_POST_FILES[FN] -- ";
-//		phpinfo();
 		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";
 		}
@@ -1753,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 ;
 
@@ -1810,7 +1829,7 @@
 	case "Co" :
 		// checkout
 		Lock("$gblFsRoot/$relDir/$F");
-		Download("$gblFsRoot/$relDir/$F");
+		Download("$gblFsRoot/$relDir/$F",1);
 		exit;
 	case "Ci" :
 		$F=stripSlashes($F);
@@ -1826,12 +1845,7 @@
 	case "V" :
 		// view
 		LogIt("$gblFsRoot/$relDir/$F","viewed");
-		if ($gblForceDownload) {
-			Download("$gblFsRoot/$relDir/$F");
-		} else {
-			header("Content-Disposition: attachment; filename=$F" );
-			Header("Location: $webRoot".urlpath("$relDir/$F"));
-		}
+		Download("$gblFsRoot/$relDir/$F",$gblForceDownload);
 		exit;
 	case "Ch" :
 		StartHTML("(File changes)","All changes chronologicaly...");