34 |
/* PHP3. Fixed bug which would send you to a non- */ |
/* PHP3. Fixed bug which would send you to a non- */ |
35 |
/* existent address after file modifications. */ |
/* existent address after file modifications. */ |
36 |
|
|
37 |
|
/* |
38 |
|
2000-07-25 Dobrica Pavlinusic <dpavlin@rot13.org> |
39 |
|
|
40 |
|
nuked exec calls (unsecure) |
41 |
|
nuked writeable function (replaced by php is_writeable) |
42 |
|
added support for https (tested with apache+mod_ssl) |
43 |
|
added users file |
44 |
|
date format user-selectable |
45 |
|
cycle backup files in bak directory |
46 |
|
support links as directoryes (for now) |
47 |
|
support of file history logging |
48 |
|
undelete capabilities (delete moves to .del directory) |
49 |
|
|
50 |
|
2000-07-26 DbP |
51 |
|
|
52 |
|
added more checking on entered filename (when creating file/dir) |
53 |
|
added rename option |
54 |
|
|
55 |
|
|
56 |
|
IMPORTANT INSTALLATION NOTE: |
57 |
|
deny serving of .* (dot-something) files in web server! |
58 |
|
Otherwise, uses can access your log files, users and/or |
59 |
|
deleted files! |
60 |
|
|
61 |
|
.htusers is in form: |
62 |
|
login:Real Name:md5(loginpassword) |
63 |
|
|
64 |
|
|
65 |
|
TODO: |
66 |
|
mixed file/directory output (add type to each entry, |
67 |
|
real support for links) |
68 |
|
add more content-management (like cms.sourceforge.net): |
69 |
|
check-out/check-in/reserve |
70 |
|
comments to files |
71 |
|
*/ |
72 |
|
|
73 |
////////////////////////////////////////////////////////////////// |
////////////////////////////////////////////////////////////////// |
74 |
|
|
75 |
// TODO : Don't let the file be modified itself. Create a hash of |
// TODO : Don't let the file be modified itself. Create a hash of |
87 |
// username/password should not be system |
// username/password should not be system |
88 |
// usernames/passwords !! |
// usernames/passwords !! |
89 |
|
|
90 |
// your (hashed) username/password here |
// $gblPw = "hash_of_your_username_and_password" ; |
91 |
$gblPw = "hash_of_your_username_and_password" ; |
|
92 |
|
// $gblAuth = false ; // use builtin authentication |
93 |
$gblAuth = false ; // use builtin authentication |
$gblAuth = true ; // use builtin authentication |
94 |
$gblHash = "md5" ; // hash function to use |
$gblHash = "md5" ; // hash function to use |
95 |
|
|
96 |
|
$gblPw = ""; |
97 |
|
|
98 |
|
if ($gblAuth) { |
99 |
|
$htusers=fopen(dirname($SCRIPT_FILENAME)."/.htusers","r"); |
100 |
|
while($user = fgetcsv($htusers,255,":")) { |
101 |
|
if ($user[0] == $GLOBALS["PHP_AUTH_USER"]) { |
102 |
|
$gblUserName=$user[1]; |
103 |
|
$gblPw=$user[2]; |
104 |
|
continue ; |
105 |
|
} |
106 |
|
} |
107 |
|
fclose($htusers); |
108 |
|
} |
109 |
|
|
110 |
|
// $gblDateFmt="D, F d, Y"; |
111 |
|
// $gblTimeFmt="g:i:sA"; |
112 |
|
|
113 |
|
$gblDateFmt="Y-m-d"; |
114 |
|
$gblTimeFmt="H:i:s"; |
115 |
|
|
116 |
|
// Number of backup files to keep |
117 |
|
$gblNumBackups=5; |
118 |
|
|
119 |
// choose GifIcon below unless you have the M$ |
// choose GifIcon below unless you have the M$ |
120 |
// WingDings font installed on your system |
// WingDings font installed on your system |
121 |
|
|
174 |
|
|
175 |
<HR> |
<HR> |
176 |
<P CLASS=FTR> |
<P CLASS=FTR> |
177 |
<B><?php echo date("D, F d, Y") ?> - |
<B><?= date($GLOBALS[gblDateFmt]) ?> - |
178 |
<?php echo date("g:i:sA") ?></B><BR>ANYPORTAL(php) Site Manager |
<?= date($GLOBALS[gblTimeFmt]) ?> - |
179 |
- © 1999 by <A HREF="http://www.anyportal.com">ANYPORTAL</A> |
<?= $GLOBALS[gblUserName] ?> |
180 |
- © 2000 by <A HREF="http://da.nger.org">d@nger.org</A> |
<small> [<a href="<?= $PHP_SELF ?>?relogin=<?= $GLOBALS[gblPw] ?>">logout</a>]</small> |
181 |
|
</B> |
182 |
|
<BR>ANYPORTAL(php) Site Manager |
183 |
|
<br><small> |
184 |
|
© 1999 by <A HREF="http://www.anyportal.com">ANYPORTAL</A>, |
185 |
|
© 2000 by <A HREF="http://da.nger.org">d@nger.org</A>, |
186 |
|
© 2000 by <A HREF="https://www.rot13.org/~dpavlin/">DbP</A> |
187 |
|
</small> |
188 |
</P> |
</P> |
189 |
<BR><BR><BR></BODY></HTML> |
<BR> |
190 |
|
<? //include("../debug.inc") ?> |
191 |
|
<BR><BR></BODY></HTML> |
192 |
|
|
193 |
<?php |
<?php |
194 |
} // end function EndHTML |
} // end function EndHTML |
198 |
function CSS() { |
function CSS() { |
199 |
?> |
?> |
200 |
|
|
201 |
BODY,TD,P,H1,H2,H3 { font-family:Helvetica,Arial,sans-serif; } |
BODY,TD,P,H1,H2,H3 { font-family:Verdana,Helvetica,Arial,sans-serif; } |
202 |
.BLK { color:black; } |
.BLK { color:black; } |
203 |
.RED { color:red; } |
.RED { color:red; } |
204 |
.TOP { color:red; font-size:70%; } /* table headings */ |
.TOP { color:red; font-size:70%; } /* table headings */ |
232 |
$exists = file_exists($fsPath) ; |
$exists = file_exists($fsPath) ; |
233 |
$ext = strtolower(strrchr($relPath,".")) ; |
$ext = strtolower(strrchr($relPath,".")) ; |
234 |
$editable = ( $ext=="" || strstr(join(" ",$gblEditable),$ext)) ; |
$editable = ( $ext=="" || strstr(join(" ",$gblEditable),$ext)) ; |
235 |
$writable = Writeable($fsPath) ; |
$writable = is_writeable($fsPath) ; |
236 |
|
|
237 |
if (!$editable && !$exists) |
if (!$editable && !$exists) |
238 |
Error("Creation unsupported for type",$relPath) ; |
Error("Creation unsupported for type",$relPath) ; |
239 |
if (!exists && !Writeable($fsDir) ) |
if (!exists && !is_writeable($fsDir) ) |
240 |
Error("Creation denied",$relDir) ; |
Error("Creation denied",$relDir) ; |
241 |
|
|
242 |
$text = "Use this page to view, modify or " ; |
$text = "Use this page to view, modify or " ; |
248 |
echo "<H3>" . $relDir . "/" . $fn . "</H3>" ; |
echo "<H3>" . $relDir . "/" . $fn . "</H3>" ; |
249 |
if ($exists) { // get file info |
if ($exists) { // get file info |
250 |
$fsize = filesize($fsPath) ; |
$fsize = filesize($fsPath) ; |
251 |
$fmodified = date("d/M/y G:i:s", filemtime($fsPath)) ; |
$fmodified = date("$GLOBALS[gblDateFmt] $GLOBALS[gblTimeFmt]", filemtime($fsPath)) ; |
252 |
$faccessed = date("d/M/y G:i:s", fileatime($fsPath)) ; |
$faccessed = date("$GLOBALS[gblDateFmt] $GLOBALS[gblTimeFmt]", fileatime($fsPath)) ; |
253 |
echo "<PRE> file size: " . $fsize . " Bytes<BR>" ; |
echo "<PRE> file size: " . $fsize . " Bytes<BR>" ; |
254 |
echo "last modified: <B>" . $fmodified . "</B><BR>" ; |
echo "last modified: <B>" . $fmodified . "</B><BR>" ; |
255 |
echo "last accessed: <B>" . $faccessed . "</B><BR>" ; |
echo "last accessed: <B>" . $faccessed . "</B><BR>" ; |
258 |
echo " permissions: <B>" ; |
echo " permissions: <B>" ; |
259 |
echo printf( "%o", fileperms($fsPath) ) . "</B>" ; |
echo printf( "%o", fileperms($fsPath) ) . "</B>" ; |
260 |
echo "</PRE>" ; |
echo "</PRE>" ; |
261 |
|
|
262 |
} |
} |
263 |
|
|
264 |
if ( $editable && ($writable || !$exists) ) { |
if ( $editable && ($writable || !$exists) ) { |
278 |
<INPUT TYPE="HIDDEN" NAME="DIR" VALUE="<?php echo $relDir ; ?>"> |
<INPUT TYPE="HIDDEN" NAME="DIR" VALUE="<?php echo $relDir ; ?>"> |
279 |
<INPUT TYPE="HIDDEN" NAME="FN" VALUE="<?php echo $fn ; ?>"> |
<INPUT TYPE="HIDDEN" NAME="FN" VALUE="<?php echo $fn ; ?>"> |
280 |
<INPUT TYPE="HIDDEN" NAME="POSTACTION" VALUE="SAVE"> |
<INPUT TYPE="HIDDEN" NAME="POSTACTION" VALUE="SAVE"> |
281 |
<INPUT TYPE="TEXT" SIZE=48 MAXLENGTH=255 NAME="RELPATH" |
<INPUT TYPE="HIDDEN" SIZE=48 MAXLENGTH=255 NAME="RELPATH" |
282 |
VALUE="<?php echo $relPath ; ?>"> |
VALUE="<?php echo $relPath ; ?>"> |
283 |
<INPUT TYPE="RESET" VALUE="RESET"> |
<br> |
284 |
|
<INPUT TYPE="RESET" VALUE="UNDO ALL CHANGES"> |
285 |
<INPUT TYPE="SUBMIT" VALUE="SAVE"> |
<INPUT TYPE="SUBMIT" VALUE="SAVE"> |
286 |
</FORM> |
</FORM> |
287 |
|
|
302 |
<INPUT TYPE="SUBMIT" NAME="POSTACTION" VALUE="CANCEL"><BR> |
<INPUT TYPE="SUBMIT" NAME="POSTACTION" VALUE="CANCEL"><BR> |
303 |
|
|
304 |
<?php |
<?php |
305 |
|
if (substr($fn,0,4) == ".del") { |
306 |
|
$action="UNDELETE"; |
307 |
|
$desc="undelete previously deleted file"; |
308 |
|
} else { |
309 |
|
$action="DELETE"; |
310 |
|
$desc="delete"; |
311 |
|
} |
312 |
|
|
313 |
if ($exists && $writable) { |
if ($exists && $writable) { |
314 |
?> |
?> |
315 |
|
|
316 |
<HR><SPAN TITLE="Check OK and click [DELETE] to delete."> |
<HR><SPAN TITLE="Check OK and click [<?= $action ?>] to <?= $desc ?>."> |
317 |
<B>OK TO DELETE "<?php echo $fn ; ?>"? </B></SPAN> |
<B>OK TO <?= $action ?> "<?php echo $fn ; ?>"? </B></SPAN> |
318 |
|
<INPUT TYPE="CHECKBOX" NAME="CONFIRM"> |
319 |
|
<INPUT TYPE="SUBMIT" NAME="POSTACTION" VALUE="<?= $action ?>"> |
320 |
|
|
321 |
|
<HR><SPAN TITLE="Check OK and click [RENAME] to rename."> |
322 |
|
<B>OK TO RENAME "<?php echo $fn ; ?>" TO |
323 |
|
<INPUT TYPE="TEXT" SIZE=24 MAXLENGTH=255 NAME="NEWNAME" VALUE="<?= $fn ?>"> |
324 |
|
? </B></SPAN> |
325 |
<INPUT TYPE="CHECKBOX" NAME="CONFIRM"> |
<INPUT TYPE="CHECKBOX" NAME="CONFIRM"> |
326 |
<INPUT TYPE="SUBMIT" NAME="POSTACTION" VALUE="DELETE"> |
<INPUT TYPE="SUBMIT" NAME="POSTACTION" VALUE="RENAME"> |
327 |
|
|
328 |
<?php |
<?php |
329 |
} |
} |
330 |
echo "</FORM>" ; |
echo "</FORM>" ; |
331 |
|
|
332 |
|
$logname=dirname("$fsDir/$fn")."/.log/".basename("$fsDir/$fn"); |
333 |
|
if (file_exists($logname)) { |
334 |
|
print "<hr><br><b>CHANGES TO THIS FILE</b><br><table border=0 width=100%>\n"; |
335 |
|
$log=fopen($logname,"r"); |
336 |
|
$cl1=" class=lst"; $cl2=""; |
337 |
|
while($line = fgetcsv($log,255,"\t")) { |
338 |
|
$cl=$cl1; $cl1=$cl2; $cl2=$cl; |
339 |
|
print "<tr><td$cl>$line[0]</td><td$cl>$line[1]</td><td$cl>$line[2]</td><td$cl>$line[3]</td></tr>\n"; |
340 |
|
} |
341 |
|
fclose($log); |
342 |
|
print "</table>"; |
343 |
|
} |
344 |
|
|
345 |
EndHTML() ; |
EndHTML() ; |
346 |
|
|
347 |
} // end function DetailPage |
} // end function DetailPage |
585 |
global $gblEditable, $gblIcon ; |
global $gblEditable, $gblIcon ; |
586 |
|
|
587 |
$self = $GLOBALS["PHP_SELF"] ; |
$self = $GLOBALS["PHP_SELF"] ; |
588 |
$webRoot = "http://" . $GLOBALS["SERVER_NAME"] ; |
if (isset($GLOBALS["HTTPS"]) && $GLOBALS["HTTPS"] == "on") { |
589 |
|
$webRoot = "https://" . $GLOBALS["SERVER_NAME"] ; |
590 |
|
} else { |
591 |
|
$webRoot = "http://" . $GLOBALS["SERVER_NAME"] ; |
592 |
|
} |
593 |
$fsDir = $fsRoot . $relDir . "/" ; // current directory |
$fsDir = $fsRoot . $relDir . "/" ; // current directory |
594 |
|
|
595 |
if (!is_dir($fsDir)) Error("Dir not found",$relDir) ; |
if (!is_dir($fsDir)) Error("Dir not found",$relDir) ; |
598 |
if ( !($dir = @opendir($fsDir)) ) |
if ( !($dir = @opendir($fsDir)) ) |
599 |
Error("Read Access denied",$relDir) ; |
Error("Read Access denied",$relDir) ; |
600 |
while ($item = readdir($dir)) { |
while ($item = readdir($dir)) { |
601 |
if ( $item == ".." || $item == "." ) continue ; |
if ( $item == ".." || $item == "." || substr($item,0,1) == "." ) continue ; |
602 |
if ( is_dir($fsDir . $item) ) { |
if ( is_dir($fsDir . $item) ) { |
603 |
$dirList[] = $item ; |
$dirList[] = $item ; |
604 |
} |
} else if ( is_file($fsDir . $item) ) { |
|
else if ( is_file($fsDir . $item) ) { |
|
605 |
$fileList[] = $item ; |
$fileList[] = $item ; |
606 |
} |
} else if ( is_link($fsDir . $item) ) { |
607 |
else { |
$dirList[] = $item ; |
608 |
|
} else { |
609 |
// unknown file type |
// unknown file type |
610 |
// $text = "Could not determine file type of " ; |
// $text = "Could not determine file type of " ; |
611 |
// Error("File Error", $text.$relDir."/".$item) ; |
// Error("File Error", $text.$relDir."/".$item) ; |
613 |
} |
} |
614 |
} |
} |
615 |
closedir($dir) ; |
closedir($dir) ; |
616 |
|
|
617 |
|
// scan deleted files |
618 |
|
if ( $GLOBALS[show_deleted] == 1 && ($dir = @opendir("$fsDir/.del")) ) { |
619 |
|
while ($item = readdir($dir)) { |
620 |
|
if ( substr($item,0,1) == "." ) continue ; |
621 |
|
$fileList[] = ".del/$item" ; |
622 |
|
} |
623 |
|
closedir($dir) ; |
624 |
|
} |
625 |
|
|
626 |
$emptyDir = ! (sizeof($dirList) || sizeof($fileList)) ; |
$emptyDir = ! (sizeof($dirList) || sizeof($fileList)) ; |
627 |
|
|
628 |
// start navigation page |
// start navigation page |
629 |
$text = "Use this page to add, delete or " ; |
$text = "Use this page to add, delete"; |
630 |
$text .= "revise files on this web site." ; |
if (! isset($show_deleted)) { |
631 |
|
$text .= ", <a href=$PHP_SELF?show_deleted=1>undelete</a>"; |
632 |
|
} |
633 |
|
$text .= " or revise files on this web site." ; |
634 |
StartHTML("(Navigate)",$text) ; |
StartHTML("(Navigate)",$text) ; |
635 |
|
|
636 |
echo "<TABLE BORDER=0 CELLPADDING=2 |
echo "<TABLE BORDER=0 CELLPADDING=2 |
702 |
|
|
703 |
$tstr = $webRoot . $relDir . "/" . $file ; |
$tstr = $webRoot . $relDir . "/" . $file ; |
704 |
$tstr = "<A HREF=\"" . $tstr . "\">" ; |
$tstr = "<A HREF=\"" . $tstr . "\">" ; |
705 |
$tstr .= $file . "</A>" . $a ; |
|
706 |
|
if (substr($file,0,5) != ".del/") { |
707 |
|
$tstr .= $file . "</A>" . $a ; |
708 |
|
} else { |
709 |
|
$tstr .= substr($file,5,strlen($file)-5) . "</a> <SPAN CLASS=RED TITLE=\"deleted\"> deleted </span>"; |
710 |
|
} |
711 |
|
|
712 |
$ext = strtolower(strrchr($file,".")) ; |
$ext = strtolower(strrchr($file,".")) ; |
713 |
if ( $ext=="" || |
if ( $ext=="" || |
727 |
<?php echo $gblIcon($ext) ?></A></TD> |
<?php echo $gblIcon($ext) ?></A></TD> |
728 |
<TD CLASS=LST><?php echo $tstr ?></TD> |
<TD CLASS=LST><?php echo $tstr ?></TD> |
729 |
<TD CLASS=LST ALIGN=center><?php echo $b ?></TD> |
<TD CLASS=LST ALIGN=center><?php echo $b ?></TD> |
730 |
<TD CLASS=LST><?php echo date("d/M/y G:i:s",$mod) ?></TD> |
<TD CLASS=LST><?php echo date("$GLOBALS[gblDateFmt] $GLOBALS[gblTimeFmt]",$mod) ?></TD> |
731 |
<TD CLASS=LST><?php echo $sz ?>Bytes</TD></TR> |
<TD CLASS=LST><?php echo $sz ?>Bytes</TD></TR> |
732 |
|
|
733 |
<?php |
<?php |
814 |
|
|
815 |
////////////////////////////////////////////////////////////////// |
////////////////////////////////////////////////////////////////// |
816 |
|
|
|
function Writeable($path) { |
|
|
// fix by -mat- filid brandy, brandy@ecrc.de, 07/JUL/99 |
|
|
|
|
|
clearstatcache ; |
|
|
$perms = @fileperms($path) ; |
|
|
$owner = @fileowner($path) ; |
|
|
exec("id",$id) ; |
|
|
eregi( "^uid=([0-9]*)",$id[0], $regs) ; |
|
|
$apacheuid = $regs[1] ; |
|
|
$perms = 0777 & $perms ; |
|
|
if ( $apacheuid != $owner ) { |
|
|
return (06 == (06 & $perms)) ? 1 : 0 ; |
|
|
} |
|
|
else { |
|
|
return (0600 == (0600 & $perms)) ? 1 : 0 ; |
|
|
} |
|
|
|
|
|
} // end function Writable |
|
|
|
|
|
////////////////////////////////////////////////////////////////// |
|
|
|
|
817 |
function CreateHash($user, $pw) { |
function CreateHash($user, $pw) { |
818 |
|
|
819 |
global $gblHash ; // hash function to use |
global $gblHash ; // hash function to use |
866 |
|
|
867 |
////////////////////////////////////////////////////////////////// |
////////////////////////////////////////////////////////////////// |
868 |
|
|
869 |
|
function Logit($target,$msg) { |
870 |
|
|
871 |
|
$dir=dirname($target); |
872 |
|
if (! file_exists($dir."/.log")) { |
873 |
|
mkdir($dir."/.log",0700); |
874 |
|
} |
875 |
|
$file=basename($target); |
876 |
|
|
877 |
|
$log=fopen("$dir/.log/$file","a+"); |
878 |
|
fputs($log,date("$GLOBALS[gblDateFmt]\t$GLOBALS[gblTimeFmt]"). |
879 |
|
"\t$GLOBALS[gblUserName]\t$msg\n"); |
880 |
|
fclose($log); |
881 |
|
|
882 |
|
} |
883 |
|
|
884 |
|
|
885 |
|
|
886 |
|
////////////////////////////////////////////////////////////////// |
887 |
|
|
888 |
// MAIN PROGRAM |
// MAIN PROGRAM |
889 |
// ============ |
// ============ |
890 |
// query parameters: capital letters |
// query parameters: capital letters |
891 |
// local functions : begin with capital letters |
// local functions : begin with capital letters |
892 |
// global constants: begin with gbl |
// global constants: begin with gbl |
893 |
|
|
894 |
$gblFilePerms = "644" ; // default for new files |
$gblFilePerms = 0640 ; // default for new files |
895 |
$gblDirPerms = 0755 ; // default for new dirs |
$gblDirPerms = 0750 ; // default for new dirs |
896 |
|
|
897 |
// phpinfo() ; |
// phpinfo() ; |
898 |
// exit ; |
// exit ; |
906 |
} |
} |
907 |
|
|
908 |
// authentication if $gblAuth == true |
// authentication if $gblAuth == true |
909 |
if ( $gblAuth && |
if ( $gblAuth && $gblHash($PHP_AUTH_USER.$PHP_AUTH_PW) != $gblPw || |
910 |
$gblHash($PHP_AUTH_USER.$PHP_AUTH_PW) != $gblPw ) { |
isset($relogin) && $gblPw == $relogin ) { |
911 |
header("WWW-authenticate: basic realm=\"$SERVER_NAME\"") ; |
header("WWW-authenticate: basic realm=\"$SERVER_NAME\"") ; |
912 |
header("HTTP/1.0 401 Unauthorized") ; |
header("HTTP/1.0 401 Unauthorized") ; |
913 |
NoEntry() ; |
NoEntry() ; |
945 |
|
|
946 |
switch ($POSTACTION) { |
switch ($POSTACTION) { |
947 |
case "UPLOAD" : |
case "UPLOAD" : |
948 |
if (!Writeable($fsDir)) Error("Write denied",$relDir) ; |
if (!is_writeable($fsDir)) Error("Write denied",$relDir) ; |
949 |
if (strstr($FN_name,"/")) |
if (strstr($FN_name,"/")) |
950 |
Error("Non-conforming filename") ; |
Error("Non-conforming filename") ; |
951 |
// TODO : should rather check for escapeshellcmds |
// TODO : should rather check for escapeshellcmds |
952 |
// but maybe RFC 18xx asserts safe filenames .... |
// but maybe RFC 18xx asserts safe filenames .... |
953 |
$source = $FN ; |
$source = $FN ; |
954 |
$target = $fsDir . "/" . $FN_name ; |
$target = $fsDir . "/" . $FN_name ; |
955 |
exec("cp $source $target") ; |
|
956 |
exec("chmod $gblFilePerms $target") ; |
// backup old files first |
957 |
|
$dir=dirname($target); |
958 |
|
if (! file_exists($dir."/.bak")) { |
959 |
|
mkdir($dir."/.bak",0700); |
960 |
|
} |
961 |
|
if (! file_exists($dir."/.bak/$GLOBALS[gblNumBackups]")) { |
962 |
|
mkdir($dir."/.bak/$GLOBALS[gblNumBackups]",0700); |
963 |
|
} |
964 |
|
$file=basename($target); |
965 |
|
for($i=$GLOBALS[gblNumBackups]-1;$i>0;$i--) { |
966 |
|
if (! file_exists($dir."/.bak/".$i)) { |
967 |
|
mkdir($dir."/.bak/".$i,0700); |
968 |
|
} |
969 |
|
if (file_exists($dir."/.bak/".$i."/".$file)) { |
970 |
|
rename($dir."/.bak/".$i."/".$file, |
971 |
|
$dir."/.bak/".($i+1)."/".$file); |
972 |
|
} |
973 |
|
} |
974 |
|
if (file_exists($target)) { |
975 |
|
rename($target,$dir."/.bak/1/".$file); |
976 |
|
} |
977 |
|
|
978 |
|
copy($source,$target) ; |
979 |
|
chmod($target,$gblFilePerms) ; |
980 |
clearstatcache() ; |
clearstatcache() ; |
981 |
|
Logit($target,"uploaded"); |
982 |
break ; |
break ; |
983 |
|
|
984 |
case "SAVE" : |
case "SAVE" : |
985 |
$path = $gblFsRoot . escapeshellcmd($RELPATH) ; |
$path = $gblFsRoot . escapeshellcmd($RELPATH) ; |
986 |
$writable = Writeable($path) ; |
$writable = is_writeable($path) ; |
987 |
$legaldir = Writeable(dirname($path)) ; |
$legaldir = is_writeable(dirname($path)) ; |
988 |
$exists = (file_exists($path)) ? 1 : 0 ; |
$exists = (file_exists($path)) ? 1 : 0 ; |
989 |
// check for legal extension here as well |
// check for legal extension here as well |
990 |
if (!($writable || (!$exists && $legaldir))) |
if (!($writable || (!$exists && $legaldir))) |
993 |
fwrite($fh,$FILEDATA) ; |
fwrite($fh,$FILEDATA) ; |
994 |
fclose($fh) ; |
fclose($fh) ; |
995 |
clearstatcache() ; |
clearstatcache() ; |
996 |
|
Logit($path,"saved changes"); |
997 |
break ; |
break ; |
998 |
|
|
999 |
case "CREATE" : |
case "CREATE" : |
1000 |
// we know $fsDir exists |
// we know $fsDir exists |
1001 |
if (!Writeable($fsDir)) Error("Write denied",$relDir) ; |
if ($FN == "") break; // no filename! |
1002 |
|
if (!is_writeable($fsDir)) Error("Write denied",$relDir) ; |
1003 |
$path = $fsDir . "/" . $FN ; // file or dir to create |
$path = $fsDir . "/" . $FN ; // file or dir to create |
1004 |
$relPath = $relDir . "/" . $FN ; |
$relPath = $relDir . "/" . $FN ; |
1005 |
switch ( $T ) { |
switch ( $T ) { |
1012 |
// this functionality is doubled in DetailView(). |
// this functionality is doubled in DetailView(). |
1013 |
// better keep it here altogether |
// better keep it here altogether |
1014 |
// chmod perms to $gblFilePerms |
// chmod perms to $gblFilePerms |
1015 |
if ( file_exists($path) && !Writable($path) ) |
if ( file_exists($path) && !is_writable($path) ) |
1016 |
Error("File not writable", $relPath) ; |
Error("File not writable", $relPath) ; |
1017 |
$tstr = $PHP_SELF . "?A=E&D=" . $relDir . "&F=" . $FN ; |
$tstr = $PHP_SELF . "?A=E&D=" . $relDir . "&F=" . $FN ; |
1018 |
header("Location: " . $tstr) ; |
header("Location: " . $tstr) ; |
1027 |
$tstr .= "insufficient privileges: " ; |
$tstr .= "insufficient privileges: " ; |
1028 |
|
|
1029 |
if ( $FN != "") { // delete file |
if ( $FN != "") { // delete file |
1030 |
$path = $fsDir . "/" . $FN ; |
$path = $fsDir . "/" . $FN ; |
1031 |
if ( ! @unlink($path) ) { |
|
1032 |
Error("File delete failed", $tstr . $path) ; |
$dir=dirname($path); |
1033 |
exit ; |
$file=basename($path); |
1034 |
} |
if (! file_exists("$dir/.del")) { |
1035 |
|
mkdir("$dir/.del",0700); |
1036 |
|
} |
1037 |
|
|
1038 |
|
// if ( ! @unlink($path) ) { |
1039 |
|
if ( ! rename($path,"$dir/.del/$file") ) { |
1040 |
|
Error("File delete failed", $tstr . $path) ; |
1041 |
|
Logit($path,"file delete failed"); |
1042 |
|
exit ; |
1043 |
|
} else { |
1044 |
|
Logit($path,"file deleted"); |
1045 |
|
if (! file_exists("$dir/.del/.log")) { |
1046 |
|
mkdir("$dir/.del/.log",0700); |
1047 |
|
} |
1048 |
|
rename("$dir/.log/$file","$dir/.del/.log/$file"); |
1049 |
|
} |
1050 |
} |
} |
1051 |
else { // delete directory |
else { // delete directory |
1052 |
if ( ! @rmdir($fsDir) ) { |
if ( ! @rmdir($fsDir) ) { |
1058 |
} |
} |
1059 |
break ; |
break ; |
1060 |
|
|
1061 |
|
case "UNDELETE" : |
1062 |
|
if ( $CONFIRM != "on" ) break ; |
1063 |
|
|
1064 |
|
if (substr($FN,0,4) != ".del") break ; |
1065 |
|
$file=substr($FN,4,strlen($FN)-4); |
1066 |
|
|
1067 |
|
Logit("$fsDir/.del/$file","undeleted"); |
1068 |
|
rename("$fsDir/.del/$file","$fsDir/$file"); |
1069 |
|
rename("$fsDir/.del/.log/$file","$fsDir/.log/$file"); |
1070 |
|
|
1071 |
|
break ; |
1072 |
|
|
1073 |
|
case "RENAME" : |
1074 |
|
if ( $CONFIRM != "on" ) break ; |
1075 |
|
|
1076 |
|
Logit("$fsDir/$FN","renamed $FN to $NEWNAME"); |
1077 |
|
rename("$fsDir/$FN","$fsDir/$NEWNAME"); |
1078 |
|
rename("$fsDir/.log/$FN","$fsDir/.log/$NEWNAME"); |
1079 |
|
|
1080 |
|
break ; |
1081 |
|
|
1082 |
default : |
default : |
1083 |
// user hit "CANCEL" or undefined action |
// user hit "CANCEL" or undefined action |
1084 |
} |
} |
1099 |
switch ($A) { |
switch ($A) { |
1100 |
case "U" : |
case "U" : |
1101 |
// upload to $relDir |
// upload to $relDir |
1102 |
if (!Writeable($gblFsRoot . $relDir)) |
if (!is_writeable($gblFsRoot . $relDir)) |
1103 |
Error("Write access denied",$relDir) ; |
Error("Write access denied",$relDir) ; |
1104 |
$text = "Use this page to upload a single " ; |
$text = "Use this page to upload a single " ; |
1105 |
$text .= "file to <B>$SERVER_NAME</B>." ; |
$text .= "file to <B>$SERVER_NAME</B>." ; |
1109 |
exit ; |
exit ; |
1110 |
case "E" : |
case "E" : |
1111 |
// detail of $relDir/$F |
// detail of $relDir/$F |
1112 |
DetailPage($gblFsRoot, $relDir, $F) ; |
if (is_file("$gblFsRoot/$relDir/$F")) DetailPage($gblFsRoot, $relDir, $F) ; |
1113 |
exit ; |
exit ; |
1114 |
case "C" : |
case "C" : |
1115 |
// listing of $relDir/$F |
// listing of $relDir/$F |