/[docman]/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.32 by dpavlin, Thu Feb 15 21:20:53 2001 UTC revision 1.43 by dpavlin, Wed Jun 20 10:29:19 2001 UTC
# Line 120  TODO: Line 120  TODO:
120          $gblImages   = array( ".jpg",".jpeg",".gif",".png",".ico",          $gblImages   = array( ".jpg",".jpeg",".gif",".png",".ico",
121                                ".bmp",".xbm") ;                                ".bmp",".xbm") ;
122    
123            // Where are users? (by default in .htusers file)
124            $gblUsers = "htusers_file";
125    
126  //////////////////////////////////////////////////////////////////  //////////////////////////////////////////////////////////////////
127    
128  function StartHTML($title,$text="") {  function StartHTML($title,$text="") {
# Line 222  function DetailPage($fsRoot,$relDir,$fn) Line 225  function DetailPage($fsRoot,$relDir,$fn)
225                  Error("Creation denied",$relDir) ;                  Error("Creation denied",$relDir) ;
226    
227          $text  = "Use this page to view, modify or " ;          $text  = "Use this page to view, modify or " ;
228          $text .= "delete a single document on this " ;          if (is_dir($fsPath)) {
229                    $text .="delete a directory on this " ;
230            } else {
231                    $text .= "delete a single document on this " ;
232            };
233          $text .= "web site." ;            $text .= "web site." ;  
234          $title = "(Detail Page)" ;          $title = "(Detail Page)" ;
235          StartHTML($title, $text) ;          StartHTML($title, $text) ;
# Line 232  function DetailPage($fsRoot,$relDir,$fn) Line 239  function DetailPage($fsRoot,$relDir,$fn)
239                  $fsize = filesize($fsPath) ;                  $fsize = filesize($fsPath) ;
240                  $fmodified = date("$GLOBALS[gblDateFmt] $GLOBALS[gblTimeFmt]", filemtime($fsPath)) ;                  $fmodified = date("$GLOBALS[gblDateFmt] $GLOBALS[gblTimeFmt]", filemtime($fsPath)) ;
241                  $faccessed = date("$GLOBALS[gblDateFmt] $GLOBALS[gblTimeFmt]", fileatime($fsPath)) ;                  $faccessed = date("$GLOBALS[gblDateFmt] $GLOBALS[gblTimeFmt]", fileatime($fsPath)) ;
242                  echo "<PRE>    file size: " . $fsize . " Bytes<BR>" ;                  $fuid=fileowner($fsPath);
243                    $fgid=filegroup($fsPath);
244                    $userinfo = posix_getpwuid($fuid);
245                    $grpinfo = posix_getgrgid($fgid);
246                    echo "<PRE>";
247                    if (!is_dir($fsPath)) echo "    file size: " . $fsize . " Bytes<BR>" ;
248                  echo "last modified: <B>" . $fmodified . "</B><BR>" ;                  echo "last modified: <B>" . $fmodified . "</B><BR>" ;
249                  echo "last accessed: <B>" . $faccessed . "</B><BR>" ;                  echo "last accessed: <B>" . $faccessed . "</B><BR>" ;
250                  echo "        owner: <B>" . fileowner($fsPath) . "</B><BR>" ;                  echo "        owner: <B>" . $userinfo["name"] . " [$fuid]</B><BR>" ;
251                  echo "        group: <B>" . filegroup($fsPath) . "</B><BR>" ;                  echo "        group: <B>" . $grpinfo["name"] . " [$fgid]</B><BR>" ;
252                  echo "  permissions: <B>" ;                  echo "  permissions: <B>" ;
253                  echo printf( "%o", fileperms($fsPath) ) . "</B>" ;                  echo printf( "%o", fileperms($fsPath) ) . "</B>" ;
254                  echo "</PRE>" ;                  echo "</PRE>" ;
255    
256          }          }
257    
258          if ( $editable && ($writable || !$exists) && !$file_lock ) {          if ( !is_dir($fsPath) && $editable && ($writable || !$exists) && !$file_lock ) {
259                  $fh = fopen($fsPath,"a+") ;                  $fh = fopen($fsPath,"a+") ;
260                  rewind($fh) ;                  rewind($fh) ;
261                  $fstr = fread($fh,filesize($fsPath)) ;                  $fstr = fread($fh,filesize($fsPath)) ;
# Line 350  echo($fstr) ; ?></TEXTAREA> Line 362  echo($fstr) ; ?></TEXTAREA>
362                          array_unshift($logarr,array($cl,$line[0],$line[1],$line[2],$line[3]));                          array_unshift($logarr,array($cl,$line[0],$line[1],$line[2],$line[3]));
363                  }                  }
364                  fclose($log);                  fclose($log);
365                  print "<hr><br><b>CHANGES TO THIS FILE</b><br><table border=0 width=100%>\n";                  if (is_dir("$fsDir/$fn")) {
366                            $whatis="DIRECTORY";
367                    } else {
368                            $whatis="FILE";
369                    }
370                    print "<hr><br><b>CHANGES TO THIS $whatis</b><br><table border=0 width=100%>\n";
371                  $bakcount = 0;  // start from 0, skip fist backup (it's current)                  $bakcount = 0;  // start from 0, skip fist backup (it's current)
372                  while ($e = array_shift($logarr)) {                  while ($e = array_shift($logarr)) {
373                          if (strstr($e[4],"upload")) {                          if (strstr($e[4],"upload")) {
# Line 680  function Navigate($fsRoot,$relDir) { Line 697  function Navigate($fsRoot,$relDir) {
697  <?php  <?php
698          }          }
699    
700    function plural($name,$count) {
701            $out="$count $name";
702            if ($count > 1) {
703                    $out.="s";
704            }
705            return $out;
706    }
707    
708          // output subdirs          // output subdirs
709          if (sizeof($dirList) > 0) {          if (sizeof($dirList) > 0) {
710                  sort($dirList) ;                  sort($dirList) ;
711  ?>  ?>
712    
713  <TR><TD></TD><TD COLSPAN=5 CLASS=TOP><HR>DIRECTORY NAME</TD></TR>  <TR><TD></TD><TD COLSPAN=2 CLASS=TOP>DIRECTORY NAME (<?= plural("dir",sizeof($dirList)) ?>)</TD><TD COLSPAN=3 CLASS=TOP>DIRECTORY NOTE</TR>
714    
715  <?php  <?php
716                  while (list($key,$dir) = each($dirList)) {                  while (list($key,$dir) = each($dirList)) {
717    
718                            $info_url=$self."?A=E&F=".urlencode($dir)."&D=".urlencode($relDir);
719                          $tstr = "<A HREF=\"" . $self . "?D=" ;                          $tstr = "<A HREF=\"" . $self . "?D=" ;
720                          $tstr .= urlencode($relDir."/".$dir) ;                          $tstr .= urlencode($relDir."/".$dir) ;
721                          $tstr .= "\">" . $dir . "/</A>" ;                          $tstr .= "\">" . $dir . "/</A>" ;
722                            $note_html="<a href=\"$info_url#note\">".$gblIcon("note")."</a>".ReadNote($fsDir.$dir);
723  ?>  ?>
724    
725  <TR><TD><?= $gblIcon("fldr") ?></TD>  <TR><TD>
726  <TD COLSPAN=5 CLASS=LST><?= $tstr ?></TD></TR>  <A HREF="<?= $info_url ?>" TITLE="View/Edit">
727    <?= $gblIcon("fldr") ?></A></TD>
728    <TD COLSPAN=2 CLASS=LST><?= $tstr ?></TD>
729    <TD COLSPAN=3 CLASS=LST><?= $note_html ?></TD></TR>
730    
731  <?php  <?php
732                  }  // iterate over dirs                  }  // iterate over dirs
# Line 705  function Navigate($fsRoot,$relDir) { Line 735  function Navigate($fsRoot,$relDir) {
735    
736  <TR><TD></TD><TD COLSPAN=5><HR><B><?= $webRoot . $relDir ?>  <TR><TD></TD><TD COLSPAN=5><HR><B><?= $webRoot . $relDir ?>
737  </B></TD></TR>  </B></TD></TR>
738  <TR><TD></TD><TD CLASS=TOP>DOCUMENT NAME</TD>  <TR><TD></TD><TD CLASS=TOP>DOCUMENT NAME (<?= plural("file",sizeof($fileList)) ?>)</TD>
739  <TD><?= $gblIcon("blank").$gblIcon("blank") ?></TD>  <TD><?= $gblIcon("blank").$gblIcon("blank") ?></TD>
740  <TD CLASS=TOP>NOTE</TD>  <TD CLASS=TOP>NOTE</TD>
741  <TD CLASS=TOP>LAST UPDATE</TD><TD CLASS=TOP>FILE SIZE</TD></TR>  <TD CLASS=TOP>LAST UPDATE</TD><TD CLASS=TOP>FILE SIZE</TD></TR>
# Line 837  if (file_exists(".info.inc")) { Line 867  if (file_exists(".info.inc")) {
867   <NOBR>NAME <INPUT TYPE="TEXT" NAME="FN" SIZE=14>   <NOBR>NAME <INPUT TYPE="TEXT" NAME="FN" SIZE=14>
868   <INPUT TYPE="HIDDEN" NAME="POSTACTION" VALUE="CREATE">   <INPUT TYPE="HIDDEN" NAME="POSTACTION" VALUE="CREATE">
869   <INPUT TYPE="HIDDEN" NAME="DIR" VALUE="<?= $relDir ?>">   <INPUT TYPE="HIDDEN" NAME="DIR" VALUE="<?= $relDir ?>">
870   <INPUT TYPE="SUBMIT" VALUE="CREATE"></NOBR>   <INPUT TYPE="SUBMIT" VALUE="CREATE" NAME="CREATE">
871     </NOBR>
872   <NOBR>OR <A HREF="<?= $self ?>?A=U&D=<?= urlencode($relDir) ?>">UPLOAD</A> A FILE   <NOBR>OR <A HREF="<?= $self ?>?A=U&D=<?= urlencode($relDir) ?>">UPLOAD</A> A FILE
873   </NOBR>   </NOBR>
874  </TD></TR>  </TD></TR>
# Line 957  function ReadNote($target) { Line 988  function ReadNote($target) {
988                  $msg=fgets($note,4096);                  $msg=fgets($note,4096);
989                  fclose($note);                  fclose($note);
990          }          }
991          return StripSlashes($msg);          return HtmlSpecialChars(StripSlashes($msg));
992    
993  }  }
994    
# Line 1038  function urlpath($url) { Line 1069  function urlpath($url) {
1069    
1070  //////////////////////////////////////////////////////////////////  //////////////////////////////////////////////////////////////////
1071    
1072  function safe_rename($from,$to) {  function safe_rename($fromdir,$fromfile,$tofile) {
1073          if (file_exists($from) && is_writable(dirname($to))) {          function try_rename($from,$to) {
1074                  rename($from,$to);  #               print "$from -> $to\n";
1075                    if (file_exists($from) && is_writeable(dirname($to))) {
1076                            rename($from,$to);
1077                    }
1078            }
1079    
1080            function try_dir($todir) {
1081                    if (! file_exists($todir)) {
1082                            mkdir($todir,0700);
1083                    }
1084            }
1085    
1086            $to="$fromdir/$tofile";
1087            $todir=dirname($to);
1088            $tofile=basename($to);
1089    
1090    #       print "<pre>$fromdir / $fromfile -> $todir / $tofile\n\n";
1091    
1092            try_rename("$fromdir/$fromfile","$todir/$tofile");
1093            try_dir("$todir/.log");
1094            try_rename("$fromdir/.log/$fromfile","$todir/.log/$tofile");
1095            try_dir("$todir/.note");
1096            try_rename("$fromdir/.note/$fromfile","$todir/.note/$tofile");
1097            try_dir("$todir/.lock");
1098            try_rename("$fromdir/.lock/$fromfile","$todir/.lock/$tofile");
1099            try_dir("$todir/.bak");
1100            for($i=0;$i<=$GLOBALS[gblNumBackups];$i++) {
1101                    try_rename("$fromdir/.bak/$i/$fromfile","$todir/.bak/$i/$tofile");
1102          }          }
1103  }  }
1104    
1105    
1106  //////////////////////////////////////////////////////////////////  //////////////////////////////////////////////////////////////////
1107    
1108  // recursivly delete directory  // recursivly delete directory
# Line 1119  function DisplayChangeLog($day) { Line 1178  function DisplayChangeLog($day) {
1178          // creation if password not yet set.          // creation if password not yet set.
1179          if ($STYLE == "get") { CSS() ; exit ; }          if ($STYLE == "get") { CSS() ; exit ; }
1180    
1181          $htusers_file=dirname($SCRIPT_FILENAME)."/.htusers";          $fsScriptDir  = dirname($SCRIPT_FILENAME) ;    
1182          if (! file_exists($htusers_file)) {          // i.e. /home/httpd/html/docman
1183                  if (is_writable(dirname($SCRIPT_FILENAME))) {  
1184                          $htusers=fopen($htusers_file,"a+");          // read user-defined configuration
1185                          fputs($htusers,"# Change owner of $htusers_file to root !!\n");          if (file_exists("$fsScriptDir/.docman.conf")) {
1186                          fputs($htusers,"demo:full name:[md5_hash|auth_*]:e-mail\n");                  include("$fsScriptDir/.docman.conf");
                         fclose($htusers);  
                         Error("Proto user file created!","Please edit <tt>$htusers_file</tt> and set it correct permissions (<B>not writable by web server as it is now!</b>). You can add users using <tt>adduser.pl</tt> script!");  
                         exit;  
                 } else {  
                         Error("Can't create proto user file!","Please make directory <tt>".dirname($htusers_file)."</tt> writable or create <tt>.htusers</tt> file by hand using <tt>adduser.pl</tt> script!");  
                         exit;  
                 }  
1187          }          }
1188          $htusers=fopen($htusers_file,"r");  
1189          while($user = fgetcsv($htusers,255,":")) {          // where do we get users from?
1190                  if ($user[0] == $GLOBALS["PHP_AUTH_USER"]) {          if (file_exists("$gblIncDir/$gblUsers.php")) {
1191                          $gblUserName=$user[1];                  include("$gblIncDir/$gblUsers.php");
1192                          $gblPw=$user[2];          } else {
1193                          if (substr($gblPw,0,5) == "auth_" && file_exists("$gblIncDir/$gblPw.php")) {                  Error("Configuration error","Can't find user handling module at <tt>$gblIncDir/$gblUsers.php</tt> ! Please fix <tt>$fsScriptDir/.docman.conf</tt>");
                                 require("$gblIncDir/$gblPw.php");  
                                 if ($gblPw($user)) {  
                                         $gblPw=md5($PHP_AUTH_USER.$PHP_AUTH_PW);  
                                 } else {  
                                         $gblPw="error".md5($PHP_AUTH_USER.$PHP_AUTH_PW);  
                                 }  
                         }  
                         $gblEmail=$user[3];  
                         continue ;  
                 }  
1194          }          }
         fclose($htusers);  
1195    
1196          // authentication failure          // authentication failure
1197          if ( md5($PHP_AUTH_USER.$PHP_AUTH_PW) != $gblPw ||          if ( md5($PHP_AUTH_USER.$PHP_AUTH_PW) != $gblPw ||
# Line 1167  function DisplayChangeLog($day) { Line 1208  function DisplayChangeLog($day) {
1208                  $relDir = urldecode($D) ;  // then use GET                  $relDir = urldecode($D) ;  // then use GET
1209          }                }      
1210    
1211            $relDir=stripSlashes($relDir);
1212    
1213          if ($relDir == "/") $relDir = "" ;                if ($relDir == "/") $relDir = "" ;      
1214          // default : website root = ""          // default : website root = ""
1215    
# Line 1180  function DisplayChangeLog($day) { Line 1223  function DisplayChangeLog($day) {
1223          $relScriptDir = dirname($SCRIPT_NAME) ;                  $relScriptDir = dirname($SCRIPT_NAME) ;        
1224          // i.e. /docman          // i.e. /docman
1225    
         $fsScriptDir  = dirname($SCRIPT_FILENAME) ;      
         // i.e. /home/httpd/html/docman  
   
1226          // start on server root          // start on server root
1227  //      $gblFsRoot = substr($fsScriptDir,0, strlen($fsScriptDir)-strlen($relScriptDir)) ;  //      $gblFsRoot = substr($fsScriptDir,0, strlen($fsScriptDir)-strlen($relScriptDir)) ;
1228          // or on script root          // or on script root
# Line 1201  function DisplayChangeLog($day) { Line 1241  function DisplayChangeLog($day) {
1241    
1242          $FN=stripSlashes($FN);          $FN=stripSlashes($FN);
1243    
1244    
1245          switch ($POSTACTION) {          switch ($POSTACTION) {
1246          case "UPLOAD" :          case "UPLOAD" :
1247                  if (!is_writeable($fsDir)) Error("Write denied",$relDir) ;                  if (!is_writeable($fsDir)) Error("Write denied",$relDir) ;
# Line 1276  function DisplayChangeLog($day) { Line 1317  function DisplayChangeLog($day) {
1317  // this functionality is doubled in DetailView().  // this functionality is doubled in DetailView().
1318  // better keep it here altogether  // better keep it here altogether
1319  // chmod perms to $gblFilePerms  // chmod perms to $gblFilePerms
1320                          if ( file_exists($path) && !is_writable($path) )                          if ( file_exists($path) && !is_writeable($path) )
1321                                  Error("File not writable", $relPath) ;                                  Error("File not writable", $relPath) ;
1322                          $fh = fopen($path, "w+") ;                          $fh = fopen($path, "w+") ;
1323                          if ($fh) {                          if ($fh) {
# Line 1348  function DisplayChangeLog($day) { Line 1389  function DisplayChangeLog($day) {
1389                  if ( $CONFIRM != "on" ) break ;                  if ( $CONFIRM != "on" ) break ;
1390    
1391                  Logit("$fsDir/$FN","renamed $FN to $NEWNAME");                  Logit("$fsDir/$FN","renamed $FN to $NEWNAME");
1392                  safe_rename("$fsDir/$FN","$fsDir/$NEWNAME");                  safe_rename($fsDir,$FN,$NEWNAME);
                 safe_rename("$fsDir/.log/$FN","$fsDir/.log/$NEWNAME");  
                 safe_rename("$fsDir/.note/$FN","$fsDir/.note/$NEWNAME");  
                 safe_rename("$fsDir/.lock/$FN","$fsDir/.lock/$NEWNAME");  
                 for($i=0;$i<=$GLOBALS[gblNumBackups];$i++) {  
                         safe_rename("$fsDir/.bak/$i/$FN","$fsDir/.bak/$i/$NEWNAME");  
                 }  
   
1393                  break ;                  break ;
1394    
1395          case "NOTE" :            case "NOTE" :  
# Line 1401  function DisplayChangeLog($day) { Line 1435  function DisplayChangeLog($day) {
1435          case "E" :          case "E" :
1436                  $F=stripSlashes($F);                  $F=stripSlashes($F);
1437                  // detail of $relDir/$F                  // detail of $relDir/$F
1438                  if (is_file("$gblFsRoot/$relDir/$F")) DetailPage($gblFsRoot, $relDir, $F) ;                  if (is_file("$gblFsRoot/$relDir/$F") || is_dir("$gblFsRoot/$relDir/$F")) DetailPage($gblFsRoot, $relDir, $F) ;
1439                  exit ;                  exit ;
1440          case "C" :          case "C" :
1441                  $F=stripSlashes($F);                  $F=stripSlashes($F);

Legend:
Removed from v.1.32  
changed lines
  Added in v.1.43

  ViewVC Help
Powered by ViewVC 1.1.26