1 |
<?php |
2 |
|
3 |
/* |
4 |
* Document Manager ][ |
5 |
* |
6 |
* Dobrica Pavlinusic <dpavlin@rot13.org> |
7 |
* |
8 |
* License: GPL2 |
9 |
* |
10 |
* Document Manager 1.x was based on |
11 |
* Copyright 1999 by John Martin d/b/a www.ANYPORTAL.com |
12 |
* PHP version Copyright 2000 by Stefan@Wiesendanger.org |
13 |
* |
14 |
* For more info, please see web pages at |
15 |
* https://www.rot13.org/~dpavlin/docman.html |
16 |
* |
17 |
*/ |
18 |
|
19 |
|
20 |
////////////////////////////////////////////////////////////////// |
21 |
// CONFIGURATION OPTIONS |
22 |
|
23 |
// error_reporting(4) ; // how verbose ? |
24 |
|
25 |
// from where to include auth_*.php modules? |
26 |
$gblIncDir = "/data/docman2"; |
27 |
|
28 |
// force download on view (so it won't open in associated application) |
29 |
$gblForceDownload = 0; |
30 |
|
31 |
// date format |
32 |
$gblDateFmt="Y-m-d"; |
33 |
// $gblDateFmt="D, F d, Y"; |
34 |
|
35 |
// time format |
36 |
$gblTimeFmt="H:i:s"; |
37 |
// $gblTimeFmt="g:i:sA"; |
38 |
|
39 |
// Number of backup files to keep |
40 |
$gblNumBackups=3; |
41 |
|
42 |
// show red star if newer than ... days |
43 |
$gblModDays=1; |
44 |
|
45 |
// choose GifIcon below unless you have the M$ |
46 |
// WingDings font installed on your system |
47 |
|
48 |
$gblIcon="GifIcon"; // MockIcon or GifIcon |
49 |
|
50 |
// the directory below should be /icons/ or /icons/small/ |
51 |
// on Apache; a set of icons is included in the distribution |
52 |
|
53 |
$gblIconLocation="/icons/"; |
54 |
|
55 |
// files you want to be able to edit in text mode |
56 |
// and view with (primitive) syntax highlighting |
57 |
|
58 |
$gblEditable = array( ".txt",".asa",".asp",".htm",".html", |
59 |
".cfm",".php3",".php",".phtml", |
60 |
".shtml",".css" ) ; |
61 |
|
62 |
// files that will display as images on the detail page |
63 |
// (useless if your browser doesn't support them) |
64 |
|
65 |
$gblImages = array( ".jpg",".jpeg",".gif",".png",".ico", |
66 |
".bmp",".xbm") ; |
67 |
|
68 |
// which files to hide (separated by ,) |
69 |
$gblHide = ""; |
70 |
|
71 |
// Where are users? (by default in .htusers file) |
72 |
$gblUsers = "file"; |
73 |
|
74 |
////////////////////////////////////////////////////////////////// |
75 |
|
76 |
$gblTitle = "Document Manager"; |
77 |
$gblVersion = "2.0-pre1"; |
78 |
|
79 |
$secHash = ""; |
80 |
|
81 |
// location of html files |
82 |
$html = $gblIncDir."/html"; |
83 |
|
84 |
LoadLanguage($HTTP_SERVER_VARS["HTTP_ACCEPT_LANGUAGE"]); |
85 |
|
86 |
// for security and configuration |
87 |
$realm=$HTTP_SERVER_VARS[HTTP_HOST]; |
88 |
|
89 |
$fsDocumentRoot = dirname($HTTP_SERVER_VARS[SCRIPT_FILENAME]); |
90 |
if ($fsDocumentRoot == "") Error("Configuration error","Can't get SCRIPT_FILENAME from your web server. Please set <tt>\$fsDocumentRoot</tt> in <tt>\$</tt>",1); |
91 |
|
92 |
// globals for later |
93 |
$gblLogin = $HTTP_SERVER_VARS[PHP_AUTH_USER]; |
94 |
$gblPasswd = $HTTP_SERVER_VARS[PHP_AUTH_PW]; |
95 |
|
96 |
////////////////////////////////////////////////////////////////// |
97 |
|
98 |
function LoadLanguage($lang) { |
99 |
|
100 |
global $gblIncDir,$html; |
101 |
|
102 |
if (file_exists($gblIncDir."/lang/$lang.php")) { |
103 |
include($gblIncDir."/lang/$lang.php"); |
104 |
$html .= "-$lang"; |
105 |
} else { |
106 |
include($gblIncDir."/lang/default.php"); |
107 |
} |
108 |
} |
109 |
|
110 |
function StartHTML($title,$text="") { |
111 |
|
112 |
global $html,$fsDocumentRoot,$HTTP_SERVER_VARS; |
113 |
|
114 |
$title = $gblTitle." ".$title ; |
115 |
$host = $HTTP_SERVER_VARS["HTTP_HOST"] ; |
116 |
$self = $HTTP_SERVER_VARS["PHP_SELF"] ; |
117 |
|
118 |
if (file_exists("$fsDocumentRoot/docman.css")) { |
119 |
$css=dirname($self)."/docman.css"; |
120 |
} else { |
121 |
$css=$self."?STYLE=get&css=$css"; |
122 |
} |
123 |
|
124 |
include("$html/head.html"); |
125 |
} |
126 |
|
127 |
////////////////////////////////////////////////////////////////// |
128 |
|
129 |
function EndHTML() { |
130 |
|
131 |
global $gblDateFmt, $gblTimeFmt, $gblUserName, $PHP_SELF, |
132 |
$secHash, $gblVersion, $html, |
133 |
$gblLogin,$gblPasswd; |
134 |
|
135 |
$url = $PHP_SELF."?relogin="; |
136 |
if (isset($secHash) && $secHash != "") { |
137 |
$url .= $secHash; |
138 |
} else { |
139 |
$url .= md5($gblLogin.$gblPasswd); |
140 |
} |
141 |
if (isset($gblLogin) && $gblLogin != "" && ($gblPasswd == "" || !isset($gblPasswd))) { |
142 |
$url_title="login"; |
143 |
$url .= "&force_login=1"; |
144 |
} else { |
145 |
$url_title="relogin"; |
146 |
} |
147 |
include("$html/footer.html"); |
148 |
} // end function EndHTML |
149 |
|
150 |
////////////////////////////////////////////////////////////////// |
151 |
|
152 |
function DetailPage($fsRoot,$relDir,$fn) { |
153 |
|
154 |
global $gblEditable, $gblImages, $webRoot, $html, $HTTP_SERVER_VARS ; |
155 |
$self = $HTTP_SERVER_VARS["PHP_SELF"] ; |
156 |
|
157 |
$relPath = $relDir . "/" . $fn ; |
158 |
$fsPath = $fsRoot . $relPath ; |
159 |
$fsDir = $fsRoot . $relDir ; |
160 |
|
161 |
$exists = file_exists($fsPath) ; |
162 |
$ext = strtolower(strrchr($relPath,".")) ; |
163 |
$editable = ( $ext=="" || strstr(join(" ",$gblEditable),$ext)) ; |
164 |
$writable = is_writeable($fsPath) ; |
165 |
$file_lock = CheckLock($fsPath); |
166 |
|
167 |
if (!$editable && !$exists) |
168 |
Error("Creation unsupported for type",$relPath) ; |
169 |
if (!exists && !is_writeable($fsDir) ) |
170 |
Error("Creation denied",$relDir) ; |
171 |
|
172 |
$text = _("Use this page to view, modify or ") ; |
173 |
if (is_dir($fsPath)) { |
174 |
$text .=_("delete a directory on this ") ; |
175 |
} else { |
176 |
$text .= _("delete a single document on this ") ; |
177 |
}; |
178 |
$text .= _("web site.") ; |
179 |
$title = "("._("Detail Page").")" ; |
180 |
StartHTML($title, $text) ; |
181 |
|
182 |
echo "<H3>" . $relDir . "/" . $fn . "</H3>" ; |
183 |
if ($exists) { // get file info |
184 |
$fsize = filesize($fsPath) ; |
185 |
$fmodified = date("$GLOBALS[gblDateFmt] $GLOBALS[gblTimeFmt]", filemtime($fsPath)) ; |
186 |
$faccessed = date("$GLOBALS[gblDateFmt] $GLOBALS[gblTimeFmt]", fileatime($fsPath)) ; |
187 |
$fuid=fileowner($fsPath); |
188 |
$fgid=filegroup($fsPath); |
189 |
$userinfo = posix_getpwuid($fuid); |
190 |
$grpinfo = posix_getgrgid($fgid); |
191 |
|
192 |
include("$html/DetailPage-file.html"); |
193 |
} |
194 |
|
195 |
if ( !is_dir($fsPath) && $editable && ($writable || !$exists) && !$file_lock ) { |
196 |
$fh = fopen($fsPath,"a+") ; |
197 |
rewind($fh) ; |
198 |
$fstr = fread($fh,filesize($fsPath)) ; |
199 |
fclose($fh) ; |
200 |
$fstr = htmlentities( $fstr ) ; |
201 |
?> |
202 |
|
203 |
<FORM ACTION="<?= $self ; ?>" METHOD="POST"> |
204 |
<SPAN TITLE="Click [SAVE] to store updated contents."> |
205 |
<B>DOCUMENT CONTENTS</B> |
206 |
</SPAN><BR> |
207 |
<TEXTAREA NAME="FILEDATA" ROWS=18 COLS=70 WRAP="OFF"><?php |
208 |
echo($fstr) ; ?></TEXTAREA> |
209 |
<INPUT TYPE="HIDDEN" NAME="DIR" VALUE="<?= $relDir ; ?>"> |
210 |
<INPUT TYPE="HIDDEN" NAME="FN" VALUE="<?= $fn ; ?>"> |
211 |
<INPUT TYPE="HIDDEN" NAME="POSTACTION" VALUE="SAVE"> |
212 |
<INPUT TYPE="HIDDEN" SIZE=48 MAXLENGTH=255 NAME="RELPATH" |
213 |
VALUE="<?= $relPath ; ?>"> |
214 |
<br> |
215 |
<INPUT TYPE="RESET" VALUE="UNDO ALL CHANGES"> |
216 |
<INPUT TYPE="SUBMIT" VALUE="SAVE"> |
217 |
</FORM> |
218 |
|
219 |
<?php |
220 |
} |
221 |
if ( !$file_lock && $ext!="" && strstr(join(' ',$gblImages),$ext) ) { |
222 |
$info = getimagesize($fsPath) ; |
223 |
$tstr = "<IMG SRC=\"$webRoot".urlpath($relPath)."\" BORDER=0 " ; |
224 |
$tstr .= $info[3] . " ALT=\"" . $fn . " - " ; |
225 |
$tstr .= (int)(($fsize+1023)/1024) . "Kb\">" ; |
226 |
// echo htmlentities($tstr) . "<BR><BR>" . $tstr ; |
227 |
echo $tstr ; |
228 |
} |
229 |
|
230 |
?> |
231 |
|
232 |
<FORM ACTION="<?= $self ; ?>" METHOD="POST"> |
233 |
<INPUT TYPE="HIDDEN" NAME="DIR" VALUE="<?= $relDir ; ?>"> |
234 |
<INPUT TYPE="HIDDEN" NAME="FN" VALUE="<?= $fn ; ?>"> |
235 |
<INPUT TYPE="SUBMIT" NAME="POSTACTION" VALUE="CANCEL"><BR> |
236 |
|
237 |
<?php |
238 |
|
239 |
if ($file_lock) { |
240 |
?> |
241 |
<hr> |
242 |
<SPAN TITLE="Check OK and click UNLOCK to remove lock on file."> |
243 |
<B>OK TO FORCE LOCK REMOVAL ON "<?= $fn ; ?>" HELD BY <?= $file_lock ?>? </B></SPAN> |
244 |
<INPUT TYPE="CHECKBOX" NAME="CONFIRM"> |
245 |
<INPUT TYPE="SUBMIT" NAME="POSTACTION" VALUE="UNLOCK"> |
246 |
<? |
247 |
} // file_lock |
248 |
|
249 |
if (substr($fn,0,4) == ".del") { |
250 |
$action="UNDELETE"; |
251 |
$desc="undelete previously deleted file"; |
252 |
} else { |
253 |
$action="DELETE"; |
254 |
$desc="delete"; |
255 |
} |
256 |
|
257 |
if ($exists && $writable) { |
258 |
?> |
259 |
|
260 |
<HR> |
261 |
<a name="undelete"> |
262 |
<SPAN TITLE="Check OK and click [<?= $action ?>] to <?= $desc ?>."> |
263 |
<B>OK TO <?= $action ?> "<?= $fn ; ?>"? </B></SPAN> |
264 |
<INPUT TYPE="CHECKBOX" NAME="CONFIRM"> |
265 |
<INPUT TYPE="SUBMIT" NAME="POSTACTION" VALUE="<?= $action ?>"> |
266 |
|
267 |
<HR> |
268 |
<a name="rename"> |
269 |
<SPAN TITLE="Check OK and click [RENAME] to rename."> |
270 |
<B>OK TO RENAME "<?= $fn ; ?>" TO |
271 |
<INPUT TYPE="TEXT" SIZE=24 MAXLENGTH=255 NAME="NEWNAME" VALUE="<?= $fn ?>"> |
272 |
? </B></SPAN> |
273 |
<INPUT TYPE="CHECKBOX" NAME="CONFIRM"> |
274 |
<INPUT TYPE="SUBMIT" NAME="POSTACTION" VALUE="RENAME"> |
275 |
|
276 |
<?php |
277 |
} // exists && writable |
278 |
?> |
279 |
<HR> |
280 |
<a name="note"> |
281 |
<B>NOTE FOR "<?= $fn ; ?>": |
282 |
<INPUT TYPE="TEXT" SIZE=50 MAXLENGTH=255 NAME="NOTE" VALUE="<?= ReadNote($fsPath) ?>"> |
283 |
</B></SPAN> |
284 |
<INPUT TYPE="SUBMIT" NAME="POSTACTION" VALUE="NOTE"> |
285 |
|
286 |
</FORM> |
287 |
|
288 |
<?php |
289 |
|
290 |
$name=basename("$fsDir/$fn"); |
291 |
$logname=dirname("$fsDir/$fn")."/.log/$name"; |
292 |
$bakdir=dirname("$fsDir/$fn")."/.bak"; |
293 |
if (file_exists($logname)) { |
294 |
$log=fopen($logname,"r"); |
295 |
$cl1=" class=LST"; $cl2=""; |
296 |
$logarr = array(); |
297 |
while($line = fgetcsv($log,512,"\t")) { |
298 |
$cl=$cl1; $cl1=$cl2; $cl2=$cl; |
299 |
array_unshift($logarr,array($cl,$line[0],$line[1],$line[2],$line[3])); |
300 |
} |
301 |
fclose($log); |
302 |
if (is_dir("$fsDir/$fn")) { |
303 |
$whatis="DIRECTORY"; |
304 |
} else { |
305 |
$whatis="FILE"; |
306 |
} |
307 |
print "<hr><br><b>CHANGES TO THIS $whatis</b><br><table border=0 width=100%>\n"; |
308 |
$bakcount = 0; // start from 0, skip fist backup (it's current) |
309 |
while ($e = array_shift($logarr)) { |
310 |
if (strstr($e[4],"upload")) { |
311 |
if (file_exists("$bakdir/$bakcount/$name")) { |
312 |
$e[4]="<a href=\"$webRoot".urlpath(dirname($relPath)."/.bak/$bakcount/$name")."\">$e[4]</a>"; |
313 |
} |
314 |
$bakcount++; |
315 |
} |
316 |
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"; |
317 |
} |
318 |
print "</table>"; |
319 |
} |
320 |
|
321 |
EndHTML() ; |
322 |
|
323 |
} // end function DetailPage |
324 |
|
325 |
////////////////////////////////////////////////////////////////// |
326 |
|
327 |
function DisplayCode($fsRoot,$relDir,$fn) { |
328 |
|
329 |
$path = $fsRoot . $relDir . "/" . $fn ; |
330 |
|
331 |
if (!file_exists($path)) Error("File not found",$path) ; |
332 |
|
333 |
StartHTML("(".$relDir."/".$fn.")",""); |
334 |
|
335 |
$tstr = join("",file($path)) ; |
336 |
$tstr = htmlentities($tstr) ; |
337 |
|
338 |
// Tabs |
339 |
$tstr = str_replace(chr(9)," ",$tstr) ; |
340 |
|
341 |
// ASP tags & XML/PHP tags |
342 |
$aspbeg = "<SPAN CLASS=XML><%</SPAN><SPAN CLASS=BLK>" ; |
343 |
$aspend = "</SPAN><SPAN CLASS=XML>%></SPAN>" ; |
344 |
$tstr = str_replace("<%",$aspbeg,$tstr) ; |
345 |
$tstr = str_replace("%>",$aspend,$tstr) ; |
346 |
|
347 |
$xmlbeg = "<SPAN CLASS=XML><?</SPAN><SPAN CLASS=BLK>" ; |
348 |
$xmlend = "</SPAN><SPAN CLASS=XML>?></SPAN>" ; |
349 |
$tstr = str_replace("<?",$xmlbeg,$tstr) ; |
350 |
$tstr = str_replace("?>",$xmlend,$tstr) ; |
351 |
|
352 |
// C style comment |
353 |
$tstr = str_replace("/*","<SPAN CLASS=REM>/*",$tstr) ; |
354 |
$tstr = str_replace("*/","*/</SPAN>",$tstr) ; |
355 |
|
356 |
// HTML comments |
357 |
$tstr = str_replace("<!--","<I CLASS=RED><!--",$tstr) ; |
358 |
$tstr = str_replace("-->","--></I>",$tstr) ; |
359 |
|
360 |
echo "<PRE>" ; |
361 |
|
362 |
$tstr = split("\n",$tstr) ; |
363 |
for ($i = 0 ; $i < sizeof($tstr) ; ++$i) { |
364 |
// add line numbers |
365 |
echo "<BR><EM>" ; |
366 |
echo substr(("000" . ($i+1)), -4) . ":</EM> " ; |
367 |
$line = $tstr[$i] ; |
368 |
// C++ style comments |
369 |
$pos = strpos($line,"//") ; |
370 |
// exceptions: two slashes aren't a script comment |
371 |
if (strstr($line,"//") && |
372 |
! ($pos>0 && substr($line,$pos-1,1)==":") && |
373 |
! (substr($line,$pos,8) == "//-->") && |
374 |
! (substr($line,$pos,9) == "// -->")) { |
375 |
$beg = substr($line,0,strpos($line,"//")) ; |
376 |
$end = strstr($line,"//") ; |
377 |
$line = $beg."<SPAN CLASS=REM>".$end."</SPAN>"; |
378 |
} |
379 |
// shell & asp style comments |
380 |
$first = substr(ltrim($line),0,1) ; |
381 |
if ($first == "#" || $first == "'") { |
382 |
$line = "<SPAN CLASS=REM>".$line."</SPAN>"; |
383 |
} |
384 |
print($line) ; |
385 |
} // next i |
386 |
|
387 |
echo "</PRE>" ; |
388 |
|
389 |
EndHTML() ; |
390 |
|
391 |
} // end function DisplayCode |
392 |
|
393 |
////////////////////////////////////////////////////////////////// |
394 |
|
395 |
function MockIcon($txt) { |
396 |
$tstr = "<SPAN CLASS=MCK>" ; |
397 |
|
398 |
switch (strtolower($txt)) { |
399 |
case ".bmp" : |
400 |
case ".gif" : |
401 |
case ".jpg" : |
402 |
case ".jpeg": |
403 |
case ".tif" : |
404 |
case ".tiff": |
405 |
$d = 176 ; |
406 |
break ; |
407 |
case ".doc" : |
408 |
$d = 50 ; |
409 |
break ; |
410 |
case ".exe" : |
411 |
case ".bat" : |
412 |
$d = 255 ; |
413 |
break ; |
414 |
case ".bas" : |
415 |
case ".c" : |
416 |
case ".cc" : |
417 |
case ".src" : |
418 |
$d = 255 ; |
419 |
break ; |
420 |
case "file" : |
421 |
$d = 51 ; |
422 |
break ; |
423 |
case "fldr" : |
424 |
$d = 48 ; |
425 |
break ; |
426 |
case ".htm" : |
427 |
case ".html": |
428 |
case ".asa" : |
429 |
case ".asp" : |
430 |
case ".cfm" : |
431 |
case ".php3": |
432 |
case ".php" : |
433 |
case ".phtml" : |
434 |
case ".shtml" : |
435 |
$d = 182 ; |
436 |
break ; |
437 |
case ".pdf" : |
438 |
$d = 38 ; |
439 |
break; |
440 |
case ".txt" : |
441 |
case ".ini" : |
442 |
$d = 52 ; |
443 |
break ; |
444 |
case ".xls" : |
445 |
$d = 252 ; |
446 |
break ; |
447 |
case ".zip" : |
448 |
case ".arc" : |
449 |
case ".sit" : |
450 |
case ".tar" : |
451 |
case ".gz" : |
452 |
case ".tgz" : |
453 |
case ".Z" : |
454 |
$d = 59 ; |
455 |
break ; |
456 |
case "view" : |
457 |
$d = 52 ; |
458 |
break ; |
459 |
case "up" : |
460 |
$d = 199 ; |
461 |
break ; |
462 |
case "blank" : |
463 |
return " </SPAN>" ; |
464 |
break ; |
465 |
default : |
466 |
$d = 51 ; |
467 |
} |
468 |
|
469 |
return $tstr . chr($d) . "</SPAN>" ; |
470 |
} // end function MockIcon |
471 |
|
472 |
////////////////////////////////////////////////////////////////// |
473 |
|
474 |
function GifIcon($txt) { |
475 |
global $gblIconLocation ; |
476 |
|
477 |
switch (strtolower($txt)) { |
478 |
case ".bmp" : |
479 |
case ".gif" : |
480 |
case ".jpg" : |
481 |
case ".jpeg": |
482 |
case ".tif" : |
483 |
case ".tiff": |
484 |
$d = "image2.gif" ; |
485 |
break ; |
486 |
case ".doc" : |
487 |
$d = "layout.gif" ; |
488 |
break ; |
489 |
case ".exe" : |
490 |
case ".bat" : |
491 |
$d = "screw2.gif" ; |
492 |
break ; |
493 |
case ".bas" : |
494 |
case ".c" : |
495 |
case ".cc" : |
496 |
case ".src" : |
497 |
$d = "c.gif" ; |
498 |
break ; |
499 |
case "file" : |
500 |
$d = "generic.gif" ; |
501 |
break ; |
502 |
case "fldr" : |
503 |
$d = "dir.gif" ; |
504 |
break ; |
505 |
case ".phps" : |
506 |
$d = "phps.gif" ; |
507 |
break ; |
508 |
case ".php3" : |
509 |
$d = "php3.gif" ; |
510 |
break ; |
511 |
case ".htm" : |
512 |
case ".html": |
513 |
case ".asa" : |
514 |
case ".asp" : |
515 |
case ".cfm" : |
516 |
case ".php3": |
517 |
case ".php" : |
518 |
case ".phtml" : |
519 |
case ".shtml" : |
520 |
$d = "world1.gif" ; |
521 |
break ; |
522 |
case ".pdf" : |
523 |
$d = "pdf.gif" ; |
524 |
break; |
525 |
case ".txt" : |
526 |
case ".ini" : |
527 |
$d = "text.gif" ; |
528 |
break ; |
529 |
case ".xls" : |
530 |
$d = "box2.gif" ; |
531 |
break ; |
532 |
case ".zip" : |
533 |
case ".arc" : |
534 |
case ".sit" : |
535 |
case ".tar" : |
536 |
case ".gz" : |
537 |
case ".tgz" : |
538 |
case ".Z" : |
539 |
$d = "compressed.gif" ; |
540 |
break ; |
541 |
case "view" : |
542 |
$d = "index.gif" ; |
543 |
break ; |
544 |
case "up" : |
545 |
$d = "back.gif" ; |
546 |
break ; |
547 |
case "blank" : |
548 |
$d = "blank.gif" ; |
549 |
break ; |
550 |
case "checkout": |
551 |
$d = "box2.gif"; |
552 |
break; |
553 |
case "checkin": |
554 |
$d = "hand.up.gif"; |
555 |
break; |
556 |
case "locked": |
557 |
$d = "screw2.gif"; |
558 |
break; |
559 |
case "note": |
560 |
$d = "quill.gif"; |
561 |
break; |
562 |
default : |
563 |
$d = "generic.gif" ; |
564 |
} |
565 |
|
566 |
return "<IMG SRC=\"$gblIconLocation" . $d . "\" BORDER=0>" ; |
567 |
} // end function GifIcon |
568 |
|
569 |
////////////////////////////////////////////////////////////////// |
570 |
|
571 |
function Navigate($fsRoot,$relDir) { |
572 |
|
573 |
global $gblEditable, $gblIcon, $gblModDays, $webRoot, $gblHide, |
574 |
$gblIgnoreUnknownFileType, |
575 |
$HTTP_GET_VARS, $html, $realm_config; |
576 |
|
577 |
$self = $HTTP_SERVER_VARS["PHP_SELF"] ; |
578 |
|
579 |
if ($relDir == "") $relDir = "/"; |
580 |
|
581 |
$fsDir = $fsRoot.$relDir."/"; // current directory |
582 |
|
583 |
if (!is_dir($fsDir)) Error("Dir not found",$relDir) ; |
584 |
|
585 |
$hide_items=",$gblHide,"; |
586 |
|
587 |
// read directory contents |
588 |
if ( !($dir = @opendir($fsDir)) ) |
589 |
Error("Read Access denied",$relDir,1) ; |
590 |
while ($item = readdir($dir)) { |
591 |
if ( substr($item,0,1) == "." || strstr($hide_items,",$item,") ) continue ; |
592 |
if (is_dir($fsDir.$item) || is_link ($fsDir.$item)) { |
593 |
if (check_perm($relDir.$item,trperm_b)) { |
594 |
$dirList[$item] = $item ; |
595 |
$dirNote[$item] = ReadNote($fsDir.$item); |
596 |
} |
597 |
} else if (is_file($fsDir.$item)) { |
598 |
if (check_perm($relDir.$item,trperm_r)) { |
599 |
$fileList[$item] = $item ; |
600 |
$fileDate[$item] = filemtime($fsDir.$item) ; |
601 |
$fileSize[$item] = filesize($fsDir.$item) ; |
602 |
$fileNote[$item] = ReadNote($fsDir.$item); |
603 |
} |
604 |
} else { |
605 |
if (! $gblIgnoreUnknownFileType) Error("File Type Error", "Item <tt>".$fsDir.$item."</tt> is not file, directory or link. If you want to ignore errors like this, set <tt>\$gblIgnoreUnknownFileType = 1</tt> in <tt>$realm_config</tt>.",1); |
606 |
} |
607 |
} |
608 |
closedir($dir) ; |
609 |
|
610 |
// scan deleted files |
611 |
if ( $HTTP_GET_VARS["show_deleted"] == 1 && ($dir = @opendir("$fsDir/.del")) ) { |
612 |
while ($item = readdir($dir)) { |
613 |
if ( substr($item,0,1) == "." || strstr($hide_items,",$item,") || !check_perm($relDir.$item,trperm_w) ) continue ; |
614 |
$fileList[$item] = ".del/$item" ; |
615 |
$fileDate[$item] = filemtime($fsDir.".del/$path") ; |
616 |
$fileSize[$item] = filesize($fsDir.".del/$path") ; |
617 |
$fileNote[$item] = ReadNote($fsDir.".del/$item"); |
618 |
} |
619 |
closedir($dir) ; |
620 |
} |
621 |
|
622 |
$emptyDir = ! (sizeof($dirList) || sizeof($fileList)) ; |
623 |
|
624 |
// start navigation page |
625 |
$text = "Use this page to add, delete"; |
626 |
if (! isset($HTTP_GET_VARS[show_deleted])) { |
627 |
$text .= ", <a href=$self?D=".urlencode($relDir)."&show_deleted=1>undelete</a>"; |
628 |
} |
629 |
$text .= " or revise files on this web site." ; |
630 |
$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>."; |
631 |
StartHTML("(Navigate)",$text) ; |
632 |
|
633 |
echo "<TABLE BORDER=0 CELLPADDING=2 |
634 |
CELLSPACING=3 WIDTH=\"100%\">" ; |
635 |
|
636 |
// updir bar |
637 |
if (chopsl($fsDir) != chopsl($fsRoot)) { |
638 |
$parent = dirname($relDir) ; |
639 |
if ($parent == "") $parent = "/" ; |
640 |
|
641 |
include("$html/Navigate-parent.html"); |
642 |
} |
643 |
|
644 |
function plural($name,$count) { |
645 |
$out="$count $name"; |
646 |
if ($count > 1) { |
647 |
$out.="s"; |
648 |
} |
649 |
return $out; |
650 |
} |
651 |
|
652 |
$dsort = $HTTP_GET_VARS[dsort]; |
653 |
if (! isset($dsort)) $dsort = "name"; // default directory sort |
654 |
|
655 |
$dsort_arr = array( |
656 |
"name" => array ("rname", "note"), |
657 |
"rname" => array ("name", "note"), |
658 |
"note" => array ("name", "rnote"), |
659 |
"rnote" => array ("name", "note") |
660 |
); |
661 |
|
662 |
$fsort = $HTTP_GET_VARS[fsort]; |
663 |
if (! isset($fsort)) $fsort = "name"; // default directory sort |
664 |
|
665 |
$fsort_arr = array( |
666 |
"name" => array ("rname", "note", "date", "size"), |
667 |
"rname" => array ("name", "note", "date", "size"), |
668 |
"note" => array ("name", "rnote", "date", "size"), |
669 |
"rnote" => array ("name", "note", "date", "size"), |
670 |
"date" => array ("name", "note", "rdate", "size"), |
671 |
"rdate" => array ("name", "note", "date", "size"), |
672 |
"size" => array ("name", "note", "date", "rsize"), |
673 |
"rsize" => array ("name", "note", "date", "size") |
674 |
); |
675 |
|
676 |
$D="D=".urlencode($relDir); |
677 |
|
678 |
function self_args($arr = array()) { |
679 |
$arg = implode("&",$arr); |
680 |
if ($arg) { |
681 |
return $self."?".$arg; |
682 |
} else { |
683 |
return $self; |
684 |
} |
685 |
} |
686 |
// output subdirs |
687 |
if (sizeof($dirList) > 0) { |
688 |
switch ($dsort) { |
689 |
case "note": |
690 |
$items = $dirNote; |
691 |
asort($items); |
692 |
break; |
693 |
case "rnote": |
694 |
$items = $dirNote; |
695 |
arsort($items); |
696 |
break; |
697 |
case "rname": |
698 |
$items = $dirList; |
699 |
krsort($items); |
700 |
break; |
701 |
default: |
702 |
$items = $dirList; |
703 |
ksort($items); |
704 |
break; |
705 |
} |
706 |
$durl = self_args(array($D,"dsort=".$dsort_arr[$dsort][0])); |
707 |
$nurl = self_args(array($D,"dsort=".$dsort_arr[$dsort][1])); |
708 |
|
709 |
include("$html/Navigate-dirHeader.html"); |
710 |
|
711 |
while (list($key,$dir) = each($items)) { |
712 |
|
713 |
$dir = $dirList[$key]; |
714 |
|
715 |
$info_url=self_args(array("A"=>"A=E", "F"=>"F=".urlencode($dir), "D"=>$D)); |
716 |
$dir_url=$self."?D=".urlencode($relDir."/".$dir); |
717 |
include("$html/Navigate-dirEntry.html"); |
718 |
|
719 |
} // iterate over dirs |
720 |
} // end if no dirs |
721 |
|
722 |
$durl = self_args(array($D,"fsort=".$fsort_arr[$fsort][0])); |
723 |
$nurl = self_args(array($D,"fsort=".$fsort_arr[$fsort][1])); |
724 |
$uurl = self_args(array($D,"fsort=".$fsort_arr[$fsort][2])); |
725 |
$surl = self_args(array($D,"fsort=".$fsort_arr[$fsort][3])); |
726 |
|
727 |
include("$html/Navigate-fileHeader.html"); |
728 |
|
729 |
if (sizeof($fileList) > 0) { |
730 |
switch ($fsort) { |
731 |
case "note": |
732 |
$items = $fileNote; |
733 |
asort($items); |
734 |
break; |
735 |
case "rnote": |
736 |
$items = $fileNote; |
737 |
arsort($items); |
738 |
break; |
739 |
case "date": |
740 |
$items = $fileDate; |
741 |
asort($items); |
742 |
break; |
743 |
case "rdate": |
744 |
$items = $fileDate; |
745 |
arsort($items); |
746 |
break; |
747 |
case "size": |
748 |
$items = $fileSize; |
749 |
asort($items); |
750 |
break; |
751 |
case "rsize": |
752 |
$items = $fileSize; |
753 |
arsort($items); |
754 |
break; |
755 |
case "rname": |
756 |
$items = $fileList; |
757 |
krsort($items); |
758 |
break; |
759 |
default: |
760 |
$items = $fileList; |
761 |
ksort($items); |
762 |
break; |
763 |
} |
764 |
|
765 |
while (list($key,$file) = each($items)) { |
766 |
$file = $fileList[$key]; |
767 |
$path = $fsDir."/".$file ; |
768 |
$mod = $fileDate[$key]; |
769 |
$sz = $fileSize[$key]; |
770 |
|
771 |
if ($sz >= 10240) { |
772 |
$sz = (int)(($sz+1023)/1024) . " k" ; |
773 |
} else { |
774 |
$sz .= " " ; |
775 |
} // end size |
776 |
|
777 |
$a = $b = "" ; |
778 |
|
779 |
$info_url=$self."?A=E&F=".urlencode($file)."&D=".urlencode($relDir); |
780 |
|
781 |
if ( ($mod + $gblModDays*86400) > time() ) { |
782 |
$a = "<SPAN CLASS=RED TITLE=\"Newer" ; |
783 |
$a .= " than $gblModDays days\"> * </SPAN>" ; |
784 |
} |
785 |
|
786 |
$file_lock=CheckLock($path); |
787 |
|
788 |
$file_url_html="<A HREF=\"$self?A=V&D=".urlencode($relDir)."&F=".urlencode($file); |
789 |
$file_url_html.="\" TITLE=\"View file\">" ; |
790 |
|
791 |
if (substr($file,0,5) != ".del/") { |
792 |
$file_url_html .= $file . "</A>" . $a ; |
793 |
} else { |
794 |
$file_url_html .= substr($file,5,strlen($file)-5) . "</a> <SPAN CLASS=RED TITLE=\"deleted\"> <a href=\"$info_url#undelete\">deleted</a> </span>"; |
795 |
} |
796 |
|
797 |
$note_html="<a href=\"$info_url#note\">".$gblIcon("note")."</a>".ReadNote($path); |
798 |
|
799 |
$ext = strtolower(strrchr($file,".")) ; |
800 |
|
801 |
if ($file_lock) { |
802 |
if ($file_lock == $GLOBALS[gblUserName]) { |
803 |
$b.="<A HREF=\"$self?A=Ci&D=".urlencode($relDir)."&F=".urlencode($file); |
804 |
$b.="\" TITLE=\"Checkin (update) file on server\">" ; |
805 |
$file_url_html=$b; |
806 |
$b.=$gblIcon("checkin")."</A>" ; |
807 |
$b.= $gblIcon("blank"); |
808 |
$file_url_html.="$file</a> $a"; |
809 |
$note_html = $gblIcon("blank")."<b>Please check-in (update) this file</b>"; |
810 |
} else { |
811 |
$b = $gblIcon("locked"); |
812 |
$b.= $gblIcon("blank"); |
813 |
$note_html = $gblIcon("blank")."<b>File locked by $file_lock</b>"; |
814 |
$file_url_html = "$file $a"; |
815 |
} |
816 |
} else { |
817 |
$b.="<A HREF=\"$self?A=Co&D=".urlencode($relDir)."&F=".urlencode($file); |
818 |
$b.="\" TITLE=\"Checkout file for edit\">" ; |
819 |
$b.=$gblIcon("checkout")."</A>"; |
820 |
|
821 |
if ( $ext=="" || strstr(join(" ",$gblEditable),$ext) ) { |
822 |
$b.="<A HREF=\"$self?A=C&D=".urlencode($relDir)."&F=".urlencode($file); |
823 |
$b.="\" TITLE=\"List contents\">" ; |
824 |
$b.=$gblIcon("view")."</A>" ; |
825 |
} else { |
826 |
$b.= $gblIcon("blank"); |
827 |
} |
828 |
} |
829 |
|
830 |
$mod = date("$GLOBALS[gblDateFmt] $GLOBALS[gblTimeFmt]",$mod); |
831 |
|
832 |
include("$html/Navigate-fileEntry.html"); |
833 |
|
834 |
} // iterate over files |
835 |
} else { // end if no files |
836 |
?> |
837 |
<TR><TD></TD><TD COLSPAN=5 CLASS=LST> |
838 |
No files in this directory |
839 |
</TD></TR> |
840 |
<? |
841 |
} |
842 |
|
843 |
if ($emptyDir && $relDir != "") { |
844 |
?> |
845 |
|
846 |
<FORM METHOD="POST" ACTION="<?= $self ?>"> |
847 |
<TR><TD></TD><TD COLSPAN=5 CLASS=BAR> |
848 |
<INPUT TYPE="HIDDEN" NAME="DIR" VALUE="<?= $relDir ?>"> |
849 |
OK TO DELETE THIS EMPTY FOLDER? |
850 |
<INPUT TYPE="CHECKBOX" NAME="CONFIRM"> |
851 |
<INPUT TYPE="SUBMIT" NAME="POSTACTION" VALUE="DELETE"> |
852 |
</TD></TR> |
853 |
</FORM> |
854 |
|
855 |
<?php |
856 |
} // end if emptyDir |
857 |
?> |
858 |
|
859 |
<TR><TD></TD><TD COLSPAN=5><HR></TD></TR> |
860 |
|
861 |
<? |
862 |
if (file_exists(".info.inc")) { |
863 |
print "<TR><TD></TD><TD COLSPAN=5>"; |
864 |
include(".info.inc"); |
865 |
print "</TD></TR> |
866 |
<TR><TD></TD><TD COLSPAN=5><HR></TD></TR>"; |
867 |
} |
868 |
?> |
869 |
|
870 |
<FORM METHOD="POST" ACTION="<?= $self ?>"> |
871 |
<TR><TD></TD><TD COLSPAN=5 CLASS=BAR>CREATE NEW |
872 |
<INPUT TYPE="RADIO" NAME="T" VALUE="D" CHECKED>DIRECTORY -OR- |
873 |
<INPUT TYPE="RADIO" NAME="T" VALUE="F">FILE : |
874 |
<NOBR>NAME <INPUT TYPE="TEXT" NAME="FN" SIZE=14> |
875 |
<INPUT TYPE="HIDDEN" NAME="POSTACTION" VALUE="CREATE"> |
876 |
<INPUT TYPE="HIDDEN" NAME="DIR" VALUE="<?= $relDir ?>"> |
877 |
<INPUT TYPE="SUBMIT" VALUE="CREATE" NAME="CREATE"> |
878 |
</NOBR> |
879 |
<NOBR>OR <A HREF="<?= $self ?>?A=U&D=<?= urlencode($relDir) ?>">UPLOAD</A> A FILE</NOBR> |
880 |
</TD></TR> |
881 |
</FORM> |
882 |
</TABLE> |
883 |
|
884 |
<?php |
885 |
EndHTML() ; |
886 |
} // end function Navigate |
887 |
|
888 |
////////////////////////////////////////////////////////////////// |
889 |
|
890 |
function UploadPage($fsRoot, $relDir, $filename="") { |
891 |
|
892 |
global $html, $HTTP_SERVER_VARS; |
893 |
|
894 |
$self = $HTTP_SERVER_VARS["PHP_SELF"] ; |
895 |
if ($relDir == "") $relDir = "/" ; |
896 |
|
897 |
include("$html/UploadPage.html"); |
898 |
|
899 |
} // end function UploadPage |
900 |
|
901 |
////////////////////////////////////////////////////////////////// |
902 |
|
903 |
// Error with sysadmin flag are reported to error_log or hidden from |
904 |
// users |
905 |
|
906 |
function Error($title,$text="",$sysadmin=0) { |
907 |
global $gblSeparateAdminMessages, |
908 |
$gblMailAdminMessages,$realm, |
909 |
$HTTP_SERVER_VARS; |
910 |
if (! headers_sent()) header("HTTP/1.0 404 Not Found"); |
911 |
if ($sysadmin) { |
912 |
if ($gblSeparateAdminMessages) { |
913 |
$user="Your administrator "; |
914 |
if ($gblMailAdminMessages) { |
915 |
mail($HTTP_SERVER_VARS["SERVER_ADMIN"], "docman $realm error message: $title", strip_tags($text)); |
916 |
$user.="<tt>".$HTTP_SERVER_VARS["SERVER_ADMIN"]."</tt> "; |
917 |
} |
918 |
$user.="has been notified about error" ; |
919 |
StartHTML("($title)",$user); |
920 |
echo "<P ALIGN=center>Hit your Browser's Back Button.</P>" ; |
921 |
EndHTML(); |
922 |
error_log("docman $realm: ".strip_tags($text)); |
923 |
} else { |
924 |
StartHTML("ADMIN: ".$title,$text) ; |
925 |
echo "<P ALIGN=center>Hit your Browser's Back Button.</P>" ; |
926 |
EndHTML(); |
927 |
} |
928 |
} else { |
929 |
StartHTML("(".$title.")",$text) ; |
930 |
echo "<P ALIGN=center>Hit your Browser's Back Button.</P>" ; |
931 |
EndHTML() ; |
932 |
} |
933 |
exit ; |
934 |
} // end function Error |
935 |
|
936 |
function LogIt($target,$msg, $changelog=0) { |
937 |
|
938 |
$dir=dirname($target); |
939 |
if (! file_exists($dir."/.log")) { |
940 |
if (! @mkdir($dir."/.log",0700)) Error("docman installation problem","can't create log directory <tt>$dir/.log</tt>",1); |
941 |
} |
942 |
$file=basename($target); |
943 |
|
944 |
$log=fopen("$dir/.log/$file","a+"); |
945 |
fputs($log,date("$GLOBALS[gblDateFmt]\t$GLOBALS[gblTimeFmt]"). |
946 |
"\t$GLOBALS[gblUserName]\t$msg\n"); |
947 |
fclose($log); |
948 |
|
949 |
if (! $changelog) return; |
950 |
|
951 |
global $gblFsRoot; |
952 |
$log=fopen("$gblFsRoot/.changelog","a+"); |
953 |
if (substr($target,0,strlen($gblFsRoot)) == $gblFsRoot) |
954 |
$target=substr($target,strlen($gblFsRoot),strlen($target)-strlen($gblFsRoot)); |
955 |
$msg=str_replace("\t"," ",$msg); |
956 |
fputs($log,time()."\t$target\t$GLOBALS[gblUserName]\t$msg\n"); |
957 |
fclose($log); |
958 |
|
959 |
// FIX: implement e-mail notification based on $changelog |
960 |
// permission |
961 |
} |
962 |
|
963 |
|
964 |
////////////////////////////////////////////////////////////////// |
965 |
|
966 |
function WriteNote($target,$msg) { |
967 |
|
968 |
$target=stripSlashes($target); |
969 |
$dir=dirname($target); |
970 |
if (! file_exists($dir."/.note")) { |
971 |
mkdir($dir."/.note",0700); |
972 |
} |
973 |
$file=basename($target); |
974 |
|
975 |
$note=fopen("$dir/.note/$file","w"); |
976 |
fputs($note,"$msg\n"); |
977 |
fclose($note); |
978 |
|
979 |
LogIt($target,"added note $msg"); |
980 |
|
981 |
} |
982 |
|
983 |
function ReadNote($target) { |
984 |
|
985 |
$target=stripSlashes($target); |
986 |
$dir=dirname($target); |
987 |
$file=basename($target); |
988 |
$msg=""; |
989 |
if (file_exists($dir."/.note/$file")) { |
990 |
$note=fopen("$dir/.note/$file","r"); |
991 |
$msg=fgets($note,4096); |
992 |
fclose($note); |
993 |
} |
994 |
return HtmlSpecialChars(StripSlashes($msg)); |
995 |
|
996 |
} |
997 |
|
998 |
////////////////////////////////////////////////////////////////// |
999 |
|
1000 |
function MoveTo($source,$folder) { |
1001 |
|
1002 |
$source=stripSlashes($source); |
1003 |
$file=basename($source); |
1004 |
if (! file_exists($folder)) { |
1005 |
mkdir($folder,0700); |
1006 |
} |
1007 |
if (file_exists($source)) { |
1008 |
rename($source,"$folder/$file"); |
1009 |
} |
1010 |
} |
1011 |
|
1012 |
////////////////////////////////////////////////////////////////// |
1013 |
|
1014 |
function Lock($target) { |
1015 |
|
1016 |
$target=stripSlashes($target); |
1017 |
$dir=dirname($target); |
1018 |
if (! file_exists($dir."/.lock")) { |
1019 |
mkdir($dir."/.lock",0700); |
1020 |
} |
1021 |
$file=basename($target); |
1022 |
|
1023 |
if (file_exists("$dir/.lock/$file")) { |
1024 |
LogIt($target,"attempt to locked allready locked file!"); |
1025 |
} else { |
1026 |
$lock=fopen("$dir/.lock/$file","w"); |
1027 |
fputs($lock,"$GLOBALS[gblUserName]\n"); |
1028 |
fclose($lock); |
1029 |
|
1030 |
LogIt($target,"file locked"); |
1031 |
} |
1032 |
|
1033 |
} |
1034 |
|
1035 |
function CheckLock($target) { |
1036 |
|
1037 |
$target=stripSlashes($target); |
1038 |
$dir=dirname($target); |
1039 |
$file=basename($target); |
1040 |
$msg=0; |
1041 |
if (file_exists($dir."/.lock/$file")) { |
1042 |
$lock=fopen("$dir/.lock/$file","r"); |
1043 |
$msg=fgets($lock,4096); |
1044 |
fclose($lock); |
1045 |
} |
1046 |
return chop($msg); |
1047 |
|
1048 |
} |
1049 |
|
1050 |
function Unlock($target) { |
1051 |
|
1052 |
$target=stripSlashes($target); |
1053 |
$dir=dirname($target); |
1054 |
$file=basename($target); |
1055 |
if (file_exists($dir."/.lock/$file")) { |
1056 |
unlink("$dir/.lock/$file"); |
1057 |
LogIt($target,"file unlocked"); |
1058 |
} else { |
1059 |
LogIt($target,"attempt to unlocked non-locked file!"); |
1060 |
} |
1061 |
|
1062 |
} |
1063 |
|
1064 |
////////////////////////////////////////////////////////////////// |
1065 |
|
1066 |
function urlpath($url) { |
1067 |
$url=urlencode(StripSlashes("$url")); |
1068 |
$url=str_replace("%2F","/",$url); |
1069 |
$url=str_replace("+","%20",$url); |
1070 |
return($url); |
1071 |
} |
1072 |
|
1073 |
////////////////////////////////////////////////////////////////// |
1074 |
|
1075 |
function safe_rename($fromdir,$fromfile,$tofile) { |
1076 |
function try_rename($from,$to) { |
1077 |
# print "$from -> $to\n"; |
1078 |
if (file_exists($from) && is_writeable(dirname($to))) { |
1079 |
return rename($from,$to); |
1080 |
} else { |
1081 |
return 0; |
1082 |
} |
1083 |
} |
1084 |
|
1085 |
function try_dir($todir) { |
1086 |
if (! file_exists($todir)) { |
1087 |
@mkdir($todir,0700); |
1088 |
} |
1089 |
} |
1090 |
|
1091 |
$to="$fromdir/$tofile"; |
1092 |
$todir=dirname($to); |
1093 |
$tofile=basename($to); |
1094 |
|
1095 |
# print "<pre>$fromdir / $fromfile -> $todir / $tofile\n\n"; |
1096 |
|
1097 |
if (! try_rename("$fromdir/$fromfile","$todir/$tofile")) Error("Rename error","Can't rename file <tt>$fromfile</tt> to <tt>$tofile</tt>",1); |
1098 |
try_dir("$todir/.log"); |
1099 |
try_rename("$fromdir/.log/$fromfile","$todir/.log/$tofile"); |
1100 |
try_dir("$todir/.note"); |
1101 |
try_rename("$fromdir/.note/$fromfile","$todir/.note/$tofile"); |
1102 |
try_dir("$todir/.lock"); |
1103 |
try_rename("$fromdir/.lock/$fromfile","$todir/.lock/$tofile"); |
1104 |
try_dir("$todir/.bak"); |
1105 |
for($i=0;$i<=$GLOBALS[gblNumBackups];$i++) { |
1106 |
try_rename("$fromdir/.bak/$i/$fromfile","$todir/.bak/$i/$tofile"); |
1107 |
} |
1108 |
} |
1109 |
|
1110 |
|
1111 |
////////////////////////////////////////////////////////////////// |
1112 |
|
1113 |
// recursivly delete directory |
1114 |
|
1115 |
function rrmdir($dir) { |
1116 |
$handle=opendir($dir); |
1117 |
while ($file = readdir($handle)) { |
1118 |
if ($file != "." && $file != "..") { |
1119 |
if (is_dir("$dir/$file")) |
1120 |
rrmdir("$dir/$file"); |
1121 |
else |
1122 |
if (! @unlink("$dir/$file")) return(0); |
1123 |
} |
1124 |
} |
1125 |
closedir($handle); |
1126 |
return @rmdir($dir); |
1127 |
} |
1128 |
|
1129 |
////////////////////////////////////////////////////////////////// |
1130 |
|
1131 |
function DisplayChangeLog($day) { |
1132 |
|
1133 |
global $gblFsRoot,$HTTP_SERVER_VARS; |
1134 |
|
1135 |
if (!file_exists("$gblFsRoot/.changelog")) return; |
1136 |
$log=fopen("$gblFsRoot/.changelog","r"); |
1137 |
$logarr = array(); |
1138 |
while($line = fgetcsv($log,512,"\t")) { |
1139 |
while (sizeof($line) > 4) { |
1140 |
$tmp = array_pop($line); |
1141 |
$line.=" $tmp"; |
1142 |
} |
1143 |
if ($day!=1 || ($day==1 && (time()-$line[0] < 24*60*60))) { |
1144 |
array_unshift($logarr,array($line[0],$line[1],$line[2],$line[3])); |
1145 |
} |
1146 |
} |
1147 |
fclose($log); |
1148 |
$cl1=" class=LST"; $cl2=""; |
1149 |
print "<table border=0 width=100%>\n"; |
1150 |
while ($e = array_shift($logarr)) { |
1151 |
$cl=$cl1; $cl1=$cl2; $cl2=$cl; |
1152 |
$date = date("$GLOBALS[gblDateFmt]", $e[0]); |
1153 |
$time = date("$GLOBALS[gblTimeFmt]", $e[0]); |
1154 |
$dir = dirname($e[1]); |
1155 |
$file = basename($e[1]); |
1156 |
print "<tr><td$cl>$date</td><td$cl>$time</td><td$cl><a href=\"$HTTP_SERVER_VARS[PHP_SELF]?D=".urlencode($dir)."\">$dir</a>/$file</td><td$cl>$e[2]</td><td$cl>$e[3]</td></tr>\n"; |
1157 |
} |
1158 |
print "</table>"; |
1159 |
print "<p>".GifIcon(up)." Back to <a href=$HTTP_SERVER_VARS[PHP_SELF]>front page</a>.</p>"; |
1160 |
} |
1161 |
|
1162 |
////////////////////////////////////////////////////////////////// |
1163 |
|
1164 |
function Download($path,$force=0) { |
1165 |
global $HTTP_SERVER_VARS,$mime_type; |
1166 |
|
1167 |
// default transfer-encoding |
1168 |
$encoding = "binary"; |
1169 |
|
1170 |
// known transfer encodings |
1171 |
$encoding_ext = array( |
1172 |
"gz" => "x-gzip", |
1173 |
"Z" => "x-compress", |
1174 |
); |
1175 |
|
1176 |
$file = basename($path); |
1177 |
$size = filesize($path); |
1178 |
|
1179 |
$ext_arr = explode(".",$file); |
1180 |
$ext = array_pop($ext_arr); |
1181 |
if ($encoding_ext[$ext]) { |
1182 |
$encoding = $encoding_ext[$ext]; |
1183 |
$ext = array_pop($ext_arr); |
1184 |
} |
1185 |
|
1186 |
if ($force || !isset($mime_type[$ext])) { |
1187 |
header("Content-Type: application/force-download"); |
1188 |
} else { |
1189 |
header("Content-Type: $mime_type[$ext]"); |
1190 |
} |
1191 |
|
1192 |
// IE5.5 just downloads index.php if we don't do this |
1193 |
if(preg_match("/MSIE 5.5/", $HTTP_SERVER_VARS[HTTP_USER_AGENT])) { |
1194 |
header("Content-Disposition: filename=$file"); |
1195 |
} else { |
1196 |
header("Content-Disposition: attachment; filename=$file"); |
1197 |
} |
1198 |
|
1199 |
header("Content-Transfer-Encoding: $encoding"); |
1200 |
$fh = fopen($path, "r"); |
1201 |
fpassthru($fh); |
1202 |
} |
1203 |
|
1204 |
|
1205 |
////////////////////////////////////////////////////////////////// |
1206 |
|
1207 |
function chopsl($path) { |
1208 |
if (substr($path,strlen($path)-1,1) == "/") $path=substr($path,0,strlen($path)-1); |
1209 |
$path=str_replace("//","/",$path); |
1210 |
return $path; |
1211 |
} |
1212 |
|
1213 |
////////////////////////////////////////////////////////////////// |
1214 |
/* |
1215 |
Document manager ACL implementation |
1216 |
|
1217 |
Written by Dobrica Pavlinusic <dpavlin@rot13.org> |
1218 |
|
1219 |
Based on ideas from Linux trustees code |
1220 |
by Vyacheslav Zavadsky <zavadsky@braysystems.com> |
1221 |
*/ |
1222 |
|
1223 |
define(trmask_not,1 << 0); |
1224 |
define(trmask_clear,1 << 1); |
1225 |
define(trmask_deny,1 << 2); |
1226 |
define(trmask_one_level,1 << 3); |
1227 |
define(trmask_group,1 << 4); |
1228 |
|
1229 |
define(trperm_r,1 << 5); |
1230 |
define(trperm_w,1 << 6); |
1231 |
define(trperm_b,1 << 7); |
1232 |
define(trperm_n,1 << 8); |
1233 |
|
1234 |
$trustee_a2n = array( |
1235 |
'!' => trmask_not, |
1236 |
'C' => trmask_clear, |
1237 |
'D' => trmask_deny, |
1238 |
'O' => trmask_one_level, |
1239 |
'+' => trmask_group, |
1240 |
'R' => trperm_r, |
1241 |
'W' => trperm_w, |
1242 |
'B' => trperm_b, |
1243 |
'N' => trperm_n, |
1244 |
); |
1245 |
|
1246 |
// debugging function |
1247 |
function display_trustee($t) { |
1248 |
global $trustee_a2n; |
1249 |
$out=""; |
1250 |
foreach ($trustee_a2n as $c=>$v) { |
1251 |
if ($t & $v) $out.=$c; |
1252 |
} |
1253 |
return $out; |
1254 |
} |
1255 |
function display_all_trustee() { |
1256 |
global $trustees; |
1257 |
print "trustee dump:<br>\n"; |
1258 |
foreach ($trustees as $path => $tr) { |
1259 |
print "<br><tt>$path</tt>\n"; |
1260 |
foreach ($tr as $user=>$perm) { |
1261 |
print "$user == $perm (".display_trustee($perm).")<br>\n"; |
1262 |
} |
1263 |
} |
1264 |
} |
1265 |
|
1266 |
function init_trustee() { |
1267 |
|
1268 |
global $trustee_conf,$trustee_php,$trustee_a2n,$groups,$trustees; |
1269 |
|
1270 |
// do we need to re-create compiled trustees? |
1271 |
if (! file_exists($trustee_conf)) { |
1272 |
# $error="$trustee_conf doesn't exits"; |
1273 |
return 0; # don't use trustees |
1274 |
} elseif (file_exists($trustee_conf) && !is_readable($trustee_conf)) { |
1275 |
$error="<tt>$trustee_conf</tt> exits, but is not readable"; |
1276 |
} elseif (!is_writable(dirname($trustee_php))) { |
1277 |
$error="<tt>".dirname($trustee_php)."</tt> must be writable by web server user"; |
1278 |
} elseif (file_exists($trustee_php) && !is_writable($trustee_php)) { |
1279 |
$error="trustees cache file <tt>$trustee_php</tt> exists, but is not writable by web server"; |
1280 |
} elseif (1 || filemtime($trustee_conf) >= filemtime($trustee_php)) { |
1281 |
$fp_php=@fopen($trustee_php,"w"); |
1282 |
fputs($fp_php,"<?php // don't edit by hand!\n"); |
1283 |
|
1284 |
$fp_conf=fopen($trustee_conf,"r"); |
1285 |
|
1286 |
$groups_arr = array(); |
1287 |
$perm_arr = array(); |
1288 |
|
1289 |
$tr_arr = array(); |
1290 |
|
1291 |
while (! feof($fp_conf)) { |
1292 |
$l = trim(fgets($fp_conf,4096)); |
1293 |
if (substr($l,0,1) == "+") { // no comment |
1294 |
$arr=explode(":",$l); |
1295 |
$groups_arr[$arr[0]] = $arr[1] ; |
1296 |
} elseif (substr($l,0,1) != "#") { |
1297 |
$arr=explode(":",$l); |
1298 |
$path=array_shift($arr); |
1299 |
if ($path == "") continue; |
1300 |
$sep2=""; |
1301 |
while ($user=array_shift($arr)) { |
1302 |
$perm=0; |
1303 |
if (substr($user,0,1) == "+") { |
1304 |
$perm|=trmask_group; |
1305 |
$user=substr($user,1,strlen($user)-1); |
1306 |
} |
1307 |
$perm_ascii=array_shift($arr); |
1308 |
for ($i=0;$i<strlen($perm_ascii);$i++) { |
1309 |
$ch=strtoupper($perm_ascii[$i]); |
1310 |
if (isset($trustee_a2n[$ch])) { |
1311 |
$perm|=$trustee_a2n[$ch]; |
1312 |
} else { |
1313 |
$error.="trustee error in line '$l' [Unknown modifier '$ch']<br>\n"; |
1314 |
} |
1315 |
} |
1316 |
$tr_arr[$path][$user] |= $perm; |
1317 |
} |
1318 |
} |
1319 |
} |
1320 |
|
1321 |
fclose($fp_conf); |
1322 |
|
1323 |
// save trustees |
1324 |
$tr_out='$trustees = array ('; |
1325 |
$sep1=""; |
1326 |
while (list ($path, $tr) = each ($tr_arr)) { |
1327 |
$tr_out.="$sep1\n\t'$path'=>array("; |
1328 |
$sep2=""; |
1329 |
while (list($user,$perm)=each($tr)) { |
1330 |
$tr_out.="$sep2\n\t\t'$user'=>$perm"; |
1331 |
$sep2=","; |
1332 |
} |
1333 |
$tr_out.="\n\t)"; |
1334 |
$sep1=","; |
1335 |
} |
1336 |
$tr_out.="\n);"; |
1337 |
|
1338 |
// save groups |
1339 |
$gr_out='$groups = array ('; |
1340 |
$sep=""; |
1341 |
while (list ($group, $members) = each ($groups_arr)) { |
1342 |
$gr_out.="$sep\n\t'"; |
1343 |
$gr_out.=substr($group,1,strlen($group)-1); |
1344 |
$gr_out.="'=>array('".join("','",explode(",",$members))."')"; |
1345 |
$sep=","; |
1346 |
} |
1347 |
$gr_out.="\n);\n"; |
1348 |
|
1349 |
fputs($fp_php,$gr_out); |
1350 |
fputs($fp_php,$tr_out); |
1351 |
fputs($fp_php,"?>\n"); |
1352 |
fclose($fp_php); |
1353 |
} |
1354 |
|
1355 |
if ($error) { |
1356 |
Error("Trustee error",$error,1); |
1357 |
} else { |
1358 |
include("$trustee_php"); |
1359 |
} |
1360 |
|
1361 |
return 1; |
1362 |
|
1363 |
}//init_trustee |
1364 |
|
1365 |
function in_group($user,$group) { |
1366 |
return in_array($groups[$group],$user); |
1367 |
} |
1368 |
|
1369 |
// helper function |
1370 |
function unroll_perm($u,$t,$user,$perm) { |
1371 |
// check user |
1372 |
if ($t & trmask_not && ($u==$user)) continue; |
1373 |
if (!($t & trmask_not) && ($u!=$user)) continue; |
1374 |
|
1375 |
if ($t & trmask_deny) { |
1376 |
if ($t & trmask_clear) { |
1377 |
$perm[deny] &= ~$t; |
1378 |
} else { |
1379 |
$perm[deny] |= $t; |
1380 |
} |
1381 |
} elseif ($t & trmask_clear) { |
1382 |
$perm[allow] &= ~$t; |
1383 |
} else { |
1384 |
$perm[allow] |= $t; |
1385 |
} |
1386 |
return $perm; |
1387 |
}// end of helper function |
1388 |
|
1389 |
function check_trustee($user,$path) { |
1390 |
global $trustees; |
1391 |
$perm[allow] = 0; |
1392 |
$perm[deny] = 0; |
1393 |
$path_arr=explode("/",$path); |
1394 |
$path = "/"; |
1395 |
while (count($path_arr)) { |
1396 |
if (substr($path,strlen($path)-1,1) != "/") $path.="/"; |
1397 |
$path.=array_shift($path_arr); |
1398 |
$tr = $trustees[$path]; |
1399 |
|
1400 |
if (isset($tr)) { |
1401 |
// first apply trustee for all |
1402 |
if (isset($tr['*'])) { |
1403 |
$perm = unroll_perm($user,$tr['*'],$user, $perm); |
1404 |
unset($tr['*']); |
1405 |
} |
1406 |
// then apply group policies |
1407 |
foreach ($tr as $u=>$t) { |
1408 |
if ($t & trmask_group && in_group($user,$u)) { |
1409 |
// resolv user |
1410 |
$t = $t & ~trmask_group; |
1411 |
$u = $user; |
1412 |
$perm = unroll_perm($u,$t,$user, $perm); |
1413 |
unset($tr[$u]); |
1414 |
} |
1415 |
} |
1416 |
// then apply use policy |
1417 |
if (isset($tr[$user])) { |
1418 |
$perm = unroll_perm($user,$tr[$user],$user, $perm); |
1419 |
unset($tr[$user]); |
1420 |
} |
1421 |
|
1422 |
} |
1423 |
|
1424 |
} |
1425 |
#print "<br>user: $user path: $path perm: "; |
1426 |
#print "d: $perm[deny] (".display_trustee($perm[deny]).") a: $perm[allow] (".display_trustee($perm[allow]).")<Br>\n"; |
1427 |
return $perm; |
1428 |
} |
1429 |
|
1430 |
// handy functions |
1431 |
|
1432 |
function check_perm($path,$trperm) { |
1433 |
global $gblLogin,$HAVE_TRUSTEE; |
1434 |
print "<br>check_perm: <tt>$path</tt> test perm ".display_trustee($perm)."<br>\n"; |
1435 |
$return = ! $HAVE_TRUSTEE; |
1436 |
if ($HAVE_TRUSTEE) { |
1437 |
$perm = check_trustee($gblLogin,$path); |
1438 |
print " d: $perm[deny] (".display_trustee($perm[deny]).") a: $perm[allow] (".display_trustee($perm[allow]).") perm: $trperm"; |
1439 |
if ($perm[deny] & $trperm) $return=0; |
1440 |
elseif ($perm[allow] & $trperm) $return=1; |
1441 |
} |
1442 |
print " return: $return<br>\n"; |
1443 |
return($return); |
1444 |
} |
1445 |
|
1446 |
////////////////////////////////////////////////////////////////// |
1447 |
|
1448 |
function readMime() { |
1449 |
global $mime_type; |
1450 |
|
1451 |
if (! isset($gblMimeTypes)) { |
1452 |
$gblMimeTypes = "/etc/mime.types"; |
1453 |
} |
1454 |
|
1455 |
$mime = @fopen($gblMimeTypes,"r"); |
1456 |
|
1457 |
if (! $mime) Error("Can't read MIME types","<tt>$gblMimeTypes</tt> file not found. You can setup other <tt>mime.types</tt> file using <tt>\$gblMimeTypes</tt> in <tt>$realm_config</tt>"); |
1458 |
|
1459 |
while($line = fgets($mime,80)) { |
1460 |
if (substr($line,0,1) == "#") continue; // skip comment |
1461 |
$arr = preg_split("/[\s\t]+/",$line); |
1462 |
$type = array_shift($arr); |
1463 |
while ($ext = array_shift($arr)) { |
1464 |
$mime_type[$ext] = $type; |
1465 |
} |
1466 |
} |
1467 |
|
1468 |
fclose($mime); |
1469 |
} |
1470 |
|
1471 |
////////////////////////////////////////////////////////////////// |
1472 |
// MAIN PROGRAM |
1473 |
|
1474 |
$gblFilePerms = 0640 ; // default for new files |
1475 |
$gblDirPerms = 0750 ; // default for new dirs |
1476 |
|
1477 |
if (isset($STYLE) && $STYLE == "get") { |
1478 |
include("$html/docman.css"); |
1479 |
exit; |
1480 |
} |
1481 |
|
1482 |
// location of master docman configuration file |
1483 |
$docman_conf = "/etc/docman.conf"; |
1484 |
if (! file_exists($docman_conf)) { |
1485 |
$error = "Can't find master configuration file $docman_conf. See docman2/doc/upgrade.html#docman_conf for more informations"; |
1486 |
|
1487 |
error_log("docman: $error"); |
1488 |
Error("docman not installed completly",$error); |
1489 |
} |
1490 |
include($docman_conf); |
1491 |
|
1492 |
if (! isset($fsRealmDir)) { |
1493 |
$fsRealmDir = "$gblIncDir/realm"; |
1494 |
} |
1495 |
$realm_config = "$fsRealmDir/$realm.conf"; |
1496 |
|
1497 |
// read user-defined configuration |
1498 |
if (file_exists($realm_config)) { |
1499 |
include($realm_config); |
1500 |
} else { |
1501 |
Error("Configuration error","Can't find configuration file at <tt>$realm_config</tt> !"); |
1502 |
} |
1503 |
|
1504 |
if (! isset($gblRepositoryDir)) Error("Configuration error","<tt>\$gblRepositoryDir</tt> is not setuped in realm configuration file <tt>$realm_config</tt>"); |
1505 |
|
1506 |
// where do we get users from? |
1507 |
if (file_exists("$gblIncDir/htusers/$gblUsers.php")) { |
1508 |
include("$gblIncDir/htusers/$gblUsers.php"); |
1509 |
} else { |
1510 |
Error("Configuration error","Can't find user handling module at <tt>$gblIncDir/htusers/$gblUsers.php</tt> ! Please fix <tt>$realm_config</tt>"); |
1511 |
} |
1512 |
|
1513 |
// if no password, or empty password logout |
1514 |
if ( |
1515 |
isset($gblLogin) && ( |
1516 |
!isset($relogin) || ( |
1517 |
isset($relogin) && $relogin != md5($gblLogin.$gblPasswd) |
1518 |
) |
1519 |
) && ( |
1520 |
$gblPasswd == "" || !isset($gblPasswd) |
1521 |
) && !isset($force_login) && $gblLogin != "anonymous" |
1522 |
) { |
1523 |
StartHTML("Logout completed","Your login credentials has been erased") ; |
1524 |
EndHTML() ; |
1525 |
exit ; |
1526 |
} |
1527 |
|
1528 |
if (!is_dir($gblRepositoryDir)) Error("Repository dir not found","Can't find repository directory <tt>$gblRepositoryDir</tt>. Please fix that in <tt>$realm_config</tt> variable <tt>\$gblRepositoryDir</tt>.",1); |
1529 |
|
1530 |
// trustee (ACL) file configuration |
1531 |
$trustee_conf="$gblIncDir/realm/$realm.trustee"; |
1532 |
// compiled version of trustee file |
1533 |
$trustee_php="$gblRepositoryDir/.trustee.php"; |
1534 |
// get ACL informations |
1535 |
$HAVE_TRUSTEE = init_trustee(); |
1536 |
|
1537 |
if (strtolower($gblLogin) == "anonymous" || !isset($gblPasswd)) { |
1538 |
$perm = check_trustee($gblLogin,$path); |
1539 |
// browsing must be explicitly allowed for root directory |
1540 |
// of repository for anonymous user to work! |
1541 |
if ($perm[allow] & trperm_b) { |
1542 |
$secHash = md5($gblLogin.$gblPasswd); |
1543 |
$gblUserName = "Anonymous user"; |
1544 |
} |
1545 |
} |
1546 |
|
1547 |
// authentication failure |
1548 |
if ( md5($gblLogin.$gblPasswd) != $secHash || |
1549 |
isset($relogin) && $secHash == $relogin) { |
1550 |
header("WWW-authenticate: basic realm=\"$realm\"") ; |
1551 |
header("HTTP/1.0 401 Unauthorized") ; |
1552 |
Error("401 Unauthorized","No trespassing !"); |
1553 |
} |
1554 |
|
1555 |
// read mime.types |
1556 |
readMime(); |
1557 |
|
1558 |
// get current directory relative to $gblFsRoot |
1559 |
$relDir = $DIR ; // from POST |
1560 |
if ($relDir == "") { // not defined in POST ? |
1561 |
$relDir = urldecode($D) ; // then use GET |
1562 |
} |
1563 |
|
1564 |
$relDir=stripSlashes($relDir); |
1565 |
|
1566 |
if ($relDir == "/") $relDir = "" ; |
1567 |
// default : website root = "" |
1568 |
|
1569 |
if (strstr($relDir,"..")) Error("No updirs allowed"); |
1570 |
|
1571 |
// full paths contain "fs" or "Fs". Paths realitve to root of |
1572 |
// website contain "rel" or "Rel". The script won't let you |
1573 |
// edit anything above directory equal to http://server.com |
1574 |
// i.e. below $gblFsRoot. |
1575 |
|
1576 |
$relScriptDir = dirname($SCRIPT_NAME) ; |
1577 |
// i.e. /docman |
1578 |
|
1579 |
// start on server root |
1580 |
$gblFsRoot = $gblRepositoryDir; |
1581 |
// i.e. /home/httpd/html |
1582 |
|
1583 |
$fsDir = $gblFsRoot . $relDir ; // current directory |
1584 |
if ( !is_dir($fsDir) ) Error("Dir not found",$relDir) ; |
1585 |
|
1586 |
if (isset($HTTP_SERVER_VARS["HTTPS"]) && $HTTP_SERVER_VARS["HTTPS"] == "on") { |
1587 |
$webRoot = "https://"; |
1588 |
} else { |
1589 |
$webRoot = "http://"; |
1590 |
} |
1591 |
$webRoot .= $HTTP_SERVER_VARS["HTTP_HOST"] . $relScriptDir; |
1592 |
|
1593 |
// take variables from server |
1594 |
$FN=stripSlashes($HTTP_POST_VARS["FN"]); |
1595 |
$DIR=stripSlashes($HTTP_POST_VARS["DIR"]); |
1596 |
$RELPATH=stripSlashes($HTTP_POST_VARS["RELPATH"]); |
1597 |
$T=stripSlashes($HTTP_POST_VARS["T"]); |
1598 |
$CONFIRM=stripSlashes($HTTP_POST_VARS["CONFIRM"]); |
1599 |
|
1600 |
// get |
1601 |
$A=stripSlashes($HTTP_GET_VARS["A"]); |
1602 |
$D=stripSlashes($HTTP_GET_VARS["D"]); |
1603 |
|
1604 |
// if (isset($F)) Error("Document manager system error","variable $F shouldn't be set here (re-check old code)",1); |
1605 |
// $F=stripSlashes($HTTP_SERVER_VARS["PATH_INFO"]); |
1606 |
$F=stripSlashes($HTTP_GET_VARS["F"]); |
1607 |
|
1608 |
switch ($HTTP_POST_VARS["POSTACTION"]) { |
1609 |
case "UPLOAD" : |
1610 |
$FN_name=stripSlashes($HTTP_POST_FILES["FN"]["tmp_name"]); |
1611 |
$FN=stripSlashes($HTTP_POST_FILES["FN"]["name"]); |
1612 |
if (!is_writeable($fsDir)) Error("Write denied",$relDir) ; |
1613 |
|
1614 |
$source = $FN_name ; |
1615 |
if (! file_exists($source)) { |
1616 |
Error("You must select file with browse to upload it!"); |
1617 |
} |
1618 |
|
1619 |
$FILENAME = $HTTP_POST_VARS["FILENAME"]; |
1620 |
if (strstr($FILENAME,"/")) |
1621 |
Error("Upload error","Non-conforming filename. Filename <tt>$FILENAME</tt> has slashes (<tt>/</tt>) in it.") ; |
1622 |
if (! isset($FILENAME)) { // from update file |
1623 |
$target = "$fsDir/".basename($FN_name); |
1624 |
} else { |
1625 |
$target = "$fsDir/$FILENAME"; |
1626 |
} |
1627 |
|
1628 |
// backup old files first |
1629 |
$dir=dirname($target); |
1630 |
if (! file_exists($dir."/.bak")) { |
1631 |
mkdir($dir."/.bak",0700); |
1632 |
} |
1633 |
if (! file_exists($dir."/.bak/$GLOBALS[gblNumBackups]")) { |
1634 |
mkdir($dir."/.bak/$GLOBALS[gblNumBackups]",0700); |
1635 |
} |
1636 |
$file=basename($target); |
1637 |
for($i=$GLOBALS[gblNumBackups]-1;$i>0;$i--) { |
1638 |
MoveTo("$dir/.bak/$i/$file","$dir/.bak/".($i+1)."/"); |
1639 |
} |
1640 |
MoveTo($target,$dir."/.bak/1/"); |
1641 |
|
1642 |
copy($source,$target) ; |
1643 |
chmod($target,$gblFilePerms) ; |
1644 |
clearstatcache() ; |
1645 |
if (isset($FILENAME)) { |
1646 |
LogIt($target,"check-in",trperm_r | trperm_w); |
1647 |
Unlock($target); |
1648 |
} else { |
1649 |
LogIt($target,"uploaded",trperm_r | trperm_w); |
1650 |
} |
1651 |
break ; |
1652 |
|
1653 |
case "SAVE" : |
1654 |
$path = $gblFsRoot . $RELPATH ; |
1655 |
$path=stripSlashes($path); |
1656 |
$writable = is_writeable($path) ; |
1657 |
$legaldir = is_writeable(dirname($path)) ; |
1658 |
$exists = (file_exists($path)) ? 1 : 0 ; |
1659 |
// check for legal extension here as well |
1660 |
if (!($writable || (!$exists && $legaldir))) |
1661 |
Error("Write denied",$RELPATH) ; |
1662 |
$fh = fopen($path, "w") ; |
1663 |
$FILEDATA=stripSlashes($FILEDATA); |
1664 |
fwrite($fh,$FILEDATA) ; |
1665 |
fclose($fh) ; |
1666 |
clearstatcache() ; |
1667 |
LogIt($path,"saved changes",trperm_r); |
1668 |
break ; |
1669 |
|
1670 |
case "CREATE" : |
1671 |
// we know $fsDir exists |
1672 |
if ($FN == "") break; // no filename! |
1673 |
if (!is_writeable($fsDir)) Error("Write denied",$relDir) ; |
1674 |
$path = $fsDir . "/" . $FN ; // file or dir to create |
1675 |
$relPath = $relDir . "/" . $FN ; |
1676 |
switch ( $T ) { |
1677 |
case "D" : // create a directory |
1678 |
if ( ! @mkdir($path,$gblDirPerms) ) |
1679 |
Error("Mkdir failed",$relPath) ; // eg. if it exists |
1680 |
else |
1681 |
LogIt($path."/","dir created",trperm_w); |
1682 |
clearstatcache() ; |
1683 |
break ; |
1684 |
case "F" : // create a new file |
1685 |
// this functionality is doubled in DetailView(). |
1686 |
// better keep it here altogether |
1687 |
// chmod perms to $gblFilePerms |
1688 |
if ( file_exists($path) && !is_writeable($path) ) |
1689 |
Error("File not writable", $relPath) ; |
1690 |
$fh = fopen($path, "w+") ; |
1691 |
if ($fh) { |
1692 |
fputs($fh,"\n"); |
1693 |
fclose($fh) ; |
1694 |
LogIt($path,"file created",trperm_r | trperm_w); |
1695 |
} else { |
1696 |
Error("Creation of file $relPath failed -- $path"); |
1697 |
} |
1698 |
$tstr = "$PHP_SELF?A=E&D=".urlencode($relDir)."&F=".urlencode($FN) ; |
1699 |
header("Location: " . $tstr) ; |
1700 |
exit ; |
1701 |
} |
1702 |
break ; |
1703 |
|
1704 |
case "DELETE" : |
1705 |
if ( $CONFIRM != "on" ) break ; |
1706 |
|
1707 |
$tstr = "Attempt to delete non-existing object or " ; |
1708 |
$tstr .= "insufficient privileges: " ; |
1709 |
|
1710 |
if ( $FN != "") { // delete file |
1711 |
$path = $fsDir . "/" . $FN ; |
1712 |
|
1713 |
$dir=dirname($path); |
1714 |
$file=basename($path); |
1715 |
if (! file_exists("$dir/.del")) { |
1716 |
mkdir("$dir/.del",0700); |
1717 |
} |
1718 |
|
1719 |
// if ( ! @unlink($path) ) { |
1720 |
if ( ! rename($path,"$dir/.del/$file") ) { |
1721 |
LogIt($path,"file delete failed"); |
1722 |
Error("File delete failed", $tstr . $path) ; |
1723 |
} else { |
1724 |
LogIt($path,"file deleted",trperm_w); |
1725 |
MoveTo("$dir/.log/$file","$dir/.del/.log/"); |
1726 |
MoveTo("$dir/.note/$file","$dir/.del/.note/"); |
1727 |
MoveTo("$dir/.lock/$file","$dir/.del/.lock/"); |
1728 |
} |
1729 |
} else { // delete directory |
1730 |
if ( ! @rrmdir($fsDir) ) { |
1731 |
Error("Rmdir failed", $tstr . $fsDir) ; |
1732 |
} else { |
1733 |
LogIt($path,"dir deleted",trperm_w); |
1734 |
$relDir = dirname($relDir) ; // move up |
1735 |
} |
1736 |
} |
1737 |
break ; |
1738 |
|
1739 |
case "UNDELETE" : |
1740 |
if ( $CONFIRM != "on" ) break ; |
1741 |
|
1742 |
if (substr($FN,0,4) != ".del") break ; |
1743 |
$file=substr($FN,4,strlen($FN)-4); |
1744 |
|
1745 |
LogIt("$fsDir/.del/$file","undeleted",trperm_w); |
1746 |
MoveTo("$fsDir/.del/$file","$fsDir/"); |
1747 |
MoveTo("$fsDir/.del/.log/$file","$fsDir/.log/"); |
1748 |
MoveTo("$fsDir/.del/.note/$file","$fsDir/.note/"); |
1749 |
MoveTo("$fsDir/.del/.lock/$file","$fsDir/.lock/"); |
1750 |
|
1751 |
break ; |
1752 |
|
1753 |
case "RENAME" : |
1754 |
if ( $CONFIRM != "on" ) break ; |
1755 |
|
1756 |
$NEWNAME=stripSlashes($HTTP_POST_VARS["NEWNAME"]); |
1757 |
LogIt("$fsDir/$FN","renamed $FN to $NEWNAME",trperm_r); |
1758 |
safe_rename($fsDir,$FN,$NEWNAME); |
1759 |
break ; |
1760 |
|
1761 |
case "NOTE" : |
1762 |
$NOTE=stripSlashes($HTTP_POST_VARS["NOTE"]); |
1763 |
WriteNote("$fsDir/$FN","$NOTE"); |
1764 |
break ; |
1765 |
|
1766 |
case "UNLOCK" : |
1767 |
if ( $CONFIRM != "on" ) break ; |
1768 |
Unlock("$fsDir/$FN"); |
1769 |
break ; |
1770 |
|
1771 |
default : |
1772 |
// user hit "CANCEL" or undefined action |
1773 |
} |
1774 |
|
1775 |
// common to all POSTs : redirect to directory view ($relDir) |
1776 |
if ( $POSTACTION != "" ) { |
1777 |
$tstr = $PHP_SELF . "?D=" . urlencode($relDir) ; |
1778 |
header("Location: " . $tstr) ; |
1779 |
exit ; |
1780 |
} |
1781 |
|
1782 |
// check for mode.. navigate, code display, upload, or detail? |
1783 |
// $A=U : upload to path given in $D |
1784 |
// $A=E : display detail of file $D/$F and edit |
1785 |
// $A=C : display code in file $D/$F |
1786 |
// $A=Co : checkout file $D/$F |
1787 |
// $A=Ci : checkin file $D/$F |
1788 |
// $A=V : view file (do nothing except log) |
1789 |
// $A=I : include file .$F.php from $gblFsRoot |
1790 |
// default : display directory $D |
1791 |
|
1792 |
switch ($A) { |
1793 |
case "U" : |
1794 |
// upload to $relDir |
1795 |
if (!is_writeable($gblFsRoot . $relDir)) |
1796 |
Error("Write access denied",$relDir) ; |
1797 |
$text = "Use this page to upload a single " ; |
1798 |
$text .= "file to <B>$realm</B>." ; |
1799 |
StartHTML("(Upload Page)", $text) ; |
1800 |
UploadPage($gblFsRoot, $relDir) ; |
1801 |
EndHTML() ; |
1802 |
exit ; |
1803 |
case "E" : |
1804 |
// detail of $relDir/$F |
1805 |
if (is_file("$gblFsRoot/$relDir/$F") || is_dir("$gblFsRoot/$relDir/$F")) DetailPage($gblFsRoot, $relDir, $F) ; |
1806 |
exit ; |
1807 |
case "C" : |
1808 |
$F=stripSlashes($F); |
1809 |
// listing of $relDir/$F |
1810 |
DisplayCode($gblFsRoot, $relDir, $F) ; |
1811 |
exit ; |
1812 |
case "Co" : |
1813 |
// checkout |
1814 |
Lock("$gblFsRoot/$relDir/$F"); |
1815 |
Download("$gblFsRoot/$relDir/$F",1); |
1816 |
exit; |
1817 |
case "Ci" : |
1818 |
$F=stripSlashes($F); |
1819 |
// upload && update to $relDir |
1820 |
if (!is_writeable($gblFsRoot . $relDir)) |
1821 |
Error("Write access denied",$relDir) ; |
1822 |
$text = "Use this page to update a single " ; |
1823 |
$text .= "file to <B>$realm</B>." ; |
1824 |
StartHTML("(Update file Page)", $text) ; |
1825 |
UploadPage($gblFsRoot, $relDir, $F) ; |
1826 |
EndHTML() ; |
1827 |
exit ; |
1828 |
case "V" : |
1829 |
// view |
1830 |
LogIt("$gblFsRoot/$relDir/$F","viewed"); |
1831 |
Download("$gblFsRoot/$relDir/$F",$gblForceDownload); |
1832 |
exit; |
1833 |
case "Ch" : |
1834 |
StartHTML("(File changes)","All changes chronologicaly..."); |
1835 |
DisplayChangeLog(0); // all |
1836 |
EndHTML() ; |
1837 |
exit; |
1838 |
case "Ch1" : |
1839 |
StartHTML("(File changes)","Changes to files in last day..."); |
1840 |
DisplayChangeLog(1); |
1841 |
EndHTML() ; |
1842 |
exit; |
1843 |
case "I" : |
1844 |
$F=stripSlashes($F); |
1845 |
$inc_file="${gblFsRoot}/.${F}.php"; |
1846 |
if (!isset($F) || $F == "" || !file_exists($inc_file)) Error("Fatal error $inc_file"); // can't find file to include |
1847 |
if (!is_readable($inc_file)) |
1848 |
Error("Read access to include file denied",".${F}.php"); |
1849 |
$text = "Your include file should define \$text variable which holds this text and \$title variable which is page title"; |
1850 |
$title = "You should define \$title variable with page title"; |
1851 |
include($inc_file); |
1852 |
StartHTML($title, $text) ; |
1853 |
print "<p>".GifIcon(up)." Back to <a href=$HTTP_SERVER_VARS[PHP_SELF]>front page</a>.</p>"; |
1854 |
EndHTML() ; |
1855 |
exit ; |
1856 |
} |
1857 |
|
1858 |
// default: display directory $relDir |
1859 |
Navigate($gblFsRoot,$relDir) ; |
1860 |
exit ; |
1861 |
|
1862 |
Error("Whooah!","By cartesian logic, this never happens",1) ; |
1863 |
?> |