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