--- docman.php 2001/06/04 08:20:55 1.41
+++ docman.php 2002/07/20 18:27:27 1.58
@@ -78,6 +78,11 @@
// from where to include auth_*.php modules?
$gblIncDir = "/home/httpd/docman";
+ // do we want to force download? (default is 0 for backward
+ // compatibility, but it's defined as 1 in docman.conf for all
+ // future applications!
+ $gblForceDownload = 0;
+
// username/password should not be system
// usernames/passwords !!
@@ -120,8 +125,16 @@
$gblImages = array( ".jpg",".jpeg",".gif",".png",".ico",
".bmp",".xbm") ;
+ // which files to hide (separated by ,)
+ $gblHide = "";
+
+ // Where are users? (by default in .htusers file)
+ $gblUsers = "htusers_file";
+
//////////////////////////////////////////////////////////////////
+ $gblVersion = "1.9";
+
function StartHTML($title,$text="") {
$title = "Document Manager " . $title ;
@@ -132,7 +145,7 @@
= $host . " " . $title ?>
-
+
@@ -151,20 +164,39 @@
//////////////////////////////////////////////////////////////////
function EndHTML() {
+
+global $gblDateFmt, $gblTimeFmt, $gblUserName, $PHP_SELF, $gblPw, $gblVersion;
+
?>
-= date($GLOBALS[gblDateFmt]) ?> -
-= date($GLOBALS[gblTimeFmt]) ?> -
-= $GLOBALS[gblUserName] ?>
- [?relogin== $GLOBALS[gblPw] ?>">logout]
+= date($gblDateFmt) ?> -
+= date($gblTimeFmt) ?> -
+= $gblUserName ?>
+
+ [= $url_title ?>]
-
ANYPORTAL(php) Site Manager
-
+
+Document Manager = $gblVersion ?>, based on ANYPORTAL(php) Site Manager
+
© 1999 by ANYPORTAL,
© 2000 by d@nger.org,
-© 2000 by DbP
+© 2000-2002 by DbP
@@ -354,7 +386,7 @@
$log=fopen($logname,"r");
$cl1=" class=LST"; $cl2="";
$logarr = array();
- while($line = fgetcsv($log,255,"\t")) {
+ while($line = fgetcsv($log,512,"\t")) {
$cl=$cl1; $cl1=$cl2; $cl2=$cl;
array_unshift($logarr,array($cl,$line[0],$line[1],$line[2],$line[3]));
}
@@ -630,7 +662,7 @@
function Navigate($fsRoot,$relDir) {
- global $gblEditable, $gblIcon, $gblModDays, $webRoot ;
+ global $gblEditable, $gblIcon, $gblModDays, $webRoot, $gblHide ;
$self = $GLOBALS["PHP_SELF"] ;
@@ -638,11 +670,13 @@
if (!is_dir($fsDir)) Error("Dir not found",$relDir) ;
+ $hide_items=",$gblHide,";
+
// read directory contents
if ( !($dir = @opendir($fsDir)) )
Error("Read Access denied",$relDir) ;
while ($item = readdir($dir)) {
- if ( $item == ".." || $item == "." || substr($item,0,1) == "." ) continue ;
+ if ( substr($item,0,1) == "." || strstr($hide_items,",$item,") ) continue ;
if ( is_dir($fsDir . $item) ) {
$dirList[] = $item ;
} else if ( is_file($fsDir . $item) ) {
@@ -661,7 +695,7 @@
// scan deleted files
if ( $GLOBALS[show_deleted] == 1 && ($dir = @opendir("$fsDir/.del")) ) {
while ($item = readdir($dir)) {
- if ( substr($item,0,1) == "." ) continue ;
+ if ( substr($item,0,1) == "." || strstr($hide_items,",$item,") ) continue ;
$fileList[] = ".del/$item" ;
}
closedir($dir) ;
@@ -682,7 +716,7 @@
CELLSPACING=3 WIDTH=\"100%\">" ;
// updir bar
- if ($fsDir != $fsRoot) {
+ if (chopsl($fsDir) != chopsl($fsRoot)) {
$parent = dirname($relDir) ;
if ($parent == "") $parent = "/" ;
?>
@@ -830,7 +864,7 @@
}
- if ($emptyDir) {
+ if ($emptyDir && $relDir != "") {
?>
@@ -931,6 +964,8 @@
$title = "(401 Unauthorized)" ;
$text = "No trespassing !" ;
+
+ global $PHP_AUTH_USER,$PHP_AUTH_PW,$gblPw,$relogin;
StartHTML($title,$text) ;
EndHTML() ;
@@ -985,7 +1020,7 @@
$msg=fgets($note,4096);
fclose($note);
}
- return StripSlashes($msg);
+ return HtmlSpecialChars(StripSlashes($msg));
}
@@ -1126,6 +1161,7 @@
$log=fopen("$gblFsRoot/.changelog","a+");
if (substr($target,0,strlen($gblFsRoot)) == $gblFsRoot)
$target=substr($target,strlen($gblFsRoot),strlen($target)-strlen($gblFsRoot));
+ $msg=str_replace("\t"," ",$msg);
fputs($log,time()."\t$target\t$GLOBALS[gblUserName]\t$msg\n");
fclose($log);
@@ -1137,7 +1173,11 @@
if (!file_exists("$gblFsRoot/.changelog")) return;
$log=fopen("$gblFsRoot/.changelog","r");
$logarr = array();
- while($line = fgetcsv($log,255,"\t")) {
+ while($line = fgetcsv($log,512,"\t")) {
+ while (sizeof($line) > 4) {
+ $tmp = array_pop($line);
+ $line.=" $tmp";
+ }
if ($day!=1 || ($day==1 && (time()-$line[0] < 24*60*60))) {
array_unshift($logarr,array($line[0],$line[1],$line[2],$line[3]));
}
@@ -1159,6 +1199,34 @@
//////////////////////////////////////////////////////////////////
+function Download($path) {
+ global $HTTP_USER_AGENT;
+ $file=basename($path);
+ $size = filesize($path);
+ //header("Content-Type: application/octet-stream");
+ header("Content-Type: application/force-download");
+ header("Content-Length: $size");
+ // IE5.5 just downloads index.php if we don't do this
+ if(preg_match("/MSIE 5.5/", $HTTP_USER_AGENT)) {
+ header("Content-Disposition: filename=$file");
+ } else {
+ header("Content-Disposition: attachment; filename=$file");
+ }
+ header("Content-Transfer-Encoding: binary");
+ $fh = fopen($path, "r");
+ fpassthru($fh);
+}
+
+
+//////////////////////////////////////////////////////////////////
+
+function chopsl($path) {
+ if (substr($path,strlen($path)-1,1) == "/") $path=substr($path,0,strlen($path)-1);
+ $path=str_replace("//","/",$path);
+ return $path;
+}
+
+//////////////////////////////////////////////////////////////////
// MAIN PROGRAM
// ============
// query parameters: capital letters
@@ -1173,45 +1241,43 @@
// forks before authentication: style sheet and hash
// creation if password not yet set.
- if ($STYLE == "get") { CSS() ; exit ; }
+ if (isset($STYLE) && $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;
- }
+ $fsScriptDir = dirname($SCRIPT_FILENAME) ;
+ // i.e. /home/httpd/html/docman
+
+ // read user-defined configuration
+ if (file_exists("$fsScriptDir/.docman.conf")) {
+ include("$fsScriptDir/.docman.conf");
}
- $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 ;
- }
+
+ // where do we get users from?
+ if (file_exists("$gblIncDir/$gblUsers.php")) {
+ include("$gblIncDir/$gblUsers.php");
+ } else {
+ Error("Configuration error","Can't find user handling module at $gblIncDir/$gblUsers.php ! Please fix $fsScriptDir/.docman.conf");
+ }
+
+ // if no password, or empty password logout
+ if (
+ isset($PHP_AUTH_USER) && (
+ !isset($relogin) || (
+ isset($relogin) && $relogin != md5($PHP_AUTH_USER.$PHP_AUTH_PW)
+ )
+ ) && (
+ $PHP_AUTH_PW == "" || !isset($PHP_AUTH_PW)
+ ) && !isset($force_login)
+ ) {
+ StartHTML("Logout completed","Your login credentials has been erased") ;
+ EndHTML() ;
+ exit ;
}
- fclose($htusers);
// authentication failure
if ( md5($PHP_AUTH_USER.$PHP_AUTH_PW) != $gblPw ||
- isset($relogin) && $gblPw == $relogin ) {
- header("WWW-authenticate: basic realm=\"$HTTP_HOST\"") ;
+ isset($relogin) && $gblPw == $relogin) {
+ $realm="$HTTP_HOST";
+ header("WWW-authenticate: basic realm=\"$realm\"") ;
header("HTTP/1.0 401 Unauthorized") ;
NoEntry() ;
exit ;
@@ -1238,9 +1304,6 @@
$relScriptDir = dirname($SCRIPT_NAME) ;
// i.e. /docman
- $fsScriptDir = dirname($SCRIPT_FILENAME) ;
- // i.e. /home/httpd/html/docman
-
// start on server root
// $gblFsRoot = substr($fsScriptDir,0, strlen($fsScriptDir)-strlen($relScriptDir)) ;
// or on script root
@@ -1259,9 +1322,6 @@
$FN=stripSlashes($FN);
- if (file_exists("$fsScriptDir/.docman.conf")) {
- include("$fsScriptDir/.docman.conf");
- }
switch ($POSTACTION) {
case "UPLOAD" :
@@ -1440,6 +1500,7 @@
// $A=Co : checkout file $D/$F
// $A=Ci : checkin file $D/$F
// $A=V : view file (do nothing except log)
+ // $A=I : include file .$F.php from $gblFsRoot
// default : display directory $D
switch ($A) {
@@ -1466,8 +1527,7 @@
case "Co" :
// checkout
Lock("$gblFsRoot/$relDir/$F");
- header("Content-Disposition: attachment; filename=$F" );
- Header("Location: $webRoot".urlpath("$relDir/$F"));
+ Download("$gblFsRoot/$relDir/$F");
exit;
case "Ci" :
$F=stripSlashes($F);
@@ -1483,8 +1543,12 @@
case "V" :
// view
LogIt("$gblFsRoot/$relDir/$F","viewed");
- header("Content-Disposition: attachment; filename=$F" );
- Header("Location: $webRoot".urlpath("$relDir/$F"));
+ if ($gblForceDownload) {
+ Download("$gblFsRoot/$relDir/$F");
+ } else {
+ header("Content-Disposition: attachment; filename=$F" );
+ Header("Location: $webRoot".urlpath("$relDir/$F"));
+ }
exit;
case "Ch" :
StartHTML("(File changes)","All changes chronologicaly...");
@@ -1496,6 +1560,19 @@
DisplayChangeLog(1);
EndHTML() ;
exit;
+ case "I" :
+ $F=stripSlashes($F);
+ $inc_file="${gblFsRoot}/.${F}.php";
+ if (!isset($F) || $F == "" || !file_exists($inc_file)) Error("Fatal error $inc_file"); // can't find file to include
+ if (!is_readable($inc_file))
+ Error("Read access to include file denied",".${F}.php");
+ $text = "Your include file should define \$text variable which holds this text and \$title variable which is page title";
+ $title = "You should define \$title variable with page title";
+ include($inc_file);
+ StartHTML($title, $text) ;
+ print "".GifIcon(up)." Back to front page.
";
+ EndHTML() ;
+ exit ;
}
// default: display directory $relDir