/[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.13 by dpavlin, Wed Sep 6 10:49:15 2000 UTC revision 1.25 by dpavlin, Thu Dec 21 07:30:04 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 108  TODO: Line 99  TODO:
99                          if ($user[0] == $GLOBALS["PHP_AUTH_USER"]) {                          if ($user[0] == $GLOBALS["PHP_AUTH_USER"]) {
100                                  $gblUserName=$user[1];                                  $gblUserName=$user[1];
101                                  $gblPw=$user[2];                                  $gblPw=$user[2];
102                                    $gblEmail=$user[3];
103                                  continue ;                                  continue ;
104                          }                          }
105                  }                  }
# Line 120  TODO: Line 112  TODO:
112          $gblDateFmt="Y-m-d";          $gblDateFmt="Y-m-d";
113          $gblTimeFmt="H:i:s";          $gblTimeFmt="H:i:s";
114    
115  // Number of backup files to keep          // Number of backup files to keep
116          $gblNumBackups=5;          $gblNumBackups=3;
117    
118            // show red star if newer than ... days
119            $gblModDays=1;
120    
121          // choose GifIcon below unless you have the M$          // choose GifIcon below unless you have the M$
122          // WingDings font installed on your system          // WingDings font installed on your system
# Line 295  echo($fstr) ; ?></TEXTAREA> Line 290  echo($fstr) ; ?></TEXTAREA>
290    
291  <?php  <?php
292          }          }
293          if ( !$file_lock && strstr(join(" ",$gblImages),$ext) ) {            if ( !$file_lock && $ext!="" && strstr(join(' ',$gblImages),$ext) ) {  
294                  $info  = getimagesize($fsPath) ;                  $info  = getimagesize($fsPath) ;
295                  $tstr = "<IMG SRC=\"".urlpath($relPath)."\" BORDER=0 " ;                  $tstr = "<IMG SRC=\"".urlpath($relPath)."\" BORDER=0 " ;
296                  $tstr .= $info[3] . " ALT=\"" . $fn . " - " ;                  $tstr .= $info[3] . " ALT=\"" . $fn . " - " ;
# Line 363  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";
# Line 642  function GifIcon($txt) { Line 637  function GifIcon($txt) {
637    
638  function Navigate($fsRoot,$relDir) {  function Navigate($fsRoot,$relDir) {
639    
640          global $gblEditable, $gblIcon ;          global $gblEditable, $gblIcon, $gblModDays ;
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 691  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 757  function Navigate($fsRoot,$relDir) { Line 753  function Navigate($fsRoot,$relDir) {
753    
754                  $info_url=$self."?A=E&F=".urlencode($file)."&D=".urlencode($relDir);                  $info_url=$self."?A=E&F=".urlencode($file)."&D=".urlencode($relDir);
755    
756                  if ( ($mod + 30*86400) > time() ) {                  if ( ($mod + $gblModDays*86400) > time() ) {
757                          $a  = "<SPAN CLASS=RED TITLE=\"Newer" ;                          $a  = "<SPAN CLASS=RED TITLE=\"Newer" ;
758                          $a .= " than 30 days\"> * </SPAN>" ;                          $a .= " than $gblModDays days\"> * </SPAN>" ;
759                  }                  }
760    
761                  $file_lock=CheckLock($path);                  $file_lock=CheckLock($path);
# Line 824  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 844  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 971  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 991  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 1007  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 1023  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 1036  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 1056  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 1070  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 1100  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 1123  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 1146  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 1193  function safe_rename($from,$to) { Line 1261  function safe_rename($from,$to) {
1261                  if (isset($FILENAME)) {                  if (isset($FILENAME)) {
1262                          Unlock($target);                          Unlock($target);
1263                  }                  }
1264                    ChangeLog($target,"updated");
1265                  break ;                  break ;
1266    
1267          case "SAVE" :          case "SAVE" :
1268                  $path = $gblFsRoot . escapeshellcmd($RELPATH) ;                  $path = $gblFsRoot . $RELPATH ;
1269                    $path=stripSlashes($path);
1270                  $writable = is_writeable($path) ;                  $writable = is_writeable($path) ;
1271                  $legaldir = is_writeable(dirname($path)) ;                  $legaldir = is_writeable(dirname($path)) ;
1272                  $exists   = (file_exists($path)) ? 1 : 0 ;                  $exists   = (file_exists($path)) ? 1 : 0 ;
# Line 1204  function safe_rename($from,$to) { Line 1274  function safe_rename($from,$to) {
1274                  if (!($writable || (!$exists && $legaldir)))                  if (!($writable || (!$exists && $legaldir)))
1275                          Error("Write denied",$RELPATH) ;                          Error("Write denied",$RELPATH) ;
1276                  $fh = fopen($path, "w") ;                  $fh = fopen($path, "w") ;
1277                    $FILEDATA=stripSlashes($FILEDATA);
1278                  fwrite($fh,$FILEDATA) ;                  fwrite($fh,$FILEDATA) ;
1279                  fclose($fh) ;                  fclose($fh) ;
1280                  clearstatcache() ;                  clearstatcache() ;
1281                  Logit($path,"saved changes");                  Logit($path,"saved changes");
1282                    ChangeLog($path,"saved changes");
1283                  break ;                  break ;
1284    
1285          case "CREATE" :          case "CREATE" :
# Line 1238  function safe_rename($from,$to) { Line 1310  function safe_rename($from,$to) {
1310                          }                          }
1311                          $tstr = "$PHP_SELF?A=E&D=".urlencode($relDir)."&F=".urlencode($FN) ;                          $tstr = "$PHP_SELF?A=E&D=".urlencode($relDir)."&F=".urlencode($FN) ;
1312                          header("Location: " . $tstr) ;                          header("Location: " . $tstr) ;
1313                            ChangeLog($target,"created");
1314                          exit ;                          exit ;
1315                  }                  }
1316                  break ;                  break ;
# Line 1270  function safe_rename($from,$to) { Line 1343  function safe_rename($from,$to) {
1343                          }                          }
1344                  }                  }
1345                  else {  // delete directory                  else {  // delete directory
1346                    if ( ! @rmdir($fsDir) ) {                    if ( ! @rrmdir($fsDir) ) {
1347                      Error("Rmdir failed", $tstr . $fsDir) ;                      Error("Rmdir failed", $tstr . $fsDir) ;
1348                    }                    }
1349                    else {                    else {
# Line 1335  function safe_rename($from,$to) { Line 1408  function safe_rename($from,$to) {
1408          // $A=Ci : checkin file $D/$F          // $A=Ci : checkin file $D/$F
1409          // $A=V : view file (do nothing except log)          // $A=V : view file (do nothing except log)
1410          // default : display directory $D          // default : display directory $D
1411            
1412          switch ($A) {          switch ($A) {
1413          case "U" :          case "U" :
1414                  // upload to $relDir                  // upload to $relDir
1415                  if (!is_writeable($gblFsRoot . $relDir))                  if (!is_writeable($gblFsRoot . $relDir))
1416                          Error("Write access denied",$relDir) ;                          Error("Write access denied",$relDir) ;
1417                  $text  = "Use this page to upload a single " ;                  $text  = "Use this page to upload a single " ;
1418                  $text .= "file to <B>$SERVER_NAME</B>." ;                  $text .= "file to <B>$HTTP_HOST</B>." ;
1419                  StartHTML("(Upload Page)", $text) ;                  StartHTML("(Upload Page)", $text) ;
1420                  UploadPage($gblFsRoot, $relDir) ;                  UploadPage($gblFsRoot, $relDir) ;
1421                  EndHTML() ;                  EndHTML() ;
1422                  exit ;                  exit ;
1423          case "E" :          case "E" :
1424                    $F=stripSlashes($F);
1425                  // detail of $relDir/$F                  // detail of $relDir/$F
1426                  if (is_file("$gblFsRoot/$relDir/$F")) DetailPage($gblFsRoot, $relDir, $F) ;                  if (is_file("$gblFsRoot/$relDir/$F")) DetailPage($gblFsRoot, $relDir, $F) ;
1427                  exit ;                  exit ;
1428          case "C" :          case "C" :
1429                    $F=stripSlashes($F);
1430                  // listing of $relDir/$F                  // listing of $relDir/$F
1431                  DisplayCode($gblFsRoot, $relDir, $F) ;                  DisplayCode($gblFsRoot, $relDir, $F) ;
1432                  exit ;                  exit ;
# Line 1362  function safe_rename($from,$to) { Line 1437  function safe_rename($from,$to) {
1437                  Header("Location: ".urlpath("$relDir/$F"));                  Header("Location: ".urlpath("$relDir/$F"));
1438                  exit;                  exit;
1439          case "Ci" :          case "Ci" :
1440                    $F=stripSlashes($F);
1441                  // upload && update to $relDir                  // upload && update to $relDir
1442                  if (!is_writeable($gblFsRoot . $relDir))                  if (!is_writeable($gblFsRoot . $relDir))
1443                          Error("Write access denied",$relDir) ;                          Error("Write access denied",$relDir) ;
1444                  $text  = "Use this page to update a single " ;                  $text  = "Use this page to update a single " ;
1445                  $text .= "file to <B>$SERVER_NAME</B>." ;                  $text .= "file to <B>$HTTP_HOST</B>." ;
1446                  StartHTML("(Update file Page)", $text) ;                  StartHTML("(Update file Page)", $text) ;
1447                  UploadPage($gblFsRoot, $relDir, $F) ;                  UploadPage($gblFsRoot, $relDir, $F) ;
1448                  EndHTML() ;                  EndHTML() ;
# Line 1377  function safe_rename($from,$to) { Line 1453  function safe_rename($from,$to) {
1453                  header("Content-Disposition: attachment; filename=$F" );                  header("Content-Disposition: attachment; filename=$F" );
1454                  Header("Location: ".urlpath("$relDir/$F"));                  Header("Location: ".urlpath("$relDir/$F"));
1455                  exit;                  exit;
1456            case "Ch" :
1457                    StartHTML("(File changes)","All changes chronologicaly...");
1458                    DisplayChangeLog(0);    // all
1459                    EndHTML() ;
1460                    exit;
1461            case "Ch1" :
1462                    StartHTML("(File changes)","Changes to files in last day...");
1463                    DisplayChangeLog(1);
1464                    EndHTML() ;
1465                    exit;
1466          }          }
1467    
1468          // default: display directory $relDir          // default: display directory $relDir

Legend:
Removed from v.1.13  
changed lines
  Added in v.1.25

  ViewVC Help
Powered by ViewVC 1.1.26