--- docman.php 2001/01/26 12:39:57 1.30 +++ docman.php 2001/06/04 08:20:55 1.41 @@ -83,32 +83,6 @@ $gblPw = ""; - $htusers_file=dirname($SCRIPT_FILENAME)."/.htusers"; - if (! file_exists($htusers_file)) { - $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); - } - $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 ; - } - } - fclose($htusers); - // date format // $gblDateFmt="D, F d, Y"; $gblDateFmt="Y-m-d"; @@ -229,7 +203,7 @@ function DetailPage($fsRoot,$relDir,$fn) { - global $gblEditable, $gblImages ; + global $gblEditable, $gblImages, $webRoot ; $self = $GLOBALS["PHP_SELF"] ; $relPath = $relDir . "/" . $fn ; @@ -248,7 +222,11 @@ Error("Creation denied",$relDir) ; $text = "Use this page to view, modify or " ; - $text .= "delete a single document on this " ; + if (is_dir($fsPath)) { + $text .="delete a directory on this " ; + } else { + $text .= "delete a single document on this " ; + }; $text .= "web site." ; $title = "(Detail Page)" ; StartHTML($title, $text) ; @@ -258,18 +236,23 @@ $fsize = filesize($fsPath) ; $fmodified = date("$GLOBALS[gblDateFmt] $GLOBALS[gblTimeFmt]", filemtime($fsPath)) ; $faccessed = date("$GLOBALS[gblDateFmt] $GLOBALS[gblTimeFmt]", fileatime($fsPath)) ; - echo "
    file size: " . $fsize . " Bytes
" ; + $fuid=fileowner($fsPath); + $fgid=filegroup($fsPath); + $userinfo = posix_getpwuid($fuid); + $grpinfo = posix_getgrgid($fgid); + echo "
";
+		if (!is_dir($fsPath)) echo "    file size: " . $fsize . " Bytes
" ; echo "last modified: " . $fmodified . "
" ; echo "last accessed: " . $faccessed . "
" ; - echo " owner: " . fileowner($fsPath) . "
" ; - echo " group: " . filegroup($fsPath) . "
" ; + echo " owner: " . $userinfo["name"] . " [$fuid]
" ; + echo " group: " . $grpinfo["name"] . " [$fgid]
" ; echo " permissions: " ; echo printf( "%o", fileperms($fsPath) ) . "" ; echo "
" ; } - if ( $editable && ($writable || !$exists) && !$file_lock ) { + if ( !is_dir($fsPath) && $editable && ($writable || !$exists) && !$file_lock ) { $fh = fopen($fsPath,"a+") ; rewind($fh) ; $fstr = fread($fh,filesize($fsPath)) ; @@ -297,7 +280,7 @@ } if ( !$file_lock && $ext!="" && strstr(join(' ',$gblImages),$ext) ) { $info = getimagesize($fsPath) ; - $tstr = "\""" ; // echo htmlentities($tstr) . "

" . $tstr ; @@ -376,12 +359,17 @@ array_unshift($logarr,array($cl,$line[0],$line[1],$line[2],$line[3])); } fclose($log); - print "

CHANGES TO THIS FILE
\n"; + if (is_dir("$fsDir/$fn")) { + $whatis="DIRECTORY"; + } else { + $whatis="FILE"; + } + print "

CHANGES TO THIS $whatis
\n"; $bakcount = 0; // start from 0, skip fist backup (it's current) while ($e = array_shift($logarr)) { if (strstr($e[4],"upload")) { if (file_exists("$bakdir/$bakcount/$name")) { - $e[4]="$e[4]"; + $e[4]="$e[4]"; } $bakcount++; } @@ -642,15 +630,11 @@ function Navigate($fsRoot,$relDir) { - global $gblEditable, $gblIcon, $gblModDays ; + global $gblEditable, $gblIcon, $gblModDays, $webRoot ; $self = $GLOBALS["PHP_SELF"] ; - if (isset($GLOBALS["HTTPS"]) && $GLOBALS["HTTPS"] == "on") { - $webRoot = "https://" . $GLOBALS["HTTP_HOST"] ; - } else { - $webRoot = "http://" . $GLOBALS["HTTP_HOST"] ; - } - $fsDir = $fsRoot . $relDir . "/" ; // current directory + + $fsDir = $fsRoot . $relDir . "/" ; // current directory if (!is_dir($fsDir)) Error("Dir not found",$relDir) ; @@ -710,23 +694,36 @@ 1) { + $out.="s"; + } + return $out; +} + // output subdirs if (sizeof($dirList) > 0) { sort($dirList) ; ?> - +" . $dir . "/" ; + $note_html="".$gblIcon("note")."".ReadNote($fsDir.$dir); ?> - - + + + - + @@ -867,7 +864,8 @@ NAME - + + OR UPLOAD A FILE @@ -1068,12 +1066,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
@@ -1149,6 +1175,39 @@
 	// creation if password not yet set.
 	if ($STYLE == "get") { CSS() ; exit ; }
 
+	$htusers_file=dirname($SCRIPT_FILENAME)."/.htusers";
+	if (! file_exists($htusers_file)) {
+		if (is_writeable(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;
+		}
+	}
+	$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 ;
+		}
+	}
+	fclose($htusers);
+
 	// authentication failure
 	if ( md5($PHP_AUTH_USER.$PHP_AUTH_PW) != $gblPw ||
 		isset($relogin) && $gblPw == $relogin ) {
@@ -1164,6 +1223,8 @@
 		$relDir = urldecode($D) ;  // then use GET
 	}	
 
+	$relDir=stripSlashes($relDir);
+
 	if ($relDir == "/") $relDir = "" ; 	
 	// default : website root = ""
 
@@ -1189,8 +1250,19 @@
 	$fsDir = $gblFsRoot . $relDir ; // current directory
 	if ( !is_dir($fsDir) ) Error("Dir not found",$relDir) ;
 
+	if (isset($GLOBALS["HTTPS"]) && $GLOBALS["HTTPS"] == "on") {
+		$webRoot  = "https://";
+	} else {
+		$webRoot  = "http://";
+	}
+	$webRoot .= $GLOBALS["HTTP_HOST"] . $relScriptDir;
+
 	$FN=stripSlashes($FN);
 
+	if (file_exists("$fsScriptDir/.docman.conf")) {
+		include("$fsScriptDir/.docman.conf");
+	}
+
 	switch ($POSTACTION) {
 	case "UPLOAD" :
 		if (!is_writeable($fsDir)) Error("Write denied",$relDir) ;
@@ -1266,7 +1338,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) {
@@ -1338,14 +1410,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" :  
@@ -1391,7 +1456,7 @@
 	case "E" :
 		$F=stripSlashes($F);
 		// detail of $relDir/$F
-		if (is_file("$gblFsRoot/$relDir/$F")) DetailPage($gblFsRoot, $relDir, $F) ;
+		if (is_file("$gblFsRoot/$relDir/$F") || is_dir("$gblFsRoot/$relDir/$F")) DetailPage($gblFsRoot, $relDir, $F) ;
 		exit ;
 	case "C" :
 		$F=stripSlashes($F);
@@ -1402,7 +1467,7 @@
 		// checkout
 		Lock("$gblFsRoot/$relDir/$F");
 		header("Content-Disposition: attachment; filename=$F" );
-		Header("Location: ".urlpath("$relDir/$F"));
+		Header("Location: $webRoot".urlpath("$relDir/$F"));
 		exit;
 	case "Ci" :
 		$F=stripSlashes($F);
@@ -1419,7 +1484,7 @@
 		// view
 		LogIt("$gblFsRoot/$relDir/$F","viewed");
 		header("Content-Disposition: attachment; filename=$F" );
-		Header("Location: ".urlpath("$relDir/$F"));
+		Header("Location: $webRoot".urlpath("$relDir/$F"));
 		exit;
 	case "Ch" :
 		StartHTML("(File changes)","All changes chronologicaly...");

DIRECTORY NAME
DIRECTORY NAME ()DIRECTORY NOTE
+ +

DOCUMENT NAME
DOCUMENT NAME () NOTE LAST UPDATEFILE SIZE