/[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.13 by dpavlin, Sun Jul 28 11:39:59 2002 UTC
# Line 25  Line 25 
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 145  function EndHTML() { Line 145  function EndHTML() {
145                  $url_title="relogin";                  $url_title="relogin";
146          }          }
147          include("$html/footer.html");          include("$html/footer.html");
148          //phpinfo();  
149            global $debug;
150            if ($debug) print $debug;
151  } // end function EndHTML  } // end function EndHTML
152    
153  //////////////////////////////////////////////////////////////////  //////////////////////////////////////////////////////////////////
154    
155  function DetailPage($fsRoot,$relDir,$fn) {  function DetailPage($fsRoot,$relDir,$fn) {
156                    
157          global $gblEditable, $gblImages, $webRoot, $html ;          global $gblEditable, $gblImages, $webRoot, $html, $HTTP_SERVER_VARS ;
158          $self = $GLOBALS["PHP_SELF"] ;          $self = $HTTP_SERVER_VARS["PHP_SELF"] ;
159    
160          $relPath  = $relDir . "/" . $fn ;          $relPath  = $relDir . "/" . $fn ;
161          $fsPath   = $fsRoot . $relPath ;          $fsPath   = $fsRoot . $relPath ;
# Line 161  function DetailPage($fsRoot,$relDir,$fn) Line 163  function DetailPage($fsRoot,$relDir,$fn)
163    
164          $exists   = file_exists($fsPath) ;          $exists   = file_exists($fsPath) ;
165          $ext      = strtolower(strrchr($relPath,".")) ;          $ext      = strtolower(strrchr($relPath,".")) ;
166          $editable = ( $ext=="" || strstr(join(" ",$gblEditable),$ext)) ;          $editable = ( $ext=="" || strstr(join(" ",$gblEditable),$ext)) &&
167          $writable = is_writeable($fsPath) ;                  check_perm($relPath,trperm_w);
168            $writable = is_writeable($fsPath) && check_perm($relPath,trperm_w) ;
169            $writable_dir = is_writeable($fsDir) && check_perm($relDir,trperm_w) ;
170          $file_lock = CheckLock($fsPath);          $file_lock = CheckLock($fsPath);
171    
172          if (!$editable && !$exists)          if (!$editable && !$exists)
173                  Error(_("Creation unsupported for type"),$relPath) ;                  Error("Creation denied","Can't create <tt>$relPath</tt>") ;
174          if (!exists && !is_writeable($fsDir) )          if (!$exists && !$writable_dir )
175                  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);
176    
177          $text  = _("Use this page to view, modify or ") ;          $text  = _("Use this page to view, modify or ") ;
178          if (is_dir($fsPath)) {          if (is_dir($fsPath)) {
# Line 201  function DetailPage($fsRoot,$relDir,$fn) Line 205  function DetailPage($fsRoot,$relDir,$fn)
205                  $fstr = htmlentities( $fstr ) ;                  $fstr = htmlentities( $fstr ) ;
206  ?>  ?>
207    
208  <FORM ACTION="<?= $self ; ?>" METHOD="POST">  <FORM ACTION="<?= $self ?>" METHOD="POST">
209  <SPAN TITLE="Click [SAVE] to store updated contents.">  <SPAN TITLE="Click [SAVE] to store updated contents.">
210          <B>DOCUMENT CONTENTS</B>          <B>DOCUMENT CONTENTS</B>
211  </SPAN><BR>  </SPAN><BR>
# Line 572  function GifIcon($txt) { Line 576  function GifIcon($txt) {
576  function Navigate($fsRoot,$relDir) {  function Navigate($fsRoot,$relDir) {
577    
578          global $gblEditable, $gblIcon, $gblModDays, $webRoot, $gblHide,          global $gblEditable, $gblIcon, $gblModDays, $webRoot, $gblHide,
579                  $HTTP_GET_VARS, $html;                  $gblIgnoreUnknownFileType, $gblRepositoryDir,
580                    $fsRealmDir, $realm, $realm_sep,
581          $self     = $GLOBALS["PHP_SELF"] ;                  $HTTP_GET_VARS, $html, $realm_config;
582            
583            $self     = $HTTP_SERVER_VARS["PHP_SELF"] ;
584    
585          if ($relDir == "") $relDir = "/";          if ($relDir == "") $relDir = "/";
586    
587          $fsDir = $fsRoot.$relDir."/";   // current directory          $fsDir = $fsRoot.$relDir."/";   // current directory
588    
589          if (!is_dir($fsDir)) Error("Dir not found",$relDir) ;          if (!is_dir($fsDir)) Error("Dir not found",$relDir,1) ;
590    
591          $hide_items=",$gblHide,";          $hide_items=",$gblHide,";
592    
 #display_all_trustee();  
 print "-- $fsDir --";  
   
593          // read directory contents          // read directory contents
594          if ( !($dir = @opendir($fsDir)) )          if ( !($dir = @opendir($fsDir)) )
595                  Error("Read Access denied",$relDir) ;                  Error("Read Access denied",$relDir,1) ;
596          while ($item = readdir($dir)) {          while ($item = readdir($dir)) {
 print "$item, ";  
597                  if ( substr($item,0,1) == "." || strstr($hide_items,",$item,") ) continue ;                  if ( substr($item,0,1) == "." || strstr($hide_items,",$item,") ) continue ;
598                  if ((is_dir($fsDir.$item) || is_link ($fsDir.$item)) && check_perm($relDir.$item,trperm_b)) {                  if (is_dir($fsDir.$item) || is_link ($fsDir.$item)) {
599                          $dirList[$item] = $item ;                          if (check_perm($relDir.$item,trperm_b)) {
600                          $dirNote[$item] = ReadNote($fsDir.$item);                                  $dirList[$item] = $item ;
601                  } else if ( is_file($fsDir.$item) && check_perm($relDir.$item,trperm_r) ) {                                  $dirNote[$item] = ReadNote($fsDir.$item);
602                          $fileList[$item] = $item ;                                        }
603                          $fileDate[$item] = filemtime($fsDir.$item) ;                  } else if (is_file($fsDir.$item)) {
604                          $fileSize[$item] = filesize($fsDir.$item) ;                          if (check_perm($relDir.$item,trperm_r)) {
605                          $fileNote[$item] = ReadNote($fsDir.$item);                                  $fileList[$item] = $item ;              
606                                    $fileDate[$item] = filemtime($fsDir.$item) ;
607                                    $fileSize[$item] = filesize($fsDir.$item) ;
608                                    $fileNote[$item] = ReadNote($fsDir.$item);
609                            }
610                  } else {                  } else {
611                    // 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 ;  
612                  }                  }
613          }          }
614          closedir($dir) ;          closedir($dir) ;
615    
616          // scan deleted files          // scan deleted files
617          if ( $GLOBALS[show_deleted] == 1 && ($dir = @opendir("$fsDir/.del")) ) {          if ( $HTTP_GET_VARS["show_deleted"] == 1 && ($dir = @opendir("$fsDir/.del")) ) {
618                  while ($item = readdir($dir)) {                  while ($item = readdir($dir)) {
619                          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 ;
620                          $fileList[$item] = ".del/$item" ;                                        $fileList[$item] = ".del/$item" ;              
# Line 626  print "$item, "; Line 629  print "$item, ";
629    
630          // start navigation page          // start navigation page
631          $text  = "Use this page to add, delete";          $text  = "Use this page to add, delete";
632          if (! isset($show_deleted)) {          if (! isset($HTTP_GET_VARS[show_deleted])) {
633                  $text .= ", <a href=$self?D=".urlencode($relDir)."&show_deleted=1>undelete</a>";                  $text .= ", <a href=$self?D=".urlencode($relDir)."&show_deleted=1>undelete</a>";
634          }          }
635          $text .= " or revise files on this web site." ;          $text .= " or revise files on this web site." ;
# Line 636  print "$item, "; Line 639  print "$item, ";
639          echo "<TABLE BORDER=0 CELLPADDING=2          echo "<TABLE BORDER=0 CELLPADDING=2
640                  CELLSPACING=3 WIDTH=\"100%\">" ;                  CELLSPACING=3 WIDTH=\"100%\">" ;
641    
642          // updir bar              // updir (parent) bar  
643          if (chopsl($fsDir) != chopsl($fsRoot)) {          if (chopsl($fsDir) != chopsl($fsRoot)) {
644                  $parent = dirname($relDir) ;                  $parent = dirname($relDir) ;
645                  if ($parent == "") $parent = "/" ;                  if ($parent == "") $parent = "/" ;
# Line 716  print "$item, "; Line 719  print "$item, ";
719                          $dir = $dirList[$key];                          $dir = $dirList[$key];
720    
721                          $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));
722                          $dir_url=$self."?D=".urlencode($relDir."/".$dir);                          $dir_url=$self."?D=".urlencode(chopsl($relDir)."/".$dir);
723                          include("$html/Navigate-dirEntry.html");                          include("$html/Navigate-dirEntry.html");
724    
725                  }  // iterate over dirs                  }  // iterate over dirs
# Line 788  print "$item, "; Line 791  print "$item, ";
791    
792                  $file_lock=CheckLock($path);                  $file_lock=CheckLock($path);
793    
794                  $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);  
795                  $file_url_html.="\" TITLE=\"View file\">" ;                  $file_url_html.="\" TITLE=\"View file\">" ;
796    
797                  if (substr($file,0,5) != ".del/") {                  if (substr($file,0,5) != ".del/") {
# Line 804  print "$item, "; Line 806  print "$item, ";
806    
807                  if ($file_lock) {                  if ($file_lock) {
808                          if ($file_lock == $GLOBALS[gblUserName]) {                          if ($file_lock == $GLOBALS[gblUserName]) {
809                                  $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);  
810                                  $b.="\" TITLE=\"Checkin (update) file on server\">" ;                                  $b.="\" TITLE=\"Checkin (update) file on server\">" ;
811                                  $file_url_html=$b;                                  $file_url_html=$b;
812                                  $b.=$gblIcon("checkin")."</A>" ;                                  $b.=$gblIcon("checkin")."</A>" ;
# Line 819  print "$item, "; Line 820  print "$item, ";
820                                  $file_url_html = "$file $a";                                  $file_url_html = "$file $a";
821                          }                          }
822                  } else {                  } else {
823                          $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);  
824                          $b.="\" TITLE=\"Checkout file for edit\">" ;                          $b.="\" TITLE=\"Checkout file for edit\">" ;
825                          $b.=$gblIcon("checkout")."</A>" ;                          $b.=$gblIcon("checkout")."</A>";
826    
827                          if ( $ext=="" || strstr(join(" ",$gblEditable),$ext) ) {                            if ( $ext=="" || strstr(join(" ",$gblEditable),$ext) ) {  
828                                  $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);  
829                                  $b.="\" TITLE=\"List contents\">" ;                                  $b.="\" TITLE=\"List contents\">" ;
830                                  $b.=$gblIcon("view")."</A>" ;                                  $b.=$gblIcon("view")."</A>" ;
831                          } else {                          } else {
# Line 866  print "$item, "; Line 865  print "$item, ";
865  <TR><TD></TD><TD COLSPAN=5><HR></TD></TR>  <TR><TD></TD><TD COLSPAN=5><HR></TD></TR>
866    
867  <?  <?
868  if (file_exists(".info.inc")) {  
869    if (file_exists("$fsRealmDir/$realm".$realm_sep."info.inc")) {
870            print "<TR><TD></TD><TD COLSPAN=5>";
871            include("$fsRealmDir/$realm".$realm_sep."info.inc");
872            print "</TD></TR><TR><TD></TD><TD COLSPAN=5><HR></TD></TR>";
873    } elseif (file_exists("$gblRepositoryDir/.info.inc")) {
874          print "<TR><TD></TD><TD COLSPAN=5>";          print "<TR><TD></TD><TD COLSPAN=5>";
875          include(".info.inc");          include("$gblRepositoryDir/.info.inc");
876          print "</TD></TR>          print "</TD></TR><TR><TD></TD><TD COLSPAN=5><HR></TD></TR>";
         <TR><TD></TD><TD COLSPAN=5><HR></TD></TR>";  
877  }  }
878    
879    
880  ?>  ?>
881    
882  <FORM METHOD="POST" ACTION="<?= $self ?>">  <FORM METHOD="POST" ACTION="<?= $self ?>">
# Line 896  if (file_exists(".info.inc")) { Line 901  if (file_exists(".info.inc")) {
901    
902  function UploadPage($fsRoot, $relDir, $filename="") {  function UploadPage($fsRoot, $relDir, $filename="") {
903    
904          $self = $GLOBALS["PHP_SELF"] ;          global $html, $HTTP_SERVER_VARS;
905    
906            $self = $HTTP_SERVER_VARS["PHP_SELF"] ;
907          if ($relDir == "") $relDir = "/" ;          if ($relDir == "") $relDir = "/" ;
 ?>  
908    
909  <P><TABLE BORDER=0 CELLPADDING=5><TR><TD WIDTH=5></TD><TD CLASS=BAR>          include("$html/UploadPage.html");
 <FORM ENCTYPE="multipart/form-data" METHOD="POST"  
  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>  
910    
 <?php    
911  } // end function UploadPage  } // end function UploadPage
912    
913  //////////////////////////////////////////////////////////////////  //////////////////////////////////////////////////////////////////
914    
915  function Error($title,$text="") {  // Error with sysadmin flag are reported to error_log or hidden from
916          StartHTML("(".$title.")",$text) ;  // users
917          echo "<P ALIGN=center>Hit your Browser's Back Button.</P>" ;  
918          EndHTML() ;  function Error($title,$text="",$sysadmin=0,$no_404=0) {
919            global $gblSeparateAdminMessages,
920                    $gblMailAdminMessages,$realm,
921                    $HTTP_SERVER_VARS;
922            if (! headers_sent() && ! $no_404) header("HTTP/1.0 404 Not Found");
923            if ($sysadmin) {
924                    if ($gblSeparateAdminMessages) {
925                            $user="Your administrator ";
926                            if ($gblMailAdminMessages) {
927                                    mail($HTTP_SERVER_VARS["SERVER_ADMIN"], "docman $realm error message: $title", strip_tags($text));
928                                    $user.="<tt>".$HTTP_SERVER_VARS["SERVER_ADMIN"]."</tt> ";
929                            }
930                            $user.="has been notified about error" ;
931                            StartHTML("($title)",$user);
932                            echo "<P ALIGN=center>Hit your Browser's Back Button.</P>" ;
933                            EndHTML();
934                            error_log("docman $realm: ".strip_tags($text));
935                    } else {
936                            StartHTML("ADMIN: ".$title,$text) ;
937                            echo "<P ALIGN=center>Hit your Browser's Back Button.</P>" ;
938                            EndHTML();
939                    }
940            } else {
941                    StartHTML("(".$title.")",$text) ;
942                    echo "<P ALIGN=center>Hit your Browser's Back Button.</P>" ;
943                    EndHTML() ;
944            }
945          exit ;          exit ;
946  } // end function Error  } // end function Error
947    
 //////////////////////////////////////////////////////////////////  
   
948  function LogIt($target,$msg, $changelog=0) {  function LogIt($target,$msg, $changelog=0) {
949    
950          $dir=dirname($target);          $dir=dirname($target);
951          if (! file_exists($dir."/.log")) {          if (! file_exists($dir."/.log")) {
952                  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);
953          }          }
954          $file=basename($target);          $file=basename($target);
955    
# Line 1082  function safe_rename($fromdir,$fromfile, Line 1088  function safe_rename($fromdir,$fromfile,
1088          function try_rename($from,$to) {          function try_rename($from,$to) {
1089  #               print "$from -> $to\n";  #               print "$from -> $to\n";
1090                  if (file_exists($from) && is_writeable(dirname($to))) {                  if (file_exists($from) && is_writeable(dirname($to))) {
1091                          rename($from,$to);                          return rename($from,$to);
1092                    } else {
1093                            return 0;
1094                  }                  }
1095          }          }
1096    
1097          function try_dir($todir) {          function try_dir($todir) {
1098                  if (! file_exists($todir)) {                  if (! file_exists($todir)) {
1099                          mkdir($todir,0700);                          @mkdir($todir,0700);
1100                  }                  }
1101          }          }
1102    
# Line 1098  function safe_rename($fromdir,$fromfile, Line 1106  function safe_rename($fromdir,$fromfile,
1106    
1107  #       print "<pre>$fromdir / $fromfile -> $todir / $tofile\n\n";  #       print "<pre>$fromdir / $fromfile -> $todir / $tofile\n\n";
1108    
1109          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);
1110          try_dir("$todir/.log");          try_dir("$todir/.log");
1111          try_rename("$fromdir/.log/$fromfile","$todir/.log/$tofile");          try_rename("$fromdir/.log/$fromfile","$todir/.log/$tofile");
1112          try_dir("$todir/.note");          try_dir("$todir/.note");
# Line 1134  function rrmdir($dir) { Line 1142  function rrmdir($dir) {
1142    
1143  function DisplayChangeLog($day) {  function DisplayChangeLog($day) {
1144    
1145          global $gblFsRoot;          global $gblFsRoot,$HTTP_SERVER_VARS;
1146    
1147          if (!file_exists("$gblFsRoot/.changelog")) return;          if (!file_exists("$gblFsRoot/.changelog")) return;
1148          $log=fopen("$gblFsRoot/.changelog","r");          $log=fopen("$gblFsRoot/.changelog","r");
1149          $logarr = array();          $logarr = array();
# Line 1156  function DisplayChangeLog($day) { Line 1165  function DisplayChangeLog($day) {
1165                  $time = date("$GLOBALS[gblTimeFmt]", $e[0]);                  $time = date("$GLOBALS[gblTimeFmt]", $e[0]);
1166                  $dir = dirname($e[1]);                  $dir = dirname($e[1]);
1167                  $file = basename($e[1]);                  $file = basename($e[1]);
1168                  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";
1169          }          }
1170          print "</table>";          print "</table>";
1171          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>";
1172  }  }
1173    
1174  //////////////////////////////////////////////////////////////////  //////////////////////////////////////////////////////////////////
1175    
1176  function Download($path) {  function Download($path,$force=0) {
1177          global $HTTP_USER_AGENT;          global $HTTP_SERVER_VARS,$mime_type;
1178          $file=basename($path);  
1179            // default transfer-encoding
1180            $encoding = "binary";
1181    
1182            // known transfer encodings
1183            $encoding_ext = array(
1184                    "gz" => "x-gzip",
1185                    "Z" => "x-compress",
1186            );
1187    
1188            $file = basename($path);
1189          $size = filesize($path);          $size = filesize($path);
1190          //header("Content-Type: application/octet-stream");  
1191          header("Content-Type: application/force-download");          $ext_arr = explode(".",$file);
1192          header("Content-Length: $size");          $ext = array_pop($ext_arr);
1193            if ($encoding_ext[$ext]) {
1194                    $encoding = $encoding_ext[$ext];
1195                    $ext = array_pop($ext_arr);
1196            }
1197    
1198            if ($force || !isset($mime_type[$ext])) {
1199                    header("Content-Type: application/force-download");
1200            } else {
1201                    header("Content-Type: $mime_type[$ext]");
1202            }
1203    
1204          // IE5.5 just downloads index.php if we don't do this          // IE5.5 just downloads index.php if we don't do this
1205          if(preg_match("/MSIE 5.5/", $HTTP_USER_AGENT)) {          if(preg_match("/MSIE 5.5/", $HTTP_SERVER_VARS[HTTP_USER_AGENT])) {
1206                  header("Content-Disposition: filename=$file");                  header("Content-Disposition: filename=$file");
1207          } else {          } else {
1208                  header("Content-Disposition: attachment; filename=$file");                  header("Content-Disposition: attachment; filename=$file");
1209          }          }
1210          header("Content-Transfer-Encoding: binary");  
1211            header("Content-Transfer-Encoding: $encoding");
1212          $fh = fopen($path, "r");          $fh = fopen($path, "r");
1213          fpassthru($fh);          fpassthru($fh);
1214  }  }
# Line 1186  function Download($path) { Line 1217  function Download($path) {
1217  //////////////////////////////////////////////////////////////////  //////////////////////////////////////////////////////////////////
1218    
1219  function chopsl($path) {  function chopsl($path) {
         if (substr($path,strlen($path)-1,1) == "/") $path=substr($path,0,strlen($path)-1);  
1220          $path=str_replace("//","/",$path);          $path=str_replace("//","/",$path);
1221            if (substr($path,strlen($path)-1,1) == "/") $path=substr($path,0,strlen($path)-1);
1222          return $path;          return $path;
1223  }  }
1224    
# Line 1267  if (! file_exists($trustee_conf)) { Line 1298  if (! file_exists($trustee_conf)) {
1298          $groups_arr = array();          $groups_arr = array();
1299          $perm_arr = array();          $perm_arr = array();
1300    
         $error=0;  
   
1301          $tr_arr = array();          $tr_arr = array();
1302    
1303          while (! feof($fp_conf)) {          while (! feof($fp_conf)) {
# Line 1336  if (! file_exists($trustee_conf)) { Line 1365  if (! file_exists($trustee_conf)) {
1365  }  }
1366    
1367  if ($error) {  if ($error) {
1368          Error("Trustee error",$error);          Error("Trustee error",$error,1);
1369  } else {  } else {
1370          include("$trustee_php");          include("$trustee_php");
1371  }  }
# Line 1414  function check_trustee($user,$path) { Line 1443  function check_trustee($user,$path) {
1443    
1444  function check_perm($path,$trperm) {  function check_perm($path,$trperm) {
1445          global $gblLogin,$HAVE_TRUSTEE;          global $gblLogin,$HAVE_TRUSTEE;
1446  print "<br>check_perm: <tt>$path</tt> test perm ".display_trustee($perm)."<br>\n";  
1447            global $debug;
1448    $debug.="<br>check_perm: <tt>$path</tt> test perm ".display_trustee($perm)."<br>\n";
1449          $return = ! $HAVE_TRUSTEE;          $return = ! $HAVE_TRUSTEE;
1450          if ($HAVE_TRUSTEE) {          if ($HAVE_TRUSTEE) {
1451                  $perm = check_trustee($gblLogin,$path);                  $perm = check_trustee($gblLogin,$path);
1452  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: $trperm";
1453                  if ($perm[deny] & $trperm) $return=0;                  if ($perm[deny] & $trperm) $return=0;
1454                  elseif ($perm[allow] & $trperm) $return=1;                  elseif ($perm[allow] & $trperm) $return=1;
1455          }          }
1456  print " return: $return<br>\n";  $debug.=" return: $return<br>\n";
1457          return($return);          return($return);
1458  }  }
1459    
1460    //////////////////////////////////////////////////////////////////
1461    
1462    function readMime() {
1463            global $mime_type;
1464    
1465            if (! isset($gblMimeTypes)) {
1466                    $gblMimeTypes = "/etc/mime.types";
1467            }
1468    
1469            $mime = @fopen($gblMimeTypes,"r");
1470    
1471            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>");
1472    
1473            while($line = fgets($mime,80)) {
1474                    if (substr($line,0,1) == "#") continue; // skip comment
1475                    $arr = preg_split("/[\s\t]+/",$line);
1476                    $type = array_shift($arr);
1477                    while ($ext = array_shift($arr)) {
1478                            $mime_type[$ext] = $type;
1479                    }
1480            }
1481    
1482            fclose($mime);
1483    }
1484    
1485    //////////////////////////////////////////////////////////////////
1486    
1487    // check for invalid characters in filename and dirname (.. and /)
1488    
1489    function check_dirname($file) {
1490            if (strstr($file,"..")) Error("Security violation","No parent dir <tt>..</tt> allowed in directory name <tt>$file</tt>",1);
1491    }
1492    
1493    function check_filename($file) {
1494            if (strstr($file,"..")) Error("Security violation","No parent dir <tt>..</tt> allowed in file name <tt>$file</tt>",1);
1495            if (strstr($file,"/")) Error("Security violation","No slashes <tt>/</tt> allowed in file name <tt>$file</tt>",1);
1496    }
1497    
1498  //////////////////////////////////////////////////////////////////  //////////////////////////////////////////////////////////////////
1499  // MAIN PROGRAM  // MAIN PROGRAM
# Line 1433  print " return: $return<br>\n"; Line 1501  print " return: $return<br>\n";
1501          $gblFilePerms = 0640 ;         // default for new files          $gblFilePerms = 0640 ;         // default for new files
1502          $gblDirPerms  = 0750 ;          // default for new dirs          $gblDirPerms  = 0750 ;          // default for new dirs
1503    
1504            $STYLE = $HTTP_GET_VARS[STYLE];
1505          if (isset($STYLE) && $STYLE == "get") {          if (isset($STYLE) && $STYLE == "get") {
1506                  include("$html/docman.css");                  include("$html/docman.css");
1507                  exit;                  exit;
# Line 1451  print " return: $return<br>\n"; Line 1520  print " return: $return<br>\n";
1520          if (! isset($fsRealmDir)) {          if (! isset($fsRealmDir)) {
1521                  $fsRealmDir = "$gblIncDir/realm";                  $fsRealmDir = "$gblIncDir/realm";
1522          }          }
1523          $realm_config = "$fsRealmDir/$realm.conf";  
1524            // try to add dir to script name to realm var
1525            if (is_dir("$fsRealmDir/$realm/".dirname($HTTP_SERVER_VARS[SCRIPT_NAME]))) {
1526                    $realm .= "/".dirname($HTTP_SERVER_VARS[SCRIPT_NAME]);
1527                    $realm_sep = "/";
1528            } else {
1529                    $realm_sep = ".";
1530            }
1531    
1532            $realm_config = $fsRealmDir."/".$realm.$realm_sep."conf";
1533    
1534          // read user-defined configuration          // read user-defined configuration
1535          if (file_exists($realm_config)) {          if (file_exists($realm_config)) {
# Line 1484  print " return: $return<br>\n"; Line 1562  print " return: $return<br>\n";
1562                  exit ;                  exit ;
1563          }          }
1564    
1565            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);
1566    
1567          // trustee (ACL) file configuration          // trustee (ACL) file configuration
1568          $trustee_conf="$gblIncDir/realm/$realm.trustee";          $trustee_conf="$fsRealmDir/$realm".$realm_sep."trustee";
1569          // compiled version of trustee file          // compiled version of trustee file
1570          $trustee_php="$gblRepositoryDir/.trustee.php";          $trustee_php="$gblRepositoryDir/.trustee.php";
1571          // get ACL informations          // get ACL informations
# Line 1506  print " return: $return<br>\n"; Line 1586  print " return: $return<br>\n";
1586                  isset($relogin) && $secHash == $relogin) {                  isset($relogin) && $secHash == $relogin) {
1587                  header("WWW-authenticate: basic realm=\"$realm\"") ;                  header("WWW-authenticate: basic realm=\"$realm\"") ;
1588                  header("HTTP/1.0 401 Unauthorized") ;                  header("HTTP/1.0 401 Unauthorized") ;
1589                  Error("401 Unauthorized","No trespassing !");                  Error("401 Unauthorized","No trespassing !",0,1);
                 exit ;  
1590          }          }
1591    
         // get current directory relative to $gblFsRoot  
         $relDir = $DIR ;        // from POST  
         if ($relDir == "") {    // not defined in POST ?  
                 $relDir = urldecode($D) ;  // then use GET  
         }        
1592    
1593          $relDir=stripSlashes($relDir);          // read mime.types
1594            readMime();
1595    
1596          if ($relDir == "/") $relDir = "" ;                if ($HTTP_SERVER_VARS["REQUEST_METHOD"] == "POST") {
1597          // default : website root = ""                  // take variables from server
1598                    $FN=stripSlashes($HTTP_POST_VARS["FN"]);
1599                    $DIR=stripSlashes($HTTP_POST_VARS["DIR"]);
1600                    $RELPATH=stripSlashes($HTTP_POST_VARS["RELPATH"]);
1601                    $T=stripSlashes($HTTP_POST_VARS["T"]);
1602                    $CONFIRM=stripSlashes($HTTP_POST_VARS["CONFIRM"]);
1603    
1604          if (strstr($relDir,"..")) Error("No updirs allowed");                  check_filename($FN);
1605                    check_dirname($DIR);
1606                    check_dirname($RELPATH);
1607    
1608                    $relDir = $DIR;
1609            } else {
1610                    // get
1611                    $A=stripSlashes($HTTP_GET_VARS["A"]);
1612                    $D=stripSlashes(urldecode($HTTP_GET_VARS["D"]));
1613                    $F=stripSlashes($HTTP_GET_VARS["F"]);
1614    
1615                    check_filename($F);
1616                    check_dirname($D);
1617    
1618                    $relDir = $D;
1619            }
1620    
1621          // full paths contain "fs" or "Fs". Paths realitve to root of          if ($relDir == "/") $relDir = "" ;      
         // website contain "rel" or "Rel". The script won't let you  
         // edit anything above directory equal to http://server.com  
         // i.e. below $gblFsRoot.  
1622    
1623          $relScriptDir = dirname($SCRIPT_NAME) ;                  $relScriptDir = dirname($SCRIPT_NAME) ;        
1624          // i.e. /docman          // i.e. /docman
1625    
1626          // start on server root          // start on server root
1627          $gblFsRoot = $gblRepositoryDir;          $gblFsRoot = $gblRepositoryDir;
1628          // i.e. /home/httpd/html          // i.e. /home/httpd/repository
1629    
1630          $fsDir = $gblFsRoot . $relDir ; // current directory          $fsDir = $gblFsRoot . $relDir ; // current directory
1631          if ( !is_dir($fsDir) ) Error("Dir not found",$relDir) ;          if ( !is_dir($fsDir) ) Error("Dir not found",$relDir,1) ;
1632    
1633          if (isset($GLOBALS["HTTPS"]) && $GLOBALS["HTTPS"] == "on") {          if (isset($HTTP_SERVER_VARS["HTTPS"]) && $HTTP_SERVER_VARS["HTTPS"] == "on") {
1634                  $webRoot  = "https://";                  $webRoot  = "https://";
1635          } else {          } else {
1636                  $webRoot  = "http://";                  $webRoot  = "http://";
1637          }          }
1638          $webRoot .= $GLOBALS["HTTP_HOST"] . $relScriptDir;          $webRoot .= $HTTP_SERVER_VARS["HTTP_HOST"] . $relScriptDir;
   
         $FN=stripSlashes($FN);  
1639    
1640          switch ($POSTACTION) {          switch ($HTTP_POST_VARS["POSTACTION"]) {
1641          case "UPLOAD" :          case "UPLOAD" :
1642                    $FN_name=stripSlashes($HTTP_POST_FILES["FN"]["tmp_name"]);
1643                    $FN=stripSlashes($HTTP_POST_FILES["FN"]["name"]);
1644                  if (!is_writeable($fsDir)) Error("Write denied",$relDir) ;                  if (!is_writeable($fsDir)) Error("Write denied",$relDir) ;
1645                  if (strstr($FN_name,"/"))  
1646                          Error("Non-conforming filename") ;                  $source = $FN_name ;
                 // TODO : should rather check for escapeshellcmds  
                 // but maybe RFC 18xx asserts safe filenames ....  
                 $source = $FN ;  
1647                  if (! file_exists($source)) {                  if (! file_exists($source)) {
1648                          Error("You must select file with browse to upload it!");                          Error("You must select file with browse to upload it!");
1649                  }                  }
1650    
1651                    $FILENAME = $HTTP_POST_VARS["FILENAME"];
1652                    check_filename($FILENAME);
1653    
1654                  if (! isset($FILENAME)) {       // from update file                  if (! isset($FILENAME)) {       // from update file
1655                          $target = "$fsDir/$FN_name" ;                          $target = "$fsDir/".basename($FN);
1656                  } else {                  } else {
1657                          $target = "$fsDir/$FILENAME";                          $target = "$fsDir/$FILENAME";
1658                  }                  }
# Line 1657  print " return: $return<br>\n"; Line 1750  print " return: $return<br>\n";
1750    
1751  //                      if ( ! @unlink($path) ) {  //                      if ( ! @unlink($path) ) {
1752                          if ( ! rename($path,"$dir/.del/$file") ) {                          if ( ! rename($path,"$dir/.del/$file") ) {
                                 Error("File delete failed", $tstr . $path) ;  
1753                                  LogIt($path,"file delete failed");                                  LogIt($path,"file delete failed");
1754                                  exit ;                                  Error("File delete failed", $tstr . $path) ;
1755                          } else {                          } else {
1756                                  LogIt($path,"file deleted",trperm_w);                                  LogIt($path,"file deleted",trperm_w);
1757                                  MoveTo("$dir/.log/$file","$dir/.del/.log/");                                  MoveTo("$dir/.log/$file","$dir/.del/.log/");
# Line 1693  print " return: $return<br>\n"; Line 1785  print " return: $return<br>\n";
1785          case "RENAME" :            case "RENAME" :  
1786                  if ( $CONFIRM != "on" ) break ;                  if ( $CONFIRM != "on" ) break ;
1787    
1788                    $NEWNAME=stripSlashes($HTTP_POST_VARS["NEWNAME"]);
1789                  LogIt("$fsDir/$FN","renamed $FN to $NEWNAME",trperm_r);                  LogIt("$fsDir/$FN","renamed $FN to $NEWNAME",trperm_r);
1790                  safe_rename($fsDir,$FN,$NEWNAME);                  safe_rename($fsDir,$FN,$NEWNAME);
1791                  break ;                  break ;
1792    
1793          case "NOTE" :            case "NOTE" :  
1794                    $NOTE=stripSlashes($HTTP_POST_VARS["NOTE"]);
1795                  WriteNote("$fsDir/$FN","$NOTE");                  WriteNote("$fsDir/$FN","$NOTE");
1796                  break ;                  break ;
1797    
# Line 1733  print " return: $return<br>\n"; Line 1827  print " return: $return<br>\n";
1827                  if (!is_writeable($gblFsRoot . $relDir))                  if (!is_writeable($gblFsRoot . $relDir))
1828                          Error("Write access denied",$relDir) ;                          Error("Write access denied",$relDir) ;
1829                  $text  = "Use this page to upload a single " ;                  $text  = "Use this page to upload a single " ;
1830                  $text .= "file to <B>$HTTP_HOST</B>." ;                  $text .= "file to <B>$realm</B>." ;
1831                  StartHTML("(Upload Page)", $text) ;                  StartHTML("(Upload Page)", $text) ;
1832                  UploadPage($gblFsRoot, $relDir) ;                  UploadPage($gblFsRoot, $relDir) ;
1833                  EndHTML() ;                  EndHTML() ;
1834                  exit ;                  exit ;
1835          case "E" :          case "E" :
                 $F=stripSlashes($F);  
1836                  // detail of $relDir/$F                  // detail of $relDir/$F
1837                  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) ;
1838                  exit ;                  exit ;
# Line 1751  print " return: $return<br>\n"; Line 1844  print " return: $return<br>\n";
1844          case "Co" :          case "Co" :
1845                  // checkout                  // checkout
1846                  Lock("$gblFsRoot/$relDir/$F");                  Lock("$gblFsRoot/$relDir/$F");
1847                  Download("$gblFsRoot/$relDir/$F");                  Download("$gblFsRoot/$relDir/$F",1);
1848                  exit;                  exit;
1849          case "Ci" :          case "Ci" :
1850                  $F=stripSlashes($F);                  $F=stripSlashes($F);
# Line 1759  print " return: $return<br>\n"; Line 1852  print " return: $return<br>\n";
1852                  if (!is_writeable($gblFsRoot . $relDir))                  if (!is_writeable($gblFsRoot . $relDir))
1853                          Error("Write access denied",$relDir) ;                          Error("Write access denied",$relDir) ;
1854                  $text  = "Use this page to update a single " ;                  $text  = "Use this page to update a single " ;
1855                  $text .= "file to <B>$HTTP_HOST</B>." ;                  $text .= "file to <B>$realm</B>." ;
1856                  StartHTML("(Update file Page)", $text) ;                  StartHTML("(Update file Page)", $text) ;
1857                  UploadPage($gblFsRoot, $relDir, $F) ;                  UploadPage($gblFsRoot, $relDir, $F) ;
1858                  EndHTML() ;                  EndHTML() ;
# Line 1767  print " return: $return<br>\n"; Line 1860  print " return: $return<br>\n";
1860          case "V" :          case "V" :
1861                  // view                  // view
1862                  LogIt("$gblFsRoot/$relDir/$F","viewed");                  LogIt("$gblFsRoot/$relDir/$F","viewed");
1863                  if ($gblForceDownload) {                  Download("$gblFsRoot/$relDir/$F",$gblForceDownload);
                         Download("$gblFsRoot/$relDir/$F");  
                 } else {  
                         header("Content-Disposition: attachment; filename=$F" );  
                         Header("Location: $webRoot".urlpath("$relDir/$F"));  
                 }  
1864                  exit;                  exit;
1865          case "Ch" :          case "Ch" :
1866                  StartHTML("(File changes)","All changes chronologicaly...");                  StartHTML("(File changes)","All changes chronologicaly...");
# Line 1794  print " return: $return<br>\n"; Line 1882  print " return: $return<br>\n";
1882                  $title = "You should define \$title variable with page title";                  $title = "You should define \$title variable with page title";
1883                  include($inc_file);                  include($inc_file);
1884                  StartHTML($title, $text) ;                  StartHTML($title, $text) ;
1885                  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>";
1886                  EndHTML() ;                  EndHTML() ;
1887                  exit ;                  exit ;
1888          }          }
# Line 1803  print " return: $return<br>\n"; Line 1891  print " return: $return<br>\n";
1891          Navigate($gblFsRoot,$relDir) ;            Navigate($gblFsRoot,$relDir) ;  
1892          exit ;          exit ;
1893    
1894          Error("Whooah!","By cartesian logic, this never happens") ;          Error("Whooah!","By cartesian logic, this never happens",1) ;
1895  ?>  ?>

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

  ViewVC Help
Powered by ViewVC 1.1.26