/[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.18 by dpavlin, Thu Sep 7 10:17:35 2000 UTC
# Line 65  IMPORTANT INSTALLATION NOTE: Line 65  IMPORTANT INSTALLATION NOTE:
65  TODO:  TODO:
66          mixed file/directory output (add type to each entry,          mixed file/directory output (add type to each entry,
67                  real support for links)                  real support for links)
68          add more content-management (like cms.sourceforge.net):          retrieve old versions of files (overwritten)
69                  check-out/check-in/reserve          show last lock date
70                  comments to files          
71  */  */
72    
73  //////////////////////////////////////////////////////////////////  //////////////////////////////////////////////////////////////////
# Line 108  TODO: Line 108  TODO:
108                          if ($user[0] == $GLOBALS["PHP_AUTH_USER"]) {                          if ($user[0] == $GLOBALS["PHP_AUTH_USER"]) {
109                                  $gblUserName=$user[1];                                  $gblUserName=$user[1];
110                                  $gblPw=$user[2];                                  $gblPw=$user[2];
111                                    $gblEmail=$user[3];
112                                  continue ;                                  continue ;
113                          }                          }
114                  }                  }
# Line 120  TODO: Line 121  TODO:
121          $gblDateFmt="Y-m-d";          $gblDateFmt="Y-m-d";
122          $gblTimeFmt="H:i:s";          $gblTimeFmt="H:i:s";
123    
124  // Number of backup files to keep          // Number of backup files to keep
125          $gblNumBackups=5;          $gblNumBackups=3;
126    
127            // show red star if newer than ... days
128            $gblModDays=1;
129    
130          // choose GifIcon below unless you have the M$          // choose GifIcon below unless you have the M$
131          // WingDings font installed on your system          // WingDings font installed on your system
# Line 184  function EndHTML() { Line 188  function EndHTML() {
188  <B><?= date($GLOBALS[gblDateFmt]) ?> -  <B><?= date($GLOBALS[gblDateFmt]) ?> -
189  <?= date($GLOBALS[gblTimeFmt]) ?> -  <?= date($GLOBALS[gblTimeFmt]) ?> -
190  <?= $GLOBALS[gblUserName] ?>  <?= $GLOBALS[gblUserName] ?>
191  <small> [<a href="<?= $PHP_SELF ?>?relogin=<?= $GLOBALS[gblPw] ?>">logout</a>]</small>  <small> [<a href="<?= $GLOBALS["PHP_SELF"] ?>?relogin=<?= $GLOBALS[gblPw] ?>">logout</a>]</small>
192  </B>  </B>
193  <BR>ANYPORTAL(php) Site Manager  <BR>ANYPORTAL(php) Site Manager
194  <br><small>  <br><small>
# Line 194  function EndHTML() { Line 198  function EndHTML() {
198  </small>  </small>
199  </P>  </P>
200  <BR>  <BR>
201  <? include(".debug.inc") ?>  <? //include(".debug.inc") ?>
202  <BR><BR></BODY></HTML>  <BR><BR></BODY></HTML>
203    
204  <?php  <?php
# Line 240  function DetailPage($fsRoot,$relDir,$fn) Line 244  function DetailPage($fsRoot,$relDir,$fn)
244          $ext      = strtolower(strrchr($relPath,".")) ;          $ext      = strtolower(strrchr($relPath,".")) ;
245          $editable = ( $ext=="" || strstr(join(" ",$gblEditable),$ext)) ;          $editable = ( $ext=="" || strstr(join(" ",$gblEditable),$ext)) ;
246          $writable = is_writeable($fsPath) ;          $writable = is_writeable($fsPath) ;
247            $file_lock = CheckLock($fsPath);
248    
249          if (!$editable && !$exists)          if (!$editable && !$exists)
250                  Error("Creation unsupported for type",$relPath) ;                  Error("Creation unsupported for type",$relPath) ;
# Line 268  function DetailPage($fsRoot,$relDir,$fn) Line 273  function DetailPage($fsRoot,$relDir,$fn)
273    
274          }          }
275    
276          if ( $editable && ($writable || !$exists) ) {          if ( $editable && ($writable || !$exists) && !$file_lock ) {
277                  $fh = fopen($fsPath,"a+") ;                  $fh = fopen($fsPath,"a+") ;
278                  rewind($fh) ;                  rewind($fh) ;
279                  $fstr = fread($fh,filesize($fsPath)) ;                  $fstr = fread($fh,filesize($fsPath)) ;
# Line 294  echo($fstr) ; ?></TEXTAREA> Line 299  echo($fstr) ; ?></TEXTAREA>
299    
300  <?php  <?php
301          }          }
302          else if ( strstr( join(" ",$gblImages), $ext ) ) {            if ( !$file_lock && $ext!="" && strstr(join(' ',$gblImages),$ext) ) {  
303            $info  = getimagesize($fsPath) ;                  $info  = getimagesize($fsPath) ;
304            $tstr  = "<IMG SRC=\"". $relPath . "\" BORDER=0 " ;                  $tstr = "<IMG SRC=\"".urlpath($relPath)."\" BORDER=0 " ;
305            $tstr .= $info[3] . " ALT=\"" . $fn . " - " ;                  $tstr .= $info[3] . " ALT=\"" . $fn . " - " ;
306            $tstr .= (int)(($fsize+1023)/1024) . "Kb\">" ;                  $tstr .= (int)(($fsize+1023)/1024) . "Kb\">" ;
307            echo htmlentities($tstr) . "<BR><BR>" . $tstr ;  //              echo htmlentities($tstr) . "<BR><BR>" . $tstr ;
308                    echo $tstr ;
309          }          }
310    
311  ?>  ?>
312    
313  <FORM ACTION="<?= $self ; ?>" METHOD="POST">  <FORM ACTION="<?= $self ; ?>" METHOD="POST">
# Line 309  echo($fstr) ; ?></TEXTAREA> Line 316  echo($fstr) ; ?></TEXTAREA>
316  <INPUT TYPE="SUBMIT" NAME="POSTACTION" VALUE="CANCEL"><BR>  <INPUT TYPE="SUBMIT" NAME="POSTACTION" VALUE="CANCEL"><BR>
317    
318  <?php  <?php
319    
320            if ($file_lock) {
321    ?>
322    <hr>
323    <SPAN TITLE="Check OK and click UNLOCK to remove lock on file.">
324    <B>OK TO FORCE LOCK REMOVAL ON "<?= $fn ; ?>" HELD BY <?= $file_lock ?>? </B></SPAN>
325    <INPUT TYPE="CHECKBOX" NAME="CONFIRM">
326    <INPUT TYPE="SUBMIT" NAME="POSTACTION" VALUE="UNLOCK">
327    <?
328            } // file_lock
329    
330          if (substr($fn,0,4) == ".del") {          if (substr($fn,0,4) == ".del") {
331                  $action="UNDELETE";                  $action="UNDELETE";
332                  $desc="undelete previously deleted file";                  $desc="undelete previously deleted file";
# Line 336  echo($fstr) ; ?></TEXTAREA> Line 354  echo($fstr) ; ?></TEXTAREA>
354  <INPUT TYPE="CHECKBOX" NAME="CONFIRM">  <INPUT TYPE="CHECKBOX" NAME="CONFIRM">
355  <INPUT TYPE="SUBMIT" NAME="POSTACTION" VALUE="RENAME">  <INPUT TYPE="SUBMIT" NAME="POSTACTION" VALUE="RENAME">
356    
357    <?php
358            }       // exists && writable
359    ?>
360  <HR>  <HR>
361  <a name="note">  <a name="note">
362  <B>NOTE FOR "<?= $fn ; ?>":  <B>NOTE FOR "<?= $fn ; ?>":
# Line 343  echo($fstr) ; ?></TEXTAREA> Line 364  echo($fstr) ; ?></TEXTAREA>
364  </B></SPAN>  </B></SPAN>
365  <INPUT TYPE="SUBMIT" NAME="POSTACTION" VALUE="NOTE">  <INPUT TYPE="SUBMIT" NAME="POSTACTION" VALUE="NOTE">
366    
367  <?php  </FORM>
         }  
         echo "</FORM>" ;  
368    
369          $logname=dirname("$fsDir/$fn")."/.log/".basename("$fsDir/$fn");  <?php
370            
371            $name=basename("$fsDir/$fn");
372            $logname=dirname("$fsDir/$fn")."/.log/$name";
373            $bakdir=dirname("$fsDir/$fn")."/.bak";
374          if (file_exists($logname)) {          if (file_exists($logname)) {
                 print "<hr><br><b>CHANGES TO THIS FILE</b><br><table border=0 width=100%>\n";  
375                  $log=fopen($logname,"r");                  $log=fopen($logname,"r");
376                  $cl1=" class=lst"; $cl2="";                  $cl1=" class=lst"; $cl2="";
377                    $logarr = array();
378                  while($line = fgetcsv($log,255,"\t")) {                  while($line = fgetcsv($log,255,"\t")) {
379                          $cl=$cl1; $cl1=$cl2; $cl2=$cl;                          $cl=$cl1; $cl1=$cl2; $cl2=$cl;
380                          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]));
381                  }                  }
382                  fclose($log);                  fclose($log);
383                    print "<hr><br><b>CHANGES TO THIS FILE</b><br><table border=0 width=100%>\n";
384                    $bakcount = 0;  // start from 0, skip fist backup (it's current)
385                    while ($e = array_shift($logarr)) {
386                            if (strstr($e[4],"upload")) {
387                                    if (file_exists("$bakdir/$bakcount/$name")) {
388                                            $e[4]="<a href=\"".dirname($relPath)."/.bak/$bakcount/$name\">$e[4]</a>";
389                                    }
390                                    $bakcount++;
391                            }
392                            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";
393                    }
394                  print "</table>";                  print "</table>";
395          }          }
396    
# Line 590  function GifIcon($txt) { Line 624  function GifIcon($txt) {
624                  $d = "blank.gif" ;                  $d = "blank.gif" ;
625                  break ;                  break ;
626          case "checkout":          case "checkout":
627                  $d = "down.gif";                  $d = "box2.gif";
628                  break;                  break;
629          case "checkin":          case "checkin":
630                  $d = "up.gif";                  $d = "hand.up.gif";
631                    break;
632            case "locked":
633                    $d = "screw2.gif";
634                  break;                  break;
635          case "note":          case "note":
636                  $d = "quill.gif";                  $d = "quill.gif";
# Line 609  function GifIcon($txt) { Line 646  function GifIcon($txt) {
646    
647  function Navigate($fsRoot,$relDir) {  function Navigate($fsRoot,$relDir) {
648    
649          global $gblEditable, $gblIcon ;          global $gblEditable, $gblIcon, $gblModDays ;
650    
651          $self     = $GLOBALS["PHP_SELF"] ;          $self     = $GLOBALS["PHP_SELF"] ;
652          if (isset($GLOBALS["HTTPS"]) && $GLOBALS["HTTPS"] == "on") {          if (isset($GLOBALS["HTTPS"]) && $GLOBALS["HTTPS"] == "on") {
# Line 655  function Navigate($fsRoot,$relDir) { Line 692  function Navigate($fsRoot,$relDir) {
692          // start navigation page          // start navigation page
693          $text  = "Use this page to add, delete";          $text  = "Use this page to add, delete";
694          if (! isset($show_deleted)) {          if (! isset($show_deleted)) {
695                  $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>";
696          }          }
697          $text .= " or revise files on this web site." ;          $text .= " or revise files on this web site." ;
698            $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>.";
699          StartHTML("(Navigate)",$text) ;          StartHTML("(Navigate)",$text) ;
700    
701          echo "<TABLE BORDER=0 CELLPADDING=2          echo "<TABLE BORDER=0 CELLPADDING=2
# Line 702  function Navigate($fsRoot,$relDir) { Line 740  function Navigate($fsRoot,$relDir) {
740  <TR><TD></TD><TD COLSPAN=5><HR><B><?= $webRoot . $relDir ?>  <TR><TD></TD><TD COLSPAN=5><HR><B><?= $webRoot . $relDir ?>
741  </B></TD></TR>  </B></TD></TR>
742  <TR><TD></TD><TD CLASS=TOP>DOCUMENT NAME</TD>  <TR><TD></TD><TD CLASS=TOP>DOCUMENT NAME</TD>
743  <TD><?= $gblIcon("blank") ?></TD>  <TD><?= $gblIcon("blank").$gblIcon("blank") ?></TD>
744  <TD CLASS=TOP>NOTE</TD>  <TD CLASS=TOP>NOTE</TD>
745  <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>
746    
# Line 724  function Navigate($fsRoot,$relDir) { Line 762  function Navigate($fsRoot,$relDir) {
762    
763                  $info_url=$self."?A=E&F=".urlencode($file)."&D=".urlencode($relDir);                  $info_url=$self."?A=E&F=".urlencode($file)."&D=".urlencode($relDir);
764    
765                  if ( ($mod + 30*86400) > time() ) {                  if ( ($mod + $gblModDays*86400) > time() ) {
766                          $a  = "<SPAN CLASS=RED TITLE=\"Newer" ;                          $a  = "<SPAN CLASS=RED TITLE=\"Newer" ;
767                          $a .= " than 30 days\"> * </SPAN>" ;                          $a .= " than $gblModDays days\"> * </SPAN>" ;
768                  }                  }
769    
770                  $tstr = $webRoot . $relDir . "/" . $file ;                  $file_lock=CheckLock($path);
771                  $tstr  = "<A HREF=\"" . $tstr . "\">" ;  
772                    $file_url_html="<A HREF=\"$self?A=V&F=".urlencode($file);
773                    $file_url_html.="&D=".urlencode($relDir);
774                    $file_url_html.="\" TITLE=\"View file\">" ;
775    
776                  if (substr($file,0,5) != ".del/") {                  if (substr($file,0,5) != ".del/") {
777                          $tstr .= $file . "</A>" . $a ;                          $file_url_html .= $file . "</A>" . $a ;
778                  } else {                  } else {
779                          $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>";
780                  }                  }
781    
782  //              $b = $gblIcon("checkout");                  $note_html="<a href=\"$info_url#note\">".$gblIcon("note")."</a>".ReadNote($path);
 //              $b .= $gblIcon("checkin");  
783    
784                  $ext = strtolower(strrchr($file,".")) ;                  $ext = strtolower(strrchr($file,".")) ;
785                  if ( $ext=="" || strstr(join(" ",$gblEditable),$ext) ) {    
786                          $b .= "<A HREF=\"" . $self . "?A=C&F=" ;                  if ($file_lock) {
787                          $b .= urlencode($file) . "&D=" . urlencode($relDir) ;                          if ($file_lock == $GLOBALS[gblUserName]) {
788                          $b .= "\" TITLE=\"List contents\">" ;                                  $b.="<A HREF=\"$self?A=Ci&F=".urlencode($file);
789                          $b .= $gblIcon("view") . "</A>" ;                                  $b.="&D=".urlencode($relDir);
790                                    $b.="\" TITLE=\"Checkin (update) file on server\">" ;
791                                    $file_url_html=$b;
792                                    $b.=$gblIcon("checkin")."</A>" ;
793                                    $b.= $gblIcon("blank");
794                                    $file_url_html.="$file</a> $a";
795                                    $note_html = $gblIcon("blank")."<b>Please check-in (update) this file</b>";
796                            } else {
797                                    $b = $gblIcon("locked");
798                                    $b.= $gblIcon("blank");
799                                    $note_html = $gblIcon("blank")."<b>File locked by $file_lock</b>";
800                                    $file_url_html = "$file $a";
801                            }
802                  } else {                  } else {
803                          $b .= $gblIcon("blank");                          $b.="<A HREF=\"$self?A=Co&F=".urlencode($file);
804                            $b.="&D=".urlencode($relDir);
805                            $b.="\" TITLE=\"Checkout file for edit\">" ;
806                            $b.=$gblIcon("checkout")."</A>" ;
807    
808                            if ( $ext=="" || strstr(join(" ",$gblEditable),$ext) ) {  
809                                    $b.="<A HREF=\"$self?A=C&F=".urlencode($file);
810                                    $b.="&D=".urlencode($relDir);
811                                    $b.="\" TITLE=\"List contents\">" ;
812                                    $b.=$gblIcon("view")."</A>" ;
813                            } else {
814                                    $b.= $gblIcon("blank");
815                            }
816                  }                  }
817    
818    
# Line 757  function Navigate($fsRoot,$relDir) { Line 821  function Navigate($fsRoot,$relDir) {
821  <TR><TD>  <TR><TD>
822  <A HREF="<?= $info_url ?>" TITLE="View/Edit">  <A HREF="<?= $info_url ?>" TITLE="View/Edit">
823  <?= $gblIcon($ext) ?></A></TD>  <?= $gblIcon($ext) ?></A></TD>
824  <TD CLASS=LST><?= $tstr ?></TD>  <TD CLASS=LST><?= $file_url_html ?></TD>
825  <TD CLASS=LST ALIGN=center><?= $b ?></TD>  <TD CLASS=LST ALIGN=center><?= $b ?></TD>
826  <TD CLASS=LST ALIGN=left><a href="<?= $info_url ?>#note"><?= $gblIcon("note") ?></a><?= ReadNote($path) ?></TD>  <TD CLASS=LST ALIGN=left><?= $note_html ?></TD>
827  <TD CLASS=LST><?= date("$GLOBALS[gblDateFmt] $GLOBALS[gblTimeFmt]",$mod) ?></TD>  <TD CLASS=LST><?= date("$GLOBALS[gblDateFmt] $GLOBALS[gblTimeFmt]",$mod) ?></TD>
828  <TD CLASS=LST><?= $sz ?>Bytes</TD></TR>  <TD CLASS=LST><?= $sz ?>Bytes</TD></TR>
829    
# Line 785  function Navigate($fsRoot,$relDir) { Line 849  function Navigate($fsRoot,$relDir) {
849    
850  <TR><TD></TD><TD COLSPAN=5><HR></TD></TR>  <TR><TD></TD><TD COLSPAN=5><HR></TD></TR>
851    
852    <TR><TD></TD><TD COLSPAN=5>
853    <?
854    if (file_exists(".info.inc")) {
855            include(".info.inc");
856    }
857    ?>
858    </TD></TR>
859    
860    <TR><TD></TD><TD COLSPAN=5><HR></TD></TR>
861    
862  <FORM METHOD="POST" ACTION="<?= $self ?>">  <FORM METHOD="POST" ACTION="<?= $self ?>">
863  <TR><TD></TD><TD COLSPAN=5 CLASS=BAR>CREATE NEW  <TR><TD></TD><TD COLSPAN=5 CLASS=BAR>CREATE NEW
864   <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 867  function Navigate($fsRoot,$relDir) {
867   <INPUT TYPE="HIDDEN" NAME="POSTACTION" VALUE="CREATE">   <INPUT TYPE="HIDDEN" NAME="POSTACTION" VALUE="CREATE">
868   <INPUT TYPE="HIDDEN" NAME="DIR" VALUE="<?= $relDir ?>">   <INPUT TYPE="HIDDEN" NAME="DIR" VALUE="<?= $relDir ?>">
869   <INPUT TYPE="SUBMIT" VALUE="CREATE"></NOBR>   <INPUT TYPE="SUBMIT" VALUE="CREATE"></NOBR>
870   <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  
871   </NOBR>   </NOBR>
872  </TD></TR>  </TD></TR>
873  </FORM>  </FORM>
# Line 806  function Navigate($fsRoot,$relDir) { Line 879  function Navigate($fsRoot,$relDir) {
879    
880  //////////////////////////////////////////////////////////////////  //////////////////////////////////////////////////////////////////
881    
882  function UploadPage($fsRoot, $relDir) {  function UploadPage($fsRoot, $relDir, $filename) {
883    
884          $self = $GLOBALS["PHP_SELF"] ;          $self = $GLOBALS["PHP_SELF"] ;
885          if ($relDir == "") $relDir = "/" ;          if ($relDir == "") $relDir = "/" ;
# Line 816  function UploadPage($fsRoot, $relDir) { Line 889  function UploadPage($fsRoot, $relDir) {
889  <FORM ENCTYPE="multipart/form-data" METHOD="POST"  <FORM ENCTYPE="multipart/form-data" METHOD="POST"
890   ACTION="<?= $self ?>">   ACTION="<?= $self ?>">
891  DESTINATION DIRECTORY:<B><?= " " . $relDir ?></B>  DESTINATION DIRECTORY:<B><?= " " . $relDir ?></B>
892    <? if (isset($filename)) { ?>
893    <br>DESTINATION FILE:<B><?= " " . $filename ?></B>
894    <INPUT TYPE="HIDDEN" NAME="FILENAME" VALUE="<?= $filename ?>">
895    <? } ?>
896  <P>PATHNAME OF LOCAL FILE<BR>  <P>PATHNAME OF LOCAL FILE<BR>
897  <INPUT TYPE="HIDDEN" NAME="DIR" VALUE="<?= $relDir ?>">  <INPUT TYPE="HIDDEN" NAME="DIR" VALUE="<?= $relDir ?>">
898  <INPUT TYPE="HIDDEN" NAME="POSTACTION" VALUE="UPLOAD">  <INPUT TYPE="HIDDEN" NAME="POSTACTION" VALUE="UPLOAD">
# Line 943  function ReadNote($target) { Line 1020  function ReadNote($target) {
1020                  $msg=fgets($note,4096);                  $msg=fgets($note,4096);
1021                  fclose($note);                  fclose($note);
1022          }          }
1023          return $msg;          return StripSlashes($msg);
1024    
1025  }  }
1026    
# Line 962  function MoveTo($source,$folder) { Line 1039  function MoveTo($source,$folder) {
1039    
1040  //////////////////////////////////////////////////////////////////  //////////////////////////////////////////////////////////////////
1041    
1042    function Lock($target) {
1043    
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            $dir=dirname($target);
1065            $file=basename($target);
1066            $msg=0;
1067            if (file_exists($dir."/.lock/$file")) {
1068                    $lock=fopen("$dir/.lock/$file","r");
1069                    $msg=fgets($lock,4096);
1070                    fclose($lock);
1071            }
1072            return chop($msg);
1073    
1074    }
1075    
1076    function Unlock($target) {
1077    
1078            $dir=dirname($target);
1079            $file=basename($target);
1080            if (file_exists($dir."/.lock/$file")) {
1081                    unlink("$dir/.lock/$file");
1082                    Logit($target,"file unlocked");
1083            } else {
1084                    Logit($target,"attempt to unlocked non-locked file!");
1085            }
1086    
1087    }
1088    
1089    //////////////////////////////////////////////////////////////////
1090    
1091    function urlpath($url) {
1092            $url=urlencode(StripSlashes("$url"));
1093            $url=str_replace("%2F","/",$url);
1094            $url=str_replace("+","%20",$url);
1095            return($url);
1096    }
1097    
1098    //////////////////////////////////////////////////////////////////
1099    
1100    function safe_rename($from,$to) {
1101            if (file_exists($from) && is_writable(dirname($to))) {
1102                    rename($from,$to);
1103            }
1104    }
1105    
1106    //////////////////////////////////////////////////////////////////
1107    
1108    // recursivly delete directory
1109    
1110    function rrmdir($dir) {
1111            $handle=opendir($dir);
1112            while ($file = readdir($handle)) {
1113                    if ($file != "." && $file != "..") {
1114                            if (is_dir("$dir/$file"))
1115                                    rrmdir("$dir/$file");
1116                            else
1117                                    if (! @unlink("$dir/$file")) return(0);
1118                    }
1119            }
1120            closedir($handle);
1121            return @rmdir($dir);
1122    }
1123    
1124    //////////////////////////////////////////////////////////////////
1125    
1126    function ChangeLog($target,$msg) {
1127    
1128            global $gblFsRoot;
1129            $log=fopen("$gblFsRoot/.changelog","a+");
1130            if (substr($target,0,strlen($gblFsRoot)) == $gblFsRoot)
1131                    $target=substr($target,strlen($gblFsRoot),strlen($target)-strlen($gblFsRoot));
1132            fputs($log,time()."\t$target\t$GLOBALS[gblUserName]\t$msg\n");
1133            fclose($log);
1134    
1135    }
1136    
1137    function DisplayChangeLog($day) {
1138    
1139            global $gblFsRoot;
1140            $log=fopen("$gblFsRoot/.changelog","r");
1141            $logarr = array();
1142            while($line = fgetcsv($log,255,"\t")) {
1143                    if ($day!=1 || $day==1 && $line[0]-time() < 24*60) {
1144                            array_unshift($logarr,array($line[0],$line[1],$line[2],$line[3]));
1145                    }
1146            }
1147            fclose($log);
1148            $cl1=" class=lst"; $cl2="";
1149            print "<table border=0 width=100%>\n";
1150            while ($e = array_shift($logarr)) {
1151                    $cl=$cl1; $cl1=$cl2; $cl2=$cl;
1152                    $date = date("$GLOBALS[gblDateFmt]", $e[0]);
1153                    $time = date("$GLOBALS[gblTimeFmt]", $e[0]);
1154                    $dir = dirname($e[1]);
1155                    $file = basename($e[1]);
1156                    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";
1157            }
1158            print "</table>";
1159    }
1160    
1161    //////////////////////////////////////////////////////////////////
1162    
1163  // MAIN PROGRAM  // MAIN PROGRAM
1164  // ============  // ============
1165  // query parameters: capital letters  // query parameters: capital letters
# Line 1028  function MoveTo($source,$folder) { Line 1226  function MoveTo($source,$folder) {
1226                  // TODO : should rather check for escapeshellcmds                  // TODO : should rather check for escapeshellcmds
1227                  // but maybe RFC 18xx asserts safe filenames ....                  // but maybe RFC 18xx asserts safe filenames ....
1228                  $source = $FN ;                  $source = $FN ;
1229                  $target = $fsDir . "/" . $FN_name ;                  if (! isset($FILENAME)) {       // from update file
1230                            $target = "$fsDir/$FN_name" ;
1231                    } else {
1232                            $target = "$fsDir/$FILENAME";
1233                    }
1234    
1235                  // backup old files first                  // backup old files first
1236                  $dir=dirname($target);                  $dir=dirname($target);
# Line 1042  function MoveTo($source,$folder) { Line 1244  function MoveTo($source,$folder) {
1244                  for($i=$GLOBALS[gblNumBackups]-1;$i>0;$i--) {                  for($i=$GLOBALS[gblNumBackups]-1;$i>0;$i--) {
1245                          MoveTo("$dir/.bak/$i/$file","$dir/.bak/".($i+1)."/");                          MoveTo("$dir/.bak/$i/$file","$dir/.bak/".($i+1)."/");
1246                  }                  }
1247                  MoveTo($target,$dir."/.bak/1/".$file);                  MoveTo($target,$dir."/.bak/1/");
1248    
1249                  copy($source,$target) ;                  copy($source,$target) ;
1250                  chmod($target,$gblFilePerms) ;                  chmod($target,$gblFilePerms) ;
1251                  clearstatcache() ;                  clearstatcache() ;
1252                  Logit($target,"uploaded");                  Logit($target,"uploaded");
1253                    if (isset($FILENAME)) {
1254                            Unlock($target);
1255                    }
1256                    ChangeLog($target,"updated");
1257                  break ;                  break ;
1258    
1259          case "SAVE" :          case "SAVE" :
1260                  $path = $gblFsRoot . escapeshellcmd($RELPATH) ;                  $path = $gblFsRoot . $RELPATH ;
1261                  $writable = is_writeable($path) ;                  $writable = is_writeable($path) ;
1262                  $legaldir = is_writeable(dirname($path)) ;                  $legaldir = is_writeable(dirname($path)) ;
1263                  $exists   = (file_exists($path)) ? 1 : 0 ;                  $exists   = (file_exists($path)) ? 1 : 0 ;
# Line 1063  function MoveTo($source,$folder) { Line 1269  function MoveTo($source,$folder) {
1269                  fclose($fh) ;                  fclose($fh) ;
1270                  clearstatcache() ;                  clearstatcache() ;
1271                  Logit($path,"saved changes");                  Logit($path,"saved changes");
1272                    ChangeLog($path,"saved changes");
1273                  break ;                  break ;
1274    
1275          case "CREATE" :          case "CREATE" :
# Line 1073  function MoveTo($source,$folder) { Line 1280  function MoveTo($source,$folder) {
1280                  $relPath = $relDir . "/" . $FN ;                  $relPath = $relDir . "/" . $FN ;
1281                  switch ( $T ) {                  switch ( $T ) {
1282                  case "D" :  // create a directory                  case "D" :  // create a directory
1283                    if ( ! @mkdir($path,$gblDirPerms) )                          if ( ! @mkdir($path,$gblDirPerms) )
1284                      Error("Mkdir failed",$relPath) ; // eg. if it exists                                  Error("Mkdir failed",$relPath) ; // eg. if it exists
1285                    clearstatcache() ;                          clearstatcache() ;
1286                    break ;                          break ;
1287                  case "F" :  // create a new file                  case "F" :  // create a new file
1288  // this functionality is doubled in DetailView().  // this functionality is doubled in DetailView().
1289  // better keep it here altogether  // better keep it here altogether
1290  // chmod perms to $gblFilePerms  // chmod perms to $gblFilePerms
1291                    if ( file_exists($path) && !is_writable($path) )                          if ( file_exists($path) && !is_writable($path) )
1292                      Error("File not writable", $relPath) ;                                  Error("File not writable", $relPath) ;
1293                    $tstr = $PHP_SELF . "?A=E&D=" . $relDir . "&F=" . $FN ;                          $fh = fopen($path, "w+") ;
1294                    header("Location: " . $tstr) ;                          if ($fh) {
1295                    exit ;                                  fputs($fh,"\n");
1296                                    fclose($fh) ;
1297                                    LogIt($path,"file created");
1298                            } else {
1299                                    Error("Creation of file $relPath failed -- $path");
1300                            }
1301                            $tstr = "$PHP_SELF?A=E&D=".urlencode($relDir)."&F=".urlencode($FN) ;
1302                            header("Location: " . $tstr) ;
1303                            ChangeLog($target,"created");
1304                            exit ;
1305                  }                  }
1306                  break ;                  break ;
1307    
# Line 1111  function MoveTo($source,$folder) { Line 1327  function MoveTo($source,$folder) {
1327                                  exit ;                                  exit ;
1328                          } else {                          } else {
1329                                  Logit($path,"file deleted");                                  Logit($path,"file deleted");
                                 if (! file_exists("$dir/.del/.log")) {  
                                         mkdir("$dir/.del/.log",0700);  
                                 }  
1330                                  MoveTo("$dir/.log/$file","$dir/.del/.log/");                                  MoveTo("$dir/.log/$file","$dir/.del/.log/");
1331                                  MoveTo("$dir/.note/$file","$dir/.del/.note/");                                  MoveTo("$dir/.note/$file","$dir/.del/.note/");
1332                                    MoveTo("$dir/.lock/$file","$dir/.del/.lock/");
1333                          }                          }
1334                  }                  }
1335                  else {  // delete directory                  else {  // delete directory
1336                    if ( ! @rmdir($fsDir) ) {                    if ( ! @rrmdir($fsDir) ) {
1337                      Error("Rmdir failed", $tstr . $fsDir) ;                      Error("Rmdir failed", $tstr . $fsDir) ;
1338                    }                    }
1339                    else {                    else {
# Line 1138  function MoveTo($source,$folder) { Line 1352  function MoveTo($source,$folder) {
1352                  MoveTo("$fsDir/.del/$file","$fsDir/");                  MoveTo("$fsDir/.del/$file","$fsDir/");
1353                  MoveTo("$fsDir/.del/.log/$file","$fsDir/.log/");                  MoveTo("$fsDir/.del/.log/$file","$fsDir/.log/");
1354                  MoveTo("$fsDir/.del/.note/$file","$fsDir/.note/");                  MoveTo("$fsDir/.del/.note/$file","$fsDir/.note/");
1355                    MoveTo("$fsDir/.del/.lock/$file","$fsDir/.lock/");
1356    
1357                  break ;                  break ;
1358    
# Line 1145  function MoveTo($source,$folder) { Line 1360  function MoveTo($source,$folder) {
1360                  if ( $CONFIRM != "on" ) break ;                  if ( $CONFIRM != "on" ) break ;
1361    
1362                  Logit("$fsDir/$FN","renamed $FN to $NEWNAME");                  Logit("$fsDir/$FN","renamed $FN to $NEWNAME");
1363                  rename("$fsDir/$FN","$fsDir/$NEWNAME");                  safe_rename("$fsDir/$FN","$fsDir/$NEWNAME");
1364                  rename("$fsDir/.log/$FN","$fsDir/.log/$NEWNAME");                  safe_rename("$fsDir/.log/$FN","$fsDir/.log/$NEWNAME");
1365                    safe_rename("$fsDir/.note/$FN","$fsDir/.note/$NEWNAME");
1366                    safe_rename("$fsDir/.lock/$FN","$fsDir/.lock/$NEWNAME");
1367                    for($i=0;$i<=$GLOBALS[gblNumBackups];$i++) {
1368                            safe_rename("$fsDir/.bak/$i/$FN","$fsDir/.bak/$i/$NEWNAME");
1369                    }
1370    
1371                  break ;                  break ;
1372    
# Line 1154  function MoveTo($source,$folder) { Line 1374  function MoveTo($source,$folder) {
1374                  WriteNote("$fsDir/$FN","$NOTE");                  WriteNote("$fsDir/$FN","$NOTE");
1375                  break ;                  break ;
1376    
1377            case "UNLOCK" :  
1378                    if ( $CONFIRM != "on" ) break ;
1379                    Unlock("$fsDir/$FN");
1380                    break ;
1381    
1382          default :          default :
1383                  // user hit "CANCEL" or undefined action                  // user hit "CANCEL" or undefined action
1384          }          }
# Line 1169  function MoveTo($source,$folder) { Line 1394  function MoveTo($source,$folder) {
1394          // $A=U : upload to path given in $D          // $A=U : upload to path given in $D
1395          // $A=E : display detail of file $D/$F and edit          // $A=E : display detail of file $D/$F and edit
1396          // $A=C : display code in file $D/$F          // $A=C : display code in file $D/$F
1397            // $A=Co : checkout file $D/$F
1398            // $A=Ci : checkin file $D/$F
1399            // $A=V : view file (do nothing except log)
1400          // default : display directory $D          // default : display directory $D
1401                    
1402          switch ($A) {          switch ($A) {
# Line 1190  function MoveTo($source,$folder) { Line 1418  function MoveTo($source,$folder) {
1418                  // listing of $relDir/$F                  // listing of $relDir/$F
1419                  DisplayCode($gblFsRoot, $relDir, $F) ;                  DisplayCode($gblFsRoot, $relDir, $F) ;
1420                  exit ;                  exit ;
1421            case "Co" :
1422                    // checkout
1423                    Lock("$gblFsRoot/$relDir/$F");
1424                    header("Content-Disposition: attachment; filename=$F" );
1425                    Header("Location: ".urlpath("$relDir/$F"));
1426                    exit;
1427            case "Ci" :
1428                    // upload && update to $relDir
1429                    if (!is_writeable($gblFsRoot . $relDir))
1430                            Error("Write access denied",$relDir) ;
1431                    $text  = "Use this page to update a single " ;
1432                    $text .= "file to <B>$SERVER_NAME</B>." ;
1433                    StartHTML("(Update file Page)", $text) ;
1434                    UploadPage($gblFsRoot, $relDir, $F) ;
1435                    EndHTML() ;
1436                    exit ;
1437            case "V" :
1438                    // view
1439                    LogIt("$gblFsRoot/$relDir/$F","viewed");
1440                    header("Content-Disposition: attachment; filename=$F" );
1441                    Header("Location: ".urlpath("$relDir/$F"));
1442                    exit;
1443            case "Ch" :
1444                    StartHTML("(File changes)","All changes chronologicaly...");
1445                    DisplayChangeLog(0);    // all
1446                    EndHTML() ;
1447                    exit;
1448            case "Ch1" :
1449                    StartHTML("(File changes)","Changes to files in last day...");
1450                    DisplayChangeLog(1);
1451                    EndHTML() ;
1452                    exit;
1453          }          }
1454    
1455          // default: display directory $relDir          // default: display directory $relDir

Legend:
Removed from v.1.4  
changed lines
  Added in v.1.18

  ViewVC Help
Powered by ViewVC 1.1.26