/[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.1.1.1 by dpavlin, Fri May 12 12:01:08 2000 UTC revision 1.3 by dpavlin, Thu Aug 3 19:35:44 2000 UTC
# Line 34  Line 34 
34  /*             PHP3. Fixed bug which would send you to a non-   */  /*             PHP3. Fixed bug which would send you to a non-   */
35  /*             existent address after file modifications.       */  /*             existent address after file modifications.       */
36    
37    /*
38            2000-07-25 Dobrica Pavlinusic <dpavlin@rot13.org>
39    
40            nuked exec calls (unsecure)
41            nuked writeable function (replaced by php is_writeable)
42            added support for https (tested with apache+mod_ssl)
43            added users file
44            date format user-selectable
45            cycle backup files in bak directory
46            support links as directoryes (for now)
47            support of file history logging
48            undelete capabilities (delete moves to .del directory)
49    
50            2000-07-26 DbP
51    
52            added more checking on entered filename (when creating file/dir)
53            added rename option
54    
55    
56    IMPORTANT INSTALLATION NOTE:
57            deny serving of .* (dot-something) files in web server!
58            Otherwise, uses can access your log files, users and/or
59            deleted files!
60    
61            .htusers is in form:
62            login:Real Name:md5(loginpassword)
63    
64    
65    TODO:
66            mixed file/directory output (add type to each entry,
67                    real support for links)
68            add more content-management (like cms.sourceforge.net):
69                    check-out/check-in/reserve
70                    comments to files
71    */
72    
73  //////////////////////////////////////////////////////////////////  //////////////////////////////////////////////////////////////////
74    
75  // TODO : Don't let the file be modified itself. Create a hash of  // TODO : Don't let the file be modified itself. Create a hash of
# Line 51  Line 87 
87          // username/password should not be system          // username/password should not be system
88          // usernames/passwords !!          // usernames/passwords !!
89    
90          // your (hashed) username/password here  //      $gblPw    = "hash_of_your_username_and_password" ;
91          $gblPw    = "hash_of_your_username_and_password" ;                
92            //      $gblAuth  = false ;             // use builtin authentication
93          $gblAuth  = false ;             // use builtin authentication          $gblAuth  = true ;             // use builtin authentication
94          $gblHash  = "md5" ;             // hash function to use          $gblHash  = "md5" ;             // hash function to use
95    
96            $gblPw    = "";
97    
98            if ($gblAuth) {
99                    $htusers_file=dirname($SCRIPT_FILENAME)."/.htusers";
100                    if (! file_exists($htusers_file)) {
101                            $htusers=fopen($htusers_file,"a+");
102                            fputs($htusers,"# Change owner of $htusers_file to root !!\n");
103                            fputs($htusers,"demo:full name:md5_hash\n");
104                            fclose($htusers);
105                    }
106                    $htusers=fopen($htusers_file,"r");
107                    while($user = fgetcsv($htusers,255,":")) {
108                            if ($user[0] == $GLOBALS["PHP_AUTH_USER"]) {
109                                    $gblUserName=$user[1];
110                                    $gblPw=$user[2];
111                                    continue ;
112                            }
113                    }
114                    fclose($htusers);
115            }
116    
117    //      $gblDateFmt="D, F d, Y";
118    //      $gblTimeFmt="g:i:sA";
119    
120            $gblDateFmt="Y-m-d";
121            $gblTimeFmt="H:i:s";
122    
123    // Number of backup files to keep
124            $gblNumBackups=5;
125    
126          // choose GifIcon below unless you have the M$          // choose GifIcon below unless you have the M$
127          // WingDings font installed on your system          // WingDings font installed on your system
128    
# Line 65  Line 131 
131          // the directory below should be /icons/ or /icons/small/          // the directory below should be /icons/ or /icons/small/
132          // on Apache; a set of icons is included in the distribution          // on Apache; a set of icons is included in the distribution
133    
134          $gblIconLocation = "icons/" ;          $gblIconLocation = "/icons/" ;
135    
136          // files you want to be able to edit in text mode          // files you want to be able to edit in text mode
137          // and view with (primitive) syntax highlighting          // and view with (primitive) syntax highlighting
# Line 115  function EndHTML() { Line 181  function EndHTML() {
181    
182  <HR>  <HR>
183  <P CLASS=FTR>  <P CLASS=FTR>
184  <B><?php echo date("D, F d, Y") ?> -  <B><?= date($GLOBALS[gblDateFmt]) ?> -
185  <?php echo date("g:i:sA") ?></B><BR>ANYPORTAL(php) Site Manager  <?= date($GLOBALS[gblTimeFmt]) ?> -
186  - &copy; 1999 by <A HREF="http://www.anyportal.com">ANYPORTAL</A>  <?= $GLOBALS[gblUserName] ?>
187  - &copy; 2000 by <A HREF="http://da.nger.org">d@nger.org</A>  <small> [<a href="<?= $PHP_SELF ?>?relogin=<?= $GLOBALS[gblPw] ?>">logout</a>]</small>
188    </B>
189    <BR>ANYPORTAL(php) Site Manager
190    <br><small>
191    &copy; 1999 by <A HREF="http://www.anyportal.com">ANYPORTAL</A>,
192    &copy; 2000 by <A HREF="http://da.nger.org">d@nger.org</A>,
193    &copy; 2000 by <A HREF="http://www.rot13.org/~dpavlin/">DbP</A>
194    </small>
195  </P>  </P>
196  <BR><BR><BR></BODY></HTML>  <BR>
197    <? //include("../debug.inc") ?>
198    <BR><BR></BODY></HTML>
199    
200  <?php  <?php
201  } // end function EndHTML  } // end function EndHTML
# Line 130  function EndHTML() { Line 205  function EndHTML() {
205  function CSS() {  function CSS() {
206  ?>  ?>
207    
208  BODY,TD,P,H1,H2,H3 { font-family:Helvetica,Arial,sans-serif; }  BODY,TD,P,H1,H2,H3 { font-family:Verdana,Helvetica,Arial,sans-serif; }
209  .BLK { color:black; }  .BLK { color:black; }
210  .RED { color:red; }  .RED { color:red; }
211  .TOP { color:red; font-size:70%; } /* table headings */  .TOP { color:red; font-size:70%; } /* table headings */
# Line 164  function DetailPage($fsRoot,$relDir,$fn) Line 239  function DetailPage($fsRoot,$relDir,$fn)
239          $exists   = file_exists($fsPath) ;          $exists   = file_exists($fsPath) ;
240          $ext      = strtolower(strrchr($relPath,".")) ;          $ext      = strtolower(strrchr($relPath,".")) ;
241          $editable = ( $ext=="" || strstr(join(" ",$gblEditable),$ext)) ;          $editable = ( $ext=="" || strstr(join(" ",$gblEditable),$ext)) ;
242          $writable = Writeable($fsPath) ;          $writable = is_writeable($fsPath) ;
243    
244          if (!$editable && !$exists)          if (!$editable && !$exists)
245                  Error("Creation unsupported for type",$relPath) ;                  Error("Creation unsupported for type",$relPath) ;
246          if (!exists && !Writeable($fsDir) )          if (!exists && !is_writeable($fsDir) )
247                  Error("Creation denied",$relDir) ;                  Error("Creation denied",$relDir) ;
248    
249          $text  = "Use this page to view, modify or " ;          $text  = "Use this page to view, modify or " ;
# Line 180  function DetailPage($fsRoot,$relDir,$fn) Line 255  function DetailPage($fsRoot,$relDir,$fn)
255          echo "<H3>" . $relDir . "/" . $fn . "</H3>" ;          echo "<H3>" . $relDir . "/" . $fn . "</H3>" ;
256          if ($exists) {  // get file info          if ($exists) {  // get file info
257            $fsize = filesize($fsPath) ;            $fsize = filesize($fsPath) ;
258            $fmodified = date("d/M/y G:i:s", filemtime($fsPath)) ;            $fmodified = date("$GLOBALS[gblDateFmt] $GLOBALS[gblTimeFmt]", filemtime($fsPath)) ;
259            $faccessed = date("d/M/y G:i:s", fileatime($fsPath)) ;            $faccessed = date("$GLOBALS[gblDateFmt] $GLOBALS[gblTimeFmt]", fileatime($fsPath)) ;
260            echo "<PRE>    file size: " . $fsize . " Bytes<BR>" ;            echo "<PRE>    file size: " . $fsize . " Bytes<BR>" ;
261            echo "last modified: <B>" . $fmodified . "</B><BR>" ;            echo "last modified: <B>" . $fmodified . "</B><BR>" ;
262            echo "last accessed: <B>" . $faccessed . "</B><BR>" ;            echo "last accessed: <B>" . $faccessed . "</B><BR>" ;
# Line 190  function DetailPage($fsRoot,$relDir,$fn) Line 265  function DetailPage($fsRoot,$relDir,$fn)
265            echo "  permissions: <B>" ;            echo "  permissions: <B>" ;
266            echo printf( "%o", fileperms($fsPath) ) . "</B>" ;            echo printf( "%o", fileperms($fsPath) ) . "</B>" ;
267            echo "</PRE>" ;            echo "</PRE>" ;
268    
269          }          }
270    
271          if ( $editable && ($writable || !$exists) ) {          if ( $editable && ($writable || !$exists) ) {
# Line 209  echo($fstr) ; ?></TEXTAREA> Line 285  echo($fstr) ; ?></TEXTAREA>
285  <INPUT TYPE="HIDDEN" NAME="DIR" VALUE="<?php echo $relDir ; ?>">  <INPUT TYPE="HIDDEN" NAME="DIR" VALUE="<?php echo $relDir ; ?>">
286  <INPUT TYPE="HIDDEN" NAME="FN" VALUE="<?php echo $fn ; ?>">  <INPUT TYPE="HIDDEN" NAME="FN" VALUE="<?php echo $fn ; ?>">
287  <INPUT TYPE="HIDDEN" NAME="POSTACTION" VALUE="SAVE">  <INPUT TYPE="HIDDEN" NAME="POSTACTION" VALUE="SAVE">
288  <INPUT TYPE="TEXT" SIZE=48 MAXLENGTH=255 NAME="RELPATH"  <INPUT TYPE="HIDDEN" SIZE=48 MAXLENGTH=255 NAME="RELPATH"
289          VALUE="<?php echo $relPath ; ?>">          VALUE="<?php echo $relPath ; ?>">
290  <INPUT TYPE="RESET" VALUE="RESET">  <br>
291    <INPUT TYPE="RESET" VALUE="UNDO ALL CHANGES">
292  <INPUT TYPE="SUBMIT" VALUE="SAVE">  <INPUT TYPE="SUBMIT" VALUE="SAVE">
293  </FORM>  </FORM>
294    
# Line 232  echo($fstr) ; ?></TEXTAREA> Line 309  echo($fstr) ; ?></TEXTAREA>
309  <INPUT TYPE="SUBMIT" NAME="POSTACTION" VALUE="CANCEL"><BR>  <INPUT TYPE="SUBMIT" NAME="POSTACTION" VALUE="CANCEL"><BR>
310    
311  <?php  <?php
312            if (substr($fn,0,4) == ".del") {
313                    $action="UNDELETE";
314                    $desc="undelete previously deleted file";
315            } else {
316                    $action="DELETE";
317                    $desc="delete";
318            }
319    
320          if ($exists && $writable) {          if ($exists && $writable) {
321  ?>  ?>
322    
323  <HR><SPAN TITLE="Check OK and click [DELETE] to delete.">  <HR><SPAN TITLE="Check OK and click [<?= $action ?>] to <?= $desc ?>.">
324  <B>OK TO DELETE "<?php echo $fn ; ?>"? </B></SPAN>  <B>OK TO <?= $action ?> "<?php echo $fn ; ?>"? </B></SPAN>
325    <INPUT TYPE="CHECKBOX" NAME="CONFIRM">
326    <INPUT TYPE="SUBMIT" NAME="POSTACTION" VALUE="<?= $action ?>">
327    
328    <HR><SPAN TITLE="Check OK and click [RENAME] to rename.">
329    <B>OK TO RENAME "<?php echo $fn ; ?>" TO
330    <INPUT TYPE="TEXT" SIZE=24 MAXLENGTH=255 NAME="NEWNAME" VALUE="<?= $fn ?>">
331    ? </B></SPAN>
332  <INPUT TYPE="CHECKBOX" NAME="CONFIRM">  <INPUT TYPE="CHECKBOX" NAME="CONFIRM">
333  <INPUT TYPE="SUBMIT" NAME="POSTACTION" VALUE="DELETE">  <INPUT TYPE="SUBMIT" NAME="POSTACTION" VALUE="RENAME">
334    
335  <?php  <?php
336          }          }
337          echo "</FORM>" ;          echo "</FORM>" ;
338    
339            $logname=dirname("$fsDir/$fn")."/.log/".basename("$fsDir/$fn");
340            if (file_exists($logname)) {
341                    print "<hr><br><b>CHANGES TO THIS FILE</b><br><table border=0 width=100%>\n";
342                    $log=fopen($logname,"r");
343                    $cl1=" class=lst"; $cl2="";
344                    while($line = fgetcsv($log,255,"\t")) {
345                            $cl=$cl1; $cl1=$cl2; $cl2=$cl;
346                            print "<tr><td$cl>$line[0]</td><td$cl>$line[1]</td><td$cl>$line[2]</td><td$cl>$line[3]</td></tr>\n";
347                    }
348                    fclose($log);
349                    print "</table>";
350            }
351    
352          EndHTML() ;          EndHTML() ;
353    
354  } // end function DetailPage  } // end function DetailPage
# Line 486  function Navigate($fsRoot,$relDir) { Line 592  function Navigate($fsRoot,$relDir) {
592          global $gblEditable, $gblIcon ;          global $gblEditable, $gblIcon ;
593    
594          $self     = $GLOBALS["PHP_SELF"] ;          $self     = $GLOBALS["PHP_SELF"] ;
595          $webRoot  = "http://" . $GLOBALS["SERVER_NAME"] ;          if (isset($GLOBALS["HTTPS"]) && $GLOBALS["HTTPS"] == "on") {
596                    $webRoot  = "https://" . $GLOBALS["SERVER_NAME"] ;
597            } else {
598                    $webRoot  = "http://" . $GLOBALS["SERVER_NAME"] ;
599            }
600          $fsDir    = $fsRoot . $relDir . "/" ; // current directory          $fsDir    = $fsRoot . $relDir . "/" ; // current directory
601    
602          if (!is_dir($fsDir)) Error("Dir not found",$relDir) ;          if (!is_dir($fsDir)) Error("Dir not found",$relDir) ;
# Line 495  function Navigate($fsRoot,$relDir) { Line 605  function Navigate($fsRoot,$relDir) {
605          if ( !($dir = @opendir($fsDir)) )          if ( !($dir = @opendir($fsDir)) )
606                  Error("Read Access denied",$relDir) ;                  Error("Read Access denied",$relDir) ;
607          while ($item = readdir($dir)) {          while ($item = readdir($dir)) {
608                  if ( $item == ".." || $item == "." ) continue ;                  if ( $item == ".." || $item == "." || substr($item,0,1) == "." ) continue ;
609                  if ( is_dir($fsDir . $item) ) {                  if ( is_dir($fsDir . $item) ) {
610                          $dirList[] = $item ;                          $dirList[] = $item ;
611                  }                  } else if ( is_file($fsDir . $item) ) {
                 else if ( is_file($fsDir . $item) ) {  
612                          $fileList[] = $item ;                                    $fileList[] = $item ;          
613                  }                  } else if ( is_link($fsDir . $item) ) {
614                  else {                          $dirList[] = $item ;
615                    } else {
616                    // unknown file type                    // unknown file type
617                    // $text = "Could not determine file type of " ;                    // $text = "Could not determine file type of " ;
618                    // Error("File Error", $text.$relDir."/".$item) ;                    // Error("File Error", $text.$relDir."/".$item) ;
# Line 510  function Navigate($fsRoot,$relDir) { Line 620  function Navigate($fsRoot,$relDir) {
620                  }                  }
621          }          }
622          closedir($dir) ;          closedir($dir) ;
623    
624            // scan deleted files
625            if ( $GLOBALS[show_deleted] == 1 && ($dir = @opendir("$fsDir/.del")) ) {
626                    while ($item = readdir($dir)) {
627                            if ( substr($item,0,1) == "." ) continue ;
628                            $fileList[] = ".del/$item" ;            
629                    }
630                    closedir($dir) ;
631            }
632    
633          $emptyDir = ! (sizeof($dirList) || sizeof($fileList)) ;          $emptyDir = ! (sizeof($dirList) || sizeof($fileList)) ;
634    
635          // start navigation page          // start navigation page
636          $text  = "Use this page to add, delete or " ;          $text  = "Use this page to add, delete";
637          $text .= "revise files on this web site." ;          if (! isset($show_deleted)) {
638                    $text .= ", <a href=".$GLOBALS[PHP_SELF]."?D=".urlencode($relDir)."&show_deleted=1>undelete</a>";
639            }
640            $text .= " or revise files on this web site." ;
641          StartHTML("(Navigate)",$text) ;          StartHTML("(Navigate)",$text) ;
642    
643          echo "<TABLE BORDER=0 CELLPADDING=2          echo "<TABLE BORDER=0 CELLPADDING=2
# Line 587  function Navigate($fsRoot,$relDir) { Line 709  function Navigate($fsRoot,$relDir) {
709    
710              $tstr = $webRoot . $relDir . "/" . $file ;              $tstr = $webRoot . $relDir . "/" . $file ;
711              $tstr  = "<A HREF=\"" . $tstr . "\">" ;              $tstr  = "<A HREF=\"" . $tstr . "\">" ;
712              $tstr .= $file . "</A>" . $a ;  
713                    if (substr($file,0,5) != ".del/") {
714                            $tstr .= $file . "</A>" . $a ;
715                    } else {
716                            $tstr .= substr($file,5,strlen($file)-5) . "</a> <SPAN CLASS=RED TITLE=\"deleted\"> deleted </span>";
717                    }
718    
719              $ext = strtolower(strrchr($file,".")) ;              $ext = strtolower(strrchr($file,".")) ;
720              if ( $ext=="" ||              if ( $ext=="" ||
# Line 607  function Navigate($fsRoot,$relDir) { Line 734  function Navigate($fsRoot,$relDir) {
734  <?php echo $gblIcon($ext) ?></A></TD>  <?php echo $gblIcon($ext) ?></A></TD>
735  <TD CLASS=LST><?php echo $tstr ?></TD>  <TD CLASS=LST><?php echo $tstr ?></TD>
736  <TD CLASS=LST ALIGN=center><?php echo $b ?></TD>  <TD CLASS=LST ALIGN=center><?php echo $b ?></TD>
737  <TD CLASS=LST><?php echo date("d/M/y G:i:s",$mod) ?></TD>  <TD CLASS=LST><?php echo date("$GLOBALS[gblDateFmt] $GLOBALS[gblTimeFmt]",$mod) ?></TD>
738  <TD CLASS=LST><?php echo $sz ?>Bytes</TD></TR>  <TD CLASS=LST><?php echo $sz ?>Bytes</TD></TR>
739    
740  <?php  <?php
# Line 694  function Error($title,$text="") { Line 821  function Error($title,$text="") {
821    
822  //////////////////////////////////////////////////////////////////  //////////////////////////////////////////////////////////////////
823    
 function Writeable($path) {  
         // fix by -mat- filid brandy, brandy@ecrc.de, 07/JUL/99  
   
         clearstatcache ;  
         $perms = @fileperms($path) ;  
         $owner = @fileowner($path) ;  
         exec("id",$id) ;  
         eregi( "^uid=([0-9]*)",$id[0], $regs) ;  
         $apacheuid = $regs[1] ;  
         $perms = 0777 & $perms ;  
         if ( $apacheuid != $owner ) {  
                 return (06 == (06 & $perms)) ?  1 : 0 ;  
         }  
         else {  
                 return (0600 == (0600 & $perms)) ? 1 : 0 ;  
         }  
   
 } // end function Writable  
   
 //////////////////////////////////////////////////////////////////  
   
824  function CreateHash($user, $pw) {  function CreateHash($user, $pw) {
825    
826          global $gblHash ;  // hash function to use          global $gblHash ;  // hash function to use
# Line 767  the source<BR>of this file.<BR><BR> Line 873  the source<BR>of this file.<BR><BR>
873    
874  //////////////////////////////////////////////////////////////////  //////////////////////////////////////////////////////////////////
875    
876    function Logit($target,$msg) {
877    
878            $dir=dirname($target);
879            if (! file_exists($dir."/.log")) {
880                    mkdir($dir."/.log",0700);
881            }
882            $file=basename($target);
883    
884            $log=fopen("$dir/.log/$file","a+");
885            fputs($log,date("$GLOBALS[gblDateFmt]\t$GLOBALS[gblTimeFmt]").
886                    "\t$GLOBALS[gblUserName]\t$msg\n");
887            fclose($log);
888    
889    }
890    
891    
892    
893    //////////////////////////////////////////////////////////////////
894    
895  // MAIN PROGRAM  // MAIN PROGRAM
896  // ============  // ============
897  // query parameters: capital letters  // query parameters: capital letters
898  // local functions : begin with capital letters  // local functions : begin with capital letters
899  // global constants: begin with gbl  // global constants: begin with gbl
900    
901          $gblFilePerms = "644" ;         // default for new files          $gblFilePerms = 0640 ;         // default for new files
902          $gblDirPerms  = 0755 ;          // default for new dirs          $gblDirPerms  = 0750 ;          // default for new dirs
903    
904          // phpinfo() ;          // phpinfo() ;
905          // exit ;          // exit ;
# Line 788  the source<BR>of this file.<BR><BR> Line 913  the source<BR>of this file.<BR><BR>
913          }          }
914    
915          // authentication if $gblAuth == true          // authentication if $gblAuth == true
916          if ( $gblAuth &&          if ( $gblAuth && $gblHash($PHP_AUTH_USER.$PHP_AUTH_PW) != $gblPw ||
917               $gblHash($PHP_AUTH_USER.$PHP_AUTH_PW) != $gblPw ) {                  isset($relogin) && $gblPw == $relogin ) {
918                  header("WWW-authenticate: basic realm=\"$SERVER_NAME\"") ;                  header("WWW-authenticate: basic realm=\"$SERVER_NAME\"") ;
919                  header("HTTP/1.0 401 Unauthorized") ;                  header("HTTP/1.0 401 Unauthorized") ;
920                  NoEntry() ;                  NoEntry() ;
# Line 827  the source<BR>of this file.<BR><BR> Line 952  the source<BR>of this file.<BR><BR>
952                    
953          switch ($POSTACTION) {          switch ($POSTACTION) {
954          case "UPLOAD" :          case "UPLOAD" :
955                  if (!Writeable($fsDir)) Error("Write denied",$relDir) ;                  if (!is_writeable($fsDir)) Error("Write denied",$relDir) ;
956                  if (strstr($FN_name,"/"))                  if (strstr($FN_name,"/"))
957                          Error("Non-conforming filename") ;                          Error("Non-conforming filename") ;
958                  // TODO : should rather check for escapeshellcmds                  // TODO : should rather check for escapeshellcmds
959                  // but maybe RFC 18xx asserts safe filenames ....                  // but maybe RFC 18xx asserts safe filenames ....
960                  $source = $FN ;                  $source = $FN ;
961                  $target = $fsDir . "/" . $FN_name ;                  $target = $fsDir . "/" . $FN_name ;
962                  exec("cp $source $target") ;  
963                  exec("chmod $gblFilePerms $target") ;                  // backup old files first
964                    $dir=dirname($target);
965                    if (! file_exists($dir."/.bak")) {
966                            mkdir($dir."/.bak",0700);
967                    }
968                    if (! file_exists($dir."/.bak/$GLOBALS[gblNumBackups]")) {
969                            mkdir($dir."/.bak/$GLOBALS[gblNumBackups]",0700);
970                    }
971                    $file=basename($target);
972                    for($i=$GLOBALS[gblNumBackups]-1;$i>0;$i--) {
973                            if (! file_exists($dir."/.bak/".$i)) {
974                                    mkdir($dir."/.bak/".$i,0700);
975                            }
976                            if (file_exists($dir."/.bak/".$i."/".$file)) {
977                                    rename($dir."/.bak/".$i."/".$file,
978                                            $dir."/.bak/".($i+1)."/".$file);
979                            }
980                    }
981                    if (file_exists($target)) {
982                            rename($target,$dir."/.bak/1/".$file);
983                    }
984    
985                    copy($source,$target) ;
986                    chmod($target,$gblFilePerms) ;
987                  clearstatcache() ;                  clearstatcache() ;
988                    Logit($target,"uploaded");
989                  break ;                  break ;
990    
991          case "SAVE" :          case "SAVE" :
992                  $path = $gblFsRoot . escapeshellcmd($RELPATH) ;                  $path = $gblFsRoot . escapeshellcmd($RELPATH) ;
993                  $writable = Writeable($path) ;                  $writable = is_writeable($path) ;
994                  $legaldir = Writeable(dirname($path)) ;                  $legaldir = is_writeable(dirname($path)) ;
995                  $exists   = (file_exists($path)) ? 1 : 0 ;                  $exists   = (file_exists($path)) ? 1 : 0 ;
996  // check for legal extension here as well  // check for legal extension here as well
997                  if (!($writable || (!$exists && $legaldir)))                  if (!($writable || (!$exists && $legaldir)))
# Line 851  the source<BR>of this file.<BR><BR> Line 1000  the source<BR>of this file.<BR><BR>
1000                  fwrite($fh,$FILEDATA) ;                  fwrite($fh,$FILEDATA) ;
1001                  fclose($fh) ;                  fclose($fh) ;
1002                  clearstatcache() ;                  clearstatcache() ;
1003                    Logit($path,"saved changes");
1004                  break ;                  break ;
1005    
1006          case "CREATE" :          case "CREATE" :
1007                  // we know $fsDir exists                  // we know $fsDir exists
1008                  if (!Writeable($fsDir)) Error("Write denied",$relDir) ;                  if ($FN == "") break;           // no filename!
1009                    if (!is_writeable($fsDir)) Error("Write denied",$relDir) ;
1010                  $path = $fsDir . "/" . $FN ;  // file or dir to create                  $path = $fsDir . "/" . $FN ;  // file or dir to create
1011                  $relPath = $relDir . "/" . $FN ;                  $relPath = $relDir . "/" . $FN ;
1012                  switch ( $T ) {                  switch ( $T ) {
# Line 868  the source<BR>of this file.<BR><BR> Line 1019  the source<BR>of this file.<BR><BR>
1019  // this functionality is doubled in DetailView().  // this functionality is doubled in DetailView().
1020  // better keep it here altogether  // better keep it here altogether
1021  // chmod perms to $gblFilePerms  // chmod perms to $gblFilePerms
1022                    if ( file_exists($path) && !Writable($path) )                    if ( file_exists($path) && !is_writable($path) )
1023                      Error("File not writable", $relPath) ;                      Error("File not writable", $relPath) ;
1024                    $tstr = $PHP_SELF . "?A=E&D=" . $relDir . "&F=" . $FN ;                    $tstr = $PHP_SELF . "?A=E&D=" . $relDir . "&F=" . $FN ;
1025                    header("Location: " . $tstr) ;                    header("Location: " . $tstr) ;
# Line 883  the source<BR>of this file.<BR><BR> Line 1034  the source<BR>of this file.<BR><BR>
1034                  $tstr .= "insufficient privileges: " ;                  $tstr .= "insufficient privileges: " ;
1035    
1036                  if ( $FN != "") {  // delete file                  if ( $FN != "") {  // delete file
1037                    $path =  $fsDir . "/" . $FN ;                          $path =  $fsDir . "/" . $FN ;
1038                    if ( ! @unlink($path) ) {                  
1039                      Error("File delete failed", $tstr . $path) ;                          $dir=dirname($path);
1040                      exit ;                          $file=basename($path);
1041                    }                                              if (! file_exists("$dir/.del")) {
1042                                    mkdir("$dir/.del",0700);
1043                            }
1044    
1045    //                      if ( ! @unlink($path) ) {
1046                            if ( ! rename($path,"$dir/.del/$file") ) {
1047                                    Error("File delete failed", $tstr . $path) ;
1048                                    Logit($path,"file delete failed");
1049                                    exit ;
1050                            } else {
1051                                    Logit($path,"file deleted");
1052                                    if (! file_exists("$dir/.del/.log")) {
1053                                            mkdir("$dir/.del/.log",0700);
1054                                    }
1055                                    rename("$dir/.log/$file","$dir/.del/.log/$file");
1056                            }
1057                  }                  }
1058                  else {  // delete directory                  else {  // delete directory
1059                    if ( ! @rmdir($fsDir) ) {                    if ( ! @rmdir($fsDir) ) {
# Line 899  the source<BR>of this file.<BR><BR> Line 1065  the source<BR>of this file.<BR><BR>
1065                  }                  }
1066                  break ;                  break ;
1067    
1068            case "UNDELETE" :  
1069                    if ( $CONFIRM != "on" ) break ;
1070    
1071                    if (substr($FN,0,4) != ".del") break ;
1072                    $file=substr($FN,4,strlen($FN)-4);
1073    
1074                    Logit("$fsDir/.del/$file","undeleted");
1075                    rename("$fsDir/.del/$file","$fsDir/$file");
1076                    rename("$fsDir/.del/.log/$file","$fsDir/.log/$file");
1077    
1078                    break ;
1079    
1080            case "RENAME" :  
1081                    if ( $CONFIRM != "on" ) break ;
1082    
1083                    Logit("$fsDir/$FN","renamed $FN to $NEWNAME");
1084                    rename("$fsDir/$FN","$fsDir/$NEWNAME");
1085                    rename("$fsDir/.log/$FN","$fsDir/.log/$NEWNAME");
1086    
1087                    break ;
1088    
1089          default :          default :
1090                  // user hit "CANCEL" or undefined action                  // user hit "CANCEL" or undefined action
1091          }          }
# Line 919  the source<BR>of this file.<BR><BR> Line 1106  the source<BR>of this file.<BR><BR>
1106          switch ($A) {          switch ($A) {
1107          case "U" :          case "U" :
1108                  // upload to $relDir                  // upload to $relDir
1109                  if (!Writeable($gblFsRoot . $relDir))                  if (!is_writeable($gblFsRoot . $relDir))
1110                          Error("Write access denied",$relDir) ;                          Error("Write access denied",$relDir) ;
1111                  $text  = "Use this page to upload a single " ;                  $text  = "Use this page to upload a single " ;
1112                  $text .= "file to <B>$SERVER_NAME</B>." ;                  $text .= "file to <B>$SERVER_NAME</B>." ;
# Line 929  the source<BR>of this file.<BR><BR> Line 1116  the source<BR>of this file.<BR><BR>
1116                  exit ;                  exit ;
1117          case "E" :          case "E" :
1118                  // detail of $relDir/$F                  // detail of $relDir/$F
1119                  DetailPage($gblFsRoot, $relDir, $F) ;                  if (is_file("$gblFsRoot/$relDir/$F")) DetailPage($gblFsRoot, $relDir, $F) ;
1120                  exit ;                  exit ;
1121          case "C" :          case "C" :
1122                  // listing of $relDir/$F                  // listing of $relDir/$F

Legend:
Removed from v.1.1.1.1  
changed lines
  Added in v.1.3

  ViewVC Help
Powered by ViewVC 1.1.26