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 |
* http://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, $gblRepositoryDir, |
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 |
|
863 |
if (file_exists("$gblRepositoryDir/.info.inc")) { |
864 |
print "<TR><TD></TD><TD COLSPAN=5>"; |
865 |
include("$gblRepositoryDir/.info.inc"); |
866 |
print "</TD></TR><TR><TD></TD><TD COLSPAN=5><HR></TD></TR>"; |
867 |
} |
868 |
|
869 |
?> |
870 |
|
871 |
<FORM METHOD="POST" ACTION="<?= $self ?>"> |
872 |
<TR><TD></TD><TD COLSPAN=5 CLASS=BAR>CREATE NEW |
873 |
<INPUT TYPE="RADIO" NAME="T" VALUE="D" CHECKED>DIRECTORY -OR- |
874 |
<INPUT TYPE="RADIO" NAME="T" VALUE="F">FILE : |
875 |
<NOBR>NAME <INPUT TYPE="TEXT" NAME="FN" SIZE=14> |
876 |
<INPUT TYPE="HIDDEN" NAME="POSTACTION" VALUE="CREATE"> |
877 |
<INPUT TYPE="HIDDEN" NAME="DIR" VALUE="<?= $relDir ?>"> |
878 |
<INPUT TYPE="SUBMIT" VALUE="CREATE" NAME="CREATE"> |
879 |
</NOBR> |
880 |
<NOBR>OR <A HREF="<?= $self ?>?A=U&D=<?= urlencode($relDir) ?>">UPLOAD</A> A FILE</NOBR> |
881 |
</TD></TR> |
882 |
</FORM> |
883 |
</TABLE> |
884 |
|
885 |
<?php |
886 |
EndHTML() ; |
887 |
} // end function Navigate |
888 |
|
889 |
////////////////////////////////////////////////////////////////// |
890 |
|
891 |
function UploadPage($fsRoot, $relDir, $filename="") { |
892 |
|
893 |
global $html, $HTTP_SERVER_VARS; |
894 |
|
895 |
$self = $HTTP_SERVER_VARS["PHP_SELF"] ; |
896 |
if ($relDir == "") $relDir = "/" ; |
897 |
|
898 |
include("$html/UploadPage.html"); |
899 |
|
900 |
} // end function UploadPage |
901 |
|
902 |
////////////////////////////////////////////////////////////////// |
903 |
|
904 |
// Error with sysadmin flag are reported to error_log or hidden from |
905 |
// users |
906 |
|
907 |
function Error($title,$text="",$sysadmin=0) { |
908 |
global $gblSeparateAdminMessages, |
909 |
$gblMailAdminMessages,$realm, |
910 |
$HTTP_SERVER_VARS; |
911 |
if (! headers_sent()) header("HTTP/1.0 404 Not Found"); |
912 |
if ($sysadmin) { |
913 |
if ($gblSeparateAdminMessages) { |
914 |
$user="Your administrator "; |
915 |
if ($gblMailAdminMessages) { |
916 |
mail($HTTP_SERVER_VARS["SERVER_ADMIN"], "docman $realm error message: $title", strip_tags($text)); |
917 |
$user.="<tt>".$HTTP_SERVER_VARS["SERVER_ADMIN"]."</tt> "; |
918 |
} |
919 |
$user.="has been notified about error" ; |
920 |
StartHTML("($title)",$user); |
921 |
echo "<P ALIGN=center>Hit your Browser's Back Button.</P>" ; |
922 |
EndHTML(); |
923 |
error_log("docman $realm: ".strip_tags($text)); |
924 |
} else { |
925 |
StartHTML("ADMIN: ".$title,$text) ; |
926 |
echo "<P ALIGN=center>Hit your Browser's Back Button.</P>" ; |
927 |
EndHTML(); |
928 |
} |
929 |
} else { |
930 |
StartHTML("(".$title.")",$text) ; |
931 |
echo "<P ALIGN=center>Hit your Browser's Back Button.</P>" ; |
932 |
EndHTML() ; |
933 |
} |
934 |
exit ; |
935 |
} // end function Error |
936 |
|
937 |
function LogIt($target,$msg, $changelog=0) { |
938 |
|
939 |
$dir=dirname($target); |
940 |
if (! file_exists($dir."/.log")) { |
941 |
if (! @mkdir($dir."/.log",0700)) Error("docman installation problem","can't create log directory <tt>$dir/.log</tt>",1); |
942 |
} |
943 |
$file=basename($target); |
944 |
|
945 |
$log=fopen("$dir/.log/$file","a+"); |
946 |
fputs($log,date("$GLOBALS[gblDateFmt]\t$GLOBALS[gblTimeFmt]"). |
947 |
"\t$GLOBALS[gblUserName]\t$msg\n"); |
948 |
fclose($log); |
949 |
|
950 |
if (! $changelog) return; |
951 |
|
952 |
global $gblFsRoot; |
953 |
$log=fopen("$gblFsRoot/.changelog","a+"); |
954 |
if (substr($target,0,strlen($gblFsRoot)) == $gblFsRoot) |
955 |
$target=substr($target,strlen($gblFsRoot),strlen($target)-strlen($gblFsRoot)); |
956 |
$msg=str_replace("\t"," ",$msg); |
957 |
fputs($log,time()."\t$target\t$GLOBALS[gblUserName]\t$msg\n"); |
958 |
fclose($log); |
959 |
|
960 |
// FIX: implement e-mail notification based on $changelog |
961 |
// permission |
962 |
} |
963 |
|
964 |
|
965 |
////////////////////////////////////////////////////////////////// |
966 |
|
967 |
function WriteNote($target,$msg) { |
968 |
|
969 |
$target=stripSlashes($target); |
970 |
$dir=dirname($target); |
971 |
if (! file_exists($dir."/.note")) { |
972 |
mkdir($dir."/.note",0700); |
973 |
} |
974 |
$file=basename($target); |
975 |
|
976 |
$note=fopen("$dir/.note/$file","w"); |
977 |
fputs($note,"$msg\n"); |
978 |
fclose($note); |
979 |
|
980 |
LogIt($target,"added note $msg"); |
981 |
|
982 |
} |
983 |
|
984 |
function ReadNote($target) { |
985 |
|
986 |
$target=stripSlashes($target); |
987 |
$dir=dirname($target); |
988 |
$file=basename($target); |
989 |
$msg=""; |
990 |
if (file_exists($dir."/.note/$file")) { |
991 |
$note=fopen("$dir/.note/$file","r"); |
992 |
$msg=fgets($note,4096); |
993 |
fclose($note); |
994 |
} |
995 |
return HtmlSpecialChars(StripSlashes($msg)); |
996 |
|
997 |
} |
998 |
|
999 |
////////////////////////////////////////////////////////////////// |
1000 |
|
1001 |
function MoveTo($source,$folder) { |
1002 |
|
1003 |
$source=stripSlashes($source); |
1004 |
$file=basename($source); |
1005 |
if (! file_exists($folder)) { |
1006 |
mkdir($folder,0700); |
1007 |
} |
1008 |
if (file_exists($source)) { |
1009 |
rename($source,"$folder/$file"); |
1010 |
} |
1011 |
} |
1012 |
|
1013 |
////////////////////////////////////////////////////////////////// |
1014 |
|
1015 |
function Lock($target) { |
1016 |
|
1017 |
$target=stripSlashes($target); |
1018 |
$dir=dirname($target); |
1019 |
if (! file_exists($dir."/.lock")) { |
1020 |
mkdir($dir."/.lock",0700); |
1021 |
} |
1022 |
$file=basename($target); |
1023 |
|
1024 |
if (file_exists("$dir/.lock/$file")) { |
1025 |
LogIt($target,"attempt to locked allready locked file!"); |
1026 |
} else { |
1027 |
$lock=fopen("$dir/.lock/$file","w"); |
1028 |
fputs($lock,"$GLOBALS[gblUserName]\n"); |
1029 |
fclose($lock); |
1030 |
|
1031 |
LogIt($target,"file locked"); |
1032 |
} |
1033 |
|
1034 |
} |
1035 |
|
1036 |
function CheckLock($target) { |
1037 |
|
1038 |
$target=stripSlashes($target); |
1039 |
$dir=dirname($target); |
1040 |
$file=basename($target); |
1041 |
$msg=0; |
1042 |
if (file_exists($dir."/.lock/$file")) { |
1043 |
$lock=fopen("$dir/.lock/$file","r"); |
1044 |
$msg=fgets($lock,4096); |
1045 |
fclose($lock); |
1046 |
} |
1047 |
return chop($msg); |
1048 |
|
1049 |
} |
1050 |
|
1051 |
function Unlock($target) { |
1052 |
|
1053 |
$target=stripSlashes($target); |
1054 |
$dir=dirname($target); |
1055 |
$file=basename($target); |
1056 |
if (file_exists($dir."/.lock/$file")) { |
1057 |
unlink("$dir/.lock/$file"); |
1058 |
LogIt($target,"file unlocked"); |
1059 |
} else { |
1060 |
LogIt($target,"attempt to unlocked non-locked file!"); |
1061 |
} |
1062 |
|
1063 |
} |
1064 |
|
1065 |
////////////////////////////////////////////////////////////////// |
1066 |
|
1067 |
function urlpath($url) { |
1068 |
$url=urlencode(StripSlashes("$url")); |
1069 |
$url=str_replace("%2F","/",$url); |
1070 |
$url=str_replace("+","%20",$url); |
1071 |
return($url); |
1072 |
} |
1073 |
|
1074 |
////////////////////////////////////////////////////////////////// |
1075 |
|
1076 |
function safe_rename($fromdir,$fromfile,$tofile) { |
1077 |
function try_rename($from,$to) { |
1078 |
# print "$from -> $to\n"; |
1079 |
if (file_exists($from) && is_writeable(dirname($to))) { |
1080 |
return rename($from,$to); |
1081 |
} else { |
1082 |
return 0; |
1083 |
} |
1084 |
} |
1085 |
|
1086 |
function try_dir($todir) { |
1087 |
if (! file_exists($todir)) { |
1088 |
@mkdir($todir,0700); |
1089 |
} |
1090 |
} |
1091 |
|
1092 |
$to="$fromdir/$tofile"; |
1093 |
$todir=dirname($to); |
1094 |
$tofile=basename($to); |
1095 |
|
1096 |
# print "<pre>$fromdir / $fromfile -> $todir / $tofile\n\n"; |
1097 |
|
1098 |
if (! try_rename("$fromdir/$fromfile","$todir/$tofile")) Error("Rename error","Can't rename file <tt>$fromfile</tt> to <tt>$tofile</tt>",1); |
1099 |
try_dir("$todir/.log"); |
1100 |
try_rename("$fromdir/.log/$fromfile","$todir/.log/$tofile"); |
1101 |
try_dir("$todir/.note"); |
1102 |
try_rename("$fromdir/.note/$fromfile","$todir/.note/$tofile"); |
1103 |
try_dir("$todir/.lock"); |
1104 |
try_rename("$fromdir/.lock/$fromfile","$todir/.lock/$tofile"); |
1105 |
try_dir("$todir/.bak"); |
1106 |
for($i=0;$i<=$GLOBALS[gblNumBackups];$i++) { |
1107 |
try_rename("$fromdir/.bak/$i/$fromfile","$todir/.bak/$i/$tofile"); |
1108 |
} |
1109 |
} |
1110 |
|
1111 |
|
1112 |
////////////////////////////////////////////////////////////////// |
1113 |
|
1114 |
// recursivly delete directory |
1115 |
|
1116 |
function rrmdir($dir) { |
1117 |
$handle=opendir($dir); |
1118 |
while ($file = readdir($handle)) { |
1119 |
if ($file != "." && $file != "..") { |
1120 |
if (is_dir("$dir/$file")) |
1121 |
rrmdir("$dir/$file"); |
1122 |
else |
1123 |
if (! @unlink("$dir/$file")) return(0); |
1124 |
} |
1125 |
} |
1126 |
closedir($handle); |
1127 |
return @rmdir($dir); |
1128 |
} |
1129 |
|
1130 |
////////////////////////////////////////////////////////////////// |
1131 |
|
1132 |
function DisplayChangeLog($day) { |
1133 |
|
1134 |
global $gblFsRoot,$HTTP_SERVER_VARS; |
1135 |
|
1136 |
if (!file_exists("$gblFsRoot/.changelog")) return; |
1137 |
$log=fopen("$gblFsRoot/.changelog","r"); |
1138 |
$logarr = array(); |
1139 |
while($line = fgetcsv($log,512,"\t")) { |
1140 |
while (sizeof($line) > 4) { |
1141 |
$tmp = array_pop($line); |
1142 |
$line.=" $tmp"; |
1143 |
} |
1144 |
if ($day!=1 || ($day==1 && (time()-$line[0] < 24*60*60))) { |
1145 |
array_unshift($logarr,array($line[0],$line[1],$line[2],$line[3])); |
1146 |
} |
1147 |
} |
1148 |
fclose($log); |
1149 |
$cl1=" class=LST"; $cl2=""; |
1150 |
print "<table border=0 width=100%>\n"; |
1151 |
while ($e = array_shift($logarr)) { |
1152 |
$cl=$cl1; $cl1=$cl2; $cl2=$cl; |
1153 |
$date = date("$GLOBALS[gblDateFmt]", $e[0]); |
1154 |
$time = date("$GLOBALS[gblTimeFmt]", $e[0]); |
1155 |
$dir = dirname($e[1]); |
1156 |
$file = basename($e[1]); |
1157 |
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"; |
1158 |
} |
1159 |
print "</table>"; |
1160 |
print "<p>".GifIcon(up)." Back to <a href=$HTTP_SERVER_VARS[PHP_SELF]>front page</a>.</p>"; |
1161 |
} |
1162 |
|
1163 |
////////////////////////////////////////////////////////////////// |
1164 |
|
1165 |
function Download($path,$force=0) { |
1166 |
global $HTTP_SERVER_VARS,$mime_type; |
1167 |
|
1168 |
// default transfer-encoding |
1169 |
$encoding = "binary"; |
1170 |
|
1171 |
// known transfer encodings |
1172 |
$encoding_ext = array( |
1173 |
"gz" => "x-gzip", |
1174 |
"Z" => "x-compress", |
1175 |
); |
1176 |
|
1177 |
$file = basename($path); |
1178 |
$size = filesize($path); |
1179 |
|
1180 |
$ext_arr = explode(".",$file); |
1181 |
$ext = array_pop($ext_arr); |
1182 |
if ($encoding_ext[$ext]) { |
1183 |
$encoding = $encoding_ext[$ext]; |
1184 |
$ext = array_pop($ext_arr); |
1185 |
} |
1186 |
|
1187 |
if ($force || !isset($mime_type[$ext])) { |
1188 |
header("Content-Type: application/force-download"); |
1189 |
} else { |
1190 |
header("Content-Type: $mime_type[$ext]"); |
1191 |
} |
1192 |
|
1193 |
// IE5.5 just downloads index.php if we don't do this |
1194 |
if(preg_match("/MSIE 5.5/", $HTTP_SERVER_VARS[HTTP_USER_AGENT])) { |
1195 |
header("Content-Disposition: filename=$file"); |
1196 |
} else { |
1197 |
header("Content-Disposition: attachment; filename=$file"); |
1198 |
} |
1199 |
|
1200 |
header("Content-Transfer-Encoding: $encoding"); |
1201 |
$fh = fopen($path, "r"); |
1202 |
fpassthru($fh); |
1203 |
} |
1204 |
|
1205 |
|
1206 |
////////////////////////////////////////////////////////////////// |
1207 |
|
1208 |
function chopsl($path) { |
1209 |
if (substr($path,strlen($path)-1,1) == "/") $path=substr($path,0,strlen($path)-1); |
1210 |
$path=str_replace("//","/",$path); |
1211 |
return $path; |
1212 |
} |
1213 |
|
1214 |
////////////////////////////////////////////////////////////////// |
1215 |
/* |
1216 |
Document manager ACL implementation |
1217 |
|
1218 |
Written by Dobrica Pavlinusic <dpavlin@rot13.org> |
1219 |
|
1220 |
Based on ideas from Linux trustees code |
1221 |
by Vyacheslav Zavadsky <zavadsky@braysystems.com> |
1222 |
*/ |
1223 |
|
1224 |
define(trmask_not,1 << 0); |
1225 |
define(trmask_clear,1 << 1); |
1226 |
define(trmask_deny,1 << 2); |
1227 |
define(trmask_one_level,1 << 3); |
1228 |
define(trmask_group,1 << 4); |
1229 |
|
1230 |
define(trperm_r,1 << 5); |
1231 |
define(trperm_w,1 << 6); |
1232 |
define(trperm_b,1 << 7); |
1233 |
define(trperm_n,1 << 8); |
1234 |
|
1235 |
$trustee_a2n = array( |
1236 |
'!' => trmask_not, |
1237 |
'C' => trmask_clear, |
1238 |
'D' => trmask_deny, |
1239 |
'O' => trmask_one_level, |
1240 |
'+' => trmask_group, |
1241 |
'R' => trperm_r, |
1242 |
'W' => trperm_w, |
1243 |
'B' => trperm_b, |
1244 |
'N' => trperm_n, |
1245 |
); |
1246 |
|
1247 |
// debugging function |
1248 |
function display_trustee($t) { |
1249 |
global $trustee_a2n; |
1250 |
$out=""; |
1251 |
foreach ($trustee_a2n as $c=>$v) { |
1252 |
if ($t & $v) $out.=$c; |
1253 |
} |
1254 |
return $out; |
1255 |
} |
1256 |
function display_all_trustee() { |
1257 |
global $trustees; |
1258 |
print "trustee dump:<br>\n"; |
1259 |
foreach ($trustees as $path => $tr) { |
1260 |
print "<br><tt>$path</tt>\n"; |
1261 |
foreach ($tr as $user=>$perm) { |
1262 |
print "$user == $perm (".display_trustee($perm).")<br>\n"; |
1263 |
} |
1264 |
} |
1265 |
} |
1266 |
|
1267 |
function init_trustee() { |
1268 |
|
1269 |
global $trustee_conf,$trustee_php,$trustee_a2n,$groups,$trustees; |
1270 |
|
1271 |
// do we need to re-create compiled trustees? |
1272 |
if (! file_exists($trustee_conf)) { |
1273 |
# $error="$trustee_conf doesn't exits"; |
1274 |
return 0; # don't use trustees |
1275 |
} elseif (file_exists($trustee_conf) && !is_readable($trustee_conf)) { |
1276 |
$error="<tt>$trustee_conf</tt> exits, but is not readable"; |
1277 |
} elseif (!is_writable(dirname($trustee_php))) { |
1278 |
$error="<tt>".dirname($trustee_php)."</tt> must be writable by web server user"; |
1279 |
} elseif (file_exists($trustee_php) && !is_writable($trustee_php)) { |
1280 |
$error="trustees cache file <tt>$trustee_php</tt> exists, but is not writable by web server"; |
1281 |
} elseif (1 || filemtime($trustee_conf) >= filemtime($trustee_php)) { |
1282 |
$fp_php=@fopen($trustee_php,"w"); |
1283 |
fputs($fp_php,"<?php // don't edit by hand!\n"); |
1284 |
|
1285 |
$fp_conf=fopen($trustee_conf,"r"); |
1286 |
|
1287 |
$groups_arr = array(); |
1288 |
$perm_arr = array(); |
1289 |
|
1290 |
$tr_arr = array(); |
1291 |
|
1292 |
while (! feof($fp_conf)) { |
1293 |
$l = trim(fgets($fp_conf,4096)); |
1294 |
if (substr($l,0,1) == "+") { // no comment |
1295 |
$arr=explode(":",$l); |
1296 |
$groups_arr[$arr[0]] = $arr[1] ; |
1297 |
} elseif (substr($l,0,1) != "#") { |
1298 |
$arr=explode(":",$l); |
1299 |
$path=array_shift($arr); |
1300 |
if ($path == "") continue; |
1301 |
$sep2=""; |
1302 |
while ($user=array_shift($arr)) { |
1303 |
$perm=0; |
1304 |
if (substr($user,0,1) == "+") { |
1305 |
$perm|=trmask_group; |
1306 |
$user=substr($user,1,strlen($user)-1); |
1307 |
} |
1308 |
$perm_ascii=array_shift($arr); |
1309 |
for ($i=0;$i<strlen($perm_ascii);$i++) { |
1310 |
$ch=strtoupper($perm_ascii[$i]); |
1311 |
if (isset($trustee_a2n[$ch])) { |
1312 |
$perm|=$trustee_a2n[$ch]; |
1313 |
} else { |
1314 |
$error.="trustee error in line '$l' [Unknown modifier '$ch']<br>\n"; |
1315 |
} |
1316 |
} |
1317 |
$tr_arr[$path][$user] |= $perm; |
1318 |
} |
1319 |
} |
1320 |
} |
1321 |
|
1322 |
fclose($fp_conf); |
1323 |
|
1324 |
// save trustees |
1325 |
$tr_out='$trustees = array ('; |
1326 |
$sep1=""; |
1327 |
while (list ($path, $tr) = each ($tr_arr)) { |
1328 |
$tr_out.="$sep1\n\t'$path'=>array("; |
1329 |
$sep2=""; |
1330 |
while (list($user,$perm)=each($tr)) { |
1331 |
$tr_out.="$sep2\n\t\t'$user'=>$perm"; |
1332 |
$sep2=","; |
1333 |
} |
1334 |
$tr_out.="\n\t)"; |
1335 |
$sep1=","; |
1336 |
} |
1337 |
$tr_out.="\n);"; |
1338 |
|
1339 |
// save groups |
1340 |
$gr_out='$groups = array ('; |
1341 |
$sep=""; |
1342 |
while (list ($group, $members) = each ($groups_arr)) { |
1343 |
$gr_out.="$sep\n\t'"; |
1344 |
$gr_out.=substr($group,1,strlen($group)-1); |
1345 |
$gr_out.="'=>array('".join("','",explode(",",$members))."')"; |
1346 |
$sep=","; |
1347 |
} |
1348 |
$gr_out.="\n);\n"; |
1349 |
|
1350 |
fputs($fp_php,$gr_out); |
1351 |
fputs($fp_php,$tr_out); |
1352 |
fputs($fp_php,"?>\n"); |
1353 |
fclose($fp_php); |
1354 |
} |
1355 |
|
1356 |
if ($error) { |
1357 |
Error("Trustee error",$error,1); |
1358 |
} else { |
1359 |
include("$trustee_php"); |
1360 |
} |
1361 |
|
1362 |
return 1; |
1363 |
|
1364 |
}//init_trustee |
1365 |
|
1366 |
function in_group($user,$group) { |
1367 |
return in_array($groups[$group],$user); |
1368 |
} |
1369 |
|
1370 |
// helper function |
1371 |
function unroll_perm($u,$t,$user,$perm) { |
1372 |
// check user |
1373 |
if ($t & trmask_not && ($u==$user)) continue; |
1374 |
if (!($t & trmask_not) && ($u!=$user)) continue; |
1375 |
|
1376 |
if ($t & trmask_deny) { |
1377 |
if ($t & trmask_clear) { |
1378 |
$perm[deny] &= ~$t; |
1379 |
} else { |
1380 |
$perm[deny] |= $t; |
1381 |
} |
1382 |
} elseif ($t & trmask_clear) { |
1383 |
$perm[allow] &= ~$t; |
1384 |
} else { |
1385 |
$perm[allow] |= $t; |
1386 |
} |
1387 |
return $perm; |
1388 |
}// end of helper function |
1389 |
|
1390 |
function check_trustee($user,$path) { |
1391 |
global $trustees; |
1392 |
$perm[allow] = 0; |
1393 |
$perm[deny] = 0; |
1394 |
$path_arr=explode("/",$path); |
1395 |
$path = "/"; |
1396 |
while (count($path_arr)) { |
1397 |
if (substr($path,strlen($path)-1,1) != "/") $path.="/"; |
1398 |
$path.=array_shift($path_arr); |
1399 |
$tr = $trustees[$path]; |
1400 |
|
1401 |
if (isset($tr)) { |
1402 |
// first apply trustee for all |
1403 |
if (isset($tr['*'])) { |
1404 |
$perm = unroll_perm($user,$tr['*'],$user, $perm); |
1405 |
unset($tr['*']); |
1406 |
} |
1407 |
// then apply group policies |
1408 |
foreach ($tr as $u=>$t) { |
1409 |
if ($t & trmask_group && in_group($user,$u)) { |
1410 |
// resolv user |
1411 |
$t = $t & ~trmask_group; |
1412 |
$u = $user; |
1413 |
$perm = unroll_perm($u,$t,$user, $perm); |
1414 |
unset($tr[$u]); |
1415 |
} |
1416 |
} |
1417 |
// then apply use policy |
1418 |
if (isset($tr[$user])) { |
1419 |
$perm = unroll_perm($user,$tr[$user],$user, $perm); |
1420 |
unset($tr[$user]); |
1421 |
} |
1422 |
|
1423 |
} |
1424 |
|
1425 |
} |
1426 |
#print "<br>user: $user path: $path perm: "; |
1427 |
#print "d: $perm[deny] (".display_trustee($perm[deny]).") a: $perm[allow] (".display_trustee($perm[allow]).")<Br>\n"; |
1428 |
return $perm; |
1429 |
} |
1430 |
|
1431 |
// handy functions |
1432 |
|
1433 |
function check_perm($path,$trperm) { |
1434 |
global $gblLogin,$HAVE_TRUSTEE; |
1435 |
print "<br>check_perm: <tt>$path</tt> test perm ".display_trustee($perm)."<br>\n"; |
1436 |
$return = ! $HAVE_TRUSTEE; |
1437 |
if ($HAVE_TRUSTEE) { |
1438 |
$perm = check_trustee($gblLogin,$path); |
1439 |
print " d: $perm[deny] (".display_trustee($perm[deny]).") a: $perm[allow] (".display_trustee($perm[allow]).") perm: $trperm"; |
1440 |
if ($perm[deny] & $trperm) $return=0; |
1441 |
elseif ($perm[allow] & $trperm) $return=1; |
1442 |
} |
1443 |
print " return: $return<br>\n"; |
1444 |
return($return); |
1445 |
} |
1446 |
|
1447 |
////////////////////////////////////////////////////////////////// |
1448 |
|
1449 |
function readMime() { |
1450 |
global $mime_type; |
1451 |
|
1452 |
if (! isset($gblMimeTypes)) { |
1453 |
$gblMimeTypes = "/etc/mime.types"; |
1454 |
} |
1455 |
|
1456 |
$mime = @fopen($gblMimeTypes,"r"); |
1457 |
|
1458 |
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>"); |
1459 |
|
1460 |
while($line = fgets($mime,80)) { |
1461 |
if (substr($line,0,1) == "#") continue; // skip comment |
1462 |
$arr = preg_split("/[\s\t]+/",$line); |
1463 |
$type = array_shift($arr); |
1464 |
while ($ext = array_shift($arr)) { |
1465 |
$mime_type[$ext] = $type; |
1466 |
} |
1467 |
} |
1468 |
|
1469 |
fclose($mime); |
1470 |
} |
1471 |
|
1472 |
////////////////////////////////////////////////////////////////// |
1473 |
// MAIN PROGRAM |
1474 |
|
1475 |
$gblFilePerms = 0640 ; // default for new files |
1476 |
$gblDirPerms = 0750 ; // default for new dirs |
1477 |
|
1478 |
if (isset($STYLE) && $STYLE == "get") { |
1479 |
include("$html/docman.css"); |
1480 |
exit; |
1481 |
} |
1482 |
|
1483 |
// location of master docman configuration file |
1484 |
$docman_conf = "/etc/docman.conf"; |
1485 |
if (! file_exists($docman_conf)) { |
1486 |
$error = "Can't find master configuration file $docman_conf. See docman2/doc/upgrade.html#docman_conf for more informations"; |
1487 |
|
1488 |
error_log("docman: $error"); |
1489 |
Error("docman not installed completly",$error); |
1490 |
} |
1491 |
include($docman_conf); |
1492 |
|
1493 |
if (! isset($fsRealmDir)) { |
1494 |
$fsRealmDir = "$gblIncDir/realm"; |
1495 |
} |
1496 |
$realm_config = "$fsRealmDir/$realm.conf"; |
1497 |
|
1498 |
// read user-defined configuration |
1499 |
if (file_exists($realm_config)) { |
1500 |
include($realm_config); |
1501 |
} else { |
1502 |
Error("Configuration error","Can't find configuration file at <tt>$realm_config</tt> !"); |
1503 |
} |
1504 |
|
1505 |
if (! isset($gblRepositoryDir)) Error("Configuration error","<tt>\$gblRepositoryDir</tt> is not setuped in realm configuration file <tt>$realm_config</tt>"); |
1506 |
|
1507 |
// where do we get users from? |
1508 |
if (file_exists("$gblIncDir/htusers/$gblUsers.php")) { |
1509 |
include("$gblIncDir/htusers/$gblUsers.php"); |
1510 |
} else { |
1511 |
Error("Configuration error","Can't find user handling module at <tt>$gblIncDir/htusers/$gblUsers.php</tt> ! Please fix <tt>$realm_config</tt>"); |
1512 |
} |
1513 |
|
1514 |
// if no password, or empty password logout |
1515 |
if ( |
1516 |
isset($gblLogin) && ( |
1517 |
!isset($relogin) || ( |
1518 |
isset($relogin) && $relogin != md5($gblLogin.$gblPasswd) |
1519 |
) |
1520 |
) && ( |
1521 |
$gblPasswd == "" || !isset($gblPasswd) |
1522 |
) && !isset($force_login) && $gblLogin != "anonymous" |
1523 |
) { |
1524 |
StartHTML("Logout completed","Your login credentials has been erased") ; |
1525 |
EndHTML() ; |
1526 |
exit ; |
1527 |
} |
1528 |
|
1529 |
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); |
1530 |
|
1531 |
// trustee (ACL) file configuration |
1532 |
$trustee_conf="$gblIncDir/realm/$realm.trustee"; |
1533 |
// compiled version of trustee file |
1534 |
$trustee_php="$gblRepositoryDir/.trustee.php"; |
1535 |
// get ACL informations |
1536 |
$HAVE_TRUSTEE = init_trustee(); |
1537 |
|
1538 |
if (strtolower($gblLogin) == "anonymous" || !isset($gblPasswd)) { |
1539 |
$perm = check_trustee($gblLogin,$path); |
1540 |
// browsing must be explicitly allowed for root directory |
1541 |
// of repository for anonymous user to work! |
1542 |
if ($perm[allow] & trperm_b) { |
1543 |
$secHash = md5($gblLogin.$gblPasswd); |
1544 |
$gblUserName = "Anonymous user"; |
1545 |
} |
1546 |
} |
1547 |
|
1548 |
// authentication failure |
1549 |
if ( md5($gblLogin.$gblPasswd) != $secHash || |
1550 |
isset($relogin) && $secHash == $relogin) { |
1551 |
header("WWW-authenticate: basic realm=\"$realm\"") ; |
1552 |
header("HTTP/1.0 401 Unauthorized") ; |
1553 |
Error("401 Unauthorized","No trespassing !"); |
1554 |
} |
1555 |
|
1556 |
// read mime.types |
1557 |
readMime(); |
1558 |
|
1559 |
// get current directory relative to $gblFsRoot |
1560 |
$relDir = $DIR ; // from POST |
1561 |
if ($relDir == "") { // not defined in POST ? |
1562 |
$relDir = urldecode($D) ; // then use GET |
1563 |
} |
1564 |
|
1565 |
$relDir=stripSlashes($relDir); |
1566 |
|
1567 |
if ($relDir == "/") $relDir = "" ; |
1568 |
// default : website root = "" |
1569 |
|
1570 |
if (strstr($relDir,"..")) Error("No updirs allowed"); |
1571 |
|
1572 |
// full paths contain "fs" or "Fs". Paths realitve to root of |
1573 |
// website contain "rel" or "Rel". The script won't let you |
1574 |
// edit anything above directory equal to http://server.com |
1575 |
// i.e. below $gblFsRoot. |
1576 |
|
1577 |
$relScriptDir = dirname($SCRIPT_NAME) ; |
1578 |
// i.e. /docman |
1579 |
|
1580 |
// start on server root |
1581 |
$gblFsRoot = $gblRepositoryDir; |
1582 |
// i.e. /home/httpd/html |
1583 |
|
1584 |
$fsDir = $gblFsRoot . $relDir ; // current directory |
1585 |
if ( !is_dir($fsDir) ) Error("Dir not found",$relDir) ; |
1586 |
|
1587 |
if (isset($HTTP_SERVER_VARS["HTTPS"]) && $HTTP_SERVER_VARS["HTTPS"] == "on") { |
1588 |
$webRoot = "https://"; |
1589 |
} else { |
1590 |
$webRoot = "http://"; |
1591 |
} |
1592 |
$webRoot .= $HTTP_SERVER_VARS["HTTP_HOST"] . $relScriptDir; |
1593 |
|
1594 |
// take variables from server |
1595 |
$FN=stripSlashes($HTTP_POST_VARS["FN"]); |
1596 |
$DIR=stripSlashes($HTTP_POST_VARS["DIR"]); |
1597 |
$RELPATH=stripSlashes($HTTP_POST_VARS["RELPATH"]); |
1598 |
$T=stripSlashes($HTTP_POST_VARS["T"]); |
1599 |
$CONFIRM=stripSlashes($HTTP_POST_VARS["CONFIRM"]); |
1600 |
|
1601 |
// get |
1602 |
$A=stripSlashes($HTTP_GET_VARS["A"]); |
1603 |
$D=stripSlashes($HTTP_GET_VARS["D"]); |
1604 |
|
1605 |
// if (isset($F)) Error("Document manager system error","variable $F shouldn't be set here (re-check old code)",1); |
1606 |
// $F=stripSlashes($HTTP_SERVER_VARS["PATH_INFO"]); |
1607 |
$F=stripSlashes($HTTP_GET_VARS["F"]); |
1608 |
|
1609 |
switch ($HTTP_POST_VARS["POSTACTION"]) { |
1610 |
case "UPLOAD" : |
1611 |
$FN_name=stripSlashes($HTTP_POST_FILES["FN"]["tmp_name"]); |
1612 |
$FN=stripSlashes($HTTP_POST_FILES["FN"]["name"]); |
1613 |
if (!is_writeable($fsDir)) Error("Write denied",$relDir) ; |
1614 |
|
1615 |
$source = $FN_name ; |
1616 |
if (! file_exists($source)) { |
1617 |
Error("You must select file with browse to upload it!"); |
1618 |
} |
1619 |
|
1620 |
$FILENAME = $HTTP_POST_VARS["FILENAME"]; |
1621 |
if (strstr($FILENAME,"/")) |
1622 |
Error("Upload error","Non-conforming filename. Filename <tt>$FILENAME</tt> has slashes (<tt>/</tt>) in it.") ; |
1623 |
if (! isset($FILENAME)) { // from update file |
1624 |
$target = "$fsDir/".basename($FN); |
1625 |
} else { |
1626 |
$target = "$fsDir/$FILENAME"; |
1627 |
} |
1628 |
|
1629 |
// backup old files first |
1630 |
$dir=dirname($target); |
1631 |
if (! file_exists($dir."/.bak")) { |
1632 |
mkdir($dir."/.bak",0700); |
1633 |
} |
1634 |
if (! file_exists($dir."/.bak/$GLOBALS[gblNumBackups]")) { |
1635 |
mkdir($dir."/.bak/$GLOBALS[gblNumBackups]",0700); |
1636 |
} |
1637 |
$file=basename($target); |
1638 |
for($i=$GLOBALS[gblNumBackups]-1;$i>0;$i--) { |
1639 |
MoveTo("$dir/.bak/$i/$file","$dir/.bak/".($i+1)."/"); |
1640 |
} |
1641 |
MoveTo($target,$dir."/.bak/1/"); |
1642 |
|
1643 |
copy($source,$target) ; |
1644 |
chmod($target,$gblFilePerms) ; |
1645 |
clearstatcache() ; |
1646 |
if (isset($FILENAME)) { |
1647 |
LogIt($target,"check-in",trperm_r | trperm_w); |
1648 |
Unlock($target); |
1649 |
} else { |
1650 |
LogIt($target,"uploaded",trperm_r | trperm_w); |
1651 |
} |
1652 |
break ; |
1653 |
|
1654 |
case "SAVE" : |
1655 |
$path = $gblFsRoot . $RELPATH ; |
1656 |
$path=stripSlashes($path); |
1657 |
$writable = is_writeable($path) ; |
1658 |
$legaldir = is_writeable(dirname($path)) ; |
1659 |
$exists = (file_exists($path)) ? 1 : 0 ; |
1660 |
// check for legal extension here as well |
1661 |
if (!($writable || (!$exists && $legaldir))) |
1662 |
Error("Write denied",$RELPATH) ; |
1663 |
$fh = fopen($path, "w") ; |
1664 |
$FILEDATA=stripSlashes($FILEDATA); |
1665 |
fwrite($fh,$FILEDATA) ; |
1666 |
fclose($fh) ; |
1667 |
clearstatcache() ; |
1668 |
LogIt($path,"saved changes",trperm_r); |
1669 |
break ; |
1670 |
|
1671 |
case "CREATE" : |
1672 |
// we know $fsDir exists |
1673 |
if ($FN == "") break; // no filename! |
1674 |
if (!is_writeable($fsDir)) Error("Write denied",$relDir) ; |
1675 |
$path = $fsDir . "/" . $FN ; // file or dir to create |
1676 |
$relPath = $relDir . "/" . $FN ; |
1677 |
switch ( $T ) { |
1678 |
case "D" : // create a directory |
1679 |
if ( ! @mkdir($path,$gblDirPerms) ) |
1680 |
Error("Mkdir failed",$relPath) ; // eg. if it exists |
1681 |
else |
1682 |
LogIt($path."/","dir created",trperm_w); |
1683 |
clearstatcache() ; |
1684 |
break ; |
1685 |
case "F" : // create a new file |
1686 |
// this functionality is doubled in DetailView(). |
1687 |
// better keep it here altogether |
1688 |
// chmod perms to $gblFilePerms |
1689 |
if ( file_exists($path) && !is_writeable($path) ) |
1690 |
Error("File not writable", $relPath) ; |
1691 |
$fh = fopen($path, "w+") ; |
1692 |
if ($fh) { |
1693 |
fputs($fh,"\n"); |
1694 |
fclose($fh) ; |
1695 |
LogIt($path,"file created",trperm_r | trperm_w); |
1696 |
} else { |
1697 |
Error("Creation of file $relPath failed -- $path"); |
1698 |
} |
1699 |
$tstr = "$PHP_SELF?A=E&D=".urlencode($relDir)."&F=".urlencode($FN) ; |
1700 |
header("Location: " . $tstr) ; |
1701 |
exit ; |
1702 |
} |
1703 |
break ; |
1704 |
|
1705 |
case "DELETE" : |
1706 |
if ( $CONFIRM != "on" ) break ; |
1707 |
|
1708 |
$tstr = "Attempt to delete non-existing object or " ; |
1709 |
$tstr .= "insufficient privileges: " ; |
1710 |
|
1711 |
if ( $FN != "") { // delete file |
1712 |
$path = $fsDir . "/" . $FN ; |
1713 |
|
1714 |
$dir=dirname($path); |
1715 |
$file=basename($path); |
1716 |
if (! file_exists("$dir/.del")) { |
1717 |
mkdir("$dir/.del",0700); |
1718 |
} |
1719 |
|
1720 |
// if ( ! @unlink($path) ) { |
1721 |
if ( ! rename($path,"$dir/.del/$file") ) { |
1722 |
LogIt($path,"file delete failed"); |
1723 |
Error("File delete failed", $tstr . $path) ; |
1724 |
} else { |
1725 |
LogIt($path,"file deleted",trperm_w); |
1726 |
MoveTo("$dir/.log/$file","$dir/.del/.log/"); |
1727 |
MoveTo("$dir/.note/$file","$dir/.del/.note/"); |
1728 |
MoveTo("$dir/.lock/$file","$dir/.del/.lock/"); |
1729 |
} |
1730 |
} else { // delete directory |
1731 |
if ( ! @rrmdir($fsDir) ) { |
1732 |
Error("Rmdir failed", $tstr . $fsDir) ; |
1733 |
} else { |
1734 |
LogIt($path,"dir deleted",trperm_w); |
1735 |
$relDir = dirname($relDir) ; // move up |
1736 |
} |
1737 |
} |
1738 |
break ; |
1739 |
|
1740 |
case "UNDELETE" : |
1741 |
if ( $CONFIRM != "on" ) break ; |
1742 |
|
1743 |
if (substr($FN,0,4) != ".del") break ; |
1744 |
$file=substr($FN,4,strlen($FN)-4); |
1745 |
|
1746 |
LogIt("$fsDir/.del/$file","undeleted",trperm_w); |
1747 |
MoveTo("$fsDir/.del/$file","$fsDir/"); |
1748 |
MoveTo("$fsDir/.del/.log/$file","$fsDir/.log/"); |
1749 |
MoveTo("$fsDir/.del/.note/$file","$fsDir/.note/"); |
1750 |
MoveTo("$fsDir/.del/.lock/$file","$fsDir/.lock/"); |
1751 |
|
1752 |
break ; |
1753 |
|
1754 |
case "RENAME" : |
1755 |
if ( $CONFIRM != "on" ) break ; |
1756 |
|
1757 |
$NEWNAME=stripSlashes($HTTP_POST_VARS["NEWNAME"]); |
1758 |
LogIt("$fsDir/$FN","renamed $FN to $NEWNAME",trperm_r); |
1759 |
safe_rename($fsDir,$FN,$NEWNAME); |
1760 |
break ; |
1761 |
|
1762 |
case "NOTE" : |
1763 |
$NOTE=stripSlashes($HTTP_POST_VARS["NOTE"]); |
1764 |
WriteNote("$fsDir/$FN","$NOTE"); |
1765 |
break ; |
1766 |
|
1767 |
case "UNLOCK" : |
1768 |
if ( $CONFIRM != "on" ) break ; |
1769 |
Unlock("$fsDir/$FN"); |
1770 |
break ; |
1771 |
|
1772 |
default : |
1773 |
// user hit "CANCEL" or undefined action |
1774 |
} |
1775 |
|
1776 |
// common to all POSTs : redirect to directory view ($relDir) |
1777 |
if ( $POSTACTION != "" ) { |
1778 |
$tstr = $PHP_SELF . "?D=" . urlencode($relDir) ; |
1779 |
header("Location: " . $tstr) ; |
1780 |
exit ; |
1781 |
} |
1782 |
|
1783 |
// check for mode.. navigate, code display, upload, or detail? |
1784 |
// $A=U : upload to path given in $D |
1785 |
// $A=E : display detail of file $D/$F and edit |
1786 |
// $A=C : display code in file $D/$F |
1787 |
// $A=Co : checkout file $D/$F |
1788 |
// $A=Ci : checkin file $D/$F |
1789 |
// $A=V : view file (do nothing except log) |
1790 |
// $A=I : include file .$F.php from $gblFsRoot |
1791 |
// default : display directory $D |
1792 |
|
1793 |
switch ($A) { |
1794 |
case "U" : |
1795 |
// upload to $relDir |
1796 |
if (!is_writeable($gblFsRoot . $relDir)) |
1797 |
Error("Write access denied",$relDir) ; |
1798 |
$text = "Use this page to upload a single " ; |
1799 |
$text .= "file to <B>$realm</B>." ; |
1800 |
StartHTML("(Upload Page)", $text) ; |
1801 |
UploadPage($gblFsRoot, $relDir) ; |
1802 |
EndHTML() ; |
1803 |
exit ; |
1804 |
case "E" : |
1805 |
// detail of $relDir/$F |
1806 |
if (is_file("$gblFsRoot/$relDir/$F") || is_dir("$gblFsRoot/$relDir/$F")) DetailPage($gblFsRoot, $relDir, $F) ; |
1807 |
exit ; |
1808 |
case "C" : |
1809 |
$F=stripSlashes($F); |
1810 |
// listing of $relDir/$F |
1811 |
DisplayCode($gblFsRoot, $relDir, $F) ; |
1812 |
exit ; |
1813 |
case "Co" : |
1814 |
// checkout |
1815 |
Lock("$gblFsRoot/$relDir/$F"); |
1816 |
Download("$gblFsRoot/$relDir/$F",1); |
1817 |
exit; |
1818 |
case "Ci" : |
1819 |
$F=stripSlashes($F); |
1820 |
// upload && update to $relDir |
1821 |
if (!is_writeable($gblFsRoot . $relDir)) |
1822 |
Error("Write access denied",$relDir) ; |
1823 |
$text = "Use this page to update a single " ; |
1824 |
$text .= "file to <B>$realm</B>." ; |
1825 |
StartHTML("(Update file Page)", $text) ; |
1826 |
UploadPage($gblFsRoot, $relDir, $F) ; |
1827 |
EndHTML() ; |
1828 |
exit ; |
1829 |
case "V" : |
1830 |
// view |
1831 |
LogIt("$gblFsRoot/$relDir/$F","viewed"); |
1832 |
Download("$gblFsRoot/$relDir/$F",$gblForceDownload); |
1833 |
exit; |
1834 |
case "Ch" : |
1835 |
StartHTML("(File changes)","All changes chronologicaly..."); |
1836 |
DisplayChangeLog(0); // all |
1837 |
EndHTML() ; |
1838 |
exit; |
1839 |
case "Ch1" : |
1840 |
StartHTML("(File changes)","Changes to files in last day..."); |
1841 |
DisplayChangeLog(1); |
1842 |
EndHTML() ; |
1843 |
exit; |
1844 |
case "I" : |
1845 |
$F=stripSlashes($F); |
1846 |
$inc_file="${gblFsRoot}/.${F}.php"; |
1847 |
if (!isset($F) || $F == "" || !file_exists($inc_file)) Error("Fatal error $inc_file"); // can't find file to include |
1848 |
if (!is_readable($inc_file)) |
1849 |
Error("Read access to include file denied",".${F}.php"); |
1850 |
$text = "Your include file should define \$text variable which holds this text and \$title variable which is page title"; |
1851 |
$title = "You should define \$title variable with page title"; |
1852 |
include($inc_file); |
1853 |
StartHTML($title, $text) ; |
1854 |
print "<p>".GifIcon(up)." Back to <a href=$HTTP_SERVER_VARS[PHP_SELF]>front page</a>.</p>"; |
1855 |
EndHTML() ; |
1856 |
exit ; |
1857 |
} |
1858 |
|
1859 |
// default: display directory $relDir |
1860 |
Navigate($gblFsRoot,$relDir) ; |
1861 |
exit ; |
1862 |
|
1863 |
Error("Whooah!","By cartesian logic, this never happens",1) ; |
1864 |
?> |