/[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.1.1.1 by dpavlin, Sun Jul 21 18:15:47 2002 UTC revision 1.10 by dpavlin, Sat Jul 27 20:30:45 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";
# 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");
         //phpinfo();  
148  } // end function EndHTML  } // end function EndHTML
149    
150  //////////////////////////////////////////////////////////////////  //////////////////////////////////////////////////////////////////
151    
152  function DetailPage($fsRoot,$relDir,$fn) {  function DetailPage($fsRoot,$relDir,$fn) {
153                    
154          global $gblEditable, $gblImages, $webRoot, $html ;          global $gblEditable, $gblImages, $webRoot, $html, $HTTP_SERVER_VARS ;
155          $self = $GLOBALS["PHP_SELF"] ;          $self = $HTTP_SERVER_VARS["PHP_SELF"] ;
156    
157          $relPath  = $relDir . "/" . $fn ;          $relPath  = $relDir . "/" . $fn ;
158          $fsPath   = $fsRoot . $relPath ;          $fsPath   = $fsRoot . $relPath ;
# Line 166  function DetailPage($fsRoot,$relDir,$fn) Line 165  function DetailPage($fsRoot,$relDir,$fn)
165          $file_lock = CheckLock($fsPath);          $file_lock = CheckLock($fsPath);
166    
167          if (!$editable && !$exists)          if (!$editable && !$exists)
168                  Error(_("Creation unsupported for type"),$relPath) ;                  Error("Creation unsupported for type",$relPath) ;
169          if (!exists && !is_writeable($fsDir) )          if (!exists && !is_writeable($fsDir) )
170                  Error(_("Creation denied"),$relDir) ;                  Error("Creation denied",$relDir) ;
171    
172          $text  = _("Use this page to view, modify or ") ;          $text  = _("Use this page to view, modify or ") ;
173          if (is_dir($fsPath)) {          if (is_dir($fsPath)) {
# Line 572  function GifIcon($txt) { Line 571  function GifIcon($txt) {
571  function Navigate($fsRoot,$relDir) {  function Navigate($fsRoot,$relDir) {
572    
573          global $gblEditable, $gblIcon, $gblModDays, $webRoot, $gblHide,          global $gblEditable, $gblIcon, $gblModDays, $webRoot, $gblHide,
574                  $HTTP_GET_VARS, $html;                  $gblIgnoreUnknownFileType, $gblRepositoryDir,
575                    $HTTP_GET_VARS, $html, $realm_config;
576    
577          $self     = $GLOBALS["PHP_SELF"] ;          $self     = $HTTP_SERVER_VARS["PHP_SELF"] ;
578    
579          if ($relDir == "") $relDir = "/";          if ($relDir == "") $relDir = "/";
580    
# Line 584  function Navigate($fsRoot,$relDir) { Line 584  function Navigate($fsRoot,$relDir) {
584    
585          $hide_items=",$gblHide,";          $hide_items=",$gblHide,";
586    
 #display_all_trustee();  
 print "-- $fsDir --";  
   
587          // read directory contents          // read directory contents
588          if ( !($dir = @opendir($fsDir)) )          if ( !($dir = @opendir($fsDir)) )
589                  Error("Read Access denied",$relDir) ;                  Error("Read Access denied",$relDir,1) ;
590          while ($item = readdir($dir)) {          while ($item = readdir($dir)) {
 print "$item, ";  
591                  if ( substr($item,0,1) == "." || strstr($hide_items,",$item,") ) continue ;                  if ( substr($item,0,1) == "." || strstr($hide_items,",$item,") ) continue ;
592                  if ((is_dir($fsDir.$item) || is_link ($fsDir.$item)) && check_perm($relDir.$item,trperm_b)) {                  if (is_dir($fsDir.$item) || is_link ($fsDir.$item)) {
593                          $dirList[$item] = $item ;                          if (check_perm($relDir.$item,trperm_b)) {
594                          $dirNote[$item] = ReadNote($fsDir.$item);                                  $dirList[$item] = $item ;
595                  } else if ( is_file($fsDir.$item) && check_perm($relDir.$item,trperm_r) ) {                                  $dirNote[$item] = ReadNote($fsDir.$item);
596                          $fileList[$item] = $item ;                                        }
597                          $fileDate[$item] = filemtime($fsDir.$item) ;                  } else if (is_file($fsDir.$item)) {
598                          $fileSize[$item] = filesize($fsDir.$item) ;                          if (check_perm($relDir.$item,trperm_r)) {
599                          $fileNote[$item] = ReadNote($fsDir.$item);                                  $fileList[$item] = $item ;              
600                                    $fileDate[$item] = filemtime($fsDir.$item) ;
601                                    $fileSize[$item] = filesize($fsDir.$item) ;
602                                    $fileNote[$item] = ReadNote($fsDir.$item);
603                            }
604                  } else {                  } else {
605                    // 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 ;  
606                  }                  }
607          }          }
608          closedir($dir) ;          closedir($dir) ;
609    
610          // scan deleted files          // scan deleted files
611          if ( $GLOBALS[show_deleted] == 1 && ($dir = @opendir("$fsDir/.del")) ) {          if ( $HTTP_GET_VARS["show_deleted"] == 1 && ($dir = @opendir("$fsDir/.del")) ) {
612                  while ($item = readdir($dir)) {                  while ($item = readdir($dir)) {
613                          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 ;
614                          $fileList[$item] = ".del/$item" ;                                        $fileList[$item] = ".del/$item" ;              
# Line 626  print "$item, "; Line 623  print "$item, ";
623    
624          // start navigation page          // start navigation page
625          $text  = "Use this page to add, delete";          $text  = "Use this page to add, delete";
626          if (! isset($show_deleted)) {          if (! isset($HTTP_GET_VARS[show_deleted])) {
627                  $text .= ", <a href=$self?D=".urlencode($relDir)."&show_deleted=1>undelete</a>";                  $text .= ", <a href=$self?D=".urlencode($relDir)."&show_deleted=1>undelete</a>";
628          }          }
629          $text .= " or revise files on this web site." ;          $text .= " or revise files on this web site." ;
# Line 715  print "$item, "; Line 712  print "$item, ";
712    
713                          $dir = $dirList[$key];                          $dir = $dirList[$key];
714    
715                          $info_url=self_args(array("A" => "A=E", "F" => "F=".urlencode($dir)));                          $info_url=self_args(array("A"=>"A=E", "F"=>"F=".urlencode($dir), "D"=>$D));
716                          $dir_url=$self."?D=".urlencode($relDir.$dir);                          $dir_url=$self."?D=".urlencode($relDir."/".$dir);
717                          include("$html/Navigate-dirEntry.html");                          include("$html/Navigate-dirEntry.html");
718    
719                  }  // iterate over dirs                  }  // iterate over dirs
# Line 788  print "$item, "; Line 785  print "$item, ";
785    
786                  $file_lock=CheckLock($path);                  $file_lock=CheckLock($path);
787    
788                  $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);  
789                  $file_url_html.="\" TITLE=\"View file\">" ;                  $file_url_html.="\" TITLE=\"View file\">" ;
790    
791                  if (substr($file,0,5) != ".del/") {                  if (substr($file,0,5) != ".del/") {
# Line 804  print "$item, "; Line 800  print "$item, ";
800    
801                  if ($file_lock) {                  if ($file_lock) {
802                          if ($file_lock == $GLOBALS[gblUserName]) {                          if ($file_lock == $GLOBALS[gblUserName]) {
803                                  $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);  
804                                  $b.="\" TITLE=\"Checkin (update) file on server\">" ;                                  $b.="\" TITLE=\"Checkin (update) file on server\">" ;
805                                  $file_url_html=$b;                                  $file_url_html=$b;
806                                  $b.=$gblIcon("checkin")."</A>" ;                                  $b.=$gblIcon("checkin")."</A>" ;
# Line 819  print "$item, "; Line 814  print "$item, ";
814                                  $file_url_html = "$file $a";                                  $file_url_html = "$file $a";
815                          }                          }
816                  } else {                  } else {
817                          $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);  
818                          $b.="\" TITLE=\"Checkout file for edit\">" ;                          $b.="\" TITLE=\"Checkout file for edit\">" ;
819                          $b.=$gblIcon("checkout")."</A>" ;                          $b.=$gblIcon("checkout")."</A>";
820    
821                          if ( $ext=="" || strstr(join(" ",$gblEditable),$ext) ) {                            if ( $ext=="" || strstr(join(" ",$gblEditable),$ext) ) {  
822                                  $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);  
823                                  $b.="\" TITLE=\"List contents\">" ;                                  $b.="\" TITLE=\"List contents\">" ;
824                                  $b.=$gblIcon("view")."</A>" ;                                  $b.=$gblIcon("view")."</A>" ;
825                          } else {                          } else {
# Line 866  print "$item, "; Line 859  print "$item, ";
859  <TR><TD></TD><TD COLSPAN=5><HR></TD></TR>  <TR><TD></TD><TD COLSPAN=5><HR></TD></TR>
860    
861  <?  <?
862  if (file_exists(".info.inc")) {  
863    if (file_exists("$gblRepositoryDir/.info.inc")) {
864          print "<TR><TD></TD><TD COLSPAN=5>";          print "<TR><TD></TD><TD COLSPAN=5>";
865          include(".info.inc");          include("$gblRepositoryDir/.info.inc");
866          print "</TD></TR>          print "</TD></TR><TR><TD></TD><TD COLSPAN=5><HR></TD></TR>";
         <TR><TD></TD><TD COLSPAN=5><HR></TD></TR>";  
867  }  }
868    
869  ?>  ?>
870    
871  <FORM METHOD="POST" ACTION="<?= $self ?>">  <FORM METHOD="POST" ACTION="<?= $self ?>">
# Line 896  if (file_exists(".info.inc")) { Line 890  if (file_exists(".info.inc")) {
890    
891  function UploadPage($fsRoot, $relDir, $filename="") {  function UploadPage($fsRoot, $relDir, $filename="") {
892    
893          $self = $GLOBALS["PHP_SELF"] ;          global $html, $HTTP_SERVER_VARS;
894    
895            $self = $HTTP_SERVER_VARS["PHP_SELF"] ;
896          if ($relDir == "") $relDir = "/" ;          if ($relDir == "") $relDir = "/" ;
 ?>  
897    
898  <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>  
899    
 <?php    
900  } // end function UploadPage  } // end function UploadPage
901    
902  //////////////////////////////////////////////////////////////////  //////////////////////////////////////////////////////////////////
903    
904  function Error($title,$text="") {  // Error with sysadmin flag are reported to error_log or hidden from
905          StartHTML("(".$title.")",$text) ;  // users
906          echo "<P ALIGN=center>Hit your Browser's Back Button.</P>" ;  
907          EndHTML() ;  function Error($title,$text="",$sysadmin=0) {
908            global $gblSeparateAdminMessages,
909                    $gblMailAdminMessages,$realm,
910                    $HTTP_SERVER_VARS;
911            if (! headers_sent()) header("HTTP/1.0 404 Not Found");
912            if ($sysadmin) {
913                    if ($gblSeparateAdminMessages) {
914                            $user="Your administrator ";
915                            if ($gblMailAdminMessages) {
916                                    mail($HTTP_SERVER_VARS["SERVER_ADMIN"], "docman $realm error message: $title", strip_tags($text));
917                                    $user.="<tt>".$HTTP_SERVER_VARS["SERVER_ADMIN"]."</tt> ";
918                            }
919                            $user.="has been notified about error" ;
920                            StartHTML("($title)",$user);
921                            echo "<P ALIGN=center>Hit your Browser's Back Button.</P>" ;
922                            EndHTML();
923                            error_log("docman $realm: ".strip_tags($text));
924                    } else {
925                            StartHTML("ADMIN: ".$title,$text) ;
926                            echo "<P ALIGN=center>Hit your Browser's Back Button.</P>" ;
927                            EndHTML();
928                    }
929            } else {
930                    StartHTML("(".$title.")",$text) ;
931                    echo "<P ALIGN=center>Hit your Browser's Back Button.</P>" ;
932                    EndHTML() ;
933            }
934          exit ;          exit ;
935  } // end function Error  } // end function Error
936    
937  //////////////////////////////////////////////////////////////////  function LogIt($target,$msg, $changelog=0) {
   
 function LogIt($target,$msg) {  
938    
939          $dir=dirname($target);          $dir=dirname($target);
940          if (! file_exists($dir."/.log")) {          if (! file_exists($dir."/.log")) {
941                  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);
942          }          }
943          $file=basename($target);          $file=basename($target);
944    
# Line 952  function LogIt($target,$msg) { Line 947  function LogIt($target,$msg) {
947                  "\t$GLOBALS[gblUserName]\t$msg\n");                  "\t$GLOBALS[gblUserName]\t$msg\n");
948          fclose($log);          fclose($log);
949    
950            if (! $changelog) return;
951    
952            global $gblFsRoot;
953            $log=fopen("$gblFsRoot/.changelog","a+");
954            if (substr($target,0,strlen($gblFsRoot)) == $gblFsRoot)
955                    $target=substr($target,strlen($gblFsRoot),strlen($target)-strlen($gblFsRoot));
956            $msg=str_replace("\t"," ",$msg);
957            fputs($log,time()."\t$target\t$GLOBALS[gblUserName]\t$msg\n");
958            fclose($log);
959    
960            // FIX: implement e-mail notification based on $changelog
961            // permission
962  }  }
963    
964    
# Line 970  function WriteNote($target,$msg) { Line 977  function WriteNote($target,$msg) {
977          fputs($note,"$msg\n");          fputs($note,"$msg\n");
978          fclose($note);          fclose($note);
979    
980          Logit($target,"added note $msg");          LogIt($target,"added note $msg");
981    
982  }  }
983    
# Line 1015  function Lock($target) { Line 1022  function Lock($target) {
1022          $file=basename($target);          $file=basename($target);
1023    
1024          if (file_exists("$dir/.lock/$file")) {          if (file_exists("$dir/.lock/$file")) {
1025                  Logit($target,"attempt to locked allready locked file!");                  LogIt($target,"attempt to locked allready locked file!");
1026          } else {          } else {
1027                  $lock=fopen("$dir/.lock/$file","w");                  $lock=fopen("$dir/.lock/$file","w");
1028                  fputs($lock,"$GLOBALS[gblUserName]\n");                  fputs($lock,"$GLOBALS[gblUserName]\n");
1029                  fclose($lock);                  fclose($lock);
1030    
1031                  Logit($target,"file locked");                  LogIt($target,"file locked");
1032          }          }
1033    
1034  }  }
# Line 1048  function Unlock($target) { Line 1055  function Unlock($target) {
1055          $file=basename($target);          $file=basename($target);
1056          if (file_exists($dir."/.lock/$file")) {          if (file_exists($dir."/.lock/$file")) {
1057                  unlink("$dir/.lock/$file");                  unlink("$dir/.lock/$file");
1058                  Logit($target,"file unlocked");                  LogIt($target,"file unlocked");
1059          } else {          } else {
1060                  Logit($target,"attempt to unlocked non-locked file!");                  LogIt($target,"attempt to unlocked non-locked file!");
1061          }          }
1062    
1063  }  }
# Line 1070  function safe_rename($fromdir,$fromfile, Line 1077  function safe_rename($fromdir,$fromfile,
1077          function try_rename($from,$to) {          function try_rename($from,$to) {
1078  #               print "$from -> $to\n";  #               print "$from -> $to\n";
1079                  if (file_exists($from) && is_writeable(dirname($to))) {                  if (file_exists($from) && is_writeable(dirname($to))) {
1080                          rename($from,$to);                          return rename($from,$to);
1081                    } else {
1082                            return 0;
1083                  }                  }
1084          }          }
1085    
1086          function try_dir($todir) {          function try_dir($todir) {
1087                  if (! file_exists($todir)) {                  if (! file_exists($todir)) {
1088                          mkdir($todir,0700);                          @mkdir($todir,0700);
1089                  }                  }
1090          }          }
1091    
# Line 1086  function safe_rename($fromdir,$fromfile, Line 1095  function safe_rename($fromdir,$fromfile,
1095    
1096  #       print "<pre>$fromdir / $fromfile -> $todir / $tofile\n\n";  #       print "<pre>$fromdir / $fromfile -> $todir / $tofile\n\n";
1097    
1098          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);
1099          try_dir("$todir/.log");          try_dir("$todir/.log");
1100          try_rename("$fromdir/.log/$fromfile","$todir/.log/$tofile");          try_rename("$fromdir/.log/$fromfile","$todir/.log/$tofile");
1101          try_dir("$todir/.note");          try_dir("$todir/.note");
# Line 1120  function rrmdir($dir) { Line 1129  function rrmdir($dir) {
1129    
1130  //////////////////////////////////////////////////////////////////  //////////////////////////////////////////////////////////////////
1131    
 function ChangeLog($target,$msg) {  
   
         global $gblFsRoot;  
         $log=fopen("$gblFsRoot/.changelog","a+");  
         if (substr($target,0,strlen($gblFsRoot)) == $gblFsRoot)  
                 $target=substr($target,strlen($gblFsRoot),strlen($target)-strlen($gblFsRoot));  
         $msg=str_replace("\t"," ",$msg);  
         fputs($log,time()."\t$target\t$GLOBALS[gblUserName]\t$msg\n");  
         fclose($log);  
   
 }  
   
1132  function DisplayChangeLog($day) {  function DisplayChangeLog($day) {
1133    
1134          global $gblFsRoot;          global $gblFsRoot,$HTTP_SERVER_VARS;
1135    
1136          if (!file_exists("$gblFsRoot/.changelog")) return;          if (!file_exists("$gblFsRoot/.changelog")) return;
1137          $log=fopen("$gblFsRoot/.changelog","r");          $log=fopen("$gblFsRoot/.changelog","r");
1138          $logarr = array();          $logarr = array();
# Line 1156  function DisplayChangeLog($day) { Line 1154  function DisplayChangeLog($day) {
1154                  $time = date("$GLOBALS[gblTimeFmt]", $e[0]);                  $time = date("$GLOBALS[gblTimeFmt]", $e[0]);
1155                  $dir = dirname($e[1]);                  $dir = dirname($e[1]);
1156                  $file = basename($e[1]);                  $file = basename($e[1]);
1157                  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";
1158          }          }
1159          print "</table>";          print "</table>";
1160          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>";
1161  }  }
1162    
1163  //////////////////////////////////////////////////////////////////  //////////////////////////////////////////////////////////////////
1164    
1165  function Download($path) {  function Download($path,$force=0) {
1166          global $HTTP_USER_AGENT;          global $HTTP_SERVER_VARS,$mime_type;
1167          $file=basename($path);  
1168            // default transfer-encoding
1169            $encoding = "binary";
1170    
1171            // known transfer encodings
1172            $encoding_ext = array(
1173                    "gz" => "x-gzip",
1174                    "Z" => "x-compress",
1175            );
1176    
1177            $file = basename($path);
1178          $size = filesize($path);          $size = filesize($path);
1179          //header("Content-Type: application/octet-stream");  
1180          header("Content-Type: application/force-download");          $ext_arr = explode(".",$file);
1181          header("Content-Length: $size");          $ext = array_pop($ext_arr);
1182            if ($encoding_ext[$ext]) {
1183                    $encoding = $encoding_ext[$ext];
1184                    $ext = array_pop($ext_arr);
1185            }
1186    
1187            if ($force || !isset($mime_type[$ext])) {
1188                    header("Content-Type: application/force-download");
1189            } else {
1190                    header("Content-Type: $mime_type[$ext]");
1191            }
1192    
1193          // IE5.5 just downloads index.php if we don't do this          // IE5.5 just downloads index.php if we don't do this
1194          if(preg_match("/MSIE 5.5/", $HTTP_USER_AGENT)) {          if(preg_match("/MSIE 5.5/", $HTTP_SERVER_VARS[HTTP_USER_AGENT])) {
1195                  header("Content-Disposition: filename=$file");                  header("Content-Disposition: filename=$file");
1196          } else {          } else {
1197                  header("Content-Disposition: attachment; filename=$file");                  header("Content-Disposition: attachment; filename=$file");
1198          }          }
1199          header("Content-Transfer-Encoding: binary");  
1200            header("Content-Transfer-Encoding: $encoding");
1201          $fh = fopen($path, "r");          $fh = fopen($path, "r");
1202          fpassthru($fh);          fpassthru($fh);
1203  }  }
# Line 1267  if (! file_exists($trustee_conf)) { Line 1287  if (! file_exists($trustee_conf)) {
1287          $groups_arr = array();          $groups_arr = array();
1288          $perm_arr = array();          $perm_arr = array();
1289    
         $error=0;  
   
1290          $tr_arr = array();          $tr_arr = array();
1291    
1292          while (! feof($fp_conf)) {          while (! feof($fp_conf)) {
# Line 1336  if (! file_exists($trustee_conf)) { Line 1354  if (! file_exists($trustee_conf)) {
1354  }  }
1355    
1356  if ($error) {  if ($error) {
1357          Error("Trustee error",$error);          Error("Trustee error",$error,1);
1358  } else {  } else {
1359          include("$trustee_php");          include("$trustee_php");
1360  }  }
# Line 1426  print " return: $return<br>\n"; Line 1444  print " return: $return<br>\n";
1444          return($return);          return($return);
1445  }  }
1446    
1447    //////////////////////////////////////////////////////////////////
1448    
1449    function readMime() {
1450            global $mime_type;
1451    
1452            if (! isset($gblMimeTypes)) {
1453                    $gblMimeTypes = "/etc/mime.types";
1454            }
1455    
1456            $mime = @fopen($gblMimeTypes,"r");
1457    
1458            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>");
1459    
1460            while($line = fgets($mime,80)) {
1461                    if (substr($line,0,1) == "#") continue; // skip comment
1462                    $arr = preg_split("/[\s\t]+/",$line);
1463                    $type = array_shift($arr);
1464                    while ($ext = array_shift($arr)) {
1465                            $mime_type[$ext] = $type;
1466                    }
1467            }
1468    
1469            fclose($mime);
1470    }
1471    
1472  //////////////////////////////////////////////////////////////////  //////////////////////////////////////////////////////////////////
1473  // MAIN PROGRAM  // MAIN PROGRAM
# Line 1484  print " return: $return<br>\n"; Line 1526  print " return: $return<br>\n";
1526                  exit ;                  exit ;
1527          }          }
1528    
1529            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);
1530    
1531          // trustee (ACL) file configuration          // trustee (ACL) file configuration
1532          $trustee_conf="$gblIncDir/realm/$realm.trustee";          $trustee_conf="$gblIncDir/realm/$realm.trustee";
1533          // compiled version of trustee file          // compiled version of trustee file
# Line 1507  print " return: $return<br>\n"; Line 1551  print " return: $return<br>\n";
1551                  header("WWW-authenticate: basic realm=\"$realm\"") ;                  header("WWW-authenticate: basic realm=\"$realm\"") ;
1552                  header("HTTP/1.0 401 Unauthorized") ;                  header("HTTP/1.0 401 Unauthorized") ;
1553                  Error("401 Unauthorized","No trespassing !");                  Error("401 Unauthorized","No trespassing !");
                 exit ;  
1554          }          }
1555    
1556            // read mime.types
1557            readMime();
1558    
1559          // get current directory relative to $gblFsRoot          // get current directory relative to $gblFsRoot
1560          $relDir = $DIR ;        // from POST          $relDir = $DIR ;        // from POST
1561          if ($relDir == "") {    // not defined in POST ?          if ($relDir == "") {    // not defined in POST ?
# Line 1538  print " return: $return<br>\n"; Line 1584  print " return: $return<br>\n";
1584          $fsDir = $gblFsRoot . $relDir ; // current directory          $fsDir = $gblFsRoot . $relDir ; // current directory
1585          if ( !is_dir($fsDir) ) Error("Dir not found",$relDir) ;          if ( !is_dir($fsDir) ) Error("Dir not found",$relDir) ;
1586    
1587          if (isset($GLOBALS["HTTPS"]) && $GLOBALS["HTTPS"] == "on") {          if (isset($HTTP_SERVER_VARS["HTTPS"]) && $HTTP_SERVER_VARS["HTTPS"] == "on") {
1588                  $webRoot  = "https://";                  $webRoot  = "https://";
1589          } else {          } else {
1590                  $webRoot  = "http://";                  $webRoot  = "http://";
1591          }          }
1592          $webRoot .= $GLOBALS["HTTP_HOST"] . $relScriptDir;          $webRoot .= $HTTP_SERVER_VARS["HTTP_HOST"] . $relScriptDir;
1593    
1594          $FN=stripSlashes($FN);          // take variables from server
1595            $FN=stripSlashes($HTTP_POST_VARS["FN"]);
1596            $DIR=stripSlashes($HTTP_POST_VARS["DIR"]);
1597            $RELPATH=stripSlashes($HTTP_POST_VARS["RELPATH"]);
1598            $T=stripSlashes($HTTP_POST_VARS["T"]);
1599            $CONFIRM=stripSlashes($HTTP_POST_VARS["CONFIRM"]);
1600    
1601            // get
1602            $A=stripSlashes($HTTP_GET_VARS["A"]);
1603            $D=stripSlashes($HTTP_GET_VARS["D"]);
1604    
1605    //      if (isset($F)) Error("Document manager system error","variable $F shouldn't be set here (re-check old code)",1);
1606    //      $F=stripSlashes($HTTP_SERVER_VARS["PATH_INFO"]);
1607            $F=stripSlashes($HTTP_GET_VARS["F"]);
1608    
1609          switch ($POSTACTION) {          switch ($HTTP_POST_VARS["POSTACTION"]) {
1610          case "UPLOAD" :          case "UPLOAD" :
1611                    $FN_name=stripSlashes($HTTP_POST_FILES["FN"]["tmp_name"]);
1612                    $FN=stripSlashes($HTTP_POST_FILES["FN"]["name"]);
1613                  if (!is_writeable($fsDir)) Error("Write denied",$relDir) ;                  if (!is_writeable($fsDir)) Error("Write denied",$relDir) ;
1614                  if (strstr($FN_name,"/"))  
1615                          Error("Non-conforming filename") ;                  $source = $FN_name ;
                 // TODO : should rather check for escapeshellcmds  
                 // but maybe RFC 18xx asserts safe filenames ....  
                 $source = $FN ;  
1616                  if (! file_exists($source)) {                  if (! file_exists($source)) {
1617                          Error("You must select file with browse to upload it!");                          Error("You must select file with browse to upload it!");
1618                  }                  }
1619    
1620                    $FILENAME = $HTTP_POST_VARS["FILENAME"];
1621                    if (strstr($FILENAME,"/"))
1622                            Error("Upload error","Non-conforming filename. Filename <tt>$FILENAME</tt> has slashes (<tt>/</tt>) in it.") ;
1623                  if (! isset($FILENAME)) {       // from update file                  if (! isset($FILENAME)) {       // from update file
1624                          $target = "$fsDir/$FN_name" ;                          $target = "$fsDir/".basename($FN);
1625                  } else {                  } else {
1626                          $target = "$fsDir/$FILENAME";                          $target = "$fsDir/$FILENAME";
1627                  }                  }
# Line 1581  print " return: $return<br>\n"; Line 1643  print " return: $return<br>\n";
1643                  copy($source,$target) ;                  copy($source,$target) ;
1644                  chmod($target,$gblFilePerms) ;                  chmod($target,$gblFilePerms) ;
1645                  clearstatcache() ;                  clearstatcache() ;
                 Logit($target,"uploaded");  
1646                  if (isset($FILENAME)) {                  if (isset($FILENAME)) {
1647                            LogIt($target,"check-in",trperm_r | trperm_w);
1648                          Unlock($target);                          Unlock($target);
1649                    } else {
1650                            LogIt($target,"uploaded",trperm_r | trperm_w);
1651                  }                  }
                 ChangeLog($target,"updated");  
1652                  break ;                  break ;
1653    
1654          case "SAVE" :          case "SAVE" :
# Line 1602  print " return: $return<br>\n"; Line 1665  print " return: $return<br>\n";
1665                  fwrite($fh,$FILEDATA) ;                  fwrite($fh,$FILEDATA) ;
1666                  fclose($fh) ;                  fclose($fh) ;
1667                  clearstatcache() ;                  clearstatcache() ;
1668                  Logit($path,"saved changes");                  LogIt($path,"saved changes",trperm_r);
                 ChangeLog($path,"saved changes");  
1669                  break ;                  break ;
1670    
1671          case "CREATE" :          case "CREATE" :
# Line 1616  print " return: $return<br>\n"; Line 1678  print " return: $return<br>\n";
1678                  case "D" :  // create a directory                  case "D" :  // create a directory
1679                          if ( ! @mkdir($path,$gblDirPerms) )                          if ( ! @mkdir($path,$gblDirPerms) )
1680                                  Error("Mkdir failed",$relPath) ; // eg. if it exists                                  Error("Mkdir failed",$relPath) ; // eg. if it exists
1681                            else
1682                                    LogIt($path."/","dir created",trperm_w);
1683                          clearstatcache() ;                          clearstatcache() ;
1684                          break ;                          break ;
1685                  case "F" :  // create a new file                  case "F" :  // create a new file
# Line 1628  print " return: $return<br>\n"; Line 1692  print " return: $return<br>\n";
1692                          if ($fh) {                          if ($fh) {
1693                                  fputs($fh,"\n");                                  fputs($fh,"\n");
1694                                  fclose($fh) ;                                  fclose($fh) ;
1695                                  LogIt($path,"file created");                                  LogIt($path,"file created",trperm_r | trperm_w);
1696                          } else {                          } else {
1697                                  Error("Creation of file $relPath failed -- $path");                                  Error("Creation of file $relPath failed -- $path");
1698                          }                          }
1699                          $tstr = "$PHP_SELF?A=E&D=".urlencode($relDir)."&F=".urlencode($FN) ;                          $tstr = "$PHP_SELF?A=E&D=".urlencode($relDir)."&F=".urlencode($FN) ;
1700                          header("Location: " . $tstr) ;                          header("Location: " . $tstr) ;
                         ChangeLog($target,"created");  
1701                          exit ;                          exit ;
1702                  }                  }
1703                  break ;                  break ;
# Line 1656  print " return: $return<br>\n"; Line 1719  print " return: $return<br>\n";
1719    
1720  //                      if ( ! @unlink($path) ) {  //                      if ( ! @unlink($path) ) {
1721                          if ( ! rename($path,"$dir/.del/$file") ) {                          if ( ! rename($path,"$dir/.del/$file") ) {
1722                                    LogIt($path,"file delete failed");
1723                                  Error("File delete failed", $tstr . $path) ;                                  Error("File delete failed", $tstr . $path) ;
                                 Logit($path,"file delete failed");  
                                 exit ;  
1724                          } else {                          } else {
1725                                  Logit($path,"file deleted");                                  LogIt($path,"file deleted",trperm_w);
1726                                  MoveTo("$dir/.log/$file","$dir/.del/.log/");                                  MoveTo("$dir/.log/$file","$dir/.del/.log/");
1727                                  MoveTo("$dir/.note/$file","$dir/.del/.note/");                                  MoveTo("$dir/.note/$file","$dir/.del/.note/");
1728                                  MoveTo("$dir/.lock/$file","$dir/.del/.lock/");                                  MoveTo("$dir/.lock/$file","$dir/.del/.lock/");
1729                          }                          }
1730                  }                  } else {  // delete directory
1731                  else {  // delete directory                          if ( ! @rrmdir($fsDir) ) {
1732                    if ( ! @rrmdir($fsDir) ) {                                  Error("Rmdir failed", $tstr . $fsDir) ;
1733                      Error("Rmdir failed", $tstr . $fsDir) ;                          } else {
1734                    }                                  LogIt($path,"dir deleted",trperm_w);
1735                    else {                                  $relDir = dirname($relDir) ;  // move up
1736                      $relDir = dirname($relDir) ;  // move up                          }
                   }  
1737                  }                  }
1738                  break ;                  break ;
1739    
# Line 1682  print " return: $return<br>\n"; Line 1743  print " return: $return<br>\n";
1743                  if (substr($FN,0,4) != ".del") break ;                  if (substr($FN,0,4) != ".del") break ;
1744                  $file=substr($FN,4,strlen($FN)-4);                  $file=substr($FN,4,strlen($FN)-4);
1745    
1746                  Logit("$fsDir/.del/$file","undeleted");                  LogIt("$fsDir/.del/$file","undeleted",trperm_w);
1747                  MoveTo("$fsDir/.del/$file","$fsDir/");                  MoveTo("$fsDir/.del/$file","$fsDir/");
1748                  MoveTo("$fsDir/.del/.log/$file","$fsDir/.log/");                  MoveTo("$fsDir/.del/.log/$file","$fsDir/.log/");
1749                  MoveTo("$fsDir/.del/.note/$file","$fsDir/.note/");                  MoveTo("$fsDir/.del/.note/$file","$fsDir/.note/");
# Line 1693  print " return: $return<br>\n"; Line 1754  print " return: $return<br>\n";
1754          case "RENAME" :            case "RENAME" :  
1755                  if ( $CONFIRM != "on" ) break ;                  if ( $CONFIRM != "on" ) break ;
1756    
1757                  Logit("$fsDir/$FN","renamed $FN to $NEWNAME");                  $NEWNAME=stripSlashes($HTTP_POST_VARS["NEWNAME"]);
1758                    LogIt("$fsDir/$FN","renamed $FN to $NEWNAME",trperm_r);
1759                  safe_rename($fsDir,$FN,$NEWNAME);                  safe_rename($fsDir,$FN,$NEWNAME);
1760                  break ;                  break ;
1761    
1762          case "NOTE" :            case "NOTE" :  
1763                    $NOTE=stripSlashes($HTTP_POST_VARS["NOTE"]);
1764                  WriteNote("$fsDir/$FN","$NOTE");                  WriteNote("$fsDir/$FN","$NOTE");
1765                  break ;                  break ;
1766    
# Line 1733  print " return: $return<br>\n"; Line 1796  print " return: $return<br>\n";
1796                  if (!is_writeable($gblFsRoot . $relDir))                  if (!is_writeable($gblFsRoot . $relDir))
1797                          Error("Write access denied",$relDir) ;                          Error("Write access denied",$relDir) ;
1798                  $text  = "Use this page to upload a single " ;                  $text  = "Use this page to upload a single " ;
1799                  $text .= "file to <B>$HTTP_HOST</B>." ;                  $text .= "file to <B>$realm</B>." ;
1800                  StartHTML("(Upload Page)", $text) ;                  StartHTML("(Upload Page)", $text) ;
1801                  UploadPage($gblFsRoot, $relDir) ;                  UploadPage($gblFsRoot, $relDir) ;
1802                  EndHTML() ;                  EndHTML() ;
1803                  exit ;                  exit ;
1804          case "E" :          case "E" :
                 $F=stripSlashes($F);  
1805                  // detail of $relDir/$F                  // detail of $relDir/$F
1806                  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) ;
1807                  exit ;                  exit ;
# Line 1751  print " return: $return<br>\n"; Line 1813  print " return: $return<br>\n";
1813          case "Co" :          case "Co" :
1814                  // checkout                  // checkout
1815                  Lock("$gblFsRoot/$relDir/$F");                  Lock("$gblFsRoot/$relDir/$F");
1816                  Download("$gblFsRoot/$relDir/$F");                  Download("$gblFsRoot/$relDir/$F",1);
1817                  exit;                  exit;
1818          case "Ci" :          case "Ci" :
1819                  $F=stripSlashes($F);                  $F=stripSlashes($F);
# Line 1759  print " return: $return<br>\n"; Line 1821  print " return: $return<br>\n";
1821                  if (!is_writeable($gblFsRoot . $relDir))                  if (!is_writeable($gblFsRoot . $relDir))
1822                          Error("Write access denied",$relDir) ;                          Error("Write access denied",$relDir) ;
1823                  $text  = "Use this page to update a single " ;                  $text  = "Use this page to update a single " ;
1824                  $text .= "file to <B>$HTTP_HOST</B>." ;                  $text .= "file to <B>$realm</B>." ;
1825                  StartHTML("(Update file Page)", $text) ;                  StartHTML("(Update file Page)", $text) ;
1826                  UploadPage($gblFsRoot, $relDir, $F) ;                  UploadPage($gblFsRoot, $relDir, $F) ;
1827                  EndHTML() ;                  EndHTML() ;
# Line 1767  print " return: $return<br>\n"; Line 1829  print " return: $return<br>\n";
1829          case "V" :          case "V" :
1830                  // view                  // view
1831                  LogIt("$gblFsRoot/$relDir/$F","viewed");                  LogIt("$gblFsRoot/$relDir/$F","viewed");
1832                  if ($gblForceDownload) {                  Download("$gblFsRoot/$relDir/$F",$gblForceDownload);
                         Download("$gblFsRoot/$relDir/$F");  
                 } else {  
                         header("Content-Disposition: attachment; filename=$F" );  
                         Header("Location: $webRoot".urlpath("$relDir/$F"));  
                 }  
1833                  exit;                  exit;
1834          case "Ch" :          case "Ch" :
1835                  StartHTML("(File changes)","All changes chronologicaly...");                  StartHTML("(File changes)","All changes chronologicaly...");
# Line 1794  print " return: $return<br>\n"; Line 1851  print " return: $return<br>\n";
1851                  $title = "You should define \$title variable with page title";                  $title = "You should define \$title variable with page title";
1852                  include($inc_file);                  include($inc_file);
1853                  StartHTML($title, $text) ;                  StartHTML($title, $text) ;
1854                  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>";
1855                  EndHTML() ;                  EndHTML() ;
1856                  exit ;                  exit ;
1857          }          }
# Line 1803  print " return: $return<br>\n"; Line 1860  print " return: $return<br>\n";
1860          Navigate($gblFsRoot,$relDir) ;            Navigate($gblFsRoot,$relDir) ;  
1861          exit ;          exit ;
1862    
1863          Error("Whooah!","By cartesian logic, this never happens") ;          Error("Whooah!","By cartesian logic, this never happens",1) ;
1864  ?>  ?>

Legend:
Removed from v.1.1.1.1  
changed lines
  Added in v.1.10

  ViewVC Help
Powered by ViewVC 1.1.26