--- docman.php 2001/02/15 22:14:21 1.33 +++ docman.php 2001/06/21 08:56:35 1.45 @@ -120,6 +120,12 @@ $gblImages = array( ".jpg",".jpeg",".gif",".png",".ico", ".bmp",".xbm") ; + // which files to hide (separated by ,) + $gblHide = ""; + + // Where are users? (by default in .htusers file) + $gblUsers = "htusers_file"; + ////////////////////////////////////////////////////////////////// function StartHTML($title,$text="") { @@ -236,14 +242,16 @@ $fsize = filesize($fsPath) ; $fmodified = date("$GLOBALS[gblDateFmt] $GLOBALS[gblTimeFmt]", filemtime($fsPath)) ; $faccessed = date("$GLOBALS[gblDateFmt] $GLOBALS[gblTimeFmt]", fileatime($fsPath)) ; - $userinfo = posix_getpwuid(fileowner($fsPath)); - $grpinfo = posix_getgrgid(filegroup($fsPath)); + $fuid=fileowner($fsPath); + $fgid=filegroup($fsPath); + $userinfo = posix_getpwuid($fuid); + $grpinfo = posix_getgrgid($fgid); echo "
";
-		if (!is_dir($fsPath)) echo "file size: " . $fsize . " Bytes
" ; + if (!is_dir($fsPath)) echo " file size: " . $fsize . " Bytes
" ; echo "last modified: " . $fmodified . "
" ; echo "last accessed: " . $faccessed . "
" ; - echo " owner: " . $userinfo["name"] . "
" ; - echo " group: " . $grpinfo["name"] . "
" ; + echo " owner: " . $userinfo["name"] . " [$fuid]
" ; + echo " group: " . $grpinfo["name"] . " [$fgid]
" ; echo " permissions: " ; echo printf( "%o", fileperms($fsPath) ) . "" ; echo "
" ; @@ -628,7 +636,7 @@ function Navigate($fsRoot,$relDir) { - global $gblEditable, $gblIcon, $gblModDays, $webRoot ; + global $gblEditable, $gblIcon, $gblModDays, $webRoot, $gblHide ; $self = $GLOBALS["PHP_SELF"] ; @@ -636,11 +644,13 @@ if (!is_dir($fsDir)) Error("Dir not found",$relDir) ; + $hide_items=",$gblHide,"; + // read directory contents if ( !($dir = @opendir($fsDir)) ) Error("Read Access denied",$relDir) ; while ($item = readdir($dir)) { - if ( $item == ".." || $item == "." || substr($item,0,1) == "." ) continue ; + if ( substr($item,0,1) == "." || strstr($hide_items,",$item,") ) continue ; if ( is_dir($fsDir . $item) ) { $dirList[] = $item ; } else if ( is_file($fsDir . $item) ) { @@ -659,7 +669,7 @@ // scan deleted files if ( $GLOBALS[show_deleted] == 1 && ($dir = @opendir("$fsDir/.del")) ) { while ($item = readdir($dir)) { - if ( substr($item,0,1) == "." ) continue ; + if ( substr($item,0,1) == "." || strstr($hide_items,",$item,") ) continue ; $fileList[] = ".del/$item" ; } closedir($dir) ; @@ -692,12 +702,20 @@ 1) { + $out.="s"; + } + return $out; +} + // output subdirs if (sizeof($dirList) > 0) { sort($dirList) ; ?> -DIRECTORY NAMEDIRECTORY NOTE +DIRECTORY NAME ()DIRECTORY NOTE
-DOCUMENT NAME +DOCUMENT NAME () NOTE LAST UPDATEFILE SIZE @@ -854,7 +872,8 @@ NAME - + + OR UPLOAD A FILE @@ -974,7 +993,7 @@ $msg=fgets($note,4096); fclose($note); } - return StripSlashes($msg); + return HtmlSpecialChars(StripSlashes($msg)); } @@ -1055,12 +1074,40 @@ ////////////////////////////////////////////////////////////////// -function safe_rename($from,$to) { - if (file_exists($from) && is_writable(dirname($to))) { - rename($from,$to); +function safe_rename($fromdir,$fromfile,$tofile) { + function try_rename($from,$to) { +# print "$from -> $to\n"; + if (file_exists($from) && is_writeable(dirname($to))) { + rename($from,$to); + } + } + + function try_dir($todir) { + if (! file_exists($todir)) { + mkdir($todir,0700); + } + } + + $to="$fromdir/$tofile"; + $todir=dirname($to); + $tofile=basename($to); + +# print "
$fromdir / $fromfile -> $todir / $tofile\n\n";
+
+	try_rename("$fromdir/$fromfile","$todir/$tofile");
+	try_dir("$todir/.log");
+	try_rename("$fromdir/.log/$fromfile","$todir/.log/$tofile");
+	try_dir("$todir/.note");
+	try_rename("$fromdir/.note/$fromfile","$todir/.note/$tofile");
+	try_dir("$todir/.lock");
+	try_rename("$fromdir/.lock/$fromfile","$todir/.lock/$tofile");
+	try_dir("$todir/.bak");
+	for($i=0;$i<=$GLOBALS[gblNumBackups];$i++) {
+		try_rename("$fromdir/.bak/$i/$fromfile","$todir/.bak/$i/$tofile");
 	}
 }
 
+
 //////////////////////////////////////////////////////////////////
 
 // recursivly delete directory
@@ -1136,38 +1183,20 @@
 	// creation if password not yet set.
 	if ($STYLE == "get") { CSS() ; exit ; }
 
-	$htusers_file=dirname($SCRIPT_FILENAME)."/.htusers";
-	if (! file_exists($htusers_file)) {
-		if (is_writable(dirname($SCRIPT_FILENAME))) {
-			$htusers=fopen($htusers_file,"a+");
-			fputs($htusers,"# Change owner of $htusers_file to root !!\n");
-			fputs($htusers,"demo:full name:[md5_hash|auth_*]:e-mail\n");
-			fclose($htusers);
-			Error("Proto user file created!","Please edit $htusers_file and set it correct permissions (not writable by web server as it is now!). You can add users using adduser.pl script!");
-			exit;
-		} else {
-			Error("Can't create proto user file!","Please make directory ".dirname($htusers_file)." writable or create .htusers file by hand using adduser.pl script!");
-			exit;
-		}
+	$fsScriptDir  = dirname($SCRIPT_FILENAME) ; 	
+	// i.e. /home/httpd/html/docman
+
+	// read user-defined configuration
+	if (file_exists("$fsScriptDir/.docman.conf")) {
+		include("$fsScriptDir/.docman.conf");
 	}
-	$htusers=fopen($htusers_file,"r");
-	while($user = fgetcsv($htusers,255,":")) {
-		if ($user[0] == $GLOBALS["PHP_AUTH_USER"]) {
-			$gblUserName=$user[1];
-			$gblPw=$user[2];
-			if (substr($gblPw,0,5) == "auth_" && file_exists("$gblIncDir/$gblPw.php")) {
-				require("$gblIncDir/$gblPw.php");
-				if ($gblPw($user)) {
-					$gblPw=md5($PHP_AUTH_USER.$PHP_AUTH_PW);
-				} else {
-					$gblPw="error".md5($PHP_AUTH_USER.$PHP_AUTH_PW);
-				}
-			}
-			$gblEmail=$user[3];
-			continue ;
-		}
+
+	// where do we get users from?
+	if (file_exists("$gblIncDir/$gblUsers.php")) {
+		include("$gblIncDir/$gblUsers.php");
+	} else {
+		Error("Configuration error","Can't find user handling module at $gblIncDir/$gblUsers.php ! Please fix $fsScriptDir/.docman.conf");
 	}
-	fclose($htusers);
 
 	// authentication failure
 	if ( md5($PHP_AUTH_USER.$PHP_AUTH_PW) != $gblPw ||
@@ -1184,6 +1213,8 @@
 		$relDir = urldecode($D) ;  // then use GET
 	}	
 
+	$relDir=stripSlashes($relDir);
+
 	if ($relDir == "/") $relDir = "" ; 	
 	// default : website root = ""
 
@@ -1197,9 +1228,6 @@
 	$relScriptDir = dirname($SCRIPT_NAME) ;  	
 	// i.e. /docman
 
-	$fsScriptDir  = dirname($SCRIPT_FILENAME) ; 	
-	// i.e. /home/httpd/html/docman
-
 	// start on server root
 //	$gblFsRoot = substr($fsScriptDir,0, strlen($fsScriptDir)-strlen($relScriptDir)) ;
 	// or on script root
@@ -1218,6 +1246,7 @@
 
 	$FN=stripSlashes($FN);
 
+
 	switch ($POSTACTION) {
 	case "UPLOAD" :
 		if (!is_writeable($fsDir)) Error("Write denied",$relDir) ;
@@ -1293,7 +1322,7 @@
 // this functionality is doubled in DetailView().
 // better keep it here altogether
 // chmod perms to $gblFilePerms
-			if ( file_exists($path) && !is_writable($path) ) 
+			if ( file_exists($path) && !is_writeable($path) ) 
 				Error("File not writable", $relPath) ;
 			$fh = fopen($path, "w+") ;
 			if ($fh) {
@@ -1365,14 +1394,7 @@
 		if ( $CONFIRM != "on" ) break ;
 
 		Logit("$fsDir/$FN","renamed $FN to $NEWNAME");
-		safe_rename("$fsDir/$FN","$fsDir/$NEWNAME");
-		safe_rename("$fsDir/.log/$FN","$fsDir/.log/$NEWNAME");
-		safe_rename("$fsDir/.note/$FN","$fsDir/.note/$NEWNAME");
-		safe_rename("$fsDir/.lock/$FN","$fsDir/.lock/$NEWNAME");
-		for($i=0;$i<=$GLOBALS[gblNumBackups];$i++) {
-			safe_rename("$fsDir/.bak/$i/$FN","$fsDir/.bak/$i/$NEWNAME");
-		}
-
+		safe_rename($fsDir,$FN,$NEWNAME);
 		break ;
 
 	case "NOTE" :