--- docman.php 2000/07/26 11:46:19 1.2 +++ docman.php 2000/08/04 10:20:22 1.8 @@ -96,7 +96,14 @@ $gblPw = ""; if ($gblAuth) { - $htusers=fopen(dirname($SCRIPT_FILENAME)."/.htusers","r"); + $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\n"); + fclose($htusers); + } + $htusers=fopen($htusers_file,"r"); while($user = fgetcsv($htusers,255,":")) { if ($user[0] == $GLOBALS["PHP_AUTH_USER"]) { $gblUserName=$user[1]; @@ -124,7 +131,7 @@ // the directory below should be /icons/ or /icons/small/ // on Apache; a set of icons is included in the distribution - $gblIconLocation = "icons/" ; + $gblIconLocation = "/icons/" ; // files you want to be able to edit in text mode // and view with (primitive) syntax highlighting @@ -150,19 +157,19 @@ - <?php echo $host . " " . $title ?> + <?= $host . " " . $title ?> + HREF="?STYLE=get"> -

+

-
-

+ +

- - - [logout] + [?relogin=">logout]
ANYPORTAL(php) Site Manager
@@ -187,7 +194,7 @@


- +

" . $relDir . "/" . $fn . "" ; if ($exists) { // get file info - $fsize = filesize($fsPath) ; - $fmodified = date("$GLOBALS[gblDateFmt] $GLOBALS[gblTimeFmt]", filemtime($fsPath)) ; - $faccessed = date("$GLOBALS[gblDateFmt] $GLOBALS[gblTimeFmt]", fileatime($fsPath)) ; - echo "
    file size: " . $fsize . " Bytes
" ; - echo "last modified: " . $fmodified . "
" ; - echo "last accessed: " . $faccessed . "
" ; - echo " owner: " . fileowner($fsPath) . "
" ; - echo " group: " . filegroup($fsPath) . "
" ; - echo " permissions: " ; - echo printf( "%o", fileperms($fsPath) ) . "" ; - echo "
" ; + $fsize = filesize($fsPath) ; + $fmodified = date("$GLOBALS[gblDateFmt] $GLOBALS[gblTimeFmt]", filemtime($fsPath)) ; + $faccessed = date("$GLOBALS[gblDateFmt] $GLOBALS[gblTimeFmt]", fileatime($fsPath)) ; + echo "
    file size: " . $fsize . " Bytes
" ; + echo "last modified: " . $fmodified . "
" ; + echo "last accessed: " . $faccessed . "
" ; + echo " owner: " . fileowner($fsPath) . "
" ; + echo " group: " . filegroup($fsPath) . "
" ; + echo " permissions: " ; + echo printf( "%o", fileperms($fsPath) ) . "" ; + echo "
" ; } - if ( $editable && ($writable || !$exists) ) { + if ( $editable && ($writable || !$exists) && !$file_lock ) { $fh = fopen($fsPath,"a+") ; rewind($fh) ; $fstr = fread($fh,filesize($fsPath)) ; @@ -269,39 +277,50 @@ $fstr = htmlentities( $fstr ) ; ?> -
+ DOCUMENT CONTENTS
- - + + + VALUE="">
" ; + echo htmlentities($tstr) . "

" . $tstr ; } - else if ( strstr( join(" ",$gblImages), $ext ) ) { - $info = getimagesize($fsPath) ; - $tstr = "\""" ; - echo htmlentities($tstr) . "

" . $tstr ; - } + ?> -
- - + + +
+
+ +OK TO FORCE LOCK REMOVAL ON "" HELD BY ? + + + -
-OK TO ""? +
+ + +OK TO ""? -
-OK TO RENAME "" TO +
+
+ +OK TO RENAME "" TO ? " ; + } // exists && writable +?> +
+
+NOTE FOR "": + + + + + + +undelete"; + $text .= ", undelete"; } $text .= " or revise files on this web site." ; StartHTML("(Navigate)",$text) ; @@ -642,9 +688,9 @@ if ($parent == "") $parent = "/" ; ?> - - - + + + -
DIRECTORY NAME +
DIRECTORY NAME " . $dir . "/" ; ?> - - + + -
+
DOCUMENT NAME - + +NOTE LAST UPDATEFILE SIZE 0) { sort($fileList) ; while (list($key,$file) = each($fileList)) { - $path = $fsDir."/".$file ; - $mod = filemtime($path) ; - $sz = filesize($path) ; - - if ($sz >= 10240) { - $sz = (int)(($sz+1023)/1024) . " k" ; - } - else { - $sz .= " " ; - } // end size - - $a = $b = "" ; - - if ( ($mod + 30*86400) > time() ) { - $a = " * " ; - } + $path = $fsDir."/".$file ; + $mod = filemtime($path) ; + $sz = filesize($path) ; + + if ($sz >= 10240) { + $sz = (int)(($sz+1023)/1024) . " k" ; + } else { + $sz .= " " ; + } // end size - $tstr = $webRoot . $relDir . "/" . $file ; - $tstr = "" ; + $a = $b = "" ; + + $info_url=$self."?A=E&F=".urlencode($file)."&D=".urlencode($relDir); + + if ( ($mod + 30*86400) > time() ) { + $a = " * " ; + } + + $file_lock=CheckLock($path); + + $file_url_html="" ; if (substr($file,0,5) != ".del/") { - $tstr .= $file . "" . $a ; + $file_url_html .= $file . "" . $a ; + } else { + $file_url_html .= substr($file,5,strlen($file)-5) . " deleted "; + } + + $note_html="".$gblIcon("note")."".ReadNote($path); + + $ext = strtolower(strrchr($file,".")) ; + + if ($file_lock) { + if ($file_lock == $GLOBALS[gblUserName]) { + $b.="" ; + $file_url_html=$b; + $b.=$gblIcon("checkin")."" ; + $b.= $gblIcon("blank"); + $file_url_html.="$file $a"; + $note_html = $gblIcon("blank")."Please check-in (update) this file"; + } else { + $b = $gblIcon("locked"); + $b.= $gblIcon("blank"); + $note_html = $gblIcon("blank")."File locked by $file_lock"; + $file_url_html = "$file $a"; + } } else { - $tstr .= substr($file,5,strlen($file)-5) . " deleted "; + $b.="" ; + $b.=$gblIcon("checkout")."" ; + + if ( $ext=="" || strstr(join(" ",$gblEditable),$ext) ) { + $b.="" ; + $b.=$gblIcon("view")."" ; + } else { + $b.= $gblIcon("blank"); + } } - $ext = strtolower(strrchr($file,".")) ; - if ( $ext=="" || - strstr(join(" ",$gblEditable),$ext) ) - { - $b = "" ; - $b .= $gblIcon("view") . "" ; - } ?> - - - - - -Bytes + + + + + + +Bytes -
- - + + + OK TO DELETE THIS EMPTY FOLDER? @@ -750,18 +828,28 @@ } // end if emptyDir ?> -
+
- -CREATE NEW + +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. + + +
+ + +CREATE NEW DIRECTORY -OR- FILE :    NAME - + - OR UPLOAD A FILE + OR UPLOAD A FILE @@ -773,7 +861,7 @@ ////////////////////////////////////////////////////////////////// -function UploadPage($fsRoot, $relDir) { +function UploadPage($fsRoot, $relDir, $filename) { $self = $GLOBALS["PHP_SELF"] ; if ($relDir == "") $relDir = "/" ; @@ -781,21 +869,25 @@

-DESTINATION DIRECTORY: + ACTION=""> +DESTINATION DIRECTORY: + +
DESTINATION FILE: + +

PATHNAME OF LOCAL FILE
- +

If the [BROWSE...] button is not displayed,
you must upgrade to an RFC1867-compliant browser.

-

Your browser:

+

Your browser:

-
-
+ +

@@ -848,9 +940,9 @@ StartHTML($title,$text) ; ?> -
- - + + +
If you are a site administrator:

Click below to generate a password hash
from @@ -882,6 +974,116 @@ } +////////////////////////////////////////////////////////////////// + +function WriteNote($target,$msg) { + + $dir=dirname($target); + if (! file_exists($dir."/.note")) { + mkdir($dir."/.note",0700); + } + $file=basename($target); + + $note=fopen("$dir/.note/$file","w"); + fputs($note,"$msg\n"); + fclose($note); + + Logit($target,"added note $msg"); + +} + +function ReadNote($target) { + + $dir=dirname($target); + $file=basename($target); + $msg=""; + if (file_exists($dir."/.note/$file")) { + $note=fopen("$dir/.note/$file","r"); + $msg=fgets($note,4096); + fclose($note); + } + return StripSlashes($msg); + +} + +////////////////////////////////////////////////////////////////// + +function MoveTo($source,$folder) { + + $file=basename($source); + if (! file_exists($folder)) { + mkdir($folder,0700); + } + if (file_exists($source)) { + rename($source,"$folder/$file"); + } +} + +////////////////////////////////////////////////////////////////// + +function Lock($target) { + + $dir=dirname($target); + if (! file_exists($dir."/.lock")) { + mkdir($dir."/.lock",0700); + } + $file=basename($target); + + if (file_exists("$dir/.lock/$file")) { + Logit($target,"attempt to locked allready locked file!"); + } else { + $lock=fopen("$dir/.lock/$file","w"); + fputs($lock,"$GLOBALS[gblUserName]\n"); + fclose($lock); + + Logit($target,"file locked"); + } + +} + +function CheckLock($target) { + + $dir=dirname($target); + $file=basename($target); + $msg=0; + if (file_exists($dir."/.lock/$file")) { + $lock=fopen("$dir/.lock/$file","r"); + $msg=fgets($lock,4096); + fclose($lock); + } + return chop($msg); + +} + +function Unlock($target) { + + $dir=dirname($target); + $file=basename($target); + if (file_exists($dir."/.lock/$file")) { + unlink("$dir/.lock/$file"); + Logit($target,"file unlocked"); + } else { + Logit($target,"attempt to unlocked non-locked file!"); + } + +} + +////////////////////////////////////////////////////////////////// + +function redir_to_url($url) { + $url=urlencode(StripSlashes("$url")); + $url=str_replace("%2F","/",$url); + $url=str_replace("+","%20",$url); + Header("Location: $url"); +} + +////////////////////////////////////////////////////////////////// + +function safe_rename($from,$to) { + if (file_exists($from) && is_writable(dirname($to))) { + rename($from,$to); + } +} ////////////////////////////////////////////////////////////////// @@ -951,7 +1153,11 @@ // TODO : should rather check for escapeshellcmds // but maybe RFC 18xx asserts safe filenames .... $source = $FN ; - $target = $fsDir . "/" . $FN_name ; + if (! isset($FILENAME)) { // from update file + $target = "$fsDir/$FN_name" ; + } else { + $target = "$fsDir/$FILENAME"; + } // backup old files first $dir=dirname($target); @@ -963,22 +1169,17 @@ } $file=basename($target); for($i=$GLOBALS[gblNumBackups]-1;$i>0;$i--) { - if (! file_exists($dir."/.bak/".$i)) { - mkdir($dir."/.bak/".$i,0700); - } - if (file_exists($dir."/.bak/".$i."/".$file)) { - rename($dir."/.bak/".$i."/".$file, - $dir."/.bak/".($i+1)."/".$file); - } - } - if (file_exists($target)) { - rename($target,$dir."/.bak/1/".$file); + MoveTo("$dir/.bak/$i/$file","$dir/.bak/".($i+1)."/"); } + MoveTo($target,$dir."/.bak/1/"); copy($source,$target) ; chmod($target,$gblFilePerms) ; clearstatcache() ; Logit($target,"uploaded"); + if (isset($FILENAME)) { + Unlock($target); + } break ; case "SAVE" : @@ -1004,19 +1205,27 @@ $relPath = $relDir . "/" . $FN ; switch ( $T ) { case "D" : // create a directory - if ( ! @mkdir($path,$gblDirPerms) ) - Error("Mkdir failed",$relPath) ; // eg. if it exists - clearstatcache() ; - break ; + if ( ! @mkdir($path,$gblDirPerms) ) + Error("Mkdir failed",$relPath) ; // eg. if it exists + clearstatcache() ; + break ; case "F" : // create a new file // this functionality is doubled in DetailView(). // better keep it here altogether // chmod perms to $gblFilePerms - if ( file_exists($path) && !is_writable($path) ) - Error("File not writable", $relPath) ; - $tstr = $PHP_SELF . "?A=E&D=" . $relDir . "&F=" . $FN ; - header("Location: " . $tstr) ; - exit ; + if ( file_exists($path) && !is_writable($path) ) + Error("File not writable", $relPath) ; + $fh = fopen($path, "w+") ; + if ($fh) { + fputs($fh,"\n"); + fclose($fh) ; + LogIt($path,"file created"); + } else { + Error("Creation of file $relPath failed -- $path"); + } + $tstr = "$PHP_SELF?A=E&D=".urlencode($relDir)."&F=".urlencode($FN) ; + header("Location: " . $tstr) ; + exit ; } break ; @@ -1042,10 +1251,9 @@ exit ; } else { Logit($path,"file deleted"); - if (! file_exists("$dir/.del/.log")) { - mkdir("$dir/.del/.log",0700); - } - rename("$dir/.log/$file","$dir/.del/.log/$file"); + MoveTo("$dir/.log/$file","$dir/.del/.log/"); + MoveTo("$dir/.note/$file","$dir/.del/.note/"); + MoveTo("$dir/.lock/$file","$dir/.del/.lock/"); } } else { // delete directory @@ -1065,8 +1273,10 @@ $file=substr($FN,4,strlen($FN)-4); Logit("$fsDir/.del/$file","undeleted"); - rename("$fsDir/.del/$file","$fsDir/$file"); - rename("$fsDir/.del/.log/$file","$fsDir/.log/$file"); + MoveTo("$fsDir/.del/$file","$fsDir/"); + MoveTo("$fsDir/.del/.log/$file","$fsDir/.log/"); + MoveTo("$fsDir/.del/.note/$file","$fsDir/.note/"); + MoveTo("$fsDir/.del/.lock/$file","$fsDir/.lock/"); break ; @@ -1074,9 +1284,20 @@ if ( $CONFIRM != "on" ) break ; Logit("$fsDir/$FN","renamed $FN to $NEWNAME"); - rename("$fsDir/$FN","$fsDir/$NEWNAME"); - rename("$fsDir/.log/$FN","$fsDir/.log/$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"); + + break ; + + case "NOTE" : + WriteNote("$fsDir/$FN","$NOTE"); + break ; + case "UNLOCK" : + if ( $CONFIRM != "on" ) break ; + Unlock("$fsDir/$FN"); break ; default : @@ -1094,6 +1315,9 @@ // $A=U : upload to path given in $D // $A=E : display detail of file $D/$F and edit // $A=C : display code in file $D/$F + // $A=Co : checkout file $D/$F + // $A=Ci : checkin file $D/$F + // $A=V : view file (do nothing except log) // default : display directory $D switch ($A) { @@ -1115,6 +1339,26 @@ // listing of $relDir/$F DisplayCode($gblFsRoot, $relDir, $F) ; exit ; + case "Co" : + // checkout + Lock("$gblFsRoot/$relDir/$F"); + redir_to_url("$relDir/$F"); + exit; + case "Ci" : + // upload && update to $relDir + if (!is_writeable($gblFsRoot . $relDir)) + Error("Write access denied",$relDir) ; + $text = "Use this page to update a single " ; + $text .= "file to $SERVER_NAME." ; + StartHTML("(Update file Page)", $text) ; + UploadPage($gblFsRoot, $relDir, $F) ; + EndHTML() ; + exit ; + case "V" : + // view + Log("viewed"); + redir_to_url("$relDir/$F"); + exit; } // default: display directory $relDir