/[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.33 by dpavlin, Thu Feb 15 22:14:21 2001 UTC revision 1.45 by dpavlin, Thu Jun 21 08:56:35 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            // which files to hide (separated by ,)
124            $gblHide = "";
125    
126            // Where are users? (by default in .htusers file)
127            $gblUsers = "htusers_file";
128    
129  //////////////////////////////////////////////////////////////////  //////////////////////////////////////////////////////////////////
130    
131  function StartHTML($title,$text="") {  function StartHTML($title,$text="") {
# Line 236  function DetailPage($fsRoot,$relDir,$fn) Line 242  function DetailPage($fsRoot,$relDir,$fn)
242                  $fsize = filesize($fsPath) ;                  $fsize = filesize($fsPath) ;
243                  $fmodified = date("$GLOBALS[gblDateFmt] $GLOBALS[gblTimeFmt]", filemtime($fsPath)) ;                  $fmodified = date("$GLOBALS[gblDateFmt] $GLOBALS[gblTimeFmt]", filemtime($fsPath)) ;
244                  $faccessed = date("$GLOBALS[gblDateFmt] $GLOBALS[gblTimeFmt]", fileatime($fsPath)) ;                  $faccessed = date("$GLOBALS[gblDateFmt] $GLOBALS[gblTimeFmt]", fileatime($fsPath)) ;
245                  $userinfo = posix_getpwuid(fileowner($fsPath));                  $fuid=fileowner($fsPath);
246                  $grpinfo = posix_getgrgid(filegroup($fsPath));                  $fgid=filegroup($fsPath);
247                    $userinfo = posix_getpwuid($fuid);
248                    $grpinfo = posix_getgrgid($fgid);
249                  echo "<PRE>";                  echo "<PRE>";
250                  if (!is_dir($fsPath)) echo "file size: " . $fsize . " Bytes<BR>" ;                  if (!is_dir($fsPath)) echo "    file size: " . $fsize . " Bytes<BR>" ;
251                  echo "last modified: <B>" . $fmodified . "</B><BR>" ;                  echo "last modified: <B>" . $fmodified . "</B><BR>" ;
252                  echo "last accessed: <B>" . $faccessed . "</B><BR>" ;                  echo "last accessed: <B>" . $faccessed . "</B><BR>" ;
253                  echo "        owner: <B>" . $userinfo["name"] . "</B><BR>" ;                  echo "        owner: <B>" . $userinfo["name"] . " [$fuid]</B><BR>" ;
254                  echo "        group: <B>" . $grpinfo["name"] . "</B><BR>" ;                  echo "        group: <B>" . $grpinfo["name"] . " [$fgid]</B><BR>" ;
255                  echo "  permissions: <B>" ;                  echo "  permissions: <B>" ;
256                  echo printf( "%o", fileperms($fsPath) ) . "</B>" ;                  echo printf( "%o", fileperms($fsPath) ) . "</B>" ;
257                  echo "</PRE>" ;                  echo "</PRE>" ;
# Line 628  function GifIcon($txt) { Line 636  function GifIcon($txt) {
636    
637  function Navigate($fsRoot,$relDir) {  function Navigate($fsRoot,$relDir) {
638    
639          global $gblEditable, $gblIcon, $gblModDays, $webRoot ;          global $gblEditable, $gblIcon, $gblModDays, $webRoot, $gblHide ;
640    
641          $self     = $GLOBALS["PHP_SELF"] ;          $self     = $GLOBALS["PHP_SELF"] ;
642    
# Line 636  function Navigate($fsRoot,$relDir) { Line 644  function Navigate($fsRoot,$relDir) {
644    
645          if (!is_dir($fsDir)) Error("Dir not found",$relDir) ;          if (!is_dir($fsDir)) Error("Dir not found",$relDir) ;
646    
647            $hide_items=",$gblHide,";
648    
649          // read directory contents          // read directory contents
650          if ( !($dir = @opendir($fsDir)) )          if ( !($dir = @opendir($fsDir)) )
651                  Error("Read Access denied",$relDir) ;                  Error("Read Access denied",$relDir) ;
652          while ($item = readdir($dir)) {          while ($item = readdir($dir)) {
653                  if ( $item == ".." || $item == "." || substr($item,0,1) == "." ) continue ;                  if ( substr($item,0,1) == "." || strstr($hide_items,",$item,") ) continue ;
654                  if ( is_dir($fsDir . $item) ) {                  if ( is_dir($fsDir . $item) ) {
655                          $dirList[] = $item ;                          $dirList[] = $item ;
656                  } else if ( is_file($fsDir . $item) ) {                  } else if ( is_file($fsDir . $item) ) {
# Line 659  function Navigate($fsRoot,$relDir) { Line 669  function Navigate($fsRoot,$relDir) {
669          // scan deleted files          // scan deleted files
670          if ( $GLOBALS[show_deleted] == 1 && ($dir = @opendir("$fsDir/.del")) ) {          if ( $GLOBALS[show_deleted] == 1 && ($dir = @opendir("$fsDir/.del")) ) {
671                  while ($item = readdir($dir)) {                  while ($item = readdir($dir)) {
672                          if ( substr($item,0,1) == "." ) continue ;                          if ( substr($item,0,1) == "." || strstr($hide_items,",$item,") ) continue ;
673                          $fileList[] = ".del/$item" ;                                      $fileList[] = ".del/$item" ;            
674                  }                  }
675                  closedir($dir) ;                  closedir($dir) ;
# Line 692  function Navigate($fsRoot,$relDir) { Line 702  function Navigate($fsRoot,$relDir) {
702  <?php  <?php
703          }          }
704    
705    function plural($name,$count) {
706            $out="$count $name";
707            if ($count > 1) {
708                    $out.="s";
709            }
710            return $out;
711    }
712    
713          // output subdirs          // output subdirs
714          if (sizeof($dirList) > 0) {          if (sizeof($dirList) > 0) {
715                  sort($dirList) ;                  sort($dirList) ;
716  ?>  ?>
717    
718  <TR><TD></TD><TD COLSPAN=2 CLASS=TOP>DIRECTORY NAME</TD><TD COLSPAN=3 CLASS=TOP>DIRECTORY NOTE</TR>  <TR><TD></TD><TD COLSPAN=2 CLASS=TOP>DIRECTORY NAME (<?= plural("dir",sizeof($dirList)) ?>)</TD><TD COLSPAN=3 CLASS=TOP>DIRECTORY NOTE</TR>
719    
720  <?php  <?php
721                  while (list($key,$dir) = each($dirList)) {                  while (list($key,$dir) = each($dirList)) {
# Line 722  function Navigate($fsRoot,$relDir) { Line 740  function Navigate($fsRoot,$relDir) {
740    
741  <TR><TD></TD><TD COLSPAN=5><HR><B><?= $webRoot . $relDir ?>  <TR><TD></TD><TD COLSPAN=5><HR><B><?= $webRoot . $relDir ?>
742  </B></TD></TR>  </B></TD></TR>
743  <TR><TD></TD><TD CLASS=TOP>DOCUMENT NAME</TD>  <TR><TD></TD><TD CLASS=TOP>DOCUMENT NAME (<?= plural("file",sizeof($fileList)) ?>)</TD>
744  <TD><?= $gblIcon("blank").$gblIcon("blank") ?></TD>  <TD><?= $gblIcon("blank").$gblIcon("blank") ?></TD>
745  <TD CLASS=TOP>NOTE</TD>  <TD CLASS=TOP>NOTE</TD>
746  <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 854  if (file_exists(".info.inc")) { Line 872  if (file_exists(".info.inc")) {
872   <NOBR>NAME <INPUT TYPE="TEXT" NAME="FN" SIZE=14>   <NOBR>NAME <INPUT TYPE="TEXT" NAME="FN" SIZE=14>
873   <INPUT TYPE="HIDDEN" NAME="POSTACTION" VALUE="CREATE">   <INPUT TYPE="HIDDEN" NAME="POSTACTION" VALUE="CREATE">
874   <INPUT TYPE="HIDDEN" NAME="DIR" VALUE="<?= $relDir ?>">   <INPUT TYPE="HIDDEN" NAME="DIR" VALUE="<?= $relDir ?>">
875   <INPUT TYPE="SUBMIT" VALUE="CREATE"></NOBR>   <INPUT TYPE="SUBMIT" VALUE="CREATE" NAME="CREATE">
876     </NOBR>
877   <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
878   </NOBR>   </NOBR>
879  </TD></TR>  </TD></TR>
# Line 974  function ReadNote($target) { Line 993  function ReadNote($target) {
993                  $msg=fgets($note,4096);                  $msg=fgets($note,4096);
994                  fclose($note);                  fclose($note);
995          }          }
996          return StripSlashes($msg);          return HtmlSpecialChars(StripSlashes($msg));
997    
998  }  }
999    
# Line 1055  function urlpath($url) { Line 1074  function urlpath($url) {
1074    
1075  //////////////////////////////////////////////////////////////////  //////////////////////////////////////////////////////////////////
1076    
1077  function safe_rename($from,$to) {  function safe_rename($fromdir,$fromfile,$tofile) {
1078          if (file_exists($from) && is_writable(dirname($to))) {          function try_rename($from,$to) {
1079                  rename($from,$to);  #               print "$from -> $to\n";
1080                    if (file_exists($from) && is_writeable(dirname($to))) {
1081                            rename($from,$to);
1082                    }
1083            }
1084    
1085            function try_dir($todir) {
1086                    if (! file_exists($todir)) {
1087                            mkdir($todir,0700);
1088                    }
1089            }
1090    
1091            $to="$fromdir/$tofile";
1092            $todir=dirname($to);
1093            $tofile=basename($to);
1094    
1095    #       print "<pre>$fromdir / $fromfile -> $todir / $tofile\n\n";
1096    
1097            try_rename("$fromdir/$fromfile","$todir/$tofile");
1098            try_dir("$todir/.log");
1099            try_rename("$fromdir/.log/$fromfile","$todir/.log/$tofile");
1100            try_dir("$todir/.note");
1101            try_rename("$fromdir/.note/$fromfile","$todir/.note/$tofile");
1102            try_dir("$todir/.lock");
1103            try_rename("$fromdir/.lock/$fromfile","$todir/.lock/$tofile");
1104            try_dir("$todir/.bak");
1105            for($i=0;$i<=$GLOBALS[gblNumBackups];$i++) {
1106                    try_rename("$fromdir/.bak/$i/$fromfile","$todir/.bak/$i/$tofile");
1107          }          }
1108  }  }
1109    
1110    
1111  //////////////////////////////////////////////////////////////////  //////////////////////////////////////////////////////////////////
1112    
1113  // recursivly delete directory  // recursivly delete directory
# Line 1136  function DisplayChangeLog($day) { Line 1183  function DisplayChangeLog($day) {
1183          // creation if password not yet set.          // creation if password not yet set.
1184          if ($STYLE == "get") { CSS() ; exit ; }          if ($STYLE == "get") { CSS() ; exit ; }
1185    
1186          $htusers_file=dirname($SCRIPT_FILENAME)."/.htusers";          $fsScriptDir  = dirname($SCRIPT_FILENAME) ;    
1187          if (! file_exists($htusers_file)) {          // i.e. /home/httpd/html/docman
1188                  if (is_writable(dirname($SCRIPT_FILENAME))) {  
1189                          $htusers=fopen($htusers_file,"a+");          // read user-defined configuration
1190                          fputs($htusers,"# Change owner of $htusers_file to root !!\n");          if (file_exists("$fsScriptDir/.docman.conf")) {
1191                          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;  
                 }  
1192          }          }
1193          $htusers=fopen($htusers_file,"r");  
1194          while($user = fgetcsv($htusers,255,":")) {          // where do we get users from?
1195                  if ($user[0] == $GLOBALS["PHP_AUTH_USER"]) {          if (file_exists("$gblIncDir/$gblUsers.php")) {
1196                          $gblUserName=$user[1];                  include("$gblIncDir/$gblUsers.php");
1197                          $gblPw=$user[2];          } else {
1198                          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 ;  
                 }  
1199          }          }
         fclose($htusers);  
1200    
1201          // authentication failure          // authentication failure
1202          if ( md5($PHP_AUTH_USER.$PHP_AUTH_PW) != $gblPw ||          if ( md5($PHP_AUTH_USER.$PHP_AUTH_PW) != $gblPw ||
# Line 1184  function DisplayChangeLog($day) { Line 1213  function DisplayChangeLog($day) {
1213                  $relDir = urldecode($D) ;  // then use GET                  $relDir = urldecode($D) ;  // then use GET
1214          }                }      
1215    
1216            $relDir=stripSlashes($relDir);
1217    
1218          if ($relDir == "/") $relDir = "" ;                if ($relDir == "/") $relDir = "" ;      
1219          // default : website root = ""          // default : website root = ""
1220    
# Line 1197  function DisplayChangeLog($day) { Line 1228  function DisplayChangeLog($day) {
1228          $relScriptDir = dirname($SCRIPT_NAME) ;                  $relScriptDir = dirname($SCRIPT_NAME) ;        
1229          // i.e. /docman          // i.e. /docman
1230    
         $fsScriptDir  = dirname($SCRIPT_FILENAME) ;      
         // i.e. /home/httpd/html/docman  
   
1231          // start on server root          // start on server root
1232  //      $gblFsRoot = substr($fsScriptDir,0, strlen($fsScriptDir)-strlen($relScriptDir)) ;  //      $gblFsRoot = substr($fsScriptDir,0, strlen($fsScriptDir)-strlen($relScriptDir)) ;
1233          // or on script root          // or on script root
# Line 1218  function DisplayChangeLog($day) { Line 1246  function DisplayChangeLog($day) {
1246    
1247          $FN=stripSlashes($FN);          $FN=stripSlashes($FN);
1248    
1249    
1250          switch ($POSTACTION) {          switch ($POSTACTION) {
1251          case "UPLOAD" :          case "UPLOAD" :
1252                  if (!is_writeable($fsDir)) Error("Write denied",$relDir) ;                  if (!is_writeable($fsDir)) Error("Write denied",$relDir) ;
# Line 1293  function DisplayChangeLog($day) { Line 1322  function DisplayChangeLog($day) {
1322  // this functionality is doubled in DetailView().  // this functionality is doubled in DetailView().
1323  // better keep it here altogether  // better keep it here altogether
1324  // chmod perms to $gblFilePerms  // chmod perms to $gblFilePerms
1325                          if ( file_exists($path) && !is_writable($path) )                          if ( file_exists($path) && !is_writeable($path) )
1326                                  Error("File not writable", $relPath) ;                                  Error("File not writable", $relPath) ;
1327                          $fh = fopen($path, "w+") ;                          $fh = fopen($path, "w+") ;
1328                          if ($fh) {                          if ($fh) {
# Line 1365  function DisplayChangeLog($day) { Line 1394  function DisplayChangeLog($day) {
1394                  if ( $CONFIRM != "on" ) break ;                  if ( $CONFIRM != "on" ) break ;
1395    
1396                  Logit("$fsDir/$FN","renamed $FN to $NEWNAME");                  Logit("$fsDir/$FN","renamed $FN to $NEWNAME");
1397                  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");  
                 }  
   
1398                  break ;                  break ;
1399    
1400          case "NOTE" :            case "NOTE" :  

Legend:
Removed from v.1.33  
changed lines
  Added in v.1.45

  ViewVC Help
Powered by ViewVC 1.1.26