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