120 |
$gblImages = array( ".jpg",".jpeg",".gif",".png",".ico", |
$gblImages = array( ".jpg",".jpeg",".gif",".png",".ico", |
121 |
".bmp",".xbm") ; |
".bmp",".xbm") ; |
122 |
|
|
123 |
|
// which files to hide (separated by ,) |
124 |
|
$gblHide = ""; |
125 |
|
|
126 |
|
// Where are users? (by default in .htusers file) |
127 |
|
$gblUsers = "htusers_file"; |
128 |
|
|
129 |
////////////////////////////////////////////////////////////////// |
////////////////////////////////////////////////////////////////// |
130 |
|
|
131 |
function StartHTML($title,$text="") { |
function StartHTML($title,$text="") { |
242 |
$fsize = filesize($fsPath) ; |
$fsize = filesize($fsPath) ; |
243 |
$fmodified = date("$GLOBALS[gblDateFmt] $GLOBALS[gblTimeFmt]", filemtime($fsPath)) ; |
$fmodified = date("$GLOBALS[gblDateFmt] $GLOBALS[gblTimeFmt]", filemtime($fsPath)) ; |
244 |
$faccessed = date("$GLOBALS[gblDateFmt] $GLOBALS[gblTimeFmt]", fileatime($fsPath)) ; |
$faccessed = date("$GLOBALS[gblDateFmt] $GLOBALS[gblTimeFmt]", fileatime($fsPath)) ; |
245 |
$userinfo = posix_getpwuid(fileowner($fsPath)); |
$fuid=fileowner($fsPath); |
246 |
$grpinfo = posix_getgrgid(filegroup($fsPath)); |
$fgid=filegroup($fsPath); |
247 |
|
$userinfo = posix_getpwuid($fuid); |
248 |
|
$grpinfo = posix_getgrgid($fgid); |
249 |
echo "<PRE>"; |
echo "<PRE>"; |
250 |
if (!is_dir($fsPath)) echo "file size: " . $fsize . " Bytes<BR>" ; |
if (!is_dir($fsPath)) echo " file size: " . $fsize . " Bytes<BR>" ; |
251 |
echo "last modified: <B>" . $fmodified . "</B><BR>" ; |
echo "last modified: <B>" . $fmodified . "</B><BR>" ; |
252 |
echo "last accessed: <B>" . $faccessed . "</B><BR>" ; |
echo "last accessed: <B>" . $faccessed . "</B><BR>" ; |
253 |
echo " owner: <B>" . $userinfo["name"] . "</B><BR>" ; |
echo " owner: <B>" . $userinfo["name"] . " [$fuid]</B><BR>" ; |
254 |
echo " group: <B>" . $grpinfo["name"] . "</B><BR>" ; |
echo " group: <B>" . $grpinfo["name"] . " [$fgid]</B><BR>" ; |
255 |
echo " permissions: <B>" ; |
echo " permissions: <B>" ; |
256 |
echo printf( "%o", fileperms($fsPath) ) . "</B>" ; |
echo printf( "%o", fileperms($fsPath) ) . "</B>" ; |
257 |
echo "</PRE>" ; |
echo "</PRE>" ; |
636 |
|
|
637 |
function Navigate($fsRoot,$relDir) { |
function Navigate($fsRoot,$relDir) { |
638 |
|
|
639 |
global $gblEditable, $gblIcon, $gblModDays, $webRoot ; |
global $gblEditable, $gblIcon, $gblModDays, $webRoot, $gblHide ; |
640 |
|
|
641 |
$self = $GLOBALS["PHP_SELF"] ; |
$self = $GLOBALS["PHP_SELF"] ; |
642 |
|
|
644 |
|
|
645 |
if (!is_dir($fsDir)) Error("Dir not found",$relDir) ; |
if (!is_dir($fsDir)) Error("Dir not found",$relDir) ; |
646 |
|
|
647 |
|
$hide_items=",$gblHide,"; |
648 |
|
|
649 |
// read directory contents |
// read directory contents |
650 |
if ( !($dir = @opendir($fsDir)) ) |
if ( !($dir = @opendir($fsDir)) ) |
651 |
Error("Read Access denied",$relDir) ; |
Error("Read Access denied",$relDir) ; |
652 |
while ($item = readdir($dir)) { |
while ($item = readdir($dir)) { |
653 |
if ( $item == ".." || $item == "." || substr($item,0,1) == "." ) continue ; |
if ( substr($item,0,1) == "." || strstr($hide_items,",$item,") ) continue ; |
654 |
if ( is_dir($fsDir . $item) ) { |
if ( is_dir($fsDir . $item) ) { |
655 |
$dirList[] = $item ; |
$dirList[] = $item ; |
656 |
} else if ( is_file($fsDir . $item) ) { |
} else if ( is_file($fsDir . $item) ) { |
702 |
<?php |
<?php |
703 |
} |
} |
704 |
|
|
705 |
|
function plural($name,$count) { |
706 |
|
$out="$count $name"; |
707 |
|
if ($count > 1) { |
708 |
|
$out.="s"; |
709 |
|
} |
710 |
|
return $out; |
711 |
|
} |
712 |
|
|
713 |
// output subdirs |
// output subdirs |
714 |
if (sizeof($dirList) > 0) { |
if (sizeof($dirList) > 0) { |
715 |
sort($dirList) ; |
sort($dirList) ; |
716 |
?> |
?> |
717 |
|
|
718 |
<TR><TD></TD><TD COLSPAN=2 CLASS=TOP>DIRECTORY NAME</TD><TD COLSPAN=3 CLASS=TOP>DIRECTORY NOTE</TR> |
<TR><TD></TD><TD COLSPAN=2 CLASS=TOP>DIRECTORY NAME (<?= plural("dir",sizeof($dirList)) ?>)</TD><TD COLSPAN=3 CLASS=TOP>DIRECTORY NOTE</TR> |
719 |
|
|
720 |
<?php |
<?php |
721 |
while (list($key,$dir) = each($dirList)) { |
while (list($key,$dir) = each($dirList)) { |
740 |
|
|
741 |
<TR><TD></TD><TD COLSPAN=5><HR><B><?= $webRoot . $relDir ?> |
<TR><TD></TD><TD COLSPAN=5><HR><B><?= $webRoot . $relDir ?> |
742 |
</B></TD></TR> |
</B></TD></TR> |
743 |
<TR><TD></TD><TD CLASS=TOP>DOCUMENT NAME</TD> |
<TR><TD></TD><TD CLASS=TOP>DOCUMENT NAME (<?= plural("file",sizeof($fileList)) ?>)</TD> |
744 |
<TD><?= $gblIcon("blank").$gblIcon("blank") ?></TD> |
<TD><?= $gblIcon("blank").$gblIcon("blank") ?></TD> |
745 |
<TD CLASS=TOP>NOTE</TD> |
<TD CLASS=TOP>NOTE</TD> |
746 |
<TD CLASS=TOP>LAST UPDATE</TD><TD CLASS=TOP>FILE SIZE</TD></TR> |
<TD CLASS=TOP>LAST UPDATE</TD><TD CLASS=TOP>FILE SIZE</TD></TR> |
872 |
<NOBR>NAME <INPUT TYPE="TEXT" NAME="FN" SIZE=14> |
<NOBR>NAME <INPUT TYPE="TEXT" NAME="FN" SIZE=14> |
873 |
<INPUT TYPE="HIDDEN" NAME="POSTACTION" VALUE="CREATE"> |
<INPUT TYPE="HIDDEN" NAME="POSTACTION" VALUE="CREATE"> |
874 |
<INPUT TYPE="HIDDEN" NAME="DIR" VALUE="<?= $relDir ?>"> |
<INPUT TYPE="HIDDEN" NAME="DIR" VALUE="<?= $relDir ?>"> |
875 |
<INPUT TYPE="SUBMIT" VALUE="CREATE"></NOBR> |
<INPUT TYPE="SUBMIT" VALUE="CREATE" NAME="CREATE"> |
876 |
|
</NOBR> |
877 |
<NOBR>OR <A HREF="<?= $self ?>?A=U&D=<?= urlencode($relDir) ?>">UPLOAD</A> A FILE |
<NOBR>OR <A HREF="<?= $self ?>?A=U&D=<?= urlencode($relDir) ?>">UPLOAD</A> A FILE |
878 |
</NOBR> |
</NOBR> |
879 |
</TD></TR> |
</TD></TR> |
993 |
$msg=fgets($note,4096); |
$msg=fgets($note,4096); |
994 |
fclose($note); |
fclose($note); |
995 |
} |
} |
996 |
return StripSlashes($msg); |
return HtmlSpecialChars(StripSlashes($msg)); |
997 |
|
|
998 |
} |
} |
999 |
|
|
1076 |
|
|
1077 |
function safe_rename($fromdir,$fromfile,$tofile) { |
function safe_rename($fromdir,$fromfile,$tofile) { |
1078 |
function try_rename($from,$to) { |
function try_rename($from,$to) { |
1079 |
print "$from -> $to\n"; |
# print "$from -> $to\n"; |
1080 |
if (file_exists($from) && is_writable(dirname($to))) { |
if (file_exists($from) && is_writeable(dirname($to))) { |
1081 |
rename($from,$to); |
rename($from,$to); |
1082 |
} |
} |
1083 |
} |
} |
1092 |
$todir=dirname($to); |
$todir=dirname($to); |
1093 |
$tofile=basename($to); |
$tofile=basename($to); |
1094 |
|
|
1095 |
print "<pre>$fromdir / $fromfile -> $todir / $tofile\n\n"; |
# print "<pre>$fromdir / $fromfile -> $todir / $tofile\n\n"; |
1096 |
|
|
1097 |
try_rename("$fromdir/$fromfile","$todir/$tofile"); |
try_rename("$fromdir/$fromfile","$todir/$tofile"); |
1098 |
try_dir("$todir/.log"); |
try_dir("$todir/.log"); |
1183 |
// creation if password not yet set. |
// creation if password not yet set. |
1184 |
if ($STYLE == "get") { CSS() ; exit ; } |
if ($STYLE == "get") { CSS() ; exit ; } |
1185 |
|
|
1186 |
$htusers_file=dirname($SCRIPT_FILENAME)."/.htusers"; |
$fsScriptDir = dirname($SCRIPT_FILENAME) ; |
1187 |
if (! file_exists($htusers_file)) { |
// i.e. /home/httpd/html/docman |
1188 |
if (is_writable(dirname($SCRIPT_FILENAME))) { |
|
1189 |
$htusers=fopen($htusers_file,"a+"); |
// read user-defined configuration |
1190 |
fputs($htusers,"# Change owner of $htusers_file to root !!\n"); |
if (file_exists("$fsScriptDir/.docman.conf")) { |
1191 |
fputs($htusers,"demo:full name:[md5_hash|auth_*]:e-mail\n"); |
include("$fsScriptDir/.docman.conf"); |
|
fclose($htusers); |
|
|
Error("Proto user file created!","Please edit <tt>$htusers_file</tt> and set it correct permissions (<B>not writable by web server as it is now!</b>). You can add users using <tt>adduser.pl</tt> script!"); |
|
|
exit; |
|
|
} else { |
|
|
Error("Can't create proto user file!","Please make directory <tt>".dirname($htusers_file)."</tt> writable or create <tt>.htusers</tt> file by hand using <tt>adduser.pl</tt> script!"); |
|
|
exit; |
|
|
} |
|
1192 |
} |
} |
1193 |
$htusers=fopen($htusers_file,"r"); |
|
1194 |
while($user = fgetcsv($htusers,255,":")) { |
// where do we get users from? |
1195 |
if ($user[0] == $GLOBALS["PHP_AUTH_USER"]) { |
if (file_exists("$gblIncDir/$gblUsers.php")) { |
1196 |
$gblUserName=$user[1]; |
include("$gblIncDir/$gblUsers.php"); |
1197 |
$gblPw=$user[2]; |
} else { |
1198 |
if (substr($gblPw,0,5) == "auth_" && file_exists("$gblIncDir/$gblPw.php")) { |
Error("Configuration error","Can't find user handling module at <tt>$gblIncDir/$gblUsers.php</tt> ! Please fix <tt>$fsScriptDir/.docman.conf</tt>"); |
|
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 ; |
|
|
} |
|
1199 |
} |
} |
|
fclose($htusers); |
|
1200 |
|
|
1201 |
// authentication failure |
// authentication failure |
1202 |
if ( md5($PHP_AUTH_USER.$PHP_AUTH_PW) != $gblPw || |
if ( md5($PHP_AUTH_USER.$PHP_AUTH_PW) != $gblPw || |
1213 |
$relDir = urldecode($D) ; // then use GET |
$relDir = urldecode($D) ; // then use GET |
1214 |
} |
} |
1215 |
|
|
1216 |
|
$relDir=stripSlashes($relDir); |
1217 |
|
|
1218 |
if ($relDir == "/") $relDir = "" ; |
if ($relDir == "/") $relDir = "" ; |
1219 |
// default : website root = "" |
// default : website root = "" |
1220 |
|
|
1228 |
$relScriptDir = dirname($SCRIPT_NAME) ; |
$relScriptDir = dirname($SCRIPT_NAME) ; |
1229 |
// i.e. /docman |
// i.e. /docman |
1230 |
|
|
|
$fsScriptDir = dirname($SCRIPT_FILENAME) ; |
|
|
// i.e. /home/httpd/html/docman |
|
|
|
|
1231 |
// start on server root |
// start on server root |
1232 |
// $gblFsRoot = substr($fsScriptDir,0, strlen($fsScriptDir)-strlen($relScriptDir)) ; |
// $gblFsRoot = substr($fsScriptDir,0, strlen($fsScriptDir)-strlen($relScriptDir)) ; |
1233 |
// or on script root |
// or on script root |
1246 |
|
|
1247 |
$FN=stripSlashes($FN); |
$FN=stripSlashes($FN); |
1248 |
|
|
1249 |
|
|
1250 |
switch ($POSTACTION) { |
switch ($POSTACTION) { |
1251 |
case "UPLOAD" : |
case "UPLOAD" : |
1252 |
if (!is_writeable($fsDir)) Error("Write denied",$relDir) ; |
if (!is_writeable($fsDir)) Error("Write denied",$relDir) ; |
1322 |
// this functionality is doubled in DetailView(). |
// this functionality is doubled in DetailView(). |
1323 |
// better keep it here altogether |
// better keep it here altogether |
1324 |
// chmod perms to $gblFilePerms |
// chmod perms to $gblFilePerms |
1325 |
if ( file_exists($path) && !is_writable($path) ) |
if ( file_exists($path) && !is_writeable($path) ) |
1326 |
Error("File not writable", $relPath) ; |
Error("File not writable", $relPath) ; |
1327 |
$fh = fopen($path, "w+") ; |
$fh = fopen($path, "w+") ; |
1328 |
if ($fh) { |
if ($fh) { |