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 |
|
|
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 ; |
188 |
$title = "("._("Detail Page").")" ; |
$title = "("._("Detail Page").")" ; |
189 |
StartHTML($title, $text) ; |
StartHTML($title, $text) ; |
190 |
|
|
191 |
echo "<H3>" . $relDir . "/" . $fn . "</H3>" ; |
print "<H3>".$relDir.$fn."</H3>"; |
192 |
|
|
193 |
if ($exists) { // get file info |
if ($exists) { // get file info |
194 |
$fsize = filesize($fsPath) ; |
$fsize = filesize($fsPath) ; |
195 |
$fmodified = date("$GLOBALS[gblDateFmt] $GLOBALS[gblTimeFmt]", filemtime($fsPath)) ; |
$fmodified = date("$gblDateFmt $gblTimeFmt", filemtime($fsPath)) ; |
196 |
$faccessed = date("$GLOBALS[gblDateFmt] $GLOBALS[gblTimeFmt]", fileatime($fsPath)) ; |
$faccessed = date("$gblDateFmt $gblTimeFmt", fileatime($fsPath)) ; |
197 |
$fuid=fileowner($fsPath); |
$fuid=fileowner($fsPath); |
198 |
$fgid=filegroup($fsPath); |
$fgid=filegroup($fsPath); |
199 |
$userinfo = posix_getpwuid($fuid); |
$userinfo = posix_getpwuid($fuid); |
582 |
|
|
583 |
global $gblEditable, $gblIcon, $gblModDays, $webRoot, $gblHide, |
global $gblEditable, $gblIcon, $gblModDays, $webRoot, $gblHide, |
584 |
$gblIgnoreUnknownFileType, $gblRepositoryDir, |
$gblIgnoreUnknownFileType, $gblRepositoryDir, |
585 |
$gblLogin, |
$gblLogin, $gblUserName, $gblDateFmt, $gblTimeFmt, |
586 |
$fsRealmDir, $realm, $realm_sep, |
$fsRealmDir, $realm, $realm_sep, |
587 |
$html, $realm_config, |
$html, $realm_config, |
588 |
$HTTP_GET_VARS, $HTTP_SERVER_VARS; |
$HTTP_GET_VARS, $HTTP_SERVER_VARS; |
633 |
if ( HTTP_GET_VAR("show_deleted") == 1 && ($dir = @opendir("$fsDir/.del")) ) { |
if ( HTTP_GET_VAR("show_deleted") == 1 && ($dir = @opendir("$fsDir/.del")) ) { |
634 |
while ($item = readdir($dir)) { |
while ($item = readdir($dir)) { |
635 |
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 ; |
636 |
$fileList[$item] = ".del/$item" ; |
if (is_file($fsDir.".del/$item")) { |
637 |
$fileDate[$item] = filemtime($fsDir.".del/$path") ; |
$fileList[$item] = ".del/$item" ; |
638 |
$fileSize[$item] = filesize($fsDir.".del/$path") ; |
$fileDate[$item] = filemtime($fsDir.".del/$item") ; |
639 |
$fileNote[$item] = ReadNote($fsDir.".del/$item"); |
$fileSize[$item] = filesize($fsDir.".del/$item") ; |
640 |
|
$fileNote[$item] = ReadNote($fsDir.".del/$item"); |
641 |
|
} else { |
642 |
|
$dirList[$item] = ".del/$item" ; |
643 |
|
$dirNote[$item] = ReadNote($fsDir.".del/$item"); |
644 |
|
} |
645 |
} |
} |
646 |
closedir($dir) ; |
closedir($dir) ; |
647 |
} |
} |
739 |
$dir = $dirList[$key]; |
$dir = $dirList[$key]; |
740 |
|
|
741 |
$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)); |
742 |
|
if (substr($dir,0,5) == ".del/") { |
743 |
|
$dir = substr($dir,5,strlen($dir)-5); |
744 |
|
$deleted = " <a href=\"$info_url#undelete\"><SPAN CLASS=deleted TITLE=\"deleted\">deleted</span></a>"; |
745 |
|
} else { |
746 |
|
$deleted = ""; |
747 |
|
} |
748 |
|
|
749 |
$dir_url=$self."?D=".urlencode(chopsl($relDir)."/".$dir); |
$dir_url=$self."?D=".urlencode(chopsl($relDir)."/".$dir); |
750 |
include("$html/Navigate-dirEntry.html"); |
include("$html/Navigate-dirEntry.html"); |
751 |
|
|
824 |
if (substr($file,0,5) != ".del/") { |
if (substr($file,0,5) != ".del/") { |
825 |
$file_url_html .= $file . "</A>" . $a ; |
$file_url_html .= $file . "</A>" . $a ; |
826 |
} else { |
} else { |
827 |
$file_url_html .= substr($file,5,strlen($file)-5) . "</a> <SPAN CLASS=RED TITLE=\"deleted\"> <a href=\"$info_url#undelete\">deleted</a> </span>"; |
$file_url_html .= substr($file,5,strlen($file)-5) . "</a> <a href=\"$info_url#undelete\"><SPAN CLASS=deleted TITLE=\"deleted\">deleted</span></a>"; |
828 |
} |
} |
829 |
|
|
830 |
$note_html="<a href=\"$info_url#note\">".$gblIcon("note")."</a>".ReadNote($path); |
$note_html="<a href=\"$info_url#note\">".$gblIcon("note")."</a>".ReadNote($path); |
832 |
$ext = strtolower(strrchr($file,".")) ; |
$ext = strtolower(strrchr($file,".")) ; |
833 |
|
|
834 |
if ($file_lock) { |
if ($file_lock) { |
835 |
if ($file_lock == $GLOBALS[gblUserName]) { |
if ($file_lock == $gblUserName) { |
836 |
$b.="<A HREF=\"$self?A=Ci&D=".urlencode($relDir)."&F=".urlencode($file); |
$b.="<A HREF=\"$self?A=Ci&D=".urlencode($relDir)."&F=".urlencode($file); |
837 |
$b.="\" TITLE=\"Checkin (update) file on server\">" ; |
$b.="\" TITLE=\"Checkin (update) file on server\">" ; |
838 |
$file_url_html=$b; |
$file_url_html=$b; |
860 |
} |
} |
861 |
} |
} |
862 |
|
|
863 |
$mod = date("$GLOBALS[gblDateFmt] $GLOBALS[gblTimeFmt]",$mod); |
$mod = date("$gblDateFmt $gblTimeFmt",$mod); |
864 |
|
|
865 |
include("$html/Navigate-fileEntry.html"); |
include("$html/Navigate-fileEntry.html"); |
866 |
|
|
972 |
|
|
973 |
function LogIt($target,$msg, $changelog=0) { |
function LogIt($target,$msg, $changelog=0) { |
974 |
|
|
975 |
|
global $gblDateFmt, $gblTimeFmt, $gblUserName, $gblFsRoot; |
976 |
|
|
977 |
$dir=dirname($target); |
$dir=dirname($target); |
978 |
if (! file_exists($dir."/.log")) { |
if (! file_exists($dir."/.log")) { |
979 |
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); |
981 |
$file=basename($target); |
$file=basename($target); |
982 |
|
|
983 |
$log=fopen("$dir/.log/$file","a+"); |
$log=fopen("$dir/.log/$file","a+"); |
984 |
fputs($log,date("$GLOBALS[gblDateFmt]\t$GLOBALS[gblTimeFmt]"). |
fputs($log,date("$gblDateFmt\t$gblTimeFmt"). |
985 |
"\t$GLOBALS[gblUserName]\t$msg\n"); |
"\t$gblUserName\t$msg\n"); |
986 |
fclose($log); |
fclose($log); |
987 |
|
|
988 |
if (! $changelog) return; |
if (! $changelog) return; |
989 |
|
|
|
global $gblFsRoot; |
|
990 |
$log=fopen("$gblFsRoot/.changelog","a+"); |
$log=fopen("$gblFsRoot/.changelog","a+"); |
991 |
if (substr($target,0,strlen($gblFsRoot)) == $gblFsRoot) |
if (substr($target,0,strlen($gblFsRoot)) == $gblFsRoot) |
992 |
$target=substr($target,strlen($gblFsRoot),strlen($target)-strlen($gblFsRoot)); |
$target=substr($target,strlen($gblFsRoot),strlen($target)-strlen($gblFsRoot)); |
993 |
$msg=str_replace("\t"," ",$msg); |
$msg=str_replace("\t"," ",$msg); |
994 |
fputs($log,time()."\t$target\t$GLOBALS[gblUserName]\t$msg\n"); |
fputs($log,time()."\t$target\t$gblUserName\t$msg\n"); |
995 |
fclose($log); |
fclose($log); |
996 |
|
|
997 |
// FIX: implement e-mail notification based on $changelog |
// FIX: implement e-mail notification based on $changelog |
1051 |
|
|
1052 |
function Lock($target) { |
function Lock($target) { |
1053 |
|
|
1054 |
|
global $gblUserName; |
1055 |
|
|
1056 |
$target=stripSlashes($target); |
$target=stripSlashes($target); |
1057 |
$dir=dirname($target); |
$dir=dirname($target); |
1058 |
if (! file_exists($dir."/.lock")) { |
if (! file_exists($dir."/.lock")) { |
1064 |
LogIt($target,"attempt to locked allready locked file!"); |
LogIt($target,"attempt to locked allready locked file!"); |
1065 |
} else { |
} else { |
1066 |
$lock=fopen("$dir/.lock/$file","w"); |
$lock=fopen("$dir/.lock/$file","w"); |
1067 |
fputs($lock,"$GLOBALS[gblUserName]\n"); |
fputs($lock,"$gblUserName\n"); |
1068 |
fclose($lock); |
fclose($lock); |
1069 |
|
|
1070 |
LogIt($target,"file locked"); |
LogIt($target,"file locked"); |
1113 |
////////////////////////////////////////////////////////////////// |
////////////////////////////////////////////////////////////////// |
1114 |
|
|
1115 |
function safe_rename($fromdir,$fromfile,$tofile) { |
function safe_rename($fromdir,$fromfile,$tofile) { |
1116 |
|
|
1117 |
|
global $gblNumBackups; |
1118 |
|
|
1119 |
function try_rename($from,$to) { |
function try_rename($from,$to) { |
1120 |
# print "$from -> $to\n"; |
# print "$from -> $to\n"; |
1121 |
if (file_exists($from) && is_writeable(dirname($to))) { |
if (file_exists($from) && is_writeable(dirname($to))) { |
1145 |
try_dir("$todir/.lock"); |
try_dir("$todir/.lock"); |
1146 |
try_rename("$fromdir/.lock/$fromfile","$todir/.lock/$tofile"); |
try_rename("$fromdir/.lock/$fromfile","$todir/.lock/$tofile"); |
1147 |
try_dir("$todir/.bak"); |
try_dir("$todir/.bak"); |
1148 |
for($i=0;$i<=$GLOBALS[gblNumBackups];$i++) { |
for($i=0;$i<=$gblNumBackups;$i++) { |
1149 |
try_rename("$fromdir/.bak/$i/$fromfile","$todir/.bak/$i/$tofile"); |
try_rename("$fromdir/.bak/$i/$fromfile","$todir/.bak/$i/$tofile"); |
1150 |
} |
} |
1151 |
} |
} |
1173 |
|
|
1174 |
function DisplayChangeLog($day) { |
function DisplayChangeLog($day) { |
1175 |
|
|
1176 |
global $gblFsRoot,$HTTP_SERVER_VARS; |
global $gblFsRoot, $gblDateFmt, $gblTimeFmt, |
1177 |
|
$HTTP_SERVER_VARS; |
1178 |
|
|
1179 |
|
$self = $HTTP_SERVER_VARS["PHP_SELF"]; |
1180 |
|
|
1181 |
if (!file_exists("$gblFsRoot/.changelog")) return; |
if (!file_exists("$gblFsRoot/.changelog")) return; |
1182 |
$log=fopen("$gblFsRoot/.changelog","r"); |
$log=fopen("$gblFsRoot/.changelog","r"); |
1195 |
print "<table border=0 width=100%>\n"; |
print "<table border=0 width=100%>\n"; |
1196 |
while ($e = array_shift($logarr)) { |
while ($e = array_shift($logarr)) { |
1197 |
$cl=$cl1; $cl1=$cl2; $cl2=$cl; |
$cl=$cl1; $cl1=$cl2; $cl2=$cl; |
1198 |
$date = date("$GLOBALS[gblDateFmt]", $e[0]); |
$date = date($gblDateFmt, $e[0]); |
1199 |
$time = date("$GLOBALS[gblTimeFmt]", $e[0]); |
$time = date($gblTimeFmt, $e[0]); |
1200 |
$dir = dirname($e[1]); |
$dir = dirname($e[1]); |
1201 |
$file = basename($e[1]); |
$file = basename($e[1]); |
1202 |
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"; |
1203 |
} |
} |
1204 |
print "</table>"; |
print "</table>"; |
1205 |
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>"; |
1206 |
} |
} |
1207 |
|
|
1208 |
////////////////////////////////////////////////////////////////// |
////////////////////////////////////////////////////////////////// |
1224 |
|
|
1225 |
$ext_arr = explode(".",$file); |
$ext_arr = explode(".",$file); |
1226 |
$ext = array_pop($ext_arr); |
$ext = array_pop($ext_arr); |
1227 |
if ($encoding_ext[$ext]) { |
if (isset($encoding_ext[$ext])) { |
1228 |
$encoding = $encoding_ext[$ext]; |
$encoding = $encoding_ext[$ext]; |
1229 |
$ext = array_pop($ext_arr); |
$ext = array_pop($ext_arr); |
1230 |
} |
} |
1236 |
} |
} |
1237 |
|
|
1238 |
// IE5.5 just downloads index.php if we don't do this |
// IE5.5 just downloads index.php if we don't do this |
1239 |
if(preg_match("/MSIE 5.5/", $HTTP_SERVER_VARS[HTTP_USER_AGENT])) { |
if(preg_match("/MSIE 5.5/", $HTTP_SERVER_VARS["HTTP_USER_AGENT"])) { |
1240 |
header("Content-Disposition: filename=$file"); |
header("Content-Disposition: filename=$file"); |
1241 |
} else { |
} else { |
1242 |
header("Content-Disposition: attachment; filename=$file"); |
header("Content-Disposition: attachment; filename=$file"); |
1418 |
} |
} |
1419 |
|
|
1420 |
// helper function |
// helper function |
1421 |
function unroll_perm($u,$t,$user,$perm,$one_level) { |
function unroll_perm($u,$t,$perm,$one_level) { |
1422 |
|
|
1423 |
if ($t & trmask_one_level && !$one_level) return $perm; |
if ($t & trmask_one_level && !$one_level) return $perm; |
1424 |
|
|
|
// user is user whose trustee is this |
|
|
if ($t & trmask_not && ($u==$user)) return $perm; |
|
|
if (!($t & trmask_not) && ($u!=$user)) return $perm; |
|
|
|
|
1425 |
if ($t & trmask_deny) { |
if ($t & trmask_deny) { |
1426 |
if ($t & trmask_clear) { |
if ($t & trmask_clear) { |
1427 |
$perm['deny'] &= ~$t; |
$perm['deny'] &= ~$t; |
1437 |
}// end of helper function |
}// end of helper function |
1438 |
|
|
1439 |
function check_trustee($user,$path) { |
function check_trustee($user,$path) { |
1440 |
global $trustees; |
global $trustees,$HAVE_TRUSTEE; |
1441 |
$perm['allow'] = 0; |
$perm['allow'] = 0; |
1442 |
$perm['deny'] = 0; |
$perm['deny'] = 0; |
1443 |
|
|
1444 |
if (! isset($trustees)) Error("Trustees not found","Can't find in-memory trustee structure \$trustees. Probably bug in code. Contact <tt>dpavlin@rot13.org</tt>",1); |
// do we use trustees? |
1445 |
|
if (! $HAVE_TRUSTEE) return $perm; |
1446 |
|
|
1447 |
|
if (! isset($trustees)) Error("Trustees not found","Can't find in-memory trustee structure <tt>\$trustees</tt>. Probably bug in code. Contact <tt>dpavlin@rot13.org</tt>",1); |
1448 |
|
|
1449 |
global $debug; |
global $debug; |
1450 |
$debug .= "<br>check_trustee $path ... "; |
$debug .= "<br>check_trustee $path ... "; |
1463 |
|
|
1464 |
if (isset($tr)) { |
if (isset($tr)) { |
1465 |
// first apply trustee for all |
// first apply trustee for all |
1466 |
if (isset($tr['*'])) { |
if (isset($tr['*']) && $user!="anonymous") { |
1467 |
$perm = unroll_perm($user,$tr['*'],'*', $perm, $one_level); |
$perm = unroll_perm($user,$tr['*'],$perm, $one_level); |
1468 |
unset($tr['*']); |
unset($tr['*']); |
1469 |
} |
} |
1470 |
// then apply group policies |
// then apply not and group policies |
1471 |
foreach ($tr as $g=>$t) { |
foreach ($tr as $g=>$t) { |
1472 |
if ($t & trmask_group && in_group($user,$g)) { |
if ($t & trmask_not && $g != $user) { |
1473 |
|
$t = $t & ~trmask_not; |
1474 |
|
$perm = unroll_perm($user,$t,$perm, $one_level); |
1475 |
|
unset($tr[$g]); |
1476 |
|
|
1477 |
|
} elseif ($t & trmask_group && in_group($user,$g)) { |
1478 |
// resolv user |
// resolv user |
1479 |
$t = $t & ~trmask_group; |
$t = $t & ~trmask_group; |
1480 |
$perm = unroll_perm($user,$t,$g, $perm, $one_level); |
$perm = unroll_perm($user,$t,$perm, $one_level); |
1481 |
unset($tr[$g]); |
unset($tr[$g]); |
1482 |
} |
} |
1483 |
} |
} |
1484 |
// then apply user policy |
// then apply user policy |
1485 |
if (isset($tr[$user])) { |
if (isset($tr[$user])) { |
1486 |
$perm = unroll_perm($user,$tr[$user],$user, $perm,$one_level); |
$perm = unroll_perm($user,$tr[$user],$perm,$one_level); |
1487 |
unset($tr[$user]); |
unset($tr[$user]); |
1488 |
} |
} |
1489 |
} |
} |
1500 |
function check_perm($path,$trperm) { |
function check_perm($path,$trperm) { |
1501 |
global $gblLogin,$HAVE_TRUSTEE; |
global $gblLogin,$HAVE_TRUSTEE; |
1502 |
|
|
1503 |
|
$path = str_replace("//","/",$path); |
1504 |
|
|
1505 |
global $debug; |
global $debug; |
1506 |
$debug.="<br>check_perm: on <tt>$path</tt> for perm ".display_trustee($trperm)."<br>\n"; |
$debug.="<br>check_perm: on <tt>$path</tt> for perm ".display_trustee($trperm)."<br>\n"; |
1507 |
|
|
1551 |
|
|
1552 |
function check_filename($file) { |
function check_filename($file) { |
1553 |
if (strstr($file,"..")) Error("Security violation","No parent dir <tt>..</tt> allowed in file name <tt>$file</tt>",1); |
if (strstr($file,"..")) Error("Security violation","No parent dir <tt>..</tt> allowed in file name <tt>$file</tt>",1); |
1554 |
|
// remove deleted directory (for undelete to work) |
1555 |
|
$file = str_replace(".del/","",$file); |
1556 |
if (strstr($file,"/")) Error("Security violation","No slashes <tt>/</tt> allowed in file name <tt>$file</tt>",1); |
if (strstr($file,"/")) Error("Security violation","No slashes <tt>/</tt> allowed in file name <tt>$file</tt>",1); |
1557 |
} |
} |
1558 |
|
|
1559 |
|
// bla/blo/../foo will return bla/foo |
1560 |
|
function remove_parent($path) { |
1561 |
|
while (preg_match(",/[^/]+/\.\./,",$path)) { |
1562 |
|
$path = preg_replace(",/[^/]+/\.\./,","",$path); |
1563 |
|
} |
1564 |
|
if (substr($path,0,1) != "/") $path = "/".$path; |
1565 |
|
return $path; |
1566 |
|
} |
1567 |
|
|
1568 |
////////////////////////////////////////////////////////////////// |
////////////////////////////////////////////////////////////////// |
1569 |
|
|
1570 |
// functions to move HTTP server variables to global namespace |
// functions to move HTTP server variables to global namespace |
1571 |
// [replacement for register_globals in php.ini] |
// [replacement for register_globals in php.ini] |
1572 |
|
|
1573 |
function HTTP_GET_VAR($var) { |
function HTTP_GET_VAR($var) { |
1574 |
global $HTTP_GET_VARS, $GLOBALS; |
global $HTTP_GET_VARS, ${$var}; |
1575 |
if (isset($HTTP_GET_VARS[$var])) { |
if (isset($HTTP_GET_VARS[$var])) { |
1576 |
$GLOBALS[$var] = stripSlashes($HTTP_GET_VARS[$var]); |
$$var = stripSlashes($HTTP_GET_VARS[$var]); |
1577 |
return $GLOBALS[$var]; |
return $$var; |
1578 |
} |
} |
1579 |
} |
} |
1580 |
|
|
1581 |
function HTTP_POST_VAR($var) { |
function HTTP_POST_VAR($var) { |
1582 |
global $HTTP_GET_VARS, $GLOBALS; |
global $HTTP_POST_VARS, ${$var}; |
1583 |
if (isset($HTTP_GET_VARS[$var])) { |
if (isset($HTTP_POST_VARS[$var])) { |
1584 |
$GLOBALS[$var] = stripSlashes($HTTP_GET_VARS[$var]); |
$$var = $HTTP_POST_VARS[$var]; |
1585 |
return $GLOBALS[$var]; |
return $$var; |
1586 |
|
} |
1587 |
|
} |
1588 |
|
|
1589 |
|
function HTTP_SERVER_VAR($var) { |
1590 |
|
global $HTTP_SERVER_VARS, ${$var}; |
1591 |
|
if (isset($HTTP_SERVER_VARS[$var])) { |
1592 |
|
$$var = $HTTP_SERVER_VARS[$var]; |
1593 |
|
return $$var; |
1594 |
} |
} |
1595 |
} |
} |
1596 |
|
|
1613 |
// location of master docman configuration file |
// location of master docman configuration file |
1614 |
$docman_conf = "/etc/docman.conf"; |
$docman_conf = "/etc/docman.conf"; |
1615 |
if (! file_exists($docman_conf)) { |
if (! file_exists($docman_conf)) { |
1616 |
$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"; |
1617 |
|
|
1618 |
error_log("docman: $error"); |
error_log("docman: $error"); |
1619 |
Error("docman not installed completly",$error); |
Error("docman not installed completly",$error); |
1701 |
// read mime.types |
// read mime.types |
1702 |
readMime(); |
readMime(); |
1703 |
|
|
1704 |
|
HTTP_POST_VAR("FN"); |
1705 |
|
|
1706 |
if ($HTTP_SERVER_VARS["REQUEST_METHOD"] == "POST") { |
if ($HTTP_SERVER_VARS["REQUEST_METHOD"] == "POST") { |
1707 |
// take variables from server |
// take variables from server |
1708 |
if (HTTP_POST_VAR("FN")) check_filename($FN); |
if (HTTP_POST_VAR("FN")) |
1709 |
|
check_filename($FN); |
1710 |
if (HTTP_POST_VAR("DIR")) { |
if (HTTP_POST_VAR("DIR")) { |
1711 |
check_dirname($DIR); |
check_dirname($DIR); |
1712 |
$relDir = $DIR; |
$relDir = $DIR; |
1713 |
} else { |
} else { |
1714 |
trigger_error("Can't get DIR",E_USER_WARNING); |
trigger_error("Can't get DIR",E_USER_WARNING); |
1715 |
|
$relDir = "/"; |
1716 |
} |
} |
1717 |
if (HTTP_POST_VAR("RELPATH")) check_dirname($RELPATH); |
if (HTTP_POST_VAR("RELPATH")) check_dirname($RELPATH); |
1718 |
HTTP_POST_VAR("T"); |
HTTP_POST_VAR("T"); |
1719 |
HTTP_POST_VAR("CONFIRM"); |
HTTP_POST_VAR("CONFIRM"); |
|
|
|
1720 |
} else { |
} else { |
1721 |
// get |
// get |
1722 |
HTTP_GET_VAR("A"); |
HTTP_GET_VAR("A"); |
1761 |
Error("You must select file with browse to upload it!"); |
Error("You must select file with browse to upload it!"); |
1762 |
} |
} |
1763 |
|
|
1764 |
$FILENAME = $HTTP_POST_VARS["FILENAME"]; |
if (HTTP_POST_VAR("FILENAME")) check_filename($FILENAME); |
|
check_filename($FILENAME); |
|
1765 |
|
|
1766 |
if (! isset($FILENAME)) { // from update file |
if (! isset($FILENAME)) { // from update file |
1767 |
$target = "$fsDir/".basename($FN); |
$target = "$fsDir/".basename($FN); |
1769 |
$target = "$fsDir/$FILENAME"; |
$target = "$fsDir/$FILENAME"; |
1770 |
} |
} |
1771 |
|
|
1772 |
|
if (! check_perm("$relDir/".basename($target), trperm_w)) |
1773 |
|
Error("Access denied","User <tt>$gblLogin</tt> tried to upload <tt>$relDir/".basename($target)."</tt> without valid trustee.",1); |
1774 |
|
|
1775 |
// backup old files first |
// backup old files first |
1776 |
$dir=dirname($target); |
$dir=dirname($target); |
1777 |
if (! file_exists($dir."/.bak")) { |
if (! file_exists($dir."/.bak")) { |
1778 |
mkdir($dir."/.bak",0700); |
mkdir($dir."/.bak",0700); |
1779 |
} |
} |
1780 |
if (! file_exists($dir."/.bak/$GLOBALS[gblNumBackups]")) { |
if (! file_exists($dir."/.bak/$gblNumBackups")) { |
1781 |
mkdir($dir."/.bak/$GLOBALS[gblNumBackups]",0700); |
mkdir($dir."/.bak/$gblNumBackups",0700); |
1782 |
} |
} |
1783 |
$file=basename($target); |
$file=basename($target); |
1784 |
for($i=$GLOBALS[gblNumBackups]-1;$i>0;$i--) { |
for($i=$gblNumBackups-1;$i>0;$i--) { |
1785 |
MoveTo("$dir/.bak/$i/$file","$dir/.bak/".($i+1)."/"); |
MoveTo("$dir/.bak/$i/$file","$dir/.bak/".($i+1)."/"); |
1786 |
} |
} |
1787 |
MoveTo($target,$dir."/.bak/1/"); |
MoveTo($target,$dir."/.bak/1/"); |
1800 |
case "SAVE" : |
case "SAVE" : |
1801 |
$path = $gblFsRoot . $RELPATH ; |
$path = $gblFsRoot . $RELPATH ; |
1802 |
$path=stripSlashes($path); |
$path=stripSlashes($path); |
1803 |
|
|
1804 |
|
if (! check_perm("$RELPATH", trperm_w)) |
1805 |
|
Error("Access denied","User <tt>$gblLogin</tt> tried to save <tt>$RELPATH</tt> without valid trustee.",1); |
1806 |
|
|
1807 |
$writable = is_writeable($path) ; |
$writable = is_writeable($path) ; |
1808 |
$legaldir = is_writeable(dirname($path)) ; |
$legaldir = is_writeable(dirname($path)) ; |
1809 |
$exists = (file_exists($path)) ? 1 : 0 ; |
$exists = (file_exists($path)) ? 1 : 0 ; |
1810 |
// check for legal extension here as well |
// FIX: more verbose error message |
1811 |
if (!($writable || (!$exists && $legaldir))) |
if (!($writable || (!$exists && $legaldir))) |
1812 |
Error("Write denied",$RELPATH) ; |
Error("Write denied",$RELPATH) ; |
1813 |
$fh = fopen($path, "w") ; |
$fh = fopen($path, "w") ; |
1814 |
$FILEDATA=stripSlashes($FILEDATA); |
HTTP_POST_VAR("FILEDATA"); |
1815 |
fwrite($fh,$FILEDATA) ; |
fwrite($fh,$FILEDATA) ; |
1816 |
fclose($fh) ; |
fclose($fh) ; |
1817 |
clearstatcache() ; |
clearstatcache() ; |
1820 |
|
|
1821 |
case "CREATE" : |
case "CREATE" : |
1822 |
// we know $fsDir exists |
// we know $fsDir exists |
1823 |
if ($FN == "") break; // no filename! |
if (! check_perm($relDir, trperm_w)) |
1824 |
if (!is_writeable($fsDir)) Error("Write denied",$relDir) ; |
Error("Write access denied","You don't have permission to write in <tt>$relDir</tt>"); |
1825 |
$path = $fsDir . "/" . $FN ; // file or dir to create |
if ($T == "D") $type = "directory"; |
1826 |
$relPath = $relDir . "/" . $FN ; |
else $type ="file"; |
1827 |
|
if ($FN == "") Error("Can't create $type","You must enter name of $type to create it."); |
1828 |
|
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) ; |
1829 |
|
$path = "$fsDir/$FN"; // file or dir to create |
1830 |
|
$relPath = "$relDir/$FN"; |
1831 |
|
|
1832 |
|
if (file_exists($path)) |
1833 |
|
Error("Can't create $type","Object <tt>$relPath</tt> allready exists"); |
1834 |
|
|
1835 |
switch ( $T ) { |
switch ( $T ) { |
1836 |
case "D" : // create a directory |
case "D" : // create a directory |
1837 |
if ( ! @mkdir($path,$gblDirPerms) ) |
if ( ! @mkdir($path,$gblDirPerms) ) |
1845 |
// better keep it here altogether |
// better keep it here altogether |
1846 |
// chmod perms to $gblFilePerms |
// chmod perms to $gblFilePerms |
1847 |
if ( file_exists($path) && !is_writeable($path) ) |
if ( file_exists($path) && !is_writeable($path) ) |
1848 |
Error("File not writable", $relPath) ; |
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) ; |
1849 |
$fh = fopen($path, "w+") ; |
$fh = fopen($path, "w+") ; |
1850 |
if ($fh) { |
if ($fh) { |
1851 |
fputs($fh,"\n"); |
fputs($fh,"\n"); |
1852 |
fclose($fh) ; |
fclose($fh) ; |
1853 |
LogIt($path,"file created",trperm_r | trperm_w); |
LogIt($path,"file created",trperm_r | trperm_w); |
1854 |
} else { |
} else { |
1855 |
Error("Creation of file $relPath failed -- $path"); |
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) ; |
1856 |
} |
} |
1857 |
$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) ; |
1858 |
header("Location: " . $tstr) ; |
header("Location: " . $tstr) ; |
1859 |
exit ; |
exit ; |
1860 |
} |
} |
1861 |
break ; |
break ; |
1862 |
|
|
1863 |
case "DELETE" : |
case "DELETE" : |
1864 |
if ( $CONFIRM != "on" ) break ; |
if ( $CONFIRM != "on" ) break; |
1865 |
|
|
1866 |
$tstr = "Attempt to delete non-existing object or " ; |
if ( isset($FN) && $FN != "") { |
1867 |
$tstr .= "insufficient privileges: " ; |
$path=$fsDir."/".$FN; |
1868 |
|
$what = "file"; |
1869 |
|
} elseif (isset($DIR)) { |
1870 |
|
$path=$gblFsRoot."/".$DIR; |
1871 |
|
$what = "directory"; |
1872 |
|
} else { |
1873 |
|
Error("Can't delete object","Can't find filename <tt>\$FN</tt> or dirname in <tt>\$DIR</tt>",1); |
1874 |
|
} |
1875 |
|
|
1876 |
if ( $FN != "") { // delete file |
if (! check_perm("$relDir/$FN", trperm_w)) |
1877 |
$path = $fsDir . "/" . $FN ; |
Error("Access denied","User <tt>$gblLogin</tt> tried to erase $what <tt>$relDir/$FN</tt> without valid trustee.",1); |
|
|
|
|
$dir=dirname($path); |
|
|
$file=basename($path); |
|
|
if (! file_exists("$dir/.del")) { |
|
|
mkdir("$dir/.del",0700); |
|
|
} |
|
1878 |
|
|
1879 |
// if ( ! @unlink($path) ) { |
$tstr = "Attempt to delete non-existing object or insufficient privileges: " ; |
1880 |
if ( ! rename($path,"$dir/.del/$file") ) { |
|
1881 |
LogIt($path,"file delete failed"); |
$dir=dirname($path); |
1882 |
Error("File delete failed", $tstr . $path) ; |
$file=basename($path); |
1883 |
} else { |
|
1884 |
LogIt($path,"file deleted",trperm_w); |
if (! file_exists("$dir/.del")) { |
1885 |
MoveTo("$dir/.log/$file","$dir/.del/.log/"); |
mkdir("$dir/.del",0700); |
1886 |
MoveTo("$dir/.note/$file","$dir/.del/.note/"); |
} |
1887 |
MoveTo("$dir/.lock/$file","$dir/.del/.lock/"); |
|
1888 |
} |
if ( ! @rename($path,"$dir/.del/$file") ) { |
1889 |
} else { // delete directory |
LogIt($path,"$what delete failed"); |
1890 |
if ( ! @rrmdir($fsDir) ) { |
Error("Can't delete $what",$tstr."<tt>".$relDir."/".$FN."</tt>") ; |
1891 |
Error("Rmdir failed", $tstr . $fsDir) ; |
} else { |
1892 |
} else { |
LogIt($path,"$what deleted",trperm_w); |
1893 |
LogIt($path,"dir deleted",trperm_w); |
MoveTo("$dir/.log/$file","$dir/.del/.log/"); |
1894 |
$relDir = dirname($relDir) ; // move up |
MoveTo("$dir/.note/$file","$dir/.del/.note/"); |
1895 |
} |
MoveTo("$dir/.lock/$file","$dir/.del/.lock/"); |
1896 |
} |
} |
1897 |
break ; |
break ; |
1898 |
|
|
1902 |
if (substr($FN,0,4) != ".del") break ; |
if (substr($FN,0,4) != ".del") break ; |
1903 |
$file=substr($FN,4,strlen($FN)-4); |
$file=substr($FN,4,strlen($FN)-4); |
1904 |
|
|
1905 |
|
if (! check_perm("$relDir/$file", trperm_w)) |
1906 |
|
Error("Access denied","User <tt>$gblLogin</tt> tried to undelete <tt>$relDir/$file</tt> without valid trustee.",1); |
1907 |
|
|
1908 |
LogIt("$fsDir/.del/$file","undeleted",trperm_w); |
LogIt("$fsDir/.del/$file","undeleted",trperm_w); |
1909 |
MoveTo("$fsDir/.del/$file","$fsDir/"); |
MoveTo("$fsDir/.del/$file","$fsDir/"); |
1910 |
MoveTo("$fsDir/.del/.log/$file","$fsDir/.log/"); |
MoveTo("$fsDir/.del/.log/$file","$fsDir/.log/"); |
1916 |
case "RENAME" : |
case "RENAME" : |
1917 |
if ( $CONFIRM != "on" ) break ; |
if ( $CONFIRM != "on" ) break ; |
1918 |
|
|
1919 |
$NEWNAME=stripSlashes($HTTP_POST_VARS["NEWNAME"]); |
if (HTTP_POST_VAR("NEWNAME")) { |
1920 |
|
$dest = remove_parent($relDir.$NEWNAME); |
1921 |
|
if (! check_perm($relDir.$FN, trperm_w) || |
1922 |
|
! check_perm($dest, trperm_w) ) |
1923 |
|
Error("Access denied","User <tt>$gblLogin</tt> tried to rename <tt>$relDir$FN</tt> to <tt>$dest</tt> without valid trustee.",1); |
1924 |
|
} else { |
1925 |
|
Error("Rename error","Can't find new name in var <tt>\$NEWNAME</tt>",1); |
1926 |
|
} |
1927 |
LogIt("$fsDir/$FN","renamed $FN to $NEWNAME",trperm_r); |
LogIt("$fsDir/$FN","renamed $FN to $NEWNAME",trperm_r); |
1928 |
safe_rename($fsDir,$FN,$NEWNAME); |
safe_rename($fsDir,$FN,$NEWNAME); |
1929 |
break ; |
break ; |
1944 |
|
|
1945 |
// common to all POSTs : redirect to directory view ($relDir) |
// common to all POSTs : redirect to directory view ($relDir) |
1946 |
if (isset($POSTACTION)) { |
if (isset($POSTACTION)) { |
1947 |
$tstr = $PHP_SELF . "?D=" . urlencode($relDir) ; |
$tstr = $HTTP_SERVER_VARS["PHP_SELF"]."?D=".urlencode($relDir); |
1948 |
header("Location: " . $tstr) ; |
header("Location: ".$tstr) ; |
1949 |
exit ; |
exit ; |
1950 |
} |
} |
1951 |
|
|