/[docman2]/docman.php
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /docman.php

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.18 by dpavlin, Sun Jul 28 16:24:54 2002 UTC revision 1.19 by dpavlin, Sun Jul 28 17:31:03 2002 UTC
# Line 86  Line 86 
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_VARS["PHP_AUTH_USER"];
94          $gblPasswd = $HTTP_SERVER_VARS[PHP_AUTH_PW];          $gblPasswd = $HTTP_SERVER_VARS["PHP_AUTH_PW"];
95    
96  //////////////////////////////////////////////////////////////////  //////////////////////////////////////////////////////////////////
97    
# Line 109  function LoadLanguage($lang) { Line 109  function LoadLanguage($lang) {
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    
# Line 579  function Navigate($fsRoot,$relDir) { Line 578  function Navigate($fsRoot,$relDir) {
578    
579          global $gblEditable, $gblIcon, $gblModDays, $webRoot, $gblHide,          global $gblEditable, $gblIcon, $gblModDays, $webRoot, $gblHide,
580                  $gblIgnoreUnknownFileType, $gblRepositoryDir,                  $gblIgnoreUnknownFileType, $gblRepositoryDir,
581                    $gblLogin,
582                  $fsRealmDir, $realm, $realm_sep,                  $fsRealmDir, $realm, $realm_sep,
583                  $HTTP_GET_VARS, $html, $realm_config;                  $html, $realm_config,
584                    $HTTP_GET_VARS, $HTTP_SERVER_VARS;
585                    
586          $self     = $HTTP_SERVER_VARS["PHP_SELF"] ;          $self     = $HTTP_SERVER_VARS["PHP_SELF"] ;
587    
# Line 598  function Navigate($fsRoot,$relDir) { Line 599  function Navigate($fsRoot,$relDir) {
599    
600          $hide_items=",$gblHide,";          $hide_items=",$gblHide,";
601    
602            $dirList = array();
603            $fileList = array();
604    
605          // read directory contents          // read directory contents
606          if ( !($dir = @opendir($fsDir)) )          if ( !($dir = @opendir($fsDir)) )
607                  Error("Read Access denied",$relDir,1) ;                  Error("Read Access denied",$relDir,1) ;
# Line 622  function Navigate($fsRoot,$relDir) { Line 626  function Navigate($fsRoot,$relDir) {
626          closedir($dir) ;          closedir($dir) ;
627    
628          // scan deleted files          // scan deleted files
629          if ( $HTTP_GET_VARS["show_deleted"] == 1 && ($dir = @opendir("$fsDir/.del")) ) {          if ( HTTP_GET_VAR("show_deleted") == 1 && ($dir = @opendir("$fsDir/.del")) ) {
630                  while ($item = readdir($dir)) {                  while ($item = readdir($dir)) {
631                          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 ;
632                          $fileList[$item] = ".del/$item" ;                                        $fileList[$item] = ".del/$item" ;              
# Line 637  function Navigate($fsRoot,$relDir) { Line 641  function Navigate($fsRoot,$relDir) {
641    
642          // start navigation page          // start navigation page
643          $text  = "Use this page to add, delete";          $text  = "Use this page to add, delete";
644          if (! isset($HTTP_GET_VARS[show_deleted])) {          if (! isset($HTTP_GET_VARS["show_deleted"])) {
645                  $text .= ", <a href=$self?D=".urlencode($relDir)."&show_deleted=1>undelete</a>";                  $text .= ", <a href=$self?D=".urlencode($relDir)."&show_deleted=1>undelete</a>";
646          }          }
647          $text .= " or revise files on this web site." ;          $text .= " or revise files on this web site." ;
# Line 663  function Navigate($fsRoot,$relDir) { Line 667  function Navigate($fsRoot,$relDir) {
667                  return $out;                  return $out;
668          }          }
669    
670          $dsort = $HTTP_GET_VARS[dsort];          if (! HTTP_GET_VAR("dsort")) $dsort = "name"; // default directory sort
         if (! isset($dsort)) $dsort = "name";   // default directory sort  
671    
672          $dsort_arr = array(          $dsort_arr = array(
673                  "name" => array ("rname", "note"),                  "name" => array ("rname", "note"),
# Line 673  function Navigate($fsRoot,$relDir) { Line 676  function Navigate($fsRoot,$relDir) {
676                  "rnote" => array ("name", "note")                  "rnote" => array ("name", "note")
677                  );                  );
678    
679          $fsort = $HTTP_GET_VARS[fsort];          if (! HTTP_GET_VAR("fsort")) $fsort = "name"; // default directory sort
         if (! isset($fsort)) $fsort = "name";   // default directory sort  
680    
681          $fsort_arr = array(          $fsort_arr = array(
682                  "name" => array ("rname", "note", "date", "size"),                  "name" => array ("rname", "note", "date", "size"),
# Line 690  function Navigate($fsRoot,$relDir) { Line 692  function Navigate($fsRoot,$relDir) {
692          $D="D=".urlencode($relDir);          $D="D=".urlencode($relDir);
693    
694          function self_args($arr = array()) {          function self_args($arr = array()) {
695                    global $self;
696                  $arg = implode("&",$arr);                  $arg = implode("&",$arr);
697                  if ($arg) {                  if ($arg) {
698                          return $self."?".$arg;                          return $self."?".$arg;
# Line 1238  function chopsl($path) { Line 1241  function chopsl($path) {
1241          by Vyacheslav Zavadsky <zavadsky@braysystems.com>          by Vyacheslav Zavadsky <zavadsky@braysystems.com>
1242  */  */
1243    
1244  define(trmask_not,1 << 0);  define('trmask_not',1 << 0);
1245  define(trmask_clear,1 << 1);  define('trmask_clear',1 << 1);
1246  define(trmask_deny,1 << 2);  define('trmask_deny',1 << 2);
1247  define(trmask_one_level,1 << 3);  define('trmask_one_level',1 << 3);
1248  define(trmask_group,1 << 4);  define('trmask_group',1 << 4);
1249    
1250  define(trperm_r,1 << 5);  define('trperm_r',1 << 5);
1251  define(trperm_w,1 << 6);  define('trperm_w',1 << 6);
1252  define(trperm_b,1 << 7);  define('trperm_b',1 << 7);
1253  define(trperm_n,1 << 8);  define('trperm_n',1 << 8);
1254    
1255  $trustee_a2n = array(  $trustee_a2n = array(
1256          '!' => trmask_not,          '!' => trmask_not,
# Line 1295  if (! file_exists($trustee_conf)) { Line 1298  if (! file_exists($trustee_conf)) {
1298          $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";
1299  } elseif (file_exists($trustee_php) && !is_writable($trustee_php)) {  } elseif (file_exists($trustee_php) && !is_writable($trustee_php)) {
1300          $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";
1301  } elseif (1 || filemtime($trustee_conf) >= filemtime($trustee_php)) {  } elseif (@filemtime($trustee_conf) >= @filemtime($trustee_php)) {
1302          $fp_php=@fopen($trustee_php,"w");          $fp_php=@fopen($trustee_php,"w");
1303          fputs($fp_php,"<?php // don't edit by hand!\n");          fputs($fp_php,"<?php // don't edit by hand!\n");
1304    
# Line 1331  if (! file_exists($trustee_conf)) { Line 1334  if (! file_exists($trustee_conf)) {
1334                                                  $error.="trustee error in line '$l' [Unknown modifier '$ch']<br>\n";                                                  $error.="trustee error in line '$l' [Unknown modifier '$ch']<br>\n";
1335                                          }                                          }
1336                                  }                                  }
1337                                  $tr_arr[$path][$user] |= $perm;                                  if (isset($tr_arr[$path][$user])) {
1338                                            $tr_arr[$path][$user] |= $perm;
1339                                    } else {
1340                                            $tr_arr[$path][$user] = $perm;
1341                                    }
1342                          }                          }
1343                  }                  }
1344          }          }
# Line 1370  if (! file_exists($trustee_conf)) { Line 1377  if (! file_exists($trustee_conf)) {
1377          fclose($fp_php);          fclose($fp_php);
1378  }  }
1379    
1380  if ($error) {  if (isset($error)) {
1381          Error("Trustee error",$error,1);          Error("Trustee error",$error,1);
1382  } else {  } else {
1383          include("$trustee_php");          include_once("$trustee_php");
1384  }  }
1385    
1386  return 1;  return 1;
# Line 1394  function unroll_perm($u,$t,$user,$perm) Line 1401  function unroll_perm($u,$t,$user,$perm)
1401    
1402          if ($t & trmask_deny) {          if ($t & trmask_deny) {
1403                  if ($t & trmask_clear) {                  if ($t & trmask_clear) {
1404                          $perm[deny] &= ~$t;                          $perm['deny'] &= ~$t;
1405                  } else {                  } else {
1406                          $perm[deny] |= $t;                          $perm['deny'] |= $t;
1407                  }                  }
1408          } elseif ($t & trmask_clear) {          } elseif ($t & trmask_clear) {
1409                  $perm[allow] &= ~$t;                  $perm['allow'] &= ~$t;
1410          } else {          } else {
1411                  $perm[allow] |= $t;                  $perm['allow'] |= $t;
1412          }          }
1413          return $perm;          return $perm;
1414  }// end of helper function  }// end of helper function
1415    
1416  function check_trustee($user,$path) {  function check_trustee($user,$path) {
1417          global $trustees;          global $trustees;
1418          $perm[allow] = 0;          $perm['allow'] = 0;
1419          $perm[deny] = 0;          $perm['deny'] = 0;
1420    
1421            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);
1422    
1423  global $debug;  global $debug;
1424  $debug .= "<br>check_trustee $path ... ";  $debug .= "<br>check_trustee $path ... ";
# Line 1419  $debug .= "<br>check_trustee $path ... " Line 1428  $debug .= "<br>check_trustee $path ... "
1428          while (count($path_arr)) {          while (count($path_arr)) {
1429                  $tmppath.=array_shift($path_arr);                  $tmppath.=array_shift($path_arr);
1430  $debug.= ">> $tmppath ";  $debug.= ">> $tmppath ";
                 if (substr($tmppath,strlen($tmppath)-1,1) != "/") $tmppath.="/";  
                 $tr = $trustees[$tmppath];  
1431    
1432                  # clear one level flag                  # clear one level flag
1433                  $perm[allow] &= ~trperm_one_level;                  $perm['allow'] &= ~trmask_one_level;
1434                  $perm[deny] &= ~trperm_one_level;                  $perm['deny'] &= ~trmask_one_level;
1435    
1436                    if (! isset($trustees[$tmppath])) continue;
1437                    $tr = $trustees[$tmppath];
1438    
1439                  if (isset($tr)) {                  if (isset($tr)) {
1440                          // first apply trustee for all                          // first apply trustee for all
# Line 1447  $debug.= ">> $tmppath "; Line 1457  $debug.= ">> $tmppath ";
1457                                  unset($tr[$user]);                                  unset($tr[$user]);
1458                          }                          }
1459                  }                  }
1460  $debug.="d:".display_trustee($perm[deny])." a:".display_trustee($perm[allow])." ";  $debug.="d(".display_trustee($perm['deny']).") a(".display_trustee($perm['allow']).") ";
1461    
1462          }          }
1463  $debug.="<br>check_trustee: user: $user path: $path==$tmppath perm: ";  $debug.="<br>check_trustee: user: $user path: $path==$tmppath perm: ";
1464  $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";
1465          return $perm;          return $perm;
1466  }  }
1467    
# Line 1461  function check_perm($path,$trperm) { Line 1471  function check_perm($path,$trperm) {
1471          global $gblLogin,$HAVE_TRUSTEE;          global $gblLogin,$HAVE_TRUSTEE;
1472    
1473          global $debug;          global $debug;
1474  $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";
1475    
1476          $return = ! $HAVE_TRUSTEE;          $return = ! $HAVE_TRUSTEE;
1477          if ($HAVE_TRUSTEE) {          if ($HAVE_TRUSTEE) {
1478                  $perm = check_trustee($gblLogin,$path);                  $perm = check_trustee($gblLogin,$path);
1479  $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).")";
1480                  if ($perm[deny] & $trperm) $return=0;                  if ($perm['deny'] & $trperm) $return=0;
1481                  elseif (($perm[allow] & $trperm) == $trperm) $return=1;                  elseif (($perm['allow'] & $trperm) == $trperm) $return=1;
1482          }          }
1483  $debug.=" return: $return<br>\n";  $debug.=" return: $return<br>\n";
1484          return($return);          return($return);
# Line 1513  function check_filename($file) { Line 1523  function check_filename($file) {
1523  }  }
1524    
1525  //////////////////////////////////////////////////////////////////  //////////////////////////////////////////////////////////////////
1526    
1527    // functions to move HTTP server variables to global namespace
1528    // [replacement for register_globals in php.ini]
1529    
1530    function HTTP_GET_VAR($var) {
1531            global $HTTP_GET_VARS, $GLOBALS;
1532            if (isset($HTTP_GET_VARS[$var])) {
1533                    $GLOBALS[$var] = stripSlashes($HTTP_GET_VARS[$var]);
1534                    return $GLOBALS[$var];
1535            }
1536    }
1537    
1538    function HTTP_POST_VAR($var) {
1539            global $HTTP_GET_VARS, $GLOBALS;
1540            if (isset($HTTP_GET_VARS[$var])) {
1541                    $GLOBALS[$var] = stripSlashes($HTTP_GET_VARS[$var]);
1542                    return $GLOBALS[$var];
1543            }
1544    }
1545    
1546    //////////////////////////////////////////////////////////////////
1547    
1548    function Warn($text) {
1549    }
1550    
1551    //////////////////////////////////////////////////////////////////
1552  // MAIN PROGRAM  // MAIN PROGRAM
1553    
1554          $gblFilePerms = 0640 ;         // default for new files          $gblFilePerms = 0640 ;         // default for new files
1555          $gblDirPerms  = 0750 ;          // default for new dirs          $gblDirPerms  = 0750 ;          // default for new dirs
1556    
1557          $STYLE = $HTTP_GET_VARS[STYLE];          if (isset($HTTP_GET_VARS["STYLE"]) && $HTTP_GET_VARS["STYLE"] == "get") {
         if (isset($STYLE) && $STYLE == "get") {  
1558                  include("$html/docman.css");                  include("$html/docman.css");
1559                  exit;                  exit;
1560          }          }
# Line 1539  function check_filename($file) { Line 1574  function check_filename($file) {
1574          }          }
1575    
1576          // try to add dir to script name to realm var          // try to add dir to script name to realm var
1577          if (is_dir("$fsRealmDir/$realm/".dirname($HTTP_SERVER_VARS[SCRIPT_NAME]))) {          if (is_dir("$fsRealmDir/$realm/".dirname($HTTP_SERVER_VARS["SCRIPT_NAME"]))) {
1578                  $realm .= dirname($HTTP_SERVER_VARS[SCRIPT_NAME]);                  $realm .= dirname($HTTP_SERVER_VARS["SCRIPT_NAME"]);
1579                  $realm_sep = "/";                  $realm_sep = "/";
1580          } else {          } else {
1581                  $realm_sep = ".";                  $realm_sep = ".";
# Line 1565  function check_filename($file) { Line 1600  function check_filename($file) {
1600          }          }
1601    
1602          // take additional login vars          // take additional login vars
1603          $relogin = $HTTP_GET_VARS[relogin];          HTTP_GET_VAR("relogin");
1604          $force_login = $HTTP_GET_VARS[force_login];          HTTP_GET_VAR("force_login");
1605    
1606          // if no password, or empty password logout          // if no password, or empty password logout
1607          if (          if (
# Line 1593  function check_filename($file) { Line 1628  function check_filename($file) {
1628          $HAVE_TRUSTEE = init_trustee();          $HAVE_TRUSTEE = init_trustee();
1629    
1630          if (strtolower($gblLogin) == "anonymous" || !isset($gblLogin)) {          if (strtolower($gblLogin) == "anonymous" || !isset($gblLogin)) {
1631                  $perm = check_trustee("anonymous",$path);                  $perm = check_trustee("anonymous","/");
1632                  // browsing must be explicitly allowed for root directory                  // browsing must be explicitly allowed for root directory
1633                  // of repository for anonymous user to work!                  // of repository for anonymous user to work!
1634                  if ($perm[allow] & trperm_b) {                  if ($perm['allow'] & trperm_b) {
1635                          $gblLogin = $gblPasswd = "anonymous";                          $gblLogin = $gblPasswd = "anonymous";
1636                          $secHash = md5($gblLogin.$gblPasswd);                          $secHash = md5($gblLogin.$gblPasswd);
1637                          $gblUserName = "Anonymous user";                          $gblUserName = "Anonymous user";
# Line 1617  function check_filename($file) { Line 1652  function check_filename($file) {
1652    
1653          if ($HTTP_SERVER_VARS["REQUEST_METHOD"] == "POST") {          if ($HTTP_SERVER_VARS["REQUEST_METHOD"] == "POST") {
1654                  // take variables from server                  // take variables from server
1655                  $FN=stripSlashes($HTTP_POST_VARS["FN"]);                  if (HTTP_POST_VAR("FN")) check_filename($FN);
1656                  $DIR=stripSlashes($HTTP_POST_VARS["DIR"]);                  if (HTTP_POST_VAR("DIR")) {
1657                  $RELPATH=stripSlashes($HTTP_POST_VARS["RELPATH"]);                          check_dirname($DIR);
1658                  $T=stripSlashes($HTTP_POST_VARS["T"]);                          $relDir = $DIR;
1659                  $CONFIRM=stripSlashes($HTTP_POST_VARS["CONFIRM"]);                  } else {
1660                            trigger_error("Can't get DIR",E_USER_WARNING);
1661                  check_filename($FN);                  }
1662                  check_dirname($DIR);                  if (HTTP_POST_VAR("RELPATH")) check_dirname($RELPATH);
1663                  check_dirname($RELPATH);                  HTTP_POST_VAR("T");
1664                    HTTP_POST_VAR("CONFIRM");
1665    
                 $relDir = $DIR;  
1666          } else {          } else {
1667                  // get                  // get
1668                  $A=stripSlashes($HTTP_GET_VARS["A"]);                  HTTP_GET_VAR("A");
1669                  $D=stripSlashes(urldecode($HTTP_GET_VARS["D"]));                  if (HTTP_GET_VAR("D")) {
1670                  $F=stripSlashes($HTTP_GET_VARS["F"]);                          check_dirname($D);
1671                            $D=urldecode($D);
1672                  check_filename($F);                          $relDir = $D;
1673                  check_dirname($D);                  } else {
1674                            //trigger_error("Can't get D",E_USER_WARNING);
1675                  $relDir = $D;                          $relDir = "/";
1676                    }
1677                    if (HTTP_GET_VAR("F")) check_filename($F);
1678          }          }
1679    
1680          $relScriptDir = dirname($SCRIPT_NAME) ;                  $relScriptDir = dirname($HTTP_SERVER_VARS["SCRIPT_NAME"]) ;    
1681          // i.e. /docman          // i.e. /docman
1682    
1683          // start on server root          // start on server root
# Line 1659  function check_filename($file) { Line 1696  function check_filename($file) {
1696          }          }
1697          $webRoot .= $HTTP_SERVER_VARS["HTTP_HOST"] . $relScriptDir;          $webRoot .= $HTTP_SERVER_VARS["HTTP_HOST"] . $relScriptDir;
1698    
1699          switch ($HTTP_POST_VARS["POSTACTION"]) {          if (HTTP_POST_VAR("POSTACTION")) switch ($POSTACTION) {
1700          case "UPLOAD" :          case "UPLOAD" :
1701                  $FN_name=stripSlashes($HTTP_POST_FILES["FN"]["tmp_name"]);                  $FN_name=stripSlashes($HTTP_POST_FILES["FN"]["tmp_name"]);
1702                  $FN=stripSlashes($HTTP_POST_FILES["FN"]["name"]);                  $FN=stripSlashes($HTTP_POST_FILES["FN"]["name"]);
# Line 1827  function check_filename($file) { Line 1864  function check_filename($file) {
1864          }          }
1865    
1866          // common to all POSTs : redirect to directory view ($relDir)          // common to all POSTs : redirect to directory view ($relDir)
1867          if ( $POSTACTION != "" ) {          if (isset($POSTACTION)) {
1868                  $tstr = $PHP_SELF . "?D=" . urlencode($relDir) ;                  $tstr = $PHP_SELF . "?D=" . urlencode($relDir) ;
1869                  header("Location: " . $tstr) ;                    header("Location: " . $tstr) ;  
1870                  exit ;                  exit ;
# Line 1843  function check_filename($file) { Line 1880  function check_filename($file) {
1880          // $A=I : include file .$F.php from [$gblIncDir|realm]/include_php          // $A=I : include file .$F.php from [$gblIncDir|realm]/include_php
1881          // default : display directory $D          // default : display directory $D
1882    
1883          switch ($A) {          if (isset($A)) switch ($A) {
1884          case "U" :          case "U" :
1885                  // upload to $relDir                  // upload to $relDir
1886                  if (! check_perm($relDir, trperm_w))                  if (! check_perm($relDir, trperm_w))

Legend:
Removed from v.1.18  
changed lines
  Added in v.1.19

  ViewVC Help
Powered by ViewVC 1.1.26