76 |
// error_reporting(4) ; // how verbose ? |
// error_reporting(4) ; // how verbose ? |
77 |
|
|
78 |
// from where to include auth_*.php modules? |
// from where to include auth_*.php modules? |
79 |
$gblIncDir = "/data/docman"; |
$gblIncDir = "/home/httpd/docman"; |
80 |
|
|
81 |
// username/password should not be system |
// username/password should not be system |
82 |
// usernames/passwords !! |
// usernames/passwords !! |
83 |
|
|
84 |
$gblPw = ""; |
$gblPw = ""; |
85 |
|
|
|
$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|auth_*]:e-mail\n"); |
|
|
fclose($htusers); |
|
|
} |
|
|
$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); |
|
|
} |
|
|
} |
|
|
$gblEmail=$user[3]; |
|
|
continue ; |
|
|
} |
|
|
} |
|
|
fclose($htusers); |
|
|
|
|
86 |
// date format |
// date format |
87 |
// $gblDateFmt="D, F d, Y"; |
// $gblDateFmt="D, F d, Y"; |
88 |
$gblDateFmt="Y-m-d"; |
$gblDateFmt="Y-m-d"; |
203 |
|
|
204 |
function DetailPage($fsRoot,$relDir,$fn) { |
function DetailPage($fsRoot,$relDir,$fn) { |
205 |
|
|
206 |
global $gblEditable, $gblImages ; |
global $gblEditable, $gblImages, $webRoot ; |
207 |
$self = $GLOBALS["PHP_SELF"] ; |
$self = $GLOBALS["PHP_SELF"] ; |
208 |
|
|
209 |
$relPath = $relDir . "/" . $fn ; |
$relPath = $relDir . "/" . $fn ; |
222 |
Error("Creation denied",$relDir) ; |
Error("Creation denied",$relDir) ; |
223 |
|
|
224 |
$text = "Use this page to view, modify or " ; |
$text = "Use this page to view, modify or " ; |
225 |
$text .= "delete a single document on this " ; |
if (is_dir($fsPath)) { |
226 |
|
$text .="delete a directory on this " ; |
227 |
|
} else { |
228 |
|
$text .= "delete a single document on this " ; |
229 |
|
}; |
230 |
$text .= "web site." ; |
$text .= "web site." ; |
231 |
$title = "(Detail Page)" ; |
$title = "(Detail Page)" ; |
232 |
StartHTML($title, $text) ; |
StartHTML($title, $text) ; |
236 |
$fsize = filesize($fsPath) ; |
$fsize = filesize($fsPath) ; |
237 |
$fmodified = date("$GLOBALS[gblDateFmt] $GLOBALS[gblTimeFmt]", filemtime($fsPath)) ; |
$fmodified = date("$GLOBALS[gblDateFmt] $GLOBALS[gblTimeFmt]", filemtime($fsPath)) ; |
238 |
$faccessed = date("$GLOBALS[gblDateFmt] $GLOBALS[gblTimeFmt]", fileatime($fsPath)) ; |
$faccessed = date("$GLOBALS[gblDateFmt] $GLOBALS[gblTimeFmt]", fileatime($fsPath)) ; |
239 |
echo "<PRE> file size: " . $fsize . " Bytes<BR>" ; |
$fuid=fileowner($fsPath); |
240 |
|
$fgid=filegroup($fsPath); |
241 |
|
$userinfo = posix_getpwuid($fuid); |
242 |
|
$grpinfo = posix_getgrgid($fgid); |
243 |
|
echo "<PRE>"; |
244 |
|
if (!is_dir($fsPath)) echo " file size: " . $fsize . " Bytes<BR>" ; |
245 |
echo "last modified: <B>" . $fmodified . "</B><BR>" ; |
echo "last modified: <B>" . $fmodified . "</B><BR>" ; |
246 |
echo "last accessed: <B>" . $faccessed . "</B><BR>" ; |
echo "last accessed: <B>" . $faccessed . "</B><BR>" ; |
247 |
echo " owner: <B>" . fileowner($fsPath) . "</B><BR>" ; |
echo " owner: <B>" . $userinfo["name"] . " [$fuid]</B><BR>" ; |
248 |
echo " group: <B>" . filegroup($fsPath) . "</B><BR>" ; |
echo " group: <B>" . $grpinfo["name"] . " [$fgid]</B><BR>" ; |
249 |
echo " permissions: <B>" ; |
echo " permissions: <B>" ; |
250 |
echo printf( "%o", fileperms($fsPath) ) . "</B>" ; |
echo printf( "%o", fileperms($fsPath) ) . "</B>" ; |
251 |
echo "</PRE>" ; |
echo "</PRE>" ; |
252 |
|
|
253 |
} |
} |
254 |
|
|
255 |
if ( $editable && ($writable || !$exists) && !$file_lock ) { |
if ( !is_dir($fsPath) && $editable && ($writable || !$exists) && !$file_lock ) { |
256 |
$fh = fopen($fsPath,"a+") ; |
$fh = fopen($fsPath,"a+") ; |
257 |
rewind($fh) ; |
rewind($fh) ; |
258 |
$fstr = fread($fh,filesize($fsPath)) ; |
$fstr = fread($fh,filesize($fsPath)) ; |
280 |
} |
} |
281 |
if ( !$file_lock && $ext!="" && strstr(join(' ',$gblImages),$ext) ) { |
if ( !$file_lock && $ext!="" && strstr(join(' ',$gblImages),$ext) ) { |
282 |
$info = getimagesize($fsPath) ; |
$info = getimagesize($fsPath) ; |
283 |
$tstr = "<IMG SRC=\"".urlpath($relPath)."\" BORDER=0 " ; |
$tstr = "<IMG SRC=\"$webRoot".urlpath($relPath)."\" BORDER=0 " ; |
284 |
$tstr .= $info[3] . " ALT=\"" . $fn . " - " ; |
$tstr .= $info[3] . " ALT=\"" . $fn . " - " ; |
285 |
$tstr .= (int)(($fsize+1023)/1024) . "Kb\">" ; |
$tstr .= (int)(($fsize+1023)/1024) . "Kb\">" ; |
286 |
// echo htmlentities($tstr) . "<BR><BR>" . $tstr ; |
// echo htmlentities($tstr) . "<BR><BR>" . $tstr ; |
359 |
array_unshift($logarr,array($cl,$line[0],$line[1],$line[2],$line[3])); |
array_unshift($logarr,array($cl,$line[0],$line[1],$line[2],$line[3])); |
360 |
} |
} |
361 |
fclose($log); |
fclose($log); |
362 |
print "<hr><br><b>CHANGES TO THIS FILE</b><br><table border=0 width=100%>\n"; |
if (is_dir("$fsDir/$fn")) { |
363 |
|
$whatis="DIRECTORY"; |
364 |
|
} else { |
365 |
|
$whatis="FILE"; |
366 |
|
} |
367 |
|
print "<hr><br><b>CHANGES TO THIS $whatis</b><br><table border=0 width=100%>\n"; |
368 |
$bakcount = 0; // start from 0, skip fist backup (it's current) |
$bakcount = 0; // start from 0, skip fist backup (it's current) |
369 |
while ($e = array_shift($logarr)) { |
while ($e = array_shift($logarr)) { |
370 |
if (strstr($e[4],"upload")) { |
if (strstr($e[4],"upload")) { |
371 |
if (file_exists("$bakdir/$bakcount/$name")) { |
if (file_exists("$bakdir/$bakcount/$name")) { |
372 |
$e[4]="<a href=\"".urlpath(dirname($relPath)."/.bak/$bakcount/$name")."\">$e[4]</a>"; |
$e[4]="<a href=\"$webRoot".urlpath(dirname($relPath)."/.bak/$bakcount/$name")."\">$e[4]</a>"; |
373 |
} |
} |
374 |
$bakcount++; |
$bakcount++; |
375 |
} |
} |
630 |
|
|
631 |
function Navigate($fsRoot,$relDir) { |
function Navigate($fsRoot,$relDir) { |
632 |
|
|
633 |
global $gblEditable, $gblIcon, $gblModDays ; |
global $gblEditable, $gblIcon, $gblModDays, $webRoot ; |
634 |
|
|
635 |
$self = $GLOBALS["PHP_SELF"] ; |
$self = $GLOBALS["PHP_SELF"] ; |
636 |
if (isset($GLOBALS["HTTPS"]) && $GLOBALS["HTTPS"] == "on") { |
|
637 |
$webRoot = "https://" . $GLOBALS["HTTP_HOST"] ; |
$fsDir = $fsRoot . $relDir . "/" ; // current directory |
|
} else { |
|
|
$webRoot = "http://" . $GLOBALS["HTTP_HOST"] ; |
|
|
} |
|
|
$fsDir = $fsRoot . $relDir . "/" ; // current directory |
|
638 |
|
|
639 |
if (!is_dir($fsDir)) Error("Dir not found",$relDir) ; |
if (!is_dir($fsDir)) Error("Dir not found",$relDir) ; |
640 |
|
|
699 |
sort($dirList) ; |
sort($dirList) ; |
700 |
?> |
?> |
701 |
|
|
702 |
<TR><TD></TD><TD COLSPAN=5 CLASS=TOP><HR>DIRECTORY NAME</TD></TR> |
<TR><TD></TD><TD COLSPAN=2 CLASS=TOP>DIRECTORY NAME</TD><TD COLSPAN=3 CLASS=TOP>DIRECTORY NOTE</TR> |
703 |
|
|
704 |
<?php |
<?php |
705 |
while (list($key,$dir) = each($dirList)) { |
while (list($key,$dir) = each($dirList)) { |
706 |
|
|
707 |
|
$info_url=$self."?A=E&F=".urlencode($dir)."&D=".urlencode($relDir); |
708 |
$tstr = "<A HREF=\"" . $self . "?D=" ; |
$tstr = "<A HREF=\"" . $self . "?D=" ; |
709 |
$tstr .= urlencode($relDir."/".$dir) ; |
$tstr .= urlencode($relDir."/".$dir) ; |
710 |
$tstr .= "\">" . $dir . "/</A>" ; |
$tstr .= "\">" . $dir . "/</A>" ; |
711 |
|
$note_html="<a href=\"$info_url#note\">".$gblIcon("note")."</a>".ReadNote($fsDir.$dir); |
712 |
?> |
?> |
713 |
|
|
714 |
<TR><TD><?= $gblIcon("fldr") ?></TD> |
<TR><TD> |
715 |
<TD COLSPAN=5 CLASS=LST><?= $tstr ?></TD></TR> |
<A HREF="<?= $info_url ?>" TITLE="View/Edit"> |
716 |
|
<?= $gblIcon("fldr") ?></A></TD> |
717 |
|
<TD COLSPAN=2 CLASS=LST><?= $tstr ?></TD> |
718 |
|
<TD COLSPAN=3 CLASS=LST><?= $note_html ?></TD></TR> |
719 |
|
|
720 |
<?php |
<?php |
721 |
} // iterate over dirs |
} // iterate over dirs |
856 |
<NOBR>NAME <INPUT TYPE="TEXT" NAME="FN" SIZE=14> |
<NOBR>NAME <INPUT TYPE="TEXT" NAME="FN" SIZE=14> |
857 |
<INPUT TYPE="HIDDEN" NAME="POSTACTION" VALUE="CREATE"> |
<INPUT TYPE="HIDDEN" NAME="POSTACTION" VALUE="CREATE"> |
858 |
<INPUT TYPE="HIDDEN" NAME="DIR" VALUE="<?= $relDir ?>"> |
<INPUT TYPE="HIDDEN" NAME="DIR" VALUE="<?= $relDir ?>"> |
859 |
<INPUT TYPE="SUBMIT" VALUE="CREATE"></NOBR> |
<INPUT TYPE="SUBMIT" VALUE="CREATE" NAME="CREATE"> |
860 |
|
</NOBR> |
861 |
<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 |
862 |
</NOBR> |
</NOBR> |
863 |
</TD></TR> |
</TD></TR> |
1058 |
|
|
1059 |
////////////////////////////////////////////////////////////////// |
////////////////////////////////////////////////////////////////// |
1060 |
|
|
1061 |
function safe_rename($from,$to) { |
function safe_rename($fromdir,$fromfile,$tofile) { |
1062 |
if (file_exists($from) && is_writable(dirname($to))) { |
function try_rename($from,$to) { |
1063 |
rename($from,$to); |
# print "$from -> $to\n"; |
1064 |
|
if (file_exists($from) && is_writeable(dirname($to))) { |
1065 |
|
rename($from,$to); |
1066 |
|
} |
1067 |
|
} |
1068 |
|
|
1069 |
|
function try_dir($todir) { |
1070 |
|
if (! file_exists($todir)) { |
1071 |
|
mkdir($todir,0700); |
1072 |
|
} |
1073 |
|
} |
1074 |
|
|
1075 |
|
$to="$fromdir/$tofile"; |
1076 |
|
$todir=dirname($to); |
1077 |
|
$tofile=basename($to); |
1078 |
|
|
1079 |
|
# print "<pre>$fromdir / $fromfile -> $todir / $tofile\n\n"; |
1080 |
|
|
1081 |
|
try_rename("$fromdir/$fromfile","$todir/$tofile"); |
1082 |
|
try_dir("$todir/.log"); |
1083 |
|
try_rename("$fromdir/.log/$fromfile","$todir/.log/$tofile"); |
1084 |
|
try_dir("$todir/.note"); |
1085 |
|
try_rename("$fromdir/.note/$fromfile","$todir/.note/$tofile"); |
1086 |
|
try_dir("$todir/.lock"); |
1087 |
|
try_rename("$fromdir/.lock/$fromfile","$todir/.lock/$tofile"); |
1088 |
|
try_dir("$todir/.bak"); |
1089 |
|
for($i=0;$i<=$GLOBALS[gblNumBackups];$i++) { |
1090 |
|
try_rename("$fromdir/.bak/$i/$fromfile","$todir/.bak/$i/$tofile"); |
1091 |
} |
} |
1092 |
} |
} |
1093 |
|
|
1094 |
|
|
1095 |
////////////////////////////////////////////////////////////////// |
////////////////////////////////////////////////////////////////// |
1096 |
|
|
1097 |
// recursivly delete directory |
// recursivly delete directory |
1167 |
// creation if password not yet set. |
// creation if password not yet set. |
1168 |
if ($STYLE == "get") { CSS() ; exit ; } |
if ($STYLE == "get") { CSS() ; exit ; } |
1169 |
|
|
1170 |
|
$htusers_file=dirname($SCRIPT_FILENAME)."/.htusers"; |
1171 |
|
if (! file_exists($htusers_file)) { |
1172 |
|
if (is_writeable(dirname($SCRIPT_FILENAME))) { |
1173 |
|
$htusers=fopen($htusers_file,"a+"); |
1174 |
|
fputs($htusers,"# Change owner of $htusers_file to root !!\n"); |
1175 |
|
fputs($htusers,"demo:full name:[md5_hash|auth_*]:e-mail\n"); |
1176 |
|
fclose($htusers); |
1177 |
|
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!"); |
1178 |
|
exit; |
1179 |
|
} else { |
1180 |
|
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!"); |
1181 |
|
exit; |
1182 |
|
} |
1183 |
|
} |
1184 |
|
$htusers=fopen($htusers_file,"r"); |
1185 |
|
while($user = fgetcsv($htusers,255,":")) { |
1186 |
|
if ($user[0] == $GLOBALS["PHP_AUTH_USER"]) { |
1187 |
|
$gblUserName=$user[1]; |
1188 |
|
$gblPw=$user[2]; |
1189 |
|
if (substr($gblPw,0,5) == "auth_" && file_exists("$gblIncDir/$gblPw.php")) { |
1190 |
|
require("$gblIncDir/$gblPw.php"); |
1191 |
|
if ($gblPw($user)) { |
1192 |
|
$gblPw=md5($PHP_AUTH_USER.$PHP_AUTH_PW); |
1193 |
|
} else { |
1194 |
|
$gblPw="error".md5($PHP_AUTH_USER.$PHP_AUTH_PW); |
1195 |
|
} |
1196 |
|
} |
1197 |
|
$gblEmail=$user[3]; |
1198 |
|
continue ; |
1199 |
|
} |
1200 |
|
} |
1201 |
|
fclose($htusers); |
1202 |
|
|
1203 |
// authentication failure |
// authentication failure |
1204 |
if ( md5($PHP_AUTH_USER.$PHP_AUTH_PW) != $gblPw || |
if ( md5($PHP_AUTH_USER.$PHP_AUTH_PW) != $gblPw || |
1205 |
isset($relogin) && $gblPw == $relogin ) { |
isset($relogin) && $gblPw == $relogin ) { |
1215 |
$relDir = urldecode($D) ; // then use GET |
$relDir = urldecode($D) ; // then use GET |
1216 |
} |
} |
1217 |
|
|
1218 |
|
$relDir=stripSlashes($relDir); |
1219 |
|
|
1220 |
if ($relDir == "/") $relDir = "" ; |
if ($relDir == "/") $relDir = "" ; |
1221 |
// default : website root = "" |
// default : website root = "" |
1222 |
|
|
1242 |
$fsDir = $gblFsRoot . $relDir ; // current directory |
$fsDir = $gblFsRoot . $relDir ; // current directory |
1243 |
if ( !is_dir($fsDir) ) Error("Dir not found",$relDir) ; |
if ( !is_dir($fsDir) ) Error("Dir not found",$relDir) ; |
1244 |
|
|
1245 |
|
if (isset($GLOBALS["HTTPS"]) && $GLOBALS["HTTPS"] == "on") { |
1246 |
|
$webRoot = "https://"; |
1247 |
|
} else { |
1248 |
|
$webRoot = "http://"; |
1249 |
|
} |
1250 |
|
$webRoot .= $GLOBALS["HTTP_HOST"] . $relScriptDir; |
1251 |
|
|
1252 |
$FN=stripSlashes($FN); |
$FN=stripSlashes($FN); |
1253 |
|
|
1254 |
|
if (file_exists("$fsScriptDir/.docman.conf")) { |
1255 |
|
include("$fsScriptDir/.docman.conf"); |
1256 |
|
} |
1257 |
|
|
1258 |
switch ($POSTACTION) { |
switch ($POSTACTION) { |
1259 |
case "UPLOAD" : |
case "UPLOAD" : |
1260 |
if (!is_writeable($fsDir)) Error("Write denied",$relDir) ; |
if (!is_writeable($fsDir)) Error("Write denied",$relDir) ; |
1330 |
// this functionality is doubled in DetailView(). |
// this functionality is doubled in DetailView(). |
1331 |
// better keep it here altogether |
// better keep it here altogether |
1332 |
// chmod perms to $gblFilePerms |
// chmod perms to $gblFilePerms |
1333 |
if ( file_exists($path) && !is_writable($path) ) |
if ( file_exists($path) && !is_writeable($path) ) |
1334 |
Error("File not writable", $relPath) ; |
Error("File not writable", $relPath) ; |
1335 |
$fh = fopen($path, "w+") ; |
$fh = fopen($path, "w+") ; |
1336 |
if ($fh) { |
if ($fh) { |
1402 |
if ( $CONFIRM != "on" ) break ; |
if ( $CONFIRM != "on" ) break ; |
1403 |
|
|
1404 |
Logit("$fsDir/$FN","renamed $FN to $NEWNAME"); |
Logit("$fsDir/$FN","renamed $FN to $NEWNAME"); |
1405 |
safe_rename("$fsDir/$FN","$fsDir/$NEWNAME"); |
safe_rename($fsDir,$FN,$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"); |
|
|
for($i=0;$i<=$GLOBALS[gblNumBackups];$i++) { |
|
|
safe_rename("$fsDir/.bak/$i/$FN","$fsDir/.bak/$i/$NEWNAME"); |
|
|
} |
|
|
|
|
1406 |
break ; |
break ; |
1407 |
|
|
1408 |
case "NOTE" : |
case "NOTE" : |
1448 |
case "E" : |
case "E" : |
1449 |
$F=stripSlashes($F); |
$F=stripSlashes($F); |
1450 |
// detail of $relDir/$F |
// detail of $relDir/$F |
1451 |
if (is_file("$gblFsRoot/$relDir/$F")) DetailPage($gblFsRoot, $relDir, $F) ; |
if (is_file("$gblFsRoot/$relDir/$F") || is_dir("$gblFsRoot/$relDir/$F")) DetailPage($gblFsRoot, $relDir, $F) ; |
1452 |
exit ; |
exit ; |
1453 |
case "C" : |
case "C" : |
1454 |
$F=stripSlashes($F); |
$F=stripSlashes($F); |
1459 |
// checkout |
// checkout |
1460 |
Lock("$gblFsRoot/$relDir/$F"); |
Lock("$gblFsRoot/$relDir/$F"); |
1461 |
header("Content-Disposition: attachment; filename=$F" ); |
header("Content-Disposition: attachment; filename=$F" ); |
1462 |
Header("Location: ".urlpath("$relDir/$F")); |
Header("Location: $webRoot".urlpath("$relDir/$F")); |
1463 |
exit; |
exit; |
1464 |
case "Ci" : |
case "Ci" : |
1465 |
$F=stripSlashes($F); |
$F=stripSlashes($F); |
1476 |
// view |
// view |
1477 |
LogIt("$gblFsRoot/$relDir/$F","viewed"); |
LogIt("$gblFsRoot/$relDir/$F","viewed"); |
1478 |
header("Content-Disposition: attachment; filename=$F" ); |
header("Content-Disposition: attachment; filename=$F" ); |
1479 |
Header("Location: ".urlpath("$relDir/$F")); |
Header("Location: $webRoot".urlpath("$relDir/$F")); |
1480 |
exit; |
exit; |
1481 |
case "Ch" : |
case "Ch" : |
1482 |
StartHTML("(File changes)","All changes chronologicaly..."); |
StartHTML("(File changes)","All changes chronologicaly..."); |