/[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.2 by dpavlin, Thu Jul 25 21:16:08 2002 UTC revision 1.18 by dpavlin, Sun Jul 28 16:24:54 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";
27    
28          // force download (so it won't open in associated application)          // force download on view (so it won't open in associated application)
29          $gblForceDownload = 1;          $gblForceDownload = 0;
30    
31          // date format          // date format
32          $gblDateFmt="Y-m-d";          $gblDateFmt="Y-m-d";
# 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_HOST";    // FIX          $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>");          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 = $PHP_AUTH_USER;          $gblLogin = $HTTP_SERVER_VARS[PHP_AUTH_USER];
94          $gblPasswd = $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;          global $html,$fsDocumentRoot,$HTTP_SERVER_VARS;
113    
114          $title = $gblTitle." ".$title ;          $title = $gblTitle." ".$title ;
115          $host  = $GLOBALS["HTTP_HOST"] ;          $host  = $HTTP_SERVER_VARS["HTTP_HOST"] ;
116          $self  = $GLOBALS["PHP_SELF"] ;          $self  = $HTTP_SERVER_VARS["PHP_SELF"] ;
117    
118          if (file_exists("$fsDocumentRoot/docman.css")) {          if (file_exists("$fsDocumentRoot/docman.css")) {
119                  $css=dirname($self)."/docman.css";                  $css=dirname($self)."/docman.css";
120          } else {          } else {
121                  $css=$self."?STYLE=get&css=$css";                  $css=$self."?STYLE=get";
122          }          }
123    
124          include("$html/head.html");          include("$html/head.html");
# Line 138  function EndHTML() { Line 138  function EndHTML() {
138          } else {          } else {
139                  $url .= md5($gblLogin.$gblPasswd);                  $url .= md5($gblLogin.$gblPasswd);
140          }          }
141          if (isset($gblLogin) && $gblLogin != "" && ($gblPasswd == "" || !isset($gblPasswd))) {          if ( (  (isset($gblLogin) && $gblLogin != "") ||
142                    (!isset($gblLogin) || $gblLogin == "")
143                 ) && ($gblPasswd == "" || !isset($gblPasswd))) {
144                  $url_title="login";                  $url_title="login";
145                  $url .= "&force_login=1";                  $url .= "&force_login=1";
146          } else {          } else {
147                  $url_title="relogin";                  $url_title="relogin";
148          }          }
149          include("$html/footer.html");          include("$html/footer.html");
150          //phpinfo();  
151            global $debug;
152            if ($debug) print $debug;
153  } // end function EndHTML  } // end function EndHTML
154    
155  //////////////////////////////////////////////////////////////////  //////////////////////////////////////////////////////////////////
156    
157  function DetailPage($fsRoot,$relDir,$fn) {  function DetailPage($fsRoot,$relDir,$fn) {
158                    
159          global $gblEditable, $gblImages, $webRoot, $html ;          global $gblEditable, $gblImages, $webRoot, $html, $HTTP_SERVER_VARS ;
160          $self = $GLOBALS["PHP_SELF"] ;          $self = $HTTP_SERVER_VARS["PHP_SELF"] ;
161    
162          $relPath  = $relDir . "/" . $fn ;          $relPath  = $relDir . "/" . $fn ;
163          $fsPath   = $fsRoot . $relPath ;          $fsPath   = $fsRoot . $relPath ;
# Line 161  function DetailPage($fsRoot,$relDir,$fn) Line 165  function DetailPage($fsRoot,$relDir,$fn)
165    
166          $exists   = file_exists($fsPath) ;          $exists   = file_exists($fsPath) ;
167          $ext      = strtolower(strrchr($relPath,".")) ;          $ext      = strtolower(strrchr($relPath,".")) ;
168          $editable = ( $ext=="" || strstr(join(" ",$gblEditable),$ext)) ;          $editable = ( $ext=="" || strstr(join(" ",$gblEditable),$ext)) &&
169          $writable = is_writeable($fsPath) ;                  check_perm($relPath,trperm_w);
170            $writable = is_writeable($fsPath) && check_perm($relPath,trperm_w) ;
171            $writable_dir = is_writeable($fsDir) && check_perm($relDir,trperm_w) ;
172          $file_lock = CheckLock($fsPath);          $file_lock = CheckLock($fsPath);
173    
174          if (!$editable && !$exists)          if (!$editable && !$exists)
175                  Error(_("Creation unsupported for type"),$relPath) ;                  Error("Creation denied","Can't create <tt>$relPath</tt>") ;
176          if (!exists && !is_writeable($fsDir) )          if (!$exists && !$writable_dir )
177                  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);
178    
179          $text  = _("Use this page to view, modify or ") ;          $text  = _("Use this page to view, modify or ") ;
180          if (is_dir($fsPath)) {          if (is_dir($fsPath)) {
# Line 201  function DetailPage($fsRoot,$relDir,$fn) Line 207  function DetailPage($fsRoot,$relDir,$fn)
207                  $fstr = htmlentities( $fstr ) ;                  $fstr = htmlentities( $fstr ) ;
208  ?>  ?>
209    
210  <FORM ACTION="<?= $self ; ?>" METHOD="POST">  <FORM ACTION="<?= $self ?>" METHOD="POST">
211  <SPAN TITLE="Click [SAVE] to store updated contents.">  <SPAN TITLE="Click [SAVE] to store updated contents.">
212          <B>DOCUMENT CONTENTS</B>          <B>DOCUMENT CONTENTS</B>
213  </SPAN><BR>  </SPAN><BR>
# Line 572  function GifIcon($txt) { Line 578  function GifIcon($txt) {
578  function Navigate($fsRoot,$relDir) {  function Navigate($fsRoot,$relDir) {
579    
580          global $gblEditable, $gblIcon, $gblModDays, $webRoot, $gblHide,          global $gblEditable, $gblIcon, $gblModDays, $webRoot, $gblHide,
581                  $HTTP_GET_VARS, $html;                  $gblIgnoreUnknownFileType, $gblRepositoryDir,
582                    $fsRealmDir, $realm, $realm_sep,
583                    $HTTP_GET_VARS, $html, $realm_config;
584            
585            $self     = $HTTP_SERVER_VARS["PHP_SELF"] ;
586    
587          $self     = $GLOBALS["PHP_SELF"] ;          $relDir = chopsl($relDir)."/";
588            $fsDir = $fsRoot.$relDir;       // current directory
589    
590          if ($relDir == "") $relDir = "/";          if (!is_dir($fsDir)) Error("Dir not found","Directory <tt>$relDir<tt> not found on filesystem at <tt>$fsDir</tt>",1) ;
591    
592          $fsDir = $fsRoot.$relDir."/";   // current directory          global $debug;
593            $debug .= "[$gblLogin|$relDir] before >";
594    
595          if (!is_dir($fsDir)) Error("Dir not found",$relDir) ;          if (! check_perm($relDir,(trperm_b | trperm_r)))
596                    Error("Access denied","User <tt>$gblLogin</tt> tried to access <tt>$relDir</tt> without valid trustee.",1);
597            $debug .= "< afeter";
598    
599          $hide_items=",$gblHide,";          $hide_items=",$gblHide,";
600    
 #display_all_trustee();  
 print "-- $fsDir --";  
   
601          // read directory contents          // read directory contents
602          if ( !($dir = @opendir($fsDir)) )          if ( !($dir = @opendir($fsDir)) )
603                  Error("Read Access denied",$relDir) ;                  Error("Read Access denied",$relDir,1) ;
604          while ($item = readdir($dir)) {          while ($item = readdir($dir)) {
 print "$item, ";  
605                  if ( substr($item,0,1) == "." || strstr($hide_items,",$item,") ) continue ;                  if ( substr($item,0,1) == "." || strstr($hide_items,",$item,") ) continue ;
606                  if ((is_dir($fsDir.$item) || is_link ($fsDir.$item)) && check_perm($relDir.$item,trperm_b)) {                  if (is_dir($fsDir.$item) || is_link ($fsDir.$item)) {
607                          $dirList[$item] = $item ;                          if (check_perm($relDir.$item,trperm_b)) {
608                          $dirNote[$item] = ReadNote($fsDir.$item);                                  $dirList[$item] = $item ;
609                  } else if ( is_file($fsDir.$item) && check_perm($relDir.$item,trperm_r) ) {                                  $dirNote[$item] = ReadNote($fsDir.$item);
610                          $fileList[$item] = $item ;                                        }
611                          $fileDate[$item] = filemtime($fsDir.$item) ;                  } else if (is_file($fsDir.$item)) {
612                          $fileSize[$item] = filesize($fsDir.$item) ;                          if (check_perm($relDir.$item,trperm_r)) {
613                          $fileNote[$item] = ReadNote($fsDir.$item);                                  $fileList[$item] = $item ;              
614                                    $fileDate[$item] = filemtime($fsDir.$item) ;
615                                    $fileSize[$item] = filesize($fsDir.$item) ;
616                                    $fileNote[$item] = ReadNote($fsDir.$item);
617                            }
618                  } else {                  } else {
619                    // unknown file type                          if (! $gblIgnoreUnknownFileType) Error("File Type Error", "Item <tt>".$fsDir.$item."</tt> is not file, directory or link. If you want to ignore errors like this, set <tt>\$gblIgnoreUnknownFileType = 1</tt> in <tt>$realm_config</tt>.",1);
                   // $text = "Could not determine file type of " ;  
                   // Error("File Error", $text.$relDir."/".$item) ;  
                   // exit ;  
620                  }                  }
621          }          }
622          closedir($dir) ;          closedir($dir) ;
623    
624          // scan deleted files          // scan deleted files
625          if ( $GLOBALS[show_deleted] == 1 && ($dir = @opendir("$fsDir/.del")) ) {          if ( $HTTP_GET_VARS["show_deleted"] == 1 && ($dir = @opendir("$fsDir/.del")) ) {
626                  while ($item = readdir($dir)) {                  while ($item = readdir($dir)) {
627                          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 ;
628                          $fileList[$item] = ".del/$item" ;                                        $fileList[$item] = ".del/$item" ;              
# Line 626  print "$item, "; Line 637  print "$item, ";
637    
638          // start navigation page          // start navigation page
639          $text  = "Use this page to add, delete";          $text  = "Use this page to add, delete";
640          if (! isset($show_deleted)) {          if (! isset($HTTP_GET_VARS[show_deleted])) {
641                  $text .= ", <a href=$self?D=".urlencode($relDir)."&show_deleted=1>undelete</a>";                  $text .= ", <a href=$self?D=".urlencode($relDir)."&show_deleted=1>undelete</a>";
642          }          }
643          $text .= " or revise files on this web site." ;          $text .= " or revise files on this web site." ;
# Line 636  print "$item, "; Line 647  print "$item, ";
647          echo "<TABLE BORDER=0 CELLPADDING=2          echo "<TABLE BORDER=0 CELLPADDING=2
648                  CELLSPACING=3 WIDTH=\"100%\">" ;                  CELLSPACING=3 WIDTH=\"100%\">" ;
649    
650          // updir bar              // updir (parent) bar  
651          if (chopsl($fsDir) != chopsl($fsRoot)) {          if (chopsl($fsDir) != chopsl($fsRoot)) {
652                  $parent = dirname($relDir) ;                  $parent = dirname($relDir) ;
653                  if ($parent == "") $parent = "/" ;                  if ($parent == "") $parent = "/" ;
# Line 716  print "$item, "; Line 727  print "$item, ";
727                          $dir = $dirList[$key];                          $dir = $dirList[$key];
728    
729                          $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));
730                          $dir_url=$self."?D=".urlencode($relDir."/".$dir);                          $dir_url=$self."?D=".urlencode(chopsl($relDir)."/".$dir);
731                          include("$html/Navigate-dirEntry.html");                          include("$html/Navigate-dirEntry.html");
732    
733                  }  // iterate over dirs                  }  // iterate over dirs
# Line 788  print "$item, "; Line 799  print "$item, ";
799    
800                  $file_lock=CheckLock($path);                  $file_lock=CheckLock($path);
801    
802                  $file_url_html="<A HREF=\"$self?A=V&F=".urlencode($file);                  $file_url_html="<A HREF=\"$self?A=V&D=".urlencode($relDir)."&F=".urlencode($file);
                 $file_url_html.="&D=".urlencode($relDir);  
803                  $file_url_html.="\" TITLE=\"View file\">" ;                  $file_url_html.="\" TITLE=\"View file\">" ;
804    
805                  if (substr($file,0,5) != ".del/") {                  if (substr($file,0,5) != ".del/") {
# Line 804  print "$item, "; Line 814  print "$item, ";
814    
815                  if ($file_lock) {                  if ($file_lock) {
816                          if ($file_lock == $GLOBALS[gblUserName]) {                          if ($file_lock == $GLOBALS[gblUserName]) {
817                                  $b.="<A HREF=\"$self?A=Ci&F=".urlencode($file);                                  $b.="<A HREF=\"$self?A=Ci&D=".urlencode($relDir)."&F=".urlencode($file);
                                 $b.="&D=".urlencode($relDir);  
818                                  $b.="\" TITLE=\"Checkin (update) file on server\">" ;                                  $b.="\" TITLE=\"Checkin (update) file on server\">" ;
819                                  $file_url_html=$b;                                  $file_url_html=$b;
820                                  $b.=$gblIcon("checkin")."</A>" ;                                  $b.=$gblIcon("checkin")."</A>" ;
# Line 819  print "$item, "; Line 828  print "$item, ";
828                                  $file_url_html = "$file $a";                                  $file_url_html = "$file $a";
829                          }                          }
830                  } else {                  } else {
831                          $b.="<A HREF=\"$self?A=Co&F=".urlencode($file);                          $b.="<A HREF=\"$self?A=Co&D=".urlencode($relDir)."&F=".urlencode($file);
                         $b.="&D=".urlencode($relDir);  
832                          $b.="\" TITLE=\"Checkout file for edit\">" ;                          $b.="\" TITLE=\"Checkout file for edit\">" ;
833                          $b.=$gblIcon("checkout")."</A>" ;                          $b.=$gblIcon("checkout")."</A>";
834    
835                          if ( $ext=="" || strstr(join(" ",$gblEditable),$ext) ) {                            if ( $ext=="" || strstr(join(" ",$gblEditable),$ext) ) {  
836                                  $b.="<A HREF=\"$self?A=C&F=".urlencode($file);                                  $b.="<A HREF=\"$self?A=C&D=".urlencode($relDir)."&F=".urlencode($file);
                                 $b.="&D=".urlencode($relDir);  
837                                  $b.="\" TITLE=\"List contents\">" ;                                  $b.="\" TITLE=\"List contents\">" ;
838                                  $b.=$gblIcon("view")."</A>" ;                                  $b.=$gblIcon("view")."</A>" ;
839                          } else {                          } else {
# Line 866  print "$item, "; Line 873  print "$item, ";
873  <TR><TD></TD><TD COLSPAN=5><HR></TD></TR>  <TR><TD></TD><TD COLSPAN=5><HR></TD></TR>
874    
875  <?  <?
876  if (file_exists(".info.inc")) {  
877    if (file_exists("$fsRealmDir/$realm".$realm_sep."info.inc")) {
878            print "<TR><TD></TD><TD COLSPAN=5>";
879            include("$fsRealmDir/$realm".$realm_sep."info.inc");
880            print "</TD></TR><TR><TD></TD><TD COLSPAN=5><HR></TD></TR>";
881    } elseif (file_exists("$gblRepositoryDir/.info.inc")) {
882          print "<TR><TD></TD><TD COLSPAN=5>";          print "<TR><TD></TD><TD COLSPAN=5>";
883          include(".info.inc");          include("$gblRepositoryDir/.info.inc");
884          print "</TD></TR>          print "</TD></TR><TR><TD></TD><TD COLSPAN=5><HR></TD></TR>";
         <TR><TD></TD><TD COLSPAN=5><HR></TD></TR>";  
885  }  }
886    
887    
888  ?>  ?>
889    
890  <FORM METHOD="POST" ACTION="<?= $self ?>">  <FORM METHOD="POST" ACTION="<?= $self ?>">
# Line 896  if (file_exists(".info.inc")) { Line 909  if (file_exists(".info.inc")) {
909    
910  function UploadPage($fsRoot, $relDir, $filename="") {  function UploadPage($fsRoot, $relDir, $filename="") {
911    
912          $self = $GLOBALS["PHP_SELF"] ;          global $html, $HTTP_SERVER_VARS;
         if ($relDir == "") $relDir = "/" ;  
 ?>  
913    
914  <P><TABLE BORDER=0 CELLPADDING=5><TR><TD WIDTH=5></TD><TD CLASS=BAR>          $self = $HTTP_SERVER_VARS["PHP_SELF"] ;
915  <FORM ENCTYPE="multipart/form-data" METHOD="POST"          include("$html/UploadPage.html");
  ACTION="<?= $self ?>">  
 DESTINATION DIRECTORY:<B><?= " " . $relDir ?></B>  
 <? if (isset($filename) && $filename!="") { ?>  
 <br>DESTINATION FILE:<B><?= " " . $filename ?></B>  
 <INPUT TYPE="HIDDEN" NAME="FILENAME" VALUE="<?= $filename ?>">  
 <? } ?>  
 <P>PATHNAME OF LOCAL FILE<BR>  
 <INPUT TYPE="HIDDEN" NAME="DIR" VALUE="<?= $relDir ?>">  
 <INPUT TYPE="HIDDEN" NAME="POSTACTION" VALUE="UPLOAD">  
 <INPUT SIZE=30 TYPE="FILE" NAME="FN"></P>  
 <P><INPUT TYPE="SUBMIT" VALUE="UPLOAD"></P>  
 <P>If the <B>[BROWSE...]</B> button is not displayed,<BR>  
 you must upgrade to an RFC1867-compliant browser.</P>  
 <P>Your browser:<BR><?= $GLOBALS["HTTP_USER_AGENT"] ?></P>  
 </FORM>  
 </TD></TR>  
 <TR><TD></TD><TD>  
 <FORM METHOD="POST" ACTION="<?= $self ?>">  
 <INPUT TYPE="HIDDEN" NAME="DIR" VALUE="<?= $relDir ?>"><BR>  
 <INPUT TYPE="SUBMIT" NAME="POSTACTION" VALUE="CANCEL">  
 </FORM>  
 </TD></TR></TABLE></P>  
916    
 <?php    
917  } // end function UploadPage  } // end function UploadPage
918    
919  //////////////////////////////////////////////////////////////////  //////////////////////////////////////////////////////////////////
920    
921  function Error($title,$text="") {  // Error with sysadmin flag are reported to error_log or hidden from
922          StartHTML("(".$title.")",$text) ;  // users
923          echo "<P ALIGN=center>Hit your Browser's Back Button.</P>" ;  
924          EndHTML() ;  function Error($title,$text="",$sysadmin=0,$no_404=0) {
925            global $gblSeparateAdminMessages,
926                    $gblMailAdminMessages,$realm,
927                    $HTTP_SERVER_VARS;
928            if (! headers_sent() && ! $no_404) header("HTTP/1.0 404 Not Found");
929            if ($sysadmin) {
930                    if ($gblSeparateAdminMessages) {
931                            $user="Your administrator ";
932                            if ($gblMailAdminMessages) {
933                                    mail($HTTP_SERVER_VARS["SERVER_ADMIN"], "docman $realm error message: $title", strip_tags($text));
934                                    $user.="<tt>".$HTTP_SERVER_VARS["SERVER_ADMIN"]."</tt> ";
935                            }
936                            $user.="has been notified about error" ;
937                            StartHTML("($title)",$user);
938                            echo "<P ALIGN=center>Hit your Browser's Back Button.</P>" ;
939                            EndHTML();
940                            error_log("docman $realm: ".strip_tags($text));
941                    } else {
942                            StartHTML("ADMIN: ".$title,$text) ;
943                            echo "<P ALIGN=center>Hit your Browser's Back Button.</P>" ;
944                            EndHTML();
945                    }
946            } else {
947                    StartHTML("(".$title.")",$text) ;
948                    echo "<P ALIGN=center>Hit your Browser's Back Button.</P>" ;
949                    EndHTML() ;
950            }
951          exit ;          exit ;
952  } // end function Error  } // end function Error
953    
 //////////////////////////////////////////////////////////////////  
   
954  function LogIt($target,$msg, $changelog=0) {  function LogIt($target,$msg, $changelog=0) {
955    
956          $dir=dirname($target);          $dir=dirname($target);
957          if (! file_exists($dir."/.log")) {          if (! file_exists($dir."/.log")) {
958                  if (! @mkdir($dir."/.log",0700)) Error("docman installation problem","can't create log directory <tt>$dir/.log</tt>");                  if (! @mkdir($dir."/.log",0700)) Error("docman installation problem","can't create log directory <tt>$dir/.log</tt>",1);
959          }          }
960          $file=basename($target);          $file=basename($target);
961    
# Line 1082  function safe_rename($fromdir,$fromfile, Line 1094  function safe_rename($fromdir,$fromfile,
1094          function try_rename($from,$to) {          function try_rename($from,$to) {
1095  #               print "$from -> $to\n";  #               print "$from -> $to\n";
1096                  if (file_exists($from) && is_writeable(dirname($to))) {                  if (file_exists($from) && is_writeable(dirname($to))) {
1097                          rename($from,$to);                          return rename($from,$to);
1098                    } else {
1099                            return 0;
1100                  }                  }
1101          }          }
1102    
1103          function try_dir($todir) {          function try_dir($todir) {
1104                  if (! file_exists($todir)) {                  if (! file_exists($todir)) {
1105                          mkdir($todir,0700);                          @mkdir($todir,0700);
1106                  }                  }
1107          }          }
1108    
# Line 1098  function safe_rename($fromdir,$fromfile, Line 1112  function safe_rename($fromdir,$fromfile,
1112    
1113  #       print "<pre>$fromdir / $fromfile -> $todir / $tofile\n\n";  #       print "<pre>$fromdir / $fromfile -> $todir / $tofile\n\n";
1114    
1115          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);
1116          try_dir("$todir/.log");          try_dir("$todir/.log");
1117          try_rename("$fromdir/.log/$fromfile","$todir/.log/$tofile");          try_rename("$fromdir/.log/$fromfile","$todir/.log/$tofile");
1118          try_dir("$todir/.note");          try_dir("$todir/.note");
# Line 1134  function rrmdir($dir) { Line 1148  function rrmdir($dir) {
1148    
1149  function DisplayChangeLog($day) {  function DisplayChangeLog($day) {
1150    
1151          global $gblFsRoot;          global $gblFsRoot,$HTTP_SERVER_VARS;
1152    
1153          if (!file_exists("$gblFsRoot/.changelog")) return;          if (!file_exists("$gblFsRoot/.changelog")) return;
1154          $log=fopen("$gblFsRoot/.changelog","r");          $log=fopen("$gblFsRoot/.changelog","r");
1155          $logarr = array();          $logarr = array();
# Line 1156  function DisplayChangeLog($day) { Line 1171  function DisplayChangeLog($day) {
1171                  $time = date("$GLOBALS[gblTimeFmt]", $e[0]);                  $time = date("$GLOBALS[gblTimeFmt]", $e[0]);
1172                  $dir = dirname($e[1]);                  $dir = dirname($e[1]);
1173                  $file = basename($e[1]);                  $file = basename($e[1]);
1174                  print "<tr><td$cl>$date</td><td$cl>$time</td><td$cl><a href=\"$GLOBALS[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";
1175          }          }
1176          print "</table>";          print "</table>";
1177          print "<p>".GifIcon(up)." Back to <a href=$GLOBALS[PHP_SELF]>front page</a>.</p>";          print "<p>".GifIcon(up)." Back to <a href=$HTTP_SERVER_VARS[PHP_SELF]>front page</a>.</p>";
1178  }  }
1179    
1180  //////////////////////////////////////////////////////////////////  //////////////////////////////////////////////////////////////////
1181    
1182  function Download($path) {  function Download($path,$force=0) {
1183          global $HTTP_USER_AGENT;          global $HTTP_SERVER_VARS,$mime_type;
1184          $file=basename($path);  
1185            // default transfer-encoding
1186            $encoding = "binary";
1187    
1188            // known transfer encodings
1189            $encoding_ext = array(
1190                    "gz" => "x-gzip",
1191                    "Z" => "x-compress",
1192            );
1193    
1194            $file = basename($path);
1195          $size = filesize($path);          $size = filesize($path);
1196          //header("Content-Type: application/octet-stream");  
1197          header("Content-Type: application/force-download");          $ext_arr = explode(".",$file);
1198          header("Content-Length: $size");          $ext = array_pop($ext_arr);
1199            if ($encoding_ext[$ext]) {
1200                    $encoding = $encoding_ext[$ext];
1201                    $ext = array_pop($ext_arr);
1202            }
1203    
1204            if ($force || !isset($mime_type[$ext])) {
1205                    header("Content-Type: application/force-download");
1206            } else {
1207                    header("Content-Type: $mime_type[$ext]");
1208            }
1209    
1210          // IE5.5 just downloads index.php if we don't do this          // IE5.5 just downloads index.php if we don't do this
1211          if(preg_match("/MSIE 5.5/", $HTTP_USER_AGENT)) {          if(preg_match("/MSIE 5.5/", $HTTP_SERVER_VARS[HTTP_USER_AGENT])) {
1212                  header("Content-Disposition: filename=$file");                  header("Content-Disposition: filename=$file");
1213          } else {          } else {
1214                  header("Content-Disposition: attachment; filename=$file");                  header("Content-Disposition: attachment; filename=$file");
1215          }          }
1216          header("Content-Transfer-Encoding: binary");  
1217            header("Content-Transfer-Encoding: $encoding");
1218          $fh = fopen($path, "r");          $fh = fopen($path, "r");
1219          fpassthru($fh);          fpassthru($fh);
1220  }  }
# Line 1186  function Download($path) { Line 1223  function Download($path) {
1223  //////////////////////////////////////////////////////////////////  //////////////////////////////////////////////////////////////////
1224    
1225  function chopsl($path) {  function chopsl($path) {
         if (substr($path,strlen($path)-1,1) == "/") $path=substr($path,0,strlen($path)-1);  
1226          $path=str_replace("//","/",$path);          $path=str_replace("//","/",$path);
1227            if (substr($path,strlen($path)-1,1) == "/") $path=substr($path,0,strlen($path)-1);
1228          return $path;          return $path;
1229  }  }
1230    
# Line 1267  if (! file_exists($trustee_conf)) { Line 1304  if (! file_exists($trustee_conf)) {
1304          $groups_arr = array();          $groups_arr = array();
1305          $perm_arr = array();          $perm_arr = array();
1306    
         $error=0;  
   
1307          $tr_arr = array();          $tr_arr = array();
1308    
1309          while (! feof($fp_conf)) {          while (! feof($fp_conf)) {
# Line 1336  if (! file_exists($trustee_conf)) { Line 1371  if (! file_exists($trustee_conf)) {
1371  }  }
1372    
1373  if ($error) {  if ($error) {
1374          Error("Trustee error",$error);          Error("Trustee error",$error,1);
1375  } else {  } else {
1376          include("$trustee_php");          include("$trustee_php");
1377  }  }
# Line 1346  return 1; Line 1381  return 1;
1381  }//init_trustee  }//init_trustee
1382    
1383  function in_group($user,$group) {  function in_group($user,$group) {
1384          return in_array($groups[$group],$user);          global $groups;
1385            return in_array($user,$groups[$group]);
1386  }  }
1387    
1388  // helper function  // helper function
1389  function unroll_perm($u,$t,$user,$perm) {  function unroll_perm($u,$t,$user,$perm) {
1390          // check user  
1391            // check user FIX
1392          if ($t & trmask_not && ($u==$user)) continue;          if ($t & trmask_not && ($u==$user)) continue;
1393          if (!($t & trmask_not) && ($u!=$user)) continue;          if (!($t & trmask_not) && ($u!=$user)) continue;
1394    
# Line 1373  function check_trustee($user,$path) { Line 1410  function check_trustee($user,$path) {
1410          global $trustees;          global $trustees;
1411          $perm[allow] = 0;          $perm[allow] = 0;
1412          $perm[deny] = 0;          $perm[deny] = 0;
1413    
1414    global $debug;
1415    $debug .= "<br>check_trustee $path ... ";
1416    
1417          $path_arr=explode("/",$path);          $path_arr=explode("/",$path);
1418          $path = "/";          $tmppath = "/";
1419          while (count($path_arr)) {          while (count($path_arr)) {
1420                  if (substr($path,strlen($path)-1,1) != "/") $path.="/";                  $tmppath.=array_shift($path_arr);
1421                  $path.=array_shift($path_arr);  $debug.= ">> $tmppath ";
1422                  $tr = $trustees[$path];                  if (substr($tmppath,strlen($tmppath)-1,1) != "/") $tmppath.="/";
1423                    $tr = $trustees[$tmppath];
1424    
1425                    # clear one level flag
1426                    $perm[allow] &= ~trperm_one_level;
1427                    $perm[deny] &= ~trperm_one_level;
1428    
1429                  if (isset($tr)) {                  if (isset($tr)) {
1430                          // first apply trustee for all                          // first apply trustee for all
# Line 1387  function check_trustee($user,$path) { Line 1433  function check_trustee($user,$path) {
1433                                  unset($tr['*']);                                  unset($tr['*']);
1434                          }                          }
1435                          // then apply group policies                          // then apply group policies
1436                          foreach ($tr as $u=>$t) {                          foreach ($tr as $g=>$t) {
1437                                  if ($t & trmask_group && in_group($user,$u)) {                                  if ($t & trmask_group && in_group($user,$g)) {
1438                                          // resolv user                                          // resolv user
1439                                          $t = $t & ~trmask_group;                                          $t = $t & ~trmask_group;
1440                                          $u = $user;                                          $perm = unroll_perm($user,$t,$user, $perm);
1441                                          $perm = unroll_perm($u,$t,$user, $perm);                                          unset($tr[$g]);
                                         unset($tr[$u]);  
1442                                  }                                  }
1443                          }                          }
1444                          // then apply use policy                          // then apply user policy
1445                          if (isset($tr[$user])) {                          if (isset($tr[$user])) {
1446                                  $perm = unroll_perm($user,$tr[$user],$user, $perm);                                  $perm = unroll_perm($user,$tr[$user],$user, $perm);
1447                                  unset($tr[$user]);                                  unset($tr[$user]);
1448                          }                          }
   
1449                  }                  }
1450    $debug.="d:".display_trustee($perm[deny])." a:".display_trustee($perm[allow])." ";
1451    
1452          }          }
1453  #print "<br>user: $user path: $path perm: ";  $debug.="<br>check_trustee: user: $user path: $path==$tmppath perm: ";
1454  #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";
1455          return $perm;          return $perm;
1456  }  }
1457    
# Line 1414  function check_trustee($user,$path) { Line 1459  function check_trustee($user,$path) {
1459    
1460  function check_perm($path,$trperm) {  function check_perm($path,$trperm) {
1461          global $gblLogin,$HAVE_TRUSTEE;          global $gblLogin,$HAVE_TRUSTEE;
1462  print "<br>check_perm: <tt>$path</tt> test perm ".display_trustee($perm)."<br>\n";  
1463            global $debug;
1464    $debug.="<br>check_perm: <tt>$path</tt> test perm ".display_trustee($perm)."<br>\n";
1465    
1466          $return = ! $HAVE_TRUSTEE;          $return = ! $HAVE_TRUSTEE;
1467          if ($HAVE_TRUSTEE) {          if ($HAVE_TRUSTEE) {
1468                  $perm = check_trustee($gblLogin,$path);                  $perm = check_trustee($gblLogin,$path);
1469  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).")";
1470                  if ($perm[deny] & $trperm) $return=0;                  if ($perm[deny] & $trperm) $return=0;
1471                  elseif ($perm[allow] & $trperm) $return=1;                  elseif (($perm[allow] & $trperm) == $trperm) $return=1;
1472          }          }
1473  print " return: $return<br>\n";  $debug.=" return: $return<br>\n";
1474          return($return);          return($return);
1475  }  }
1476    
1477    //////////////////////////////////////////////////////////////////
1478    
1479    function readMime() {
1480            global $mime_type;
1481    
1482            if (! isset($gblMimeTypes)) {
1483                    $gblMimeTypes = "/etc/mime.types";
1484            }
1485    
1486            $mime = @fopen($gblMimeTypes,"r");
1487    
1488            if (! $mime) Error("Can't read MIME types","<tt>$gblMimeTypes</tt> file not found. You can setup other <tt>mime.types</tt> file using <tt>\$gblMimeTypes</tt> in <tt>$realm_config</tt>");
1489    
1490            while($line = fgets($mime,80)) {
1491                    if (substr($line,0,1) == "#") continue; // skip comment
1492                    $arr = preg_split("/[\s\t]+/",$line);
1493                    $type = array_shift($arr);
1494                    while ($ext = array_shift($arr)) {
1495                            $mime_type[$ext] = $type;
1496                    }
1497            }
1498    
1499            fclose($mime);
1500    }
1501    
1502    //////////////////////////////////////////////////////////////////
1503    
1504    // check for invalid characters in filename and dirname (.. and /)
1505    
1506    function check_dirname($file) {
1507            if (strstr($file,"..")) Error("Security violation","No parent dir <tt>..</tt> allowed in directory name <tt>$file</tt>",1);
1508    }
1509    
1510    function check_filename($file) {
1511            if (strstr($file,"..")) Error("Security violation","No parent dir <tt>..</tt> allowed in file name <tt>$file</tt>",1);
1512            if (strstr($file,"/")) Error("Security violation","No slashes <tt>/</tt> allowed in file name <tt>$file</tt>",1);
1513    }
1514    
1515  //////////////////////////////////////////////////////////////////  //////////////////////////////////////////////////////////////////
1516  // MAIN PROGRAM  // MAIN PROGRAM
# Line 1433  print " return: $return<br>\n"; Line 1518  print " return: $return<br>\n";
1518          $gblFilePerms = 0640 ;         // default for new files          $gblFilePerms = 0640 ;         // default for new files
1519          $gblDirPerms  = 0750 ;          // default for new dirs          $gblDirPerms  = 0750 ;          // default for new dirs
1520    
1521            $STYLE = $HTTP_GET_VARS[STYLE];
1522          if (isset($STYLE) && $STYLE == "get") {          if (isset($STYLE) && $STYLE == "get") {
1523                  include("$html/docman.css");                  include("$html/docman.css");
1524                  exit;                  exit;
# Line 1451  print " return: $return<br>\n"; Line 1537  print " return: $return<br>\n";
1537          if (! isset($fsRealmDir)) {          if (! isset($fsRealmDir)) {
1538                  $fsRealmDir = "$gblIncDir/realm";                  $fsRealmDir = "$gblIncDir/realm";
1539          }          }
1540          $realm_config = "$fsRealmDir/$realm.conf";  
1541            // try to add dir to script name to realm var
1542            if (is_dir("$fsRealmDir/$realm/".dirname($HTTP_SERVER_VARS[SCRIPT_NAME]))) {
1543                    $realm .= dirname($HTTP_SERVER_VARS[SCRIPT_NAME]);
1544                    $realm_sep = "/";
1545            } else {
1546                    $realm_sep = ".";
1547            }
1548    
1549            $realm_config = $fsRealmDir."/".$realm.$realm_sep."conf";
1550    
1551          // read user-defined configuration          // read user-defined configuration
1552          if (file_exists($realm_config)) {          if (file_exists($realm_config)) {
# Line 1469  print " return: $return<br>\n"; Line 1564  print " return: $return<br>\n";
1564                  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>");
1565          }          }
1566    
1567            // take additional login vars
1568            $relogin = $HTTP_GET_VARS[relogin];
1569            $force_login = $HTTP_GET_VARS[force_login];
1570    
1571          // if no password, or empty password logout          // if no password, or empty password logout
1572          if (          if (
1573                  isset($gblLogin) && (                  isset($gblLogin) && (
# Line 1484  print " return: $return<br>\n"; Line 1583  print " return: $return<br>\n";
1583                  exit ;                  exit ;
1584          }          }
1585    
1586            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);
1587    
1588          // trustee (ACL) file configuration          // trustee (ACL) file configuration
1589          $trustee_conf="$gblIncDir/realm/$realm.trustee";          $trustee_conf="$fsRealmDir/$realm".$realm_sep."trustee";
1590          // compiled version of trustee file          // compiled version of trustee file
1591          $trustee_php="$gblRepositoryDir/.trustee.php";          $trustee_php="$gblRepositoryDir/.trustee.php";
1592          // get ACL informations          // get ACL informations
1593          $HAVE_TRUSTEE = init_trustee();          $HAVE_TRUSTEE = init_trustee();
1594    
1595          if (strtolower($gblLogin) == "anonymous" || !isset($gblPasswd)) {          if (strtolower($gblLogin) == "anonymous" || !isset($gblLogin)) {
1596                  $perm = check_trustee($gblLogin,$path);                  $perm = check_trustee("anonymous",$path);
1597                  // browsing must be explicitly allowed for root directory                  // browsing must be explicitly allowed for root directory
1598                  // of repository for anonymous user to work!                  // of repository for anonymous user to work!
1599                  if ($perm[allow] & trperm_b) {                  if ($perm[allow] & trperm_b) {
1600                            $gblLogin = $gblPasswd = "anonymous";
1601                          $secHash = md5($gblLogin.$gblPasswd);                          $secHash = md5($gblLogin.$gblPasswd);
1602                          $gblUserName = "Anonymous user";                          $gblUserName = "Anonymous user";
1603                  }                  }
# Line 1506  print " return: $return<br>\n"; Line 1608  print " return: $return<br>\n";
1608                  isset($relogin) && $secHash == $relogin) {                  isset($relogin) && $secHash == $relogin) {
1609                  header("WWW-authenticate: basic realm=\"$realm\"") ;                  header("WWW-authenticate: basic realm=\"$realm\"") ;
1610                  header("HTTP/1.0 401 Unauthorized") ;                  header("HTTP/1.0 401 Unauthorized") ;
1611                  Error("401 Unauthorized","No trespassing !");                  Error("401 Unauthorized","No trespassing !",0,1);
                 exit ;  
1612          }          }
1613    
1614          // get current directory relative to $gblFsRoot  
1615          $relDir = $DIR ;        // from POST          // read mime.types
1616          if ($relDir == "") {    // not defined in POST ?          readMime();
1617                  $relDir = urldecode($D) ;  // then use GET  
1618          }                if ($HTTP_SERVER_VARS["REQUEST_METHOD"] == "POST") {
1619                    // take variables from server
1620          $relDir=stripSlashes($relDir);                  $FN=stripSlashes($HTTP_POST_VARS["FN"]);
1621                    $DIR=stripSlashes($HTTP_POST_VARS["DIR"]);
1622          if ($relDir == "/") $relDir = "" ;                        $RELPATH=stripSlashes($HTTP_POST_VARS["RELPATH"]);
1623          // default : website root = ""                  $T=stripSlashes($HTTP_POST_VARS["T"]);
1624                    $CONFIRM=stripSlashes($HTTP_POST_VARS["CONFIRM"]);
1625          if (strstr($relDir,"..")) Error("No updirs allowed");  
1626                    check_filename($FN);
1627          // full paths contain "fs" or "Fs". Paths realitve to root of                  check_dirname($DIR);
1628          // website contain "rel" or "Rel". The script won't let you                  check_dirname($RELPATH);
1629          // edit anything above directory equal to http://server.com  
1630          // i.e. below $gblFsRoot.                  $relDir = $DIR;
1631            } else {
1632                    // get
1633                    $A=stripSlashes($HTTP_GET_VARS["A"]);
1634                    $D=stripSlashes(urldecode($HTTP_GET_VARS["D"]));
1635                    $F=stripSlashes($HTTP_GET_VARS["F"]);
1636    
1637                    check_filename($F);
1638                    check_dirname($D);
1639    
1640                    $relDir = $D;
1641            }
1642    
1643          $relScriptDir = dirname($SCRIPT_NAME) ;                  $relScriptDir = dirname($SCRIPT_NAME) ;        
1644          // i.e. /docman          // i.e. /docman
1645    
1646          // start on server root          // start on server root
1647          $gblFsRoot = $gblRepositoryDir;          $gblFsRoot = $gblRepositoryDir;
1648          // i.e. /home/httpd/html          // i.e. /home/httpd/repository
1649    
1650          $fsDir = $gblFsRoot . $relDir ; // current directory          $fsDir = $gblFsRoot . $relDir ; // current directory
1651          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) ;
1652    
1653            if ($relDir == "") $relDir="/";
1654    
1655          if (isset($GLOBALS["HTTPS"]) && $GLOBALS["HTTPS"] == "on") {          if (isset($HTTP_SERVER_VARS["HTTPS"]) && $HTTP_SERVER_VARS["HTTPS"] == "on") {
1656                  $webRoot  = "https://";                  $webRoot  = "https://";
1657          } else {          } else {
1658                  $webRoot  = "http://";                  $webRoot  = "http://";
1659          }          }
1660          $webRoot .= $GLOBALS["HTTP_HOST"] . $relScriptDir;          $webRoot .= $HTTP_SERVER_VARS["HTTP_HOST"] . $relScriptDir;
   
         $FN=stripSlashes($FN);  
1661    
1662          switch ($POSTACTION) {          switch ($HTTP_POST_VARS["POSTACTION"]) {
1663          case "UPLOAD" :          case "UPLOAD" :
1664                    $FN_name=stripSlashes($HTTP_POST_FILES["FN"]["tmp_name"]);
1665                    $FN=stripSlashes($HTTP_POST_FILES["FN"]["name"]);
1666                  if (!is_writeable($fsDir)) Error("Write denied",$relDir) ;                  if (!is_writeable($fsDir)) Error("Write denied",$relDir) ;
1667                  if (strstr($FN_name,"/"))  
1668                          Error("Non-conforming filename") ;                  $source = $FN_name ;
                 // TODO : should rather check for escapeshellcmds  
                 // but maybe RFC 18xx asserts safe filenames ....  
                 $source = $FN ;  
1669                  if (! file_exists($source)) {                  if (! file_exists($source)) {
1670                          Error("You must select file with browse to upload it!");                          Error("You must select file with browse to upload it!");
1671                  }                  }
1672    
1673                    $FILENAME = $HTTP_POST_VARS["FILENAME"];
1674                    check_filename($FILENAME);
1675    
1676                  if (! isset($FILENAME)) {       // from update file                  if (! isset($FILENAME)) {       // from update file
1677                          $target = "$fsDir/$FN_name" ;                          $target = "$fsDir/".basename($FN);
1678                  } else {                  } else {
1679                          $target = "$fsDir/$FILENAME";                          $target = "$fsDir/$FILENAME";
1680                  }                  }
# Line 1657  print " return: $return<br>\n"; Line 1772  print " return: $return<br>\n";
1772    
1773  //                      if ( ! @unlink($path) ) {  //                      if ( ! @unlink($path) ) {
1774                          if ( ! rename($path,"$dir/.del/$file") ) {                          if ( ! rename($path,"$dir/.del/$file") ) {
                                 Error("File delete failed", $tstr . $path) ;  
1775                                  LogIt($path,"file delete failed");                                  LogIt($path,"file delete failed");
1776                                  exit ;                                  Error("File delete failed", $tstr . $path) ;
1777                          } else {                          } else {
1778                                  LogIt($path,"file deleted",trperm_w);                                  LogIt($path,"file deleted",trperm_w);
1779                                  MoveTo("$dir/.log/$file","$dir/.del/.log/");                                  MoveTo("$dir/.log/$file","$dir/.del/.log/");
# Line 1693  print " return: $return<br>\n"; Line 1807  print " return: $return<br>\n";
1807          case "RENAME" :            case "RENAME" :  
1808                  if ( $CONFIRM != "on" ) break ;                  if ( $CONFIRM != "on" ) break ;
1809    
1810                    $NEWNAME=stripSlashes($HTTP_POST_VARS["NEWNAME"]);
1811                  LogIt("$fsDir/$FN","renamed $FN to $NEWNAME",trperm_r);                  LogIt("$fsDir/$FN","renamed $FN to $NEWNAME",trperm_r);
1812                  safe_rename($fsDir,$FN,$NEWNAME);                  safe_rename($fsDir,$FN,$NEWNAME);
1813                  break ;                  break ;
1814    
1815          case "NOTE" :            case "NOTE" :  
1816                    $NOTE=stripSlashes($HTTP_POST_VARS["NOTE"]);
1817                  WriteNote("$fsDir/$FN","$NOTE");                  WriteNote("$fsDir/$FN","$NOTE");
1818                  break ;                  break ;
1819    
# Line 1724  print " return: $return<br>\n"; Line 1840  print " return: $return<br>\n";
1840          // $A=Co : checkout file $D/$F          // $A=Co : checkout file $D/$F
1841          // $A=Ci : checkin file $D/$F          // $A=Ci : checkin file $D/$F
1842          // $A=V : view file (do nothing except log)          // $A=V : view file (do nothing except log)
1843          // $A=I : include file .$F.php from $gblFsRoot          // $A=I : include file .$F.php from [$gblIncDir|realm]/include_php
1844          // default : display directory $D          // default : display directory $D
1845    
1846          switch ($A) {          switch ($A) {
1847          case "U" :          case "U" :
1848                  // upload to $relDir                  // upload to $relDir
1849                    if (! check_perm($relDir, trperm_w))
1850                            Error("Write access denied","You don't have permission to write in <tt>$relDir</tt>");
1851                  if (!is_writeable($gblFsRoot . $relDir))                  if (!is_writeable($gblFsRoot . $relDir))
1852                          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);
1853                  $text  = "Use this page to upload a single " ;                  $text  = "Use this page to upload a single " ;
1854                  $text .= "file to <B>$HTTP_HOST</B>." ;                  $text .= "file to <B>$realm</B>." ;
1855                  StartHTML("(Upload Page)", $text) ;                  StartHTML("(Upload Page)", $text) ;
1856                  UploadPage($gblFsRoot, $relDir) ;                  UploadPage($gblFsRoot, $relDir) ;
1857                  EndHTML() ;                  EndHTML() ;
1858                  exit ;                  exit ;
1859          case "E" :          case "E" :
                 $F=stripSlashes($F);  
1860                  // detail of $relDir/$F                  // detail of $relDir/$F
1861                  if (is_file("$gblFsRoot/$relDir/$F") || is_dir("$gblFsRoot/$relDir/$F")) DetailPage($gblFsRoot, $relDir, $F) ;                  if (is_file("$gblFsRoot/$relDir/$F") || is_dir("$gblFsRoot/$relDir/$F")) DetailPage($gblFsRoot, $relDir, $F) ;
1862                  exit ;                  exit ;
# Line 1751  print " return: $return<br>\n"; Line 1868  print " return: $return<br>\n";
1868          case "Co" :          case "Co" :
1869                  // checkout                  // checkout
1870                  Lock("$gblFsRoot/$relDir/$F");                  Lock("$gblFsRoot/$relDir/$F");
1871                  Download("$gblFsRoot/$relDir/$F");                  Download("$gblFsRoot/$relDir/$F",1);
1872                  exit;                  exit;
1873          case "Ci" :          case "Ci" :
1874                  $F=stripSlashes($F);                  $F=stripSlashes($F);
# Line 1759  print " return: $return<br>\n"; Line 1876  print " return: $return<br>\n";
1876                  if (!is_writeable($gblFsRoot . $relDir))                  if (!is_writeable($gblFsRoot . $relDir))
1877                          Error("Write access denied",$relDir) ;                          Error("Write access denied",$relDir) ;
1878                  $text  = "Use this page to update a single " ;                  $text  = "Use this page to update a single " ;
1879                  $text .= "file to <B>$HTTP_HOST</B>." ;                  $text .= "file to <B>$realm</B>." ;
1880                  StartHTML("(Update file Page)", $text) ;                  StartHTML("(Update file Page)", $text) ;
1881                  UploadPage($gblFsRoot, $relDir, $F) ;                  UploadPage($gblFsRoot, $relDir, $F) ;
1882                  EndHTML() ;                  EndHTML() ;
# Line 1767  print " return: $return<br>\n"; Line 1884  print " return: $return<br>\n";
1884          case "V" :          case "V" :
1885                  // view                  // view
1886                  LogIt("$gblFsRoot/$relDir/$F","viewed");                  LogIt("$gblFsRoot/$relDir/$F","viewed");
1887                  if ($gblForceDownload) {                  Download("$gblFsRoot/$relDir/$F",$gblForceDownload);
                         Download("$gblFsRoot/$relDir/$F");  
                 } else {  
                         header("Content-Disposition: attachment; filename=$F" );  
                         Header("Location: $webRoot".urlpath("$relDir/$F"));  
                 }  
1888                  exit;                  exit;
1889          case "Ch" :          case "Ch" :
1890                  StartHTML("(File changes)","All changes chronologicaly...");                  StartHTML("(File changes)","All changes chronologicaly...");
# Line 1785  print " return: $return<br>\n"; Line 1897  print " return: $return<br>\n";
1897                  EndHTML() ;                  EndHTML() ;
1898                  exit;                  exit;
1899          case "I" :          case "I" :
1900                  $F=stripSlashes($F);                  if (! isset($F) || $F == "")
1901                  $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);
1902                  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";
1903                    if (! file_exists($inc_file)) {
1904                            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);
1905                    }
1906                  if (!is_readable($inc_file))                  if (!is_readable($inc_file))
1907                          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);
1908                  $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";
1909                  $title = "You should define \$title variable with page title";                  $title = "You should define \$title variable with page title";
1910                  include($inc_file);                  include($inc_file);
1911                  StartHTML($title, $text) ;                  StartHTML($title, $text) ;
1912                  print "<p>".GifIcon(up)." Back to <a href=$GLOBALS[PHP_SELF]>front page</a>.</p>";                  print "<p>".GifIcon(up)." Back to <a href=$HTTP_SERVER_VARS[PHP_SELF]>front page</a>.</p>";
1913                  EndHTML() ;                  EndHTML() ;
1914                  exit ;                  exit ;
1915          }          }
# Line 1803  print " return: $return<br>\n"; Line 1918  print " return: $return<br>\n";
1918          Navigate($gblFsRoot,$relDir) ;            Navigate($gblFsRoot,$relDir) ;  
1919          exit ;          exit ;
1920    
1921          Error("Whooah!","By cartesian logic, this never happens") ;          Error("Whooah!","By cartesian logic, this never happens",1) ;
1922  ?>  ?>

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

  ViewVC Help
Powered by ViewVC 1.1.26