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 |
add more content-management (like cms.sourceforge.net): |
access controll |
61 |
check-out/check-in/reserve |
|
|
comments to files |
|
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) { |
// date format |
|
$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\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]; |
|
|
continue ; |
|
|
} |
|
|
} |
|
|
fclose($htusers); |
|
|
} |
|
|
|
|
87 |
// $gblDateFmt="D, F d, Y"; |
// $gblDateFmt="D, F d, Y"; |
|
// $gblTimeFmt="g:i:sA"; |
|
|
|
|
88 |
$gblDateFmt="Y-m-d"; |
$gblDateFmt="Y-m-d"; |
89 |
|
|
90 |
|
// time format |
91 |
|
// $gblTimeFmt="g:i:sA"; |
92 |
$gblTimeFmt="H:i:s"; |
$gblTimeFmt="H:i:s"; |
93 |
|
|
94 |
// Number of backup files to keep |
// Number of backup files to keep |
95 |
$gblNumBackups=5; |
$gblNumBackups=3; |
96 |
|
|
97 |
|
// show red star if newer than ... days |
98 |
|
$gblModDays=1; |
99 |
|
|
100 |
// choose GifIcon below unless you have the M$ |
// choose GifIcon below unless you have the M$ |
101 |
// WingDings font installed on your system |
// WingDings font installed on your system |
102 |
|
|
103 |
$gblIcon = "GifIcon" ; // MockIcon or GifIcon |
$gblIcon="GifIcon"; // MockIcon or GifIcon |
104 |
|
|
105 |
// the directory below should be /icons/ or /icons/small/ |
// the directory below should be /icons/ or /icons/small/ |
106 |
// on Apache; a set of icons is included in the distribution |
// on Apache; a set of icons is included in the distribution |
107 |
|
|
108 |
$gblIconLocation = "/icons/" ; |
$gblIconLocation="/icons/"; |
109 |
|
|
110 |
// files you want to be able to edit in text mode |
// files you want to be able to edit in text mode |
111 |
// and view with (primitive) syntax highlighting |
// and view with (primitive) syntax highlighting |
124 |
|
|
125 |
function StartHTML($title,$text="") { |
function StartHTML($title,$text="") { |
126 |
|
|
127 |
$title = "Site Manager " . $title ; |
$title = "Document Manager " . $title ; |
128 |
$host = $GLOBALS["HTTP_HOST"] ; |
$host = $GLOBALS["HTTP_HOST"] ; |
129 |
$self = $GLOBALS["PHP_SELF"] ; |
$self = $GLOBALS["PHP_SELF"] ; |
130 |
?> |
?> |
158 |
<B><?= date($GLOBALS[gblDateFmt]) ?> - |
<B><?= date($GLOBALS[gblDateFmt]) ?> - |
159 |
<?= date($GLOBALS[gblTimeFmt]) ?> - |
<?= date($GLOBALS[gblTimeFmt]) ?> - |
160 |
<?= $GLOBALS[gblUserName] ?> |
<?= $GLOBALS[gblUserName] ?> |
161 |
<small> [<a href="<?= $PHP_SELF ?>?relogin=<?= $GLOBALS[gblPw] ?>">logout</a>]</small> |
<small> [<a href="<?= $GLOBALS["PHP_SELF"] ?>?relogin=<?= $GLOBALS[gblPw] ?>">logout</a>]</small> |
162 |
</B> |
</B> |
163 |
<BR>ANYPORTAL(php) Site Manager |
<BR>ANYPORTAL(php) Site Manager |
164 |
<br><small> |
<br><small> |
168 |
</small> |
</small> |
169 |
</P> |
</P> |
170 |
<BR> |
<BR> |
171 |
<? include(".debug.inc") ?> |
<? //include(".debug.inc") ?> |
172 |
<BR><BR></BODY></HTML> |
<BR><BR></BODY></HTML> |
173 |
|
|
174 |
<?php |
<?php |
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 ; |
214 |
$ext = strtolower(strrchr($relPath,".")) ; |
$ext = strtolower(strrchr($relPath,".")) ; |
215 |
$editable = ( $ext=="" || strstr(join(" ",$gblEditable),$ext)) ; |
$editable = ( $ext=="" || strstr(join(" ",$gblEditable),$ext)) ; |
216 |
$writable = is_writeable($fsPath) ; |
$writable = is_writeable($fsPath) ; |
217 |
|
$file_lock = CheckLock($fsPath); |
218 |
|
|
219 |
if (!$editable && !$exists) |
if (!$editable && !$exists) |
220 |
Error("Creation unsupported for type",$relPath) ; |
Error("Creation unsupported for type",$relPath) ; |
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>" ; |
$userinfo = posix_getpwuid(fileowner($fsPath)); |
240 |
|
$grpinfo = posix_getgrgid(filegroup($fsPath)); |
241 |
|
echo "<PRE>"; |
242 |
|
if (!is_dir($fsPath)) echo "file size: " . $fsize . " Bytes<BR>" ; |
243 |
echo "last modified: <B>" . $fmodified . "</B><BR>" ; |
echo "last modified: <B>" . $fmodified . "</B><BR>" ; |
244 |
echo "last accessed: <B>" . $faccessed . "</B><BR>" ; |
echo "last accessed: <B>" . $faccessed . "</B><BR>" ; |
245 |
echo " owner: <B>" . fileowner($fsPath) . "</B><BR>" ; |
echo " owner: <B>" . $userinfo["name"] . "</B><BR>" ; |
246 |
echo " group: <B>" . filegroup($fsPath) . "</B><BR>" ; |
echo " group: <B>" . $grpinfo["name"] . "</B><BR>" ; |
247 |
echo " permissions: <B>" ; |
echo " permissions: <B>" ; |
248 |
echo printf( "%o", fileperms($fsPath) ) . "</B>" ; |
echo printf( "%o", fileperms($fsPath) ) . "</B>" ; |
249 |
echo "</PRE>" ; |
echo "</PRE>" ; |
250 |
|
|
251 |
} |
} |
252 |
|
|
253 |
if ( $editable && ($writable || !$exists) ) { |
if ( !is_dir($fsPath) && $editable && ($writable || !$exists) && !$file_lock ) { |
254 |
$fh = fopen($fsPath,"a+") ; |
$fh = fopen($fsPath,"a+") ; |
255 |
rewind($fh) ; |
rewind($fh) ; |
256 |
$fstr = fread($fh,filesize($fsPath)) ; |
$fstr = fread($fh,filesize($fsPath)) ; |
276 |
|
|
277 |
<?php |
<?php |
278 |
} |
} |
279 |
else if ( strstr( join(" ",$gblImages), $ext ) ) { |
if ( !$file_lock && $ext!="" && strstr(join(' ',$gblImages),$ext) ) { |
280 |
$info = getimagesize($fsPath) ; |
$info = getimagesize($fsPath) ; |
281 |
$tstr = "<IMG SRC=\"". $relPath . "\" BORDER=0 " ; |
$tstr = "<IMG SRC=\"$webRoot".urlpath($relPath)."\" BORDER=0 " ; |
282 |
$tstr .= $info[3] . " ALT=\"" . $fn . " - " ; |
$tstr .= $info[3] . " ALT=\"" . $fn . " - " ; |
283 |
$tstr .= (int)(($fsize+1023)/1024) . "Kb\">" ; |
$tstr .= (int)(($fsize+1023)/1024) . "Kb\">" ; |
284 |
echo htmlentities($tstr) . "<BR><BR>" . $tstr ; |
// echo htmlentities($tstr) . "<BR><BR>" . $tstr ; |
285 |
|
echo $tstr ; |
286 |
} |
} |
287 |
|
|
288 |
?> |
?> |
289 |
|
|
290 |
<FORM ACTION="<?= $self ; ?>" METHOD="POST"> |
<FORM ACTION="<?= $self ; ?>" METHOD="POST"> |
293 |
<INPUT TYPE="SUBMIT" NAME="POSTACTION" VALUE="CANCEL"><BR> |
<INPUT TYPE="SUBMIT" NAME="POSTACTION" VALUE="CANCEL"><BR> |
294 |
|
|
295 |
<?php |
<?php |
296 |
|
|
297 |
|
if ($file_lock) { |
298 |
|
?> |
299 |
|
<hr> |
300 |
|
<SPAN TITLE="Check OK and click UNLOCK to remove lock on file."> |
301 |
|
<B>OK TO FORCE LOCK REMOVAL ON "<?= $fn ; ?>" HELD BY <?= $file_lock ?>? </B></SPAN> |
302 |
|
<INPUT TYPE="CHECKBOX" NAME="CONFIRM"> |
303 |
|
<INPUT TYPE="SUBMIT" NAME="POSTACTION" VALUE="UNLOCK"> |
304 |
|
<? |
305 |
|
} // file_lock |
306 |
|
|
307 |
if (substr($fn,0,4) == ".del") { |
if (substr($fn,0,4) == ".del") { |
308 |
$action="UNDELETE"; |
$action="UNDELETE"; |
309 |
$desc="undelete previously deleted file"; |
$desc="undelete previously deleted file"; |
331 |
<INPUT TYPE="CHECKBOX" NAME="CONFIRM"> |
<INPUT TYPE="CHECKBOX" NAME="CONFIRM"> |
332 |
<INPUT TYPE="SUBMIT" NAME="POSTACTION" VALUE="RENAME"> |
<INPUT TYPE="SUBMIT" NAME="POSTACTION" VALUE="RENAME"> |
333 |
|
|
334 |
|
<?php |
335 |
|
} // exists && writable |
336 |
|
?> |
337 |
<HR> |
<HR> |
338 |
<a name="note"> |
<a name="note"> |
339 |
<B>NOTE FOR "<?= $fn ; ?>": |
<B>NOTE FOR "<?= $fn ; ?>": |
341 |
</B></SPAN> |
</B></SPAN> |
342 |
<INPUT TYPE="SUBMIT" NAME="POSTACTION" VALUE="NOTE"> |
<INPUT TYPE="SUBMIT" NAME="POSTACTION" VALUE="NOTE"> |
343 |
|
|
344 |
|
</FORM> |
345 |
|
|
346 |
<?php |
<?php |
|
} |
|
|
echo "</FORM>" ; |
|
347 |
|
|
348 |
$logname=dirname("$fsDir/$fn")."/.log/".basename("$fsDir/$fn"); |
$name=basename("$fsDir/$fn"); |
349 |
|
$logname=dirname("$fsDir/$fn")."/.log/$name"; |
350 |
|
$bakdir=dirname("$fsDir/$fn")."/.bak"; |
351 |
if (file_exists($logname)) { |
if (file_exists($logname)) { |
|
print "<hr><br><b>CHANGES TO THIS FILE</b><br><table border=0 width=100%>\n"; |
|
352 |
$log=fopen($logname,"r"); |
$log=fopen($logname,"r"); |
353 |
$cl1=" class=lst"; $cl2=""; |
$cl1=" class=LST"; $cl2=""; |
354 |
|
$logarr = array(); |
355 |
while($line = fgetcsv($log,255,"\t")) { |
while($line = fgetcsv($log,255,"\t")) { |
356 |
$cl=$cl1; $cl1=$cl2; $cl2=$cl; |
$cl=$cl1; $cl1=$cl2; $cl2=$cl; |
357 |
print "<tr><td$cl>$line[0]</td><td$cl>$line[1]</td><td$cl>$line[2]</td><td$cl>$line[3]</td></tr>\n"; |
array_unshift($logarr,array($cl,$line[0],$line[1],$line[2],$line[3])); |
358 |
} |
} |
359 |
fclose($log); |
fclose($log); |
360 |
|
if (is_dir("$fsDir/$fn")) { |
361 |
|
$whatis="DIRECTORY"; |
362 |
|
} else { |
363 |
|
$whatis="FILE"; |
364 |
|
} |
365 |
|
print "<hr><br><b>CHANGES TO THIS $whatis</b><br><table border=0 width=100%>\n"; |
366 |
|
$bakcount = 0; // start from 0, skip fist backup (it's current) |
367 |
|
while ($e = array_shift($logarr)) { |
368 |
|
if (strstr($e[4],"upload")) { |
369 |
|
if (file_exists("$bakdir/$bakcount/$name")) { |
370 |
|
$e[4]="<a href=\"$webRoot".urlpath(dirname($relPath)."/.bak/$bakcount/$name")."\">$e[4]</a>"; |
371 |
|
} |
372 |
|
$bakcount++; |
373 |
|
} |
374 |
|
print "<tr><td$e[0]>$e[1]</td><td$e[0]>$e[2]</td><td$e[0]>$e[3]</td><td$e[0]>$e[4]</td></tr>\n"; |
375 |
|
} |
376 |
print "</table>"; |
print "</table>"; |
377 |
} |
} |
378 |
|
|
606 |
$d = "blank.gif" ; |
$d = "blank.gif" ; |
607 |
break ; |
break ; |
608 |
case "checkout": |
case "checkout": |
609 |
$d = "down.gif"; |
$d = "box2.gif"; |
610 |
break; |
break; |
611 |
case "checkin": |
case "checkin": |
612 |
$d = "up.gif"; |
$d = "hand.up.gif"; |
613 |
|
break; |
614 |
|
case "locked": |
615 |
|
$d = "screw2.gif"; |
616 |
break; |
break; |
617 |
case "note": |
case "note": |
618 |
$d = "quill.gif"; |
$d = "quill.gif"; |
628 |
|
|
629 |
function Navigate($fsRoot,$relDir) { |
function Navigate($fsRoot,$relDir) { |
630 |
|
|
631 |
global $gblEditable, $gblIcon ; |
global $gblEditable, $gblIcon, $gblModDays, $webRoot ; |
632 |
|
|
633 |
$self = $GLOBALS["PHP_SELF"] ; |
$self = $GLOBALS["PHP_SELF"] ; |
634 |
if (isset($GLOBALS["HTTPS"]) && $GLOBALS["HTTPS"] == "on") { |
|
635 |
$webRoot = "https://" . $GLOBALS["SERVER_NAME"] ; |
$fsDir = $fsRoot . $relDir . "/" ; // current directory |
|
} else { |
|
|
$webRoot = "http://" . $GLOBALS["SERVER_NAME"] ; |
|
|
} |
|
|
$fsDir = $fsRoot . $relDir . "/" ; // current directory |
|
636 |
|
|
637 |
if (!is_dir($fsDir)) Error("Dir not found",$relDir) ; |
if (!is_dir($fsDir)) Error("Dir not found",$relDir) ; |
638 |
|
|
670 |
// start navigation page |
// start navigation page |
671 |
$text = "Use this page to add, delete"; |
$text = "Use this page to add, delete"; |
672 |
if (! isset($show_deleted)) { |
if (! isset($show_deleted)) { |
673 |
$text .= ", <a href=".$GLOBALS[PHP_SELF]."?D=".urlencode($relDir)."&show_deleted=1>undelete</a>"; |
$text .= ", <a href=$self?D=".urlencode($relDir)."&show_deleted=1>undelete</a>"; |
674 |
} |
} |
675 |
$text .= " or revise files on this web site." ; |
$text .= " or revise files on this web site." ; |
676 |
|
$text .= "<br>Examine list of files <a href=\"$self?A=Ch1\">changed in last day</a> or <a href=\"$self?A=Ch\">all changes</a>."; |
677 |
StartHTML("(Navigate)",$text) ; |
StartHTML("(Navigate)",$text) ; |
678 |
|
|
679 |
echo "<TABLE BORDER=0 CELLPADDING=2 |
echo "<TABLE BORDER=0 CELLPADDING=2 |
697 |
sort($dirList) ; |
sort($dirList) ; |
698 |
?> |
?> |
699 |
|
|
700 |
<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> |
701 |
|
|
702 |
<?php |
<?php |
703 |
while (list($key,$dir) = each($dirList)) { |
while (list($key,$dir) = each($dirList)) { |
704 |
|
|
705 |
|
$info_url=$self."?A=E&F=".urlencode($dir)."&D=".urlencode($relDir); |
706 |
$tstr = "<A HREF=\"" . $self . "?D=" ; |
$tstr = "<A HREF=\"" . $self . "?D=" ; |
707 |
$tstr .= urlencode($relDir."/".$dir) ; |
$tstr .= urlencode($relDir."/".$dir) ; |
708 |
$tstr .= "\">" . $dir . "/</A>" ; |
$tstr .= "\">" . $dir . "/</A>" ; |
709 |
|
$note_html="<a href=\"$info_url#note\">".$gblIcon("note")."</a>".ReadNote($fsDir.$dir); |
710 |
?> |
?> |
711 |
|
|
712 |
<TR><TD><?= $gblIcon("fldr") ?></TD> |
<TR><TD> |
713 |
<TD COLSPAN=5 CLASS=LST><?= $tstr ?></TD></TR> |
<A HREF="<?= $info_url ?>" TITLE="View/Edit"> |
714 |
|
<?= $gblIcon("fldr") ?></A></TD> |
715 |
|
<TD COLSPAN=2 CLASS=LST><?= $tstr ?></TD> |
716 |
|
<TD COLSPAN=3 CLASS=LST><?= $note_html ?></TD></TR> |
717 |
|
|
718 |
<?php |
<?php |
719 |
} // iterate over dirs |
} // iterate over dirs |
723 |
<TR><TD></TD><TD COLSPAN=5><HR><B><?= $webRoot . $relDir ?> |
<TR><TD></TD><TD COLSPAN=5><HR><B><?= $webRoot . $relDir ?> |
724 |
</B></TD></TR> |
</B></TD></TR> |
725 |
<TR><TD></TD><TD CLASS=TOP>DOCUMENT NAME</TD> |
<TR><TD></TD><TD CLASS=TOP>DOCUMENT NAME</TD> |
726 |
<TD><?= $gblIcon("blank") ?></TD> |
<TD><?= $gblIcon("blank").$gblIcon("blank") ?></TD> |
727 |
<TD CLASS=TOP>NOTE</TD> |
<TD CLASS=TOP>NOTE</TD> |
728 |
<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> |
729 |
|
|
745 |
|
|
746 |
$info_url=$self."?A=E&F=".urlencode($file)."&D=".urlencode($relDir); |
$info_url=$self."?A=E&F=".urlencode($file)."&D=".urlencode($relDir); |
747 |
|
|
748 |
if ( ($mod + 30*86400) > time() ) { |
if ( ($mod + $gblModDays*86400) > time() ) { |
749 |
$a = "<SPAN CLASS=RED TITLE=\"Newer" ; |
$a = "<SPAN CLASS=RED TITLE=\"Newer" ; |
750 |
$a .= " than 30 days\"> * </SPAN>" ; |
$a .= " than $gblModDays days\"> * </SPAN>" ; |
751 |
} |
} |
752 |
|
|
753 |
$tstr = $webRoot . $relDir . "/" . $file ; |
$file_lock=CheckLock($path); |
754 |
$tstr = "<A HREF=\"" . $tstr . "\">" ; |
|
755 |
|
$file_url_html="<A HREF=\"$self?A=V&F=".urlencode($file); |
756 |
|
$file_url_html.="&D=".urlencode($relDir); |
757 |
|
$file_url_html.="\" TITLE=\"View file\">" ; |
758 |
|
|
759 |
if (substr($file,0,5) != ".del/") { |
if (substr($file,0,5) != ".del/") { |
760 |
$tstr .= $file . "</A>" . $a ; |
$file_url_html .= $file . "</A>" . $a ; |
761 |
} else { |
} else { |
762 |
$tstr .= substr($file,5,strlen($file)-5) . "</a> <SPAN CLASS=RED TITLE=\"deleted\"> <a href=\"$info_url#undelete\">deleted</a> </span>"; |
$file_url_html .= substr($file,5,strlen($file)-5) . "</a> <SPAN CLASS=RED TITLE=\"deleted\"> <a href=\"$info_url#undelete\">deleted</a> </span>"; |
763 |
} |
} |
764 |
|
|
765 |
// $b = $gblIcon("checkout"); |
$note_html="<a href=\"$info_url#note\">".$gblIcon("note")."</a>".ReadNote($path); |
|
// $b .= $gblIcon("checkin"); |
|
766 |
|
|
767 |
$ext = strtolower(strrchr($file,".")) ; |
$ext = strtolower(strrchr($file,".")) ; |
768 |
if ( $ext=="" || strstr(join(" ",$gblEditable),$ext) ) { |
|
769 |
$b .= "<A HREF=\"" . $self . "?A=C&F=" ; |
if ($file_lock) { |
770 |
$b .= urlencode($file) . "&D=" . urlencode($relDir) ; |
if ($file_lock == $GLOBALS[gblUserName]) { |
771 |
$b .= "\" TITLE=\"List contents\">" ; |
$b.="<A HREF=\"$self?A=Ci&F=".urlencode($file); |
772 |
$b .= $gblIcon("view") . "</A>" ; |
$b.="&D=".urlencode($relDir); |
773 |
|
$b.="\" TITLE=\"Checkin (update) file on server\">" ; |
774 |
|
$file_url_html=$b; |
775 |
|
$b.=$gblIcon("checkin")."</A>" ; |
776 |
|
$b.= $gblIcon("blank"); |
777 |
|
$file_url_html.="$file</a> $a"; |
778 |
|
$note_html = $gblIcon("blank")."<b>Please check-in (update) this file</b>"; |
779 |
|
} else { |
780 |
|
$b = $gblIcon("locked"); |
781 |
|
$b.= $gblIcon("blank"); |
782 |
|
$note_html = $gblIcon("blank")."<b>File locked by $file_lock</b>"; |
783 |
|
$file_url_html = "$file $a"; |
784 |
|
} |
785 |
} else { |
} else { |
786 |
$b .= $gblIcon("blank"); |
$b.="<A HREF=\"$self?A=Co&F=".urlencode($file); |
787 |
|
$b.="&D=".urlencode($relDir); |
788 |
|
$b.="\" TITLE=\"Checkout file for edit\">" ; |
789 |
|
$b.=$gblIcon("checkout")."</A>" ; |
790 |
|
|
791 |
|
if ( $ext=="" || strstr(join(" ",$gblEditable),$ext) ) { |
792 |
|
$b.="<A HREF=\"$self?A=C&F=".urlencode($file); |
793 |
|
$b.="&D=".urlencode($relDir); |
794 |
|
$b.="\" TITLE=\"List contents\">" ; |
795 |
|
$b.=$gblIcon("view")."</A>" ; |
796 |
|
} else { |
797 |
|
$b.= $gblIcon("blank"); |
798 |
|
} |
799 |
} |
} |
800 |
|
|
801 |
|
|
804 |
<TR><TD> |
<TR><TD> |
805 |
<A HREF="<?= $info_url ?>" TITLE="View/Edit"> |
<A HREF="<?= $info_url ?>" TITLE="View/Edit"> |
806 |
<?= $gblIcon($ext) ?></A></TD> |
<?= $gblIcon($ext) ?></A></TD> |
807 |
<TD CLASS=LST><?= $tstr ?></TD> |
<TD CLASS=LST><?= $file_url_html ?></TD> |
808 |
<TD CLASS=LST ALIGN=center><?= $b ?></TD> |
<TD CLASS=LST ALIGN=center><?= $b ?></TD> |
809 |
<TD CLASS=LST ALIGN=left><a href="<?= $info_url ?>#note"><?= $gblIcon("note") ?></a><?= ReadNote($path) ?></TD> |
<TD CLASS=LST ALIGN=left><?= $note_html ?></TD> |
810 |
<TD CLASS=LST><?= date("$GLOBALS[gblDateFmt] $GLOBALS[gblTimeFmt]",$mod) ?></TD> |
<TD CLASS=LST><?= date("$GLOBALS[gblDateFmt] $GLOBALS[gblTimeFmt]",$mod) ?></TD> |
811 |
<TD CLASS=LST><?= $sz ?>Bytes</TD></TR> |
<TD CLASS=LST><?= $sz ?>Bytes</TD></TR> |
812 |
|
|
813 |
<?php |
<?php |
814 |
} // iterate over files |
} // iterate over files |
815 |
} // end if no files |
} else { // end if no files |
816 |
|
?> |
817 |
|
<TR><TD></TD><TD COLSPAN=5 CLASS=LST> |
818 |
|
No files in this directory |
819 |
|
</TD></TR> |
820 |
|
<? |
821 |
|
} |
822 |
|
|
823 |
if ($emptyDir) { |
if ($emptyDir) { |
824 |
?> |
?> |
838 |
|
|
839 |
<TR><TD></TD><TD COLSPAN=5><HR></TD></TR> |
<TR><TD></TD><TD COLSPAN=5><HR></TD></TR> |
840 |
|
|
841 |
|
<? |
842 |
|
if (file_exists(".info.inc")) { |
843 |
|
print "<TR><TD></TD><TD COLSPAN=5>"; |
844 |
|
include(".info.inc"); |
845 |
|
print "</TD></TR> |
846 |
|
<TR><TD></TD><TD COLSPAN=5><HR></TD></TR>"; |
847 |
|
} |
848 |
|
?> |
849 |
|
|
850 |
<FORM METHOD="POST" ACTION="<?= $self ?>"> |
<FORM METHOD="POST" ACTION="<?= $self ?>"> |
851 |
<TR><TD></TD><TD COLSPAN=5 CLASS=BAR>CREATE NEW |
<TR><TD></TD><TD COLSPAN=5 CLASS=BAR>CREATE NEW |
852 |
<INPUT TYPE="RADIO" NAME="T" VALUE="D" CHECKED>DIRECTORY -OR- |
<INPUT TYPE="RADIO" NAME="T" VALUE="D" CHECKED>DIRECTORY -OR- |
855 |
<INPUT TYPE="HIDDEN" NAME="POSTACTION" VALUE="CREATE"> |
<INPUT TYPE="HIDDEN" NAME="POSTACTION" VALUE="CREATE"> |
856 |
<INPUT TYPE="HIDDEN" NAME="DIR" VALUE="<?= $relDir ?>"> |
<INPUT TYPE="HIDDEN" NAME="DIR" VALUE="<?= $relDir ?>"> |
857 |
<INPUT TYPE="SUBMIT" VALUE="CREATE"></NOBR> |
<INPUT TYPE="SUBMIT" VALUE="CREATE"></NOBR> |
858 |
<NOBR>OR <A HREF="<?= $self |
<NOBR>OR <A HREF="<?= $self ?>?A=U&D=<?= urlencode($relDir) ?>">UPLOAD</A> A FILE |
|
?>?A=U&D=<?= urlencode($relDir) ?>">UPLOAD</A> A FILE |
|
859 |
</NOBR> |
</NOBR> |
860 |
</TD></TR> |
</TD></TR> |
861 |
</FORM> |
</FORM> |
867 |
|
|
868 |
////////////////////////////////////////////////////////////////// |
////////////////////////////////////////////////////////////////// |
869 |
|
|
870 |
function UploadPage($fsRoot, $relDir) { |
function UploadPage($fsRoot, $relDir, $filename="") { |
871 |
|
|
872 |
$self = $GLOBALS["PHP_SELF"] ; |
$self = $GLOBALS["PHP_SELF"] ; |
873 |
if ($relDir == "") $relDir = "/" ; |
if ($relDir == "") $relDir = "/" ; |
877 |
<FORM ENCTYPE="multipart/form-data" METHOD="POST" |
<FORM ENCTYPE="multipart/form-data" METHOD="POST" |
878 |
ACTION="<?= $self ?>"> |
ACTION="<?= $self ?>"> |
879 |
DESTINATION DIRECTORY:<B><?= " " . $relDir ?></B> |
DESTINATION DIRECTORY:<B><?= " " . $relDir ?></B> |
880 |
|
<? if (isset($filename) && $filename!="") { ?> |
881 |
|
<br>DESTINATION FILE:<B><?= " " . $filename ?></B> |
882 |
|
<INPUT TYPE="HIDDEN" NAME="FILENAME" VALUE="<?= $filename ?>"> |
883 |
|
<? } ?> |
884 |
<P>PATHNAME OF LOCAL FILE<BR> |
<P>PATHNAME OF LOCAL FILE<BR> |
885 |
<INPUT TYPE="HIDDEN" NAME="DIR" VALUE="<?= $relDir ?>"> |
<INPUT TYPE="HIDDEN" NAME="DIR" VALUE="<?= $relDir ?>"> |
886 |
<INPUT TYPE="HIDDEN" NAME="POSTACTION" VALUE="UPLOAD"> |
<INPUT TYPE="HIDDEN" NAME="POSTACTION" VALUE="UPLOAD"> |
912 |
|
|
913 |
////////////////////////////////////////////////////////////////// |
////////////////////////////////////////////////////////////////// |
914 |
|
|
|
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 |
|
|
|
|
|
////////////////////////////////////////////////////////////////// |
|
|
|
|
915 |
function NoEntry() { |
function NoEntry() { |
916 |
|
|
917 |
$user = $GLOBALS["PHP_AUTH_USER"] ; |
$user = $GLOBALS["PHP_AUTH_USER"] ; |
921 |
$title = "(401 Unauthorized)" ; |
$title = "(401 Unauthorized)" ; |
922 |
$text = "No trespassing !" ; |
$text = "No trespassing !" ; |
923 |
StartHTML($title,$text) ; |
StartHTML($title,$text) ; |
|
?> |
|
|
|
|
|
<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> |
|
924 |
|
|
|
<?php |
|
925 |
EndHTML() ; |
EndHTML() ; |
926 |
exit ; |
exit ; |
927 |
} |
} |
928 |
|
|
929 |
////////////////////////////////////////////////////////////////// |
////////////////////////////////////////////////////////////////// |
930 |
|
|
931 |
function Logit($target,$msg) { |
function LogIt($target,$msg) { |
932 |
|
|
933 |
$dir=dirname($target); |
$dir=dirname($target); |
934 |
if (! file_exists($dir."/.log")) { |
if (! file_exists($dir."/.log")) { |
948 |
|
|
949 |
function WriteNote($target,$msg) { |
function WriteNote($target,$msg) { |
950 |
|
|
951 |
|
$target=stripSlashes($target); |
952 |
$dir=dirname($target); |
$dir=dirname($target); |
953 |
if (! file_exists($dir."/.note")) { |
if (! file_exists($dir."/.note")) { |
954 |
mkdir($dir."/.note",0700); |
mkdir($dir."/.note",0700); |
965 |
|
|
966 |
function ReadNote($target) { |
function ReadNote($target) { |
967 |
|
|
968 |
|
$target=stripSlashes($target); |
969 |
$dir=dirname($target); |
$dir=dirname($target); |
970 |
$file=basename($target); |
$file=basename($target); |
971 |
$msg=""; |
$msg=""; |
974 |
$msg=fgets($note,4096); |
$msg=fgets($note,4096); |
975 |
fclose($note); |
fclose($note); |
976 |
} |
} |
977 |
return $msg; |
return StripSlashes($msg); |
978 |
|
|
979 |
} |
} |
980 |
|
|
982 |
|
|
983 |
function MoveTo($source,$folder) { |
function MoveTo($source,$folder) { |
984 |
|
|
985 |
|
$source=stripSlashes($source); |
986 |
$file=basename($source); |
$file=basename($source); |
987 |
if (! file_exists($folder)) { |
if (! file_exists($folder)) { |
988 |
mkdir($folder,0700); |
mkdir($folder,0700); |
994 |
|
|
995 |
////////////////////////////////////////////////////////////////// |
////////////////////////////////////////////////////////////////// |
996 |
|
|
997 |
|
function Lock($target) { |
998 |
|
|
999 |
|
$target=stripSlashes($target); |
1000 |
|
$dir=dirname($target); |
1001 |
|
if (! file_exists($dir."/.lock")) { |
1002 |
|
mkdir($dir."/.lock",0700); |
1003 |
|
} |
1004 |
|
$file=basename($target); |
1005 |
|
|
1006 |
|
if (file_exists("$dir/.lock/$file")) { |
1007 |
|
Logit($target,"attempt to locked allready locked file!"); |
1008 |
|
} else { |
1009 |
|
$lock=fopen("$dir/.lock/$file","w"); |
1010 |
|
fputs($lock,"$GLOBALS[gblUserName]\n"); |
1011 |
|
fclose($lock); |
1012 |
|
|
1013 |
|
Logit($target,"file locked"); |
1014 |
|
} |
1015 |
|
|
1016 |
|
} |
1017 |
|
|
1018 |
|
function CheckLock($target) { |
1019 |
|
|
1020 |
|
$target=stripSlashes($target); |
1021 |
|
$dir=dirname($target); |
1022 |
|
$file=basename($target); |
1023 |
|
$msg=0; |
1024 |
|
if (file_exists($dir."/.lock/$file")) { |
1025 |
|
$lock=fopen("$dir/.lock/$file","r"); |
1026 |
|
$msg=fgets($lock,4096); |
1027 |
|
fclose($lock); |
1028 |
|
} |
1029 |
|
return chop($msg); |
1030 |
|
|
1031 |
|
} |
1032 |
|
|
1033 |
|
function Unlock($target) { |
1034 |
|
|
1035 |
|
$target=stripSlashes($target); |
1036 |
|
$dir=dirname($target); |
1037 |
|
$file=basename($target); |
1038 |
|
if (file_exists($dir."/.lock/$file")) { |
1039 |
|
unlink("$dir/.lock/$file"); |
1040 |
|
Logit($target,"file unlocked"); |
1041 |
|
} else { |
1042 |
|
Logit($target,"attempt to unlocked non-locked file!"); |
1043 |
|
} |
1044 |
|
|
1045 |
|
} |
1046 |
|
|
1047 |
|
////////////////////////////////////////////////////////////////// |
1048 |
|
|
1049 |
|
function urlpath($url) { |
1050 |
|
$url=urlencode(StripSlashes("$url")); |
1051 |
|
$url=str_replace("%2F","/",$url); |
1052 |
|
$url=str_replace("+","%20",$url); |
1053 |
|
return($url); |
1054 |
|
} |
1055 |
|
|
1056 |
|
////////////////////////////////////////////////////////////////// |
1057 |
|
|
1058 |
|
function safe_rename($from,$to) { |
1059 |
|
if (file_exists($from) && is_writable(dirname($to))) { |
1060 |
|
rename($from,$to); |
1061 |
|
} |
1062 |
|
} |
1063 |
|
|
1064 |
|
////////////////////////////////////////////////////////////////// |
1065 |
|
|
1066 |
|
// recursivly delete directory |
1067 |
|
|
1068 |
|
function rrmdir($dir) { |
1069 |
|
$handle=opendir($dir); |
1070 |
|
while ($file = readdir($handle)) { |
1071 |
|
if ($file != "." && $file != "..") { |
1072 |
|
if (is_dir("$dir/$file")) |
1073 |
|
rrmdir("$dir/$file"); |
1074 |
|
else |
1075 |
|
if (! @unlink("$dir/$file")) return(0); |
1076 |
|
} |
1077 |
|
} |
1078 |
|
closedir($handle); |
1079 |
|
return @rmdir($dir); |
1080 |
|
} |
1081 |
|
|
1082 |
|
////////////////////////////////////////////////////////////////// |
1083 |
|
|
1084 |
|
function ChangeLog($target,$msg) { |
1085 |
|
|
1086 |
|
global $gblFsRoot; |
1087 |
|
$log=fopen("$gblFsRoot/.changelog","a+"); |
1088 |
|
if (substr($target,0,strlen($gblFsRoot)) == $gblFsRoot) |
1089 |
|
$target=substr($target,strlen($gblFsRoot),strlen($target)-strlen($gblFsRoot)); |
1090 |
|
fputs($log,time()."\t$target\t$GLOBALS[gblUserName]\t$msg\n"); |
1091 |
|
fclose($log); |
1092 |
|
|
1093 |
|
} |
1094 |
|
|
1095 |
|
function DisplayChangeLog($day) { |
1096 |
|
|
1097 |
|
global $gblFsRoot; |
1098 |
|
if (!file_exists("$gblFsRoot/.changelog")) return; |
1099 |
|
$log=fopen("$gblFsRoot/.changelog","r"); |
1100 |
|
$logarr = array(); |
1101 |
|
while($line = fgetcsv($log,255,"\t")) { |
1102 |
|
if ($day!=1 || ($day==1 && (time()-$line[0] < 24*60*60))) { |
1103 |
|
array_unshift($logarr,array($line[0],$line[1],$line[2],$line[3])); |
1104 |
|
} |
1105 |
|
} |
1106 |
|
fclose($log); |
1107 |
|
$cl1=" class=LST"; $cl2=""; |
1108 |
|
print "<table border=0 width=100%>\n"; |
1109 |
|
while ($e = array_shift($logarr)) { |
1110 |
|
$cl=$cl1; $cl1=$cl2; $cl2=$cl; |
1111 |
|
$date = date("$GLOBALS[gblDateFmt]", $e[0]); |
1112 |
|
$time = date("$GLOBALS[gblTimeFmt]", $e[0]); |
1113 |
|
$dir = dirname($e[1]); |
1114 |
|
$file = basename($e[1]); |
1115 |
|
print "<tr><td$cl>$date</td><td$cl>$time</td><td$cl><a href=\"$GLOBALS[PHP_SELF]?D=".urlencode($dir)."\">$dir</a>/$file</td><td$cl>$e[2]</td><td$cl>$e[3]</td></tr>\n"; |
1116 |
|
} |
1117 |
|
print "</table>"; |
1118 |
|
print "<p>".GifIcon(up)." Back to <a href=$GLOBALS[PHP_SELF]>front page</a>.</p>"; |
1119 |
|
} |
1120 |
|
|
1121 |
|
////////////////////////////////////////////////////////////////// |
1122 |
|
|
1123 |
// MAIN PROGRAM |
// MAIN PROGRAM |
1124 |
// ============ |
// ============ |
1125 |
// query parameters: capital letters |
// query parameters: capital letters |
1135 |
// forks before authentication: style sheet and hash |
// forks before authentication: style sheet and hash |
1136 |
// creation if password not yet set. |
// creation if password not yet set. |
1137 |
if ($STYLE == "get") { CSS() ; exit ; } |
if ($STYLE == "get") { CSS() ; exit ; } |
1138 |
if ($HASH != "") { |
|
1139 |
CreateHash($USER, $PW) ; |
$htusers_file=dirname($SCRIPT_FILENAME)."/.htusers"; |
1140 |
exit ; |
if (! file_exists($htusers_file)) { |
1141 |
|
if (is_writable(dirname($SCRIPT_FILENAME))) { |
1142 |
|
$htusers=fopen($htusers_file,"a+"); |
1143 |
|
fputs($htusers,"# Change owner of $htusers_file to root !!\n"); |
1144 |
|
fputs($htusers,"demo:full name:[md5_hash|auth_*]:e-mail\n"); |
1145 |
|
fclose($htusers); |
1146 |
|
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!"); |
1147 |
|
exit; |
1148 |
|
} else { |
1149 |
|
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!"); |
1150 |
|
exit; |
1151 |
|
} |
1152 |
|
} |
1153 |
|
$htusers=fopen($htusers_file,"r"); |
1154 |
|
while($user = fgetcsv($htusers,255,":")) { |
1155 |
|
if ($user[0] == $GLOBALS["PHP_AUTH_USER"]) { |
1156 |
|
$gblUserName=$user[1]; |
1157 |
|
$gblPw=$user[2]; |
1158 |
|
if (substr($gblPw,0,5) == "auth_" && file_exists("$gblIncDir/$gblPw.php")) { |
1159 |
|
require("$gblIncDir/$gblPw.php"); |
1160 |
|
if ($gblPw($user)) { |
1161 |
|
$gblPw=md5($PHP_AUTH_USER.$PHP_AUTH_PW); |
1162 |
|
} else { |
1163 |
|
$gblPw="error".md5($PHP_AUTH_USER.$PHP_AUTH_PW); |
1164 |
|
} |
1165 |
|
} |
1166 |
|
$gblEmail=$user[3]; |
1167 |
|
continue ; |
1168 |
|
} |
1169 |
} |
} |
1170 |
|
fclose($htusers); |
1171 |
|
|
1172 |
// authentication if $gblAuth == true |
// authentication failure |
1173 |
if ( $gblAuth && $gblHash($PHP_AUTH_USER.$PHP_AUTH_PW) != $gblPw || |
if ( md5($PHP_AUTH_USER.$PHP_AUTH_PW) != $gblPw || |
1174 |
isset($relogin) && $gblPw == $relogin ) { |
isset($relogin) && $gblPw == $relogin ) { |
1175 |
header("WWW-authenticate: basic realm=\"$SERVER_NAME\"") ; |
header("WWW-authenticate: basic realm=\"$HTTP_HOST\"") ; |
1176 |
header("HTTP/1.0 401 Unauthorized") ; |
header("HTTP/1.0 401 Unauthorized") ; |
1177 |
NoEntry() ; |
NoEntry() ; |
1178 |
exit ; |
exit ; |
1195 |
// i.e. below $gblFsRoot. |
// i.e. below $gblFsRoot. |
1196 |
|
|
1197 |
$relScriptDir = dirname($SCRIPT_NAME) ; |
$relScriptDir = dirname($SCRIPT_NAME) ; |
1198 |
// i.e. /siteman |
// i.e. /docman |
1199 |
|
|
1200 |
$fsScriptDir = dirname($SCRIPT_FILENAME) ; |
$fsScriptDir = dirname($SCRIPT_FILENAME) ; |
1201 |
// i.e. /home/httpd/html/siteman |
// i.e. /home/httpd/html/docman |
1202 |
|
|
1203 |
$gblFsRoot = substr($fsScriptDir,0, |
// start on server root |
1204 |
strlen($fsScriptDir)-strlen($relScriptDir)) ; |
// $gblFsRoot = substr($fsScriptDir,0, strlen($fsScriptDir)-strlen($relScriptDir)) ; |
1205 |
|
// or on script root |
1206 |
|
$gblFsRoot = $fsScriptDir; |
1207 |
// i.e. /home/httpd/html |
// i.e. /home/httpd/html |
1208 |
|
|
1209 |
$fsDir = $gblFsRoot . $relDir ; // current directory |
$fsDir = $gblFsRoot . $relDir ; // current directory |
1210 |
if ( !is_dir($fsDir) ) Error("Dir not found",$relDir) ; |
if ( !is_dir($fsDir) ) Error("Dir not found",$relDir) ; |
1211 |
|
|
1212 |
|
if (isset($GLOBALS["HTTPS"]) && $GLOBALS["HTTPS"] == "on") { |
1213 |
|
$webRoot = "https://"; |
1214 |
|
} else { |
1215 |
|
$webRoot = "http://"; |
1216 |
|
} |
1217 |
|
$webRoot .= $GLOBALS["HTTP_HOST"] . $relScriptDir; |
1218 |
|
|
1219 |
|
$FN=stripSlashes($FN); |
1220 |
|
|
1221 |
switch ($POSTACTION) { |
switch ($POSTACTION) { |
1222 |
case "UPLOAD" : |
case "UPLOAD" : |
1223 |
if (!is_writeable($fsDir)) Error("Write denied",$relDir) ; |
if (!is_writeable($fsDir)) Error("Write denied",$relDir) ; |
1226 |
// TODO : should rather check for escapeshellcmds |
// TODO : should rather check for escapeshellcmds |
1227 |
// but maybe RFC 18xx asserts safe filenames .... |
// but maybe RFC 18xx asserts safe filenames .... |
1228 |
$source = $FN ; |
$source = $FN ; |
1229 |
$target = $fsDir . "/" . $FN_name ; |
if (! file_exists($source)) { |
1230 |
|
Error("You must select file with browse to upload it!"); |
1231 |
|
} |
1232 |
|
if (! isset($FILENAME)) { // from update file |
1233 |
|
$target = "$fsDir/$FN_name" ; |
1234 |
|
} else { |
1235 |
|
$target = "$fsDir/$FILENAME"; |
1236 |
|
} |
1237 |
|
|
1238 |
// backup old files first |
// backup old files first |
1239 |
$dir=dirname($target); |
$dir=dirname($target); |
1247 |
for($i=$GLOBALS[gblNumBackups]-1;$i>0;$i--) { |
for($i=$GLOBALS[gblNumBackups]-1;$i>0;$i--) { |
1248 |
MoveTo("$dir/.bak/$i/$file","$dir/.bak/".($i+1)."/"); |
MoveTo("$dir/.bak/$i/$file","$dir/.bak/".($i+1)."/"); |
1249 |
} |
} |
1250 |
MoveTo($target,$dir."/.bak/1/".$file); |
MoveTo($target,$dir."/.bak/1/"); |
1251 |
|
|
1252 |
copy($source,$target) ; |
copy($source,$target) ; |
1253 |
chmod($target,$gblFilePerms) ; |
chmod($target,$gblFilePerms) ; |
1254 |
clearstatcache() ; |
clearstatcache() ; |
1255 |
Logit($target,"uploaded"); |
Logit($target,"uploaded"); |
1256 |
|
if (isset($FILENAME)) { |
1257 |
|
Unlock($target); |
1258 |
|
} |
1259 |
|
ChangeLog($target,"updated"); |
1260 |
break ; |
break ; |
1261 |
|
|
1262 |
case "SAVE" : |
case "SAVE" : |
1263 |
$path = $gblFsRoot . escapeshellcmd($RELPATH) ; |
$path = $gblFsRoot . $RELPATH ; |
1264 |
|
$path=stripSlashes($path); |
1265 |
$writable = is_writeable($path) ; |
$writable = is_writeable($path) ; |
1266 |
$legaldir = is_writeable(dirname($path)) ; |
$legaldir = is_writeable(dirname($path)) ; |
1267 |
$exists = (file_exists($path)) ? 1 : 0 ; |
$exists = (file_exists($path)) ? 1 : 0 ; |
1269 |
if (!($writable || (!$exists && $legaldir))) |
if (!($writable || (!$exists && $legaldir))) |
1270 |
Error("Write denied",$RELPATH) ; |
Error("Write denied",$RELPATH) ; |
1271 |
$fh = fopen($path, "w") ; |
$fh = fopen($path, "w") ; |
1272 |
|
$FILEDATA=stripSlashes($FILEDATA); |
1273 |
fwrite($fh,$FILEDATA) ; |
fwrite($fh,$FILEDATA) ; |
1274 |
fclose($fh) ; |
fclose($fh) ; |
1275 |
clearstatcache() ; |
clearstatcache() ; |
1276 |
Logit($path,"saved changes"); |
Logit($path,"saved changes"); |
1277 |
|
ChangeLog($path,"saved changes"); |
1278 |
break ; |
break ; |
1279 |
|
|
1280 |
case "CREATE" : |
case "CREATE" : |
1285 |
$relPath = $relDir . "/" . $FN ; |
$relPath = $relDir . "/" . $FN ; |
1286 |
switch ( $T ) { |
switch ( $T ) { |
1287 |
case "D" : // create a directory |
case "D" : // create a directory |
1288 |
if ( ! @mkdir($path,$gblDirPerms) ) |
if ( ! @mkdir($path,$gblDirPerms) ) |
1289 |
Error("Mkdir failed",$relPath) ; // eg. if it exists |
Error("Mkdir failed",$relPath) ; // eg. if it exists |
1290 |
clearstatcache() ; |
clearstatcache() ; |
1291 |
break ; |
break ; |
1292 |
case "F" : // create a new file |
case "F" : // create a new file |
1293 |
// this functionality is doubled in DetailView(). |
// this functionality is doubled in DetailView(). |
1294 |
// better keep it here altogether |
// better keep it here altogether |
1295 |
// chmod perms to $gblFilePerms |
// chmod perms to $gblFilePerms |
1296 |
if ( file_exists($path) && !is_writable($path) ) |
if ( file_exists($path) && !is_writable($path) ) |
1297 |
Error("File not writable", $relPath) ; |
Error("File not writable", $relPath) ; |
1298 |
$tstr = $PHP_SELF . "?A=E&D=" . $relDir . "&F=" . $FN ; |
$fh = fopen($path, "w+") ; |
1299 |
header("Location: " . $tstr) ; |
if ($fh) { |
1300 |
exit ; |
fputs($fh,"\n"); |
1301 |
|
fclose($fh) ; |
1302 |
|
LogIt($path,"file created"); |
1303 |
|
} else { |
1304 |
|
Error("Creation of file $relPath failed -- $path"); |
1305 |
|
} |
1306 |
|
$tstr = "$PHP_SELF?A=E&D=".urlencode($relDir)."&F=".urlencode($FN) ; |
1307 |
|
header("Location: " . $tstr) ; |
1308 |
|
ChangeLog($target,"created"); |
1309 |
|
exit ; |
1310 |
} |
} |
1311 |
break ; |
break ; |
1312 |
|
|
1332 |
exit ; |
exit ; |
1333 |
} else { |
} else { |
1334 |
Logit($path,"file deleted"); |
Logit($path,"file deleted"); |
|
if (! file_exists("$dir/.del/.log")) { |
|
|
mkdir("$dir/.del/.log",0700); |
|
|
} |
|
1335 |
MoveTo("$dir/.log/$file","$dir/.del/.log/"); |
MoveTo("$dir/.log/$file","$dir/.del/.log/"); |
1336 |
MoveTo("$dir/.note/$file","$dir/.del/.note/"); |
MoveTo("$dir/.note/$file","$dir/.del/.note/"); |
1337 |
|
MoveTo("$dir/.lock/$file","$dir/.del/.lock/"); |
1338 |
} |
} |
1339 |
} |
} |
1340 |
else { // delete directory |
else { // delete directory |
1341 |
if ( ! @rmdir($fsDir) ) { |
if ( ! @rrmdir($fsDir) ) { |
1342 |
Error("Rmdir failed", $tstr . $fsDir) ; |
Error("Rmdir failed", $tstr . $fsDir) ; |
1343 |
} |
} |
1344 |
else { |
else { |
1357 |
MoveTo("$fsDir/.del/$file","$fsDir/"); |
MoveTo("$fsDir/.del/$file","$fsDir/"); |
1358 |
MoveTo("$fsDir/.del/.log/$file","$fsDir/.log/"); |
MoveTo("$fsDir/.del/.log/$file","$fsDir/.log/"); |
1359 |
MoveTo("$fsDir/.del/.note/$file","$fsDir/.note/"); |
MoveTo("$fsDir/.del/.note/$file","$fsDir/.note/"); |
1360 |
|
MoveTo("$fsDir/.del/.lock/$file","$fsDir/.lock/"); |
1361 |
|
|
1362 |
break ; |
break ; |
1363 |
|
|
1365 |
if ( $CONFIRM != "on" ) break ; |
if ( $CONFIRM != "on" ) break ; |
1366 |
|
|
1367 |
Logit("$fsDir/$FN","renamed $FN to $NEWNAME"); |
Logit("$fsDir/$FN","renamed $FN to $NEWNAME"); |
1368 |
rename("$fsDir/$FN","$fsDir/$NEWNAME"); |
safe_rename("$fsDir/$FN","$fsDir/$NEWNAME"); |
1369 |
rename("$fsDir/.log/$FN","$fsDir/.log/$NEWNAME"); |
safe_rename("$fsDir/.log/$FN","$fsDir/.log/$NEWNAME"); |
1370 |
|
safe_rename("$fsDir/.note/$FN","$fsDir/.note/$NEWNAME"); |
1371 |
|
safe_rename("$fsDir/.lock/$FN","$fsDir/.lock/$NEWNAME"); |
1372 |
|
for($i=0;$i<=$GLOBALS[gblNumBackups];$i++) { |
1373 |
|
safe_rename("$fsDir/.bak/$i/$FN","$fsDir/.bak/$i/$NEWNAME"); |
1374 |
|
} |
1375 |
|
|
1376 |
break ; |
break ; |
1377 |
|
|
1379 |
WriteNote("$fsDir/$FN","$NOTE"); |
WriteNote("$fsDir/$FN","$NOTE"); |
1380 |
break ; |
break ; |
1381 |
|
|
1382 |
|
case "UNLOCK" : |
1383 |
|
if ( $CONFIRM != "on" ) break ; |
1384 |
|
Unlock("$fsDir/$FN"); |
1385 |
|
break ; |
1386 |
|
|
1387 |
default : |
default : |
1388 |
// user hit "CANCEL" or undefined action |
// user hit "CANCEL" or undefined action |
1389 |
} |
} |
1399 |
// $A=U : upload to path given in $D |
// $A=U : upload to path given in $D |
1400 |
// $A=E : display detail of file $D/$F and edit |
// $A=E : display detail of file $D/$F and edit |
1401 |
// $A=C : display code in file $D/$F |
// $A=C : display code in file $D/$F |
1402 |
|
// $A=Co : checkout file $D/$F |
1403 |
|
// $A=Ci : checkin file $D/$F |
1404 |
|
// $A=V : view file (do nothing except log) |
1405 |
// default : display directory $D |
// default : display directory $D |
1406 |
|
|
1407 |
switch ($A) { |
switch ($A) { |
1408 |
case "U" : |
case "U" : |
1409 |
// upload to $relDir |
// upload to $relDir |
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 upload a single " ; |
$text = "Use this page to upload a single " ; |
1413 |
$text .= "file to <B>$SERVER_NAME</B>." ; |
$text .= "file to <B>$HTTP_HOST</B>." ; |
1414 |
StartHTML("(Upload Page)", $text) ; |
StartHTML("(Upload Page)", $text) ; |
1415 |
UploadPage($gblFsRoot, $relDir) ; |
UploadPage($gblFsRoot, $relDir) ; |
1416 |
EndHTML() ; |
EndHTML() ; |
1417 |
exit ; |
exit ; |
1418 |
case "E" : |
case "E" : |
1419 |
|
$F=stripSlashes($F); |
1420 |
// detail of $relDir/$F |
// detail of $relDir/$F |
1421 |
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) ; |
1422 |
exit ; |
exit ; |
1423 |
case "C" : |
case "C" : |
1424 |
|
$F=stripSlashes($F); |
1425 |
// listing of $relDir/$F |
// listing of $relDir/$F |
1426 |
DisplayCode($gblFsRoot, $relDir, $F) ; |
DisplayCode($gblFsRoot, $relDir, $F) ; |
1427 |
exit ; |
exit ; |
1428 |
|
case "Co" : |
1429 |
|
// checkout |
1430 |
|
Lock("$gblFsRoot/$relDir/$F"); |
1431 |
|
header("Content-Disposition: attachment; filename=$F" ); |
1432 |
|
Header("Location: $webRoot".urlpath("$relDir/$F")); |
1433 |
|
exit; |
1434 |
|
case "Ci" : |
1435 |
|
$F=stripSlashes($F); |
1436 |
|
// upload && update to $relDir |
1437 |
|
if (!is_writeable($gblFsRoot . $relDir)) |
1438 |
|
Error("Write access denied",$relDir) ; |
1439 |
|
$text = "Use this page to update a single " ; |
1440 |
|
$text .= "file to <B>$HTTP_HOST</B>." ; |
1441 |
|
StartHTML("(Update file Page)", $text) ; |
1442 |
|
UploadPage($gblFsRoot, $relDir, $F) ; |
1443 |
|
EndHTML() ; |
1444 |
|
exit ; |
1445 |
|
case "V" : |
1446 |
|
// view |
1447 |
|
LogIt("$gblFsRoot/$relDir/$F","viewed"); |
1448 |
|
header("Content-Disposition: attachment; filename=$F" ); |
1449 |
|
Header("Location: $webRoot".urlpath("$relDir/$F")); |
1450 |
|
exit; |
1451 |
|
case "Ch" : |
1452 |
|
StartHTML("(File changes)","All changes chronologicaly..."); |
1453 |
|
DisplayChangeLog(0); // all |
1454 |
|
EndHTML() ; |
1455 |
|
exit; |
1456 |
|
case "Ch1" : |
1457 |
|
StartHTML("(File changes)","Changes to files in last day..."); |
1458 |
|
DisplayChangeLog(1); |
1459 |
|
EndHTML() ; |
1460 |
|
exit; |
1461 |
} |
} |
1462 |
|
|
1463 |
// default: display directory $relDir |
// default: display directory $relDir |