/[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.4 by dpavlin, Thu Aug 3 20:54:27 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          add more content-management (like cms.sourceforge.net):          access controll
61                  check-out/check-in/reserve  
                 comments to files  
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 184  function EndHTML() { Line 179  function EndHTML() {
179  <B><?= date($GLOBALS[gblDateFmt]) ?> -  <B><?= date($GLOBALS[gblDateFmt]) ?> -
180  <?= date($GLOBALS[gblTimeFmt]) ?> -  <?= date($GLOBALS[gblTimeFmt]) ?> -
181  <?= $GLOBALS[gblUserName] ?>  <?= $GLOBALS[gblUserName] ?>
182  <small> [<a href="<?= $PHP_SELF ?>?relogin=<?= $GLOBALS[gblPw] ?>">logout</a>]</small>  <small> [<a href="<?= $GLOBALS["PHP_SELF"] ?>?relogin=<?= $GLOBALS[gblPw] ?>">logout</a>]</small>
183  </B>  </B>
184  <BR>ANYPORTAL(php) Site Manager  <BR>ANYPORTAL(php) Site Manager
185  <br><small>  <br><small>
# Line 194  function EndHTML() { Line 189  function EndHTML() {
189  </small>  </small>
190  </P>  </P>
191  <BR>  <BR>
192  <? include(".debug.inc") ?>  <? //include(".debug.inc") ?>
193  <BR><BR></BODY></HTML>  <BR><BR></BODY></HTML>
194    
195  <?php  <?php
# Line 240  function DetailPage($fsRoot,$relDir,$fn) Line 235  function DetailPage($fsRoot,$relDir,$fn)
235          $ext      = strtolower(strrchr($relPath,".")) ;          $ext      = strtolower(strrchr($relPath,".")) ;
236          $editable = ( $ext=="" || strstr(join(" ",$gblEditable),$ext)) ;          $editable = ( $ext=="" || strstr(join(" ",$gblEditable),$ext)) ;
237          $writable = is_writeable($fsPath) ;          $writable = is_writeable($fsPath) ;
238            $file_lock = CheckLock($fsPath);
239    
240          if (!$editable && !$exists)          if (!$editable && !$exists)
241                  Error("Creation unsupported for type",$relPath) ;                  Error("Creation unsupported for type",$relPath) ;
# Line 268  function DetailPage($fsRoot,$relDir,$fn) Line 264  function DetailPage($fsRoot,$relDir,$fn)
264    
265          }          }
266    
267          if ( $editable && ($writable || !$exists) ) {          if ( $editable && ($writable || !$exists) && !$file_lock ) {
268                  $fh = fopen($fsPath,"a+") ;                  $fh = fopen($fsPath,"a+") ;
269                  rewind($fh) ;                  rewind($fh) ;
270                  $fstr = fread($fh,filesize($fsPath)) ;                  $fstr = fread($fh,filesize($fsPath)) ;
# Line 294  echo($fstr) ; ?></TEXTAREA> Line 290  echo($fstr) ; ?></TEXTAREA>
290    
291  <?php  <?php
292          }          }
293          else if ( strstr( join(" ",$gblImages), $ext ) ) {            if ( !$file_lock && $ext!="" && strstr(join(' ',$gblImages),$ext) ) {  
294            $info  = getimagesize($fsPath) ;                  $info  = getimagesize($fsPath) ;
295            $tstr  = "<IMG SRC=\"". $relPath . "\" BORDER=0 " ;                  $tstr = "<IMG SRC=\"".urlpath($relPath)."\" BORDER=0 " ;
296            $tstr .= $info[3] . " ALT=\"" . $fn . " - " ;                  $tstr .= $info[3] . " ALT=\"" . $fn . " - " ;
297            $tstr .= (int)(($fsize+1023)/1024) . "Kb\">" ;                  $tstr .= (int)(($fsize+1023)/1024) . "Kb\">" ;
298            echo htmlentities($tstr) . "<BR><BR>" . $tstr ;  //              echo htmlentities($tstr) . "<BR><BR>" . $tstr ;
299                    echo $tstr ;
300          }          }
301    
302  ?>  ?>
303    
304  <FORM ACTION="<?= $self ; ?>" METHOD="POST">  <FORM ACTION="<?= $self ; ?>" METHOD="POST">
# Line 309  echo($fstr) ; ?></TEXTAREA> Line 307  echo($fstr) ; ?></TEXTAREA>
307  <INPUT TYPE="SUBMIT" NAME="POSTACTION" VALUE="CANCEL"><BR>  <INPUT TYPE="SUBMIT" NAME="POSTACTION" VALUE="CANCEL"><BR>
308    
309  <?php  <?php
310    
311            if ($file_lock) {
312    ?>
313    <hr>
314    <SPAN TITLE="Check OK and click UNLOCK to remove lock on file.">
315    <B>OK TO FORCE LOCK REMOVAL ON "<?= $fn ; ?>" HELD BY <?= $file_lock ?>? </B></SPAN>
316    <INPUT TYPE="CHECKBOX" NAME="CONFIRM">
317    <INPUT TYPE="SUBMIT" NAME="POSTACTION" VALUE="UNLOCK">
318    <?
319            } // file_lock
320    
321          if (substr($fn,0,4) == ".del") {          if (substr($fn,0,4) == ".del") {
322                  $action="UNDELETE";                  $action="UNDELETE";
323                  $desc="undelete previously deleted file";                  $desc="undelete previously deleted file";
# Line 336  echo($fstr) ; ?></TEXTAREA> Line 345  echo($fstr) ; ?></TEXTAREA>
345  <INPUT TYPE="CHECKBOX" NAME="CONFIRM">  <INPUT TYPE="CHECKBOX" NAME="CONFIRM">
346  <INPUT TYPE="SUBMIT" NAME="POSTACTION" VALUE="RENAME">  <INPUT TYPE="SUBMIT" NAME="POSTACTION" VALUE="RENAME">
347    
348    <?php
349            }       // exists && writable
350    ?>
351  <HR>  <HR>
352  <a name="note">  <a name="note">
353  <B>NOTE FOR "<?= $fn ; ?>":  <B>NOTE FOR "<?= $fn ; ?>":
# Line 343  echo($fstr) ; ?></TEXTAREA> Line 355  echo($fstr) ; ?></TEXTAREA>
355  </B></SPAN>  </B></SPAN>
356  <INPUT TYPE="SUBMIT" NAME="POSTACTION" VALUE="NOTE">  <INPUT TYPE="SUBMIT" NAME="POSTACTION" VALUE="NOTE">
357    
358    </FORM>
359    
360  <?php  <?php
         }  
         echo "</FORM>" ;  
361    
362          $logname=dirname("$fsDir/$fn")."/.log/".basename("$fsDir/$fn");          $name=basename("$fsDir/$fn");
363            $logname=dirname("$fsDir/$fn")."/.log/$name";
364            $bakdir=dirname("$fsDir/$fn")."/.bak";
365          if (file_exists($logname)) {          if (file_exists($logname)) {
                 print "<hr><br><b>CHANGES TO THIS FILE</b><br><table border=0 width=100%>\n";  
366                  $log=fopen($logname,"r");                  $log=fopen($logname,"r");
367                  $cl1=" class=lst"; $cl2="";                  $cl1=" class=LST"; $cl2="";
368                    $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;
371                          print "<tr><td$cl>$line[0]</td><td$cl>$line[1]</td><td$cl>$line[2]</td><td$cl>$line[3]</td></tr>\n";                          array_unshift($logarr,array($cl,$line[0],$line[1],$line[2],$line[3]));
372                  }                  }
373                  fclose($log);                  fclose($log);
374                    print "<hr><br><b>CHANGES TO THIS FILE</b><br><table border=0 width=100%>\n";
375                    $bakcount = 0;  // start from 0, skip fist backup (it's current)
376                    while ($e = array_shift($logarr)) {
377                            if (strstr($e[4],"upload")) {
378                                    if (file_exists("$bakdir/$bakcount/$name")) {
379                                            $e[4]="<a href=\"".dirname($relPath)."/.bak/$bakcount/$name\">$e[4]</a>";
380                                    }
381                                    $bakcount++;
382                            }
383                            print "<tr><td$e[0]>$e[1]</td><td$e[0]>$e[2]</td><td$e[0]>$e[3]</td><td$e[0]>$e[4]</td></tr>\n";
384                    }
385                  print "</table>";                  print "</table>";
386          }          }
387    
# Line 590  function GifIcon($txt) { Line 615  function GifIcon($txt) {
615                  $d = "blank.gif" ;                  $d = "blank.gif" ;
616                  break ;                  break ;
617          case "checkout":          case "checkout":
618                  $d = "down.gif";                  $d = "box2.gif";
619                  break;                  break;
620          case "checkin":          case "checkin":
621                  $d = "up.gif";                  $d = "hand.up.gif";
622                    break;
623            case "locked":
624                    $d = "screw2.gif";
625                  break;                  break;
626          case "note":          case "note":
627                  $d = "quill.gif";                  $d = "quill.gif";
# Line 609  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 655  function Navigate($fsRoot,$relDir) { Line 683  function Navigate($fsRoot,$relDir) {
683          // start navigation page          // start navigation page
684          $text  = "Use this page to add, delete";          $text  = "Use this page to add, delete";
685          if (! isset($show_deleted)) {          if (! isset($show_deleted)) {
686                  $text .= ", <a href=".$GLOBALS[PHP_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 702  function Navigate($fsRoot,$relDir) { Line 731  function Navigate($fsRoot,$relDir) {
731  <TR><TD></TD><TD COLSPAN=5><HR><B><?= $webRoot . $relDir ?>  <TR><TD></TD><TD COLSPAN=5><HR><B><?= $webRoot . $relDir ?>
732  </B></TD></TR>  </B></TD></TR>
733  <TR><TD></TD><TD CLASS=TOP>DOCUMENT NAME</TD>  <TR><TD></TD><TD CLASS=TOP>DOCUMENT NAME</TD>
734  <TD><?= $gblIcon("blank") ?></TD>  <TD><?= $gblIcon("blank").$gblIcon("blank") ?></TD>
735  <TD CLASS=TOP>NOTE</TD>  <TD CLASS=TOP>NOTE</TD>
736  <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>
737    
# Line 724  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                  $tstr = $webRoot . $relDir . "/" . $file ;                  $file_lock=CheckLock($path);
762                  $tstr  = "<A HREF=\"" . $tstr . "\">" ;  
763                    $file_url_html="<A HREF=\"$self?A=V&F=".urlencode($file);
764                    $file_url_html.="&D=".urlencode($relDir);
765                    $file_url_html.="\" TITLE=\"View file\">" ;
766    
767                  if (substr($file,0,5) != ".del/") {                  if (substr($file,0,5) != ".del/") {
768                          $tstr .= $file . "</A>" . $a ;                          $file_url_html .= $file . "</A>" . $a ;
769                  } else {                  } else {
770                          $tstr .= substr($file,5,strlen($file)-5) . "</a> <SPAN CLASS=RED TITLE=\"deleted\"> <a href=\"$info_url#undelete\">deleted</a> </span>";                          $file_url_html .= substr($file,5,strlen($file)-5) . "</a> <SPAN CLASS=RED TITLE=\"deleted\"> <a href=\"$info_url#undelete\">deleted</a> </span>";
771                  }                  }
772    
773  //              $b = $gblIcon("checkout");                  $note_html="<a href=\"$info_url#note\">".$gblIcon("note")."</a>".ReadNote($path);
 //              $b .= $gblIcon("checkin");  
774    
775                  $ext = strtolower(strrchr($file,".")) ;                  $ext = strtolower(strrchr($file,".")) ;
776                  if ( $ext=="" || strstr(join(" ",$gblEditable),$ext) ) {    
777                          $b .= "<A HREF=\"" . $self . "?A=C&F=" ;                  if ($file_lock) {
778                          $b .= urlencode($file) . "&D=" . urlencode($relDir) ;                          if ($file_lock == $GLOBALS[gblUserName]) {
779                          $b .= "\" TITLE=\"List contents\">" ;                                  $b.="<A HREF=\"$self?A=Ci&F=".urlencode($file);
780                          $b .= $gblIcon("view") . "</A>" ;                                  $b.="&D=".urlencode($relDir);
781                                    $b.="\" TITLE=\"Checkin (update) file on server\">" ;
782                                    $file_url_html=$b;
783                                    $b.=$gblIcon("checkin")."</A>" ;
784                                    $b.= $gblIcon("blank");
785                                    $file_url_html.="$file</a> $a";
786                                    $note_html = $gblIcon("blank")."<b>Please check-in (update) this file</b>";
787                            } else {
788                                    $b = $gblIcon("locked");
789                                    $b.= $gblIcon("blank");
790                                    $note_html = $gblIcon("blank")."<b>File locked by $file_lock</b>";
791                                    $file_url_html = "$file $a";
792                            }
793                  } else {                  } else {
794                          $b .= $gblIcon("blank");                          $b.="<A HREF=\"$self?A=Co&F=".urlencode($file);
795                            $b.="&D=".urlencode($relDir);
796                            $b.="\" TITLE=\"Checkout file for edit\">" ;
797                            $b.=$gblIcon("checkout")."</A>" ;
798    
799                            if ( $ext=="" || strstr(join(" ",$gblEditable),$ext) ) {  
800                                    $b.="<A HREF=\"$self?A=C&F=".urlencode($file);
801                                    $b.="&D=".urlencode($relDir);
802                                    $b.="\" TITLE=\"List contents\">" ;
803                                    $b.=$gblIcon("view")."</A>" ;
804                            } else {
805                                    $b.= $gblIcon("blank");
806                            }
807                  }                  }
808    
809    
# Line 757  function Navigate($fsRoot,$relDir) { Line 812  function Navigate($fsRoot,$relDir) {
812  <TR><TD>  <TR><TD>
813  <A HREF="<?= $info_url ?>" TITLE="View/Edit">  <A HREF="<?= $info_url ?>" TITLE="View/Edit">
814  <?= $gblIcon($ext) ?></A></TD>  <?= $gblIcon($ext) ?></A></TD>
815  <TD CLASS=LST><?= $tstr ?></TD>  <TD CLASS=LST><?= $file_url_html ?></TD>
816  <TD CLASS=LST ALIGN=center><?= $b ?></TD>  <TD CLASS=LST ALIGN=center><?= $b ?></TD>
817  <TD CLASS=LST ALIGN=left><a href="<?= $info_url ?>#note"><?= $gblIcon("note") ?></a><?= ReadNote($path) ?></TD>  <TD CLASS=LST ALIGN=left><?= $note_html ?></TD>
818  <TD CLASS=LST><?= date("$GLOBALS[gblDateFmt] $GLOBALS[gblTimeFmt]",$mod) ?></TD>  <TD CLASS=LST><?= date("$GLOBALS[gblDateFmt] $GLOBALS[gblTimeFmt]",$mod) ?></TD>
819  <TD CLASS=LST><?= $sz ?>Bytes</TD></TR>  <TD CLASS=LST><?= $sz ?>Bytes</TD></TR>
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 785  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    
849    <?
850    if (file_exists(".info.inc")) {
851            print "<TR><TD></TD><TD COLSPAN=5>";
852            include(".info.inc");
853            print "</TD></TR>
854            <TR><TD></TD><TD COLSPAN=5><HR></TD></TR>";
855    }
856    ?>
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
860   <INPUT TYPE="RADIO" NAME="T" VALUE="D" CHECKED>DIRECTORY -OR-   <INPUT TYPE="RADIO" NAME="T" VALUE="D" CHECKED>DIRECTORY -OR-
# Line 793  function Navigate($fsRoot,$relDir) { Line 863  function Navigate($fsRoot,$relDir) {
863   <INPUT TYPE="HIDDEN" NAME="POSTACTION" VALUE="CREATE">   <INPUT TYPE="HIDDEN" NAME="POSTACTION" VALUE="CREATE">
864   <INPUT TYPE="HIDDEN" NAME="DIR" VALUE="<?= $relDir ?>">   <INPUT TYPE="HIDDEN" NAME="DIR" VALUE="<?= $relDir ?>">
865   <INPUT TYPE="SUBMIT" VALUE="CREATE"></NOBR>   <INPUT TYPE="SUBMIT" VALUE="CREATE"></NOBR>
866   <NOBR>OR <A HREF="<?= $self   <NOBR>OR <A HREF="<?= $self ?>?A=U&D=<?= urlencode($relDir) ?>">UPLOAD</A> A FILE
         ?>?A=U&D=<?= urlencode($relDir) ?>">UPLOAD</A> A FILE  
867   </NOBR>   </NOBR>
868  </TD></TR>  </TD></TR>
869  </FORM>  </FORM>
# Line 806  function Navigate($fsRoot,$relDir) { Line 875  function Navigate($fsRoot,$relDir) {
875    
876  //////////////////////////////////////////////////////////////////  //////////////////////////////////////////////////////////////////
877    
878  function UploadPage($fsRoot, $relDir) {  function UploadPage($fsRoot, $relDir, $filename="") {
879    
880          $self = $GLOBALS["PHP_SELF"] ;          $self = $GLOBALS["PHP_SELF"] ;
881          if ($relDir == "") $relDir = "/" ;          if ($relDir == "") $relDir = "/" ;
# Line 816  function UploadPage($fsRoot, $relDir) { Line 885  function UploadPage($fsRoot, $relDir) {
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) && $filename!="") { ?>
889    <br>DESTINATION FILE:<B><?= " " . $filename ?></B>
890    <INPUT TYPE="HIDDEN" NAME="FILENAME" VALUE="<?= $filename ?>">
891    <? } ?>
892  <P>PATHNAME OF LOCAL FILE<BR>  <P>PATHNAME OF LOCAL FILE<BR>
893  <INPUT TYPE="HIDDEN" NAME="DIR" VALUE="<?= $relDir ?>">  <INPUT TYPE="HIDDEN" NAME="DIR" VALUE="<?= $relDir ?>">
894  <INPUT TYPE="HIDDEN" NAME="POSTACTION" VALUE="UPLOAD">  <INPUT TYPE="HIDDEN" NAME="POSTACTION" VALUE="UPLOAD">
# Line 899  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 919  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 935  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 943  function ReadNote($target) { Line 1018  function ReadNote($target) {
1018                  $msg=fgets($note,4096);                  $msg=fgets($note,4096);
1019                  fclose($note);                  fclose($note);
1020          }          }
1021          return $msg;          return StripSlashes($msg);
1022    
1023  }  }
1024    
# Line 951  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 962  function MoveTo($source,$folder) { Line 1038  function MoveTo($source,$folder) {
1038    
1039  //////////////////////////////////////////////////////////////////  //////////////////////////////////////////////////////////////////
1040    
1041    function Lock($target) {
1042    
1043            $target=stripSlashes($target);
1044            $dir=dirname($target);
1045            if (! file_exists($dir."/.lock")) {
1046                    mkdir($dir."/.lock",0700);
1047            }
1048            $file=basename($target);
1049    
1050            if (file_exists("$dir/.lock/$file")) {
1051                    Logit($target,"attempt to locked allready locked file!");
1052            } else {
1053                    $lock=fopen("$dir/.lock/$file","w");
1054                    fputs($lock,"$GLOBALS[gblUserName]\n");
1055                    fclose($lock);
1056    
1057                    Logit($target,"file locked");
1058            }
1059    
1060    }
1061    
1062    function CheckLock($target) {
1063    
1064            $target=stripSlashes($target);
1065            $dir=dirname($target);
1066            $file=basename($target);
1067            $msg=0;
1068            if (file_exists($dir."/.lock/$file")) {
1069                    $lock=fopen("$dir/.lock/$file","r");
1070                    $msg=fgets($lock,4096);
1071                    fclose($lock);
1072            }
1073            return chop($msg);
1074    
1075    }
1076    
1077    function Unlock($target) {
1078    
1079            $target=stripSlashes($target);
1080            $dir=dirname($target);
1081            $file=basename($target);
1082            if (file_exists($dir."/.lock/$file")) {
1083                    unlink("$dir/.lock/$file");
1084                    Logit($target,"file unlocked");
1085            } else {
1086                    Logit($target,"attempt to unlocked non-locked file!");
1087            }
1088    
1089    }
1090    
1091    //////////////////////////////////////////////////////////////////
1092    
1093    function urlpath($url) {
1094            $url=urlencode(StripSlashes("$url"));
1095            $url=str_replace("%2F","/",$url);
1096            $url=str_replace("+","%20",$url);
1097            return($url);
1098    }
1099    
1100    //////////////////////////////////////////////////////////////////
1101    
1102    function safe_rename($from,$to) {
1103            if (file_exists($from) && is_writable(dirname($to))) {
1104                    rename($from,$to);
1105            }
1106    }
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 985  function MoveTo($source,$folder) { Line 1187  function MoveTo($source,$folder) {
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 1008  function MoveTo($source,$folder) { Line 1210  function MoveTo($source,$folder) {
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 1028  function MoveTo($source,$folder) { Line 1234  function MoveTo($source,$folder) {
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                  $target = $fsDir . "/" . $FN_name ;                  if (! file_exists($source)) {
1238                            Error("You must select file with browse to upload it!");
1239                    }
1240                    if (! isset($FILENAME)) {       // from update file
1241                            $target = "$fsDir/$FN_name" ;
1242                    } else {
1243                            $target = "$fsDir/$FILENAME";
1244                    }
1245    
1246                  // backup old files first                  // backup old files first
1247                  $dir=dirname($target);                  $dir=dirname($target);
# Line 1042  function MoveTo($source,$folder) { Line 1255  function MoveTo($source,$folder) {
1255                  for($i=$GLOBALS[gblNumBackups]-1;$i>0;$i--) {                  for($i=$GLOBALS[gblNumBackups]-1;$i>0;$i--) {
1256                          MoveTo("$dir/.bak/$i/$file","$dir/.bak/".($i+1)."/");                          MoveTo("$dir/.bak/$i/$file","$dir/.bak/".($i+1)."/");
1257                  }                  }
1258                  MoveTo($target,$dir."/.bak/1/".$file);                  MoveTo($target,$dir."/.bak/1/");
1259    
1260                  copy($source,$target) ;                  copy($source,$target) ;
1261                  chmod($target,$gblFilePerms) ;                  chmod($target,$gblFilePerms) ;
1262                  clearstatcache() ;                  clearstatcache() ;
1263                  Logit($target,"uploaded");                  Logit($target,"uploaded");
1264                    if (isset($FILENAME)) {
1265                            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 1059  function MoveTo($source,$folder) { Line 1277  function MoveTo($source,$folder) {
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 1073  function MoveTo($source,$folder) { Line 1293  function MoveTo($source,$folder) {
1293                  $relPath = $relDir . "/" . $FN ;                  $relPath = $relDir . "/" . $FN ;
1294                  switch ( $T ) {                  switch ( $T ) {
1295                  case "D" :  // create a directory                  case "D" :  // create a directory
1296                    if ( ! @mkdir($path,$gblDirPerms) )                          if ( ! @mkdir($path,$gblDirPerms) )
1297                      Error("Mkdir failed",$relPath) ; // eg. if it exists                                  Error("Mkdir failed",$relPath) ; // eg. if it exists
1298                    clearstatcache() ;                          clearstatcache() ;
1299                    break ;                          break ;
1300                  case "F" :  // create a new file                  case "F" :  // create a new file
1301  // this functionality is doubled in DetailView().  // this functionality is doubled in DetailView().
1302  // better keep it here altogether  // better keep it here altogether
1303  // chmod perms to $gblFilePerms  // chmod perms to $gblFilePerms
1304                    if ( file_exists($path) && !is_writable($path) )                          if ( file_exists($path) && !is_writable($path) )
1305                      Error("File not writable", $relPath) ;                                  Error("File not writable", $relPath) ;
1306                    $tstr = $PHP_SELF . "?A=E&D=" . $relDir . "&F=" . $FN ;                          $fh = fopen($path, "w+") ;
1307                    header("Location: " . $tstr) ;                          if ($fh) {
1308                    exit ;                                  fputs($fh,"\n");
1309                                    fclose($fh) ;
1310                                    LogIt($path,"file created");
1311                            } else {
1312                                    Error("Creation of file $relPath failed -- $path");
1313                            }
1314                            $tstr = "$PHP_SELF?A=E&D=".urlencode($relDir)."&F=".urlencode($FN) ;
1315                            header("Location: " . $tstr) ;
1316                            ChangeLog($target,"created");
1317                            exit ;
1318                  }                  }
1319                  break ;                  break ;
1320    
# Line 1111  function MoveTo($source,$folder) { Line 1340  function MoveTo($source,$folder) {
1340                                  exit ;                                  exit ;
1341                          } else {                          } else {
1342                                  Logit($path,"file deleted");                                  Logit($path,"file deleted");
                                 if (! file_exists("$dir/.del/.log")) {  
                                         mkdir("$dir/.del/.log",0700);  
                                 }  
1343                                  MoveTo("$dir/.log/$file","$dir/.del/.log/");                                  MoveTo("$dir/.log/$file","$dir/.del/.log/");
1344                                  MoveTo("$dir/.note/$file","$dir/.del/.note/");                                  MoveTo("$dir/.note/$file","$dir/.del/.note/");
1345                                    MoveTo("$dir/.lock/$file","$dir/.del/.lock/");
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 1138  function MoveTo($source,$folder) { Line 1365  function MoveTo($source,$folder) {
1365                  MoveTo("$fsDir/.del/$file","$fsDir/");                  MoveTo("$fsDir/.del/$file","$fsDir/");
1366                  MoveTo("$fsDir/.del/.log/$file","$fsDir/.log/");                  MoveTo("$fsDir/.del/.log/$file","$fsDir/.log/");
1367                  MoveTo("$fsDir/.del/.note/$file","$fsDir/.note/");                  MoveTo("$fsDir/.del/.note/$file","$fsDir/.note/");
1368                    MoveTo("$fsDir/.del/.lock/$file","$fsDir/.lock/");
1369    
1370                  break ;                  break ;
1371    
# Line 1145  function MoveTo($source,$folder) { Line 1373  function MoveTo($source,$folder) {
1373                  if ( $CONFIRM != "on" ) break ;                  if ( $CONFIRM != "on" ) break ;
1374    
1375                  Logit("$fsDir/$FN","renamed $FN to $NEWNAME");                  Logit("$fsDir/$FN","renamed $FN to $NEWNAME");
1376                  rename("$fsDir/$FN","$fsDir/$NEWNAME");                  safe_rename("$fsDir/$FN","$fsDir/$NEWNAME");
1377                  rename("$fsDir/.log/$FN","$fsDir/.log/$NEWNAME");                  safe_rename("$fsDir/.log/$FN","$fsDir/.log/$NEWNAME");
1378                    safe_rename("$fsDir/.note/$FN","$fsDir/.note/$NEWNAME");
1379                    safe_rename("$fsDir/.lock/$FN","$fsDir/.lock/$NEWNAME");
1380                    for($i=0;$i<=$GLOBALS[gblNumBackups];$i++) {
1381                            safe_rename("$fsDir/.bak/$i/$FN","$fsDir/.bak/$i/$NEWNAME");
1382                    }
1383    
1384                  break ;                  break ;
1385    
# Line 1154  function MoveTo($source,$folder) { Line 1387  function MoveTo($source,$folder) {
1387                  WriteNote("$fsDir/$FN","$NOTE");                  WriteNote("$fsDir/$FN","$NOTE");
1388                  break ;                  break ;
1389    
1390            case "UNLOCK" :  
1391                    if ( $CONFIRM != "on" ) break ;
1392                    Unlock("$fsDir/$FN");
1393                    break ;
1394    
1395          default :          default :
1396                  // user hit "CANCEL" or undefined action                  // user hit "CANCEL" or undefined action
1397          }          }
# Line 1169  function MoveTo($source,$folder) { Line 1407  function MoveTo($source,$folder) {
1407          // $A=U : upload to path given in $D          // $A=U : upload to path given in $D
1408          // $A=E : display detail of file $D/$F and edit          // $A=E : display detail of file $D/$F and edit
1409          // $A=C : display code in file $D/$F          // $A=C : display code in file $D/$F
1410            // $A=Co : checkout file $D/$F
1411            // $A=Ci : checkin file $D/$F
1412            // $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 ;
1436            case "Co" :
1437                    // checkout
1438                    Lock("$gblFsRoot/$relDir/$F");
1439                    header("Content-Disposition: attachment; filename=$F" );
1440                    Header("Location: ".urlpath("$relDir/$F"));
1441                    exit;
1442            case "Ci" :
1443                    $F=stripSlashes($F);
1444                    // upload && update to $relDir
1445                    if (!is_writeable($gblFsRoot . $relDir))
1446                            Error("Write access denied",$relDir) ;
1447                    $text  = "Use this page to update a single " ;
1448                    $text .= "file to <B>$HTTP_HOST</B>." ;
1449                    StartHTML("(Update file Page)", $text) ;
1450                    UploadPage($gblFsRoot, $relDir, $F) ;
1451                    EndHTML() ;
1452                    exit ;
1453            case "V" :
1454                    // view
1455                    LogIt("$gblFsRoot/$relDir/$F","viewed");
1456                    header("Content-Disposition: attachment; filename=$F" );
1457                    Header("Location: ".urlpath("$relDir/$F"));
1458                    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.4  
changed lines
  Added in v.1.27

  ViewVC Help
Powered by ViewVC 1.1.26