/[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.13 by dpavlin, Sun Jul 28 11:39:59 2002 UTC revision 1.27 by dpavlin, Mon Jul 29 12:04:43 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_VAR("PHP_AUTH_USER");
94          $gblPasswd = $HTTP_SERVER_VARS[PHP_AUTH_PW];          $gblPasswd = HTTP_SERVER_VAR("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 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 {
# Line 154  function EndHTML() { Line 155  function EndHTML() {
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 ;
# Line 184  function DetailPage($fsRoot,$relDir,$fn) Line 188  function DetailPage($fsRoot,$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);
# Line 577  function Navigate($fsRoot,$relDir) { Line 582  function Navigate($fsRoot,$relDir) {
582    
583          global $gblEditable, $gblIcon, $gblModDays, $webRoot, $gblHide,          global $gblEditable, $gblIcon, $gblModDays, $webRoot, $gblHide,
584                  $gblIgnoreUnknownFileType, $gblRepositoryDir,                  $gblIgnoreUnknownFileType, $gblRepositoryDir,
585                    $gblLogin, $gblUserName, $gblDateFmt, $gblTimeFmt,
586                  $fsRealmDir, $realm, $realm_sep,                  $fsRealmDir, $realm, $realm_sep,
587                  $HTTP_GET_VARS, $html, $realm_config;                  $html, $realm_config,
588                    $HTTP_GET_VARS, $HTTP_SERVER_VARS;
589                    
590          $self     = $HTTP_SERVER_VARS["PHP_SELF"] ;          $self     = $HTTP_SERVER_VARS["PHP_SELF"] ;
591    
592          if ($relDir == "") $relDir = "/";          $relDir = chopsl($relDir)."/";
593            $fsDir = $fsRoot.$relDir;       // current directory
594    
595            if (!is_dir($fsDir)) Error("Dir not found","Directory <tt>$relDir<tt> not found on filesystem at <tt>$fsDir</tt>",1) ;
596    
597          $fsDir = $fsRoot.$relDir."/";   // current directory          global $debug;
598            $debug .= "[$gblLogin|$relDir] before >";
599    
600          if (!is_dir($fsDir)) Error("Dir not found",$relDir,1) ;          if (! check_perm($relDir,trperm_b))
601                    Error("Access denied","User <tt>$gblLogin</tt> tried to access <tt>$relDir</tt> without valid trustee.",1);
602            $debug .= "< afeter";
603    
604          $hide_items=",$gblHide,";          $hide_items=",$gblHide,";
605    
606            $dirList = array();
607            $fileList = array();
608    
609          // read directory contents          // read directory contents
610          if ( !($dir = @opendir($fsDir)) )          if ( !($dir = @opendir($fsDir)) )
611                  Error("Read Access denied",$relDir,1) ;                  Error("Read Access denied",$relDir,1) ;
# Line 614  function Navigate($fsRoot,$relDir) { Line 630  function Navigate($fsRoot,$relDir) {
630          closedir($dir) ;          closedir($dir) ;
631    
632          // scan deleted files          // scan deleted files
633          if ( $HTTP_GET_VARS["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          }          }
# Line 629  function Navigate($fsRoot,$relDir) { Line 650  function Navigate($fsRoot,$relDir) {
650    
651          // start navigation page          // start navigation page
652          $text  = "Use this page to add, delete";          $text  = "Use this page to add, delete";
653          if (! isset($HTTP_GET_VARS[show_deleted])) {          if (! isset($HTTP_GET_VARS["show_deleted"])) {
654                  $text .= ", <a href=$self?D=".urlencode($relDir)."&show_deleted=1>undelete</a>";                  $text .= ", <a href=$self?D=".urlencode($relDir)."&show_deleted=1>undelete</a>";
655          }          }
656          $text .= " or revise files on this web site." ;          $text .= " or revise files on this web site." ;
# Line 655  function Navigate($fsRoot,$relDir) { Line 676  function Navigate($fsRoot,$relDir) {
676                  return $out;                  return $out;
677          }          }
678    
679          $dsort = $HTTP_GET_VARS[dsort];          if (! HTTP_GET_VAR("dsort")) $dsort = "name"; // default directory sort
         if (! isset($dsort)) $dsort = "name";   // default directory sort  
680    
681          $dsort_arr = array(          $dsort_arr = array(
682                  "name" => array ("rname", "note"),                  "name" => array ("rname", "note"),
# Line 665  function Navigate($fsRoot,$relDir) { Line 685  function Navigate($fsRoot,$relDir) {
685                  "rnote" => array ("name", "note")                  "rnote" => array ("name", "note")
686                  );                  );
687    
688          $fsort = $HTTP_GET_VARS[fsort];          if (! HTTP_GET_VAR("fsort")) $fsort = "name"; // default directory sort
         if (! isset($fsort)) $fsort = "name";   // default directory sort  
689    
690          $fsort_arr = array(          $fsort_arr = array(
691                  "name" => array ("rname", "note", "date", "size"),                  "name" => array ("rname", "note", "date", "size"),
# Line 682  function Navigate($fsRoot,$relDir) { Line 701  function Navigate($fsRoot,$relDir) {
701          $D="D=".urlencode($relDir);          $D="D=".urlencode($relDir);
702    
703          function self_args($arr = array()) {          function self_args($arr = array()) {
704                    global $self;
705                  $arg = implode("&",$arr);                  $arg = implode("&",$arr);
706                  if ($arg) {                  if ($arg) {
707                          return $self."?".$arg;                          return $self."?".$arg;
# Line 719  function Navigate($fsRoot,$relDir) { Line 739  function Navigate($fsRoot,$relDir) {
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    
# Line 797  function Navigate($fsRoot,$relDir) { Line 824  function Navigate($fsRoot,$relDir) {
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);
# Line 805  function Navigate($fsRoot,$relDir) { Line 832  function Navigate($fsRoot,$relDir) {
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;
# Line 833  function Navigate($fsRoot,$relDir) { Line 860  function Navigate($fsRoot,$relDir) {
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    
# Line 904  function UploadPage($fsRoot, $relDir, $f Line 931  function UploadPage($fsRoot, $relDir, $f
931          global $html, $HTTP_SERVER_VARS;          global $html, $HTTP_SERVER_VARS;
932    
933          $self = $HTTP_SERVER_VARS["PHP_SELF"] ;          $self = $HTTP_SERVER_VARS["PHP_SELF"] ;
         if ($relDir == "") $relDir = "/" ;  
   
934          include("$html/UploadPage.html");          include("$html/UploadPage.html");
935    
936  } // end function UploadPage  } // end function UploadPage
# Line 947  function Error($title,$text="",$sysadmin Line 972  function Error($title,$text="",$sysadmin
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);
# Line 954  function LogIt($target,$msg, $changelog= Line 981  function LogIt($target,$msg, $changelog=
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
# Line 1025  function MoveTo($source,$folder) { Line 1051  function MoveTo($source,$folder) {
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")) {
# Line 1036  function Lock($target) { Line 1064  function Lock($target) {
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");
# Line 1085  function urlpath($url) { Line 1113  function urlpath($url) {
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))) {
# Line 1114  function safe_rename($fromdir,$fromfile, Line 1145  function safe_rename($fromdir,$fromfile,
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  }  }
# Line 1142  function rrmdir($dir) { Line 1173  function rrmdir($dir) {
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");
# Line 1161  function DisplayChangeLog($day) { Line 1195  function DisplayChangeLog($day) {
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  //////////////////////////////////////////////////////////////////  //////////////////////////////////////////////////////////////////
# Line 1190  function Download($path,$force=0) { Line 1224  function Download($path,$force=0) {
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          }          }
# Line 1202  function Download($path,$force=0) { Line 1236  function Download($path,$force=0) {
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");
# Line 1232  function chopsl($path) { Line 1266  function chopsl($path) {
1266          by Vyacheslav Zavadsky <zavadsky@braysystems.com>          by Vyacheslav Zavadsky <zavadsky@braysystems.com>
1267  */  */
1268    
1269  define(trmask_not,1 << 0);  define('trmask_not',1 << 0);
1270  define(trmask_clear,1 << 1);  define('trmask_clear',1 << 1);
1271  define(trmask_deny,1 << 2);  define('trmask_deny',1 << 2);
1272  define(trmask_one_level,1 << 3);  define('trmask_one_level',1 << 3);
1273  define(trmask_group,1 << 4);  define('trmask_group',1 << 4);
1274    
1275  define(trperm_r,1 << 5);  define('trperm_r',1 << 5);
1276  define(trperm_w,1 << 6);  define('trperm_w',1 << 6);
1277  define(trperm_b,1 << 7);  define('trperm_b',1 << 7);
1278  define(trperm_n,1 << 8);  define('trperm_n',1 << 8);
1279    
1280  $trustee_a2n = array(  $trustee_a2n = array(
1281          '!' => trmask_not,          '!' => trmask_not,
# Line 1289  if (! file_exists($trustee_conf)) { Line 1323  if (! file_exists($trustee_conf)) {
1323          $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";
1324  } elseif (file_exists($trustee_php) && !is_writable($trustee_php)) {  } elseif (file_exists($trustee_php) && !is_writable($trustee_php)) {
1325          $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";
1326  } elseif (1 || filemtime($trustee_conf) >= filemtime($trustee_php)) {  } elseif (@filemtime($trustee_conf) >= @filemtime($trustee_php)) {
1327          $fp_php=@fopen($trustee_php,"w");          $fp_php=@fopen($trustee_php,"w");
1328          fputs($fp_php,"<?php // don't edit by hand!\n");          fputs($fp_php,"<?php // don't edit by hand!\n");
1329    
# Line 1325  if (! file_exists($trustee_conf)) { Line 1359  if (! file_exists($trustee_conf)) {
1359                                                  $error.="trustee error in line '$l' [Unknown modifier '$ch']<br>\n";                                                  $error.="trustee error in line '$l' [Unknown modifier '$ch']<br>\n";
1360                                          }                                          }
1361                                  }                                  }
1362                                  $tr_arr[$path][$user] |= $perm;                                  if (isset($tr_arr[$path][$user])) {
1363                                            $tr_arr[$path][$user] |= $perm;
1364                                    } else {
1365                                            $tr_arr[$path][$user] = $perm;
1366                                    }
1367                          }                          }
1368                  }                  }
1369          }          }
# Line 1364  if (! file_exists($trustee_conf)) { Line 1402  if (! file_exists($trustee_conf)) {
1402          fclose($fp_php);          fclose($fp_php);
1403  }  }
1404    
1405  if ($error) {  if (isset($error)) {
1406          Error("Trustee error",$error,1);          Error("Trustee error",$error,1);
1407  } else {  } else {
1408          include("$trustee_php");          include_once("$trustee_php");
1409  }  }
1410    
1411  return 1;  return 1;
# Line 1375  return 1; Line 1413  return 1;
1413  }//init_trustee  }//init_trustee
1414    
1415  function in_group($user,$group) {  function in_group($user,$group) {
1416          return in_array($groups[$group],$user);          global $groups;
1417            return in_array($user,$groups[$group]);
1418  }  }
1419    
1420  // helper function  // helper function
1421  function unroll_perm($u,$t,$user,$perm) {  function unroll_perm($u,$t,$perm,$one_level) {
1422          // check user  
1423          if ($t & trmask_not && ($u==$user)) continue;          if ($t & trmask_one_level && !$one_level) return $perm;
         if (!($t & trmask_not) && ($u!=$user)) continue;  
1424    
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;
1428                  } else {                  } else {
1429                          $perm[deny] |= $t;                          $perm['deny'] |= $t;
1430                  }                  }
1431          } elseif ($t & trmask_clear) {          } elseif ($t & trmask_clear) {
1432                  $perm[allow] &= ~$t;                  $perm['allow'] &= ~$t;
1433          } else {          } else {
1434                  $perm[allow] |= $t;                  $perm['allow'] |= $t;
1435          }          }
1436          return $perm;          return $perm;
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            // 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;
1450    $debug .= "<br>check_trustee $path ... ";
1451    
1452          $path_arr=explode("/",$path);          $path_arr=explode("/",$path);
1453          $path = "/";          $tmppath = "/";
1454          while (count($path_arr)) {          while (count($path_arr)) {
1455                  if (substr($path,strlen($path)-1,1) != "/") $path.="/";                  $tmppath.=array_shift($path_arr);
1456                  $path.=array_shift($path_arr);  $debug.= ">> $tmppath ";
1457                  $tr = $trustees[$path];  
1458                    if (! isset($trustees[$tmppath])) continue;
1459                    $tr = $trustees[$tmppath];
1460    
1461                    $one_level = (!count($path_arr));
1462    $debug.=" O($one_level) ";
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['*'],$user, $perm);                                  $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 $u=>$t) {                          foreach ($tr as $g=>$t) {
1472                                  if ($t & trmask_group && in_group($user,$u)) {                                  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                                          $u = $user;                                          $perm = unroll_perm($user,$t,$perm, $one_level);
1481                                          $perm = unroll_perm($u,$t,$user, $perm);                                          unset($tr[$g]);
                                         unset($tr[$u]);  
1482                                  }                                  }
1483                          }                          }
1484                          // then apply use policy                          // then apply user policy
1485                          if (isset($tr[$user])) {                          if (isset($tr[$user])) {
1486                                  $perm = unroll_perm($user,$tr[$user],$user, $perm);                                  $perm = unroll_perm($user,$tr[$user],$perm,$one_level);
1487                                  unset($tr[$user]);                                  unset($tr[$user]);
1488                          }                          }
   
1489                  }                  }
1490    $debug.="d(".display_trustee($perm['deny']).") a(".display_trustee($perm['allow']).") ";
1491    
1492          }          }
1493  #print "<br>user: $user path: $path perm: ";  $debug.="<br>check_trustee: user: $user path: $path==$tmppath perm: ";
1494  #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";
1495          return $perm;          return $perm;
1496  }  }
1497    
# Line 1444  function check_trustee($user,$path) { Line 1500  function check_trustee($user,$path) {
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: <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";
1507    
1508          $return = ! $HAVE_TRUSTEE;          $return = ! $HAVE_TRUSTEE;
1509          if ($HAVE_TRUSTEE) {          if ($HAVE_TRUSTEE) {
1510                  $perm = check_trustee($gblLogin,$path);                  $perm = check_trustee($gblLogin,$path);
1511  $debug.=" 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).")";
1512                  if ($perm[deny] & $trperm) $return=0;                  if ($perm['deny'] & $trperm) $return=0;
1513                  elseif ($perm[allow] & $trperm) $return=1;                  elseif (($perm['allow'] & $trperm) == $trperm) $return=1;
1514          }          }
1515  $debug.=" return: $return<br>\n";  $debug.=" return: $return<br>\n";
1516          return($return);          return($return);
# Line 1492  function check_dirname($file) { Line 1551  function check_dirname($file) {
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
1571    // [replacement for register_globals in php.ini]
1572    
1573    function HTTP_GET_VAR($var) {
1574            global $HTTP_GET_VARS, ${$var};
1575            if (isset($HTTP_GET_VARS[$var])) {
1576                    $$var = stripSlashes($HTTP_GET_VARS[$var]);
1577                    return $$var;
1578            }
1579    }
1580    
1581    function HTTP_POST_VAR($var) {
1582            global $HTTP_POST_VARS, ${$var};
1583            if (isset($HTTP_POST_VARS[$var])) {
1584                    $$var = $HTTP_POST_VARS[$var];
1585                    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    
1597    //////////////////////////////////////////////////////////////////
1598    
1599    function Warn($text) {
1600    }
1601    
1602  //////////////////////////////////////////////////////////////////  //////////////////////////////////////////////////////////////////
1603  // MAIN PROGRAM  // MAIN PROGRAM
1604    
1605          $gblFilePerms = 0640 ;         // default for new files          $gblFilePerms = 0640 ;         // default for new files
1606          $gblDirPerms  = 0750 ;          // default for new dirs          $gblDirPerms  = 0750 ;          // default for new dirs
1607    
1608          $STYLE = $HTTP_GET_VARS[STYLE];          if (isset($HTTP_GET_VARS["STYLE"]) && $HTTP_GET_VARS["STYLE"] == "get") {
         if (isset($STYLE) && $STYLE == "get") {  
1609                  include("$html/docman.css");                  include("$html/docman.css");
1610                  exit;                  exit;
1611          }          }
# Line 1510  function check_filename($file) { Line 1613  function check_filename($file) {
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);
# Line 1522  function check_filename($file) { Line 1625  function check_filename($file) {
1625          }          }
1626    
1627          // try to add dir to script name to realm var          // try to add dir to script name to realm var
1628          if (is_dir("$fsRealmDir/$realm/".dirname($HTTP_SERVER_VARS[SCRIPT_NAME]))) {          if (is_dir("$fsRealmDir/$realm/".dirname($HTTP_SERVER_VARS["SCRIPT_NAME"]))) {
1629                  $realm .= "/".dirname($HTTP_SERVER_VARS[SCRIPT_NAME]);                  $realm .= dirname($HTTP_SERVER_VARS["SCRIPT_NAME"]);
1630                  $realm_sep = "/";                  $realm_sep = "/";
1631          } else {          } else {
1632                  $realm_sep = ".";                  $realm_sep = ".";
# Line 1547  function check_filename($file) { Line 1650  function check_filename($file) {
1650                  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>");
1651          }          }
1652    
1653            // take additional login vars
1654            HTTP_GET_VAR("relogin");
1655            HTTP_GET_VAR("force_login");
1656    
1657          // if no password, or empty password logout          // if no password, or empty password logout
1658          if (          if (
1659                  isset($gblLogin) && (                  isset($gblLogin) && (
# Line 1571  function check_filename($file) { Line 1678  function check_filename($file) {
1678          // get ACL informations          // get ACL informations
1679          $HAVE_TRUSTEE = init_trustee();          $HAVE_TRUSTEE = init_trustee();
1680    
1681          if (strtolower($gblLogin) == "anonymous" || !isset($gblPasswd)) {          if (strtolower($gblLogin) == "anonymous" || !isset($gblLogin)) {
1682                  $perm = check_trustee($gblLogin,$path);                  $perm = check_trustee("anonymous","/");
1683                  // browsing must be explicitly allowed for root directory                  // browsing must be explicitly allowed for root directory
1684                  // of repository for anonymous user to work!                  // of repository for anonymous user to work!
1685                  if ($perm[allow] & trperm_b) {                  if ($perm['allow'] & trperm_b) {
1686                            $gblLogin = $gblPasswd = "anonymous";
1687                          $secHash = md5($gblLogin.$gblPasswd);                          $secHash = md5($gblLogin.$gblPasswd);
1688                          $gblUserName = "Anonymous user";                          $gblUserName = "Anonymous user";
1689                  }                  }
# Line 1593  function check_filename($file) { Line 1701  function check_filename($file) {
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                  $FN=stripSlashes($HTTP_POST_VARS["FN"]);                  if (HTTP_POST_VAR("FN"))
1709                  $DIR=stripSlashes($HTTP_POST_VARS["DIR"]);                          check_filename($FN);
1710                  $RELPATH=stripSlashes($HTTP_POST_VARS["RELPATH"]);                  if (HTTP_POST_VAR("DIR")) {
1711                  $T=stripSlashes($HTTP_POST_VARS["T"]);                          check_dirname($DIR);
1712                  $CONFIRM=stripSlashes($HTTP_POST_VARS["CONFIRM"]);                          $relDir = $DIR;
1713                    } else {
1714                  check_filename($FN);                          trigger_error("Can't get DIR",E_USER_WARNING);
1715                  check_dirname($DIR);                          $relDir = "/";
1716                  check_dirname($RELPATH);                  }
1717                    if (HTTP_POST_VAR("RELPATH")) check_dirname($RELPATH);
1718                  $relDir = $DIR;                  HTTP_POST_VAR("T");
1719                    HTTP_POST_VAR("CONFIRM");
1720          } else {          } else {
1721                  // get                  // get
1722                  $A=stripSlashes($HTTP_GET_VARS["A"]);                  HTTP_GET_VAR("A");
1723                  $D=stripSlashes(urldecode($HTTP_GET_VARS["D"]));                  if (HTTP_GET_VAR("D")) {
1724                  $F=stripSlashes($HTTP_GET_VARS["F"]);                          check_dirname($D);
1725                            $D=urldecode($D);
1726                  check_filename($F);                          $relDir = $D;
1727                  check_dirname($D);                  } else {
1728                            //trigger_error("Can't get D",E_USER_WARNING);
1729                  $relDir = $D;                          $relDir = "/";
1730                    }
1731                    if (HTTP_GET_VAR("F")) check_filename($F);
1732          }          }
1733    
1734          if ($relDir == "/") $relDir = "" ;                $relScriptDir = dirname($HTTP_SERVER_VARS["SCRIPT_NAME"]) ;    
   
         $relScriptDir = dirname($SCRIPT_NAME) ;          
1735          // i.e. /docman          // i.e. /docman
1736    
1737          // start on server root          // start on server root
# Line 1628  function check_filename($file) { Line 1739  function check_filename($file) {
1739          // i.e. /home/httpd/repository          // i.e. /home/httpd/repository
1740    
1741          $fsDir = $gblFsRoot . $relDir ; // current directory          $fsDir = $gblFsRoot . $relDir ; // current directory
1742          if ( !is_dir($fsDir) ) Error("Dir not found",$relDir,1) ;          if ( !is_dir($fsDir) ) Error("Dir not found","Can't find <tt>$relDir</tt> which points to <tt>$fsDir</tt>",1) ;
1743    
1744            if ($relDir == "") $relDir="/";
1745    
1746          if (isset($HTTP_SERVER_VARS["HTTPS"]) && $HTTP_SERVER_VARS["HTTPS"] == "on") {          if (isset($HTTP_SERVER_VARS["HTTPS"]) && $HTTP_SERVER_VARS["HTTPS"] == "on") {
1747                  $webRoot  = "https://";                  $webRoot  = "https://";
# Line 1637  function check_filename($file) { Line 1750  function check_filename($file) {
1750          }          }
1751          $webRoot .= $HTTP_SERVER_VARS["HTTP_HOST"] . $relScriptDir;          $webRoot .= $HTTP_SERVER_VARS["HTTP_HOST"] . $relScriptDir;
1752    
1753          switch ($HTTP_POST_VARS["POSTACTION"]) {          if (HTTP_POST_VAR("POSTACTION")) switch ($POSTACTION) {
1754          case "UPLOAD" :          case "UPLOAD" :
1755                  $FN_name=stripSlashes($HTTP_POST_FILES["FN"]["tmp_name"]);                  $FN_name=stripSlashes($HTTP_POST_FILES["FN"]["tmp_name"]);
1756                  $FN=stripSlashes($HTTP_POST_FILES["FN"]["name"]);                  $FN=stripSlashes($HTTP_POST_FILES["FN"]["name"]);
# Line 1648  function check_filename($file) { Line 1761  function check_filename($file) {
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);
# Line 1662  function check_filename($file) { Line 1774  function check_filename($file) {
1774                  if (! file_exists($dir."/.bak")) {                  if (! file_exists($dir."/.bak")) {
1775                          mkdir($dir."/.bak",0700);                          mkdir($dir."/.bak",0700);
1776                  }                  }
1777                  if (! file_exists($dir."/.bak/$GLOBALS[gblNumBackups]")) {                  if (! file_exists($dir."/.bak/$gblNumBackups")) {
1778                          mkdir($dir."/.bak/$GLOBALS[gblNumBackups]",0700);                          mkdir($dir."/.bak/$gblNumBackups",0700);
1779                  }                  }
1780                  $file=basename($target);                  $file=basename($target);
1781                  for($i=$GLOBALS[gblNumBackups]-1;$i>0;$i--) {                  for($i=$gblNumBackups-1;$i>0;$i--) {
1782                          MoveTo("$dir/.bak/$i/$file","$dir/.bak/".($i+1)."/");                          MoveTo("$dir/.bak/$i/$file","$dir/.bak/".($i+1)."/");
1783                  }                  }
1784                  MoveTo($target,$dir."/.bak/1/");                  MoveTo($target,$dir."/.bak/1/");
# Line 1692  function check_filename($file) { Line 1804  function check_filename($file) {
1804                  if (!($writable || (!$exists && $legaldir)))                  if (!($writable || (!$exists && $legaldir)))
1805                          Error("Write denied",$RELPATH) ;                          Error("Write denied",$RELPATH) ;
1806                  $fh = fopen($path, "w") ;                  $fh = fopen($path, "w") ;
1807                  $FILEDATA=stripSlashes($FILEDATA);                  HTTP_POST_VAR("FILEDATA");
1808                  fwrite($fh,$FILEDATA) ;                  fwrite($fh,$FILEDATA) ;
1809                  fclose($fh) ;                  fclose($fh) ;
1810                  clearstatcache() ;                  clearstatcache() ;
# Line 1701  function check_filename($file) { Line 1813  function check_filename($file) {
1813    
1814          case "CREATE" :          case "CREATE" :
1815                  // we know $fsDir exists                  // we know $fsDir exists
1816                  if ($FN == "") break;           // no filename!                  if (! check_perm($relDir, trperm_w))
1817                  if (!is_writeable($fsDir)) Error("Write denied",$relDir) ;                          Error("Write access denied","You don't have permission to write in <tt>$relDir</tt>");
1818                  $path = $fsDir . "/" . $FN ;  // file or dir to create                  if ($T == "D") $type = "directory";
1819                  $relPath = $relDir . "/" . $FN ;                  else $type ="file";
1820                    if ($FN == "") Error("Can't create $type","You must enter name of $type to create it.");
1821                    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) ;
1822                    $path = "$fsDir/$FN";           // file or dir to create
1823                    $relPath = "$relDir/$FN";
1824    
1825                    if (file_exists($path))
1826                            Error("Can't create $type","Object <tt>$relPath</tt> allready exists");
1827    
1828                  switch ( $T ) {                  switch ( $T ) {
1829                  case "D" :  // create a directory                  case "D" :  // create a directory
1830                          if ( ! @mkdir($path,$gblDirPerms) )                          if ( ! @mkdir($path,$gblDirPerms) )
# Line 1718  function check_filename($file) { Line 1838  function check_filename($file) {
1838  // better keep it here altogether  // better keep it here altogether
1839  // chmod perms to $gblFilePerms  // chmod perms to $gblFilePerms
1840                          if ( file_exists($path) && !is_writeable($path) )                          if ( file_exists($path) && !is_writeable($path) )
1841                                  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) ;
1842                          $fh = fopen($path, "w+") ;                          $fh = fopen($path, "w+") ;
1843                          if ($fh) {                          if ($fh) {
1844                                  fputs($fh,"\n");                                  fputs($fh,"\n");
1845                                  fclose($fh) ;                                  fclose($fh) ;
1846                                  LogIt($path,"file created",trperm_r | trperm_w);                                  LogIt($path,"file created",trperm_r | trperm_w);
1847                          } else {                          } else {
1848                                  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) ;
1849                          }                          }
1850                          $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) ;
1851                          header("Location: " . $tstr) ;                          header("Location: " . $tstr) ;
1852                          exit ;                          exit ;
1853                  }                  }
1854                  break ;                  break ;
1855    
1856          case "DELETE" :            case "DELETE" :  
1857                  if ( $CONFIRM != "on" ) break ;                  if ( $CONFIRM != "on" ) break;
1858    
1859                  $tstr  = "Attempt to delete non-existing object or " ;                  if ( isset($FN) && $FN != "") {
1860                  $tstr .= "insufficient privileges: " ;                          $path=$fsDir."/".$FN;
1861                            $what = "file";
1862                    } elseif (isset($DIR)) {
1863                            $path=$gblFsRoot."/".$DIR;
1864                            $what = "directory";
1865                    } else  {
1866                            Error("Can't delete object","Can't find filename <tt>\$FN</tt> or dirname in <tt>\$DIR</tt>",1);
1867                    }
1868    
1869                  if ( $FN != "") {  // delete file                  if (! check_perm("$relDir/$FN", trperm_w))
1870                          $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);  
                         }  
1871    
1872  //                      if ( ! @unlink($path) ) {                  $tstr  = "Attempt to delete non-existing object or insufficient privileges: " ;
1873                          if ( ! rename($path,"$dir/.del/$file") ) {  
1874                                  LogIt($path,"file delete failed");                  $dir=dirname($path);
1875                                  Error("File delete failed", $tstr . $path) ;                  $file=basename($path);
1876                          } else {  
1877                                  LogIt($path,"file deleted",trperm_w);                  if (! file_exists("$dir/.del")) {
1878                                  MoveTo("$dir/.log/$file","$dir/.del/.log/");                          mkdir("$dir/.del",0700);
1879                                  MoveTo("$dir/.note/$file","$dir/.del/.note/");                  }
1880                                  MoveTo("$dir/.lock/$file","$dir/.del/.lock/");  
1881                          }                  if ( ! @rename($path,"$dir/.del/$file") ) {
1882                  } else {  // delete directory                          LogIt($path,"$what delete failed");
1883                          if ( ! @rrmdir($fsDir) ) {                          Error("Can't delete $what",$tstr."<tt>".$relDir."/".$FN."</tt>") ;
1884                                  Error("Rmdir failed", $tstr . $fsDir) ;                  } else {
1885                          } else {                          LogIt($path,"$what deleted",trperm_w);
1886                                  LogIt($path,"dir deleted",trperm_w);                          MoveTo("$dir/.log/$file","$dir/.del/.log/");
1887                                  $relDir = dirname($relDir) ;  // move up                          MoveTo("$dir/.note/$file","$dir/.del/.note/");
1888                          }                          MoveTo("$dir/.lock/$file","$dir/.del/.lock/");
1889                  }                  }
1890                  break ;                  break ;
1891    
# Line 1785  function check_filename($file) { Line 1906  function check_filename($file) {
1906          case "RENAME" :            case "RENAME" :  
1907                  if ( $CONFIRM != "on" ) break ;                  if ( $CONFIRM != "on" ) break ;
1908    
1909                  $NEWNAME=stripSlashes($HTTP_POST_VARS["NEWNAME"]);                  if (HTTP_POST_VAR("NEWNAME")) {
1910                            $dest = remove_parent($relDir.$NEWNAME);
1911                            if (! check_perm($relDir.$FN, trperm_w) ||
1912                                ! check_perm($dest, trperm_w) )
1913                                    Error("Access denied","User <tt>$gblLogin</tt> tried to rename <tt>$relDir$FN</tt> to <tt>$dest</tt> without valid trustee.",1);
1914                    } else {
1915                            Error("Rename error","Can't find new name in var <tt>\$NEWNAME</tt>",1);
1916                    }
1917                  LogIt("$fsDir/$FN","renamed $FN to $NEWNAME",trperm_r);                  LogIt("$fsDir/$FN","renamed $FN to $NEWNAME",trperm_r);
1918                  safe_rename($fsDir,$FN,$NEWNAME);                  safe_rename($fsDir,$FN,$NEWNAME);
1919                  break ;                  break ;
# Line 1805  function check_filename($file) { Line 1933  function check_filename($file) {
1933          }          }
1934    
1935          // common to all POSTs : redirect to directory view ($relDir)          // common to all POSTs : redirect to directory view ($relDir)
1936          if ( $POSTACTION != "" ) {          if (isset($POSTACTION)) {
1937                  $tstr = $PHP_SELF . "?D=" . urlencode($relDir) ;                  $tstr = $HTTP_SERVER_VARS["PHP_SELF"]."?D=".urlencode($relDir);
1938                  header("Location: " . $tstr) ;                    header("Location: ".$tstr) ;  
1939                  exit ;                  exit ;
1940          }          }
1941                    
# Line 1818  function check_filename($file) { Line 1946  function check_filename($file) {
1946          // $A=Co : checkout file $D/$F          // $A=Co : checkout file $D/$F
1947          // $A=Ci : checkin file $D/$F          // $A=Ci : checkin file $D/$F
1948          // $A=V : view file (do nothing except log)          // $A=V : view file (do nothing except log)
1949          // $A=I : include file .$F.php from $gblFsRoot          // $A=I : include file .$F.php from [$gblIncDir|realm]/include_php
1950          // default : display directory $D          // default : display directory $D
1951    
1952          switch ($A) {          if (isset($A)) switch ($A) {
1953          case "U" :          case "U" :
1954                  // upload to $relDir                  // upload to $relDir
1955                    if (! check_perm($relDir, trperm_w))
1956                            Error("Write access denied","You don't have permission to write in <tt>$relDir</tt>");
1957                  if (!is_writeable($gblFsRoot . $relDir))                  if (!is_writeable($gblFsRoot . $relDir))
1958                          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);
1959                  $text  = "Use this page to upload a single " ;                  $text  = "Use this page to upload a single " ;
1960                  $text .= "file to <B>$realm</B>." ;                  $text .= "file to <B>$realm</B>." ;
1961                  StartHTML("(Upload Page)", $text) ;                  StartHTML("(Upload Page)", $text) ;
# Line 1873  function check_filename($file) { Line 2003  function check_filename($file) {
2003                  EndHTML() ;                  EndHTML() ;
2004                  exit;                  exit;
2005          case "I" :          case "I" :
2006                  $F=stripSlashes($F);                  if (! isset($F) || $F == "")
2007                  $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);
2008                  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";
2009                    if (! file_exists($inc_file)) {
2010                            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);
2011                    }
2012                  if (!is_readable($inc_file))                  if (!is_readable($inc_file))
2013                          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);
2014                  $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";
2015                  $title = "You should define \$title variable with page title";                  $title = "You should define \$title variable with page title";
2016                  include($inc_file);                  include($inc_file);

Legend:
Removed from v.1.13  
changed lines
  Added in v.1.27

  ViewVC Help
Powered by ViewVC 1.1.26