20 |
////////////////////////////////////////////////////////////////// |
////////////////////////////////////////////////////////////////// |
21 |
// CONFIGURATION OPTIONS |
// CONFIGURATION OPTIONS |
22 |
|
|
23 |
// error_reporting(4) ; // how verbose ? |
error_reporting(E_ALL) ; // how verbose ? |
24 |
|
|
25 |
// from where to include auth_*.php modules? |
// from where to include auth_*.php modules? |
26 |
$gblIncDir = "/data/docman2"; |
$gblIncDir = "/data/docman2"; |
27 |
|
|
28 |
// force download (so it won't open in associated application) |
// force download on view (so it won't open in associated application) |
29 |
$gblForceDownload = 1; |
$gblForceDownload = 0; |
30 |
|
|
31 |
// date format |
// date format |
32 |
$gblDateFmt="Y-m-d"; |
$gblDateFmt="Y-m-d"; |
84 |
LoadLanguage($HTTP_SERVER_VARS["HTTP_ACCEPT_LANGUAGE"]); |
LoadLanguage($HTTP_SERVER_VARS["HTTP_ACCEPT_LANGUAGE"]); |
85 |
|
|
86 |
// for security and configuration |
// for security and configuration |
87 |
$realm=$HTTP_SERVER_VARS[HTTP_HOST]; |
$realm=$HTTP_SERVER_VARS["HTTP_HOST"]; |
88 |
|
|
89 |
$fsDocumentRoot = dirname($HTTP_SERVER_VARS[SCRIPT_FILENAME]); |
$fsDocumentRoot = dirname($HTTP_SERVER_VARS[SCRIPT_FILENAME]); |
90 |
if ($fsDocumentRoot == "") Error("Configuration error","Can't get SCRIPT_FILENAME from your web server. Please set <tt>\$fsDocumentRoot</tt> in <tt>\$</tt>",1); |
if ($fsDocumentRoot == "") Error("Configuration error","Can't get SCRIPT_FILENAME from your web server. Please set <tt>\$fsDocumentRoot</tt> in <tt>\$</tt>",1); |
118 |
if (file_exists("$fsDocumentRoot/docman.css")) { |
if (file_exists("$fsDocumentRoot/docman.css")) { |
119 |
$css=dirname($self)."/docman.css"; |
$css=dirname($self)."/docman.css"; |
120 |
} else { |
} else { |
121 |
$css=$self."?STYLE=get&css=$css"; |
$css=$self."?STYLE=get"; |
122 |
} |
} |
123 |
|
|
124 |
include("$html/head.html"); |
include("$html/head.html"); |
138 |
} else { |
} else { |
139 |
$url .= md5($gblLogin.$gblPasswd); |
$url .= md5($gblLogin.$gblPasswd); |
140 |
} |
} |
141 |
if (isset($gblLogin) && $gblLogin != "" && ($gblPasswd == "" || !isset($gblPasswd))) { |
if ( ( (isset($gblLogin) && $gblLogin != "") || |
142 |
|
(!isset($gblLogin) || $gblLogin == "") |
143 |
|
) && ($gblPasswd == "" || !isset($gblPasswd))) { |
144 |
$url_title="login"; |
$url_title="login"; |
145 |
$url .= "&force_login=1"; |
$url .= "&force_login=1"; |
146 |
} else { |
} else { |
147 |
$url_title="relogin"; |
$url_title="relogin"; |
148 |
} |
} |
149 |
include("$html/footer.html"); |
include("$html/footer.html"); |
150 |
//phpinfo(); |
|
151 |
|
global $debug; |
152 |
|
if ($debug) print $debug; |
153 |
} // end function EndHTML |
} // end function EndHTML |
154 |
|
|
155 |
////////////////////////////////////////////////////////////////// |
////////////////////////////////////////////////////////////////// |
165 |
|
|
166 |
$exists = file_exists($fsPath) ; |
$exists = file_exists($fsPath) ; |
167 |
$ext = strtolower(strrchr($relPath,".")) ; |
$ext = strtolower(strrchr($relPath,".")) ; |
168 |
$editable = ( $ext=="" || strstr(join(" ",$gblEditable),$ext)) ; |
$editable = ( $ext=="" || strstr(join(" ",$gblEditable),$ext)) && |
169 |
$writable = is_writeable($fsPath) ; |
check_perm($relPath,trperm_w); |
170 |
|
$writable = is_writeable($fsPath) && check_perm($relPath,trperm_w) ; |
171 |
|
$writable_dir = is_writeable($fsDir) && check_perm($relDir,trperm_w) ; |
172 |
$file_lock = CheckLock($fsPath); |
$file_lock = CheckLock($fsPath); |
173 |
|
|
174 |
if (!$editable && !$exists) |
if (!$editable && !$exists) |
175 |
Error("Creation unsupported for type",$relPath) ; |
Error("Creation denied","Can't create <tt>$relPath</tt>") ; |
176 |
if (!exists && !is_writeable($fsDir) ) |
if (!$exists && !$writable_dir ) |
177 |
Error("Creation denied",$relDir) ; |
Error("Creation denied","Can't write in directory <tt>$relDir</tt> while creating <tt>$relPath</tt>for which user has permissions.",1); |
178 |
|
|
179 |
$text = _("Use this page to view, modify or ") ; |
$text = _("Use this page to view, modify or ") ; |
180 |
if (is_dir($fsPath)) { |
if (is_dir($fsPath)) { |
207 |
$fstr = htmlentities( $fstr ) ; |
$fstr = htmlentities( $fstr ) ; |
208 |
?> |
?> |
209 |
|
|
210 |
<FORM ACTION="<?= $self ; ?>" METHOD="POST"> |
<FORM ACTION="<?= $self ?>" METHOD="POST"> |
211 |
<SPAN TITLE="Click [SAVE] to store updated contents."> |
<SPAN TITLE="Click [SAVE] to store updated contents."> |
212 |
<B>DOCUMENT CONTENTS</B> |
<B>DOCUMENT CONTENTS</B> |
213 |
</SPAN><BR> |
</SPAN><BR> |
578 |
function Navigate($fsRoot,$relDir) { |
function Navigate($fsRoot,$relDir) { |
579 |
|
|
580 |
global $gblEditable, $gblIcon, $gblModDays, $webRoot, $gblHide, |
global $gblEditable, $gblIcon, $gblModDays, $webRoot, $gblHide, |
581 |
$gblIgnoreUnknownFileType, |
$gblIgnoreUnknownFileType, $gblRepositoryDir, |
582 |
|
$fsRealmDir, $realm, $realm_sep, |
583 |
$HTTP_GET_VARS, $html, $realm_config; |
$HTTP_GET_VARS, $html, $realm_config; |
584 |
|
|
585 |
$self = $HTTP_SERVER_VARS["PHP_SELF"] ; |
$self = $HTTP_SERVER_VARS["PHP_SELF"] ; |
586 |
|
|
587 |
if ($relDir == "") $relDir = "/"; |
$relDir = chopsl($relDir)."/"; |
588 |
|
$fsDir = $fsRoot.$relDir; // current directory |
589 |
|
|
590 |
|
if (!is_dir($fsDir)) Error("Dir not found","Directory <tt>$relDir<tt> not found on filesystem at <tt>$fsDir</tt>",1) ; |
591 |
|
|
592 |
$fsDir = $fsRoot.$relDir."/"; // current directory |
global $debug; |
593 |
|
$debug .= "[$gblLogin|$relDir] before >"; |
594 |
|
|
595 |
if (!is_dir($fsDir)) Error("Dir not found",$relDir) ; |
if (! check_perm($relDir,(trperm_b | trperm_r))) |
596 |
|
Error("Access denied","User <tt>$gblLogin</tt> tried to access <tt>$relDir</tt> without valid trustee.",1); |
597 |
|
$debug .= "< afeter"; |
598 |
|
|
599 |
$hide_items=",$gblHide,"; |
$hide_items=",$gblHide,"; |
600 |
|
|
647 |
echo "<TABLE BORDER=0 CELLPADDING=2 |
echo "<TABLE BORDER=0 CELLPADDING=2 |
648 |
CELLSPACING=3 WIDTH=\"100%\">" ; |
CELLSPACING=3 WIDTH=\"100%\">" ; |
649 |
|
|
650 |
// updir bar |
// updir (parent) bar |
651 |
if (chopsl($fsDir) != chopsl($fsRoot)) { |
if (chopsl($fsDir) != chopsl($fsRoot)) { |
652 |
$parent = dirname($relDir) ; |
$parent = dirname($relDir) ; |
653 |
if ($parent == "") $parent = "/" ; |
if ($parent == "") $parent = "/" ; |
727 |
$dir = $dirList[$key]; |
$dir = $dirList[$key]; |
728 |
|
|
729 |
$info_url=self_args(array("A"=>"A=E", "F"=>"F=".urlencode($dir), "D"=>$D)); |
$info_url=self_args(array("A"=>"A=E", "F"=>"F=".urlencode($dir), "D"=>$D)); |
730 |
$dir_url=$self."?D=".urlencode($relDir."/".$dir); |
$dir_url=$self."?D=".urlencode(chopsl($relDir)."/".$dir); |
731 |
include("$html/Navigate-dirEntry.html"); |
include("$html/Navigate-dirEntry.html"); |
732 |
|
|
733 |
} // iterate over dirs |
} // iterate over dirs |
873 |
<TR><TD></TD><TD COLSPAN=5><HR></TD></TR> |
<TR><TD></TD><TD COLSPAN=5><HR></TD></TR> |
874 |
|
|
875 |
<? |
<? |
876 |
if (file_exists(".info.inc")) { |
|
877 |
|
if (file_exists("$fsRealmDir/$realm".$realm_sep."info.inc")) { |
878 |
print "<TR><TD></TD><TD COLSPAN=5>"; |
print "<TR><TD></TD><TD COLSPAN=5>"; |
879 |
include(".info.inc"); |
include("$fsRealmDir/$realm".$realm_sep."info.inc"); |
880 |
print "</TD></TR> |
print "</TD></TR><TR><TD></TD><TD COLSPAN=5><HR></TD></TR>"; |
881 |
<TR><TD></TD><TD COLSPAN=5><HR></TD></TR>"; |
} elseif (file_exists("$gblRepositoryDir/.info.inc")) { |
882 |
|
print "<TR><TD></TD><TD COLSPAN=5>"; |
883 |
|
include("$gblRepositoryDir/.info.inc"); |
884 |
|
print "</TD></TR><TR><TD></TD><TD COLSPAN=5><HR></TD></TR>"; |
885 |
} |
} |
886 |
|
|
887 |
|
|
888 |
?> |
?> |
889 |
|
|
890 |
<FORM METHOD="POST" ACTION="<?= $self ?>"> |
<FORM METHOD="POST" ACTION="<?= $self ?>"> |
912 |
global $html, $HTTP_SERVER_VARS; |
global $html, $HTTP_SERVER_VARS; |
913 |
|
|
914 |
$self = $HTTP_SERVER_VARS["PHP_SELF"] ; |
$self = $HTTP_SERVER_VARS["PHP_SELF"] ; |
|
if ($relDir == "") $relDir = "/" ; |
|
|
|
|
915 |
include("$html/UploadPage.html"); |
include("$html/UploadPage.html"); |
916 |
|
|
917 |
} // end function UploadPage |
} // end function UploadPage |
921 |
// Error with sysadmin flag are reported to error_log or hidden from |
// Error with sysadmin flag are reported to error_log or hidden from |
922 |
// users |
// users |
923 |
|
|
924 |
function Error($title,$text="",$sysadmin=0) { |
function Error($title,$text="",$sysadmin=0,$no_404=0) { |
925 |
global $gblSeparateAdminMessages, |
global $gblSeparateAdminMessages, |
926 |
$gblMailAdminMessages,$realm, |
$gblMailAdminMessages,$realm, |
927 |
$HTTP_SERVER_VARS; |
$HTTP_SERVER_VARS; |
928 |
if (! headers_sent()) header("HTTP/1.0 404 Not Found"); |
if (! headers_sent() && ! $no_404) header("HTTP/1.0 404 Not Found"); |
929 |
if ($sysadmin) { |
if ($sysadmin) { |
930 |
if ($gblSeparateAdminMessages) { |
if ($gblSeparateAdminMessages) { |
931 |
$user="Your administrator "; |
$user="Your administrator "; |
1094 |
function try_rename($from,$to) { |
function try_rename($from,$to) { |
1095 |
# print "$from -> $to\n"; |
# print "$from -> $to\n"; |
1096 |
if (file_exists($from) && is_writeable(dirname($to))) { |
if (file_exists($from) && is_writeable(dirname($to))) { |
1097 |
rename($from,$to); |
return rename($from,$to); |
1098 |
|
} else { |
1099 |
|
return 0; |
1100 |
} |
} |
1101 |
} |
} |
1102 |
|
|
1103 |
function try_dir($todir) { |
function try_dir($todir) { |
1104 |
if (! file_exists($todir)) { |
if (! file_exists($todir)) { |
1105 |
mkdir($todir,0700); |
@mkdir($todir,0700); |
1106 |
} |
} |
1107 |
} |
} |
1108 |
|
|
1112 |
|
|
1113 |
# print "<pre>$fromdir / $fromfile -> $todir / $tofile\n\n"; |
# print "<pre>$fromdir / $fromfile -> $todir / $tofile\n\n"; |
1114 |
|
|
1115 |
try_rename("$fromdir/$fromfile","$todir/$tofile"); |
if (! try_rename("$fromdir/$fromfile","$todir/$tofile")) Error("Rename error","Can't rename file <tt>$fromfile</tt> to <tt>$tofile</tt>",1); |
1116 |
try_dir("$todir/.log"); |
try_dir("$todir/.log"); |
1117 |
try_rename("$fromdir/.log/$fromfile","$todir/.log/$tofile"); |
try_rename("$fromdir/.log/$fromfile","$todir/.log/$tofile"); |
1118 |
try_dir("$todir/.note"); |
try_dir("$todir/.note"); |
1223 |
////////////////////////////////////////////////////////////////// |
////////////////////////////////////////////////////////////////// |
1224 |
|
|
1225 |
function chopsl($path) { |
function chopsl($path) { |
|
if (substr($path,strlen($path)-1,1) == "/") $path=substr($path,0,strlen($path)-1); |
|
1226 |
$path=str_replace("//","/",$path); |
$path=str_replace("//","/",$path); |
1227 |
|
if (substr($path,strlen($path)-1,1) == "/") $path=substr($path,0,strlen($path)-1); |
1228 |
return $path; |
return $path; |
1229 |
} |
} |
1230 |
|
|
1381 |
}//init_trustee |
}//init_trustee |
1382 |
|
|
1383 |
function in_group($user,$group) { |
function in_group($user,$group) { |
1384 |
return in_array($groups[$group],$user); |
global $groups; |
1385 |
|
return in_array($user,$groups[$group]); |
1386 |
} |
} |
1387 |
|
|
1388 |
// helper function |
// helper function |
1389 |
function unroll_perm($u,$t,$user,$perm) { |
function unroll_perm($u,$t,$user,$perm) { |
1390 |
// check user |
|
1391 |
|
// check user FIX |
1392 |
if ($t & trmask_not && ($u==$user)) continue; |
if ($t & trmask_not && ($u==$user)) continue; |
1393 |
if (!($t & trmask_not) && ($u!=$user)) continue; |
if (!($t & trmask_not) && ($u!=$user)) continue; |
1394 |
|
|
1410 |
global $trustees; |
global $trustees; |
1411 |
$perm[allow] = 0; |
$perm[allow] = 0; |
1412 |
$perm[deny] = 0; |
$perm[deny] = 0; |
1413 |
|
|
1414 |
|
global $debug; |
1415 |
|
$debug .= "<br>check_trustee $path ... "; |
1416 |
|
|
1417 |
$path_arr=explode("/",$path); |
$path_arr=explode("/",$path); |
1418 |
$path = "/"; |
$tmppath = "/"; |
1419 |
while (count($path_arr)) { |
while (count($path_arr)) { |
1420 |
if (substr($path,strlen($path)-1,1) != "/") $path.="/"; |
$tmppath.=array_shift($path_arr); |
1421 |
$path.=array_shift($path_arr); |
$debug.= ">> $tmppath "; |
1422 |
$tr = $trustees[$path]; |
if (substr($tmppath,strlen($tmppath)-1,1) != "/") $tmppath.="/"; |
1423 |
|
$tr = $trustees[$tmppath]; |
1424 |
|
|
1425 |
|
# clear one level flag |
1426 |
|
$perm[allow] &= ~trperm_one_level; |
1427 |
|
$perm[deny] &= ~trperm_one_level; |
1428 |
|
|
1429 |
if (isset($tr)) { |
if (isset($tr)) { |
1430 |
// first apply trustee for all |
// first apply trustee for all |
1433 |
unset($tr['*']); |
unset($tr['*']); |
1434 |
} |
} |
1435 |
// then apply group policies |
// then apply group policies |
1436 |
foreach ($tr as $u=>$t) { |
foreach ($tr as $g=>$t) { |
1437 |
if ($t & trmask_group && in_group($user,$u)) { |
if ($t & trmask_group && in_group($user,$g)) { |
1438 |
// resolv user |
// resolv user |
1439 |
$t = $t & ~trmask_group; |
$t = $t & ~trmask_group; |
1440 |
$u = $user; |
$perm = unroll_perm($user,$t,$user, $perm); |
1441 |
$perm = unroll_perm($u,$t,$user, $perm); |
unset($tr[$g]); |
|
unset($tr[$u]); |
|
1442 |
} |
} |
1443 |
} |
} |
1444 |
// then apply use policy |
// then apply user policy |
1445 |
if (isset($tr[$user])) { |
if (isset($tr[$user])) { |
1446 |
$perm = unroll_perm($user,$tr[$user],$user, $perm); |
$perm = unroll_perm($user,$tr[$user],$user, $perm); |
1447 |
unset($tr[$user]); |
unset($tr[$user]); |
1448 |
} |
} |
|
|
|
1449 |
} |
} |
1450 |
|
$debug.="d:".display_trustee($perm[deny])." a:".display_trustee($perm[allow])." "; |
1451 |
|
|
1452 |
} |
} |
1453 |
#print "<br>user: $user path: $path perm: "; |
$debug.="<br>check_trustee: user: $user path: $path==$tmppath perm: "; |
1454 |
#print "d: $perm[deny] (".display_trustee($perm[deny]).") a: $perm[allow] (".display_trustee($perm[allow]).")<Br>\n"; |
$debug.="d: $perm[deny] (".display_trustee($perm[deny]).") a: $perm[allow] (".display_trustee($perm[allow]).")<Br>\n"; |
1455 |
return $perm; |
return $perm; |
1456 |
} |
} |
1457 |
|
|
1459 |
|
|
1460 |
function check_perm($path,$trperm) { |
function check_perm($path,$trperm) { |
1461 |
global $gblLogin,$HAVE_TRUSTEE; |
global $gblLogin,$HAVE_TRUSTEE; |
1462 |
print "<br>check_perm: <tt>$path</tt> test perm ".display_trustee($perm)."<br>\n"; |
|
1463 |
|
global $debug; |
1464 |
|
$debug.="<br>check_perm: <tt>$path</tt> test perm ".display_trustee($perm)."<br>\n"; |
1465 |
|
|
1466 |
$return = ! $HAVE_TRUSTEE; |
$return = ! $HAVE_TRUSTEE; |
1467 |
if ($HAVE_TRUSTEE) { |
if ($HAVE_TRUSTEE) { |
1468 |
$perm = check_trustee($gblLogin,$path); |
$perm = check_trustee($gblLogin,$path); |
1469 |
print " d: $perm[deny] (".display_trustee($perm[deny]).") a: $perm[allow] (".display_trustee($perm[allow]).") perm: $trperm"; |
$debug.=" d: $perm[deny] (".display_trustee($perm[deny]).") a: $perm[allow] (".display_trustee($perm[allow]).") perm to have: $trperm (".display_trustee($trperm).")"; |
1470 |
if ($perm[deny] & $trperm) $return=0; |
if ($perm[deny] & $trperm) $return=0; |
1471 |
elseif ($perm[allow] & $trperm) $return=1; |
elseif (($perm[allow] & $trperm) == $trperm) $return=1; |
1472 |
} |
} |
1473 |
print " return: $return<br>\n"; |
$debug.=" return: $return<br>\n"; |
1474 |
return($return); |
return($return); |
1475 |
} |
} |
1476 |
|
|
1500 |
} |
} |
1501 |
|
|
1502 |
////////////////////////////////////////////////////////////////// |
////////////////////////////////////////////////////////////////// |
1503 |
|
|
1504 |
|
// check for invalid characters in filename and dirname (.. and /) |
1505 |
|
|
1506 |
|
function check_dirname($file) { |
1507 |
|
if (strstr($file,"..")) Error("Security violation","No parent dir <tt>..</tt> allowed in directory name <tt>$file</tt>",1); |
1508 |
|
} |
1509 |
|
|
1510 |
|
function check_filename($file) { |
1511 |
|
if (strstr($file,"..")) Error("Security violation","No parent dir <tt>..</tt> allowed in file name <tt>$file</tt>",1); |
1512 |
|
if (strstr($file,"/")) Error("Security violation","No slashes <tt>/</tt> allowed in file name <tt>$file</tt>",1); |
1513 |
|
} |
1514 |
|
|
1515 |
|
////////////////////////////////////////////////////////////////// |
1516 |
// MAIN PROGRAM |
// MAIN PROGRAM |
1517 |
|
|
1518 |
$gblFilePerms = 0640 ; // default for new files |
$gblFilePerms = 0640 ; // default for new files |
1519 |
$gblDirPerms = 0750 ; // default for new dirs |
$gblDirPerms = 0750 ; // default for new dirs |
1520 |
|
|
1521 |
|
$STYLE = $HTTP_GET_VARS[STYLE]; |
1522 |
if (isset($STYLE) && $STYLE == "get") { |
if (isset($STYLE) && $STYLE == "get") { |
1523 |
include("$html/docman.css"); |
include("$html/docman.css"); |
1524 |
exit; |
exit; |
1537 |
if (! isset($fsRealmDir)) { |
if (! isset($fsRealmDir)) { |
1538 |
$fsRealmDir = "$gblIncDir/realm"; |
$fsRealmDir = "$gblIncDir/realm"; |
1539 |
} |
} |
1540 |
$realm_config = "$fsRealmDir/$realm.conf"; |
|
1541 |
|
// try to add dir to script name to realm var |
1542 |
|
if (is_dir("$fsRealmDir/$realm/".dirname($HTTP_SERVER_VARS[SCRIPT_NAME]))) { |
1543 |
|
$realm .= dirname($HTTP_SERVER_VARS[SCRIPT_NAME]); |
1544 |
|
$realm_sep = "/"; |
1545 |
|
} else { |
1546 |
|
$realm_sep = "."; |
1547 |
|
} |
1548 |
|
|
1549 |
|
$realm_config = $fsRealmDir."/".$realm.$realm_sep."conf"; |
1550 |
|
|
1551 |
// read user-defined configuration |
// read user-defined configuration |
1552 |
if (file_exists($realm_config)) { |
if (file_exists($realm_config)) { |
1564 |
Error("Configuration error","Can't find user handling module at <tt>$gblIncDir/htusers/$gblUsers.php</tt> ! Please fix <tt>$realm_config</tt>"); |
Error("Configuration error","Can't find user handling module at <tt>$gblIncDir/htusers/$gblUsers.php</tt> ! Please fix <tt>$realm_config</tt>"); |
1565 |
} |
} |
1566 |
|
|
1567 |
|
// take additional login vars |
1568 |
|
$relogin = $HTTP_GET_VARS[relogin]; |
1569 |
|
$force_login = $HTTP_GET_VARS[force_login]; |
1570 |
|
|
1571 |
// if no password, or empty password logout |
// if no password, or empty password logout |
1572 |
if ( |
if ( |
1573 |
isset($gblLogin) && ( |
isset($gblLogin) && ( |
1586 |
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); |
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); |
1587 |
|
|
1588 |
// trustee (ACL) file configuration |
// trustee (ACL) file configuration |
1589 |
$trustee_conf="$gblIncDir/realm/$realm.trustee"; |
$trustee_conf="$fsRealmDir/$realm".$realm_sep."trustee"; |
1590 |
// compiled version of trustee file |
// compiled version of trustee file |
1591 |
$trustee_php="$gblRepositoryDir/.trustee.php"; |
$trustee_php="$gblRepositoryDir/.trustee.php"; |
1592 |
// get ACL informations |
// get ACL informations |
1593 |
$HAVE_TRUSTEE = init_trustee(); |
$HAVE_TRUSTEE = init_trustee(); |
1594 |
|
|
1595 |
if (strtolower($gblLogin) == "anonymous" || !isset($gblPasswd)) { |
if (strtolower($gblLogin) == "anonymous" || !isset($gblLogin)) { |
1596 |
$perm = check_trustee($gblLogin,$path); |
$perm = check_trustee("anonymous",$path); |
1597 |
// browsing must be explicitly allowed for root directory |
// browsing must be explicitly allowed for root directory |
1598 |
// of repository for anonymous user to work! |
// of repository for anonymous user to work! |
1599 |
if ($perm[allow] & trperm_b) { |
if ($perm[allow] & trperm_b) { |
1600 |
|
$gblLogin = $gblPasswd = "anonymous"; |
1601 |
$secHash = md5($gblLogin.$gblPasswd); |
$secHash = md5($gblLogin.$gblPasswd); |
1602 |
$gblUserName = "Anonymous user"; |
$gblUserName = "Anonymous user"; |
1603 |
} |
} |
1608 |
isset($relogin) && $secHash == $relogin) { |
isset($relogin) && $secHash == $relogin) { |
1609 |
header("WWW-authenticate: basic realm=\"$realm\"") ; |
header("WWW-authenticate: basic realm=\"$realm\"") ; |
1610 |
header("HTTP/1.0 401 Unauthorized") ; |
header("HTTP/1.0 401 Unauthorized") ; |
1611 |
phpinfo(); |
Error("401 Unauthorized","No trespassing !",0,1); |
|
Error("401 Unauthorized","No trespassing !"); |
|
1612 |
} |
} |
1613 |
|
|
1614 |
|
|
1615 |
// read mime.types |
// read mime.types |
1616 |
readMime(); |
readMime(); |
1617 |
|
|
1618 |
// get current directory relative to $gblFsRoot |
if ($HTTP_SERVER_VARS["REQUEST_METHOD"] == "POST") { |
1619 |
$relDir = $DIR ; // from POST |
// take variables from server |
1620 |
if ($relDir == "") { // not defined in POST ? |
$FN=stripSlashes($HTTP_POST_VARS["FN"]); |
1621 |
$relDir = urldecode($D) ; // then use GET |
$DIR=stripSlashes($HTTP_POST_VARS["DIR"]); |
1622 |
} |
$RELPATH=stripSlashes($HTTP_POST_VARS["RELPATH"]); |
1623 |
|
$T=stripSlashes($HTTP_POST_VARS["T"]); |
1624 |
$relDir=stripSlashes($relDir); |
$CONFIRM=stripSlashes($HTTP_POST_VARS["CONFIRM"]); |
1625 |
|
|
1626 |
if ($relDir == "/") $relDir = "" ; |
check_filename($FN); |
1627 |
// default : website root = "" |
check_dirname($DIR); |
1628 |
|
check_dirname($RELPATH); |
1629 |
if (strstr($relDir,"..")) Error("No updirs allowed"); |
|
1630 |
|
$relDir = $DIR; |
1631 |
// full paths contain "fs" or "Fs". Paths realitve to root of |
} else { |
1632 |
// website contain "rel" or "Rel". The script won't let you |
// get |
1633 |
// edit anything above directory equal to http://server.com |
$A=stripSlashes($HTTP_GET_VARS["A"]); |
1634 |
// i.e. below $gblFsRoot. |
$D=stripSlashes(urldecode($HTTP_GET_VARS["D"])); |
1635 |
|
$F=stripSlashes($HTTP_GET_VARS["F"]); |
1636 |
|
|
1637 |
|
check_filename($F); |
1638 |
|
check_dirname($D); |
1639 |
|
|
1640 |
|
$relDir = $D; |
1641 |
|
} |
1642 |
|
|
1643 |
$relScriptDir = dirname($SCRIPT_NAME) ; |
$relScriptDir = dirname($SCRIPT_NAME) ; |
1644 |
// i.e. /docman |
// i.e. /docman |
1645 |
|
|
1646 |
// start on server root |
// start on server root |
1647 |
$gblFsRoot = $gblRepositoryDir; |
$gblFsRoot = $gblRepositoryDir; |
1648 |
// i.e. /home/httpd/html |
// i.e. /home/httpd/repository |
1649 |
|
|
1650 |
$fsDir = $gblFsRoot . $relDir ; // current directory |
$fsDir = $gblFsRoot . $relDir ; // current directory |
1651 |
if ( !is_dir($fsDir) ) Error("Dir not found",$relDir) ; |
if ( !is_dir($fsDir) ) Error("Dir not found","Can't find <tt>$relDir</tt> which points to <tt>$fsDir</tt>",1) ; |
1652 |
|
|
1653 |
|
if ($relDir == "") $relDir="/"; |
1654 |
|
|
1655 |
if (isset($HTTP_SERVER_VARS["HTTPS"]) && $HTTP_SERVER_VARS["HTTPS"] == "on") { |
if (isset($HTTP_SERVER_VARS["HTTPS"]) && $HTTP_SERVER_VARS["HTTPS"] == "on") { |
1656 |
$webRoot = "https://"; |
$webRoot = "https://"; |
1659 |
} |
} |
1660 |
$webRoot .= $HTTP_SERVER_VARS["HTTP_HOST"] . $relScriptDir; |
$webRoot .= $HTTP_SERVER_VARS["HTTP_HOST"] . $relScriptDir; |
1661 |
|
|
|
// take variables from server |
|
|
$FN=stripSlashes($HTTP_POST_VARS["FN"]); |
|
|
$DIR=stripSlashes($HTTP_POST_VARS["DIR"]); |
|
|
$RELPATH=stripSlashes($HTTP_POST_VARS["RELPATH"]); |
|
|
$T=stripSlashes($HTTP_POST_VARS["T"]); |
|
|
|
|
|
// get |
|
|
$A=stripSlashes($HTTP_GET_VARS["A"]); |
|
|
$D=stripSlashes($HTTP_GET_VARS["D"]); |
|
|
|
|
|
// if (isset($F)) Error("Document manager system error","variable $F shouldn't be set here (re-check old code)",1); |
|
|
// $F=stripSlashes($HTTP_SERVER_VARS["PATH_INFO"]); |
|
|
$F=stripSlashes($HTTP_GET_VARS["F"]); |
|
|
|
|
1662 |
switch ($HTTP_POST_VARS["POSTACTION"]) { |
switch ($HTTP_POST_VARS["POSTACTION"]) { |
1663 |
case "UPLOAD" : |
case "UPLOAD" : |
1664 |
$FN_name=stripSlashes($HTTP_POST_FILES["FN"]["tmp_name"]); |
$FN_name=stripSlashes($HTTP_POST_FILES["FN"]["tmp_name"]); |
1665 |
|
$FN=stripSlashes($HTTP_POST_FILES["FN"]["name"]); |
1666 |
if (!is_writeable($fsDir)) Error("Write denied",$relDir) ; |
if (!is_writeable($fsDir)) Error("Write denied",$relDir) ; |
1667 |
if (strstr($FN_name,"/")) |
|
|
Error("Non-conforming filename") ; |
|
|
// TODO : should rather check for escapeshellcmds |
|
|
// but maybe RFC 18xx asserts safe filenames .... |
|
1668 |
$source = $FN_name ; |
$source = $FN_name ; |
|
print "-- $source -- $FN_name -- $HTTP_POST_FILES[FN] -- "; |
|
|
// phpinfo(); |
|
1669 |
if (! file_exists($source)) { |
if (! file_exists($source)) { |
1670 |
Error("You must select file with browse to upload it!"); |
Error("You must select file with browse to upload it!"); |
1671 |
} |
} |
1672 |
|
|
1673 |
$FILENAME = $HTTP_POST_VARS["FILENAME"]; |
$FILENAME = $HTTP_POST_VARS["FILENAME"]; |
1674 |
|
check_filename($FILENAME); |
1675 |
|
|
1676 |
if (! isset($FILENAME)) { // from update file |
if (! isset($FILENAME)) { // from update file |
1677 |
$target = "$fsDir/$FN_name" ; |
$target = "$fsDir/".basename($FN); |
1678 |
} else { |
} else { |
1679 |
$target = "$fsDir/$FILENAME"; |
$target = "$fsDir/$FILENAME"; |
1680 |
} |
} |
1807 |
case "RENAME" : |
case "RENAME" : |
1808 |
if ( $CONFIRM != "on" ) break ; |
if ( $CONFIRM != "on" ) break ; |
1809 |
|
|
1810 |
|
$NEWNAME=stripSlashes($HTTP_POST_VARS["NEWNAME"]); |
1811 |
LogIt("$fsDir/$FN","renamed $FN to $NEWNAME",trperm_r); |
LogIt("$fsDir/$FN","renamed $FN to $NEWNAME",trperm_r); |
1812 |
safe_rename($fsDir,$FN,$NEWNAME); |
safe_rename($fsDir,$FN,$NEWNAME); |
1813 |
break ; |
break ; |
1814 |
|
|
1815 |
case "NOTE" : |
case "NOTE" : |
1816 |
|
$NOTE=stripSlashes($HTTP_POST_VARS["NOTE"]); |
1817 |
WriteNote("$fsDir/$FN","$NOTE"); |
WriteNote("$fsDir/$FN","$NOTE"); |
1818 |
break ; |
break ; |
1819 |
|
|
1840 |
// $A=Co : checkout file $D/$F |
// $A=Co : checkout file $D/$F |
1841 |
// $A=Ci : checkin file $D/$F |
// $A=Ci : checkin file $D/$F |
1842 |
// $A=V : view file (do nothing except log) |
// $A=V : view file (do nothing except log) |
1843 |
// $A=I : include file .$F.php from $gblFsRoot |
// $A=I : include file .$F.php from [$gblIncDir|realm]/include_php |
1844 |
// default : display directory $D |
// default : display directory $D |
1845 |
|
|
1846 |
switch ($A) { |
switch ($A) { |
1847 |
case "U" : |
case "U" : |
1848 |
// upload to $relDir |
// upload to $relDir |
1849 |
|
if (! check_perm($relDir, trperm_w)) |
1850 |
|
Error("Write access denied","You don't have permission to write in <tt>$relDir</tt>"); |
1851 |
if (!is_writeable($gblFsRoot . $relDir)) |
if (!is_writeable($gblFsRoot . $relDir)) |
1852 |
Error("Write access denied",$relDir) ; |
Error("Write access denied","User <tt>$gblLogin</tt> has permission on <tt>$relDir</tt>, but directory is not writable",1); |
1853 |
$text = "Use this page to upload a single " ; |
$text = "Use this page to upload a single " ; |
1854 |
$text .= "file to <B>$realm</B>." ; |
$text .= "file to <B>$realm</B>." ; |
1855 |
StartHTML("(Upload Page)", $text) ; |
StartHTML("(Upload Page)", $text) ; |
1868 |
case "Co" : |
case "Co" : |
1869 |
// checkout |
// checkout |
1870 |
Lock("$gblFsRoot/$relDir/$F"); |
Lock("$gblFsRoot/$relDir/$F"); |
1871 |
Download("$gblFsRoot/$relDir/$F"); |
Download("$gblFsRoot/$relDir/$F",1); |
1872 |
exit; |
exit; |
1873 |
case "Ci" : |
case "Ci" : |
1874 |
$F=stripSlashes($F); |
$F=stripSlashes($F); |
1884 |
case "V" : |
case "V" : |
1885 |
// view |
// view |
1886 |
LogIt("$gblFsRoot/$relDir/$F","viewed"); |
LogIt("$gblFsRoot/$relDir/$F","viewed"); |
1887 |
if ($gblForceDownload) { |
Download("$gblFsRoot/$relDir/$F",$gblForceDownload); |
|
Download("$gblFsRoot/$relDir/$F"); |
|
|
} else { |
|
|
header("Content-Disposition: attachment; filename=$F" ); |
|
|
Header("Location: $webRoot".urlpath("$relDir/$F")); |
|
|
} |
|
1888 |
exit; |
exit; |
1889 |
case "Ch" : |
case "Ch" : |
1890 |
StartHTML("(File changes)","All changes chronologicaly..."); |
StartHTML("(File changes)","All changes chronologicaly..."); |
1897 |
EndHTML() ; |
EndHTML() ; |
1898 |
exit; |
exit; |
1899 |
case "I" : |
case "I" : |
1900 |
$F=stripSlashes($F); |
if (! isset($F) || $F == "") |
1901 |
$inc_file="${gblFsRoot}/.${F}.php"; |
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); |
1902 |
if (!isset($F) || $F == "" || !file_exists($inc_file)) Error("Fatal error $inc_file"); // can't find file to include |
$inc_file="$fsRealmDir/$realm".$realm_sep.$F.".php"; |
1903 |
|
if (! file_exists($inc_file)) { |
1904 |
|
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); |
1905 |
|
} |
1906 |
if (!is_readable($inc_file)) |
if (!is_readable($inc_file)) |
1907 |
Error("Read access to include file denied",".${F}.php"); |
Error("Read access to include file denied","Can't read PHP include file <tt>$inc_file</tt>. Fix permissions on it.",1); |
1908 |
$text = "Your include file should define \$text variable which holds this text and \$title variable which is page title"; |
$text = "Your include file should define \$text variable which holds this text and \$title variable which is page title"; |
1909 |
$title = "You should define \$title variable with page title"; |
$title = "You should define \$title variable with page title"; |
1910 |
include($inc_file); |
include($inc_file); |