/[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.7 by dpavlin, Sat Jul 27 19:45:28 2002 UTC revision 1.20 by dpavlin, Sun Jul 28 17:51:20 2002 UTC
# Line 20  Line 20 
20  //////////////////////////////////////////////////////////////////  //////////////////////////////////////////////////////////////////
21  // CONFIGURATION OPTIONS  // CONFIGURATION OPTIONS
22    
23  //      error_reporting(4) ;            // how verbose ?          error_reporting(E_ALL) ;                // how verbose ?
24    
25          // from where to include auth_*.php modules?          // from where to include auth_*.php modules?
26          $gblIncDir = "/data/docman2";          $gblIncDir = "/data/docman2";
# Line 84  Line 84 
84          LoadLanguage($HTTP_SERVER_VARS["HTTP_ACCEPT_LANGUAGE"]);          LoadLanguage($HTTP_SERVER_VARS["HTTP_ACCEPT_LANGUAGE"]);
85    
86          // for security and configuration          // for security and configuration
87          $realm=$HTTP_SERVER_VARS[HTTP_HOST];          $realm=$HTTP_SERVER_VARS["HTTP_HOST"];
88    
89          $fsDocumentRoot = dirname($HTTP_SERVER_VARS[SCRIPT_FILENAME]);          $fsDocumentRoot = dirname($HTTP_SERVER_VARS["SCRIPT_FILENAME"]);
90          if ($fsDocumentRoot == "") Error("Configuration error","Can't get SCRIPT_FILENAME from your web server. Please set <tt>\$fsDocumentRoot</tt> in <tt>\$</tt>",1);          if ($fsDocumentRoot == "") Error("Configuration error","Can't get SCRIPT_FILENAME from your web server. Please set <tt>\$fsDocumentRoot</tt> in <tt>\$</tt>",1);
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    
117          if (file_exists("$fsDocumentRoot/docman.css")) {          if (file_exists("$fsDocumentRoot/docman.css")) {
118                  $css=dirname($self)."/docman.css";                  $css=dirname($self)."/docman.css";
119          } else {          } else {
120                  $css=$self."?STYLE=get&css=$css";                  $css=$self."?STYLE=get";
121          }          }
122    
123          include("$html/head.html");          include("$html/head.html");
# Line 138  function EndHTML() { Line 137  function EndHTML() {
137          } else {          } else {
138                  $url .= md5($gblLogin.$gblPasswd);                  $url .= md5($gblLogin.$gblPasswd);
139          }          }
140          if (isset($gblLogin) && $gblLogin != "" && ($gblPasswd == "" || !isset($gblPasswd))) {          if ( (  (isset($gblLogin) && $gblLogin != "") ||
141                    (!isset($gblLogin) || $gblLogin == "")
142                 ) && ($gblPasswd == "" || !isset($gblPasswd))) {
143                  $url_title="login";                  $url_title="login";
144                  $url .= "&force_login=1";                  $url .= "&force_login=1";
145          } else {          } else {
146                  $url_title="relogin";                  $url_title="relogin";
147          }          }
148          include("$html/footer.html");          include("$html/footer.html");
149    
150            global $debug;
151            if ($debug) print $debug;
152  } // end function EndHTML  } // end function EndHTML
153    
154  //////////////////////////////////////////////////////////////////  //////////////////////////////////////////////////////////////////
# Line 160  function DetailPage($fsRoot,$relDir,$fn) Line 164  function DetailPage($fsRoot,$relDir,$fn)
164    
165          $exists   = file_exists($fsPath) ;          $exists   = file_exists($fsPath) ;
166          $ext      = strtolower(strrchr($relPath,".")) ;          $ext      = strtolower(strrchr($relPath,".")) ;
167          $editable = ( $ext=="" || strstr(join(" ",$gblEditable),$ext)) ;          $editable = ( $ext=="" || strstr(join(" ",$gblEditable),$ext)) &&
168          $writable = is_writeable($fsPath) ;                  check_perm($relPath,trperm_w);
169            $writable = is_writeable($fsPath) && check_perm($relPath,trperm_w) ;
170            $writable_dir = is_writeable($fsDir) && check_perm($relDir,trperm_w) ;
171          $file_lock = CheckLock($fsPath);          $file_lock = CheckLock($fsPath);
172    
173          if (!$editable && !$exists)          if (!$editable && !$exists)
174                  Error("Creation unsupported for type",$relPath) ;                  Error("Creation denied","Can't create <tt>$relPath</tt>") ;
175          if (!exists && !is_writeable($fsDir) )          if (!$exists && !$writable_dir )
176                  Error("Creation denied",$relDir) ;                  Error("Creation denied","Can't write in directory <tt>$relDir</tt> while creating <tt>$relPath</tt>for which user has permissions.",1);
177    
178          $text  = _("Use this page to view, modify or ") ;          $text  = _("Use this page to view, modify or ") ;
179          if (is_dir($fsPath)) {          if (is_dir($fsPath)) {
# Line 200  function DetailPage($fsRoot,$relDir,$fn) Line 206  function DetailPage($fsRoot,$relDir,$fn)
206                  $fstr = htmlentities( $fstr ) ;                  $fstr = htmlentities( $fstr ) ;
207  ?>  ?>
208    
209  <FORM ACTION="<?= $self ; ?>" METHOD="POST">  <FORM ACTION="<?= $self ?>" METHOD="POST">
210  <SPAN TITLE="Click [SAVE] to store updated contents.">  <SPAN TITLE="Click [SAVE] to store updated contents.">
211          <B>DOCUMENT CONTENTS</B>          <B>DOCUMENT CONTENTS</B>
212  </SPAN><BR>  </SPAN><BR>
# Line 571  function GifIcon($txt) { Line 577  function GifIcon($txt) {
577  function Navigate($fsRoot,$relDir) {  function Navigate($fsRoot,$relDir) {
578    
579          global $gblEditable, $gblIcon, $gblModDays, $webRoot, $gblHide,          global $gblEditable, $gblIcon, $gblModDays, $webRoot, $gblHide,
580                  $gblIgnoreUnknownFileType,                  $gblIgnoreUnknownFileType, $gblRepositoryDir,
581                  $HTTP_GET_VARS, $html, $realm_config;                  $gblLogin,
582                    $fsRealmDir, $realm, $realm_sep,
583                    $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    
588          if ($relDir == "") $relDir = "/";          $relDir = chopsl($relDir)."/";
589            $fsDir = $fsRoot.$relDir;       // current directory
590    
591            if (!is_dir($fsDir)) Error("Dir not found","Directory <tt>$relDir<tt> not found on filesystem at <tt>$fsDir</tt>",1) ;
592    
593          $fsDir = $fsRoot.$relDir."/";   // current directory          global $debug;
594            $debug .= "[$gblLogin|$relDir] before >";
595    
596          if (!is_dir($fsDir)) Error("Dir not found",$relDir) ;          if (! check_perm($relDir,trperm_b))
597                    Error("Access denied","User <tt>$gblLogin</tt> tried to access <tt>$relDir</tt> without valid trustee.",1);
598            $debug .= "< afeter";
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 608  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 623  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 633  function Navigate($fsRoot,$relDir) { Line 651  function Navigate($fsRoot,$relDir) {
651          echo "<TABLE BORDER=0 CELLPADDING=2          echo "<TABLE BORDER=0 CELLPADDING=2
652                  CELLSPACING=3 WIDTH=\"100%\">" ;                  CELLSPACING=3 WIDTH=\"100%\">" ;
653    
654          // updir bar              // updir (parent) bar  
655          if (chopsl($fsDir) != chopsl($fsRoot)) {          if (chopsl($fsDir) != chopsl($fsRoot)) {
656                  $parent = dirname($relDir) ;                  $parent = dirname($relDir) ;
657                  if ($parent == "") $parent = "/" ;                  if ($parent == "") $parent = "/" ;
# Line 649  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 659  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 676  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 713  function Navigate($fsRoot,$relDir) { Line 730  function Navigate($fsRoot,$relDir) {
730                          $dir = $dirList[$key];                          $dir = $dirList[$key];
731    
732                          $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));
733                          $dir_url=$self."?D=".urlencode($relDir."/".$dir);                          $dir_url=$self."?D=".urlencode(chopsl($relDir)."/".$dir);
734                          include("$html/Navigate-dirEntry.html");                          include("$html/Navigate-dirEntry.html");
735    
736                  }  // iterate over dirs                  }  // iterate over dirs
# Line 859  function Navigate($fsRoot,$relDir) { Line 876  function Navigate($fsRoot,$relDir) {
876  <TR><TD></TD><TD COLSPAN=5><HR></TD></TR>  <TR><TD></TD><TD COLSPAN=5><HR></TD></TR>
877    
878  <?  <?
879  if (file_exists(".info.inc")) {  
880    if (file_exists("$fsRealmDir/$realm".$realm_sep."info.inc")) {
881          print "<TR><TD></TD><TD COLSPAN=5>";          print "<TR><TD></TD><TD COLSPAN=5>";
882          include(".info.inc");          include("$fsRealmDir/$realm".$realm_sep."info.inc");
883          print "</TD></TR>          print "</TD></TR><TR><TD></TD><TD COLSPAN=5><HR></TD></TR>";
884          <TR><TD></TD><TD COLSPAN=5><HR></TD></TR>";  } elseif (file_exists("$gblRepositoryDir/.info.inc")) {
885            print "<TR><TD></TD><TD COLSPAN=5>";
886            include("$gblRepositoryDir/.info.inc");
887            print "</TD></TR><TR><TD></TD><TD COLSPAN=5><HR></TD></TR>";
888  }  }
889    
890    
891  ?>  ?>
892    
893  <FORM METHOD="POST" ACTION="<?= $self ?>">  <FORM METHOD="POST" ACTION="<?= $self ?>">
# Line 892  function UploadPage($fsRoot, $relDir, $f Line 915  function UploadPage($fsRoot, $relDir, $f
915          global $html, $HTTP_SERVER_VARS;          global $html, $HTTP_SERVER_VARS;
916    
917          $self = $HTTP_SERVER_VARS["PHP_SELF"] ;          $self = $HTTP_SERVER_VARS["PHP_SELF"] ;
         if ($relDir == "") $relDir = "/" ;  
   
918          include("$html/UploadPage.html");          include("$html/UploadPage.html");
919    
920  } // end function UploadPage  } // end function UploadPage
# Line 903  function UploadPage($fsRoot, $relDir, $f Line 924  function UploadPage($fsRoot, $relDir, $f
924  // Error with sysadmin flag are reported to error_log or hidden from  // Error with sysadmin flag are reported to error_log or hidden from
925  // users  // users
926    
927  function Error($title,$text="",$sysadmin=0) {  function Error($title,$text="",$sysadmin=0,$no_404=0) {
928          global $gblSeparateAdminMessages,          global $gblSeparateAdminMessages,
929                  $gblMailAdminMessages,$realm,                  $gblMailAdminMessages,$realm,
930                  $HTTP_SERVER_VARS;                  $HTTP_SERVER_VARS;
931          if (! headers_sent()) header("HTTP/1.0 404 Not Found");          if (! headers_sent() && ! $no_404) header("HTTP/1.0 404 Not Found");
932          if ($sysadmin) {          if ($sysadmin) {
933                  if ($gblSeparateAdminMessages) {                  if ($gblSeparateAdminMessages) {
934                          $user="Your administrator ";                          $user="Your administrator ";
# Line 1076  function safe_rename($fromdir,$fromfile, Line 1097  function safe_rename($fromdir,$fromfile,
1097          function try_rename($from,$to) {          function try_rename($from,$to) {
1098  #               print "$from -> $to\n";  #               print "$from -> $to\n";
1099                  if (file_exists($from) && is_writeable(dirname($to))) {                  if (file_exists($from) && is_writeable(dirname($to))) {
1100                          rename($from,$to);                          return rename($from,$to);
1101                    } else {
1102                            return 0;
1103                  }                  }
1104          }          }
1105    
1106          function try_dir($todir) {          function try_dir($todir) {
1107                  if (! file_exists($todir)) {                  if (! file_exists($todir)) {
1108                          mkdir($todir,0700);                          @mkdir($todir,0700);
1109                  }                  }
1110          }          }
1111    
# Line 1092  function safe_rename($fromdir,$fromfile, Line 1115  function safe_rename($fromdir,$fromfile,
1115    
1116  #       print "<pre>$fromdir / $fromfile -> $todir / $tofile\n\n";  #       print "<pre>$fromdir / $fromfile -> $todir / $tofile\n\n";
1117    
1118          try_rename("$fromdir/$fromfile","$todir/$tofile");          if (! try_rename("$fromdir/$fromfile","$todir/$tofile")) Error("Rename error","Can't rename file <tt>$fromfile</tt> to <tt>$tofile</tt>",1);
1119          try_dir("$todir/.log");          try_dir("$todir/.log");
1120          try_rename("$fromdir/.log/$fromfile","$todir/.log/$tofile");          try_rename("$fromdir/.log/$fromfile","$todir/.log/$tofile");
1121          try_dir("$todir/.note");          try_dir("$todir/.note");
# Line 1203  function Download($path,$force=0) { Line 1226  function Download($path,$force=0) {
1226  //////////////////////////////////////////////////////////////////  //////////////////////////////////////////////////////////////////
1227    
1228  function chopsl($path) {  function chopsl($path) {
         if (substr($path,strlen($path)-1,1) == "/") $path=substr($path,0,strlen($path)-1);  
1229          $path=str_replace("//","/",$path);          $path=str_replace("//","/",$path);
1230            if (substr($path,strlen($path)-1,1) == "/") $path=substr($path,0,strlen($path)-1);
1231          return $path;          return $path;
1232  }  }
1233    
# Line 1218  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 1275  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 1311  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 1350  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 1361  return 1; Line 1388  return 1;
1388  }//init_trustee  }//init_trustee
1389    
1390  function in_group($user,$group) {  function in_group($user,$group) {
1391          return in_array($groups[$group],$user);          global $groups;
1392            return in_array($user,$groups[$group]);
1393  }  }
1394    
1395  // helper function  // helper function
1396  function unroll_perm($u,$t,$user,$perm) {  function unroll_perm($u,$t,$user,$perm) {
1397          // check user  
1398            // check user FIX
1399          if ($t & trmask_not && ($u==$user)) continue;          if ($t & trmask_not && ($u==$user)) continue;
1400          if (!($t & trmask_not) && ($u!=$user)) continue;          if (!($t & trmask_not) && ($u!=$user)) continue;
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;
1424    $debug .= "<br>check_trustee $path ... ";
1425    
1426          $path_arr=explode("/",$path);          $path_arr=explode("/",$path);
1427          $path = "/";          $tmppath = "/";
1428          while (count($path_arr)) {          while (count($path_arr)) {
1429                  if (substr($path,strlen($path)-1,1) != "/") $path.="/";                  $tmppath.=array_shift($path_arr);
1430                  $path.=array_shift($path_arr);  $debug.= ">> $tmppath ";
1431                  $tr = $trustees[$path];  
1432                    # clear one level flag
1433                    $perm['allow'] &= ~trmask_one_level;
1434                    $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 1402  function check_trustee($user,$path) { Line 1443  function check_trustee($user,$path) {
1443                                  unset($tr['*']);                                  unset($tr['*']);
1444                          }                          }
1445                          // then apply group policies                          // then apply group policies
1446                          foreach ($tr as $u=>$t) {                          foreach ($tr as $g=>$t) {
1447                                  if ($t & trmask_group && in_group($user,$u)) {                                  if ($t & trmask_group && in_group($user,$g)) {
1448                                          // resolv user                                          // resolv user
1449                                          $t = $t & ~trmask_group;                                          $t = $t & ~trmask_group;
1450                                          $u = $user;                                          $perm = unroll_perm($user,$t,$user, $perm);
1451                                          $perm = unroll_perm($u,$t,$user, $perm);                                          unset($tr[$g]);
                                         unset($tr[$u]);  
1452                                  }                                  }
1453                          }                          }
1454                          // then apply use policy                          // then apply user policy
1455                          if (isset($tr[$user])) {                          if (isset($tr[$user])) {
1456                                  $perm = unroll_perm($user,$tr[$user],$user, $perm);                                  $perm = unroll_perm($user,$tr[$user],$user, $perm);
1457                                  unset($tr[$user]);                                  unset($tr[$user]);
1458                          }                          }
   
1459                  }                  }
1460    $debug.="d(".display_trustee($perm['deny']).") a(".display_trustee($perm['allow']).") ";
1461    
1462          }          }
1463  #print "<br>user: $user path: $path perm: ";  $debug.="<br>check_trustee: user: $user path: $path==$tmppath perm: ";
1464  #print "d: $perm[deny] (".display_trustee($perm[deny]).") a: $perm[allow] (".display_trustee($perm[allow]).")<Br>\n";  $debug.="d: ".$perm['deny']." (".display_trustee($perm['deny']).") a: ".$perm['allow']." (".display_trustee($perm['allow']).")<Br>\n";
1465          return $perm;          return $perm;
1466  }  }
1467    
# Line 1429  function check_trustee($user,$path) { Line 1469  function check_trustee($user,$path) {
1469    
1470  function check_perm($path,$trperm) {  function check_perm($path,$trperm) {
1471          global $gblLogin,$HAVE_TRUSTEE;          global $gblLogin,$HAVE_TRUSTEE;
1472  print "<br>check_perm: <tt>$path</tt> test perm ".display_trustee($perm)."<br>\n";  
1473            global $debug;
1474    $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  print " d: $perm[deny] (".display_trustee($perm[deny]).") a: $perm[allow] (".display_trustee($perm[allow]).") perm: $trperm";  $debug.=" d: ".$perm['deny']." (".display_trustee($perm['deny']).") a: ".$perm['allow']." (".display_trustee($perm['allow']).") perm to have: $trperm (".display_trustee($trperm).")";
1480                  if ($perm[deny] & $trperm) $return=0;                  if ($perm['deny'] & $trperm) $return=0;
1481                  elseif ($perm[allow] & $trperm) $return=1;                  elseif (($perm['allow'] & $trperm) == $trperm) $return=1;
1482          }          }
1483  print " return: $return<br>\n";  $debug.=" return: $return<br>\n";
1484          return($return);          return($return);
1485  }  }
1486    
# Line 1467  function readMime() { Line 1510  function readMime() {
1510  }  }
1511    
1512  //////////////////////////////////////////////////////////////////  //////////////////////////////////////////////////////////////////
1513    
1514    // check for invalid characters in filename and dirname (.. and /)
1515    
1516    function check_dirname($file) {
1517            if (strstr($file,"..")) Error("Security violation","No parent dir <tt>..</tt> allowed in directory name <tt>$file</tt>",1);
1518    }
1519    
1520    function check_filename($file) {
1521            if (strstr($file,"..")) Error("Security violation","No parent dir <tt>..</tt> allowed in file name <tt>$file</tt>",1);
1522            if (strstr($file,"/")) Error("Security violation","No slashes <tt>/</tt> allowed in file name <tt>$file</tt>",1);
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          if (isset($STYLE) && $STYLE == "get") {          if (isset($HTTP_GET_VARS["STYLE"]) && $HTTP_GET_VARS["STYLE"] == "get") {
1558                  include("$html/docman.css");                  include("$html/docman.css");
1559                  exit;                  exit;
1560          }          }
# Line 1490  function readMime() { Line 1572  function readMime() {
1572          if (! isset($fsRealmDir)) {          if (! isset($fsRealmDir)) {
1573                  $fsRealmDir = "$gblIncDir/realm";                  $fsRealmDir = "$gblIncDir/realm";
1574          }          }
1575          $realm_config = "$fsRealmDir/$realm.conf";  
1576            // try to add dir to script name to realm var
1577            if (is_dir("$fsRealmDir/$realm/".dirname($HTTP_SERVER_VARS["SCRIPT_NAME"]))) {
1578                    $realm .= dirname($HTTP_SERVER_VARS["SCRIPT_NAME"]);
1579                    $realm_sep = "/";
1580            } else {
1581                    $realm_sep = ".";
1582            }
1583    
1584            $realm_config = $fsRealmDir."/".$realm.$realm_sep."conf";
1585    
1586          // read user-defined configuration          // read user-defined configuration
1587          if (file_exists($realm_config)) {          if (file_exists($realm_config)) {
# Line 1508  function readMime() { Line 1599  function readMime() {
1599                  Error("Configuration error","Can't find user handling module at <tt>$gblIncDir/htusers/$gblUsers.php</tt> ! Please fix <tt>$realm_config</tt>");                  Error("Configuration error","Can't find user handling module at <tt>$gblIncDir/htusers/$gblUsers.php</tt> ! Please fix <tt>$realm_config</tt>");
1600          }          }
1601    
1602            // take additional login vars
1603            HTTP_GET_VAR("relogin");
1604            HTTP_GET_VAR("force_login");
1605    
1606          // if no password, or empty password logout          // if no password, or empty password logout
1607          if (          if (
1608                  isset($gblLogin) && (                  isset($gblLogin) && (
# Line 1526  function readMime() { Line 1621  function readMime() {
1621          if (!is_dir($gblRepositoryDir)) Error("Repository dir not found","Can't find repository directory <tt>$gblRepositoryDir</tt>. Please fix that in <tt>$realm_config</tt> variable <tt>\$gblRepositoryDir</tt>.",1);          if (!is_dir($gblRepositoryDir)) Error("Repository dir not found","Can't find repository directory <tt>$gblRepositoryDir</tt>. Please fix that in <tt>$realm_config</tt> variable <tt>\$gblRepositoryDir</tt>.",1);
1622    
1623          // trustee (ACL) file configuration          // trustee (ACL) file configuration
1624          $trustee_conf="$gblIncDir/realm/$realm.trustee";          $trustee_conf="$fsRealmDir/$realm".$realm_sep."trustee";
1625          // compiled version of trustee file          // compiled version of trustee file
1626          $trustee_php="$gblRepositoryDir/.trustee.php";          $trustee_php="$gblRepositoryDir/.trustee.php";
1627          // get ACL informations          // get ACL informations
1628          $HAVE_TRUSTEE = init_trustee();          $HAVE_TRUSTEE = init_trustee();
1629    
1630          if (strtolower($gblLogin) == "anonymous" || !isset($gblPasswd)) {          if (strtolower($gblLogin) == "anonymous" || !isset($gblLogin)) {
1631                  $perm = check_trustee($gblLogin,$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";
1636                          $secHash = md5($gblLogin.$gblPasswd);                          $secHash = md5($gblLogin.$gblPasswd);
1637                          $gblUserName = "Anonymous user";                          $gblUserName = "Anonymous user";
1638                  }                  }
# Line 1547  function readMime() { Line 1643  function readMime() {
1643                  isset($relogin) && $secHash == $relogin) {                  isset($relogin) && $secHash == $relogin) {
1644                  header("WWW-authenticate: basic realm=\"$realm\"") ;                  header("WWW-authenticate: basic realm=\"$realm\"") ;
1645                  header("HTTP/1.0 401 Unauthorized") ;                  header("HTTP/1.0 401 Unauthorized") ;
1646                  Error("401 Unauthorized","No trespassing !");                  Error("401 Unauthorized","No trespassing !",0,1);
1647          }          }
1648    
1649    
1650          // read mime.types          // read mime.types
1651          readMime();          readMime();
1652    
1653          // get current directory relative to $gblFsRoot          if ($HTTP_SERVER_VARS["REQUEST_METHOD"] == "POST") {
1654          $relDir = $DIR ;        // from POST                  // take variables from server
1655          if ($relDir == "") {    // not defined in POST ?                  if (HTTP_POST_VAR("FN")) check_filename($FN);
1656                  $relDir = urldecode($D) ;  // then use GET                  if (HTTP_POST_VAR("DIR")) {
1657          }                                check_dirname($DIR);
1658                            $relDir = $DIR;
1659          $relDir=stripSlashes($relDir);                  } else {
1660                            trigger_error("Can't get DIR",E_USER_WARNING);
1661          if ($relDir == "/") $relDir = "" ;                        }
1662          // default : website root = ""                  if (HTTP_POST_VAR("RELPATH")) check_dirname($RELPATH);
1663                    HTTP_POST_VAR("T");
1664          if (strstr($relDir,"..")) Error("No updirs allowed");                  HTTP_POST_VAR("CONFIRM");
1665    
1666          // full paths contain "fs" or "Fs". Paths realitve to root of          } else {
1667          // website contain "rel" or "Rel". The script won't let you                  // get
1668          // edit anything above directory equal to http://server.com                  HTTP_GET_VAR("A");
1669          // i.e. below $gblFsRoot.                  if (HTTP_GET_VAR("D")) {
1670                            check_dirname($D);
1671                            $D=urldecode($D);
1672                            $relDir = $D;
1673                    } else {
1674                            //trigger_error("Can't get D",E_USER_WARNING);
1675                            $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
1684          $gblFsRoot = $gblRepositoryDir;          $gblFsRoot = $gblRepositoryDir;
1685          // i.e. /home/httpd/html          // i.e. /home/httpd/repository
1686    
1687          $fsDir = $gblFsRoot . $relDir ; // current directory          $fsDir = $gblFsRoot . $relDir ; // current directory
1688          if ( !is_dir($fsDir) ) Error("Dir not found",$relDir) ;          if ( !is_dir($fsDir) ) Error("Dir not found","Can't find <tt>$relDir</tt> which points to <tt>$fsDir</tt>",1) ;
1689    
1690            if ($relDir == "") $relDir="/";
1691    
1692          if (isset($HTTP_SERVER_VARS["HTTPS"]) && $HTTP_SERVER_VARS["HTTPS"] == "on") {          if (isset($HTTP_SERVER_VARS["HTTPS"]) && $HTTP_SERVER_VARS["HTTPS"] == "on") {
1693                  $webRoot  = "https://";                  $webRoot  = "https://";
# Line 1588  function readMime() { Line 1696  function readMime() {
1696          }          }
1697          $webRoot .= $HTTP_SERVER_VARS["HTTP_HOST"] . $relScriptDir;          $webRoot .= $HTTP_SERVER_VARS["HTTP_HOST"] . $relScriptDir;
1698    
1699          // take variables from server          if (HTTP_POST_VAR("POSTACTION")) switch ($POSTACTION) {
         $FN=stripSlashes($HTTP_POST_VARS["FN"]);  
         $DIR=stripSlashes($HTTP_POST_VARS["DIR"]);  
         $RELPATH=stripSlashes($HTTP_POST_VARS["RELPATH"]);  
         $T=stripSlashes($HTTP_POST_VARS["T"]);  
         $CONFIRM=stripSlashes($HTTP_POST_VARS["CONFIRM"]);  
   
         // get  
         $A=stripSlashes($HTTP_GET_VARS["A"]);  
         $D=stripSlashes($HTTP_GET_VARS["D"]);  
   
 //      if (isset($F)) Error("Document manager system error","variable $F shouldn't be set here (re-check old code)",1);  
 //      $F=stripSlashes($HTTP_SERVER_VARS["PATH_INFO"]);  
         $F=stripSlashes($HTTP_GET_VARS["F"]);  
   
         switch ($HTTP_POST_VARS["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 1615  function readMime() { Line 1708  function readMime() {
1708                  }                  }
1709    
1710                  $FILENAME = $HTTP_POST_VARS["FILENAME"];                  $FILENAME = $HTTP_POST_VARS["FILENAME"];
1711                  if (strstr($FILENAME,"/"))                  check_filename($FILENAME);
1712                          Error("Upload error","Non-conforming filename. Filename <tt>$FILENAME</tt> has slashes (<tt>/</tt>) in it.") ;  
1713                  if (! isset($FILENAME)) {       // from update file                  if (! isset($FILENAME)) {       // from update file
1714                          $target = "$fsDir/".basename($FN_name);                          $target = "$fsDir/".basename($FN);
1715                  } else {                  } else {
1716                          $target = "$fsDir/$FILENAME";                          $target = "$fsDir/$FILENAME";
1717                  }                  }
# Line 1751  function readMime() { Line 1844  function readMime() {
1844          case "RENAME" :            case "RENAME" :  
1845                  if ( $CONFIRM != "on" ) break ;                  if ( $CONFIRM != "on" ) break ;
1846    
1847                    $NEWNAME=stripSlashes($HTTP_POST_VARS["NEWNAME"]);
1848                  LogIt("$fsDir/$FN","renamed $FN to $NEWNAME",trperm_r);                  LogIt("$fsDir/$FN","renamed $FN to $NEWNAME",trperm_r);
1849                  safe_rename($fsDir,$FN,$NEWNAME);                  safe_rename($fsDir,$FN,$NEWNAME);
1850                  break ;                  break ;
1851    
1852          case "NOTE" :            case "NOTE" :  
1853                    $NOTE=stripSlashes($HTTP_POST_VARS["NOTE"]);
1854                  WriteNote("$fsDir/$FN","$NOTE");                  WriteNote("$fsDir/$FN","$NOTE");
1855                  break ;                  break ;
1856    
# Line 1769  function readMime() { Line 1864  function readMime() {
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 1782  function readMime() { Line 1877  function readMime() {
1877          // $A=Co : checkout file $D/$F          // $A=Co : checkout file $D/$F
1878          // $A=Ci : checkin file $D/$F          // $A=Ci : checkin file $D/$F
1879          // $A=V : view file (do nothing except log)          // $A=V : view file (do nothing except log)
1880          // $A=I : include file .$F.php from $gblFsRoot          // $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))
1887                            Error("Write access denied","You don't have permission to write in <tt>$relDir</tt>");
1888                  if (!is_writeable($gblFsRoot . $relDir))                  if (!is_writeable($gblFsRoot . $relDir))
1889                          Error("Write access denied",$relDir) ;                          Error("Write access denied","User <tt>$gblLogin</tt> has permission on <tt>$relDir</tt>, but directory is not writable",1);
1890                  $text  = "Use this page to upload a single " ;                  $text  = "Use this page to upload a single " ;
1891                  $text .= "file to <B>$realm</B>." ;                  $text .= "file to <B>$realm</B>." ;
1892                  StartHTML("(Upload Page)", $text) ;                  StartHTML("(Upload Page)", $text) ;
# Line 1837  function readMime() { Line 1934  function readMime() {
1934                  EndHTML() ;                  EndHTML() ;
1935                  exit;                  exit;
1936          case "I" :          case "I" :
1937                  $F=stripSlashes($F);                  if (! isset($F) || $F == "")
1938                  $inc_file="${gblFsRoot}/.${F}.php";                          Error("Can't find file to include","Your request didn't specify file to include which should be in variable <tt>F</tt> like <tt>$HTTP_SERVER_VARS[REQUEST_URI]<b>&F=include_php_file</b></tt>",1);
1939                  if (!isset($F) || $F == "" || !file_exists($inc_file)) Error("Fatal error $inc_file"); // can't find file to include                  $inc_file="$fsRealmDir/$realm".$realm_sep.$F.".php";
1940                    if (! file_exists($inc_file)) {
1941                            Error("Can't find file to include","Can't find include file <tt>$F.php</tt> in <tt>$fsRealmDir/$realm/</tt>. Meybe you should copy <tt>$gblIncDir/include_php/$F.php</tt> to <tt>$inc_file<tt> ?",1);
1942                    }
1943                  if (!is_readable($inc_file))                  if (!is_readable($inc_file))
1944                          Error("Read access to include file denied",".${F}.php");                          Error("Read access to include file denied","Can't read PHP include file <tt>$inc_file</tt>. Fix permissions on it.",1);
1945                  $text  = "Your include file should define \$text variable which holds this text and \$title variable which is page title";                  $text  = "Your include file should define \$text variable which holds this text and \$title variable which is page title";
1946                  $title = "You should define \$title variable with page title";                  $title = "You should define \$title variable with page title";
1947                  include($inc_file);                  include($inc_file);

Legend:
Removed from v.1.7  
changed lines
  Added in v.1.20

  ViewVC Help
Powered by ViewVC 1.1.26