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); |
91 |
|
|
92 |
// globals for later |
// globals for later |
93 |
$gblLogin = $HTTP_SERVER_VARS[PHP_AUTH_USER]; |
$gblLogin = HTTP_SERVER_VAR("PHP_AUTH_USER"); |
94 |
$gblPasswd = $HTTP_SERVER_VARS[PHP_AUTH_PW]; |
$gblPasswd = HTTP_SERVER_VAR("PHP_AUTH_PW"); |
95 |
|
|
96 |
////////////////////////////////////////////////////////////////// |
////////////////////////////////////////////////////////////////// |
97 |
|
|
109 |
|
|
110 |
function StartHTML($title,$text="") { |
function StartHTML($title,$text="") { |
111 |
|
|
112 |
global $html,$fsDocumentRoot,$HTTP_SERVER_VARS; |
global $html,$fsDocumentRoot,$gblTitle,$HTTP_SERVER_VARS; |
113 |
|
|
|
$title = $gblTitle." ".$title ; |
|
114 |
$host = $HTTP_SERVER_VARS["HTTP_HOST"] ; |
$host = $HTTP_SERVER_VARS["HTTP_HOST"] ; |
115 |
$self = $HTTP_SERVER_VARS["PHP_SELF"] ; |
$self = $HTTP_SERVER_VARS["PHP_SELF"] ; |
116 |
|
|
155 |
|
|
156 |
function DetailPage($fsRoot,$relDir,$fn) { |
function DetailPage($fsRoot,$relDir,$fn) { |
157 |
|
|
158 |
global $gblEditable, $gblImages, $webRoot, $html, $HTTP_SERVER_VARS ; |
global $gblEditable, $gblImages, |
159 |
|
$gblDateFmt, $gblTimeFmt, |
160 |
|
$webRoot, $html, |
161 |
|
$HTTP_SERVER_VARS ; |
162 |
$self = $HTTP_SERVER_VARS["PHP_SELF"] ; |
$self = $HTTP_SERVER_VARS["PHP_SELF"] ; |
163 |
|
|
164 |
$relPath = $relDir . "/" . $fn ; |
$relPath = $relDir . "/" . $fn ; |
191 |
echo "<H3>" . $relDir . "/" . $fn . "</H3>" ; |
echo "<H3>" . $relDir . "/" . $fn . "</H3>" ; |
192 |
if ($exists) { // get file info |
if ($exists) { // get file info |
193 |
$fsize = filesize($fsPath) ; |
$fsize = filesize($fsPath) ; |
194 |
$fmodified = date("$GLOBALS[gblDateFmt] $GLOBALS[gblTimeFmt]", filemtime($fsPath)) ; |
$fmodified = date("$gblDateFmt $gblTimeFmt", filemtime($fsPath)) ; |
195 |
$faccessed = date("$GLOBALS[gblDateFmt] $GLOBALS[gblTimeFmt]", fileatime($fsPath)) ; |
$faccessed = date("$gblDateFmt $gblTimeFmt", fileatime($fsPath)) ; |
196 |
$fuid=fileowner($fsPath); |
$fuid=fileowner($fsPath); |
197 |
$fgid=filegroup($fsPath); |
$fgid=filegroup($fsPath); |
198 |
$userinfo = posix_getpwuid($fuid); |
$userinfo = posix_getpwuid($fuid); |
581 |
|
|
582 |
global $gblEditable, $gblIcon, $gblModDays, $webRoot, $gblHide, |
global $gblEditable, $gblIcon, $gblModDays, $webRoot, $gblHide, |
583 |
$gblIgnoreUnknownFileType, $gblRepositoryDir, |
$gblIgnoreUnknownFileType, $gblRepositoryDir, |
584 |
|
$gblLogin, $gblUserName, $gblDateFmt, $gblTimeFmt, |
585 |
$fsRealmDir, $realm, $realm_sep, |
$fsRealmDir, $realm, $realm_sep, |
586 |
$HTTP_GET_VARS, $html, $realm_config; |
$html, $realm_config, |
587 |
|
$HTTP_GET_VARS, $HTTP_SERVER_VARS; |
588 |
|
|
589 |
$self = $HTTP_SERVER_VARS["PHP_SELF"] ; |
$self = $HTTP_SERVER_VARS["PHP_SELF"] ; |
590 |
|
|
596 |
global $debug; |
global $debug; |
597 |
$debug .= "[$gblLogin|$relDir] before >"; |
$debug .= "[$gblLogin|$relDir] before >"; |
598 |
|
|
599 |
if (! check_perm($relDir,(trperm_b | trperm_r))) |
if (! check_perm($relDir,trperm_b)) |
600 |
Error("Access denied","User <tt>$gblLogin</tt> tried to access <tt>$relDir</tt> without valid trustee.",1); |
Error("Access denied","User <tt>$gblLogin</tt> tried to access <tt>$relDir</tt> without valid trustee.",1); |
601 |
$debug .= "< afeter"; |
$debug .= "< afeter"; |
602 |
|
|
603 |
$hide_items=",$gblHide,"; |
$hide_items=",$gblHide,"; |
604 |
|
|
605 |
|
$dirList = array(); |
606 |
|
$fileList = array(); |
607 |
|
|
608 |
// read directory contents |
// read directory contents |
609 |
if ( !($dir = @opendir($fsDir)) ) |
if ( !($dir = @opendir($fsDir)) ) |
610 |
Error("Read Access denied",$relDir,1) ; |
Error("Read Access denied",$relDir,1) ; |
629 |
closedir($dir) ; |
closedir($dir) ; |
630 |
|
|
631 |
// scan deleted files |
// scan deleted files |
632 |
if ( $HTTP_GET_VARS["show_deleted"] == 1 && ($dir = @opendir("$fsDir/.del")) ) { |
if ( HTTP_GET_VAR("show_deleted") == 1 && ($dir = @opendir("$fsDir/.del")) ) { |
633 |
while ($item = readdir($dir)) { |
while ($item = readdir($dir)) { |
634 |
if ( substr($item,0,1) == "." || strstr($hide_items,",$item,") || !check_perm($relDir.$item,trperm_w) ) continue ; |
if ( substr($item,0,1) == "." || strstr($hide_items,",$item,") || !check_perm($relDir.$item,trperm_w) ) continue ; |
635 |
$fileList[$item] = ".del/$item" ; |
$fileList[$item] = ".del/$item" ; |
644 |
|
|
645 |
// start navigation page |
// start navigation page |
646 |
$text = "Use this page to add, delete"; |
$text = "Use this page to add, delete"; |
647 |
if (! isset($HTTP_GET_VARS[show_deleted])) { |
if (! isset($HTTP_GET_VARS["show_deleted"])) { |
648 |
$text .= ", <a href=$self?D=".urlencode($relDir)."&show_deleted=1>undelete</a>"; |
$text .= ", <a href=$self?D=".urlencode($relDir)."&show_deleted=1>undelete</a>"; |
649 |
} |
} |
650 |
$text .= " or revise files on this web site." ; |
$text .= " or revise files on this web site." ; |
670 |
return $out; |
return $out; |
671 |
} |
} |
672 |
|
|
673 |
$dsort = $HTTP_GET_VARS[dsort]; |
if (! HTTP_GET_VAR("dsort")) $dsort = "name"; // default directory sort |
|
if (! isset($dsort)) $dsort = "name"; // default directory sort |
|
674 |
|
|
675 |
$dsort_arr = array( |
$dsort_arr = array( |
676 |
"name" => array ("rname", "note"), |
"name" => array ("rname", "note"), |
679 |
"rnote" => array ("name", "note") |
"rnote" => array ("name", "note") |
680 |
); |
); |
681 |
|
|
682 |
$fsort = $HTTP_GET_VARS[fsort]; |
if (! HTTP_GET_VAR("fsort")) $fsort = "name"; // default directory sort |
|
if (! isset($fsort)) $fsort = "name"; // default directory sort |
|
683 |
|
|
684 |
$fsort_arr = array( |
$fsort_arr = array( |
685 |
"name" => array ("rname", "note", "date", "size"), |
"name" => array ("rname", "note", "date", "size"), |
695 |
$D="D=".urlencode($relDir); |
$D="D=".urlencode($relDir); |
696 |
|
|
697 |
function self_args($arr = array()) { |
function self_args($arr = array()) { |
698 |
|
global $self; |
699 |
$arg = implode("&",$arr); |
$arg = implode("&",$arr); |
700 |
if ($arg) { |
if ($arg) { |
701 |
return $self."?".$arg; |
return $self."?".$arg; |
819 |
$ext = strtolower(strrchr($file,".")) ; |
$ext = strtolower(strrchr($file,".")) ; |
820 |
|
|
821 |
if ($file_lock) { |
if ($file_lock) { |
822 |
if ($file_lock == $GLOBALS[gblUserName]) { |
if ($file_lock == $gblUserName) { |
823 |
$b.="<A HREF=\"$self?A=Ci&D=".urlencode($relDir)."&F=".urlencode($file); |
$b.="<A HREF=\"$self?A=Ci&D=".urlencode($relDir)."&F=".urlencode($file); |
824 |
$b.="\" TITLE=\"Checkin (update) file on server\">" ; |
$b.="\" TITLE=\"Checkin (update) file on server\">" ; |
825 |
$file_url_html=$b; |
$file_url_html=$b; |
847 |
} |
} |
848 |
} |
} |
849 |
|
|
850 |
$mod = date("$GLOBALS[gblDateFmt] $GLOBALS[gblTimeFmt]",$mod); |
$mod = date("$gblDateFmt $gblTimeFmt",$mod); |
851 |
|
|
852 |
include("$html/Navigate-fileEntry.html"); |
include("$html/Navigate-fileEntry.html"); |
853 |
|
|
959 |
|
|
960 |
function LogIt($target,$msg, $changelog=0) { |
function LogIt($target,$msg, $changelog=0) { |
961 |
|
|
962 |
|
global $gblDateFmt, $gblTimeFmt, $gblUserName, $gblFsRoot; |
963 |
|
|
964 |
$dir=dirname($target); |
$dir=dirname($target); |
965 |
if (! file_exists($dir."/.log")) { |
if (! file_exists($dir."/.log")) { |
966 |
if (! @mkdir($dir."/.log",0700)) Error("docman installation problem","can't create log directory <tt>$dir/.log</tt>",1); |
if (! @mkdir($dir."/.log",0700)) Error("docman installation problem","can't create log directory <tt>$dir/.log</tt>",1); |
968 |
$file=basename($target); |
$file=basename($target); |
969 |
|
|
970 |
$log=fopen("$dir/.log/$file","a+"); |
$log=fopen("$dir/.log/$file","a+"); |
971 |
fputs($log,date("$GLOBALS[gblDateFmt]\t$GLOBALS[gblTimeFmt]"). |
fputs($log,date("$gblDateFmt\t$gblTimeFmt"). |
972 |
"\t$GLOBALS[gblUserName]\t$msg\n"); |
"\t$gblUserName\t$msg\n"); |
973 |
fclose($log); |
fclose($log); |
974 |
|
|
975 |
if (! $changelog) return; |
if (! $changelog) return; |
976 |
|
|
|
global $gblFsRoot; |
|
977 |
$log=fopen("$gblFsRoot/.changelog","a+"); |
$log=fopen("$gblFsRoot/.changelog","a+"); |
978 |
if (substr($target,0,strlen($gblFsRoot)) == $gblFsRoot) |
if (substr($target,0,strlen($gblFsRoot)) == $gblFsRoot) |
979 |
$target=substr($target,strlen($gblFsRoot),strlen($target)-strlen($gblFsRoot)); |
$target=substr($target,strlen($gblFsRoot),strlen($target)-strlen($gblFsRoot)); |
980 |
$msg=str_replace("\t"," ",$msg); |
$msg=str_replace("\t"," ",$msg); |
981 |
fputs($log,time()."\t$target\t$GLOBALS[gblUserName]\t$msg\n"); |
fputs($log,time()."\t$target\t$gblUserName\t$msg\n"); |
982 |
fclose($log); |
fclose($log); |
983 |
|
|
984 |
// FIX: implement e-mail notification based on $changelog |
// FIX: implement e-mail notification based on $changelog |
1038 |
|
|
1039 |
function Lock($target) { |
function Lock($target) { |
1040 |
|
|
1041 |
|
global $gblUserName; |
1042 |
|
|
1043 |
$target=stripSlashes($target); |
$target=stripSlashes($target); |
1044 |
$dir=dirname($target); |
$dir=dirname($target); |
1045 |
if (! file_exists($dir."/.lock")) { |
if (! file_exists($dir."/.lock")) { |
1051 |
LogIt($target,"attempt to locked allready locked file!"); |
LogIt($target,"attempt to locked allready locked file!"); |
1052 |
} else { |
} else { |
1053 |
$lock=fopen("$dir/.lock/$file","w"); |
$lock=fopen("$dir/.lock/$file","w"); |
1054 |
fputs($lock,"$GLOBALS[gblUserName]\n"); |
fputs($lock,"$gblUserName\n"); |
1055 |
fclose($lock); |
fclose($lock); |
1056 |
|
|
1057 |
LogIt($target,"file locked"); |
LogIt($target,"file locked"); |
1100 |
////////////////////////////////////////////////////////////////// |
////////////////////////////////////////////////////////////////// |
1101 |
|
|
1102 |
function safe_rename($fromdir,$fromfile,$tofile) { |
function safe_rename($fromdir,$fromfile,$tofile) { |
1103 |
|
|
1104 |
|
global $gblNumBackups; |
1105 |
|
|
1106 |
function try_rename($from,$to) { |
function try_rename($from,$to) { |
1107 |
# print "$from -> $to\n"; |
# print "$from -> $to\n"; |
1108 |
if (file_exists($from) && is_writeable(dirname($to))) { |
if (file_exists($from) && is_writeable(dirname($to))) { |
1132 |
try_dir("$todir/.lock"); |
try_dir("$todir/.lock"); |
1133 |
try_rename("$fromdir/.lock/$fromfile","$todir/.lock/$tofile"); |
try_rename("$fromdir/.lock/$fromfile","$todir/.lock/$tofile"); |
1134 |
try_dir("$todir/.bak"); |
try_dir("$todir/.bak"); |
1135 |
for($i=0;$i<=$GLOBALS[gblNumBackups];$i++) { |
for($i=0;$i<=$gblNumBackups;$i++) { |
1136 |
try_rename("$fromdir/.bak/$i/$fromfile","$todir/.bak/$i/$tofile"); |
try_rename("$fromdir/.bak/$i/$fromfile","$todir/.bak/$i/$tofile"); |
1137 |
} |
} |
1138 |
} |
} |
1160 |
|
|
1161 |
function DisplayChangeLog($day) { |
function DisplayChangeLog($day) { |
1162 |
|
|
1163 |
global $gblFsRoot,$HTTP_SERVER_VARS; |
global $gblFsRoot, $gblDateFmt, $gblTimeFmt, |
1164 |
|
$HTTP_SERVER_VARS; |
1165 |
|
|
1166 |
|
$self = $HTTP_SERVER_VARS["PHP_SELF"]; |
1167 |
|
|
1168 |
if (!file_exists("$gblFsRoot/.changelog")) return; |
if (!file_exists("$gblFsRoot/.changelog")) return; |
1169 |
$log=fopen("$gblFsRoot/.changelog","r"); |
$log=fopen("$gblFsRoot/.changelog","r"); |
1182 |
print "<table border=0 width=100%>\n"; |
print "<table border=0 width=100%>\n"; |
1183 |
while ($e = array_shift($logarr)) { |
while ($e = array_shift($logarr)) { |
1184 |
$cl=$cl1; $cl1=$cl2; $cl2=$cl; |
$cl=$cl1; $cl1=$cl2; $cl2=$cl; |
1185 |
$date = date("$GLOBALS[gblDateFmt]", $e[0]); |
$date = date($gblDateFmt, $e[0]); |
1186 |
$time = date("$GLOBALS[gblTimeFmt]", $e[0]); |
$time = date($gblTimeFmt, $e[0]); |
1187 |
$dir = dirname($e[1]); |
$dir = dirname($e[1]); |
1188 |
$file = basename($e[1]); |
$file = basename($e[1]); |
1189 |
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"; |
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"; |
1190 |
} |
} |
1191 |
print "</table>"; |
print "</table>"; |
1192 |
print "<p>".GifIcon(up)." Back to <a href=$HTTP_SERVER_VARS[PHP_SELF]>front page</a>.</p>"; |
print "<p>".GifIcon("up")." Back to <a href=\"$self\">front page</a>.</p>"; |
1193 |
} |
} |
1194 |
|
|
1195 |
////////////////////////////////////////////////////////////////// |
////////////////////////////////////////////////////////////////// |
1253 |
by Vyacheslav Zavadsky <zavadsky@braysystems.com> |
by Vyacheslav Zavadsky <zavadsky@braysystems.com> |
1254 |
*/ |
*/ |
1255 |
|
|
1256 |
define(trmask_not,1 << 0); |
define('trmask_not',1 << 0); |
1257 |
define(trmask_clear,1 << 1); |
define('trmask_clear',1 << 1); |
1258 |
define(trmask_deny,1 << 2); |
define('trmask_deny',1 << 2); |
1259 |
define(trmask_one_level,1 << 3); |
define('trmask_one_level',1 << 3); |
1260 |
define(trmask_group,1 << 4); |
define('trmask_group',1 << 4); |
1261 |
|
|
1262 |
define(trperm_r,1 << 5); |
define('trperm_r',1 << 5); |
1263 |
define(trperm_w,1 << 6); |
define('trperm_w',1 << 6); |
1264 |
define(trperm_b,1 << 7); |
define('trperm_b',1 << 7); |
1265 |
define(trperm_n,1 << 8); |
define('trperm_n',1 << 8); |
1266 |
|
|
1267 |
$trustee_a2n = array( |
$trustee_a2n = array( |
1268 |
'!' => trmask_not, |
'!' => trmask_not, |
1310 |
$error="<tt>".dirname($trustee_php)."</tt> must be writable by web server user"; |
$error="<tt>".dirname($trustee_php)."</tt> must be writable by web server user"; |
1311 |
} elseif (file_exists($trustee_php) && !is_writable($trustee_php)) { |
} elseif (file_exists($trustee_php) && !is_writable($trustee_php)) { |
1312 |
$error="trustees cache file <tt>$trustee_php</tt> exists, but is not writable by web server"; |
$error="trustees cache file <tt>$trustee_php</tt> exists, but is not writable by web server"; |
1313 |
} elseif (1 || filemtime($trustee_conf) >= filemtime($trustee_php)) { |
} elseif (@filemtime($trustee_conf) >= @filemtime($trustee_php)) { |
1314 |
$fp_php=@fopen($trustee_php,"w"); |
$fp_php=@fopen($trustee_php,"w"); |
1315 |
fputs($fp_php,"<?php // don't edit by hand!\n"); |
fputs($fp_php,"<?php // don't edit by hand!\n"); |
1316 |
|
|
1346 |
$error.="trustee error in line '$l' [Unknown modifier '$ch']<br>\n"; |
$error.="trustee error in line '$l' [Unknown modifier '$ch']<br>\n"; |
1347 |
} |
} |
1348 |
} |
} |
1349 |
$tr_arr[$path][$user] |= $perm; |
if (isset($tr_arr[$path][$user])) { |
1350 |
|
$tr_arr[$path][$user] |= $perm; |
1351 |
|
} else { |
1352 |
|
$tr_arr[$path][$user] = $perm; |
1353 |
|
} |
1354 |
} |
} |
1355 |
} |
} |
1356 |
} |
} |
1389 |
fclose($fp_php); |
fclose($fp_php); |
1390 |
} |
} |
1391 |
|
|
1392 |
if ($error) { |
if (isset($error)) { |
1393 |
Error("Trustee error",$error,1); |
Error("Trustee error",$error,1); |
1394 |
} else { |
} else { |
1395 |
include("$trustee_php"); |
include_once("$trustee_php"); |
1396 |
} |
} |
1397 |
|
|
1398 |
return 1; |
return 1; |
1405 |
} |
} |
1406 |
|
|
1407 |
// helper function |
// helper function |
1408 |
function unroll_perm($u,$t,$user,$perm) { |
function unroll_perm($u,$t,$perm,$one_level) { |
1409 |
|
|
1410 |
// check user FIX |
if ($t & trmask_one_level && !$one_level) return $perm; |
|
if ($t & trmask_not && ($u==$user)) continue; |
|
|
if (!($t & trmask_not) && ($u!=$user)) continue; |
|
1411 |
|
|
1412 |
if ($t & trmask_deny) { |
if ($t & trmask_deny) { |
1413 |
if ($t & trmask_clear) { |
if ($t & trmask_clear) { |
1414 |
$perm[deny] &= ~$t; |
$perm['deny'] &= ~$t; |
1415 |
} else { |
} else { |
1416 |
$perm[deny] |= $t; |
$perm['deny'] |= $t; |
1417 |
} |
} |
1418 |
} elseif ($t & trmask_clear) { |
} elseif ($t & trmask_clear) { |
1419 |
$perm[allow] &= ~$t; |
$perm['allow'] &= ~$t; |
1420 |
} else { |
} else { |
1421 |
$perm[allow] |= $t; |
$perm['allow'] |= $t; |
1422 |
} |
} |
1423 |
return $perm; |
return $perm; |
1424 |
}// end of helper function |
}// end of helper function |
1425 |
|
|
1426 |
function check_trustee($user,$path) { |
function check_trustee($user,$path) { |
1427 |
global $trustees; |
global $trustees,$HAVE_TRUSTEE; |
1428 |
$perm[allow] = 0; |
$perm['allow'] = 0; |
1429 |
$perm[deny] = 0; |
$perm['deny'] = 0; |
1430 |
|
|
1431 |
|
// do we use trustees? |
1432 |
|
if (! $HAVE_TRUSTEE) return $perm; |
1433 |
|
|
1434 |
|
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); |
1435 |
|
|
1436 |
global $debug; |
global $debug; |
1437 |
$debug .= "<br>check_trustee $path ... "; |
$debug .= "<br>check_trustee $path ... "; |
1441 |
while (count($path_arr)) { |
while (count($path_arr)) { |
1442 |
$tmppath.=array_shift($path_arr); |
$tmppath.=array_shift($path_arr); |
1443 |
$debug.= ">> $tmppath "; |
$debug.= ">> $tmppath "; |
1444 |
if (substr($tmppath,strlen($tmppath)-1,1) != "/") $tmppath.="/"; |
|
1445 |
|
if (! isset($trustees[$tmppath])) continue; |
1446 |
$tr = $trustees[$tmppath]; |
$tr = $trustees[$tmppath]; |
1447 |
|
|
1448 |
# clear one level flag |
$one_level = (!count($path_arr)); |
1449 |
$perm[allow] &= ~trperm_one_level; |
$debug.=" O($one_level) "; |
|
$perm[deny] &= ~trperm_one_level; |
|
1450 |
|
|
1451 |
if (isset($tr)) { |
if (isset($tr)) { |
1452 |
// first apply trustee for all |
// first apply trustee for all |
1453 |
if (isset($tr['*'])) { |
if (isset($tr['*'])) { |
1454 |
$perm = unroll_perm($user,$tr['*'],$user, $perm); |
$perm = unroll_perm($user,$tr['*'],$perm, $one_level); |
1455 |
unset($tr['*']); |
unset($tr['*']); |
1456 |
} |
} |
1457 |
// then apply group policies |
// then apply not and group policies |
1458 |
foreach ($tr as $g=>$t) { |
foreach ($tr as $g=>$t) { |
1459 |
if ($t & trmask_group && in_group($user,$g)) { |
if ($t & trmask_not && $g != $user) { |
1460 |
|
$t = $t & ~trmask_not; |
1461 |
|
$perm = unroll_perm($user,$t,$perm, $one_level); |
1462 |
|
unset($tr[$g]); |
1463 |
|
|
1464 |
|
} elseif ($t & trmask_group && in_group($user,$g)) { |
1465 |
// resolv user |
// resolv user |
1466 |
$t = $t & ~trmask_group; |
$t = $t & ~trmask_group; |
1467 |
$perm = unroll_perm($user,$t,$user, $perm); |
$perm = unroll_perm($user,$t,$perm, $one_level); |
1468 |
unset($tr[$g]); |
unset($tr[$g]); |
1469 |
} |
} |
1470 |
} |
} |
1471 |
// then apply user policy |
// then apply user policy |
1472 |
if (isset($tr[$user])) { |
if (isset($tr[$user])) { |
1473 |
$perm = unroll_perm($user,$tr[$user],$user, $perm); |
$perm = unroll_perm($user,$tr[$user],$perm,$one_level); |
1474 |
unset($tr[$user]); |
unset($tr[$user]); |
1475 |
} |
} |
1476 |
} |
} |
1477 |
$debug.="d:".display_trustee($perm[deny])." a:".display_trustee($perm[allow])." "; |
$debug.="d(".display_trustee($perm['deny']).") a(".display_trustee($perm['allow']).") "; |
1478 |
|
|
1479 |
} |
} |
1480 |
$debug.="<br>check_trustee: user: $user path: $path==$tmppath perm: "; |
$debug.="<br>check_trustee: user: $user path: $path==$tmppath perm: "; |
1481 |
$debug.="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"; |
1482 |
return $perm; |
return $perm; |
1483 |
} |
} |
1484 |
|
|
1488 |
global $gblLogin,$HAVE_TRUSTEE; |
global $gblLogin,$HAVE_TRUSTEE; |
1489 |
|
|
1490 |
global $debug; |
global $debug; |
1491 |
$debug.="<br>check_perm: <tt>$path</tt> test perm ".display_trustee($perm)."<br>\n"; |
$debug.="<br>check_perm: on <tt>$path</tt> for perm ".display_trustee($trperm)."<br>\n"; |
1492 |
|
|
1493 |
$return = ! $HAVE_TRUSTEE; |
$return = ! $HAVE_TRUSTEE; |
1494 |
if ($HAVE_TRUSTEE) { |
if ($HAVE_TRUSTEE) { |
1495 |
$perm = check_trustee($gblLogin,$path); |
$perm = check_trustee($gblLogin,$path); |
1496 |
$debug.=" d: $perm[deny] (".display_trustee($perm[deny]).") a: $perm[allow] (".display_trustee($perm[allow]).") perm to have: $trperm (".display_trustee($trperm).")"; |
$debug.=" d: ".$perm['deny']." (".display_trustee($perm['deny']).") a: ".$perm['allow']." (".display_trustee($perm['allow']).") perm to have: $trperm (".display_trustee($trperm).")"; |
1497 |
if ($perm[deny] & $trperm) $return=0; |
if ($perm['deny'] & $trperm) $return=0; |
1498 |
elseif (($perm[allow] & $trperm) == $trperm) $return=1; |
elseif (($perm['allow'] & $trperm) == $trperm) $return=1; |
1499 |
} |
} |
1500 |
$debug.=" return: $return<br>\n"; |
$debug.=" return: $return<br>\n"; |
1501 |
return($return); |
return($return); |
1540 |
} |
} |
1541 |
|
|
1542 |
////////////////////////////////////////////////////////////////// |
////////////////////////////////////////////////////////////////// |
1543 |
|
|
1544 |
|
// functions to move HTTP server variables to global namespace |
1545 |
|
// [replacement for register_globals in php.ini] |
1546 |
|
|
1547 |
|
function HTTP_GET_VAR($var) { |
1548 |
|
global $HTTP_GET_VARS, ${$var}; |
1549 |
|
if (isset($HTTP_GET_VARS[$var])) { |
1550 |
|
$$var = stripSlashes($HTTP_GET_VARS[$var]); |
1551 |
|
return $$var; |
1552 |
|
} |
1553 |
|
} |
1554 |
|
|
1555 |
|
function HTTP_POST_VAR($var) { |
1556 |
|
global $HTTP_POST_VARS, ${$var}; |
1557 |
|
if (isset($HTTP_POST_VARS[$var])) { |
1558 |
|
$$var = $HTTP_POST_VARS[$var]; |
1559 |
|
return $$var; |
1560 |
|
} |
1561 |
|
} |
1562 |
|
|
1563 |
|
function HTTP_SERVER_VAR($var) { |
1564 |
|
global $HTTP_SERVER_VARS, ${$var}; |
1565 |
|
if (isset($HTTP_SERVER_VARS[$var])) { |
1566 |
|
$$var = $HTTP_SERVER_VARS[$var]; |
1567 |
|
return $$var; |
1568 |
|
} |
1569 |
|
} |
1570 |
|
|
1571 |
|
////////////////////////////////////////////////////////////////// |
1572 |
|
|
1573 |
|
function Warn($text) { |
1574 |
|
} |
1575 |
|
|
1576 |
|
////////////////////////////////////////////////////////////////// |
1577 |
// MAIN PROGRAM |
// MAIN PROGRAM |
1578 |
|
|
1579 |
$gblFilePerms = 0640 ; // default for new files |
$gblFilePerms = 0640 ; // default for new files |
1580 |
$gblDirPerms = 0750 ; // default for new dirs |
$gblDirPerms = 0750 ; // default for new dirs |
1581 |
|
|
1582 |
$STYLE = $HTTP_GET_VARS[STYLE]; |
if (isset($HTTP_GET_VARS["STYLE"]) && $HTTP_GET_VARS["STYLE"] == "get") { |
|
if (isset($STYLE) && $STYLE == "get") { |
|
1583 |
include("$html/docman.css"); |
include("$html/docman.css"); |
1584 |
exit; |
exit; |
1585 |
} |
} |
1587 |
// location of master docman configuration file |
// location of master docman configuration file |
1588 |
$docman_conf = "/etc/docman.conf"; |
$docman_conf = "/etc/docman.conf"; |
1589 |
if (! file_exists($docman_conf)) { |
if (! file_exists($docman_conf)) { |
1590 |
$error = "Can't find master configuration file $docman_conf. See docman2/doc/upgrade.html#docman_conf for more informations"; |
$error = "Can't find master configuration file <tt>$docman_conf</tt>. See <tt>docman2/doc/upgrade.html#docman_conf</tt> for more informations"; |
1591 |
|
|
1592 |
error_log("docman: $error"); |
error_log("docman: $error"); |
1593 |
Error("docman not installed completly",$error); |
Error("docman not installed completly",$error); |
1599 |
} |
} |
1600 |
|
|
1601 |
// try to add dir to script name to realm var |
// try to add dir to script name to realm var |
1602 |
if (is_dir("$fsRealmDir/$realm/".dirname($HTTP_SERVER_VARS[SCRIPT_NAME]))) { |
if (is_dir("$fsRealmDir/$realm/".dirname($HTTP_SERVER_VARS["SCRIPT_NAME"]))) { |
1603 |
$realm .= dirname($HTTP_SERVER_VARS[SCRIPT_NAME]); |
$realm .= dirname($HTTP_SERVER_VARS["SCRIPT_NAME"]); |
1604 |
$realm_sep = "/"; |
$realm_sep = "/"; |
1605 |
} else { |
} else { |
1606 |
$realm_sep = "."; |
$realm_sep = "."; |
1625 |
} |
} |
1626 |
|
|
1627 |
// take additional login vars |
// take additional login vars |
1628 |
$relogin = $HTTP_GET_VARS[relogin]; |
HTTP_GET_VAR("relogin"); |
1629 |
$force_login = $HTTP_GET_VARS[force_login]; |
HTTP_GET_VAR("force_login"); |
1630 |
|
|
1631 |
// if no password, or empty password logout |
// if no password, or empty password logout |
1632 |
if ( |
if ( |
1653 |
$HAVE_TRUSTEE = init_trustee(); |
$HAVE_TRUSTEE = init_trustee(); |
1654 |
|
|
1655 |
if (strtolower($gblLogin) == "anonymous" || !isset($gblLogin)) { |
if (strtolower($gblLogin) == "anonymous" || !isset($gblLogin)) { |
1656 |
$perm = check_trustee("anonymous",$path); |
$perm = check_trustee("anonymous","/"); |
1657 |
// browsing must be explicitly allowed for root directory |
// browsing must be explicitly allowed for root directory |
1658 |
// of repository for anonymous user to work! |
// of repository for anonymous user to work! |
1659 |
if ($perm[allow] & trperm_b) { |
if ($perm['allow'] & trperm_b) { |
1660 |
$gblLogin = $gblPasswd = "anonymous"; |
$gblLogin = $gblPasswd = "anonymous"; |
1661 |
$secHash = md5($gblLogin.$gblPasswd); |
$secHash = md5($gblLogin.$gblPasswd); |
1662 |
$gblUserName = "Anonymous user"; |
$gblUserName = "Anonymous user"; |
1675 |
// read mime.types |
// read mime.types |
1676 |
readMime(); |
readMime(); |
1677 |
|
|
1678 |
|
HTTP_POST_VAR("FN"); |
1679 |
|
|
1680 |
if ($HTTP_SERVER_VARS["REQUEST_METHOD"] == "POST") { |
if ($HTTP_SERVER_VARS["REQUEST_METHOD"] == "POST") { |
1681 |
// take variables from server |
// take variables from server |
1682 |
$FN=stripSlashes($HTTP_POST_VARS["FN"]); |
if (HTTP_POST_VAR("FN")) |
1683 |
$DIR=stripSlashes($HTTP_POST_VARS["DIR"]); |
check_filename($FN); |
1684 |
$RELPATH=stripSlashes($HTTP_POST_VARS["RELPATH"]); |
if (HTTP_POST_VAR("DIR")) { |
1685 |
$T=stripSlashes($HTTP_POST_VARS["T"]); |
check_dirname($DIR); |
1686 |
$CONFIRM=stripSlashes($HTTP_POST_VARS["CONFIRM"]); |
$relDir = $DIR; |
1687 |
|
} else { |
1688 |
check_filename($FN); |
trigger_error("Can't get DIR",E_USER_WARNING); |
1689 |
check_dirname($DIR); |
$relDir = "/"; |
1690 |
check_dirname($RELPATH); |
} |
1691 |
|
if (HTTP_POST_VAR("RELPATH")) check_dirname($RELPATH); |
1692 |
$relDir = $DIR; |
HTTP_POST_VAR("T"); |
1693 |
|
HTTP_POST_VAR("CONFIRM"); |
1694 |
} else { |
} else { |
1695 |
// get |
// get |
1696 |
$A=stripSlashes($HTTP_GET_VARS["A"]); |
HTTP_GET_VAR("A"); |
1697 |
$D=stripSlashes(urldecode($HTTP_GET_VARS["D"])); |
if (HTTP_GET_VAR("D")) { |
1698 |
$F=stripSlashes($HTTP_GET_VARS["F"]); |
check_dirname($D); |
1699 |
|
$D=urldecode($D); |
1700 |
check_filename($F); |
$relDir = $D; |
1701 |
check_dirname($D); |
} else { |
1702 |
|
//trigger_error("Can't get D",E_USER_WARNING); |
1703 |
$relDir = $D; |
$relDir = "/"; |
1704 |
|
} |
1705 |
|
if (HTTP_GET_VAR("F")) check_filename($F); |
1706 |
} |
} |
1707 |
|
|
1708 |
$relScriptDir = dirname($SCRIPT_NAME) ; |
$relScriptDir = dirname($HTTP_SERVER_VARS["SCRIPT_NAME"]) ; |
1709 |
// i.e. /docman |
// i.e. /docman |
1710 |
|
|
1711 |
// start on server root |
// start on server root |
1724 |
} |
} |
1725 |
$webRoot .= $HTTP_SERVER_VARS["HTTP_HOST"] . $relScriptDir; |
$webRoot .= $HTTP_SERVER_VARS["HTTP_HOST"] . $relScriptDir; |
1726 |
|
|
1727 |
switch ($HTTP_POST_VARS["POSTACTION"]) { |
if (HTTP_POST_VAR("POSTACTION")) switch ($POSTACTION) { |
1728 |
case "UPLOAD" : |
case "UPLOAD" : |
1729 |
$FN_name=stripSlashes($HTTP_POST_FILES["FN"]["tmp_name"]); |
$FN_name=stripSlashes($HTTP_POST_FILES["FN"]["tmp_name"]); |
1730 |
$FN=stripSlashes($HTTP_POST_FILES["FN"]["name"]); |
$FN=stripSlashes($HTTP_POST_FILES["FN"]["name"]); |
1735 |
Error("You must select file with browse to upload it!"); |
Error("You must select file with browse to upload it!"); |
1736 |
} |
} |
1737 |
|
|
1738 |
$FILENAME = $HTTP_POST_VARS["FILENAME"]; |
if (HTTP_POST_VAR("FILENAME")) check_filename($FILENAME); |
|
check_filename($FILENAME); |
|
1739 |
|
|
1740 |
if (! isset($FILENAME)) { // from update file |
if (! isset($FILENAME)) { // from update file |
1741 |
$target = "$fsDir/".basename($FN); |
$target = "$fsDir/".basename($FN); |
1748 |
if (! file_exists($dir."/.bak")) { |
if (! file_exists($dir."/.bak")) { |
1749 |
mkdir($dir."/.bak",0700); |
mkdir($dir."/.bak",0700); |
1750 |
} |
} |
1751 |
if (! file_exists($dir."/.bak/$GLOBALS[gblNumBackups]")) { |
if (! file_exists($dir."/.bak/$gblNumBackups")) { |
1752 |
mkdir($dir."/.bak/$GLOBALS[gblNumBackups]",0700); |
mkdir($dir."/.bak/$gblNumBackups",0700); |
1753 |
} |
} |
1754 |
$file=basename($target); |
$file=basename($target); |
1755 |
for($i=$GLOBALS[gblNumBackups]-1;$i>0;$i--) { |
for($i=$gblNumBackups-1;$i>0;$i--) { |
1756 |
MoveTo("$dir/.bak/$i/$file","$dir/.bak/".($i+1)."/"); |
MoveTo("$dir/.bak/$i/$file","$dir/.bak/".($i+1)."/"); |
1757 |
} |
} |
1758 |
MoveTo($target,$dir."/.bak/1/"); |
MoveTo($target,$dir."/.bak/1/"); |
1778 |
if (!($writable || (!$exists && $legaldir))) |
if (!($writable || (!$exists && $legaldir))) |
1779 |
Error("Write denied",$RELPATH) ; |
Error("Write denied",$RELPATH) ; |
1780 |
$fh = fopen($path, "w") ; |
$fh = fopen($path, "w") ; |
1781 |
$FILEDATA=stripSlashes($FILEDATA); |
HTTP_POST_VAR("FILEDATA"); |
1782 |
fwrite($fh,$FILEDATA) ; |
fwrite($fh,$FILEDATA) ; |
1783 |
fclose($fh) ; |
fclose($fh) ; |
1784 |
clearstatcache() ; |
clearstatcache() ; |
1787 |
|
|
1788 |
case "CREATE" : |
case "CREATE" : |
1789 |
// we know $fsDir exists |
// we know $fsDir exists |
1790 |
if ($FN == "") break; // no filename! |
if (! check_perm($relDir, trperm_w)) |
1791 |
|
Error("Write access denied","You don't have permission to write in <tt>$relDir</tt>"); |
1792 |
|
if ($T == "D") $type = "directory"; |
1793 |
|
else $type ="file"; |
1794 |
|
if ($FN == "") Error("Can't create $type","You must enter name of $type to create it."); |
1795 |
if (!is_writeable($fsDir)) Error("Write denied",$relDir) ; |
if (!is_writeable($fsDir)) Error("Write denied",$relDir) ; |
1796 |
$path = $fsDir . "/" . $FN ; // file or dir to create |
$path = $fsDir . "/" . $FN ; // file or dir to create |
1797 |
$relPath = $relDir . "/" . $FN ; |
$relPath = $relDir . "/" . $FN ; |
1817 |
} else { |
} else { |
1818 |
Error("Creation of file $relPath failed -- $path"); |
Error("Creation of file $relPath failed -- $path"); |
1819 |
} |
} |
1820 |
$tstr = "$PHP_SELF?A=E&D=".urlencode($relDir)."&F=".urlencode($FN) ; |
$tstr = $HTTP_SERVER_VARS["PHP_SELF"]."?A=E&D=".urlencode($relDir)."&F=".urlencode($FN) ; |
1821 |
header("Location: " . $tstr) ; |
header("Location: " . $tstr) ; |
1822 |
exit ; |
exit ; |
1823 |
} |
} |
1895 |
} |
} |
1896 |
|
|
1897 |
// common to all POSTs : redirect to directory view ($relDir) |
// common to all POSTs : redirect to directory view ($relDir) |
1898 |
if ( $POSTACTION != "" ) { |
if (isset($POSTACTION)) { |
1899 |
$tstr = $PHP_SELF . "?D=" . urlencode($relDir) ; |
$tstr = $HTTP_SERVER_VARS["PHP_SELF"]."?D=".urlencode($relDir); |
1900 |
header("Location: " . $tstr) ; |
header("Location: ".$tstr) ; |
1901 |
exit ; |
exit ; |
1902 |
} |
} |
1903 |
|
|
1911 |
// $A=I : include file .$F.php from [$gblIncDir|realm]/include_php |
// $A=I : include file .$F.php from [$gblIncDir|realm]/include_php |
1912 |
// default : display directory $D |
// default : display directory $D |
1913 |
|
|
1914 |
switch ($A) { |
if (isset($A)) switch ($A) { |
1915 |
case "U" : |
case "U" : |
1916 |
// upload to $relDir |
// upload to $relDir |
1917 |
if (! check_perm($relDir, trperm_w)) |
if (! check_perm($relDir, trperm_w)) |