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