35 |
/* existent address after file modifications. */ |
/* existent address after file modifications. */ |
36 |
|
|
37 |
/* |
/* |
|
2000-07-25 Dobrica Pavlinusic <dpavlin@rot13.org> |
|
38 |
|
|
39 |
nuked exec calls (unsecure) |
This project is now called Directory Manager. |
|
nuked writeable function (replaced by php is_writeable) |
|
|
added support for https (tested with apache+mod_ssl) |
|
|
added users file |
|
|
date format user-selectable |
|
|
cycle backup files in bak directory |
|
|
support links as directoryes (for now) |
|
|
support of file history logging |
|
|
undelete capabilities (delete moves to .del directory) |
|
40 |
|
|
41 |
2000-07-26 DbP |
For more info, please see web pages at |
42 |
|
http://www.rot13.org/~dpavlin/docman.html |
43 |
|
|
44 |
added more checking on entered filename (when creating file/dir) |
It's relased under GPL by |
45 |
added rename option |
Dobrica Pavlinusic <dpavlin@rot13.org> |
46 |
|
|
47 |
|
|
48 |
IMPORTANT INSTALLATION NOTE: |
IMPORTANT INSTALLATION NOTE: |
51 |
deleted files! |
deleted files! |
52 |
|
|
53 |
.htusers is in form: |
.htusers is in form: |
54 |
login:Real Name:md5(loginpassword) |
login:Real Name:[md5(loginpassword)|auth_*]:email@host.dom |
55 |
|
|
56 |
|
|
57 |
TODO: |
TODO: |
58 |
mixed file/directory output (add type to each entry, |
mixed file/directory output (add type to each entry, |
59 |
real support for links) |
real support for links) |
60 |
retrieve old versions of files (overwritten) |
access controll |
61 |
show last lock date |
|
|
|
|
62 |
*/ |
*/ |
63 |
|
|
64 |
////////////////////////////////////////////////////////////////// |
////////////////////////////////////////////////////////////////// |
71 |
|
|
72 |
// GLOBAL PARAMETERS |
// GLOBAL PARAMETERS |
73 |
// ================= |
// ================= |
74 |
// Make modifications here to suit siteman to your needs |
// Make modifications here to suit docman to your needs |
75 |
|
|
76 |
// error_reporting(4) ; // how verbose ? |
// error_reporting(4) ; // how verbose ? |
77 |
|
|
78 |
|
// from where to include auth_*.php modules? |
79 |
|
$gblIncDir = "/home/httpd/docman"; |
80 |
|
|
81 |
// username/password should not be system |
// username/password should not be system |
82 |
// usernames/passwords !! |
// usernames/passwords !! |
83 |
|
|
|
// $gblPw = "hash_of_your_username_and_password" ; |
|
|
|
|
|
// $gblAuth = false ; // use builtin authentication |
|
|
$gblAuth = true ; // use builtin authentication |
|
|
$gblHash = "md5" ; // hash function to use |
|
|
|
|
84 |
$gblPw = ""; |
$gblPw = ""; |
85 |
|
|
86 |
if ($gblAuth) { |
$htusers_file=dirname($SCRIPT_FILENAME)."/.htusers"; |
87 |
$htusers_file=dirname($SCRIPT_FILENAME)."/.htusers"; |
if (! file_exists($htusers_file)) { |
88 |
if (! file_exists($htusers_file)) { |
$htusers=fopen($htusers_file,"a+"); |
89 |
$htusers=fopen($htusers_file,"a+"); |
fputs($htusers,"# Change owner of $htusers_file to root !!\n"); |
90 |
fputs($htusers,"# Change owner of $htusers_file to root !!\n"); |
fputs($htusers,"demo:full name:[md5_hash|auth_*]:e-mail\n"); |
91 |
fputs($htusers,"demo:full name:md5_hash\n"); |
fclose($htusers); |
92 |
fclose($htusers); |
} |
93 |
} |
$htusers=fopen($htusers_file,"r"); |
94 |
$htusers=fopen($htusers_file,"r"); |
while($user = fgetcsv($htusers,255,":")) { |
95 |
while($user = fgetcsv($htusers,255,":")) { |
if ($user[0] == $GLOBALS["PHP_AUTH_USER"]) { |
96 |
if ($user[0] == $GLOBALS["PHP_AUTH_USER"]) { |
$gblUserName=$user[1]; |
97 |
$gblUserName=$user[1]; |
$gblPw=$user[2]; |
98 |
$gblPw=$user[2]; |
if (substr($gblPw,0,5) == "auth_" && file_exists("$gblIncDir/$gblPw.php")) { |
99 |
$gblEmail=$user[3]; |
require("$gblIncDir/$gblPw.php"); |
100 |
continue ; |
if ($gblPw($user)) { |
101 |
|
$gblPw=md5($PHP_AUTH_USER.$PHP_AUTH_PW); |
102 |
|
} else { |
103 |
|
$gblPw="error".md5($PHP_AUTH_USER.$PHP_AUTH_PW); |
104 |
|
} |
105 |
} |
} |
106 |
|
$gblEmail=$user[3]; |
107 |
|
continue ; |
108 |
} |
} |
|
fclose($htusers); |
|
109 |
} |
} |
110 |
|
fclose($htusers); |
111 |
|
|
112 |
|
// date format |
113 |
// $gblDateFmt="D, F d, Y"; |
// $gblDateFmt="D, F d, Y"; |
|
// $gblTimeFmt="g:i:sA"; |
|
|
|
|
114 |
$gblDateFmt="Y-m-d"; |
$gblDateFmt="Y-m-d"; |
115 |
|
|
116 |
|
// time format |
117 |
|
// $gblTimeFmt="g:i:sA"; |
118 |
$gblTimeFmt="H:i:s"; |
$gblTimeFmt="H:i:s"; |
119 |
|
|
120 |
// Number of backup files to keep |
// Number of backup files to keep |
126 |
// choose GifIcon below unless you have the M$ |
// choose GifIcon below unless you have the M$ |
127 |
// WingDings font installed on your system |
// WingDings font installed on your system |
128 |
|
|
129 |
$gblIcon = "GifIcon" ; // MockIcon or GifIcon |
$gblIcon="GifIcon"; // MockIcon or GifIcon |
130 |
|
|
131 |
// the directory below should be /icons/ or /icons/small/ |
// the directory below should be /icons/ or /icons/small/ |
132 |
// on Apache; a set of icons is included in the distribution |
// on Apache; a set of icons is included in the distribution |
133 |
|
|
134 |
$gblIconLocation = "/icons/" ; |
$gblIconLocation="/icons/"; |
135 |
|
|
136 |
// files you want to be able to edit in text mode |
// files you want to be able to edit in text mode |
137 |
// and view with (primitive) syntax highlighting |
// and view with (primitive) syntax highlighting |
150 |
|
|
151 |
function StartHTML($title,$text="") { |
function StartHTML($title,$text="") { |
152 |
|
|
153 |
$title = "Site Manager " . $title ; |
$title = "Document Manager " . $title ; |
154 |
$host = $GLOBALS["HTTP_HOST"] ; |
$host = $GLOBALS["HTTP_HOST"] ; |
155 |
$self = $GLOBALS["PHP_SELF"] ; |
$self = $GLOBALS["PHP_SELF"] ; |
156 |
?> |
?> |
369 |
$bakdir=dirname("$fsDir/$fn")."/.bak"; |
$bakdir=dirname("$fsDir/$fn")."/.bak"; |
370 |
if (file_exists($logname)) { |
if (file_exists($logname)) { |
371 |
$log=fopen($logname,"r"); |
$log=fopen($logname,"r"); |
372 |
$cl1=" class=lst"; $cl2=""; |
$cl1=" class=LST"; $cl2=""; |
373 |
$logarr = array(); |
$logarr = array(); |
374 |
while($line = fgetcsv($log,255,"\t")) { |
while($line = fgetcsv($log,255,"\t")) { |
375 |
$cl=$cl1; $cl1=$cl2; $cl2=$cl; |
$cl=$cl1; $cl1=$cl2; $cl2=$cl; |
381 |
while ($e = array_shift($logarr)) { |
while ($e = array_shift($logarr)) { |
382 |
if (strstr($e[4],"upload")) { |
if (strstr($e[4],"upload")) { |
383 |
if (file_exists("$bakdir/$bakcount/$name")) { |
if (file_exists("$bakdir/$bakcount/$name")) { |
384 |
$e[4]="<a href=\"".dirname($relPath)."/.bak/$bakcount/$name\">$e[4]</a>"; |
$e[4]="<a href=\"".urlpath(dirname($relPath)."/.bak/$bakcount/$name")."\">$e[4]</a>"; |
385 |
} |
} |
386 |
$bakcount++; |
$bakcount++; |
387 |
} |
} |
646 |
|
|
647 |
$self = $GLOBALS["PHP_SELF"] ; |
$self = $GLOBALS["PHP_SELF"] ; |
648 |
if (isset($GLOBALS["HTTPS"]) && $GLOBALS["HTTPS"] == "on") { |
if (isset($GLOBALS["HTTPS"]) && $GLOBALS["HTTPS"] == "on") { |
649 |
$webRoot = "https://" . $GLOBALS["SERVER_NAME"] ; |
$webRoot = "https://" . $GLOBALS["HTTP_HOST"] ; |
650 |
} else { |
} else { |
651 |
$webRoot = "http://" . $GLOBALS["SERVER_NAME"] ; |
$webRoot = "http://" . $GLOBALS["HTTP_HOST"] ; |
652 |
} |
} |
653 |
$fsDir = $fsRoot . $relDir . "/" ; // current directory |
$fsDir = $fsRoot . $relDir . "/" ; // current directory |
654 |
|
|
825 |
|
|
826 |
<?php |
<?php |
827 |
} // iterate over files |
} // iterate over files |
828 |
} // end if no files |
} else { // end if no files |
829 |
|
?> |
830 |
|
<TR><TD></TD><TD COLSPAN=5 CLASS=LST> |
831 |
|
No files in this directory |
832 |
|
</TD></TR> |
833 |
|
<? |
834 |
|
} |
835 |
|
|
836 |
if ($emptyDir) { |
if ($emptyDir) { |
837 |
?> |
?> |
851 |
|
|
852 |
<TR><TD></TD><TD COLSPAN=5><HR></TD></TR> |
<TR><TD></TD><TD COLSPAN=5><HR></TD></TR> |
853 |
|
|
|
<TR><TD></TD><TD COLSPAN=5> |
|
854 |
<? |
<? |
855 |
if (file_exists(".info.inc")) { |
if (file_exists(".info.inc")) { |
856 |
|
print "<TR><TD></TD><TD COLSPAN=5>"; |
857 |
include(".info.inc"); |
include(".info.inc"); |
858 |
|
print "</TD></TR> |
859 |
|
<TR><TD></TD><TD COLSPAN=5><HR></TD></TR>"; |
860 |
} |
} |
861 |
?> |
?> |
|
</TD></TR> |
|
|
|
|
|
<TR><TD></TD><TD COLSPAN=5><HR></TD></TR> |
|
862 |
|
|
863 |
<FORM METHOD="POST" ACTION="<?= $self ?>"> |
<FORM METHOD="POST" ACTION="<?= $self ?>"> |
864 |
<TR><TD></TD><TD COLSPAN=5 CLASS=BAR>CREATE NEW |
<TR><TD></TD><TD COLSPAN=5 CLASS=BAR>CREATE NEW |
880 |
|
|
881 |
////////////////////////////////////////////////////////////////// |
////////////////////////////////////////////////////////////////// |
882 |
|
|
883 |
function UploadPage($fsRoot, $relDir, $filename) { |
function UploadPage($fsRoot, $relDir, $filename="") { |
884 |
|
|
885 |
$self = $GLOBALS["PHP_SELF"] ; |
$self = $GLOBALS["PHP_SELF"] ; |
886 |
if ($relDir == "") $relDir = "/" ; |
if ($relDir == "") $relDir = "/" ; |
890 |
<FORM ENCTYPE="multipart/form-data" METHOD="POST" |
<FORM ENCTYPE="multipart/form-data" METHOD="POST" |
891 |
ACTION="<?= $self ?>"> |
ACTION="<?= $self ?>"> |
892 |
DESTINATION DIRECTORY:<B><?= " " . $relDir ?></B> |
DESTINATION DIRECTORY:<B><?= " " . $relDir ?></B> |
893 |
<? if (isset($filename)) { ?> |
<? if (isset($filename) && $filename!="") { ?> |
894 |
<br>DESTINATION FILE:<B><?= " " . $filename ?></B> |
<br>DESTINATION FILE:<B><?= " " . $filename ?></B> |
895 |
<INPUT TYPE="HIDDEN" NAME="FILENAME" VALUE="<?= $filename ?>"> |
<INPUT TYPE="HIDDEN" NAME="FILENAME" VALUE="<?= $filename ?>"> |
896 |
<? } ?> |
<? } ?> |
925 |
|
|
926 |
////////////////////////////////////////////////////////////////// |
////////////////////////////////////////////////////////////////// |
927 |
|
|
|
function CreateHash($user, $pw) { |
|
|
|
|
|
global $gblHash ; // hash function to use |
|
|
|
|
|
if ($user == "" || $pw == "") { |
|
|
$text = "either no password or no username supplied" ; |
|
|
Error("Create Hash",$text) ; |
|
|
} |
|
|
$title = "(Create Hash)" ; |
|
|
StartHTML($title) ; |
|
|
echo "<P ALIGN=center>" ; |
|
|
echo "<BLOCKQUOTE>Copy the value below and paste it " ; |
|
|
echo "into the<BR>value for \$gblPw in the source of " ; |
|
|
echo "this file<BR><BR><B>" . $gblHash($user.$pw) ; |
|
|
echo "</B><BR><BR>Hash function: " . $gblHash ; |
|
|
echo "</BLOCKQUOTE></P>" ; |
|
|
EndHTML() ; |
|
|
exit ; |
|
|
|
|
|
} // end function CreateHash |
|
|
|
|
|
////////////////////////////////////////////////////////////////// |
|
|
|
|
928 |
function NoEntry() { |
function NoEntry() { |
929 |
|
|
930 |
$user = $GLOBALS["PHP_AUTH_USER"] ; |
$user = $GLOBALS["PHP_AUTH_USER"] ; |
934 |
$title = "(401 Unauthorized)" ; |
$title = "(401 Unauthorized)" ; |
935 |
$text = "No trespassing !" ; |
$text = "No trespassing !" ; |
936 |
StartHTML($title,$text) ; |
StartHTML($title,$text) ; |
|
?> |
|
937 |
|
|
|
<FORM ACTION="<?= $self ?>?HASH=create" METHOD="POST"> |
|
|
<INPUT TYPE="HIDDEN" NAME="USER" VALUE="<?= $user ?>"> |
|
|
<INPUT TYPE="HIDDEN" NAME="PW" VALUE="<?= $pw ?>"> |
|
|
|
|
|
<BLOCKQUOTE><B>If you are a site administrator:</B><BR><BR> |
|
|
Click below to <B>generate a password hash</B><BR>from |
|
|
the username-password pair you just<BR>entered. Then include the hash in |
|
|
the source<BR>of this file.<BR><BR> |
|
|
<INPUT TYPE="SUBMIT" VALUE="CREATE HASH"> |
|
|
</BLOCKQUOTE></FORM> |
|
|
|
|
|
<?php |
|
938 |
EndHTML() ; |
EndHTML() ; |
939 |
exit ; |
exit ; |
940 |
} |
} |
1112 |
$log=fopen("$gblFsRoot/.changelog","r"); |
$log=fopen("$gblFsRoot/.changelog","r"); |
1113 |
$logarr = array(); |
$logarr = array(); |
1114 |
while($line = fgetcsv($log,255,"\t")) { |
while($line = fgetcsv($log,255,"\t")) { |
1115 |
if ($day!=1 || ($day==1 && (time()-$line[0] < 24*60))) { |
if ($day!=1 || ($day==1 && (time()-$line[0] < 24*60*60))) { |
1116 |
array_unshift($logarr,array($line[0],$line[1],$line[2],$line[3])); |
array_unshift($logarr,array($line[0],$line[1],$line[2],$line[3])); |
1117 |
} |
} |
1118 |
} |
} |
1119 |
fclose($log); |
fclose($log); |
1120 |
$cl1=" class=lst"; $cl2=""; |
$cl1=" class=LST"; $cl2=""; |
1121 |
print "<table border=0 width=100%>\n"; |
print "<table border=0 width=100%>\n"; |
1122 |
while ($e = array_shift($logarr)) { |
while ($e = array_shift($logarr)) { |
1123 |
$cl=$cl1; $cl1=$cl2; $cl2=$cl; |
$cl=$cl1; $cl1=$cl2; $cl2=$cl; |
1148 |
// forks before authentication: style sheet and hash |
// forks before authentication: style sheet and hash |
1149 |
// creation if password not yet set. |
// creation if password not yet set. |
1150 |
if ($STYLE == "get") { CSS() ; exit ; } |
if ($STYLE == "get") { CSS() ; exit ; } |
|
if ($HASH != "") { |
|
|
CreateHash($USER, $PW) ; |
|
|
exit ; |
|
|
} |
|
1151 |
|
|
1152 |
// authentication if $gblAuth == true |
// authentication failure |
1153 |
if ( $gblAuth && $gblHash($PHP_AUTH_USER.$PHP_AUTH_PW) != $gblPw || |
if ( md5($PHP_AUTH_USER.$PHP_AUTH_PW) != $gblPw || |
1154 |
isset($relogin) && $gblPw == $relogin ) { |
isset($relogin) && $gblPw == $relogin ) { |
1155 |
header("WWW-authenticate: basic realm=\"$SERVER_NAME\"") ; |
header("WWW-authenticate: basic realm=\"$HTTP_HOST\"") ; |
1156 |
header("HTTP/1.0 401 Unauthorized") ; |
header("HTTP/1.0 401 Unauthorized") ; |
1157 |
NoEntry() ; |
NoEntry() ; |
1158 |
exit ; |
exit ; |
1175 |
// i.e. below $gblFsRoot. |
// i.e. below $gblFsRoot. |
1176 |
|
|
1177 |
$relScriptDir = dirname($SCRIPT_NAME) ; |
$relScriptDir = dirname($SCRIPT_NAME) ; |
1178 |
// i.e. /siteman |
// i.e. /docman |
1179 |
|
|
1180 |
$fsScriptDir = dirname($SCRIPT_FILENAME) ; |
$fsScriptDir = dirname($SCRIPT_FILENAME) ; |
1181 |
// i.e. /home/httpd/html/siteman |
// i.e. /home/httpd/html/docman |
1182 |
|
|
1183 |
$gblFsRoot = substr($fsScriptDir,0, |
// start on server root |
1184 |
strlen($fsScriptDir)-strlen($relScriptDir)) ; |
// $gblFsRoot = substr($fsScriptDir,0, strlen($fsScriptDir)-strlen($relScriptDir)) ; |
1185 |
|
// or on script root |
1186 |
|
$gblFsRoot = $fsScriptDir; |
1187 |
// i.e. /home/httpd/html |
// i.e. /home/httpd/html |
1188 |
|
|
1189 |
$fsDir = $gblFsRoot . $relDir ; // current directory |
$fsDir = $gblFsRoot . $relDir ; // current directory |
1199 |
// TODO : should rather check for escapeshellcmds |
// TODO : should rather check for escapeshellcmds |
1200 |
// but maybe RFC 18xx asserts safe filenames .... |
// but maybe RFC 18xx asserts safe filenames .... |
1201 |
$source = $FN ; |
$source = $FN ; |
1202 |
|
if (! file_exists($source)) { |
1203 |
|
Error("You must select file with browse to upload it!"); |
1204 |
|
} |
1205 |
if (! isset($FILENAME)) { // from update file |
if (! isset($FILENAME)) { // from update file |
1206 |
$target = "$fsDir/$FN_name" ; |
$target = "$fsDir/$FN_name" ; |
1207 |
} else { |
} else { |
1383 |
if (!is_writeable($gblFsRoot . $relDir)) |
if (!is_writeable($gblFsRoot . $relDir)) |
1384 |
Error("Write access denied",$relDir) ; |
Error("Write access denied",$relDir) ; |
1385 |
$text = "Use this page to upload a single " ; |
$text = "Use this page to upload a single " ; |
1386 |
$text .= "file to <B>$SERVER_NAME</B>." ; |
$text .= "file to <B>$HTTP_HOST</B>." ; |
1387 |
StartHTML("(Upload Page)", $text) ; |
StartHTML("(Upload Page)", $text) ; |
1388 |
UploadPage($gblFsRoot, $relDir) ; |
UploadPage($gblFsRoot, $relDir) ; |
1389 |
EndHTML() ; |
EndHTML() ; |
1410 |
if (!is_writeable($gblFsRoot . $relDir)) |
if (!is_writeable($gblFsRoot . $relDir)) |
1411 |
Error("Write access denied",$relDir) ; |
Error("Write access denied",$relDir) ; |
1412 |
$text = "Use this page to update a single " ; |
$text = "Use this page to update a single " ; |
1413 |
$text .= "file to <B>$SERVER_NAME</B>." ; |
$text .= "file to <B>$HTTP_HOST</B>." ; |
1414 |
StartHTML("(Update file Page)", $text) ; |
StartHTML("(Update file Page)", $text) ; |
1415 |
UploadPage($gblFsRoot, $relDir, $F) ; |
UploadPage($gblFsRoot, $relDir, $F) ; |
1416 |
EndHTML() ; |
EndHTML() ; |