--- docman.php 2002/07/27 14:45:30 1.3 +++ docman.php 2002/07/27 19:12:42 1.4 @@ -84,14 +84,14 @@ LoadLanguage($HTTP_SERVER_VARS["HTTP_ACCEPT_LANGUAGE"]); // for security and configuration - $realm="$HTTP_HOST"; // FIX + $realm=$HTTP_SERVER_VARS[HTTP_HOST]; $fsDocumentRoot = dirname($HTTP_SERVER_VARS[SCRIPT_FILENAME]); if ($fsDocumentRoot == "") Error("Configuration error","Can't get SCRIPT_FILENAME from your web server. Please set \$fsDocumentRoot in \$",1); // globals for later - $gblLogin = $PHP_AUTH_USER; - $gblPasswd = $PHP_AUTH_PW; + $gblLogin = $HTTP_SERVER_VARS[PHP_AUTH_USER]; + $gblPasswd = $HTTP_SERVER_VARS[PHP_AUTH_PW]; ////////////////////////////////////////////////////////////////// @@ -109,11 +109,11 @@ function StartHTML($title,$text="") { - global $html,$fsDocumentRoot; + global $html,$fsDocumentRoot,$HTTP_SERVER_VARS; $title = $gblTitle." ".$title ; - $host = $GLOBALS["HTTP_HOST"] ; - $self = $GLOBALS["PHP_SELF"] ; + $host = $HTTP_SERVER_VARS["HTTP_HOST"] ; + $self = $HTTP_SERVER_VARS["PHP_SELF"] ; if (file_exists("$fsDocumentRoot/docman.css")) { $css=dirname($self)."/docman.css"; @@ -152,8 +152,8 @@ function DetailPage($fsRoot,$relDir,$fn) { - global $gblEditable, $gblImages, $webRoot, $html ; - $self = $GLOBALS["PHP_SELF"] ; + global $gblEditable, $gblImages, $webRoot, $html, $HTTP_SERVER_VARS ; + $self = $HTTP_SERVER_VARS["PHP_SELF"] ; $relPath = $relDir . "/" . $fn ; $fsPath = $fsRoot . $relPath ; @@ -572,9 +572,10 @@ function Navigate($fsRoot,$relDir) { global $gblEditable, $gblIcon, $gblModDays, $webRoot, $gblHide, - $HTTP_GET_VARS, $html; + $gblIgnoreUnknownFileType, + $HTTP_GET_VARS, $html, $realm_config; - $self = $GLOBALS["PHP_SELF"] ; + $self = $HTTP_SERVER_VARS["PHP_SELF"] ; if ($relDir == "") $relDir = "/"; @@ -584,34 +585,31 @@ $hide_items=",$gblHide,"; -#display_all_trustee(); -print "-- $fsDir --"; - // read directory contents if ( !($dir = @opendir($fsDir)) ) - Error("Read Access denied",$relDir) ; + Error("Read Access denied",$relDir,1) ; while ($item = readdir($dir)) { -print "$item, "; if ( substr($item,0,1) == "." || strstr($hide_items,",$item,") ) continue ; - if ((is_dir($fsDir.$item) || is_link ($fsDir.$item)) && check_perm($relDir.$item,trperm_b)) { - $dirList[$item] = $item ; - $dirNote[$item] = ReadNote($fsDir.$item); - } else if ( is_file($fsDir.$item) && check_perm($relDir.$item,trperm_r) ) { - $fileList[$item] = $item ; - $fileDate[$item] = filemtime($fsDir.$item) ; - $fileSize[$item] = filesize($fsDir.$item) ; - $fileNote[$item] = ReadNote($fsDir.$item); + if (is_dir($fsDir.$item) || is_link ($fsDir.$item)) { + if (check_perm($relDir.$item,trperm_b)) { + $dirList[$item] = $item ; + $dirNote[$item] = ReadNote($fsDir.$item); + } + } else if (is_file($fsDir.$item)) { + if (check_perm($relDir.$item,trperm_r)) { + $fileList[$item] = $item ; + $fileDate[$item] = filemtime($fsDir.$item) ; + $fileSize[$item] = filesize($fsDir.$item) ; + $fileNote[$item] = ReadNote($fsDir.$item); + } } else { - // unknown file type - // $text = "Could not determine file type of " ; - // Error("File Error", $text.$relDir."/".$item) ; - // exit ; + if (! $gblIgnoreUnknownFileType) Error("File Type Error", "Item ".$fsDir.$item." is not file, directory or link. If you want to ignore errors like this, set \$gblIgnoreUnknownFileType = 1 in $realm_config.",1); } } closedir($dir) ; // scan deleted files - if ( $GLOBALS[show_deleted] == 1 && ($dir = @opendir("$fsDir/.del")) ) { + if ( $HTTP_GET_VARS["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" ; @@ -626,7 +624,7 @@ // start navigation page $text = "Use this page to add, delete"; - if (! isset($show_deleted)) { + if (! isset($HTTP_GET_VARS[show_deleted])) { $text .= ", undelete"; } $text .= " or revise files on this web site." ; @@ -788,8 +786,7 @@ $file_lock=CheckLock($path); - $file_url_html="" ; if (substr($file,0,5) != ".del/") { @@ -804,8 +801,7 @@ if ($file_lock) { if ($file_lock == $GLOBALS[gblUserName]) { - $b.="" ; $file_url_html=$b; $b.=$gblIcon("checkin")."" ; @@ -819,14 +815,12 @@ $file_url_html = "$file $a"; } } else { - $b.="" ; - $b.=$gblIcon("checkout")."" ; + $b.=$gblIcon("checkout").""; if ( $ext=="" || strstr(join(" ",$gblEditable),$ext) ) { - $b.="" ; $b.=$gblIcon("view")."" ; } else { @@ -896,36 +890,13 @@ function UploadPage($fsRoot, $relDir, $filename="") { - $self = $GLOBALS["PHP_SELF"] ; + global $html, $HTTP_SERVER_VARS; + + $self = $HTTP_SERVER_VARS["PHP_SELF"] ; if ($relDir == "") $relDir = "/" ; -?> -

-
-
-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:

-
-
-
-
- -
-

+ include("$html/UploadPage.html"); -$date$time$dir/$file$e[2]$e[3]\n"; + 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.

"; } ////////////////////////////////////////////////////////////////// -function Download($path) { - global $HTTP_USER_AGENT; - $file=basename($path); +function Download($path,$force=0) { + global $HTTP_SERVER_VARS,$mime_type; + + // default transfer-encoding + $encoding = "binary"; + + // known transfer encodings + $encoding_ext = array( + "gz" => "x-gzip", + "Z" => "x-compress", + ); + + $file = basename($path); $size = filesize($path); - //header("Content-Type: application/octet-stream"); - header("Content-Type: application/force-download"); - header("Content-Length: $size"); + + $ext_arr = explode(".",$file); + $ext = array_pop($ext_arr); + if ($encoding_ext[$ext]) { + $encoding = $encoding_ext[$ext]; + $ext = array_pop($ext_arr); + } + + if ($force || !isset($mime_type[$ext])) { + header("Content-Type: application/force-download"); + } else { + header("Content-Type: $mime_type[$ext]"); + } + // IE5.5 just downloads index.php if we don't do this - if(preg_match("/MSIE 5.5/", $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"); } - header("Content-Transfer-Encoding: binary"); + + header("Content-Transfer-Encoding: $encoding"); $fh = fopen($path, "r"); fpassthru($fh); } @@ -1447,6 +1442,30 @@ return($return); } +////////////////////////////////////////////////////////////////// + +function readMime() { + global $mime_type; + + if (! isset($gblMimeTypes)) { + $gblMimeTypes = "/etc/mime.types"; + } + + $mime = @fopen($gblMimeTypes,"r"); + + if (! $mime) Error("Can't read MIME types","$gblMimeTypes file not found. You can setup other mime.types file using \$gblMimeTypes in $realm_config"); + + while($line = fgets($mime,80)) { + if (substr($line,0,1) == "#") continue; // skip comment + $arr = preg_split("/[\s\t]+/",$line); + $type = array_shift($arr); + while ($ext = array_shift($arr)) { + $mime_type[$ext] = $type; + } + } + + fclose($mime); +} ////////////////////////////////////////////////////////////////// // MAIN PROGRAM @@ -1529,10 +1548,13 @@ isset($relogin) && $secHash == $relogin) { header("WWW-authenticate: basic realm=\"$realm\"") ; header("HTTP/1.0 401 Unauthorized") ; +phpinfo(); Error("401 Unauthorized","No trespassing !"); - exit ; } + // read mime.types + readMime(); + // get current directory relative to $gblFsRoot $relDir = $DIR ; // from POST if ($relDir == "") { // not defined in POST ? @@ -1561,26 +1583,42 @@ $fsDir = $gblFsRoot . $relDir ; // current directory if ( !is_dir($fsDir) ) Error("Dir not found",$relDir) ; - if (isset($GLOBALS["HTTPS"]) && $GLOBALS["HTTPS"] == "on") { + if (isset($HTTP_SERVER_VARS["HTTPS"]) && $HTTP_SERVER_VARS["HTTPS"] == "on") { $webRoot = "https://"; } else { $webRoot = "http://"; } - $webRoot .= $GLOBALS["HTTP_HOST"] . $relScriptDir; + $webRoot .= $HTTP_SERVER_VARS["HTTP_HOST"] . $relScriptDir; - $FN=stripSlashes($FN); + // take variables from server + $FN=stripSlashes($HTTP_POST_VARS["FN"]); + $DIR=stripSlashes($HTTP_POST_VARS["DIR"]); + $RELPATH=stripSlashes($HTTP_POST_VARS["RELPATH"]); + $T=stripSlashes($HTTP_POST_VARS["T"]); + + // get + $A=stripSlashes($HTTP_GET_VARS["A"]); + $D=stripSlashes($HTTP_GET_VARS["D"]); + +// if (isset($F)) Error("Document manager system error","variable $F shouldn't be set here (re-check old code)",1); +// $F=stripSlashes($HTTP_SERVER_VARS["PATH_INFO"]); + $F=stripSlashes($HTTP_GET_VARS["F"]); - switch ($POSTACTION) { + switch ($HTTP_POST_VARS["POSTACTION"]) { case "UPLOAD" : + $FN_name=stripSlashes($HTTP_POST_FILES["FN"]["tmp_name"]); if (!is_writeable($fsDir)) Error("Write denied",$relDir) ; if (strstr($FN_name,"/")) Error("Non-conforming filename") ; // TODO : should rather check for escapeshellcmds // but maybe RFC 18xx asserts safe filenames .... - $source = $FN ; + $source = $FN_name ; + print "-- $source -- $FN_name -- $HTTP_POST_FILES[FN] -- "; +// phpinfo(); if (! file_exists($source)) { Error("You must select file with browse to upload it!"); } + $FILENAME = $HTTP_POST_VARS["FILENAME"]; if (! isset($FILENAME)) { // from update file $target = "$fsDir/$FN_name" ; } else { @@ -1680,9 +1718,8 @@ // if ( ! @unlink($path) ) { if ( ! rename($path,"$dir/.del/$file") ) { - Error("File delete failed", $tstr . $path) ; LogIt($path,"file delete failed"); - exit ; + Error("File delete failed", $tstr . $path) ; } else { LogIt($path,"file deleted",trperm_w); MoveTo("$dir/.log/$file","$dir/.del/.log/"); @@ -1756,13 +1793,12 @@ if (!is_writeable($gblFsRoot . $relDir)) Error("Write access denied",$relDir) ; $text = "Use this page to upload a single " ; - $text .= "file to $HTTP_HOST." ; + $text .= "file to $realm." ; StartHTML("(Upload Page)", $text) ; UploadPage($gblFsRoot, $relDir) ; EndHTML() ; exit ; case "E" : - $F=stripSlashes($F); // detail of $relDir/$F if (is_file("$gblFsRoot/$relDir/$F") || is_dir("$gblFsRoot/$relDir/$F")) DetailPage($gblFsRoot, $relDir, $F) ; exit ; @@ -1782,7 +1818,7 @@ if (!is_writeable($gblFsRoot . $relDir)) Error("Write access denied",$relDir) ; $text = "Use this page to update a single " ; - $text .= "file to $HTTP_HOST." ; + $text .= "file to $realm." ; StartHTML("(Update file Page)", $text) ; UploadPage($gblFsRoot, $relDir, $F) ; EndHTML() ; @@ -1817,7 +1853,7 @@ $title = "You should define \$title variable with page title"; include($inc_file); StartHTML($title, $text) ; - print "

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

"; + print "

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

"; EndHTML() ; exit ; }