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