--- docman.php 2000/08/04 11:25:05 1.11 +++ docman.php 2000/09/13 09:59:16 1.22 @@ -66,6 +66,8 @@ mixed file/directory output (add type to each entry, real support for links) retrieve old versions of files (overwritten) + show last lock date + */ ////////////////////////////////////////////////////////////////// @@ -106,6 +108,7 @@ if ($user[0] == $GLOBALS["PHP_AUTH_USER"]) { $gblUserName=$user[1]; $gblPw=$user[2]; + $gblEmail=$user[3]; continue ; } } @@ -118,8 +121,11 @@ $gblDateFmt="Y-m-d"; $gblTimeFmt="H:i:s"; -// Number of backup files to keep - $gblNumBackups=5; + // Number of backup files to keep + $gblNumBackups=3; + + // show red star if newer than ... days + $gblModDays=1; // choose GifIcon below unless you have the M$ // WingDings font installed on your system @@ -293,7 +299,7 @@ undelete"; } $text .= " or revise files on this web site." ; + $text .= "
Examine list of files changed in last day or all changes."; StartHTML("(Navigate)",$text) ; echo " time() ) { + if ( ($mod + $gblModDays*86400) > time() ) { $a = " * " ; + $a .= " than $gblModDays days\"> * " ; } $file_lock=CheckLock($path); @@ -843,11 +850,11 @@ @@ -969,7 +976,7 @@ ////////////////////////////////////////////////////////////////// -function Logit($target,$msg) { +function LogIt($target,$msg) { $dir=dirname($target); if (! file_exists($dir."/.log")) { @@ -989,6 +996,7 @@ function WriteNote($target,$msg) { + $target=stripSlashes($target); $dir=dirname($target); if (! file_exists($dir."/.note")) { mkdir($dir."/.note",0700); @@ -1005,6 +1013,7 @@ function ReadNote($target) { + $target=stripSlashes($target); $dir=dirname($target); $file=basename($target); $msg=""; @@ -1021,6 +1030,7 @@ function MoveTo($source,$folder) { + $source=stripSlashes($source); $file=basename($source); if (! file_exists($folder)) { mkdir($folder,0700); @@ -1034,6 +1044,7 @@ function Lock($target) { + $target=stripSlashes($target); $dir=dirname($target); if (! file_exists($dir."/.lock")) { mkdir($dir."/.lock",0700); @@ -1054,6 +1065,7 @@ function CheckLock($target) { + $target=stripSlashes($target); $dir=dirname($target); $file=basename($target); $msg=0; @@ -1068,6 +1080,7 @@ function Unlock($target) { + $target=stripSlashes($target); $dir=dirname($target); $file=basename($target); if (file_exists($dir."/.lock/$file")) { @@ -1098,6 +1111,63 @@ ////////////////////////////////////////////////////////////////// +// recursivly delete directory + +function rrmdir($dir) { + $handle=opendir($dir); + while ($file = readdir($handle)) { + if ($file != "." && $file != "..") { + if (is_dir("$dir/$file")) + rrmdir("$dir/$file"); + else + if (! @unlink("$dir/$file")) return(0); + } + } + closedir($handle); + return @rmdir($dir); +} + +////////////////////////////////////////////////////////////////// + +function ChangeLog($target,$msg) { + + global $gblFsRoot; + $log=fopen("$gblFsRoot/.changelog","a+"); + if (substr($target,0,strlen($gblFsRoot)) == $gblFsRoot) + $target=substr($target,strlen($gblFsRoot),strlen($target)-strlen($gblFsRoot)); + fputs($log,time()."\t$target\t$GLOBALS[gblUserName]\t$msg\n"); + fclose($log); + +} + +function DisplayChangeLog($day) { + + global $gblFsRoot; + if (!file_exists("$gblFsRoot/.changelog")) return; + $log=fopen("$gblFsRoot/.changelog","r"); + $logarr = array(); + while($line = fgetcsv($log,255,"\t")) { + if ($day!=1 || ($day==1 && (time()-$line[0] < 24*60))) { + array_unshift($logarr,array($line[0],$line[1],$line[2],$line[3])); + } + } + fclose($log); + $cl1=" class=lst"; $cl2=""; + print "

-To just view file without editing, select it's filename (don't edit files which are opened this way!)
-To edit file select to check-out -and edit it locally. After editing is over, select filename or to check-in (update copy of file on server).
-If you select icon left from filename, you will get detailed information -about file, as well as delete, rename and annotation options. +

\n"; + while ($e = array_shift($logarr)) { + $cl=$cl1; $cl1=$cl2; $cl2=$cl; + $date = date("$GLOBALS[gblDateFmt]", $e[0]); + $time = date("$GLOBALS[gblTimeFmt]", $e[0]); + $dir = dirname($e[1]); + $file = basename($e[1]); + print "$date$time$dir/$file$e[2]$e[3]\n"; + } + print "
"; + print "

".GifIcon(up)." Back to front page.

"; +} + +////////////////////////////////////////////////////////////////// + // MAIN PROGRAM // ============ // query parameters: capital letters @@ -1155,7 +1225,9 @@ $fsDir = $gblFsRoot . $relDir ; // current directory if ( !is_dir($fsDir) ) Error("Dir not found",$relDir) ; - + + $FN=stripSlashes($FN); + switch ($POSTACTION) { case "UPLOAD" : if (!is_writeable($fsDir)) Error("Write denied",$relDir) ; @@ -1191,10 +1263,12 @@ if (isset($FILENAME)) { Unlock($target); } + ChangeLog($target,"updated"); break ; case "SAVE" : - $path = $gblFsRoot . escapeshellcmd($RELPATH) ; + $path = $gblFsRoot . $RELPATH ; + $path=stripSlashes($path); $writable = is_writeable($path) ; $legaldir = is_writeable(dirname($path)) ; $exists = (file_exists($path)) ? 1 : 0 ; @@ -1202,10 +1276,12 @@ if (!($writable || (!$exists && $legaldir))) Error("Write denied",$RELPATH) ; $fh = fopen($path, "w") ; + $FILEDATA=stripSlashes($FILEDATA); fwrite($fh,$FILEDATA) ; fclose($fh) ; clearstatcache() ; Logit($path,"saved changes"); + ChangeLog($path,"saved changes"); break ; case "CREATE" : @@ -1236,6 +1312,7 @@ } $tstr = "$PHP_SELF?A=E&D=".urlencode($relDir)."&F=".urlencode($FN) ; header("Location: " . $tstr) ; + ChangeLog($target,"created"); exit ; } break ; @@ -1268,7 +1345,7 @@ } } else { // delete directory - if ( ! @rmdir($fsDir) ) { + if ( ! @rrmdir($fsDir) ) { Error("Rmdir failed", $tstr . $fsDir) ; } else { @@ -1333,7 +1410,7 @@ // $A=Ci : checkin file $D/$F // $A=V : view file (do nothing except log) // default : display directory $D - + switch ($A) { case "U" : // upload to $relDir @@ -1346,19 +1423,23 @@ EndHTML() ; exit ; case "E" : + $F=stripSlashes($F); // detail of $relDir/$F if (is_file("$gblFsRoot/$relDir/$F")) DetailPage($gblFsRoot, $relDir, $F) ; exit ; case "C" : + $F=stripSlashes($F); // listing of $relDir/$F DisplayCode($gblFsRoot, $relDir, $F) ; exit ; case "Co" : // checkout Lock("$gblFsRoot/$relDir/$F"); + header("Content-Disposition: attachment; filename=$F" ); Header("Location: ".urlpath("$relDir/$F")); exit; case "Ci" : + $F=stripSlashes($F); // upload && update to $relDir if (!is_writeable($gblFsRoot . $relDir)) Error("Write access denied",$relDir) ; @@ -1371,8 +1452,19 @@ case "V" : // view LogIt("$gblFsRoot/$relDir/$F","viewed"); + header("Content-Disposition: attachment; filename=$F" ); Header("Location: ".urlpath("$relDir/$F")); exit; + case "Ch" : + StartHTML("(File changes)","All changes chronologicaly..."); + DisplayChangeLog(0); // all + EndHTML() ; + exit; + case "Ch1" : + StartHTML("(File changes)","Changes to files in last day..."); + DisplayChangeLog(1); + EndHTML() ; + exit; } // default: display directory $relDir