/[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.15 by dpavlin, Wed Sep 6 11:04:32 2000 UTC revision 1.27 by dpavlin, Thu Dec 21 08:46:18 2000 UTC
# Line 35  Line 35 
35  /*             existent address after file modifications.       */  /*             existent address after file modifications.       */
36    
37  /*  /*
         2000-07-25 Dobrica Pavlinusic <dpavlin@rot13.org>  
38    
39          nuked exec calls (unsecure)          This project is now called Directory Manager.
         nuked writeable function (replaced by php is_writeable)  
         added support for https (tested with apache+mod_ssl)  
         added users file  
         date format user-selectable  
         cycle backup files in bak directory  
         support links as directoryes (for now)  
         support of file history logging  
         undelete capabilities (delete moves to .del directory)  
40    
41          2000-07-26 DbP          For more info, please see web pages at
42            http://www.rot13.org/~dpavlin/docman.html
43    
44          added more checking on entered filename (when creating file/dir)          It's relased under GPL by
45          added rename option          Dobrica Pavlinusic <dpavlin@rot13.org>
46    
47    
48  IMPORTANT INSTALLATION NOTE:  IMPORTANT INSTALLATION NOTE:
# Line 65  IMPORTANT INSTALLATION NOTE: Line 57  IMPORTANT INSTALLATION NOTE:
57  TODO:  TODO:
58          mixed file/directory output (add type to each entry,          mixed file/directory output (add type to each entry,
59                  real support for links)                  real support for links)
60          retrieve old versions of files (overwritten)          access controll
61          show last lock date  
           
62  */  */
63    
64  //////////////////////////////////////////////////////////////////  //////////////////////////////////////////////////////////////////
# Line 80  TODO: Line 71  TODO:
71    
72  // GLOBAL PARAMETERS  // GLOBAL PARAMETERS
73  // =================  // =================
74  // Make modifications here to suit siteman to your needs  // Make modifications here to suit docman to your needs
75    
76  //      error_reporting(4) ;            // how verbose ?  //      error_reporting(4) ;            // how verbose ?
77    
# Line 367  echo($fstr) ; ?></TEXTAREA> Line 358  echo($fstr) ; ?></TEXTAREA>
358  </FORM>  </FORM>
359    
360  <?php  <?php
361            
362          $name=basename("$fsDir/$fn");          $name=basename("$fsDir/$fn");
363          $logname=dirname("$fsDir/$fn")."/.log/$name";          $logname=dirname("$fsDir/$fn")."/.log/$name";
364          $bakdir=dirname("$fsDir/$fn")."/.bak";          $bakdir=dirname("$fsDir/$fn")."/.bak";
365          if (file_exists($logname)) {          if (file_exists($logname)) {
366                  $log=fopen($logname,"r");                  $log=fopen($logname,"r");
367                  $cl1=" class=lst"; $cl2="";                  $cl1=" class=LST"; $cl2="";
368                  $logarr = array();                  $logarr = array();
369                  while($line = fgetcsv($log,255,"\t")) {                  while($line = fgetcsv($log,255,"\t")) {
370                          $cl=$cl1; $cl1=$cl2; $cl2=$cl;                          $cl=$cl1; $cl1=$cl2; $cl2=$cl;
# Line 650  function Navigate($fsRoot,$relDir) { Line 641  function Navigate($fsRoot,$relDir) {
641    
642          $self     = $GLOBALS["PHP_SELF"] ;          $self     = $GLOBALS["PHP_SELF"] ;
643          if (isset($GLOBALS["HTTPS"]) && $GLOBALS["HTTPS"] == "on") {          if (isset($GLOBALS["HTTPS"]) && $GLOBALS["HTTPS"] == "on") {
644                  $webRoot  = "https://" . $GLOBALS["SERVER_NAME"] ;                  $webRoot  = "https://" . $GLOBALS["HTTP_HOST"] ;
645          } else {          } else {
646                  $webRoot  = "http://" . $GLOBALS["SERVER_NAME"] ;                  $webRoot  = "http://" . $GLOBALS["HTTP_HOST"] ;
647          }          }
648          $fsDir    = $fsRoot . $relDir . "/" ; // current directory          $fsDir    = $fsRoot . $relDir . "/" ; // current directory
649    
# Line 695  function Navigate($fsRoot,$relDir) { Line 686  function Navigate($fsRoot,$relDir) {
686                  $text .= ", <a href=$self?D=".urlencode($relDir)."&show_deleted=1>undelete</a>";                  $text .= ", <a href=$self?D=".urlencode($relDir)."&show_deleted=1>undelete</a>";
687          }          }
688          $text .= " or revise files on this web site." ;          $text .= " or revise files on this web site." ;
689            $text .= "<br>Examine list of files <a href=\"$self?A=Ch1\">changed in last day</a> or <a href=\"$self?A=Ch\">all changes</a>.";
690          StartHTML("(Navigate)",$text) ;          StartHTML("(Navigate)",$text) ;
691    
692          echo "<TABLE BORDER=0 CELLPADDING=2          echo "<TABLE BORDER=0 CELLPADDING=2
# Line 828  function Navigate($fsRoot,$relDir) { Line 820  function Navigate($fsRoot,$relDir) {
820    
821  <?php  <?php
822            }  // iterate over files            }  // iterate over files
823          }  // end if no files          } else {  // end if no files
824    ?>
825     <TR><TD></TD><TD COLSPAN=5 CLASS=LST>
826      No files in this directory
827     </TD></TR>
828    <?
829            }
830    
831          if ($emptyDir) {          if ($emptyDir) {
832  ?>  ?>
# Line 848  function Navigate($fsRoot,$relDir) { Line 846  function Navigate($fsRoot,$relDir) {
846    
847  <TR><TD></TD><TD COLSPAN=5><HR></TD></TR>  <TR><TD></TD><TD COLSPAN=5><HR></TD></TR>
848    
 <TR><TD></TD><TD COLSPAN=5>  
849  <?  <?
850  if (file_exists(".info.inc")) {  if (file_exists(".info.inc")) {
851            print "<TR><TD></TD><TD COLSPAN=5>";
852          include(".info.inc");          include(".info.inc");
853            print "</TD></TR>
854            <TR><TD></TD><TD COLSPAN=5><HR></TD></TR>";
855  }  }
856  ?>  ?>
 </TD></TR>  
   
 <TR><TD></TD><TD COLSPAN=5><HR></TD></TR>  
857    
858  <FORM METHOD="POST" ACTION="<?= $self ?>">  <FORM METHOD="POST" ACTION="<?= $self ?>">
859  <TR><TD></TD><TD COLSPAN=5 CLASS=BAR>CREATE NEW  <TR><TD></TD><TD COLSPAN=5 CLASS=BAR>CREATE NEW
# Line 878  if (file_exists(".info.inc")) { Line 875  if (file_exists(".info.inc")) {
875    
876  //////////////////////////////////////////////////////////////////  //////////////////////////////////////////////////////////////////
877    
878  function UploadPage($fsRoot, $relDir, $filename) {  function UploadPage($fsRoot, $relDir, $filename="") {
879    
880          $self = $GLOBALS["PHP_SELF"] ;          $self = $GLOBALS["PHP_SELF"] ;
881          if ($relDir == "") $relDir = "/" ;          if ($relDir == "") $relDir = "/" ;
# Line 888  function UploadPage($fsRoot, $relDir, $f Line 885  function UploadPage($fsRoot, $relDir, $f
885  <FORM ENCTYPE="multipart/form-data" METHOD="POST"  <FORM ENCTYPE="multipart/form-data" METHOD="POST"
886   ACTION="<?= $self ?>">   ACTION="<?= $self ?>">
887  DESTINATION DIRECTORY:<B><?= " " . $relDir ?></B>  DESTINATION DIRECTORY:<B><?= " " . $relDir ?></B>
888  <? if (isset($filename)) { ?>  <? if (isset($filename) && $filename!="") { ?>
889  <br>DESTINATION FILE:<B><?= " " . $filename ?></B>  <br>DESTINATION FILE:<B><?= " " . $filename ?></B>
890  <INPUT TYPE="HIDDEN" NAME="FILENAME" VALUE="<?= $filename ?>">  <INPUT TYPE="HIDDEN" NAME="FILENAME" VALUE="<?= $filename ?>">
891  <? } ?>  <? } ?>
# Line 975  the source<BR>of this file.<BR><BR> Line 972  the source<BR>of this file.<BR><BR>
972    
973  //////////////////////////////////////////////////////////////////  //////////////////////////////////////////////////////////////////
974    
975  function Logit($target,$msg) {  function LogIt($target,$msg) {
976    
977          $dir=dirname($target);          $dir=dirname($target);
978          if (! file_exists($dir."/.log")) {          if (! file_exists($dir."/.log")) {
# Line 995  function Logit($target,$msg) { Line 992  function Logit($target,$msg) {
992    
993  function WriteNote($target,$msg) {  function WriteNote($target,$msg) {
994    
995            $target=stripSlashes($target);
996          $dir=dirname($target);          $dir=dirname($target);
997          if (! file_exists($dir."/.note")) {          if (! file_exists($dir."/.note")) {
998                  mkdir($dir."/.note",0700);                  mkdir($dir."/.note",0700);
# Line 1011  function WriteNote($target,$msg) { Line 1009  function WriteNote($target,$msg) {
1009    
1010  function ReadNote($target) {  function ReadNote($target) {
1011    
1012            $target=stripSlashes($target);
1013          $dir=dirname($target);          $dir=dirname($target);
1014          $file=basename($target);          $file=basename($target);
1015          $msg="";          $msg="";
# Line 1027  function ReadNote($target) { Line 1026  function ReadNote($target) {
1026    
1027  function MoveTo($source,$folder) {  function MoveTo($source,$folder) {
1028    
1029            $source=stripSlashes($source);
1030          $file=basename($source);          $file=basename($source);
1031          if (! file_exists($folder)) {          if (! file_exists($folder)) {
1032                  mkdir($folder,0700);                  mkdir($folder,0700);
# Line 1040  function MoveTo($source,$folder) { Line 1040  function MoveTo($source,$folder) {
1040    
1041  function Lock($target) {  function Lock($target) {
1042    
1043            $target=stripSlashes($target);
1044          $dir=dirname($target);          $dir=dirname($target);
1045          if (! file_exists($dir."/.lock")) {          if (! file_exists($dir."/.lock")) {
1046                  mkdir($dir."/.lock",0700);                  mkdir($dir."/.lock",0700);
# Line 1060  function Lock($target) { Line 1061  function Lock($target) {
1061    
1062  function CheckLock($target) {  function CheckLock($target) {
1063    
1064            $target=stripSlashes($target);
1065          $dir=dirname($target);          $dir=dirname($target);
1066          $file=basename($target);          $file=basename($target);
1067          $msg=0;          $msg=0;
# Line 1074  function CheckLock($target) { Line 1076  function CheckLock($target) {
1076    
1077  function Unlock($target) {  function Unlock($target) {
1078    
1079            $target=stripSlashes($target);
1080          $dir=dirname($target);          $dir=dirname($target);
1081          $file=basename($target);          $file=basename($target);
1082          if (file_exists($dir."/.lock/$file")) {          if (file_exists($dir."/.lock/$file")) {
# Line 1104  function safe_rename($from,$to) { Line 1107  function safe_rename($from,$to) {
1107    
1108  //////////////////////////////////////////////////////////////////  //////////////////////////////////////////////////////////////////
1109    
1110    // recursivly delete directory
1111    
1112    function rrmdir($dir) {
1113            $handle=opendir($dir);
1114            while ($file = readdir($handle)) {
1115                    if ($file != "." && $file != "..") {
1116                            if (is_dir("$dir/$file"))
1117                                    rrmdir("$dir/$file");
1118                            else
1119                                    if (! @unlink("$dir/$file")) return(0);
1120                    }
1121            }
1122            closedir($handle);
1123            return @rmdir($dir);
1124    }
1125    
1126    //////////////////////////////////////////////////////////////////
1127    
1128    function ChangeLog($target,$msg) {
1129    
1130            global $gblFsRoot;
1131            $log=fopen("$gblFsRoot/.changelog","a+");
1132            if (substr($target,0,strlen($gblFsRoot)) == $gblFsRoot)
1133                    $target=substr($target,strlen($gblFsRoot),strlen($target)-strlen($gblFsRoot));
1134            fputs($log,time()."\t$target\t$GLOBALS[gblUserName]\t$msg\n");
1135            fclose($log);
1136    
1137    }
1138    
1139    function DisplayChangeLog($day) {
1140    
1141            global $gblFsRoot;
1142            if (!file_exists("$gblFsRoot/.changelog")) return;
1143            $log=fopen("$gblFsRoot/.changelog","r");
1144            $logarr = array();
1145            while($line = fgetcsv($log,255,"\t")) {
1146                    if ($day!=1 || ($day==1 && (time()-$line[0] < 24*60*60))) {
1147                            array_unshift($logarr,array($line[0],$line[1],$line[2],$line[3]));
1148                    }
1149            }
1150            fclose($log);
1151            $cl1=" class=LST"; $cl2="";
1152            print "<table border=0 width=100%>\n";
1153            while ($e = array_shift($logarr)) {
1154                    $cl=$cl1; $cl1=$cl2; $cl2=$cl;
1155                    $date = date("$GLOBALS[gblDateFmt]", $e[0]);
1156                    $time = date("$GLOBALS[gblTimeFmt]", $e[0]);
1157                    $dir = dirname($e[1]);
1158                    $file = basename($e[1]);
1159                    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";
1160            }
1161            print "</table>";
1162            print "<p>".GifIcon(up)." Back to <a href=$GLOBALS[PHP_SELF]>front page</a>.</p>";
1163    }
1164    
1165    //////////////////////////////////////////////////////////////////
1166    
1167  // MAIN PROGRAM  // MAIN PROGRAM
1168  // ============  // ============
1169  // query parameters: capital letters  // query parameters: capital letters
# Line 1127  function safe_rename($from,$to) { Line 1187  function safe_rename($from,$to) {
1187          // authentication if $gblAuth == true          // authentication if $gblAuth == true
1188          if ( $gblAuth && $gblHash($PHP_AUTH_USER.$PHP_AUTH_PW) != $gblPw ||          if ( $gblAuth && $gblHash($PHP_AUTH_USER.$PHP_AUTH_PW) != $gblPw ||
1189                  isset($relogin) && $gblPw == $relogin ) {                  isset($relogin) && $gblPw == $relogin ) {
1190                  header("WWW-authenticate: basic realm=\"$SERVER_NAME\"") ;                  header("WWW-authenticate: basic realm=\"$HTTP_HOST\"") ;
1191                  header("HTTP/1.0 401 Unauthorized") ;                  header("HTTP/1.0 401 Unauthorized") ;
1192                  NoEntry() ;                  NoEntry() ;
1193                  exit ;                  exit ;
# Line 1150  function safe_rename($from,$to) { Line 1210  function safe_rename($from,$to) {
1210          // i.e. below $gblFsRoot.          // i.e. below $gblFsRoot.
1211    
1212          $relScriptDir = dirname($SCRIPT_NAME) ;                  $relScriptDir = dirname($SCRIPT_NAME) ;        
1213          // i.e. /siteman          // i.e. /docman
1214    
1215          $fsScriptDir  = dirname($SCRIPT_FILENAME) ;              $fsScriptDir  = dirname($SCRIPT_FILENAME) ;    
1216          // i.e. /home/httpd/html/siteman          // i.e. /home/httpd/html/docman
1217    
1218          $gblFsRoot = substr($fsScriptDir,0,          // start on server root
1219            strlen($fsScriptDir)-strlen($relScriptDir)) ;  //      $gblFsRoot = substr($fsScriptDir,0, strlen($fsScriptDir)-strlen($relScriptDir)) ;
1220            // or on script root
1221            $gblFsRoot = $fsScriptDir;
1222          // i.e. /home/httpd/html          // i.e. /home/httpd/html
1223    
1224          $fsDir = $gblFsRoot . $relDir ; // current directory          $fsDir = $gblFsRoot . $relDir ; // current directory
1225          if ( !is_dir($fsDir) ) Error("Dir not found",$relDir) ;          if ( !is_dir($fsDir) ) Error("Dir not found",$relDir) ;
1226            
1227            $FN=stripSlashes($FN);
1228    
1229          switch ($POSTACTION) {          switch ($POSTACTION) {
1230          case "UPLOAD" :          case "UPLOAD" :
1231                  if (!is_writeable($fsDir)) Error("Write denied",$relDir) ;                  if (!is_writeable($fsDir)) Error("Write denied",$relDir) ;
# Line 1170  function safe_rename($from,$to) { Line 1234  function safe_rename($from,$to) {
1234                  // TODO : should rather check for escapeshellcmds                  // TODO : should rather check for escapeshellcmds
1235                  // but maybe RFC 18xx asserts safe filenames ....                  // but maybe RFC 18xx asserts safe filenames ....
1236                  $source = $FN ;                  $source = $FN ;
1237                    if (! file_exists($source)) {
1238                            Error("You must select file with browse to upload it!");
1239                    }
1240                  if (! isset($FILENAME)) {       // from update file                  if (! isset($FILENAME)) {       // from update file
1241                          $target = "$fsDir/$FN_name" ;                          $target = "$fsDir/$FN_name" ;
1242                  } else {                  } else {
# Line 1197  function safe_rename($from,$to) { Line 1264  function safe_rename($from,$to) {
1264                  if (isset($FILENAME)) {                  if (isset($FILENAME)) {
1265                          Unlock($target);                          Unlock($target);
1266                  }                  }
1267                    ChangeLog($target,"updated");
1268                  break ;                  break ;
1269    
1270          case "SAVE" :          case "SAVE" :
1271                  $path = $gblFsRoot . escapeshellcmd($RELPATH) ;                  $path = $gblFsRoot . $RELPATH ;
1272                    $path=stripSlashes($path);
1273                  $writable = is_writeable($path) ;                  $writable = is_writeable($path) ;
1274                  $legaldir = is_writeable(dirname($path)) ;                  $legaldir = is_writeable(dirname($path)) ;
1275                  $exists   = (file_exists($path)) ? 1 : 0 ;                  $exists   = (file_exists($path)) ? 1 : 0 ;
# Line 1208  function safe_rename($from,$to) { Line 1277  function safe_rename($from,$to) {
1277                  if (!($writable || (!$exists && $legaldir)))                  if (!($writable || (!$exists && $legaldir)))
1278                          Error("Write denied",$RELPATH) ;                          Error("Write denied",$RELPATH) ;
1279                  $fh = fopen($path, "w") ;                  $fh = fopen($path, "w") ;
1280                    $FILEDATA=stripSlashes($FILEDATA);
1281                  fwrite($fh,$FILEDATA) ;                  fwrite($fh,$FILEDATA) ;
1282                  fclose($fh) ;                  fclose($fh) ;
1283                  clearstatcache() ;                  clearstatcache() ;
1284                  Logit($path,"saved changes");                  Logit($path,"saved changes");
1285                    ChangeLog($path,"saved changes");
1286                  break ;                  break ;
1287    
1288          case "CREATE" :          case "CREATE" :
# Line 1242  function safe_rename($from,$to) { Line 1313  function safe_rename($from,$to) {
1313                          }                          }
1314                          $tstr = "$PHP_SELF?A=E&D=".urlencode($relDir)."&F=".urlencode($FN) ;                          $tstr = "$PHP_SELF?A=E&D=".urlencode($relDir)."&F=".urlencode($FN) ;
1315                          header("Location: " . $tstr) ;                          header("Location: " . $tstr) ;
1316                            ChangeLog($target,"created");
1317                          exit ;                          exit ;
1318                  }                  }
1319                  break ;                  break ;
# Line 1274  function safe_rename($from,$to) { Line 1346  function safe_rename($from,$to) {
1346                          }                          }
1347                  }                  }
1348                  else {  // delete directory                  else {  // delete directory
1349                    if ( ! @rmdir($fsDir) ) {                    if ( ! @rrmdir($fsDir) ) {
1350                      Error("Rmdir failed", $tstr . $fsDir) ;                      Error("Rmdir failed", $tstr . $fsDir) ;
1351                    }                    }
1352                    else {                    else {
# Line 1339  function safe_rename($from,$to) { Line 1411  function safe_rename($from,$to) {
1411          // $A=Ci : checkin file $D/$F          // $A=Ci : checkin file $D/$F
1412          // $A=V : view file (do nothing except log)          // $A=V : view file (do nothing except log)
1413          // default : display directory $D          // default : display directory $D
1414            
1415          switch ($A) {          switch ($A) {
1416          case "U" :          case "U" :
1417                  // upload to $relDir                  // upload to $relDir
1418                  if (!is_writeable($gblFsRoot . $relDir))                  if (!is_writeable($gblFsRoot . $relDir))
1419                          Error("Write access denied",$relDir) ;                          Error("Write access denied",$relDir) ;
1420                  $text  = "Use this page to upload a single " ;                  $text  = "Use this page to upload a single " ;
1421                  $text .= "file to <B>$SERVER_NAME</B>." ;                  $text .= "file to <B>$HTTP_HOST</B>." ;
1422                  StartHTML("(Upload Page)", $text) ;                  StartHTML("(Upload Page)", $text) ;
1423                  UploadPage($gblFsRoot, $relDir) ;                  UploadPage($gblFsRoot, $relDir) ;
1424                  EndHTML() ;                  EndHTML() ;
1425                  exit ;                  exit ;
1426          case "E" :          case "E" :
1427                    $F=stripSlashes($F);
1428                  // detail of $relDir/$F                  // detail of $relDir/$F
1429                  if (is_file("$gblFsRoot/$relDir/$F")) DetailPage($gblFsRoot, $relDir, $F) ;                  if (is_file("$gblFsRoot/$relDir/$F")) DetailPage($gblFsRoot, $relDir, $F) ;
1430                  exit ;                  exit ;
1431          case "C" :          case "C" :
1432                    $F=stripSlashes($F);
1433                  // listing of $relDir/$F                  // listing of $relDir/$F
1434                  DisplayCode($gblFsRoot, $relDir, $F) ;                  DisplayCode($gblFsRoot, $relDir, $F) ;
1435                  exit ;                  exit ;
# Line 1366  function safe_rename($from,$to) { Line 1440  function safe_rename($from,$to) {
1440                  Header("Location: ".urlpath("$relDir/$F"));                  Header("Location: ".urlpath("$relDir/$F"));
1441                  exit;                  exit;
1442          case "Ci" :          case "Ci" :
1443                    $F=stripSlashes($F);
1444                  // upload && update to $relDir                  // upload && update to $relDir
1445                  if (!is_writeable($gblFsRoot . $relDir))                  if (!is_writeable($gblFsRoot . $relDir))
1446                          Error("Write access denied",$relDir) ;                          Error("Write access denied",$relDir) ;
1447                  $text  = "Use this page to update a single " ;                  $text  = "Use this page to update a single " ;
1448                  $text .= "file to <B>$SERVER_NAME</B>." ;                  $text .= "file to <B>$HTTP_HOST</B>." ;
1449                  StartHTML("(Update file Page)", $text) ;                  StartHTML("(Update file Page)", $text) ;
1450                  UploadPage($gblFsRoot, $relDir, $F) ;                  UploadPage($gblFsRoot, $relDir, $F) ;
1451                  EndHTML() ;                  EndHTML() ;
# Line 1381  function safe_rename($from,$to) { Line 1456  function safe_rename($from,$to) {
1456                  header("Content-Disposition: attachment; filename=$F" );                  header("Content-Disposition: attachment; filename=$F" );
1457                  Header("Location: ".urlpath("$relDir/$F"));                  Header("Location: ".urlpath("$relDir/$F"));
1458                  exit;                  exit;
1459            case "Ch" :
1460                    StartHTML("(File changes)","All changes chronologicaly...");
1461                    DisplayChangeLog(0);    // all
1462                    EndHTML() ;
1463                    exit;
1464            case "Ch1" :
1465                    StartHTML("(File changes)","Changes to files in last day...");
1466                    DisplayChangeLog(1);
1467                    EndHTML() ;
1468                    exit;
1469          }          }
1470    
1471          // default: display directory $relDir          // default: display directory $relDir

Legend:
Removed from v.1.15  
changed lines
  Added in v.1.27

  ViewVC Help
Powered by ViewVC 1.1.26