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"); |
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 |
} |
} |
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 |
|
|
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 |
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")) { |
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") ; |
1825 |
if ($T == "D") $type = "directory"; |
if ($T == "D") $type = "directory"; |
1826 |
else $type ="file"; |
else $type ="file"; |
1827 |
if ($FN == "") Error("Can't create $type","You must enter name of $type to create it."); |
if ($FN == "") Error("Can't create $type","You must enter name of $type to create it."); |
1828 |
if (!is_writeable($fsDir)) Error("Write denied",$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) ; |
1829 |
$path = $fsDir . "/" . $FN ; // file or dir to create |
$path = "$fsDir/$FN"; // file or dir to create |
1830 |
$relPath = $relDir . "/" . $FN ; |
$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 = $HTTP_SERVER_VARS["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) ; |
1865 |
|
|
1866 |
if ( isset($FN) && $FN != "") { |
if ( isset($FN) && $FN != "") { |
1867 |
$path=$fsDir."/".$FN; |
$path=$fsDir."/".$FN; |
|
|
|
1868 |
$what = "file"; |
$what = "file"; |
1869 |
if (is_dir($path)) { |
} elseif (isset($DIR)) { |
1870 |
$what = "dir"; |
$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 (! check_perm($relDir."/".$FN, trperm_w)) |
if (! check_perm("$relDir/$FN", trperm_w)) |
1877 |
Error("Access denied","User <tt>$gblLogin</tt> tried to erase $what <tt>$relDir/$FN</tt> without valid trustee.",1); |
Error("Access denied","User <tt>$gblLogin</tt> tried to erase $what <tt>$relDir/$FN</tt> without valid trustee.",1); |
1878 |
|
|
1879 |
$tstr = "Attempt to delete non-existing object or " ; |
$tstr = "Attempt to delete non-existing object or insufficient privileges: " ; |
|
$tstr .= "insufficient privileges: " ; |
|
1880 |
|
|
1881 |
$dir=dirname($path); |
$dir=dirname($path); |
1882 |
$file=basename($path); |
$file=basename($path); |
|
if (! file_exists("$dir/.del")) { |
|
|
mkdir("$dir/.del",0700); |
|
|
} |
|
1883 |
|
|
1884 |
// if ( ! @unlink($path) ) { |
if (! file_exists("$dir/.del")) { |
1885 |
if ( ! @rename($path,"$dir/.del/$file") ) { |
mkdir("$dir/.del",0700); |
1886 |
LogIt($path,"$what delete failed"); |
} |
1887 |
Error("Can't delete $what",$tstr.$relDir."/".$FN) ; |
|
1888 |
} else { |
if ( ! @rename($path,"$dir/.del/$file") ) { |
1889 |
LogIt($path,"$what deleted",trperm_w); |
LogIt($path,"$what delete failed"); |
1890 |
MoveTo("$dir/.log/$file","$dir/.del/.log/"); |
Error("Can't delete $what",$tstr."<tt>".$relDir."/".$FN."</tt>") ; |
|
MoveTo("$dir/.note/$file","$dir/.del/.note/"); |
|
|
MoveTo("$dir/.lock/$file","$dir/.del/.lock/"); |
|
|
} |
|
1891 |
} else { |
} else { |
1892 |
Error("Rmdir failed", $tstr . $fsDir) ; |
LogIt($path,"$what deleted",trperm_w); |
1893 |
|
MoveTo("$dir/.log/$file","$dir/.del/.log/"); |
1894 |
|
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 ; |