/[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.5 by dpavlin, Thu Aug 3 22:02:03 2000 UTC revision 1.37 by dpavlin, Mon Mar 12 13:30:44 2001 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 59  IMPORTANT INSTALLATION NOTE: Line 51  IMPORTANT INSTALLATION NOTE:
51          deleted files!          deleted files!
52    
53          .htusers is in form:          .htusers is in form:
54          login:Real Name:md5(loginpassword)          login:Real Name:[md5(loginpassword)|auth_*]:email@host.dom
55    
56    
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    
78            // from where to include auth_*.php modules?
79            $gblIncDir = "/home/httpd/docman";
80    
81          // username/password should not be system          // username/password should not be system
82          // usernames/passwords !!          // usernames/passwords !!
83    
 //      $gblPw    = "hash_of_your_username_and_password" ;  
   
 //      $gblAuth  = false ;             // use builtin authentication  
         $gblAuth  = true ;             // use builtin authentication  
         $gblHash  = "md5" ;             // hash function to use  
   
84          $gblPw    = "";          $gblPw    = "";
85    
86          if ($gblAuth) {          // date format
                 $htusers_file=dirname($SCRIPT_FILENAME)."/.htusers";  
                 if (! file_exists($htusers_file)) {  
                         $htusers=fopen($htusers_file,"a+");  
                         fputs($htusers,"# Change owner of $htusers_file to root !!\n");  
                         fputs($htusers,"demo:full name:md5_hash\n");  
                         fclose($htusers);  
                 }  
                 $htusers=fopen($htusers_file,"r");  
                 while($user = fgetcsv($htusers,255,":")) {  
                         if ($user[0] == $GLOBALS["PHP_AUTH_USER"]) {  
                                 $gblUserName=$user[1];  
                                 $gblPw=$user[2];  
                                 continue ;  
                         }  
                 }  
                 fclose($htusers);  
         }  
   
87  //      $gblDateFmt="D, F d, Y";  //      $gblDateFmt="D, F d, Y";
 //      $gblTimeFmt="g:i:sA";  
   
88          $gblDateFmt="Y-m-d";          $gblDateFmt="Y-m-d";
89    
90            // time format
91    //      $gblTimeFmt="g:i:sA";
92          $gblTimeFmt="H:i:s";          $gblTimeFmt="H:i:s";
93    
94  // Number of backup files to keep          // Number of backup files to keep
95          $gblNumBackups=5;          $gblNumBackups=3;
96    
97            // show red star if newer than ... days
98            $gblModDays=1;
99    
100          // choose GifIcon below unless you have the M$          // choose GifIcon below unless you have the M$
101          // WingDings font installed on your system          // WingDings font installed on your system
102    
103          $gblIcon = "GifIcon" ;          // MockIcon or GifIcon          $gblIcon="GifIcon";             // MockIcon or GifIcon
104    
105          // the directory below should be /icons/ or /icons/small/          // the directory below should be /icons/ or /icons/small/
106          // on Apache; a set of icons is included in the distribution          // on Apache; a set of icons is included in the distribution
107    
108          $gblIconLocation = "/icons/" ;          $gblIconLocation="/icons/";
109    
110          // files you want to be able to edit in text mode          // files you want to be able to edit in text mode
111          // and view with (primitive) syntax highlighting          // and view with (primitive) syntax highlighting
# Line 150  TODO: Line 124  TODO:
124    
125  function StartHTML($title,$text="") {  function StartHTML($title,$text="") {
126    
127          $title = "Site Manager " . $title ;          $title = "Document Manager " . $title ;
128          $host  = $GLOBALS["HTTP_HOST"] ;          $host  = $GLOBALS["HTTP_HOST"] ;
129          $self  = $GLOBALS["PHP_SELF"] ;          $self  = $GLOBALS["PHP_SELF"] ;
130  ?>  ?>
# Line 184  function EndHTML() { Line 158  function EndHTML() {
158  <B><?= date($GLOBALS[gblDateFmt]) ?> -  <B><?= date($GLOBALS[gblDateFmt]) ?> -
159  <?= date($GLOBALS[gblTimeFmt]) ?> -  <?= date($GLOBALS[gblTimeFmt]) ?> -
160  <?= $GLOBALS[gblUserName] ?>  <?= $GLOBALS[gblUserName] ?>
161  <small> [<a href="<?= $PHP_SELF ?>?relogin=<?= $GLOBALS[gblPw] ?>">logout</a>]</small>  <small> [<a href="<?= $GLOBALS["PHP_SELF"] ?>?relogin=<?= $GLOBALS[gblPw] ?>">logout</a>]</small>
162  </B>  </B>
163  <BR>ANYPORTAL(php) Site Manager  <BR>ANYPORTAL(php) Site Manager
164  <br><small>  <br><small>
# Line 194  function EndHTML() { Line 168  function EndHTML() {
168  </small>  </small>
169  </P>  </P>
170  <BR>  <BR>
171  <? include(".debug.inc") ?>  <? //include(".debug.inc") ?>
172  <BR><BR></BODY></HTML>  <BR><BR></BODY></HTML>
173    
174  <?php  <?php
# Line 229  A:HOVER { color:red; } Line 203  A:HOVER { color:red; }
203    
204  function DetailPage($fsRoot,$relDir,$fn) {  function DetailPage($fsRoot,$relDir,$fn) {
205                    
206          global $gblEditable, $gblImages ;          global $gblEditable, $gblImages, $webRoot ;
207          $self = $GLOBALS["PHP_SELF"] ;          $self = $GLOBALS["PHP_SELF"] ;
208    
209          $relPath  = $relDir . "/" . $fn ;          $relPath  = $relDir . "/" . $fn ;
# Line 240  function DetailPage($fsRoot,$relDir,$fn) Line 214  function DetailPage($fsRoot,$relDir,$fn)
214          $ext      = strtolower(strrchr($relPath,".")) ;          $ext      = strtolower(strrchr($relPath,".")) ;
215          $editable = ( $ext=="" || strstr(join(" ",$gblEditable),$ext)) ;          $editable = ( $ext=="" || strstr(join(" ",$gblEditable),$ext)) ;
216          $writable = is_writeable($fsPath) ;          $writable = is_writeable($fsPath) ;
217            $file_lock = CheckLock($fsPath);
218    
219          if (!$editable && !$exists)          if (!$editable && !$exists)
220                  Error("Creation unsupported for type",$relPath) ;                  Error("Creation unsupported for type",$relPath) ;
# Line 247  function DetailPage($fsRoot,$relDir,$fn) Line 222  function DetailPage($fsRoot,$relDir,$fn)
222                  Error("Creation denied",$relDir) ;                  Error("Creation denied",$relDir) ;
223    
224          $text  = "Use this page to view, modify or " ;          $text  = "Use this page to view, modify or " ;
225          $text .= "delete a single document on this " ;          if (is_dir($fsPath)) {
226                    $text .="delete a directory on this " ;
227            } else {
228                    $text .= "delete a single document on this " ;
229            };
230          $text .= "web site." ;            $text .= "web site." ;  
231          $title = "(Detail Page)" ;          $title = "(Detail Page)" ;
232          StartHTML($title, $text) ;          StartHTML($title, $text) ;
# Line 257  function DetailPage($fsRoot,$relDir,$fn) Line 236  function DetailPage($fsRoot,$relDir,$fn)
236                  $fsize = filesize($fsPath) ;                  $fsize = filesize($fsPath) ;
237                  $fmodified = date("$GLOBALS[gblDateFmt] $GLOBALS[gblTimeFmt]", filemtime($fsPath)) ;                  $fmodified = date("$GLOBALS[gblDateFmt] $GLOBALS[gblTimeFmt]", filemtime($fsPath)) ;
238                  $faccessed = date("$GLOBALS[gblDateFmt] $GLOBALS[gblTimeFmt]", fileatime($fsPath)) ;                  $faccessed = date("$GLOBALS[gblDateFmt] $GLOBALS[gblTimeFmt]", fileatime($fsPath)) ;
239                  echo "<PRE>    file size: " . $fsize . " Bytes<BR>" ;                  $fuid=fileowner($fsPath);
240                    $fgid=filegroup($fsPath);
241                    $userinfo = posix_getpwuid($fuid);
242                    $grpinfo = posix_getgrgid($fgid);
243                    echo "<PRE>";
244                    if (!is_dir($fsPath)) echo "    file size: " . $fsize . " Bytes<BR>" ;
245                  echo "last modified: <B>" . $fmodified . "</B><BR>" ;                  echo "last modified: <B>" . $fmodified . "</B><BR>" ;
246                  echo "last accessed: <B>" . $faccessed . "</B><BR>" ;                  echo "last accessed: <B>" . $faccessed . "</B><BR>" ;
247                  echo "        owner: <B>" . fileowner($fsPath) . "</B><BR>" ;                  echo "        owner: <B>" . $userinfo["name"] . " [$fuid]</B><BR>" ;
248                  echo "        group: <B>" . filegroup($fsPath) . "</B><BR>" ;                  echo "        group: <B>" . $grpinfo["name"] . " [$fgid]</B><BR>" ;
249                  echo "  permissions: <B>" ;                  echo "  permissions: <B>" ;
250                  echo printf( "%o", fileperms($fsPath) ) . "</B>" ;                  echo printf( "%o", fileperms($fsPath) ) . "</B>" ;
251                  echo "</PRE>" ;                  echo "</PRE>" ;
252    
253          }          }
254    
255          if ( $editable && ($writable || !$exists) ) {          if ( !is_dir($fsPath) && $editable && ($writable || !$exists) && !$file_lock ) {
256                  $fh = fopen($fsPath,"a+") ;                  $fh = fopen($fsPath,"a+") ;
257                  rewind($fh) ;                  rewind($fh) ;
258                  $fstr = fread($fh,filesize($fsPath)) ;                  $fstr = fread($fh,filesize($fsPath)) ;
# Line 294  echo($fstr) ; ?></TEXTAREA> Line 278  echo($fstr) ; ?></TEXTAREA>
278    
279  <?php  <?php
280          }          }
281          else if ( strstr( join(" ",$gblImages), $ext ) ) {            if ( !$file_lock && $ext!="" && strstr(join(' ',$gblImages),$ext) ) {  
282            $info  = getimagesize($fsPath) ;                  $info  = getimagesize($fsPath) ;
283            $tstr  = "<IMG SRC=\"". $relPath . "\" BORDER=0 " ;                  $tstr = "<IMG SRC=\"$webRoot".urlpath($relPath)."\" BORDER=0 " ;
284            $tstr .= $info[3] . " ALT=\"" . $fn . " - " ;                  $tstr .= $info[3] . " ALT=\"" . $fn . " - " ;
285            $tstr .= (int)(($fsize+1023)/1024) . "Kb\">" ;                  $tstr .= (int)(($fsize+1023)/1024) . "Kb\">" ;
286            echo htmlentities($tstr) . "<BR><BR>" . $tstr ;  //              echo htmlentities($tstr) . "<BR><BR>" . $tstr ;
287                    echo $tstr ;
288          }          }
289    
290  ?>  ?>
291    
292  <FORM ACTION="<?= $self ; ?>" METHOD="POST">  <FORM ACTION="<?= $self ; ?>" METHOD="POST">
# Line 309  echo($fstr) ; ?></TEXTAREA> Line 295  echo($fstr) ; ?></TEXTAREA>
295  <INPUT TYPE="SUBMIT" NAME="POSTACTION" VALUE="CANCEL"><BR>  <INPUT TYPE="SUBMIT" NAME="POSTACTION" VALUE="CANCEL"><BR>
296    
297  <?php  <?php
298    
299            if ($file_lock) {
300    ?>
301    <hr>
302    <SPAN TITLE="Check OK and click UNLOCK to remove lock on file.">
303    <B>OK TO FORCE LOCK REMOVAL ON "<?= $fn ; ?>" HELD BY <?= $file_lock ?>? </B></SPAN>
304    <INPUT TYPE="CHECKBOX" NAME="CONFIRM">
305    <INPUT TYPE="SUBMIT" NAME="POSTACTION" VALUE="UNLOCK">
306    <?
307            } // file_lock
308    
309          if (substr($fn,0,4) == ".del") {          if (substr($fn,0,4) == ".del") {
310                  $action="UNDELETE";                  $action="UNDELETE";
311                  $desc="undelete previously deleted file";                  $desc="undelete previously deleted file";
# Line 349  echo($fstr) ; ?></TEXTAREA> Line 346  echo($fstr) ; ?></TEXTAREA>
346  </FORM>  </FORM>
347    
348  <?php  <?php
           
349    
350          $logname=dirname("$fsDir/$fn")."/.log/".basename("$fsDir/$fn");          $name=basename("$fsDir/$fn");
351            $logname=dirname("$fsDir/$fn")."/.log/$name";
352            $bakdir=dirname("$fsDir/$fn")."/.bak";
353          if (file_exists($logname)) {          if (file_exists($logname)) {
                 print "<hr><br><b>CHANGES TO THIS FILE</b><br><table border=0 width=100%>\n";  
354                  $log=fopen($logname,"r");                  $log=fopen($logname,"r");
355                  $cl1=" class=lst"; $cl2="";                  $cl1=" class=LST"; $cl2="";
356                    $logarr = array();
357                  while($line = fgetcsv($log,255,"\t")) {                  while($line = fgetcsv($log,255,"\t")) {
358                          $cl=$cl1; $cl1=$cl2; $cl2=$cl;                          $cl=$cl1; $cl1=$cl2; $cl2=$cl;
359                          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]));
360                  }                  }
361                  fclose($log);                  fclose($log);
362                    if (is_dir("$fsDir/$fn")) {
363                            $whatis="DIRECTORY";
364                    } else {
365                            $whatis="FILE";
366                    }
367                    print "<hr><br><b>CHANGES TO THIS $whatis</b><br><table border=0 width=100%>\n";
368                    $bakcount = 0;  // start from 0, skip fist backup (it's current)
369                    while ($e = array_shift($logarr)) {
370                            if (strstr($e[4],"upload")) {
371                                    if (file_exists("$bakdir/$bakcount/$name")) {
372                                            $e[4]="<a href=\"$webRoot".urlpath(dirname($relPath)."/.bak/$bakcount/$name")."\">$e[4]</a>";
373                                    }
374                                    $bakcount++;
375                            }
376                            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";
377                    }
378                  print "</table>";                  print "</table>";
379          }          }
380    
# Line 594  function GifIcon($txt) { Line 608  function GifIcon($txt) {
608                  $d = "blank.gif" ;                  $d = "blank.gif" ;
609                  break ;                  break ;
610          case "checkout":          case "checkout":
611                  $d = "down.gif";                  $d = "box2.gif";
612                  break;                  break;
613          case "checkin":          case "checkin":
614                  $d = "up.gif";                  $d = "hand.up.gif";
615                    break;
616            case "locked":
617                    $d = "screw2.gif";
618                  break;                  break;
619          case "note":          case "note":
620                  $d = "quill.gif";                  $d = "quill.gif";
# Line 613  function GifIcon($txt) { Line 630  function GifIcon($txt) {
630    
631  function Navigate($fsRoot,$relDir) {  function Navigate($fsRoot,$relDir) {
632    
633          global $gblEditable, $gblIcon ;          global $gblEditable, $gblIcon, $gblModDays, $webRoot ;
634    
635          $self     = $GLOBALS["PHP_SELF"] ;          $self     = $GLOBALS["PHP_SELF"] ;
636          if (isset($GLOBALS["HTTPS"]) && $GLOBALS["HTTPS"] == "on") {  
637                  $webRoot  = "https://" . $GLOBALS["SERVER_NAME"] ;          $fsDir = $fsRoot . $relDir . "/" ; // current directory
         } else {  
                 $webRoot  = "http://" . $GLOBALS["SERVER_NAME"] ;  
         }  
         $fsDir    = $fsRoot . $relDir . "/" ; // current directory  
638    
639          if (!is_dir($fsDir)) Error("Dir not found",$relDir) ;          if (!is_dir($fsDir)) Error("Dir not found",$relDir) ;
640    
# Line 659  function Navigate($fsRoot,$relDir) { Line 672  function Navigate($fsRoot,$relDir) {
672          // start navigation page          // start navigation page
673          $text  = "Use this page to add, delete";          $text  = "Use this page to add, delete";
674          if (! isset($show_deleted)) {          if (! isset($show_deleted)) {
675                  $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>";
676          }          }
677          $text .= " or revise files on this web site." ;          $text .= " or revise files on this web site." ;
678            $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>.";
679          StartHTML("(Navigate)",$text) ;          StartHTML("(Navigate)",$text) ;
680    
681          echo "<TABLE BORDER=0 CELLPADDING=2          echo "<TABLE BORDER=0 CELLPADDING=2
# Line 685  function Navigate($fsRoot,$relDir) { Line 699  function Navigate($fsRoot,$relDir) {
699                  sort($dirList) ;                  sort($dirList) ;
700  ?>  ?>
701    
702  <TR><TD></TD><TD COLSPAN=5 CLASS=TOP><HR>DIRECTORY NAME</TD></TR>  <TR><TD></TD><TD COLSPAN=2 CLASS=TOP>DIRECTORY NAME</TD><TD COLSPAN=3 CLASS=TOP>DIRECTORY NOTE</TR>
703    
704  <?php  <?php
705                  while (list($key,$dir) = each($dirList)) {                  while (list($key,$dir) = each($dirList)) {
706    
707                            $info_url=$self."?A=E&F=".urlencode($dir)."&D=".urlencode($relDir);
708                          $tstr = "<A HREF=\"" . $self . "?D=" ;                          $tstr = "<A HREF=\"" . $self . "?D=" ;
709                          $tstr .= urlencode($relDir."/".$dir) ;                          $tstr .= urlencode($relDir."/".$dir) ;
710                          $tstr .= "\">" . $dir . "/</A>" ;                          $tstr .= "\">" . $dir . "/</A>" ;
711                            $note_html="<a href=\"$info_url#note\">".$gblIcon("note")."</a>".ReadNote($fsDir.$dir);
712  ?>  ?>
713    
714  <TR><TD><?= $gblIcon("fldr") ?></TD>  <TR><TD>
715  <TD COLSPAN=5 CLASS=LST><?= $tstr ?></TD></TR>  <A HREF="<?= $info_url ?>" TITLE="View/Edit">
716    <?= $gblIcon("fldr") ?></A></TD>
717    <TD COLSPAN=2 CLASS=LST><?= $tstr ?></TD>
718    <TD COLSPAN=3 CLASS=LST><?= $note_html ?></TD></TR>
719    
720  <?php  <?php
721                  }  // iterate over dirs                  }  // iterate over dirs
# Line 706  function Navigate($fsRoot,$relDir) { Line 725  function Navigate($fsRoot,$relDir) {
725  <TR><TD></TD><TD COLSPAN=5><HR><B><?= $webRoot . $relDir ?>  <TR><TD></TD><TD COLSPAN=5><HR><B><?= $webRoot . $relDir ?>
726  </B></TD></TR>  </B></TD></TR>
727  <TR><TD></TD><TD CLASS=TOP>DOCUMENT NAME</TD>  <TR><TD></TD><TD CLASS=TOP>DOCUMENT NAME</TD>
728  <TD><?= $gblIcon("blank") ?></TD>  <TD><?= $gblIcon("blank").$gblIcon("blank") ?></TD>
729  <TD CLASS=TOP>NOTE</TD>  <TD CLASS=TOP>NOTE</TD>
730  <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>
731    
# Line 728  function Navigate($fsRoot,$relDir) { Line 747  function Navigate($fsRoot,$relDir) {
747    
748                  $info_url=$self."?A=E&F=".urlencode($file)."&D=".urlencode($relDir);                  $info_url=$self."?A=E&F=".urlencode($file)."&D=".urlencode($relDir);
749    
750                  if ( ($mod + 30*86400) > time() ) {                  if ( ($mod + $gblModDays*86400) > time() ) {
751                          $a  = "<SPAN CLASS=RED TITLE=\"Newer" ;                          $a  = "<SPAN CLASS=RED TITLE=\"Newer" ;
752                          $a .= " than 30 days\"> * </SPAN>" ;                          $a .= " than $gblModDays days\"> * </SPAN>" ;
753                  }                  }
754    
755                  $tstr = $webRoot . $relDir . "/" . $file ;                  $file_lock=CheckLock($path);
756                  $tstr  = "<A HREF=\"" . $tstr . "\">" ;  
757                    $file_url_html="<A HREF=\"$self?A=V&F=".urlencode($file);
758                    $file_url_html.="&D=".urlencode($relDir);
759                    $file_url_html.="\" TITLE=\"View file\">" ;
760    
761                  if (substr($file,0,5) != ".del/") {                  if (substr($file,0,5) != ".del/") {
762                          $tstr .= $file . "</A>" . $a ;                          $file_url_html .= $file . "</A>" . $a ;
763                  } else {                  } else {
764                          $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>";
765                  }                  }
766    
767  //              $b = $gblIcon("checkout");                  $note_html="<a href=\"$info_url#note\">".$gblIcon("note")."</a>".ReadNote($path);
 //              $b .= $gblIcon("checkin");  
768    
769                  $ext = strtolower(strrchr($file,".")) ;                  $ext = strtolower(strrchr($file,".")) ;
770                  if ( $ext=="" || strstr(join(" ",$gblEditable),$ext) ) {    
771                          $b .= "<A HREF=\"" . $self . "?A=C&F=" ;                  if ($file_lock) {
772                          $b .= urlencode($file) . "&D=" . urlencode($relDir) ;                          if ($file_lock == $GLOBALS[gblUserName]) {
773                          $b .= "\" TITLE=\"List contents\">" ;                                  $b.="<A HREF=\"$self?A=Ci&F=".urlencode($file);
774                          $b .= $gblIcon("view") . "</A>" ;                                  $b.="&D=".urlencode($relDir);
775                                    $b.="\" TITLE=\"Checkin (update) file on server\">" ;
776                                    $file_url_html=$b;
777                                    $b.=$gblIcon("checkin")."</A>" ;
778                                    $b.= $gblIcon("blank");
779                                    $file_url_html.="$file</a> $a";
780                                    $note_html = $gblIcon("blank")."<b>Please check-in (update) this file</b>";
781                            } else {
782                                    $b = $gblIcon("locked");
783                                    $b.= $gblIcon("blank");
784                                    $note_html = $gblIcon("blank")."<b>File locked by $file_lock</b>";
785                                    $file_url_html = "$file $a";
786                            }
787                  } else {                  } else {
788                          $b .= $gblIcon("blank");                          $b.="<A HREF=\"$self?A=Co&F=".urlencode($file);
789                            $b.="&D=".urlencode($relDir);
790                            $b.="\" TITLE=\"Checkout file for edit\">" ;
791                            $b.=$gblIcon("checkout")."</A>" ;
792    
793                            if ( $ext=="" || strstr(join(" ",$gblEditable),$ext) ) {  
794                                    $b.="<A HREF=\"$self?A=C&F=".urlencode($file);
795                                    $b.="&D=".urlencode($relDir);
796                                    $b.="\" TITLE=\"List contents\">" ;
797                                    $b.=$gblIcon("view")."</A>" ;
798                            } else {
799                                    $b.= $gblIcon("blank");
800                            }
801                  }                  }
802    
803    
# Line 761  function Navigate($fsRoot,$relDir) { Line 806  function Navigate($fsRoot,$relDir) {
806  <TR><TD>  <TR><TD>
807  <A HREF="<?= $info_url ?>" TITLE="View/Edit">  <A HREF="<?= $info_url ?>" TITLE="View/Edit">
808  <?= $gblIcon($ext) ?></A></TD>  <?= $gblIcon($ext) ?></A></TD>
809  <TD CLASS=LST><?= $tstr ?></TD>  <TD CLASS=LST><?= $file_url_html ?></TD>
810  <TD CLASS=LST ALIGN=center><?= $b ?></TD>  <TD CLASS=LST ALIGN=center><?= $b ?></TD>
811  <TD CLASS=LST ALIGN=left><a href="<?= $info_url ?>#note"><?= $gblIcon("note") ?></a><?= ReadNote($path) ?></TD>  <TD CLASS=LST ALIGN=left><?= $note_html ?></TD>
812  <TD CLASS=LST><?= date("$GLOBALS[gblDateFmt] $GLOBALS[gblTimeFmt]",$mod) ?></TD>  <TD CLASS=LST><?= date("$GLOBALS[gblDateFmt] $GLOBALS[gblTimeFmt]",$mod) ?></TD>
813  <TD CLASS=LST><?= $sz ?>Bytes</TD></TR>  <TD CLASS=LST><?= $sz ?>Bytes</TD></TR>
814    
815  <?php  <?php
816            }  // iterate over files            }  // iterate over files
817          }  // end if no files          } else {  // end if no files
818    ?>
819     <TR><TD></TD><TD COLSPAN=5 CLASS=LST>
820      No files in this directory
821     </TD></TR>
822    <?
823            }
824    
825          if ($emptyDir) {          if ($emptyDir) {
826  ?>  ?>
# Line 789  function Navigate($fsRoot,$relDir) { Line 840  function Navigate($fsRoot,$relDir) {
840    
841  <TR><TD></TD><TD COLSPAN=5><HR></TD></TR>  <TR><TD></TD><TD COLSPAN=5><HR></TD></TR>
842    
843    <?
844    if (file_exists(".info.inc")) {
845            print "<TR><TD></TD><TD COLSPAN=5>";
846            include(".info.inc");
847            print "</TD></TR>
848            <TR><TD></TD><TD COLSPAN=5><HR></TD></TR>";
849    }
850    ?>
851    
852  <FORM METHOD="POST" ACTION="<?= $self ?>">  <FORM METHOD="POST" ACTION="<?= $self ?>">
853  <TR><TD></TD><TD COLSPAN=5 CLASS=BAR>CREATE NEW  <TR><TD></TD><TD COLSPAN=5 CLASS=BAR>CREATE NEW
854   <INPUT TYPE="RADIO" NAME="T" VALUE="D" CHECKED>DIRECTORY -OR-   <INPUT TYPE="RADIO" NAME="T" VALUE="D" CHECKED>DIRECTORY -OR-
# Line 797  function Navigate($fsRoot,$relDir) { Line 857  function Navigate($fsRoot,$relDir) {
857   <INPUT TYPE="HIDDEN" NAME="POSTACTION" VALUE="CREATE">   <INPUT TYPE="HIDDEN" NAME="POSTACTION" VALUE="CREATE">
858   <INPUT TYPE="HIDDEN" NAME="DIR" VALUE="<?= $relDir ?>">   <INPUT TYPE="HIDDEN" NAME="DIR" VALUE="<?= $relDir ?>">
859   <INPUT TYPE="SUBMIT" VALUE="CREATE"></NOBR>   <INPUT TYPE="SUBMIT" VALUE="CREATE"></NOBR>
860   <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  
861   </NOBR>   </NOBR>
862  </TD></TR>  </TD></TR>
863  </FORM>  </FORM>
# Line 810  function Navigate($fsRoot,$relDir) { Line 869  function Navigate($fsRoot,$relDir) {
869    
870  //////////////////////////////////////////////////////////////////  //////////////////////////////////////////////////////////////////
871    
872  function UploadPage($fsRoot, $relDir) {  function UploadPage($fsRoot, $relDir, $filename="") {
873    
874          $self = $GLOBALS["PHP_SELF"] ;          $self = $GLOBALS["PHP_SELF"] ;
875          if ($relDir == "") $relDir = "/" ;          if ($relDir == "") $relDir = "/" ;
# Line 820  function UploadPage($fsRoot, $relDir) { Line 879  function UploadPage($fsRoot, $relDir) {
879  <FORM ENCTYPE="multipart/form-data" METHOD="POST"  <FORM ENCTYPE="multipart/form-data" METHOD="POST"
880   ACTION="<?= $self ?>">   ACTION="<?= $self ?>">
881  DESTINATION DIRECTORY:<B><?= " " . $relDir ?></B>  DESTINATION DIRECTORY:<B><?= " " . $relDir ?></B>
882    <? if (isset($filename) && $filename!="") { ?>
883    <br>DESTINATION FILE:<B><?= " " . $filename ?></B>
884    <INPUT TYPE="HIDDEN" NAME="FILENAME" VALUE="<?= $filename ?>">
885    <? } ?>
886  <P>PATHNAME OF LOCAL FILE<BR>  <P>PATHNAME OF LOCAL FILE<BR>
887  <INPUT TYPE="HIDDEN" NAME="DIR" VALUE="<?= $relDir ?>">  <INPUT TYPE="HIDDEN" NAME="DIR" VALUE="<?= $relDir ?>">
888  <INPUT TYPE="HIDDEN" NAME="POSTACTION" VALUE="UPLOAD">  <INPUT TYPE="HIDDEN" NAME="POSTACTION" VALUE="UPLOAD">
# Line 851  function Error($title,$text="") { Line 914  function Error($title,$text="") {
914    
915  //////////////////////////////////////////////////////////////////  //////////////////////////////////////////////////////////////////
916    
 function CreateHash($user, $pw) {  
   
         global $gblHash ;  // hash function to use  
   
         if ($user == "" || $pw == "") {  
                 $text = "either no password or no username supplied" ;  
                 Error("Create Hash",$text) ;  
         }  
         $title = "(Create Hash)" ;  
         StartHTML($title) ;  
         echo "<P ALIGN=center>" ;  
         echo "<BLOCKQUOTE>Copy the value below and paste it " ;  
         echo "into the<BR>value for \$gblPw in the source of " ;  
         echo "this file<BR><BR><B>" . $gblHash($user.$pw) ;  
         echo "</B><BR><BR>Hash function: " . $gblHash ;  
         echo "</BLOCKQUOTE></P>" ;  
         EndHTML() ;  
         exit ;  
   
 } // end function CreateHash  
   
 //////////////////////////////////////////////////////////////////  
   
917  function NoEntry() {  function NoEntry() {
918    
919          $user = $GLOBALS["PHP_AUTH_USER"] ;          $user = $GLOBALS["PHP_AUTH_USER"] ;
# Line 883  function NoEntry() { Line 923  function NoEntry() {
923          $title = "(401 Unauthorized)" ;          $title = "(401 Unauthorized)" ;
924          $text  = "No trespassing !" ;          $text  = "No trespassing !" ;
925          StartHTML($title,$text) ;          StartHTML($title,$text) ;
 ?>  
   
 <FORM ACTION="<?= $self ?>?HASH=create" METHOD="POST">  
 <INPUT TYPE="HIDDEN" NAME="USER" VALUE="<?= $user ?>">  
 <INPUT TYPE="HIDDEN" NAME="PW" VALUE="<?= $pw ?>">  
   
 <BLOCKQUOTE><B>If you are a site administrator:</B><BR><BR>  
 Click below to <B>generate a password hash</B><BR>from  
 the username-password pair you just<BR>entered. Then include the hash in  
 the source<BR>of this file.<BR><BR>  
 <INPUT TYPE="SUBMIT" VALUE="CREATE HASH">  
 </BLOCKQUOTE></FORM>  
926    
 <?php  
927          EndHTML() ;          EndHTML() ;
928          exit ;          exit ;
929  }  }
930    
931  //////////////////////////////////////////////////////////////////  //////////////////////////////////////////////////////////////////
932    
933  function Logit($target,$msg) {  function LogIt($target,$msg) {
934    
935          $dir=dirname($target);          $dir=dirname($target);
936          if (! file_exists($dir."/.log")) {          if (! file_exists($dir."/.log")) {
# Line 923  function Logit($target,$msg) { Line 950  function Logit($target,$msg) {
950    
951  function WriteNote($target,$msg) {  function WriteNote($target,$msg) {
952    
953            $target=stripSlashes($target);
954          $dir=dirname($target);          $dir=dirname($target);
955          if (! file_exists($dir."/.note")) {          if (! file_exists($dir."/.note")) {
956                  mkdir($dir."/.note",0700);                  mkdir($dir."/.note",0700);
# Line 939  function WriteNote($target,$msg) { Line 967  function WriteNote($target,$msg) {
967    
968  function ReadNote($target) {  function ReadNote($target) {
969    
970            $target=stripSlashes($target);
971          $dir=dirname($target);          $dir=dirname($target);
972          $file=basename($target);          $file=basename($target);
973          $msg="";          $msg="";
# Line 947  function ReadNote($target) { Line 976  function ReadNote($target) {
976                  $msg=fgets($note,4096);                  $msg=fgets($note,4096);
977                  fclose($note);                  fclose($note);
978          }          }
979          return $msg;          return StripSlashes($msg);
980    
981  }  }
982    
# Line 955  function ReadNote($target) { Line 984  function ReadNote($target) {
984    
985  function MoveTo($source,$folder) {  function MoveTo($source,$folder) {
986    
987            $source=stripSlashes($source);
988          $file=basename($source);          $file=basename($source);
989          if (! file_exists($folder)) {          if (! file_exists($folder)) {
990                  mkdir($folder,0700);                  mkdir($folder,0700);
# Line 966  function MoveTo($source,$folder) { Line 996  function MoveTo($source,$folder) {
996    
997  //////////////////////////////////////////////////////////////////  //////////////////////////////////////////////////////////////////
998    
999    function Lock($target) {
1000    
1001            $target=stripSlashes($target);
1002            $dir=dirname($target);
1003            if (! file_exists($dir."/.lock")) {
1004                    mkdir($dir."/.lock",0700);
1005            }
1006            $file=basename($target);
1007    
1008            if (file_exists("$dir/.lock/$file")) {
1009                    Logit($target,"attempt to locked allready locked file!");
1010            } else {
1011                    $lock=fopen("$dir/.lock/$file","w");
1012                    fputs($lock,"$GLOBALS[gblUserName]\n");
1013                    fclose($lock);
1014    
1015                    Logit($target,"file locked");
1016            }
1017    
1018    }
1019    
1020    function CheckLock($target) {
1021    
1022            $target=stripSlashes($target);
1023            $dir=dirname($target);
1024            $file=basename($target);
1025            $msg=0;
1026            if (file_exists($dir."/.lock/$file")) {
1027                    $lock=fopen("$dir/.lock/$file","r");
1028                    $msg=fgets($lock,4096);
1029                    fclose($lock);
1030            }
1031            return chop($msg);
1032    
1033    }
1034    
1035    function Unlock($target) {
1036    
1037            $target=stripSlashes($target);
1038            $dir=dirname($target);
1039            $file=basename($target);
1040            if (file_exists($dir."/.lock/$file")) {
1041                    unlink("$dir/.lock/$file");
1042                    Logit($target,"file unlocked");
1043            } else {
1044                    Logit($target,"attempt to unlocked non-locked file!");
1045            }
1046    
1047    }
1048    
1049    //////////////////////////////////////////////////////////////////
1050    
1051    function urlpath($url) {
1052            $url=urlencode(StripSlashes("$url"));
1053            $url=str_replace("%2F","/",$url);
1054            $url=str_replace("+","%20",$url);
1055            return($url);
1056    }
1057    
1058    //////////////////////////////////////////////////////////////////
1059    
1060    function safe_rename($fromdir,$fromfile,$tofile) {
1061            function try_rename($from,$to) {
1062                    print "$from -> $to\n";
1063                    if (file_exists($from) && is_writeable(dirname($to))) {
1064                            rename($from,$to);
1065                    }
1066            }
1067    
1068            function try_dir($todir) {
1069                    if (! file_exists($todir)) {
1070                            mkdir($todir,0700);
1071                    }
1072            }
1073    
1074            $to="$fromdir/$tofile";
1075            $todir=dirname($to);
1076            $tofile=basename($to);
1077    
1078            print "<pre>$fromdir / $fromfile -> $todir / $tofile\n\n";
1079    
1080            try_rename("$fromdir/$fromfile","$todir/$tofile");
1081            try_dir("$todir/.log");
1082            try_rename("$fromdir/.log/$fromfile","$todir/.log/$tofile");
1083            try_dir("$todir/.note");
1084            try_rename("$fromdir/.note/$fromfile","$todir/.note/$tofile");
1085            try_dir("$todir/.lock");
1086            try_rename("$fromdir/.lock/$fromfile","$todir/.lock/$tofile");
1087            try_dir("$todir/.bak");
1088            for($i=0;$i<=$GLOBALS[gblNumBackups];$i++) {
1089                    try_rename("$fromdir/.bak/$i/$fromfile","$todir/.bak/$i/$tofile");
1090            }
1091    }
1092    
1093    
1094    //////////////////////////////////////////////////////////////////
1095    
1096    // recursivly delete directory
1097    
1098    function rrmdir($dir) {
1099            $handle=opendir($dir);
1100            while ($file = readdir($handle)) {
1101                    if ($file != "." && $file != "..") {
1102                            if (is_dir("$dir/$file"))
1103                                    rrmdir("$dir/$file");
1104                            else
1105                                    if (! @unlink("$dir/$file")) return(0);
1106                    }
1107            }
1108            closedir($handle);
1109            return @rmdir($dir);
1110    }
1111    
1112    //////////////////////////////////////////////////////////////////
1113    
1114    function ChangeLog($target,$msg) {
1115    
1116            global $gblFsRoot;
1117            $log=fopen("$gblFsRoot/.changelog","a+");
1118            if (substr($target,0,strlen($gblFsRoot)) == $gblFsRoot)
1119                    $target=substr($target,strlen($gblFsRoot),strlen($target)-strlen($gblFsRoot));
1120            fputs($log,time()."\t$target\t$GLOBALS[gblUserName]\t$msg\n");
1121            fclose($log);
1122    
1123    }
1124    
1125    function DisplayChangeLog($day) {
1126    
1127            global $gblFsRoot;
1128            if (!file_exists("$gblFsRoot/.changelog")) return;
1129            $log=fopen("$gblFsRoot/.changelog","r");
1130            $logarr = array();
1131            while($line = fgetcsv($log,255,"\t")) {
1132                    if ($day!=1 || ($day==1 && (time()-$line[0] < 24*60*60))) {
1133                            array_unshift($logarr,array($line[0],$line[1],$line[2],$line[3]));
1134                    }
1135            }
1136            fclose($log);
1137            $cl1=" class=LST"; $cl2="";
1138            print "<table border=0 width=100%>\n";
1139            while ($e = array_shift($logarr)) {
1140                    $cl=$cl1; $cl1=$cl2; $cl2=$cl;
1141                    $date = date("$GLOBALS[gblDateFmt]", $e[0]);
1142                    $time = date("$GLOBALS[gblTimeFmt]", $e[0]);
1143                    $dir = dirname($e[1]);
1144                    $file = basename($e[1]);
1145                    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";
1146            }
1147            print "</table>";
1148            print "<p>".GifIcon(up)." Back to <a href=$GLOBALS[PHP_SELF]>front page</a>.</p>";
1149    }
1150    
1151    //////////////////////////////////////////////////////////////////
1152    
1153  // MAIN PROGRAM  // MAIN PROGRAM
1154  // ============  // ============
1155  // query parameters: capital letters  // query parameters: capital letters
# Line 981  function MoveTo($source,$folder) { Line 1165  function MoveTo($source,$folder) {
1165          // forks before authentication: style sheet and hash          // forks before authentication: style sheet and hash
1166          // creation if password not yet set.          // creation if password not yet set.
1167          if ($STYLE == "get") { CSS() ; exit ; }          if ($STYLE == "get") { CSS() ; exit ; }
1168          if ($HASH != "") {  
1169                  CreateHash($USER, $PW) ;          $htusers_file=dirname($SCRIPT_FILENAME)."/.htusers";
1170                  exit ;          if (! file_exists($htusers_file)) {
1171                    if (is_writeable(dirname($SCRIPT_FILENAME))) {
1172                            $htusers=fopen($htusers_file,"a+");
1173                            fputs($htusers,"# Change owner of $htusers_file to root !!\n");
1174                            fputs($htusers,"demo:full name:[md5_hash|auth_*]:e-mail\n");
1175                            fclose($htusers);
1176                            Error("Proto user file created!","Please edit <tt>$htusers_file</tt> and set it correct permissions (<B>not writable by web server as it is now!</b>). You can add users using <tt>adduser.pl</tt> script!");
1177                            exit;
1178                    } else {
1179                            Error("Can't create proto user file!","Please make directory <tt>".dirname($htusers_file)."</tt> writable or create <tt>.htusers</tt> file by hand using <tt>adduser.pl</tt> script!");
1180                            exit;
1181                    }
1182            }
1183            $htusers=fopen($htusers_file,"r");
1184            while($user = fgetcsv($htusers,255,":")) {
1185                    if ($user[0] == $GLOBALS["PHP_AUTH_USER"]) {
1186                            $gblUserName=$user[1];
1187                            $gblPw=$user[2];
1188                            if (substr($gblPw,0,5) == "auth_" && file_exists("$gblIncDir/$gblPw.php")) {
1189                                    require("$gblIncDir/$gblPw.php");
1190                                    if ($gblPw($user)) {
1191                                            $gblPw=md5($PHP_AUTH_USER.$PHP_AUTH_PW);
1192                                    } else {
1193                                            $gblPw="error".md5($PHP_AUTH_USER.$PHP_AUTH_PW);
1194                                    }
1195                            }
1196                            $gblEmail=$user[3];
1197                            continue ;
1198                    }
1199          }          }
1200            fclose($htusers);
1201    
1202          // authentication if $gblAuth == true          // authentication failure
1203          if ( $gblAuth && $gblHash($PHP_AUTH_USER.$PHP_AUTH_PW) != $gblPw ||          if ( md5($PHP_AUTH_USER.$PHP_AUTH_PW) != $gblPw ||
1204                  isset($relogin) && $gblPw == $relogin ) {                  isset($relogin) && $gblPw == $relogin ) {
1205                  header("WWW-authenticate: basic realm=\"$SERVER_NAME\"") ;                  header("WWW-authenticate: basic realm=\"$HTTP_HOST\"") ;
1206                  header("HTTP/1.0 401 Unauthorized") ;                  header("HTTP/1.0 401 Unauthorized") ;
1207                  NoEntry() ;                  NoEntry() ;
1208                  exit ;                  exit ;
# Line 1001  function MoveTo($source,$folder) { Line 1214  function MoveTo($source,$folder) {
1214                  $relDir = urldecode($D) ;  // then use GET                  $relDir = urldecode($D) ;  // then use GET
1215          }                }      
1216    
1217            $relDir=stripSlashes($relDir);
1218    
1219          if ($relDir == "/") $relDir = "" ;                if ($relDir == "/") $relDir = "" ;      
1220          // default : website root = ""          // default : website root = ""
1221    
# Line 1012  function MoveTo($source,$folder) { Line 1227  function MoveTo($source,$folder) {
1227          // i.e. below $gblFsRoot.          // i.e. below $gblFsRoot.
1228    
1229          $relScriptDir = dirname($SCRIPT_NAME) ;                  $relScriptDir = dirname($SCRIPT_NAME) ;        
1230          // i.e. /siteman          // i.e. /docman
1231    
1232          $fsScriptDir  = dirname($SCRIPT_FILENAME) ;              $fsScriptDir  = dirname($SCRIPT_FILENAME) ;    
1233          // i.e. /home/httpd/html/siteman          // i.e. /home/httpd/html/docman
1234    
1235          $gblFsRoot = substr($fsScriptDir,0,          // start on server root
1236            strlen($fsScriptDir)-strlen($relScriptDir)) ;  //      $gblFsRoot = substr($fsScriptDir,0, strlen($fsScriptDir)-strlen($relScriptDir)) ;
1237            // or on script root
1238            $gblFsRoot = $fsScriptDir;
1239          // i.e. /home/httpd/html          // i.e. /home/httpd/html
1240    
1241          $fsDir = $gblFsRoot . $relDir ; // current directory          $fsDir = $gblFsRoot . $relDir ; // current directory
1242          if ( !is_dir($fsDir) ) Error("Dir not found",$relDir) ;          if ( !is_dir($fsDir) ) Error("Dir not found",$relDir) ;
1243            
1244            if (isset($GLOBALS["HTTPS"]) && $GLOBALS["HTTPS"] == "on") {
1245                    $webRoot  = "https://";
1246            } else {
1247                    $webRoot  = "http://";
1248            }
1249            $webRoot .= $GLOBALS["HTTP_HOST"] . $relScriptDir;
1250    
1251            $FN=stripSlashes($FN);
1252    
1253          switch ($POSTACTION) {          switch ($POSTACTION) {
1254          case "UPLOAD" :          case "UPLOAD" :
1255                  if (!is_writeable($fsDir)) Error("Write denied",$relDir) ;                  if (!is_writeable($fsDir)) Error("Write denied",$relDir) ;
# Line 1032  function MoveTo($source,$folder) { Line 1258  function MoveTo($source,$folder) {
1258                  // TODO : should rather check for escapeshellcmds                  // TODO : should rather check for escapeshellcmds
1259                  // but maybe RFC 18xx asserts safe filenames ....                  // but maybe RFC 18xx asserts safe filenames ....
1260                  $source = $FN ;                  $source = $FN ;
1261                  $target = $fsDir . "/" . $FN_name ;                  if (! file_exists($source)) {
1262                            Error("You must select file with browse to upload it!");
1263                    }
1264                    if (! isset($FILENAME)) {       // from update file
1265                            $target = "$fsDir/$FN_name" ;
1266                    } else {
1267                            $target = "$fsDir/$FILENAME";
1268                    }
1269    
1270                  // backup old files first                  // backup old files first
1271                  $dir=dirname($target);                  $dir=dirname($target);
# Line 1046  function MoveTo($source,$folder) { Line 1279  function MoveTo($source,$folder) {
1279                  for($i=$GLOBALS[gblNumBackups]-1;$i>0;$i--) {                  for($i=$GLOBALS[gblNumBackups]-1;$i>0;$i--) {
1280                          MoveTo("$dir/.bak/$i/$file","$dir/.bak/".($i+1)."/");                          MoveTo("$dir/.bak/$i/$file","$dir/.bak/".($i+1)."/");
1281                  }                  }
1282                  MoveTo($target,$dir."/.bak/1/".$file);                  MoveTo($target,$dir."/.bak/1/");
1283    
1284                  copy($source,$target) ;                  copy($source,$target) ;
1285                  chmod($target,$gblFilePerms) ;                  chmod($target,$gblFilePerms) ;
1286                  clearstatcache() ;                  clearstatcache() ;
1287                  Logit($target,"uploaded");                  Logit($target,"uploaded");
1288                    if (isset($FILENAME)) {
1289                            Unlock($target);
1290                    }
1291                    ChangeLog($target,"updated");
1292                  break ;                  break ;
1293    
1294          case "SAVE" :          case "SAVE" :
1295                  $path = $gblFsRoot . escapeshellcmd($RELPATH) ;                  $path = $gblFsRoot . $RELPATH ;
1296                    $path=stripSlashes($path);
1297                  $writable = is_writeable($path) ;                  $writable = is_writeable($path) ;
1298                  $legaldir = is_writeable(dirname($path)) ;                  $legaldir = is_writeable(dirname($path)) ;
1299                  $exists   = (file_exists($path)) ? 1 : 0 ;                  $exists   = (file_exists($path)) ? 1 : 0 ;
# Line 1063  function MoveTo($source,$folder) { Line 1301  function MoveTo($source,$folder) {
1301                  if (!($writable || (!$exists && $legaldir)))                  if (!($writable || (!$exists && $legaldir)))
1302                          Error("Write denied",$RELPATH) ;                          Error("Write denied",$RELPATH) ;
1303                  $fh = fopen($path, "w") ;                  $fh = fopen($path, "w") ;
1304                    $FILEDATA=stripSlashes($FILEDATA);
1305                  fwrite($fh,$FILEDATA) ;                  fwrite($fh,$FILEDATA) ;
1306                  fclose($fh) ;                  fclose($fh) ;
1307                  clearstatcache() ;                  clearstatcache() ;
1308                  Logit($path,"saved changes");                  Logit($path,"saved changes");
1309                    ChangeLog($path,"saved changes");
1310                  break ;                  break ;
1311    
1312          case "CREATE" :          case "CREATE" :
# Line 1077  function MoveTo($source,$folder) { Line 1317  function MoveTo($source,$folder) {
1317                  $relPath = $relDir . "/" . $FN ;                  $relPath = $relDir . "/" . $FN ;
1318                  switch ( $T ) {                  switch ( $T ) {
1319                  case "D" :  // create a directory                  case "D" :  // create a directory
1320                    if ( ! @mkdir($path,$gblDirPerms) )                          if ( ! @mkdir($path,$gblDirPerms) )
1321                      Error("Mkdir failed",$relPath) ; // eg. if it exists                                  Error("Mkdir failed",$relPath) ; // eg. if it exists
1322                    clearstatcache() ;                          clearstatcache() ;
1323                    break ;                          break ;
1324                  case "F" :  // create a new file                  case "F" :  // create a new file
1325  // this functionality is doubled in DetailView().  // this functionality is doubled in DetailView().
1326  // better keep it here altogether  // better keep it here altogether
1327  // chmod perms to $gblFilePerms  // chmod perms to $gblFilePerms
1328                    if ( file_exists($path) && !is_writable($path) )                          if ( file_exists($path) && !is_writeable($path) )
1329                      Error("File not writable", $relPath) ;                                  Error("File not writable", $relPath) ;
1330                    $tstr = $PHP_SELF . "?A=E&D=" . $relDir . "&F=" . $FN ;                          $fh = fopen($path, "w+") ;
1331                    header("Location: " . $tstr) ;                          if ($fh) {
1332                    exit ;                                  fputs($fh,"\n");
1333                                    fclose($fh) ;
1334                                    LogIt($path,"file created");
1335                            } else {
1336                                    Error("Creation of file $relPath failed -- $path");
1337                            }
1338                            $tstr = "$PHP_SELF?A=E&D=".urlencode($relDir)."&F=".urlencode($FN) ;
1339                            header("Location: " . $tstr) ;
1340                            ChangeLog($target,"created");
1341                            exit ;
1342                  }                  }
1343                  break ;                  break ;
1344    
# Line 1115  function MoveTo($source,$folder) { Line 1364  function MoveTo($source,$folder) {
1364                                  exit ;                                  exit ;
1365                          } else {                          } else {
1366                                  Logit($path,"file deleted");                                  Logit($path,"file deleted");
                                 if (! file_exists("$dir/.del/.log")) {  
                                         mkdir("$dir/.del/.log",0700);  
                                 }  
1367                                  MoveTo("$dir/.log/$file","$dir/.del/.log/");                                  MoveTo("$dir/.log/$file","$dir/.del/.log/");
1368                                  MoveTo("$dir/.note/$file","$dir/.del/.note/");                                  MoveTo("$dir/.note/$file","$dir/.del/.note/");
1369                                    MoveTo("$dir/.lock/$file","$dir/.del/.lock/");
1370                          }                          }
1371                  }                  }
1372                  else {  // delete directory                  else {  // delete directory
1373                    if ( ! @rmdir($fsDir) ) {                    if ( ! @rrmdir($fsDir) ) {
1374                      Error("Rmdir failed", $tstr . $fsDir) ;                      Error("Rmdir failed", $tstr . $fsDir) ;
1375                    }                    }
1376                    else {                    else {
# Line 1142  function MoveTo($source,$folder) { Line 1389  function MoveTo($source,$folder) {
1389                  MoveTo("$fsDir/.del/$file","$fsDir/");                  MoveTo("$fsDir/.del/$file","$fsDir/");
1390                  MoveTo("$fsDir/.del/.log/$file","$fsDir/.log/");                  MoveTo("$fsDir/.del/.log/$file","$fsDir/.log/");
1391                  MoveTo("$fsDir/.del/.note/$file","$fsDir/.note/");                  MoveTo("$fsDir/.del/.note/$file","$fsDir/.note/");
1392                    MoveTo("$fsDir/.del/.lock/$file","$fsDir/.lock/");
1393    
1394                  break ;                  break ;
1395    
# Line 1149  function MoveTo($source,$folder) { Line 1397  function MoveTo($source,$folder) {
1397                  if ( $CONFIRM != "on" ) break ;                  if ( $CONFIRM != "on" ) break ;
1398    
1399                  Logit("$fsDir/$FN","renamed $FN to $NEWNAME");                  Logit("$fsDir/$FN","renamed $FN to $NEWNAME");
1400                  rename("$fsDir/$FN","$fsDir/$NEWNAME");                  safe_rename($fsDir,$FN,$NEWNAME);
                 rename("$fsDir/.log/$FN","$fsDir/.log/$NEWNAME");  
   
1401                  break ;                  break ;
1402    
1403          case "NOTE" :            case "NOTE" :  
1404                  WriteNote("$fsDir/$FN","$NOTE");                  WriteNote("$fsDir/$FN","$NOTE");
1405                  break ;                  break ;
1406    
1407            case "UNLOCK" :  
1408                    if ( $CONFIRM != "on" ) break ;
1409                    Unlock("$fsDir/$FN");
1410                    break ;
1411    
1412          default :          default :
1413                  // user hit "CANCEL" or undefined action                  // user hit "CANCEL" or undefined action
1414          }          }
# Line 1173  function MoveTo($source,$folder) { Line 1424  function MoveTo($source,$folder) {
1424          // $A=U : upload to path given in $D          // $A=U : upload to path given in $D
1425          // $A=E : display detail of file $D/$F and edit          // $A=E : display detail of file $D/$F and edit
1426          // $A=C : display code in file $D/$F          // $A=C : display code in file $D/$F
1427            // $A=Co : checkout file $D/$F
1428            // $A=Ci : checkin file $D/$F
1429            // $A=V : view file (do nothing except log)
1430          // default : display directory $D          // default : display directory $D
1431            
1432          switch ($A) {          switch ($A) {
1433          case "U" :          case "U" :
1434                  // upload to $relDir                  // upload to $relDir
1435                  if (!is_writeable($gblFsRoot . $relDir))                  if (!is_writeable($gblFsRoot . $relDir))
1436                          Error("Write access denied",$relDir) ;                          Error("Write access denied",$relDir) ;
1437                  $text  = "Use this page to upload a single " ;                  $text  = "Use this page to upload a single " ;
1438                  $text .= "file to <B>$SERVER_NAME</B>." ;                  $text .= "file to <B>$HTTP_HOST</B>." ;
1439                  StartHTML("(Upload Page)", $text) ;                  StartHTML("(Upload Page)", $text) ;
1440                  UploadPage($gblFsRoot, $relDir) ;                  UploadPage($gblFsRoot, $relDir) ;
1441                  EndHTML() ;                  EndHTML() ;
1442                  exit ;                  exit ;
1443          case "E" :          case "E" :
1444                    $F=stripSlashes($F);
1445                  // detail of $relDir/$F                  // detail of $relDir/$F
1446                  if (is_file("$gblFsRoot/$relDir/$F")) DetailPage($gblFsRoot, $relDir, $F) ;                  if (is_file("$gblFsRoot/$relDir/$F") || is_dir("$gblFsRoot/$relDir/$F")) DetailPage($gblFsRoot, $relDir, $F) ;
1447                  exit ;                  exit ;
1448          case "C" :          case "C" :
1449                    $F=stripSlashes($F);
1450                  // listing of $relDir/$F                  // listing of $relDir/$F
1451                  DisplayCode($gblFsRoot, $relDir, $F) ;                  DisplayCode($gblFsRoot, $relDir, $F) ;
1452                  exit ;                  exit ;
1453            case "Co" :
1454                    // checkout
1455                    Lock("$gblFsRoot/$relDir/$F");
1456                    header("Content-Disposition: attachment; filename=$F" );
1457                    Header("Location: $webRoot".urlpath("$relDir/$F"));
1458                    exit;
1459            case "Ci" :
1460                    $F=stripSlashes($F);
1461                    // upload && update to $relDir
1462                    if (!is_writeable($gblFsRoot . $relDir))
1463                            Error("Write access denied",$relDir) ;
1464                    $text  = "Use this page to update a single " ;
1465                    $text .= "file to <B>$HTTP_HOST</B>." ;
1466                    StartHTML("(Update file Page)", $text) ;
1467                    UploadPage($gblFsRoot, $relDir, $F) ;
1468                    EndHTML() ;
1469                    exit ;
1470            case "V" :
1471                    // view
1472                    LogIt("$gblFsRoot/$relDir/$F","viewed");
1473                    header("Content-Disposition: attachment; filename=$F" );
1474                    Header("Location: $webRoot".urlpath("$relDir/$F"));
1475                    exit;
1476            case "Ch" :
1477                    StartHTML("(File changes)","All changes chronologicaly...");
1478                    DisplayChangeLog(0);    // all
1479                    EndHTML() ;
1480                    exit;
1481            case "Ch1" :
1482                    StartHTML("(File changes)","Changes to files in last day...");
1483                    DisplayChangeLog(1);
1484                    EndHTML() ;
1485                    exit;
1486          }          }
1487    
1488          // default: display directory $relDir          // default: display directory $relDir

Legend:
Removed from v.1.5  
changed lines
  Added in v.1.37

  ViewVC Help
Powered by ViewVC 1.1.26