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