--- docman.php 2002/07/28 18:56:49 1.22
+++ docman.php 2002/07/29 14:17:05 1.32
@@ -90,8 +90,8 @@
if ($fsDocumentRoot == "") Error("Configuration error","Can't get SCRIPT_FILENAME from your web server. Please set \$fsDocumentRoot in \$",1);
// globals for later
- $gblLogin = $HTTP_SERVER_VARS["PHP_AUTH_USER"];
- $gblPasswd = $HTTP_SERVER_VARS["PHP_AUTH_PW"];
+ $gblLogin = HTTP_SERVER_VAR("PHP_AUTH_USER");
+ $gblPasswd = HTTP_SERVER_VAR("PHP_AUTH_PW");
//////////////////////////////////////////////////////////////////
@@ -157,6 +157,7 @@
global $gblEditable, $gblImages,
$gblDateFmt, $gblTimeFmt,
+ $gblPermNote,
$webRoot, $html,
$HTTP_SERVER_VARS ;
$self = $HTTP_SERVER_VARS["PHP_SELF"] ;
@@ -188,7 +189,8 @@
$title = "("._("Detail Page").")" ;
StartHTML($title, $text) ;
- echo "
" . $relDir . "/" . $fn . "
" ;
+ print "".$relDir.$fn."
";
+
if ($exists) { // get file info
$fsize = filesize($fsPath) ;
$fmodified = date("$gblDateFmt $gblTimeFmt", filemtime($fsPath)) ;
@@ -207,52 +209,27 @@
$fstr = fread($fh,filesize($fsPath)) ;
fclose($fh) ;
$fstr = htmlentities( $fstr ) ;
-?>
-
-
-" ;
// echo htmlentities($tstr) . "
" . $tstr ;
echo $tstr ;
}
-?>
-
+ }
+
+ if (check_perm($relDir.$fn,$gblPermNote)) {
+ include("$html/DetailPage-note.html");
+ }
-";
$name=basename("$fsDir/$fn");
$logname=dirname("$fsDir/$fn")."/.log/$name";
@@ -480,18 +436,10 @@
//////////////////////////////////////////////////////////////////
-function GifIcon($txt) {
- global $gblIconLocation ;
+function GifIcon($txt = "") {
+ global $gblIconLocation, $gblImages ;
switch (strtolower($txt)) {
- case ".bmp" :
- case ".gif" :
- case ".jpg" :
- case ".jpeg":
- case ".tif" :
- case ".tiff":
- $d = "image2.gif" ;
- break ;
case ".doc" :
$d = "layout.gif" ;
break ;
@@ -569,9 +517,14 @@
$d = "quill.gif";
break;
default :
- $d = "generic.gif" ;
+ if (in_array(strtolower($txt),$gblImages)) {
+ $d = "image2.gif" ;
+ } else {
+ $d = "generic.gif" ;
+ }
}
+
return "" ;
} // end function GifIcon
@@ -581,7 +534,8 @@
global $gblEditable, $gblIcon, $gblModDays, $webRoot, $gblHide,
$gblIgnoreUnknownFileType, $gblRepositoryDir,
- $gblLogin, $gblUserName,
+ $gblLogin, $gblUserName, $gblDateFmt, $gblTimeFmt,
+ $gblPermNote,
$fsRealmDir, $realm, $realm_sep,
$html, $realm_config,
$HTTP_GET_VARS, $HTTP_SERVER_VARS;
@@ -632,10 +586,15 @@
if ( HTTP_GET_VAR("show_deleted") == 1 && ($dir = @opendir("$fsDir/.del")) ) {
while ($item = readdir($dir)) {
if ( substr($item,0,1) == "." || strstr($hide_items,",$item,") || !check_perm($relDir.$item,trperm_w) ) continue ;
- $fileList[$item] = ".del/$item" ;
- $fileDate[$item] = filemtime($fsDir.".del/$path") ;
- $fileSize[$item] = filesize($fsDir.".del/$path") ;
- $fileNote[$item] = ReadNote($fsDir.".del/$item");
+ if (is_file($fsDir.".del/$item")) {
+ $fileList[$item] = ".del/$item" ;
+ $fileDate[$item] = filemtime($fsDir.".del/$item") ;
+ $fileSize[$item] = filesize($fsDir.".del/$item") ;
+ $fileNote[$item] = ReadNote($fsDir.".del/$item");
+ } else {
+ $dirList[$item] = ".del/$item" ;
+ $dirNote[$item] = ReadNote($fsDir.".del/$item");
+ }
}
closedir($dir) ;
}
@@ -651,8 +610,7 @@
$text .= "
Examine list of files changed in last day or all changes.";
StartHTML("(Navigate)",$text) ;
- echo "" ;
+ print "" ;
// updir (parent) bar
if (chopsl($fsDir) != chopsl($fsRoot)) {
@@ -670,7 +628,8 @@
return $out;
}
- if (! HTTP_GET_VAR("dsort")) $dsort = "name"; // default directory sort
+ $dsort = HTTP_GET_VAR("dsort");
+ if (! isset($dsort)) $dsort = "name"; // default directory sort
$dsort_arr = array(
"name" => array ("rname", "note"),
@@ -679,7 +638,8 @@
"rnote" => array ("name", "note")
);
- if (! HTTP_GET_VAR("fsort")) $fsort = "name"; // default directory sort
+ $fsort = HTTP_GET_VAR("fsort");
+ if (! isset($fsort)) $fsort = "name"; // default directory sort
$fsort_arr = array(
"name" => array ("rname", "note", "date", "size"),
@@ -733,7 +693,20 @@
$dir = $dirList[$key];
$info_url=self_args(array("A"=>"A=E", "F"=>"F=".urlencode($dir), "D"=>$D));
+ if (substr($dir,0,5) == ".del/") {
+ $dir = substr($dir,5,strlen($dir)-5);
+ $deleted = " deleted";
+ } else {
+ $deleted = "";
+ }
+
$dir_url=$self."?D=".urlencode(chopsl($relDir)."/".$dir);
+ if (check_perm($relDir.$dir,$gblPermNote)) {
+ $note_html="".$gblIcon("note")."".$dirNote[$key];
+ } else {
+ $note_html=$dirNote[$key];
+ }
+
include("$html/Navigate-dirEntry.html");
} // iterate over dirs
@@ -811,10 +784,14 @@
if (substr($file,0,5) != ".del/") {
$file_url_html .= $file . "" . $a ;
} else {
- $file_url_html .= substr($file,5,strlen($file)-5) . " deleted ";
+ $file_url_html .= substr($file,5,strlen($file)-5) . " deleted";
}
- $note_html="".$gblIcon("note")."".ReadNote($path);
+ if (check_perm($relDir.$file,$gblPermNote)) {
+ $note_html="".$gblIcon("note")."".$fileNote[$key];
+ } else {
+ $note_html=$fileNote[$key];
+ }
$ext = strtolower(strrchr($file,".")) ;
@@ -834,9 +811,11 @@
$file_url_html = "$file $a";
}
} else {
- $b.="" ;
- $b.=$gblIcon("checkout")."";
+ if (check_perm($relDir.$file,trperm_w)) {
+ $b.="" ;
+ $b.=$gblIcon("checkout")."";
+ }
if ( $ext=="" || strstr(join(" ",$gblEditable),$ext) ) {
$b.="
- |
- No files in this directory
- |
-
+ include("$html/Navigate-noFiles.html");
}
if ($emptyDir && $relDir != "") {
-?>
-
-
-
-
-
- |
|
-
+ include("$html/Navigate-hr.html");
-if (file_exists("$fsRealmDir/$realm".$realm_sep."info.inc")) {
- print " | ";
- include("$fsRealmDir/$realm".$realm_sep."info.inc");
- print " |
|
|
";
-} elseif (file_exists("$gblRepositoryDir/.info.inc")) {
- print " | ";
- include("$gblRepositoryDir/.info.inc");
- print " |
|
|
";
-}
+ if (file_exists("$fsRealmDir/$realm".$realm_sep."info.inc")) {
+ print " | ";
+ include("$fsRealmDir/$realm".$realm_sep."info.inc");
+ print " |
";
+ include("$html/Navigate-hr.html");
+ } elseif (file_exists("$gblRepositoryDir/.info.inc")) {
+ print " | ";
+ include("$gblRepositoryDir/.info.inc");
+ print " |
";
+ include("$html/Navigate-hr.html");
+ }
+ include("$html/Navigate-createNew.html");
-?>
-
-
-
+ print "
";
-$dir/.note/$file for writing",1);
+ }
fputs($note,"$msg\n");
fclose($note);
@@ -1160,7 +1112,7 @@
function DisplayChangeLog($day) {
- global $gblFsRoot, $gblDateFmt, $gblTimeFmt;
+ global $gblFsRoot, $gblDateFmt, $gblTimeFmt,
$HTTP_SERVER_VARS;
$self = $HTTP_SERVER_VARS["PHP_SELF"];
@@ -1189,7 +1141,7 @@
print "$date | $time | $dir/$file | $e[2] | $e[3] |
\n";
}
print "";
- print "".GifIcon(up)." Back to front page.
";
+ print "".GifIcon("up")." Back to front page.
";
}
//////////////////////////////////////////////////////////////////
@@ -1211,7 +1163,7 @@
$ext_arr = explode(".",$file);
$ext = array_pop($ext_arr);
- if ($encoding_ext[$ext]) {
+ if (isset($encoding_ext[$ext])) {
$encoding = $encoding_ext[$ext];
$ext = array_pop($ext_arr);
}
@@ -1223,7 +1175,7 @@
}
// IE5.5 just downloads index.php if we don't do this
- if(preg_match("/MSIE 5.5/", $HTTP_SERVER_VARS[HTTP_USER_AGENT])) {
+ if(preg_match("/MSIE 5.5/", $HTTP_SERVER_VARS["HTTP_USER_AGENT"])) {
header("Content-Disposition: filename=$file");
} else {
header("Content-Disposition: attachment; filename=$file");
@@ -1405,14 +1357,10 @@
}
// helper function
-function unroll_perm($u,$t,$user,$perm,$one_level) {
+function unroll_perm($u,$t,$perm,$one_level) {
if ($t & trmask_one_level && !$one_level) return $perm;
- // user is user whose trustee is this
- if ($t & trmask_not && ($u==$user)) return $perm;
- if (!($t & trmask_not) && ($u!=$user)) return $perm;
-
if ($t & trmask_deny) {
if ($t & trmask_clear) {
$perm['deny'] &= ~$t;
@@ -1428,11 +1376,14 @@
}// end of helper function
function check_trustee($user,$path) {
- global $trustees;
+ global $trustees,$HAVE_TRUSTEE;
$perm['allow'] = 0;
$perm['deny'] = 0;
- if (! isset($trustees)) Error("Trustees not found","Can't find in-memory trustee structure \$trustees. Probably bug in code. Contact dpavlin@rot13.org",1);
+ // do we use trustees?
+ if (! $HAVE_TRUSTEE) return $perm;
+
+ if (! isset($trustees)) Error("Trustees not found","Can't find in-memory trustee structure \$trustees. Probably bug in code. Contact dpavlin@rot13.org",1);
global $debug;
$debug .= "
check_trustee $path ... ";
@@ -1451,22 +1402,27 @@
if (isset($tr)) {
// first apply trustee for all
- if (isset($tr['*'])) {
- $perm = unroll_perm($user,$tr['*'],'*', $perm, $one_level);
+ if (isset($tr['*']) && $user!="anonymous") {
+ $perm = unroll_perm($user,$tr['*'],$perm, $one_level);
unset($tr['*']);
}
- // then apply group policies
+ // then apply not and group policies
foreach ($tr as $g=>$t) {
- if ($t & trmask_group && in_group($user,$g)) {
+ if ($t & trmask_not && $g != $user) {
+ $t = $t & ~trmask_not;
+ $perm = unroll_perm($user,$t,$perm, $one_level);
+ unset($tr[$g]);
+
+ } elseif ($t & trmask_group && in_group($user,$g)) {
// resolv user
$t = $t & ~trmask_group;
- $perm = unroll_perm($user,$t,$g, $perm, $one_level);
+ $perm = unroll_perm($user,$t,$perm, $one_level);
unset($tr[$g]);
}
}
// then apply user policy
if (isset($tr[$user])) {
- $perm = unroll_perm($user,$tr[$user],$user, $perm,$one_level);
+ $perm = unroll_perm($user,$tr[$user],$perm,$one_level);
unset($tr[$user]);
}
}
@@ -1483,6 +1439,8 @@
function check_perm($path,$trperm) {
global $gblLogin,$HAVE_TRUSTEE;
+ $path = str_replace("//","/",$path);
+
global $debug;
$debug.="
check_perm: on $path for perm ".display_trustee($trperm)."
\n";
@@ -1532,27 +1490,46 @@
function check_filename($file) {
if (strstr($file,"..")) Error("Security violation","No parent dir .. allowed in file name $file",1);
+ // remove deleted directory (for undelete to work)
+ $file = str_replace(".del/","",$file);
if (strstr($file,"/")) Error("Security violation","No slashes / allowed in file name $file",1);
}
+// bla/blo/../foo will return bla/foo
+function remove_parent($path) {
+ while (preg_match(",/[^/]+/\.\./,",$path)) {
+ $path = preg_replace(",/[^/]+/\.\./,","",$path);
+ }
+ if (substr($path,0,1) != "/") $path = "/".$path;
+ return $path;
+}
+
//////////////////////////////////////////////////////////////////
// functions to move HTTP server variables to global namespace
// [replacement for register_globals in php.ini]
function HTTP_GET_VAR($var) {
- global $HTTP_GET_VARS, $GLOBALS;
+ global $HTTP_GET_VARS, ${$var};
if (isset($HTTP_GET_VARS[$var])) {
- $GLOBALS[$var] = stripSlashes($HTTP_GET_VARS[$var]);
- return $GLOBALS[$var];
+ $$var = stripSlashes($HTTP_GET_VARS[$var]);
+ return $$var;
}
}
function HTTP_POST_VAR($var) {
- global $HTTP_POST_VARS, $GLOBALS;
+ global $HTTP_POST_VARS, ${$var};
if (isset($HTTP_POST_VARS[$var])) {
- $GLOBALS[$var] = stripSlashes($HTTP_POST_VARS[$var]);
- return $GLOBALS[$var];
+ $$var = $HTTP_POST_VARS[$var];
+ return $$var;
+ }
+}
+
+function HTTP_SERVER_VAR($var) {
+ global $HTTP_SERVER_VARS, ${$var};
+ if (isset($HTTP_SERVER_VARS[$var])) {
+ $$var = $HTTP_SERVER_VARS[$var];
+ return $$var;
}
}
@@ -1575,7 +1552,7 @@
// location of master docman configuration file
$docman_conf = "/etc/docman.conf";
if (! file_exists($docman_conf)) {
- $error = "Can't find master configuration file $docman_conf. See docman2/doc/upgrade.html#docman_conf for more informations";
+ $error = "Can't find master configuration file $docman_conf. See docman2/doc/upgrade.html#docman_conf for more informations";
error_log("docman: $error");
Error("docman not installed completly",$error);
@@ -1663,9 +1640,16 @@
// read mime.types
readMime();
+ if (! isset($gblPermNote)) {
+ $gblPermNote = trperm_r;
+ }
+
+ HTTP_POST_VAR("FN");
+
if ($HTTP_SERVER_VARS["REQUEST_METHOD"] == "POST") {
// take variables from server
- if (HTTP_POST_VAR("FN")) check_filename($FN);
+ if (HTTP_POST_VAR("FN"))
+ check_filename($FN);
if (HTTP_POST_VAR("DIR")) {
check_dirname($DIR);
$relDir = $DIR;
@@ -1676,7 +1660,6 @@
if (HTTP_POST_VAR("RELPATH")) check_dirname($RELPATH);
HTTP_POST_VAR("T");
HTTP_POST_VAR("CONFIRM");
-
} else {
// get
HTTP_GET_VAR("A");
@@ -1729,6 +1712,9 @@
$target = "$fsDir/$FILENAME";
}
+ if (! check_perm("$relDir/".basename($target), trperm_w))
+ Error("Access denied","User $gblLogin tried to upload $relDir/".basename($target)." without valid trustee.",1);
+
// backup old files first
$dir=dirname($target);
if (! file_exists($dir."/.bak")) {
@@ -1757,14 +1743,18 @@
case "SAVE" :
$path = $gblFsRoot . $RELPATH ;
$path=stripSlashes($path);
+
+ if (! check_perm("$RELPATH", trperm_w))
+ Error("Access denied","User $gblLogin tried to save $RELPATH without valid trustee.",1);
+
$writable = is_writeable($path) ;
$legaldir = is_writeable(dirname($path)) ;
$exists = (file_exists($path)) ? 1 : 0 ;
-// check for legal extension here as well
+ // FIX: more verbose error message
if (!($writable || (!$exists && $legaldir)))
Error("Write denied",$RELPATH) ;
$fh = fopen($path, "w") ;
- $FILEDATA=stripSlashes($FILEDATA);
+ HTTP_POST_VAR("FILEDATA");
fwrite($fh,$FILEDATA) ;
fclose($fh) ;
clearstatcache() ;
@@ -1773,10 +1763,18 @@
case "CREATE" :
// we know $fsDir exists
- if ($FN == "") break; // no filename!
- if (!is_writeable($fsDir)) Error("Write denied",$relDir) ;
- $path = $fsDir . "/" . $FN ; // file or dir to create
- $relPath = $relDir . "/" . $FN ;
+ if (! check_perm($relDir, trperm_w))
+ Error("Write access denied","You don't have permission to write in $relDir");
+ if ($T == "D") $type = "directory";
+ else $type ="file";
+ if ($FN == "") Error("Can't create $type","You must enter name of $type to create it.");
+ if (!is_writeable($fsDir)) Error("Write denied","User $gblLogin has trustee to write in $relDir but permissions on $fsDir are wrong!", 1) ;
+ $path = "$fsDir/$FN"; // file or dir to create
+ $relPath = "$relDir/$FN";
+
+ if (file_exists($path))
+ Error("Can't create $type","Object $relPath allready exists");
+
switch ( $T ) {
case "D" : // create a directory
if ( ! @mkdir($path,$gblDirPerms) )
@@ -1790,53 +1788,54 @@
// better keep it here altogether
// chmod perms to $gblFilePerms
if ( file_exists($path) && !is_writeable($path) )
- Error("File not writable", $relPath) ;
+ Error("File not writable", "User $gblLogin has trustee to write in $relPath but permissions on $path are wrong!", 1) ;
$fh = fopen($path, "w+") ;
if ($fh) {
fputs($fh,"\n");
fclose($fh) ;
LogIt($path,"file created",trperm_r | trperm_w);
} else {
- Error("Creation of file $relPath failed -- $path");
+ Error("Creation of file $relPath failed", "User $gblLogin has trustee to write in $relPath but creation of $path failed!", 1) ;
}
- $tstr = "$PHP_SELF?A=E&D=".urlencode($relDir)."&F=".urlencode($FN) ;
+ $tstr = $HTTP_SERVER_VARS["PHP_SELF"]."?A=E&D=".urlencode($relDir)."&F=".urlencode($FN) ;
header("Location: " . $tstr) ;
exit ;
}
break ;
case "DELETE" :
- if ( $CONFIRM != "on" ) break ;
+ if ( $CONFIRM != "on" ) break;
- $tstr = "Attempt to delete non-existing object or " ;
- $tstr .= "insufficient privileges: " ;
+ if ( isset($FN) && $FN != "") {
+ $path=$fsDir."/".$FN;
+ $what = "file";
+ } elseif (isset($DIR)) {
+ $path=$gblFsRoot."/".$DIR;
+ $what = "directory";
+ } else {
+ Error("Can't delete object","Can't find filename \$FN or dirname in \$DIR",1);
+ }
- if ( $FN != "") { // delete file
- $path = $fsDir . "/" . $FN ;
-
- $dir=dirname($path);
- $file=basename($path);
- if (! file_exists("$dir/.del")) {
- mkdir("$dir/.del",0700);
- }
+ if (! check_perm("$relDir/$FN", trperm_w))
+ Error("Access denied","User $gblLogin tried to erase $what $relDir/$FN without valid trustee.",1);
-// if ( ! @unlink($path) ) {
- if ( ! rename($path,"$dir/.del/$file") ) {
- LogIt($path,"file delete failed");
- Error("File delete failed", $tstr . $path) ;
- } else {
- LogIt($path,"file deleted",trperm_w);
- MoveTo("$dir/.log/$file","$dir/.del/.log/");
- MoveTo("$dir/.note/$file","$dir/.del/.note/");
- MoveTo("$dir/.lock/$file","$dir/.del/.lock/");
- }
- } else { // delete directory
- if ( ! @rrmdir($fsDir) ) {
- Error("Rmdir failed", $tstr . $fsDir) ;
- } else {
- LogIt($path,"dir deleted",trperm_w);
- $relDir = dirname($relDir) ; // move up
- }
+ $tstr = "Attempt to delete non-existing object or insufficient privileges: " ;
+
+ $dir=dirname($path);
+ $file=basename($path);
+
+ if (! file_exists("$dir/.del")) {
+ mkdir("$dir/.del",0700);
+ }
+
+ if ( ! @rename($path,"$dir/.del/$file") ) {
+ LogIt($path,"$what delete failed");
+ Error("Can't delete $what",$tstr."".$relDir."/".$FN."") ;
+ } else {
+ LogIt($path,"$what deleted",trperm_w);
+ MoveTo("$dir/.log/$file","$dir/.del/.log/");
+ MoveTo("$dir/.note/$file","$dir/.del/.note/");
+ MoveTo("$dir/.lock/$file","$dir/.del/.lock/");
}
break ;
@@ -1846,6 +1845,9 @@
if (substr($FN,0,4) != ".del") break ;
$file=substr($FN,4,strlen($FN)-4);
+ if (! check_perm("$relDir/$file", trperm_w))
+ Error("Access denied","User $gblLogin tried to undelete $relDir/$file without valid trustee.",1);
+
LogIt("$fsDir/.del/$file","undeleted",trperm_w);
MoveTo("$fsDir/.del/$file","$fsDir/");
MoveTo("$fsDir/.del/.log/$file","$fsDir/.log/");
@@ -1857,18 +1859,31 @@
case "RENAME" :
if ( $CONFIRM != "on" ) break ;
- $NEWNAME=stripSlashes($HTTP_POST_VARS["NEWNAME"]);
+ if (HTTP_POST_VAR("NEWNAME")) {
+ $dest = remove_parent($relDir.$NEWNAME);
+ if (! check_perm($relDir.$FN, trperm_w) ||
+ ! check_perm($dest, trperm_w) )
+ Error("Access denied","User $gblLogin tried to rename $relDir$FN to $dest without valid trustee.",1);
+ } else {
+ Error("Rename error","Can't find new name in var \$NEWNAME",1);
+ }
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");
+ case "NOTE" :
+ if (! HTTP_POST_VAR("NOTE"))
+ Error("Can't add note to object","Can't find var \$NOTE",1);
+ if (! check_perm("$relDir/$FN", trperm_w))
+ Error("Access denied","User $gblLogin tried to add note to $relDir/$FN without valid trustee.",1);
+
+ WriteNote("$fsDir/$FN",$NOTE);
break ;
case "UNLOCK" :
if ( $CONFIRM != "on" ) break ;
+ if (! check_perm("$relDir/$FN", trperm_w))
+ Error("Access denied","User $gblLogin tried to unlock $relDir/$FN without valid trustee.",1);
Unlock("$fsDir/$FN");
break ;
@@ -1882,7 +1897,7 @@
header("Location: ".$tstr) ;
exit ;
}
-
+
// check for mode.. navigate, code display, upload, or detail?
// $A=U : upload to path given in $D
// $A=E : display detail of file $D/$F and edit