/[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.30 by dpavlin, Fri Jan 26 12:39:57 2001 UTC revision 1.41 by dpavlin, Mon Jun 4 08:20:55 2001 UTC
# Line 83  TODO: Line 83  TODO:
83    
84          $gblPw    = "";          $gblPw    = "";
85    
         $htusers_file=dirname($SCRIPT_FILENAME)."/.htusers";  
         if (! file_exists($htusers_file)) {  
                 $htusers=fopen($htusers_file,"a+");  
                 fputs($htusers,"# Change owner of $htusers_file to root !!\n");  
                 fputs($htusers,"demo:full name:[md5_hash|auth_*]:e-mail\n");  
                 fclose($htusers);  
         }  
         $htusers=fopen($htusers_file,"r");  
         while($user = fgetcsv($htusers,255,":")) {  
                 if ($user[0] == $GLOBALS["PHP_AUTH_USER"]) {  
                         $gblUserName=$user[1];  
                         $gblPw=$user[2];  
                         if (substr($gblPw,0,5) == "auth_" && file_exists("$gblIncDir/$gblPw.php")) {  
                                 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 ;  
                 }  
         }  
         fclose($htusers);  
   
86          // date format          // date format
87  //      $gblDateFmt="D, F d, Y";  //      $gblDateFmt="D, F d, Y";
88          $gblDateFmt="Y-m-d";          $gblDateFmt="Y-m-d";
# Line 229  A:HOVER { color:red; } Line 203  A:HOVER { color:red; }
203    
204  function DetailPage($fsRoot,$relDir,$fn) {  function DetailPage($fsRoot,$relDir,$fn) {
205                    
206          global $gblEditable, $gblImages ;          global $gblEditable, $gblImages, $webRoot ;
207          $self = $GLOBALS["PHP_SELF"] ;          $self = $GLOBALS["PHP_SELF"] ;
208    
209          $relPath  = $relDir . "/" . $fn ;          $relPath  = $relDir . "/" . $fn ;
# Line 248  function DetailPage($fsRoot,$relDir,$fn) Line 222  function DetailPage($fsRoot,$relDir,$fn)
222                  Error("Creation denied",$relDir) ;                  Error("Creation denied",$relDir) ;
223    
224          $text  = "Use this page to view, modify or " ;          $text  = "Use this page to view, modify or " ;
225          $text .= "delete a single document on this " ;          if (is_dir($fsPath)) {
226                    $text .="delete a directory on this " ;
227            } else {
228                    $text .= "delete a single document on this " ;
229            };
230          $text .= "web site." ;            $text .= "web site." ;  
231          $title = "(Detail Page)" ;          $title = "(Detail Page)" ;
232          StartHTML($title, $text) ;          StartHTML($title, $text) ;
# Line 258  function DetailPage($fsRoot,$relDir,$fn) Line 236  function DetailPage($fsRoot,$relDir,$fn)
236                  $fsize = filesize($fsPath) ;                  $fsize = filesize($fsPath) ;
237                  $fmodified = date("$GLOBALS[gblDateFmt] $GLOBALS[gblTimeFmt]", filemtime($fsPath)) ;                  $fmodified = date("$GLOBALS[gblDateFmt] $GLOBALS[gblTimeFmt]", filemtime($fsPath)) ;
238                  $faccessed = date("$GLOBALS[gblDateFmt] $GLOBALS[gblTimeFmt]", fileatime($fsPath)) ;                  $faccessed = date("$GLOBALS[gblDateFmt] $GLOBALS[gblTimeFmt]", fileatime($fsPath)) ;
239                  echo "<PRE>    file size: " . $fsize . " Bytes<BR>" ;                  $fuid=fileowner($fsPath);
240                    $fgid=filegroup($fsPath);
241                    $userinfo = posix_getpwuid($fuid);
242                    $grpinfo = posix_getgrgid($fgid);
243                    echo "<PRE>";
244                    if (!is_dir($fsPath)) echo "    file size: " . $fsize . " Bytes<BR>" ;
245                  echo "last modified: <B>" . $fmodified . "</B><BR>" ;                  echo "last modified: <B>" . $fmodified . "</B><BR>" ;
246                  echo "last accessed: <B>" . $faccessed . "</B><BR>" ;                  echo "last accessed: <B>" . $faccessed . "</B><BR>" ;
247                  echo "        owner: <B>" . fileowner($fsPath) . "</B><BR>" ;                  echo "        owner: <B>" . $userinfo["name"] . " [$fuid]</B><BR>" ;
248                  echo "        group: <B>" . filegroup($fsPath) . "</B><BR>" ;                  echo "        group: <B>" . $grpinfo["name"] . " [$fgid]</B><BR>" ;
249                  echo "  permissions: <B>" ;                  echo "  permissions: <B>" ;
250                  echo printf( "%o", fileperms($fsPath) ) . "</B>" ;                  echo printf( "%o", fileperms($fsPath) ) . "</B>" ;
251                  echo "</PRE>" ;                  echo "</PRE>" ;
252    
253          }          }
254    
255          if ( $editable && ($writable || !$exists) && !$file_lock ) {          if ( !is_dir($fsPath) && $editable && ($writable || !$exists) && !$file_lock ) {
256                  $fh = fopen($fsPath,"a+") ;                  $fh = fopen($fsPath,"a+") ;
257                  rewind($fh) ;                  rewind($fh) ;
258                  $fstr = fread($fh,filesize($fsPath)) ;                  $fstr = fread($fh,filesize($fsPath)) ;
# Line 297  echo($fstr) ; ?></TEXTAREA> Line 280  echo($fstr) ; ?></TEXTAREA>
280          }          }
281          if ( !$file_lock && $ext!="" && strstr(join(' ',$gblImages),$ext) ) {            if ( !$file_lock && $ext!="" && strstr(join(' ',$gblImages),$ext) ) {  
282                  $info  = getimagesize($fsPath) ;                  $info  = getimagesize($fsPath) ;
283                  $tstr = "<IMG SRC=\"".urlpath($relPath)."\" BORDER=0 " ;                  $tstr = "<IMG SRC=\"$webRoot".urlpath($relPath)."\" BORDER=0 " ;
284                  $tstr .= $info[3] . " ALT=\"" . $fn . " - " ;                  $tstr .= $info[3] . " ALT=\"" . $fn . " - " ;
285                  $tstr .= (int)(($fsize+1023)/1024) . "Kb\">" ;                  $tstr .= (int)(($fsize+1023)/1024) . "Kb\">" ;
286  //              echo htmlentities($tstr) . "<BR><BR>" . $tstr ;  //              echo htmlentities($tstr) . "<BR><BR>" . $tstr ;
# Line 376  echo($fstr) ; ?></TEXTAREA> Line 359  echo($fstr) ; ?></TEXTAREA>
359                          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]));
360                  }                  }
361                  fclose($log);                  fclose($log);
362                  print "<hr><br><b>CHANGES TO THIS FILE</b><br><table border=0 width=100%>\n";                  if (is_dir("$fsDir/$fn")) {
363                            $whatis="DIRECTORY";
364                    } else {
365                            $whatis="FILE";
366                    }
367                    print "<hr><br><b>CHANGES TO THIS $whatis</b><br><table border=0 width=100%>\n";
368                  $bakcount = 0;  // start from 0, skip fist backup (it's current)                  $bakcount = 0;  // start from 0, skip fist backup (it's current)
369                  while ($e = array_shift($logarr)) {                  while ($e = array_shift($logarr)) {
370                          if (strstr($e[4],"upload")) {                          if (strstr($e[4],"upload")) {
371                                  if (file_exists("$bakdir/$bakcount/$name")) {                                  if (file_exists("$bakdir/$bakcount/$name")) {
372                                          $e[4]="<a href=\"".urlpath(dirname($relPath)."/.bak/$bakcount/$name")."\">$e[4]</a>";                                          $e[4]="<a href=\"$webRoot".urlpath(dirname($relPath)."/.bak/$bakcount/$name")."\">$e[4]</a>";
373                                  }                                  }
374                                  $bakcount++;                                  $bakcount++;
375                          }                          }
# Line 642  function GifIcon($txt) { Line 630  function GifIcon($txt) {
630    
631  function Navigate($fsRoot,$relDir) {  function Navigate($fsRoot,$relDir) {
632    
633          global $gblEditable, $gblIcon, $gblModDays ;          global $gblEditable, $gblIcon, $gblModDays, $webRoot ;
634    
635          $self     = $GLOBALS["PHP_SELF"] ;          $self     = $GLOBALS["PHP_SELF"] ;
636          if (isset($GLOBALS["HTTPS"]) && $GLOBALS["HTTPS"] == "on") {  
637                  $webRoot  = "https://" . $GLOBALS["HTTP_HOST"] ;          $fsDir = $fsRoot . $relDir . "/" ; // current directory
         } else {  
                 $webRoot  = "http://" . $GLOBALS["HTTP_HOST"] ;  
         }  
         $fsDir    = $fsRoot . $relDir . "/" ; // current directory  
638    
639          if (!is_dir($fsDir)) Error("Dir not found",$relDir) ;          if (!is_dir($fsDir)) Error("Dir not found",$relDir) ;
640    
# Line 710  function Navigate($fsRoot,$relDir) { Line 694  function Navigate($fsRoot,$relDir) {
694  <?php  <?php
695          }          }
696    
697    function plural($name,$count) {
698            $out="$count $name";
699            if ($count > 1) {
700                    $out.="s";
701            }
702            return $out;
703    }
704    
705          // output subdirs          // output subdirs
706          if (sizeof($dirList) > 0) {          if (sizeof($dirList) > 0) {
707                  sort($dirList) ;                  sort($dirList) ;
708  ?>  ?>
709    
710  <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>
711    
712  <?php  <?php
713                  while (list($key,$dir) = each($dirList)) {                  while (list($key,$dir) = each($dirList)) {
714    
715                            $info_url=$self."?A=E&F=".urlencode($dir)."&D=".urlencode($relDir);
716                          $tstr = "<A HREF=\"" . $self . "?D=" ;                          $tstr = "<A HREF=\"" . $self . "?D=" ;
717                          $tstr .= urlencode($relDir."/".$dir) ;                          $tstr .= urlencode($relDir."/".$dir) ;
718                          $tstr .= "\">" . $dir . "/</A>" ;                          $tstr .= "\">" . $dir . "/</A>" ;
719                            $note_html="<a href=\"$info_url#note\">".$gblIcon("note")."</a>".ReadNote($fsDir.$dir);
720  ?>  ?>
721    
722  <TR><TD><?= $gblIcon("fldr") ?></TD>  <TR><TD>
723  <TD COLSPAN=5 CLASS=LST><?= $tstr ?></TD></TR>  <A HREF="<?= $info_url ?>" TITLE="View/Edit">
724    <?= $gblIcon("fldr") ?></A></TD>
725    <TD COLSPAN=2 CLASS=LST><?= $tstr ?></TD>
726    <TD COLSPAN=3 CLASS=LST><?= $note_html ?></TD></TR>
727    
728  <?php  <?php
729                  }  // iterate over dirs                  }  // iterate over dirs
# Line 735  function Navigate($fsRoot,$relDir) { Line 732  function Navigate($fsRoot,$relDir) {
732    
733  <TR><TD></TD><TD COLSPAN=5><HR><B><?= $webRoot . $relDir ?>  <TR><TD></TD><TD COLSPAN=5><HR><B><?= $webRoot . $relDir ?>
734  </B></TD></TR>  </B></TD></TR>
735  <TR><TD></TD><TD CLASS=TOP>DOCUMENT NAME</TD>  <TR><TD></TD><TD CLASS=TOP>DOCUMENT NAME (<?= plural("file",sizeof($fileList)) ?>)</TD>
736  <TD><?= $gblIcon("blank").$gblIcon("blank") ?></TD>  <TD><?= $gblIcon("blank").$gblIcon("blank") ?></TD>
737  <TD CLASS=TOP>NOTE</TD>  <TD CLASS=TOP>NOTE</TD>
738  <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 867  if (file_exists(".info.inc")) { Line 864  if (file_exists(".info.inc")) {
864   <NOBR>NAME <INPUT TYPE="TEXT" NAME="FN" SIZE=14>   <NOBR>NAME <INPUT TYPE="TEXT" NAME="FN" SIZE=14>
865   <INPUT TYPE="HIDDEN" NAME="POSTACTION" VALUE="CREATE">   <INPUT TYPE="HIDDEN" NAME="POSTACTION" VALUE="CREATE">
866   <INPUT TYPE="HIDDEN" NAME="DIR" VALUE="<?= $relDir ?>">   <INPUT TYPE="HIDDEN" NAME="DIR" VALUE="<?= $relDir ?>">
867   <INPUT TYPE="SUBMIT" VALUE="CREATE"></NOBR>   <INPUT TYPE="SUBMIT" VALUE="CREATE" NAME="CREATE">
868     </NOBR>
869   <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
870   </NOBR>   </NOBR>
871  </TD></TR>  </TD></TR>
# Line 1068  function urlpath($url) { Line 1066  function urlpath($url) {
1066    
1067  //////////////////////////////////////////////////////////////////  //////////////////////////////////////////////////////////////////
1068    
1069  function safe_rename($from,$to) {  function safe_rename($fromdir,$fromfile,$tofile) {
1070          if (file_exists($from) && is_writable(dirname($to))) {          function try_rename($from,$to) {
1071                  rename($from,$to);  #               print "$from -> $to\n";
1072                    if (file_exists($from) && is_writeable(dirname($to))) {
1073                            rename($from,$to);
1074                    }
1075            }
1076    
1077            function try_dir($todir) {
1078                    if (! file_exists($todir)) {
1079                            mkdir($todir,0700);
1080                    }
1081            }
1082    
1083            $to="$fromdir/$tofile";
1084            $todir=dirname($to);
1085            $tofile=basename($to);
1086    
1087    #       print "<pre>$fromdir / $fromfile -> $todir / $tofile\n\n";
1088    
1089            try_rename("$fromdir/$fromfile","$todir/$tofile");
1090            try_dir("$todir/.log");
1091            try_rename("$fromdir/.log/$fromfile","$todir/.log/$tofile");
1092            try_dir("$todir/.note");
1093            try_rename("$fromdir/.note/$fromfile","$todir/.note/$tofile");
1094            try_dir("$todir/.lock");
1095            try_rename("$fromdir/.lock/$fromfile","$todir/.lock/$tofile");
1096            try_dir("$todir/.bak");
1097            for($i=0;$i<=$GLOBALS[gblNumBackups];$i++) {
1098                    try_rename("$fromdir/.bak/$i/$fromfile","$todir/.bak/$i/$tofile");
1099          }          }
1100  }  }
1101    
1102    
1103  //////////////////////////////////////////////////////////////////  //////////////////////////////////////////////////////////////////
1104    
1105  // recursivly delete directory  // recursivly delete directory
# Line 1149  function DisplayChangeLog($day) { Line 1175  function DisplayChangeLog($day) {
1175          // creation if password not yet set.          // creation if password not yet set.
1176          if ($STYLE == "get") { CSS() ; exit ; }          if ($STYLE == "get") { CSS() ; exit ; }
1177    
1178            $htusers_file=dirname($SCRIPT_FILENAME)."/.htusers";
1179            if (! file_exists($htusers_file)) {
1180                    if (is_writeable(dirname($SCRIPT_FILENAME))) {
1181                            $htusers=fopen($htusers_file,"a+");
1182                            fputs($htusers,"# Change owner of $htusers_file to root !!\n");
1183                            fputs($htusers,"demo:full name:[md5_hash|auth_*]:e-mail\n");
1184                            fclose($htusers);
1185                            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!");
1186                            exit;
1187                    } else {
1188                            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!");
1189                            exit;
1190                    }
1191            }
1192            $htusers=fopen($htusers_file,"r");
1193            while($user = fgetcsv($htusers,255,":")) {
1194                    if ($user[0] == $GLOBALS["PHP_AUTH_USER"]) {
1195                            $gblUserName=$user[1];
1196                            $gblPw=$user[2];
1197                            if (substr($gblPw,0,5) == "auth_" && file_exists("$gblIncDir/$gblPw.php")) {
1198                                    require("$gblIncDir/$gblPw.php");
1199                                    if ($gblPw($user)) {
1200                                            $gblPw=md5($PHP_AUTH_USER.$PHP_AUTH_PW);
1201                                    } else {
1202                                            $gblPw="error".md5($PHP_AUTH_USER.$PHP_AUTH_PW);
1203                                    }
1204                            }
1205                            $gblEmail=$user[3];
1206                            continue ;
1207                    }
1208            }
1209            fclose($htusers);
1210    
1211          // authentication failure          // authentication failure
1212          if ( md5($PHP_AUTH_USER.$PHP_AUTH_PW) != $gblPw ||          if ( md5($PHP_AUTH_USER.$PHP_AUTH_PW) != $gblPw ||
1213                  isset($relogin) && $gblPw == $relogin ) {                  isset($relogin) && $gblPw == $relogin ) {
# Line 1164  function DisplayChangeLog($day) { Line 1223  function DisplayChangeLog($day) {
1223                  $relDir = urldecode($D) ;  // then use GET                  $relDir = urldecode($D) ;  // then use GET
1224          }                }      
1225    
1226            $relDir=stripSlashes($relDir);
1227    
1228          if ($relDir == "/") $relDir = "" ;                if ($relDir == "/") $relDir = "" ;      
1229          // default : website root = ""          // default : website root = ""
1230    
# Line 1189  function DisplayChangeLog($day) { Line 1250  function DisplayChangeLog($day) {
1250          $fsDir = $gblFsRoot . $relDir ; // current directory          $fsDir = $gblFsRoot . $relDir ; // current directory
1251          if ( !is_dir($fsDir) ) Error("Dir not found",$relDir) ;          if ( !is_dir($fsDir) ) Error("Dir not found",$relDir) ;
1252    
1253            if (isset($GLOBALS["HTTPS"]) && $GLOBALS["HTTPS"] == "on") {
1254                    $webRoot  = "https://";
1255            } else {
1256                    $webRoot  = "http://";
1257            }
1258            $webRoot .= $GLOBALS["HTTP_HOST"] . $relScriptDir;
1259    
1260          $FN=stripSlashes($FN);          $FN=stripSlashes($FN);
1261    
1262            if (file_exists("$fsScriptDir/.docman.conf")) {
1263                    include("$fsScriptDir/.docman.conf");
1264            }
1265    
1266          switch ($POSTACTION) {          switch ($POSTACTION) {
1267          case "UPLOAD" :          case "UPLOAD" :
1268                  if (!is_writeable($fsDir)) Error("Write denied",$relDir) ;                  if (!is_writeable($fsDir)) Error("Write denied",$relDir) ;
# Line 1266  function DisplayChangeLog($day) { Line 1338  function DisplayChangeLog($day) {
1338  // this functionality is doubled in DetailView().  // this functionality is doubled in DetailView().
1339  // better keep it here altogether  // better keep it here altogether
1340  // chmod perms to $gblFilePerms  // chmod perms to $gblFilePerms
1341                          if ( file_exists($path) && !is_writable($path) )                          if ( file_exists($path) && !is_writeable($path) )
1342                                  Error("File not writable", $relPath) ;                                  Error("File not writable", $relPath) ;
1343                          $fh = fopen($path, "w+") ;                          $fh = fopen($path, "w+") ;
1344                          if ($fh) {                          if ($fh) {
# Line 1338  function DisplayChangeLog($day) { Line 1410  function DisplayChangeLog($day) {
1410                  if ( $CONFIRM != "on" ) break ;                  if ( $CONFIRM != "on" ) break ;
1411    
1412                  Logit("$fsDir/$FN","renamed $FN to $NEWNAME");                  Logit("$fsDir/$FN","renamed $FN to $NEWNAME");
1413                  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");  
                 }  
   
1414                  break ;                  break ;
1415    
1416          case "NOTE" :            case "NOTE" :  
# Line 1391  function DisplayChangeLog($day) { Line 1456  function DisplayChangeLog($day) {
1456          case "E" :          case "E" :
1457                  $F=stripSlashes($F);                  $F=stripSlashes($F);
1458                  // detail of $relDir/$F                  // detail of $relDir/$F
1459                  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) ;
1460                  exit ;                  exit ;
1461          case "C" :          case "C" :
1462                  $F=stripSlashes($F);                  $F=stripSlashes($F);
# Line 1402  function DisplayChangeLog($day) { Line 1467  function DisplayChangeLog($day) {
1467                  // checkout                  // checkout
1468                  Lock("$gblFsRoot/$relDir/$F");                  Lock("$gblFsRoot/$relDir/$F");
1469                  header("Content-Disposition: attachment; filename=$F" );                  header("Content-Disposition: attachment; filename=$F" );
1470                  Header("Location: ".urlpath("$relDir/$F"));                  Header("Location: $webRoot".urlpath("$relDir/$F"));
1471                  exit;                  exit;
1472          case "Ci" :          case "Ci" :
1473                  $F=stripSlashes($F);                  $F=stripSlashes($F);
# Line 1419  function DisplayChangeLog($day) { Line 1484  function DisplayChangeLog($day) {
1484                  // view                  // view
1485                  LogIt("$gblFsRoot/$relDir/$F","viewed");                  LogIt("$gblFsRoot/$relDir/$F","viewed");
1486                  header("Content-Disposition: attachment; filename=$F" );                  header("Content-Disposition: attachment; filename=$F" );
1487                  Header("Location: ".urlpath("$relDir/$F"));                  Header("Location: $webRoot".urlpath("$relDir/$F"));
1488                  exit;                  exit;
1489          case "Ch" :          case "Ch" :
1490                  StartHTML("(File changes)","All changes chronologicaly...");                  StartHTML("(File changes)","All changes chronologicaly...");

Legend:
Removed from v.1.30  
changed lines
  Added in v.1.41

  ViewVC Help
Powered by ViewVC 1.1.26