1 |
<?php |
2 |
|
3 |
/* Copyright 1999 by John Martin d/b/a www.ANYPORTAL.com */ |
4 |
/* All Rights Reserved. */ |
5 |
/* */ |
6 |
/* This software is freeware and is not in the public domain. */ |
7 |
/* You are hereby granted the right to freely distribute this */ |
8 |
/* software as long as this copyright notice remains in place. */ |
9 |
/* */ |
10 |
/* Comments or suggestions? email: andmore@alief.com */ |
11 |
/* */ |
12 |
/* This is the PHP port: AnyPortal(php)-0.1 */ |
13 |
/* ======================================== */ |
14 |
/* */ |
15 |
/* PHP version 2000 by Stefan@Wiesendanger.org */ |
16 |
/* No Rights Reserved. What for, anyhow ? */ |
17 |
/* */ |
18 |
/* Date Remarks */ |
19 |
/* --------- ----------------------------------------------- */ |
20 |
/* 25 MAY 99 original ASP version */ |
21 |
/* 17 SEP 99 change upload from SA-FILEUP to aspSmartUpload */ |
22 |
/* 10 APR 00 simplified PHP3 version */ |
23 |
/* 18 APR 00 most of PHP3 port working. Slight modifications */ |
24 |
/* 22 APR 00 modified syntax highlighting, no absolute paths */ |
25 |
/* revealed, PHP builtin authentication, global */ |
26 |
/* style sheet as callback, use apache default */ |
27 |
/* icons as an alternative to the wingdings font. */ |
28 |
/* 25 APR 00 catch some exceptions (not foolproof yet) */ |
29 |
/* 26 APR 00 catch some more exceptions, implicit copy */ |
30 |
/* function by saving somewhere else in the detail */ |
31 |
/* view, MD5 hashed password. */ |
32 |
/* 27 APR 00 Fixed authentication bug */ |
33 |
/* 12 MAY 00 Fixed trouble with exec() with newer versions of */ |
34 |
/* PHP3. Fixed bug which would send you to a non- */ |
35 |
/* existent address after file modifications. */ |
36 |
|
37 |
/* |
38 |
|
39 |
This project is now called Directory Manager. |
40 |
|
41 |
For more info, please see web pages at |
42 |
http://www.rot13.org/~dpavlin/docman.html |
43 |
|
44 |
It's relased under GPL by |
45 |
Dobrica Pavlinusic <dpavlin@rot13.org> |
46 |
|
47 |
|
48 |
IMPORTANT INSTALLATION NOTE: |
49 |
deny serving of .* (dot-something) files in web server! |
50 |
Otherwise, uses can access your log files, users and/or |
51 |
deleted files! |
52 |
|
53 |
.htusers is in form: |
54 |
login:Real Name:[md5(loginpassword)|auth_*]:email@host.dom |
55 |
|
56 |
|
57 |
TODO: |
58 |
mixed file/directory output (add type to each entry, |
59 |
real support for links) |
60 |
access controll |
61 |
|
62 |
*/ |
63 |
|
64 |
////////////////////////////////////////////////////////////////// |
65 |
|
66 |
// TODO : Don't let the file be modified itself. Create a hash of |
67 |
// it (kinda hard since it's self-referential ;-). Make better use |
68 |
// of session management. Escapeshellcmd for all user input. |
69 |
|
70 |
////////////////////////////////////////////////////////////////// |
71 |
|
72 |
// GLOBAL PARAMETERS |
73 |
// ================= |
74 |
// Make modifications here to suit docman to your needs |
75 |
|
76 |
// 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 |
82 |
// usernames/passwords !! |
83 |
|
84 |
$gblPw = ""; |
85 |
|
86 |
$htusers_file=dirname($SCRIPT_FILENAME)."/.htusers"; |
87 |
if (! file_exists($htusers_file)) { |
88 |
$htusers=fopen($htusers_file,"a+"); |
89 |
fputs($htusers,"# Change owner of $htusers_file to root !!\n"); |
90 |
fputs($htusers,"demo:full name:[md5_hash|auth_*]:e-mail\n"); |
91 |
fclose($htusers); |
92 |
} |
93 |
$htusers=fopen($htusers_file,"r"); |
94 |
while($user = fgetcsv($htusers,255,":")) { |
95 |
if ($user[0] == $GLOBALS["PHP_AUTH_USER"]) { |
96 |
$gblUserName=$user[1]; |
97 |
$gblPw=$user[2]; |
98 |
if (substr($gblPw,0,5) == "auth_" && file_exists("$gblIncDir/$gblPw.php")) { |
99 |
require("$gblIncDir/$gblPw.php"); |
100 |
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 |
} |
109 |
} |
110 |
fclose($htusers); |
111 |
|
112 |
// date format |
113 |
// $gblDateFmt="D, F d, Y"; |
114 |
$gblDateFmt="Y-m-d"; |
115 |
|
116 |
// time format |
117 |
// $gblTimeFmt="g:i:sA"; |
118 |
$gblTimeFmt="H:i:s"; |
119 |
|
120 |
// Number of backup files to keep |
121 |
$gblNumBackups=3; |
122 |
|
123 |
// show red star if newer than ... days |
124 |
$gblModDays=1; |
125 |
|
126 |
// choose GifIcon below unless you have the M$ |
127 |
// WingDings font installed on your system |
128 |
|
129 |
$gblIcon="GifIcon"; // MockIcon or GifIcon |
130 |
|
131 |
// the directory below should be /icons/ or /icons/small/ |
132 |
// on Apache; a set of icons is included in the distribution |
133 |
|
134 |
$gblIconLocation="/icons/"; |
135 |
|
136 |
// files you want to be able to edit in text mode |
137 |
// and view with (primitive) syntax highlighting |
138 |
|
139 |
$gblEditable = array( ".txt",".asa",".asp",".htm",".html", |
140 |
".cfm",".php3",".php",".phtml", |
141 |
".shtml",".css" ) ; |
142 |
|
143 |
// files that will display as images on the detail page |
144 |
// (useless if your browser doesn't support them) |
145 |
|
146 |
$gblImages = array( ".jpg",".jpeg",".gif",".png",".ico", |
147 |
".bmp",".xbm") ; |
148 |
|
149 |
////////////////////////////////////////////////////////////////// |
150 |
|
151 |
function StartHTML($title,$text="") { |
152 |
|
153 |
$title = "Document Manager " . $title ; |
154 |
$host = $GLOBALS["HTTP_HOST"] ; |
155 |
$self = $GLOBALS["PHP_SELF"] ; |
156 |
?> |
157 |
|
158 |
<HTML> |
159 |
<HEAD> |
160 |
<TITLE><?= $host . " " . $title ?></TITLE> |
161 |
<META NAME="description" CONTENT="PHP port of AnyPortal Site Manager"> |
162 |
<META NAME="keywords" CONTENT="site manager, web site maintenance"> |
163 |
<META NAME="robots" CONTENT="noindex"> |
164 |
<META HTTP-EQUIV="expires" CONTENT="0"> |
165 |
<LINK REL="stylesheet" TYPE="text/css" |
166 |
HREF="<?= $self ?>?STYLE=get"> |
167 |
</HEAD> |
168 |
<BODY BGCOLOR="#FFFFFF"> |
169 |
<H3 ALIGN="RIGHT"><?= $host ?></H3> |
170 |
<TABLE BORDER=0 WIDTH="100%"><TR> |
171 |
<TD CLASS=INV><?= $title ?></TD></TR></TABLE> |
172 |
<P><?= $text ?></P> |
173 |
|
174 |
<?php |
175 |
} // end function StartHTML |
176 |
|
177 |
////////////////////////////////////////////////////////////////// |
178 |
|
179 |
function EndHTML() { |
180 |
?> |
181 |
|
182 |
<HR> |
183 |
<P CLASS=FTR> |
184 |
<B><?= date($GLOBALS[gblDateFmt]) ?> - |
185 |
<?= date($GLOBALS[gblTimeFmt]) ?> - |
186 |
<?= $GLOBALS[gblUserName] ?> |
187 |
<small> [<a href="<?= $GLOBALS["PHP_SELF"] ?>?relogin=<?= $GLOBALS[gblPw] ?>">logout</a>]</small> |
188 |
</B> |
189 |
<BR>ANYPORTAL(php) Site Manager |
190 |
<br><small> |
191 |
© 1999 by <A HREF="http://www.anyportal.com">ANYPORTAL</A>, |
192 |
© 2000 by <A HREF="http://da.nger.org">d@nger.org</A>, |
193 |
© 2000 by <A HREF="http://www.rot13.org/~dpavlin/">DbP</A> |
194 |
</small> |
195 |
</P> |
196 |
<BR> |
197 |
<? //include(".debug.inc") ?> |
198 |
<BR><BR></BODY></HTML> |
199 |
|
200 |
<?php |
201 |
} // end function EndHTML |
202 |
|
203 |
////////////////////////////////////////////////////////////////// |
204 |
|
205 |
function CSS() { |
206 |
?> |
207 |
|
208 |
BODY,TD,P,H1,H2,H3 { font-family:Verdana,Helvetica,Arial,sans-serif; } |
209 |
.BLK { color:black; } |
210 |
.RED { color:red; } |
211 |
.TOP { color:red; font-size:70%; } /* table headings */ |
212 |
.INV { color:white; background-color:navy; |
213 |
font-weight:bold; font-size:120%; } /* title */ |
214 |
.FTR { } /* footer */ |
215 |
.LST { background-color:#E0E0E0; } /* table cells */ |
216 |
.BAR { background-color:#E0E0E0; } /* action bar */ |
217 |
PRE { color:blue; font-family:Lucida Console,Courier New, |
218 |
Courier,sans-serif; } /* source code */ |
219 |
EM { color:green; font-style:normal; } /* line numbers */ |
220 |
.REM { color:silver; } |
221 |
.XML { color:navy; background-color:yellow; } |
222 |
.MCK { color:red; font-family:WingDings; } /* Mock Icons */ |
223 |
A:HOVER { color:red; } |
224 |
|
225 |
<?php |
226 |
} // end function CSS |
227 |
|
228 |
////////////////////////////////////////////////////////////////// |
229 |
|
230 |
function DetailPage($fsRoot,$relDir,$fn) { |
231 |
|
232 |
global $gblEditable, $gblImages ; |
233 |
$self = $GLOBALS["PHP_SELF"] ; |
234 |
|
235 |
$relPath = $relDir . "/" . $fn ; |
236 |
$fsPath = $fsRoot . $relPath ; |
237 |
$fsDir = $fsRoot . $relDir ; |
238 |
|
239 |
$exists = file_exists($fsPath) ; |
240 |
$ext = strtolower(strrchr($relPath,".")) ; |
241 |
$editable = ( $ext=="" || strstr(join(" ",$gblEditable),$ext)) ; |
242 |
$writable = is_writeable($fsPath) ; |
243 |
$file_lock = CheckLock($fsPath); |
244 |
|
245 |
if (!$editable && !$exists) |
246 |
Error("Creation unsupported for type",$relPath) ; |
247 |
if (!exists && !is_writeable($fsDir) ) |
248 |
Error("Creation denied",$relDir) ; |
249 |
|
250 |
$text = "Use this page to view, modify or " ; |
251 |
$text .= "delete a single document on this " ; |
252 |
$text .= "web site." ; |
253 |
$title = "(Detail Page)" ; |
254 |
StartHTML($title, $text) ; |
255 |
|
256 |
echo "<H3>" . $relDir . "/" . $fn . "</H3>" ; |
257 |
if ($exists) { // get file info |
258 |
$fsize = filesize($fsPath) ; |
259 |
$fmodified = date("$GLOBALS[gblDateFmt] $GLOBALS[gblTimeFmt]", filemtime($fsPath)) ; |
260 |
$faccessed = date("$GLOBALS[gblDateFmt] $GLOBALS[gblTimeFmt]", fileatime($fsPath)) ; |
261 |
echo "<PRE> file size: " . $fsize . " Bytes<BR>" ; |
262 |
echo "last modified: <B>" . $fmodified . "</B><BR>" ; |
263 |
echo "last accessed: <B>" . $faccessed . "</B><BR>" ; |
264 |
echo " owner: <B>" . fileowner($fsPath) . "</B><BR>" ; |
265 |
echo " group: <B>" . filegroup($fsPath) . "</B><BR>" ; |
266 |
echo " permissions: <B>" ; |
267 |
echo printf( "%o", fileperms($fsPath) ) . "</B>" ; |
268 |
echo "</PRE>" ; |
269 |
|
270 |
} |
271 |
|
272 |
if ( $editable && ($writable || !$exists) && !$file_lock ) { |
273 |
$fh = fopen($fsPath,"a+") ; |
274 |
rewind($fh) ; |
275 |
$fstr = fread($fh,filesize($fsPath)) ; |
276 |
fclose($fh) ; |
277 |
$fstr = htmlentities( $fstr ) ; |
278 |
?> |
279 |
|
280 |
<FORM ACTION="<?= $self ; ?>" METHOD="POST"> |
281 |
<SPAN TITLE="Click [SAVE] to store updated contents."> |
282 |
<B>DOCUMENT CONTENTS</B> |
283 |
</SPAN><BR> |
284 |
<TEXTAREA NAME="FILEDATA" ROWS=18 COLS=70 WRAP="OFF"><?php |
285 |
echo($fstr) ; ?></TEXTAREA> |
286 |
<INPUT TYPE="HIDDEN" NAME="DIR" VALUE="<?= $relDir ; ?>"> |
287 |
<INPUT TYPE="HIDDEN" NAME="FN" VALUE="<?= $fn ; ?>"> |
288 |
<INPUT TYPE="HIDDEN" NAME="POSTACTION" VALUE="SAVE"> |
289 |
<INPUT TYPE="HIDDEN" SIZE=48 MAXLENGTH=255 NAME="RELPATH" |
290 |
VALUE="<?= $relPath ; ?>"> |
291 |
<br> |
292 |
<INPUT TYPE="RESET" VALUE="UNDO ALL CHANGES"> |
293 |
<INPUT TYPE="SUBMIT" VALUE="SAVE"> |
294 |
</FORM> |
295 |
|
296 |
<?php |
297 |
} |
298 |
if ( !$file_lock && $ext!="" && strstr(join(' ',$gblImages),$ext) ) { |
299 |
$info = getimagesize($fsPath) ; |
300 |
$tstr = "<IMG SRC=\"".urlpath($relPath)."\" BORDER=0 " ; |
301 |
$tstr .= $info[3] . " ALT=\"" . $fn . " - " ; |
302 |
$tstr .= (int)(($fsize+1023)/1024) . "Kb\">" ; |
303 |
// echo htmlentities($tstr) . "<BR><BR>" . $tstr ; |
304 |
echo $tstr ; |
305 |
} |
306 |
|
307 |
?> |
308 |
|
309 |
<FORM ACTION="<?= $self ; ?>" METHOD="POST"> |
310 |
<INPUT TYPE="HIDDEN" NAME="DIR" VALUE="<?= $relDir ; ?>"> |
311 |
<INPUT TYPE="HIDDEN" NAME="FN" VALUE="<?= $fn ; ?>"> |
312 |
<INPUT TYPE="SUBMIT" NAME="POSTACTION" VALUE="CANCEL"><BR> |
313 |
|
314 |
<?php |
315 |
|
316 |
if ($file_lock) { |
317 |
?> |
318 |
<hr> |
319 |
<SPAN TITLE="Check OK and click UNLOCK to remove lock on file."> |
320 |
<B>OK TO FORCE LOCK REMOVAL ON "<?= $fn ; ?>" HELD BY <?= $file_lock ?>? </B></SPAN> |
321 |
<INPUT TYPE="CHECKBOX" NAME="CONFIRM"> |
322 |
<INPUT TYPE="SUBMIT" NAME="POSTACTION" VALUE="UNLOCK"> |
323 |
<? |
324 |
} // file_lock |
325 |
|
326 |
if (substr($fn,0,4) == ".del") { |
327 |
$action="UNDELETE"; |
328 |
$desc="undelete previously deleted file"; |
329 |
} else { |
330 |
$action="DELETE"; |
331 |
$desc="delete"; |
332 |
} |
333 |
|
334 |
if ($exists && $writable) { |
335 |
?> |
336 |
|
337 |
<HR> |
338 |
<a name="undelete"> |
339 |
<SPAN TITLE="Check OK and click [<?= $action ?>] to <?= $desc ?>."> |
340 |
<B>OK TO <?= $action ?> "<?= $fn ; ?>"? </B></SPAN> |
341 |
<INPUT TYPE="CHECKBOX" NAME="CONFIRM"> |
342 |
<INPUT TYPE="SUBMIT" NAME="POSTACTION" VALUE="<?= $action ?>"> |
343 |
|
344 |
<HR> |
345 |
<a name="rename"> |
346 |
<SPAN TITLE="Check OK and click [RENAME] to rename."> |
347 |
<B>OK TO RENAME "<?= $fn ; ?>" TO |
348 |
<INPUT TYPE="TEXT" SIZE=24 MAXLENGTH=255 NAME="NEWNAME" VALUE="<?= $fn ?>"> |
349 |
? </B></SPAN> |
350 |
<INPUT TYPE="CHECKBOX" NAME="CONFIRM"> |
351 |
<INPUT TYPE="SUBMIT" NAME="POSTACTION" VALUE="RENAME"> |
352 |
|
353 |
<?php |
354 |
} // exists && writable |
355 |
?> |
356 |
<HR> |
357 |
<a name="note"> |
358 |
<B>NOTE FOR "<?= $fn ; ?>": |
359 |
<INPUT TYPE="TEXT" SIZE=50 MAXLENGTH=255 NAME="NOTE" VALUE="<?= ReadNote($fsPath) ?>"> |
360 |
</B></SPAN> |
361 |
<INPUT TYPE="SUBMIT" NAME="POSTACTION" VALUE="NOTE"> |
362 |
|
363 |
</FORM> |
364 |
|
365 |
<?php |
366 |
|
367 |
$name=basename("$fsDir/$fn"); |
368 |
$logname=dirname("$fsDir/$fn")."/.log/$name"; |
369 |
$bakdir=dirname("$fsDir/$fn")."/.bak"; |
370 |
if (file_exists($logname)) { |
371 |
$log=fopen($logname,"r"); |
372 |
$cl1=" class=LST"; $cl2=""; |
373 |
$logarr = array(); |
374 |
while($line = fgetcsv($log,255,"\t")) { |
375 |
$cl=$cl1; $cl1=$cl2; $cl2=$cl; |
376 |
array_unshift($logarr,array($cl,$line[0],$line[1],$line[2],$line[3])); |
377 |
} |
378 |
fclose($log); |
379 |
print "<hr><br><b>CHANGES TO THIS FILE</b><br><table border=0 width=100%>\n"; |
380 |
$bakcount = 0; // start from 0, skip fist backup (it's current) |
381 |
while ($e = array_shift($logarr)) { |
382 |
if (strstr($e[4],"upload")) { |
383 |
if (file_exists("$bakdir/$bakcount/$name")) { |
384 |
$e[4]="<a href=\"".urlpath(dirname($relPath)."/.bak/$bakcount/$name")."\">$e[4]</a>"; |
385 |
} |
386 |
$bakcount++; |
387 |
} |
388 |
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"; |
389 |
} |
390 |
print "</table>"; |
391 |
} |
392 |
|
393 |
EndHTML() ; |
394 |
|
395 |
} // end function DetailPage |
396 |
|
397 |
////////////////////////////////////////////////////////////////// |
398 |
|
399 |
function DisplayCode($fsRoot,$relDir,$fn) { |
400 |
|
401 |
$path = $fsRoot . $relDir . "/" . $fn ; |
402 |
|
403 |
if (!file_exists($path)) Error("File not found",$path) ; |
404 |
|
405 |
StartHTML("(".$relDir."/".$fn.")",""); |
406 |
|
407 |
$tstr = join("",file($path)) ; |
408 |
$tstr = htmlentities($tstr) ; |
409 |
|
410 |
// Tabs |
411 |
$tstr = str_replace(chr(9)," ",$tstr) ; |
412 |
|
413 |
// ASP tags & XML/PHP tags |
414 |
$aspbeg = "<SPAN CLASS=XML><%</SPAN><SPAN CLASS=BLK>" ; |
415 |
$aspend = "</SPAN><SPAN CLASS=XML>%></SPAN>" ; |
416 |
$tstr = str_replace("<%",$aspbeg,$tstr) ; |
417 |
$tstr = str_replace("%>",$aspend,$tstr) ; |
418 |
|
419 |
$xmlbeg = "<SPAN CLASS=XML><?</SPAN><SPAN CLASS=BLK>" ; |
420 |
$xmlend = "</SPAN><SPAN CLASS=XML>?></SPAN>" ; |
421 |
$tstr = str_replace("<?",$xmlbeg,$tstr) ; |
422 |
$tstr = str_replace("?>",$xmlend,$tstr) ; |
423 |
|
424 |
// C style comment |
425 |
$tstr = str_replace("/*","<SPAN CLASS=REM>/*",$tstr) ; |
426 |
$tstr = str_replace("*/","*/</SPAN>",$tstr) ; |
427 |
|
428 |
// HTML comments |
429 |
$tstr = str_replace("<!--","<I CLASS=RED><!--",$tstr) ; |
430 |
$tstr = str_replace("-->","--></I>",$tstr) ; |
431 |
|
432 |
echo "<PRE>" ; |
433 |
|
434 |
$tstr = split("\n",$tstr) ; |
435 |
for ($i = 0 ; $i < sizeof($tstr) ; ++$i) { |
436 |
// add line numbers |
437 |
echo "<BR><EM>" ; |
438 |
echo substr(("000" . ($i+1)), -4) . ":</EM> " ; |
439 |
$line = $tstr[$i] ; |
440 |
// C++ style comments |
441 |
$pos = strpos($line,"//") ; |
442 |
// exceptions: two slashes aren't a script comment |
443 |
if (strstr($line,"//") && |
444 |
! ($pos>0 && substr($line,$pos-1,1)==":") && |
445 |
! (substr($line,$pos,8) == "//-->") && |
446 |
! (substr($line,$pos,9) == "// -->")) { |
447 |
$beg = substr($line,0,strpos($line,"//")) ; |
448 |
$end = strstr($line,"//") ; |
449 |
$line = $beg."<SPAN CLASS=REM>".$end."</SPAN>"; |
450 |
} |
451 |
// shell & asp style comments |
452 |
$first = substr(ltrim($line),0,1) ; |
453 |
if ($first == "#" || $first == "'") { |
454 |
$line = "<SPAN CLASS=REM>".$line."</SPAN>"; |
455 |
} |
456 |
print($line) ; |
457 |
} // next i |
458 |
|
459 |
echo "</PRE>" ; |
460 |
|
461 |
EndHTML() ; |
462 |
|
463 |
} // end function DisplayCode |
464 |
|
465 |
////////////////////////////////////////////////////////////////// |
466 |
|
467 |
function MockIcon($txt) { |
468 |
$tstr = "<SPAN CLASS=MCK>" ; |
469 |
|
470 |
switch (strtolower($txt)) { |
471 |
case ".bmp" : |
472 |
case ".gif" : |
473 |
case ".jpg" : |
474 |
case ".jpeg": |
475 |
case ".tif" : |
476 |
case ".tiff": |
477 |
$d = 176 ; |
478 |
break ; |
479 |
case ".doc" : |
480 |
$d = 50 ; |
481 |
break ; |
482 |
case ".exe" : |
483 |
case ".bat" : |
484 |
$d = 255 ; |
485 |
break ; |
486 |
case ".bas" : |
487 |
case ".c" : |
488 |
case ".cc" : |
489 |
case ".src" : |
490 |
$d = 255 ; |
491 |
break ; |
492 |
case "file" : |
493 |
$d = 51 ; |
494 |
break ; |
495 |
case "fldr" : |
496 |
$d = 48 ; |
497 |
break ; |
498 |
case ".htm" : |
499 |
case ".html": |
500 |
case ".asa" : |
501 |
case ".asp" : |
502 |
case ".cfm" : |
503 |
case ".php3": |
504 |
case ".php" : |
505 |
case ".phtml" : |
506 |
case ".shtml" : |
507 |
$d = 182 ; |
508 |
break ; |
509 |
case ".pdf" : |
510 |
$d = 38 ; |
511 |
break; |
512 |
case ".txt" : |
513 |
case ".ini" : |
514 |
$d = 52 ; |
515 |
break ; |
516 |
case ".xls" : |
517 |
$d = 252 ; |
518 |
break ; |
519 |
case ".zip" : |
520 |
case ".arc" : |
521 |
case ".sit" : |
522 |
case ".tar" : |
523 |
case ".gz" : |
524 |
case ".tgz" : |
525 |
case ".Z" : |
526 |
$d = 59 ; |
527 |
break ; |
528 |
case "view" : |
529 |
$d = 52 ; |
530 |
break ; |
531 |
case "up" : |
532 |
$d = 199 ; |
533 |
break ; |
534 |
case "blank" : |
535 |
return " </SPAN>" ; |
536 |
break ; |
537 |
default : |
538 |
$d = 51 ; |
539 |
} |
540 |
|
541 |
return $tstr . chr($d) . "</SPAN>" ; |
542 |
} // end function MockIcon |
543 |
|
544 |
////////////////////////////////////////////////////////////////// |
545 |
|
546 |
function GifIcon($txt) { |
547 |
global $gblIconLocation ; |
548 |
|
549 |
switch (strtolower($txt)) { |
550 |
case ".bmp" : |
551 |
case ".gif" : |
552 |
case ".jpg" : |
553 |
case ".jpeg": |
554 |
case ".tif" : |
555 |
case ".tiff": |
556 |
$d = "image2.gif" ; |
557 |
break ; |
558 |
case ".doc" : |
559 |
$d = "layout.gif" ; |
560 |
break ; |
561 |
case ".exe" : |
562 |
case ".bat" : |
563 |
$d = "screw2.gif" ; |
564 |
break ; |
565 |
case ".bas" : |
566 |
case ".c" : |
567 |
case ".cc" : |
568 |
case ".src" : |
569 |
$d = "c.gif" ; |
570 |
break ; |
571 |
case "file" : |
572 |
$d = "generic.gif" ; |
573 |
break ; |
574 |
case "fldr" : |
575 |
$d = "dir.gif" ; |
576 |
break ; |
577 |
case ".phps" : |
578 |
$d = "phps.gif" ; |
579 |
break ; |
580 |
case ".php3" : |
581 |
$d = "php3.gif" ; |
582 |
break ; |
583 |
case ".htm" : |
584 |
case ".html": |
585 |
case ".asa" : |
586 |
case ".asp" : |
587 |
case ".cfm" : |
588 |
case ".php3": |
589 |
case ".php" : |
590 |
case ".phtml" : |
591 |
case ".shtml" : |
592 |
$d = "world1.gif" ; |
593 |
break ; |
594 |
case ".pdf" : |
595 |
$d = "pdf.gif" ; |
596 |
break; |
597 |
case ".txt" : |
598 |
case ".ini" : |
599 |
$d = "text.gif" ; |
600 |
break ; |
601 |
case ".xls" : |
602 |
$d = "box2.gif" ; |
603 |
break ; |
604 |
case ".zip" : |
605 |
case ".arc" : |
606 |
case ".sit" : |
607 |
case ".tar" : |
608 |
case ".gz" : |
609 |
case ".tgz" : |
610 |
case ".Z" : |
611 |
$d = "compressed.gif" ; |
612 |
break ; |
613 |
case "view" : |
614 |
$d = "index.gif" ; |
615 |
break ; |
616 |
case "up" : |
617 |
$d = "back.gif" ; |
618 |
break ; |
619 |
case "blank" : |
620 |
$d = "blank.gif" ; |
621 |
break ; |
622 |
case "checkout": |
623 |
$d = "box2.gif"; |
624 |
break; |
625 |
case "checkin": |
626 |
$d = "hand.up.gif"; |
627 |
break; |
628 |
case "locked": |
629 |
$d = "screw2.gif"; |
630 |
break; |
631 |
case "note": |
632 |
$d = "quill.gif"; |
633 |
break; |
634 |
default : |
635 |
$d = "generic.gif" ; |
636 |
} |
637 |
|
638 |
return "<IMG SRC=\"$gblIconLocation" . $d . "\" BORDER=0>" ; |
639 |
} // end function GifIcon |
640 |
|
641 |
////////////////////////////////////////////////////////////////// |
642 |
|
643 |
function Navigate($fsRoot,$relDir) { |
644 |
|
645 |
global $gblEditable, $gblIcon, $gblModDays ; |
646 |
|
647 |
$self = $GLOBALS["PHP_SELF"] ; |
648 |
if (isset($GLOBALS["HTTPS"]) && $GLOBALS["HTTPS"] == "on") { |
649 |
$webRoot = "https://" . $GLOBALS["HTTP_HOST"] ; |
650 |
} else { |
651 |
$webRoot = "http://" . $GLOBALS["HTTP_HOST"] ; |
652 |
} |
653 |
$fsDir = $fsRoot . $relDir . "/" ; // current directory |
654 |
|
655 |
if (!is_dir($fsDir)) Error("Dir not found",$relDir) ; |
656 |
|
657 |
// read directory contents |
658 |
if ( !($dir = @opendir($fsDir)) ) |
659 |
Error("Read Access denied",$relDir) ; |
660 |
while ($item = readdir($dir)) { |
661 |
if ( $item == ".." || $item == "." || substr($item,0,1) == "." ) continue ; |
662 |
if ( is_dir($fsDir . $item) ) { |
663 |
$dirList[] = $item ; |
664 |
} else if ( is_file($fsDir . $item) ) { |
665 |
$fileList[] = $item ; |
666 |
} else if ( is_link($fsDir . $item) ) { |
667 |
$dirList[] = $item ; |
668 |
} else { |
669 |
// unknown file type |
670 |
// $text = "Could not determine file type of " ; |
671 |
// Error("File Error", $text.$relDir."/".$item) ; |
672 |
// exit ; |
673 |
} |
674 |
} |
675 |
closedir($dir) ; |
676 |
|
677 |
// scan deleted files |
678 |
if ( $GLOBALS[show_deleted] == 1 && ($dir = @opendir("$fsDir/.del")) ) { |
679 |
while ($item = readdir($dir)) { |
680 |
if ( substr($item,0,1) == "." ) continue ; |
681 |
$fileList[] = ".del/$item" ; |
682 |
} |
683 |
closedir($dir) ; |
684 |
} |
685 |
|
686 |
$emptyDir = ! (sizeof($dirList) || sizeof($fileList)) ; |
687 |
|
688 |
// start navigation page |
689 |
$text = "Use this page to add, delete"; |
690 |
if (! isset($show_deleted)) { |
691 |
$text .= ", <a href=$self?D=".urlencode($relDir)."&show_deleted=1>undelete</a>"; |
692 |
} |
693 |
$text .= " or revise files on this web site." ; |
694 |
$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>."; |
695 |
StartHTML("(Navigate)",$text) ; |
696 |
|
697 |
echo "<TABLE BORDER=0 CELLPADDING=2 |
698 |
CELLSPACING=3 WIDTH=\"100%\">" ; |
699 |
|
700 |
// updir bar |
701 |
if ($fsDir != $fsRoot) { |
702 |
$parent = dirname($relDir) ; |
703 |
if ($parent == "") $parent = "/" ; |
704 |
?> |
705 |
|
706 |
<TR><TD><?= $gblIcon("up") ?></TD><TD COLSPAN=5 CLASS=LST> |
707 |
<A HREF="<?= $self ?>?D=<?= urlencode($parent) ?>"> |
708 |
<B><?= $parent ?></B></A></TD></TR> |
709 |
|
710 |
<?php |
711 |
} |
712 |
|
713 |
// output subdirs |
714 |
if (sizeof($dirList) > 0) { |
715 |
sort($dirList) ; |
716 |
?> |
717 |
|
718 |
<TR><TD></TD><TD COLSPAN=5 CLASS=TOP><HR>DIRECTORY NAME</TD></TR> |
719 |
|
720 |
<?php |
721 |
while (list($key,$dir) = each($dirList)) { |
722 |
|
723 |
$tstr = "<A HREF=\"" . $self . "?D=" ; |
724 |
$tstr .= urlencode($relDir."/".$dir) ; |
725 |
$tstr .= "\">" . $dir . "/</A>" ; |
726 |
?> |
727 |
|
728 |
<TR><TD><?= $gblIcon("fldr") ?></TD> |
729 |
<TD COLSPAN=5 CLASS=LST><?= $tstr ?></TD></TR> |
730 |
|
731 |
<?php |
732 |
} // iterate over dirs |
733 |
} // end if no dirs |
734 |
?> |
735 |
|
736 |
<TR><TD></TD><TD COLSPAN=5><HR><B><?= $webRoot . $relDir ?> |
737 |
</B></TD></TR> |
738 |
<TR><TD></TD><TD CLASS=TOP>DOCUMENT NAME</TD> |
739 |
<TD><?= $gblIcon("blank").$gblIcon("blank") ?></TD> |
740 |
<TD CLASS=TOP>NOTE</TD> |
741 |
<TD CLASS=TOP>LAST UPDATE</TD><TD CLASS=TOP>FILE SIZE</TD></TR> |
742 |
|
743 |
<?php |
744 |
if (sizeof($fileList) > 0) { |
745 |
sort($fileList) ; |
746 |
while (list($key,$file) = each($fileList)) { |
747 |
$path = $fsDir."/".$file ; |
748 |
$mod = filemtime($path) ; |
749 |
$sz = filesize($path) ; |
750 |
|
751 |
if ($sz >= 10240) { |
752 |
$sz = (int)(($sz+1023)/1024) . " k" ; |
753 |
} else { |
754 |
$sz .= " " ; |
755 |
} // end size |
756 |
|
757 |
$a = $b = "" ; |
758 |
|
759 |
$info_url=$self."?A=E&F=".urlencode($file)."&D=".urlencode($relDir); |
760 |
|
761 |
if ( ($mod + $gblModDays*86400) > time() ) { |
762 |
$a = "<SPAN CLASS=RED TITLE=\"Newer" ; |
763 |
$a .= " than $gblModDays days\"> * </SPAN>" ; |
764 |
} |
765 |
|
766 |
$file_lock=CheckLock($path); |
767 |
|
768 |
$file_url_html="<A HREF=\"$self?A=V&F=".urlencode($file); |
769 |
$file_url_html.="&D=".urlencode($relDir); |
770 |
$file_url_html.="\" TITLE=\"View file\">" ; |
771 |
|
772 |
if (substr($file,0,5) != ".del/") { |
773 |
$file_url_html .= $file . "</A>" . $a ; |
774 |
} else { |
775 |
$file_url_html .= substr($file,5,strlen($file)-5) . "</a> <SPAN CLASS=RED TITLE=\"deleted\"> <a href=\"$info_url#undelete\">deleted</a> </span>"; |
776 |
} |
777 |
|
778 |
$note_html="<a href=\"$info_url#note\">".$gblIcon("note")."</a>".ReadNote($path); |
779 |
|
780 |
$ext = strtolower(strrchr($file,".")) ; |
781 |
|
782 |
if ($file_lock) { |
783 |
if ($file_lock == $GLOBALS[gblUserName]) { |
784 |
$b.="<A HREF=\"$self?A=Ci&F=".urlencode($file); |
785 |
$b.="&D=".urlencode($relDir); |
786 |
$b.="\" TITLE=\"Checkin (update) file on server\">" ; |
787 |
$file_url_html=$b; |
788 |
$b.=$gblIcon("checkin")."</A>" ; |
789 |
$b.= $gblIcon("blank"); |
790 |
$file_url_html.="$file</a> $a"; |
791 |
$note_html = $gblIcon("blank")."<b>Please check-in (update) this file</b>"; |
792 |
} else { |
793 |
$b = $gblIcon("locked"); |
794 |
$b.= $gblIcon("blank"); |
795 |
$note_html = $gblIcon("blank")."<b>File locked by $file_lock</b>"; |
796 |
$file_url_html = "$file $a"; |
797 |
} |
798 |
} else { |
799 |
$b.="<A HREF=\"$self?A=Co&F=".urlencode($file); |
800 |
$b.="&D=".urlencode($relDir); |
801 |
$b.="\" TITLE=\"Checkout file for edit\">" ; |
802 |
$b.=$gblIcon("checkout")."</A>" ; |
803 |
|
804 |
if ( $ext=="" || strstr(join(" ",$gblEditable),$ext) ) { |
805 |
$b.="<A HREF=\"$self?A=C&F=".urlencode($file); |
806 |
$b.="&D=".urlencode($relDir); |
807 |
$b.="\" TITLE=\"List contents\">" ; |
808 |
$b.=$gblIcon("view")."</A>" ; |
809 |
} else { |
810 |
$b.= $gblIcon("blank"); |
811 |
} |
812 |
} |
813 |
|
814 |
|
815 |
?> |
816 |
|
817 |
<TR><TD> |
818 |
<A HREF="<?= $info_url ?>" TITLE="View/Edit"> |
819 |
<?= $gblIcon($ext) ?></A></TD> |
820 |
<TD CLASS=LST><?= $file_url_html ?></TD> |
821 |
<TD CLASS=LST ALIGN=center><?= $b ?></TD> |
822 |
<TD CLASS=LST ALIGN=left><?= $note_html ?></TD> |
823 |
<TD CLASS=LST><?= date("$GLOBALS[gblDateFmt] $GLOBALS[gblTimeFmt]",$mod) ?></TD> |
824 |
<TD CLASS=LST><?= $sz ?>Bytes</TD></TR> |
825 |
|
826 |
<?php |
827 |
} // iterate over files |
828 |
} 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) { |
837 |
?> |
838 |
|
839 |
<FORM METHOD="POST" ACTION="<?= $self ?>"> |
840 |
<TR><TD></TD><TD COLSPAN=5 CLASS=BAR> |
841 |
<INPUT TYPE="HIDDEN" NAME="DIR" VALUE="<?= $relDir ?>"> |
842 |
OK TO DELETE THIS EMPTY FOLDER? |
843 |
<INPUT TYPE="CHECKBOX" NAME="CONFIRM"> |
844 |
<INPUT TYPE="SUBMIT" NAME="POSTACTION" VALUE="DELETE"> |
845 |
</TD></TR> |
846 |
</FORM> |
847 |
|
848 |
<?php |
849 |
} // end if emptyDir |
850 |
?> |
851 |
|
852 |
<TR><TD></TD><TD COLSPAN=5><HR></TD></TR> |
853 |
|
854 |
<? |
855 |
if (file_exists(".info.inc")) { |
856 |
print "<TR><TD></TD><TD COLSPAN=5>"; |
857 |
include(".info.inc"); |
858 |
print "</TD></TR> |
859 |
<TR><TD></TD><TD COLSPAN=5><HR></TD></TR>"; |
860 |
} |
861 |
?> |
862 |
|
863 |
<FORM METHOD="POST" ACTION="<?= $self ?>"> |
864 |
<TR><TD></TD><TD COLSPAN=5 CLASS=BAR>CREATE NEW |
865 |
<INPUT TYPE="RADIO" NAME="T" VALUE="D" CHECKED>DIRECTORY -OR- |
866 |
<INPUT TYPE="RADIO" NAME="T" VALUE="F">FILE : |
867 |
<NOBR>NAME <INPUT TYPE="TEXT" NAME="FN" SIZE=14> |
868 |
<INPUT TYPE="HIDDEN" NAME="POSTACTION" VALUE="CREATE"> |
869 |
<INPUT TYPE="HIDDEN" NAME="DIR" VALUE="<?= $relDir ?>"> |
870 |
<INPUT TYPE="SUBMIT" VALUE="CREATE"></NOBR> |
871 |
<NOBR>OR <A HREF="<?= $self ?>?A=U&D=<?= urlencode($relDir) ?>">UPLOAD</A> A FILE |
872 |
</NOBR> |
873 |
</TD></TR> |
874 |
</FORM> |
875 |
</TABLE> |
876 |
|
877 |
<?php |
878 |
EndHTML() ; |
879 |
} // end function Navigate |
880 |
|
881 |
////////////////////////////////////////////////////////////////// |
882 |
|
883 |
function UploadPage($fsRoot, $relDir, $filename="") { |
884 |
|
885 |
$self = $GLOBALS["PHP_SELF"] ; |
886 |
if ($relDir == "") $relDir = "/" ; |
887 |
?> |
888 |
|
889 |
<P><TABLE BORDER=0 CELLPADDING=5><TR><TD WIDTH=5></TD><TD CLASS=BAR> |
890 |
<FORM ENCTYPE="multipart/form-data" METHOD="POST" |
891 |
ACTION="<?= $self ?>"> |
892 |
DESTINATION DIRECTORY:<B><?= " " . $relDir ?></B> |
893 |
<? if (isset($filename) && $filename!="") { ?> |
894 |
<br>DESTINATION FILE:<B><?= " " . $filename ?></B> |
895 |
<INPUT TYPE="HIDDEN" NAME="FILENAME" VALUE="<?= $filename ?>"> |
896 |
<? } ?> |
897 |
<P>PATHNAME OF LOCAL FILE<BR> |
898 |
<INPUT TYPE="HIDDEN" NAME="DIR" VALUE="<?= $relDir ?>"> |
899 |
<INPUT TYPE="HIDDEN" NAME="POSTACTION" VALUE="UPLOAD"> |
900 |
<INPUT SIZE=30 TYPE="FILE" NAME="FN"></P> |
901 |
<P><INPUT TYPE="SUBMIT" VALUE="UPLOAD"></P> |
902 |
<P>If the <B>[BROWSE...]</B> button is not displayed,<BR> |
903 |
you must upgrade to an RFC1867-compliant browser.</P> |
904 |
<P>Your browser:<BR><?= $GLOBALS["HTTP_USER_AGENT"] ?></P> |
905 |
</FORM> |
906 |
</TD></TR> |
907 |
<TR><TD></TD><TD> |
908 |
<FORM METHOD="POST" ACTION="<?= $self ?>"> |
909 |
<INPUT TYPE="HIDDEN" NAME="DIR" VALUE="<?= $relDir ?>"><BR> |
910 |
<INPUT TYPE="SUBMIT" NAME="POSTACTION" VALUE="CANCEL"> |
911 |
</FORM> |
912 |
</TD></TR></TABLE></P> |
913 |
|
914 |
<?php |
915 |
} // end function UploadPage |
916 |
|
917 |
////////////////////////////////////////////////////////////////// |
918 |
|
919 |
function Error($title,$text="") { |
920 |
StartHTML("(".$title.")",$text) ; |
921 |
echo "<P ALIGN=center>Hit your Browser's Back Button.</P>" ; |
922 |
EndHTML() ; |
923 |
exit ; |
924 |
} // end function Error |
925 |
|
926 |
////////////////////////////////////////////////////////////////// |
927 |
|
928 |
function NoEntry() { |
929 |
|
930 |
$user = $GLOBALS["PHP_AUTH_USER"] ; |
931 |
$pw = $GLOBALS["PHP_AUTH_PW"] ; |
932 |
$self = $GLOBALS["PHP_SELF"] ; |
933 |
|
934 |
$title = "(401 Unauthorized)" ; |
935 |
$text = "No trespassing !" ; |
936 |
StartHTML($title,$text) ; |
937 |
|
938 |
EndHTML() ; |
939 |
exit ; |
940 |
} |
941 |
|
942 |
////////////////////////////////////////////////////////////////// |
943 |
|
944 |
function LogIt($target,$msg) { |
945 |
|
946 |
$dir=dirname($target); |
947 |
if (! file_exists($dir."/.log")) { |
948 |
mkdir($dir."/.log",0700); |
949 |
} |
950 |
$file=basename($target); |
951 |
|
952 |
$log=fopen("$dir/.log/$file","a+"); |
953 |
fputs($log,date("$GLOBALS[gblDateFmt]\t$GLOBALS[gblTimeFmt]"). |
954 |
"\t$GLOBALS[gblUserName]\t$msg\n"); |
955 |
fclose($log); |
956 |
|
957 |
} |
958 |
|
959 |
|
960 |
////////////////////////////////////////////////////////////////// |
961 |
|
962 |
function WriteNote($target,$msg) { |
963 |
|
964 |
$target=stripSlashes($target); |
965 |
$dir=dirname($target); |
966 |
if (! file_exists($dir."/.note")) { |
967 |
mkdir($dir."/.note",0700); |
968 |
} |
969 |
$file=basename($target); |
970 |
|
971 |
$note=fopen("$dir/.note/$file","w"); |
972 |
fputs($note,"$msg\n"); |
973 |
fclose($note); |
974 |
|
975 |
Logit($target,"added note $msg"); |
976 |
|
977 |
} |
978 |
|
979 |
function ReadNote($target) { |
980 |
|
981 |
$target=stripSlashes($target); |
982 |
$dir=dirname($target); |
983 |
$file=basename($target); |
984 |
$msg=""; |
985 |
if (file_exists($dir."/.note/$file")) { |
986 |
$note=fopen("$dir/.note/$file","r"); |
987 |
$msg=fgets($note,4096); |
988 |
fclose($note); |
989 |
} |
990 |
return StripSlashes($msg); |
991 |
|
992 |
} |
993 |
|
994 |
////////////////////////////////////////////////////////////////// |
995 |
|
996 |
function MoveTo($source,$folder) { |
997 |
|
998 |
$source=stripSlashes($source); |
999 |
$file=basename($source); |
1000 |
if (! file_exists($folder)) { |
1001 |
mkdir($folder,0700); |
1002 |
} |
1003 |
if (file_exists($source)) { |
1004 |
rename($source,"$folder/$file"); |
1005 |
} |
1006 |
} |
1007 |
|
1008 |
////////////////////////////////////////////////////////////////// |
1009 |
|
1010 |
function Lock($target) { |
1011 |
|
1012 |
$target=stripSlashes($target); |
1013 |
$dir=dirname($target); |
1014 |
if (! file_exists($dir."/.lock")) { |
1015 |
mkdir($dir."/.lock",0700); |
1016 |
} |
1017 |
$file=basename($target); |
1018 |
|
1019 |
if (file_exists("$dir/.lock/$file")) { |
1020 |
Logit($target,"attempt to locked allready locked file!"); |
1021 |
} else { |
1022 |
$lock=fopen("$dir/.lock/$file","w"); |
1023 |
fputs($lock,"$GLOBALS[gblUserName]\n"); |
1024 |
fclose($lock); |
1025 |
|
1026 |
Logit($target,"file locked"); |
1027 |
} |
1028 |
|
1029 |
} |
1030 |
|
1031 |
function CheckLock($target) { |
1032 |
|
1033 |
$target=stripSlashes($target); |
1034 |
$dir=dirname($target); |
1035 |
$file=basename($target); |
1036 |
$msg=0; |
1037 |
if (file_exists($dir."/.lock/$file")) { |
1038 |
$lock=fopen("$dir/.lock/$file","r"); |
1039 |
$msg=fgets($lock,4096); |
1040 |
fclose($lock); |
1041 |
} |
1042 |
return chop($msg); |
1043 |
|
1044 |
} |
1045 |
|
1046 |
function Unlock($target) { |
1047 |
|
1048 |
$target=stripSlashes($target); |
1049 |
$dir=dirname($target); |
1050 |
$file=basename($target); |
1051 |
if (file_exists($dir."/.lock/$file")) { |
1052 |
unlink("$dir/.lock/$file"); |
1053 |
Logit($target,"file unlocked"); |
1054 |
} else { |
1055 |
Logit($target,"attempt to unlocked non-locked file!"); |
1056 |
} |
1057 |
|
1058 |
} |
1059 |
|
1060 |
////////////////////////////////////////////////////////////////// |
1061 |
|
1062 |
function urlpath($url) { |
1063 |
$url=urlencode(StripSlashes("$url")); |
1064 |
$url=str_replace("%2F","/",$url); |
1065 |
$url=str_replace("+","%20",$url); |
1066 |
return($url); |
1067 |
} |
1068 |
|
1069 |
////////////////////////////////////////////////////////////////// |
1070 |
|
1071 |
function safe_rename($from,$to) { |
1072 |
if (file_exists($from) && is_writable(dirname($to))) { |
1073 |
rename($from,$to); |
1074 |
} |
1075 |
} |
1076 |
|
1077 |
////////////////////////////////////////////////////////////////// |
1078 |
|
1079 |
// recursivly delete directory |
1080 |
|
1081 |
function rrmdir($dir) { |
1082 |
$handle=opendir($dir); |
1083 |
while ($file = readdir($handle)) { |
1084 |
if ($file != "." && $file != "..") { |
1085 |
if (is_dir("$dir/$file")) |
1086 |
rrmdir("$dir/$file"); |
1087 |
else |
1088 |
if (! @unlink("$dir/$file")) return(0); |
1089 |
} |
1090 |
} |
1091 |
closedir($handle); |
1092 |
return @rmdir($dir); |
1093 |
} |
1094 |
|
1095 |
////////////////////////////////////////////////////////////////// |
1096 |
|
1097 |
function ChangeLog($target,$msg) { |
1098 |
|
1099 |
global $gblFsRoot; |
1100 |
$log=fopen("$gblFsRoot/.changelog","a+"); |
1101 |
if (substr($target,0,strlen($gblFsRoot)) == $gblFsRoot) |
1102 |
$target=substr($target,strlen($gblFsRoot),strlen($target)-strlen($gblFsRoot)); |
1103 |
fputs($log,time()."\t$target\t$GLOBALS[gblUserName]\t$msg\n"); |
1104 |
fclose($log); |
1105 |
|
1106 |
} |
1107 |
|
1108 |
function DisplayChangeLog($day) { |
1109 |
|
1110 |
global $gblFsRoot; |
1111 |
if (!file_exists("$gblFsRoot/.changelog")) return; |
1112 |
$log=fopen("$gblFsRoot/.changelog","r"); |
1113 |
$logarr = array(); |
1114 |
while($line = fgetcsv($log,255,"\t")) { |
1115 |
if ($day!=1 || ($day==1 && (time()-$line[0] < 24*60*60))) { |
1116 |
array_unshift($logarr,array($line[0],$line[1],$line[2],$line[3])); |
1117 |
} |
1118 |
} |
1119 |
fclose($log); |
1120 |
$cl1=" class=LST"; $cl2=""; |
1121 |
print "<table border=0 width=100%>\n"; |
1122 |
while ($e = array_shift($logarr)) { |
1123 |
$cl=$cl1; $cl1=$cl2; $cl2=$cl; |
1124 |
$date = date("$GLOBALS[gblDateFmt]", $e[0]); |
1125 |
$time = date("$GLOBALS[gblTimeFmt]", $e[0]); |
1126 |
$dir = dirname($e[1]); |
1127 |
$file = basename($e[1]); |
1128 |
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"; |
1129 |
} |
1130 |
print "</table>"; |
1131 |
print "<p>".GifIcon(up)." Back to <a href=$GLOBALS[PHP_SELF]>front page</a>.</p>"; |
1132 |
} |
1133 |
|
1134 |
////////////////////////////////////////////////////////////////// |
1135 |
|
1136 |
// MAIN PROGRAM |
1137 |
// ============ |
1138 |
// query parameters: capital letters |
1139 |
// local functions : begin with capital letters |
1140 |
// global constants: begin with gbl |
1141 |
|
1142 |
$gblFilePerms = 0640 ; // default for new files |
1143 |
$gblDirPerms = 0750 ; // default for new dirs |
1144 |
|
1145 |
// phpinfo() ; |
1146 |
// exit ; |
1147 |
|
1148 |
// forks before authentication: style sheet and hash |
1149 |
// creation if password not yet set. |
1150 |
if ($STYLE == "get") { CSS() ; exit ; } |
1151 |
|
1152 |
// authentication failure |
1153 |
if ( md5($PHP_AUTH_USER.$PHP_AUTH_PW) != $gblPw || |
1154 |
isset($relogin) && $gblPw == $relogin ) { |
1155 |
header("WWW-authenticate: basic realm=\"$HTTP_HOST\"") ; |
1156 |
header("HTTP/1.0 401 Unauthorized") ; |
1157 |
NoEntry() ; |
1158 |
exit ; |
1159 |
} |
1160 |
|
1161 |
// get current directory relative to $gblFsRoot |
1162 |
$relDir = $DIR ; // from POST |
1163 |
if ($relDir == "") { // not defined in POST ? |
1164 |
$relDir = urldecode($D) ; // then use GET |
1165 |
} |
1166 |
|
1167 |
if ($relDir == "/") $relDir = "" ; |
1168 |
// default : website root = "" |
1169 |
|
1170 |
if (strstr($relDir,"..")) Error("No updirs allowed"); |
1171 |
|
1172 |
// full paths contain "fs" or "Fs". Paths realitve to root of |
1173 |
// website contain "rel" or "Rel". The script won't let you |
1174 |
// edit anything above directory equal to http://server.com |
1175 |
// i.e. below $gblFsRoot. |
1176 |
|
1177 |
$relScriptDir = dirname($SCRIPT_NAME) ; |
1178 |
// i.e. /docman |
1179 |
|
1180 |
$fsScriptDir = dirname($SCRIPT_FILENAME) ; |
1181 |
// i.e. /home/httpd/html/docman |
1182 |
|
1183 |
// start on server root |
1184 |
// $gblFsRoot = substr($fsScriptDir,0, strlen($fsScriptDir)-strlen($relScriptDir)) ; |
1185 |
// or on script root |
1186 |
$gblFsRoot = $fsScriptDir; |
1187 |
// i.e. /home/httpd/html |
1188 |
|
1189 |
$fsDir = $gblFsRoot . $relDir ; // current directory |
1190 |
if ( !is_dir($fsDir) ) Error("Dir not found",$relDir) ; |
1191 |
|
1192 |
$FN=stripSlashes($FN); |
1193 |
|
1194 |
switch ($POSTACTION) { |
1195 |
case "UPLOAD" : |
1196 |
if (!is_writeable($fsDir)) Error("Write denied",$relDir) ; |
1197 |
if (strstr($FN_name,"/")) |
1198 |
Error("Non-conforming filename") ; |
1199 |
// TODO : should rather check for escapeshellcmds |
1200 |
// but maybe RFC 18xx asserts safe filenames .... |
1201 |
$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 |
1206 |
$target = "$fsDir/$FN_name" ; |
1207 |
} else { |
1208 |
$target = "$fsDir/$FILENAME"; |
1209 |
} |
1210 |
|
1211 |
// backup old files first |
1212 |
$dir=dirname($target); |
1213 |
if (! file_exists($dir."/.bak")) { |
1214 |
mkdir($dir."/.bak",0700); |
1215 |
} |
1216 |
if (! file_exists($dir."/.bak/$GLOBALS[gblNumBackups]")) { |
1217 |
mkdir($dir."/.bak/$GLOBALS[gblNumBackups]",0700); |
1218 |
} |
1219 |
$file=basename($target); |
1220 |
for($i=$GLOBALS[gblNumBackups]-1;$i>0;$i--) { |
1221 |
MoveTo("$dir/.bak/$i/$file","$dir/.bak/".($i+1)."/"); |
1222 |
} |
1223 |
MoveTo($target,$dir."/.bak/1/"); |
1224 |
|
1225 |
copy($source,$target) ; |
1226 |
chmod($target,$gblFilePerms) ; |
1227 |
clearstatcache() ; |
1228 |
Logit($target,"uploaded"); |
1229 |
if (isset($FILENAME)) { |
1230 |
Unlock($target); |
1231 |
} |
1232 |
ChangeLog($target,"updated"); |
1233 |
break ; |
1234 |
|
1235 |
case "SAVE" : |
1236 |
$path = $gblFsRoot . $RELPATH ; |
1237 |
$path=stripSlashes($path); |
1238 |
$writable = is_writeable($path) ; |
1239 |
$legaldir = is_writeable(dirname($path)) ; |
1240 |
$exists = (file_exists($path)) ? 1 : 0 ; |
1241 |
// check for legal extension here as well |
1242 |
if (!($writable || (!$exists && $legaldir))) |
1243 |
Error("Write denied",$RELPATH) ; |
1244 |
$fh = fopen($path, "w") ; |
1245 |
$FILEDATA=stripSlashes($FILEDATA); |
1246 |
fwrite($fh,$FILEDATA) ; |
1247 |
fclose($fh) ; |
1248 |
clearstatcache() ; |
1249 |
Logit($path,"saved changes"); |
1250 |
ChangeLog($path,"saved changes"); |
1251 |
break ; |
1252 |
|
1253 |
case "CREATE" : |
1254 |
// we know $fsDir exists |
1255 |
if ($FN == "") break; // no filename! |
1256 |
if (!is_writeable($fsDir)) Error("Write denied",$relDir) ; |
1257 |
$path = $fsDir . "/" . $FN ; // file or dir to create |
1258 |
$relPath = $relDir . "/" . $FN ; |
1259 |
switch ( $T ) { |
1260 |
case "D" : // create a directory |
1261 |
if ( ! @mkdir($path,$gblDirPerms) ) |
1262 |
Error("Mkdir failed",$relPath) ; // eg. if it exists |
1263 |
clearstatcache() ; |
1264 |
break ; |
1265 |
case "F" : // create a new file |
1266 |
// this functionality is doubled in DetailView(). |
1267 |
// better keep it here altogether |
1268 |
// chmod perms to $gblFilePerms |
1269 |
if ( file_exists($path) && !is_writable($path) ) |
1270 |
Error("File not writable", $relPath) ; |
1271 |
$fh = fopen($path, "w+") ; |
1272 |
if ($fh) { |
1273 |
fputs($fh,"\n"); |
1274 |
fclose($fh) ; |
1275 |
LogIt($path,"file created"); |
1276 |
} else { |
1277 |
Error("Creation of file $relPath failed -- $path"); |
1278 |
} |
1279 |
$tstr = "$PHP_SELF?A=E&D=".urlencode($relDir)."&F=".urlencode($FN) ; |
1280 |
header("Location: " . $tstr) ; |
1281 |
ChangeLog($target,"created"); |
1282 |
exit ; |
1283 |
} |
1284 |
break ; |
1285 |
|
1286 |
case "DELETE" : |
1287 |
if ( $CONFIRM != "on" ) break ; |
1288 |
|
1289 |
$tstr = "Attempt to delete non-existing object or " ; |
1290 |
$tstr .= "insufficient privileges: " ; |
1291 |
|
1292 |
if ( $FN != "") { // delete file |
1293 |
$path = $fsDir . "/" . $FN ; |
1294 |
|
1295 |
$dir=dirname($path); |
1296 |
$file=basename($path); |
1297 |
if (! file_exists("$dir/.del")) { |
1298 |
mkdir("$dir/.del",0700); |
1299 |
} |
1300 |
|
1301 |
// if ( ! @unlink($path) ) { |
1302 |
if ( ! rename($path,"$dir/.del/$file") ) { |
1303 |
Error("File delete failed", $tstr . $path) ; |
1304 |
Logit($path,"file delete failed"); |
1305 |
exit ; |
1306 |
} else { |
1307 |
Logit($path,"file deleted"); |
1308 |
MoveTo("$dir/.log/$file","$dir/.del/.log/"); |
1309 |
MoveTo("$dir/.note/$file","$dir/.del/.note/"); |
1310 |
MoveTo("$dir/.lock/$file","$dir/.del/.lock/"); |
1311 |
} |
1312 |
} |
1313 |
else { // delete directory |
1314 |
if ( ! @rrmdir($fsDir) ) { |
1315 |
Error("Rmdir failed", $tstr . $fsDir) ; |
1316 |
} |
1317 |
else { |
1318 |
$relDir = dirname($relDir) ; // move up |
1319 |
} |
1320 |
} |
1321 |
break ; |
1322 |
|
1323 |
case "UNDELETE" : |
1324 |
if ( $CONFIRM != "on" ) break ; |
1325 |
|
1326 |
if (substr($FN,0,4) != ".del") break ; |
1327 |
$file=substr($FN,4,strlen($FN)-4); |
1328 |
|
1329 |
Logit("$fsDir/.del/$file","undeleted"); |
1330 |
MoveTo("$fsDir/.del/$file","$fsDir/"); |
1331 |
MoveTo("$fsDir/.del/.log/$file","$fsDir/.log/"); |
1332 |
MoveTo("$fsDir/.del/.note/$file","$fsDir/.note/"); |
1333 |
MoveTo("$fsDir/.del/.lock/$file","$fsDir/.lock/"); |
1334 |
|
1335 |
break ; |
1336 |
|
1337 |
case "RENAME" : |
1338 |
if ( $CONFIRM != "on" ) break ; |
1339 |
|
1340 |
Logit("$fsDir/$FN","renamed $FN to $NEWNAME"); |
1341 |
safe_rename("$fsDir/$FN","$fsDir/$NEWNAME"); |
1342 |
safe_rename("$fsDir/.log/$FN","$fsDir/.log/$NEWNAME"); |
1343 |
safe_rename("$fsDir/.note/$FN","$fsDir/.note/$NEWNAME"); |
1344 |
safe_rename("$fsDir/.lock/$FN","$fsDir/.lock/$NEWNAME"); |
1345 |
for($i=0;$i<=$GLOBALS[gblNumBackups];$i++) { |
1346 |
safe_rename("$fsDir/.bak/$i/$FN","$fsDir/.bak/$i/$NEWNAME"); |
1347 |
} |
1348 |
|
1349 |
break ; |
1350 |
|
1351 |
case "NOTE" : |
1352 |
WriteNote("$fsDir/$FN","$NOTE"); |
1353 |
break ; |
1354 |
|
1355 |
case "UNLOCK" : |
1356 |
if ( $CONFIRM != "on" ) break ; |
1357 |
Unlock("$fsDir/$FN"); |
1358 |
break ; |
1359 |
|
1360 |
default : |
1361 |
// user hit "CANCEL" or undefined action |
1362 |
} |
1363 |
|
1364 |
// common to all POSTs : redirect to directory view ($relDir) |
1365 |
if ( $POSTACTION != "" ) { |
1366 |
$tstr = $PHP_SELF . "?D=" . urlencode($relDir) ; |
1367 |
header("Location: " . $tstr) ; |
1368 |
exit ; |
1369 |
} |
1370 |
|
1371 |
// check for mode.. navigate, code display, upload, or detail? |
1372 |
// $A=U : upload to path given in $D |
1373 |
// $A=E : display detail of file $D/$F and edit |
1374 |
// $A=C : display code in file $D/$F |
1375 |
// $A=Co : checkout file $D/$F |
1376 |
// $A=Ci : checkin file $D/$F |
1377 |
// $A=V : view file (do nothing except log) |
1378 |
// default : display directory $D |
1379 |
|
1380 |
switch ($A) { |
1381 |
case "U" : |
1382 |
// upload to $relDir |
1383 |
if (!is_writeable($gblFsRoot . $relDir)) |
1384 |
Error("Write access denied",$relDir) ; |
1385 |
$text = "Use this page to upload a single " ; |
1386 |
$text .= "file to <B>$HTTP_HOST</B>." ; |
1387 |
StartHTML("(Upload Page)", $text) ; |
1388 |
UploadPage($gblFsRoot, $relDir) ; |
1389 |
EndHTML() ; |
1390 |
exit ; |
1391 |
case "E" : |
1392 |
$F=stripSlashes($F); |
1393 |
// detail of $relDir/$F |
1394 |
if (is_file("$gblFsRoot/$relDir/$F")) DetailPage($gblFsRoot, $relDir, $F) ; |
1395 |
exit ; |
1396 |
case "C" : |
1397 |
$F=stripSlashes($F); |
1398 |
// listing of $relDir/$F |
1399 |
DisplayCode($gblFsRoot, $relDir, $F) ; |
1400 |
exit ; |
1401 |
case "Co" : |
1402 |
// checkout |
1403 |
Lock("$gblFsRoot/$relDir/$F"); |
1404 |
header("Content-Disposition: attachment; filename=$F" ); |
1405 |
Header("Location: ".urlpath("$relDir/$F")); |
1406 |
exit; |
1407 |
case "Ci" : |
1408 |
$F=stripSlashes($F); |
1409 |
// upload && update to $relDir |
1410 |
if (!is_writeable($gblFsRoot . $relDir)) |
1411 |
Error("Write access denied",$relDir) ; |
1412 |
$text = "Use this page to update a single " ; |
1413 |
$text .= "file to <B>$HTTP_HOST</B>." ; |
1414 |
StartHTML("(Update file Page)", $text) ; |
1415 |
UploadPage($gblFsRoot, $relDir, $F) ; |
1416 |
EndHTML() ; |
1417 |
exit ; |
1418 |
case "V" : |
1419 |
// view |
1420 |
LogIt("$gblFsRoot/$relDir/$F","viewed"); |
1421 |
header("Content-Disposition: attachment; filename=$F" ); |
1422 |
Header("Location: ".urlpath("$relDir/$F")); |
1423 |
exit; |
1424 |
case "Ch" : |
1425 |
StartHTML("(File changes)","All changes chronologicaly..."); |
1426 |
DisplayChangeLog(0); // all |
1427 |
EndHTML() ; |
1428 |
exit; |
1429 |
case "Ch1" : |
1430 |
StartHTML("(File changes)","Changes to files in last day..."); |
1431 |
DisplayChangeLog(1); |
1432 |
EndHTML() ; |
1433 |
exit; |
1434 |
} |
1435 |
|
1436 |
// default: display directory $relDir |
1437 |
Navigate($gblFsRoot,$relDir) ; |
1438 |
exit ; |
1439 |
|
1440 |
Error("Whooah!","By cartesian logic, this never happens") ; |
1441 |
?> |