/[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.9 by dpavlin, Fri Aug 4 10:43:23 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            retrieve old versions of files (overwritten)
69    */
70    
71  //////////////////////////////////////////////////////////////////  //////////////////////////////////////////////////////////////////
72    
73  // 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 85 
85          // username/password should not be system          // username/password should not be system
86          // usernames/passwords !!          // usernames/passwords !!
87    
88          // your (hashed) username/password here  //      $gblPw    = "hash_of_your_username_and_password" ;
89          $gblPw    = "hash_of_your_username_and_password" ;                
90            //      $gblAuth  = false ;             // use builtin authentication
91          $gblAuth  = false ;             // use builtin authentication          $gblAuth  = true ;             // use builtin authentication
92          $gblHash  = "md5" ;             // hash function to use          $gblHash  = "md5" ;             // hash function to use
93    
94            $gblPw    = "";
95    
96            if ($gblAuth) {
97                    $htusers_file=dirname($SCRIPT_FILENAME)."/.htusers";
98                    if (! file_exists($htusers_file)) {
99                            $htusers=fopen($htusers_file,"a+");
100                            fputs($htusers,"# Change owner of $htusers_file to root !!\n");
101                            fputs($htusers,"demo:full name:md5_hash\n");
102                            fclose($htusers);
103                    }
104                    $htusers=fopen($htusers_file,"r");
105                    while($user = fgetcsv($htusers,255,":")) {
106                            if ($user[0] == $GLOBALS["PHP_AUTH_USER"]) {
107                                    $gblUserName=$user[1];
108                                    $gblPw=$user[2];
109                                    continue ;
110                            }
111                    }
112                    fclose($htusers);
113            }
114    
115    //      $gblDateFmt="D, F d, Y";
116    //      $gblTimeFmt="g:i:sA";
117    
118            $gblDateFmt="Y-m-d";
119            $gblTimeFmt="H:i:s";
120    
121    // Number of backup files to keep
122            $gblNumBackups=5;
123    
124          // choose GifIcon below unless you have the M$          // choose GifIcon below unless you have the M$
125          // WingDings font installed on your system          // WingDings font installed on your system
126    
# Line 65  Line 129 
129          // the directory below should be /icons/ or /icons/small/          // the directory below should be /icons/ or /icons/small/
130          // on Apache; a set of icons is included in the distribution          // on Apache; a set of icons is included in the distribution
131    
132          $gblIconLocation = "icons/" ;          $gblIconLocation = "/icons/" ;
133    
134          // files you want to be able to edit in text mode          // files you want to be able to edit in text mode
135          // and view with (primitive) syntax highlighting          // and view with (primitive) syntax highlighting
# Line 91  function StartHTML($title,$text="") { Line 155  function StartHTML($title,$text="") {
155    
156  <HTML>  <HTML>
157  <HEAD>  <HEAD>
158   <TITLE><?php echo $host . " " . $title ?></TITLE>   <TITLE><?= $host . " " . $title ?></TITLE>
159   <META NAME="description" CONTENT="PHP port of AnyPortal Site Manager">   <META NAME="description" CONTENT="PHP port of AnyPortal Site Manager">
160   <META NAME="keywords" CONTENT="site manager, web site maintenance">   <META NAME="keywords" CONTENT="site manager, web site maintenance">
161   <META NAME="robots" CONTENT="noindex">   <META NAME="robots" CONTENT="noindex">
162   <META HTTP-EQUIV="expires" CONTENT="0">   <META HTTP-EQUIV="expires" CONTENT="0">
163   <LINK REL="stylesheet" TYPE="text/css"   <LINK REL="stylesheet" TYPE="text/css"
164          HREF="<?php echo $self ?>?STYLE=get">          HREF="<?= $self ?>?STYLE=get">
165  </HEAD>  </HEAD>
166  <BODY BGCOLOR="#FFFFFF">  <BODY BGCOLOR="#FFFFFF">
167   <H3 ALIGN="RIGHT"><?php echo $host ?></H3>   <H3 ALIGN="RIGHT"><?= $host ?></H3>
168  <TABLE BORDER=0 WIDTH="100%"><TR>  <TABLE BORDER=0 WIDTH="100%"><TR>
169   <TD CLASS=INV><?php echo $title ?></TD></TR></TABLE>   <TD CLASS=INV><?= $title ?></TD></TR></TABLE>
170   <P><?php echo $text ?></P>   <P><?= $text ?></P>
171    
172  <?php  <?php
173  } // end function StartHTML  } // end function StartHTML
# Line 115  function EndHTML() { Line 179  function EndHTML() {
179    
180  <HR>  <HR>
181  <P CLASS=FTR>  <P CLASS=FTR>
182  <B><?php echo date("D, F d, Y") ?> -  <B><?= date($GLOBALS[gblDateFmt]) ?> -
183  <?php echo date("g:i:sA") ?></B><BR>ANYPORTAL(php) Site Manager  <?= date($GLOBALS[gblTimeFmt]) ?> -
184  - &copy; 1999 by <A HREF="http://www.anyportal.com">ANYPORTAL</A>  <?= $GLOBALS[gblUserName] ?>
185  - &copy; 2000 by <A HREF="http://da.nger.org">d@nger.org</A>  <small> [<a href="<?= $GLOBALS["PHP_SELF"] ?>?relogin=<?= $GLOBALS[gblPw] ?>">logout</a>]</small>
186    </B>
187    <BR>ANYPORTAL(php) Site Manager
188    <br><small>
189    &copy; 1999 by <A HREF="http://www.anyportal.com">ANYPORTAL</A>,
190    &copy; 2000 by <A HREF="http://da.nger.org">d@nger.org</A>,
191    &copy; 2000 by <A HREF="http://www.rot13.org/~dpavlin/">DbP</A>
192    </small>
193  </P>  </P>
194  <BR><BR><BR></BODY></HTML>  <BR>
195    <? //include(".debug.inc") ?>
196    <BR><BR></BODY></HTML>
197    
198  <?php  <?php
199  } // end function EndHTML  } // end function EndHTML
# Line 130  function EndHTML() { Line 203  function EndHTML() {
203  function CSS() {  function CSS() {
204  ?>  ?>
205    
206  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; }
207  .BLK { color:black; }  .BLK { color:black; }
208  .RED { color:red; }  .RED { color:red; }
209  .TOP { color:red; font-size:70%; } /* table headings */  .TOP { color:red; font-size:70%; } /* table headings */
# Line 164  function DetailPage($fsRoot,$relDir,$fn) Line 237  function DetailPage($fsRoot,$relDir,$fn)
237          $exists   = file_exists($fsPath) ;          $exists   = file_exists($fsPath) ;
238          $ext      = strtolower(strrchr($relPath,".")) ;          $ext      = strtolower(strrchr($relPath,".")) ;
239          $editable = ( $ext=="" || strstr(join(" ",$gblEditable),$ext)) ;          $editable = ( $ext=="" || strstr(join(" ",$gblEditable),$ext)) ;
240          $writable = Writeable($fsPath) ;          $writable = is_writeable($fsPath) ;
241            $file_lock = CheckLock($fsPath);
242    
243          if (!$editable && !$exists)          if (!$editable && !$exists)
244                  Error("Creation unsupported for type",$relPath) ;                  Error("Creation unsupported for type",$relPath) ;
245          if (!exists && !Writeable($fsDir) )          if (!exists && !is_writeable($fsDir) )
246                  Error("Creation denied",$relDir) ;                  Error("Creation denied",$relDir) ;
247    
248          $text  = "Use this page to view, modify or " ;          $text  = "Use this page to view, modify or " ;
# Line 179  function DetailPage($fsRoot,$relDir,$fn) Line 253  function DetailPage($fsRoot,$relDir,$fn)
253    
254          echo "<H3>" . $relDir . "/" . $fn . "</H3>" ;          echo "<H3>" . $relDir . "/" . $fn . "</H3>" ;
255          if ($exists) {  // get file info          if ($exists) {  // get file info
256            $fsize = filesize($fsPath) ;                  $fsize = filesize($fsPath) ;
257            $fmodified = date("d/M/y G:i:s", filemtime($fsPath)) ;                  $fmodified = date("$GLOBALS[gblDateFmt] $GLOBALS[gblTimeFmt]", filemtime($fsPath)) ;
258            $faccessed = date("d/M/y G:i:s", fileatime($fsPath)) ;                  $faccessed = date("$GLOBALS[gblDateFmt] $GLOBALS[gblTimeFmt]", fileatime($fsPath)) ;
259            echo "<PRE>    file size: " . $fsize . " Bytes<BR>" ;                  echo "<PRE>    file size: " . $fsize . " Bytes<BR>" ;
260            echo "last modified: <B>" . $fmodified . "</B><BR>" ;                  echo "last modified: <B>" . $fmodified . "</B><BR>" ;
261            echo "last accessed: <B>" . $faccessed . "</B><BR>" ;                  echo "last accessed: <B>" . $faccessed . "</B><BR>" ;
262            echo "        owner: <B>" . fileowner($fsPath) . "</B><BR>" ;                  echo "        owner: <B>" . fileowner($fsPath) . "</B><BR>" ;
263            echo "        group: <B>" . filegroup($fsPath) . "</B><BR>" ;                  echo "        group: <B>" . filegroup($fsPath) . "</B><BR>" ;
264            echo "  permissions: <B>" ;                  echo "  permissions: <B>" ;
265            echo printf( "%o", fileperms($fsPath) ) . "</B>" ;                  echo printf( "%o", fileperms($fsPath) ) . "</B>" ;
266            echo "</PRE>" ;                  echo "</PRE>" ;
267    
268          }          }
269    
270          if ( $editable && ($writable || !$exists) ) {          if ( $editable && ($writable || !$exists) && !$file_lock ) {
271                  $fh = fopen($fsPath,"a+") ;                  $fh = fopen($fsPath,"a+") ;
272                  rewind($fh) ;                  rewind($fh) ;
273                  $fstr = fread($fh,filesize($fsPath)) ;                  $fstr = fread($fh,filesize($fsPath)) ;
# Line 200  function DetailPage($fsRoot,$relDir,$fn) Line 275  function DetailPage($fsRoot,$relDir,$fn)
275                  $fstr = htmlentities( $fstr ) ;                  $fstr = htmlentities( $fstr ) ;
276  ?>  ?>
277    
278  <FORM ACTION="<?php echo $self ; ?>" METHOD="POST">  <FORM ACTION="<?= $self ; ?>" METHOD="POST">
279  <SPAN TITLE="Click [SAVE] to store updated contents.">  <SPAN TITLE="Click [SAVE] to store updated contents.">
280          <B>DOCUMENT CONTENTS</B>          <B>DOCUMENT CONTENTS</B>
281  </SPAN><BR>  </SPAN><BR>
282  <TEXTAREA NAME="FILEDATA" ROWS=18 COLS=70 WRAP="OFF"><?php  <TEXTAREA NAME="FILEDATA" ROWS=18 COLS=70 WRAP="OFF"><?php
283  echo($fstr) ; ?></TEXTAREA>  echo($fstr) ; ?></TEXTAREA>
284  <INPUT TYPE="HIDDEN" NAME="DIR" VALUE="<?php echo $relDir ; ?>">  <INPUT TYPE="HIDDEN" NAME="DIR" VALUE="<?= $relDir ; ?>">
285  <INPUT TYPE="HIDDEN" NAME="FN" VALUE="<?php echo $fn ; ?>">  <INPUT TYPE="HIDDEN" NAME="FN" VALUE="<?= $fn ; ?>">
286  <INPUT TYPE="HIDDEN" NAME="POSTACTION" VALUE="SAVE">  <INPUT TYPE="HIDDEN" NAME="POSTACTION" VALUE="SAVE">
287  <INPUT TYPE="TEXT" SIZE=48 MAXLENGTH=255 NAME="RELPATH"  <INPUT TYPE="HIDDEN" SIZE=48 MAXLENGTH=255 NAME="RELPATH"
288          VALUE="<?php echo $relPath ; ?>">          VALUE="<?= $relPath ; ?>">
289  <INPUT TYPE="RESET" VALUE="RESET">  <br>
290    <INPUT TYPE="RESET" VALUE="UNDO ALL CHANGES">
291  <INPUT TYPE="SUBMIT" VALUE="SAVE">  <INPUT TYPE="SUBMIT" VALUE="SAVE">
292  </FORM>  </FORM>
293    
294  <?php  <?php
295          }          }
296          else if ( strstr( join(" ",$gblImages), $ext ) ) {            if ( !$file_lock && strstr(join(" ",$gblImages),$ext) ) {  
297            $info  = getimagesize($fsPath) ;                  $info  = getimagesize($fsPath) ;
298            $tstr  = "<IMG SRC=\"". $relPath . "\" BORDER=0 " ;                  $tstr = "<IMG SRC=\"".urlpath($relPath)."\" BORDER=0 " ;
299            $tstr .= $info[3] . " ALT=\"" . $fn . " - " ;                  $tstr .= $info[3] . " ALT=\"" . $fn . " - " ;
300            $tstr .= (int)(($fsize+1023)/1024) . "Kb\">" ;                  $tstr .= (int)(($fsize+1023)/1024) . "Kb\">" ;
301            echo htmlentities($tstr) . "<BR><BR>" . $tstr ;  //              echo htmlentities($tstr) . "<BR><BR>" . $tstr ;
302                    echo $tstr ;
303          }          }
304    
305  ?>  ?>
306    
307  <FORM ACTION="<?php echo $self ; ?>" METHOD="POST">  <FORM ACTION="<?= $self ; ?>" METHOD="POST">
308  <INPUT TYPE="HIDDEN" NAME="DIR" VALUE="<?php echo $relDir ; ?>">  <INPUT TYPE="HIDDEN" NAME="DIR" VALUE="<?= $relDir ; ?>">
309  <INPUT TYPE="HIDDEN" NAME="FN" VALUE="<?php echo $fn ; ?>">  <INPUT TYPE="HIDDEN" NAME="FN" VALUE="<?= $fn ; ?>">
310  <INPUT TYPE="SUBMIT" NAME="POSTACTION" VALUE="CANCEL"><BR>  <INPUT TYPE="SUBMIT" NAME="POSTACTION" VALUE="CANCEL"><BR>
311    
312  <?php  <?php
313    
314            if ($file_lock) {
315    ?>
316    <hr>
317    <SPAN TITLE="Check OK and click UNLOCK to remove lock on file.">
318    <B>OK TO FORCE LOCK REMOVAL ON "<?= $fn ; ?>" HELD BY <?= $file_lock ?>? </B></SPAN>
319    <INPUT TYPE="CHECKBOX" NAME="CONFIRM">
320    <INPUT TYPE="SUBMIT" NAME="POSTACTION" VALUE="UNLOCK">
321    <?
322            } // file_lock
323    
324            if (substr($fn,0,4) == ".del") {
325                    $action="UNDELETE";
326                    $desc="undelete previously deleted file";
327            } else {
328                    $action="DELETE";
329                    $desc="delete";
330            }
331    
332          if ($exists && $writable) {          if ($exists && $writable) {
333  ?>  ?>
334    
335  <HR><SPAN TITLE="Check OK and click [DELETE] to delete.">  <HR>
336  <B>OK TO DELETE "<?php echo $fn ; ?>"? </B></SPAN>  <a name="undelete">
337    <SPAN TITLE="Check OK and click [<?= $action ?>] to <?= $desc ?>.">
338    <B>OK TO <?= $action ?> "<?= $fn ; ?>"? </B></SPAN>
339  <INPUT TYPE="CHECKBOX" NAME="CONFIRM">  <INPUT TYPE="CHECKBOX" NAME="CONFIRM">
340  <INPUT TYPE="SUBMIT" NAME="POSTACTION" VALUE="DELETE">  <INPUT TYPE="SUBMIT" NAME="POSTACTION" VALUE="<?= $action ?>">
341    
342    <HR>
343    <a name="rename">
344    <SPAN TITLE="Check OK and click [RENAME] to rename.">
345    <B>OK TO RENAME "<?= $fn ; ?>" TO
346    <INPUT TYPE="TEXT" SIZE=24 MAXLENGTH=255 NAME="NEWNAME" VALUE="<?= $fn ?>">
347    ? </B></SPAN>
348    <INPUT TYPE="CHECKBOX" NAME="CONFIRM">
349    <INPUT TYPE="SUBMIT" NAME="POSTACTION" VALUE="RENAME">
350    
351    <?php
352            }       // exists && writable
353    ?>
354    <HR>
355    <a name="note">
356    <B>NOTE FOR "<?= $fn ; ?>":
357    <INPUT TYPE="TEXT" SIZE=50 MAXLENGTH=255 NAME="NOTE" VALUE="<?= ReadNote($fsPath) ?>">
358    </B></SPAN>
359    <INPUT TYPE="SUBMIT" NAME="POSTACTION" VALUE="NOTE">
360    
361    </FORM>
362    
363  <?php  <?php
364            
365    
366            $logname=dirname("$fsDir/$fn")."/.log/".basename("$fsDir/$fn");
367            if (file_exists($logname)) {
368                    print "<hr><br><b>CHANGES TO THIS FILE</b><br><table border=0 width=100%>\n";
369                    $log=fopen($logname,"r");
370                    $cl1=" class=lst"; $cl2="";
371                    while($line = fgetcsv($log,255,"\t")) {
372                            $cl=$cl1; $cl1=$cl2; $cl2=$cl;
373                            print "<tr><td$cl>$line[0]</td><td$cl>$line[1]</td><td$cl>$line[2]</td><td$cl>$line[3]</td></tr>\n";
374                    }
375                    fclose($log);
376                    print "</table>";
377          }          }
378          echo "</FORM>" ;  
379          EndHTML() ;          EndHTML() ;
380    
381  } // end function DetailPage  } // end function DetailPage
# Line 472  function GifIcon($txt) { Line 605  function GifIcon($txt) {
605          case "blank" :          case "blank" :
606                  $d = "blank.gif" ;                  $d = "blank.gif" ;
607                  break ;                  break ;
608            case "checkout":
609                    $d = "box2.gif";
610                    break;
611            case "checkin":
612                    $d = "hand.up.gif";
613                    break;
614            case "locked":
615                    $d = "screw2.gif";
616                    break;
617            case "note":
618                    $d = "quill.gif";
619                    break;
620          default :          default :
621                  $d = "generic.gif" ;                  $d = "generic.gif" ;
622          }          }
# Line 486  function Navigate($fsRoot,$relDir) { Line 631  function Navigate($fsRoot,$relDir) {
631          global $gblEditable, $gblIcon ;          global $gblEditable, $gblIcon ;
632    
633          $self     = $GLOBALS["PHP_SELF"] ;          $self     = $GLOBALS["PHP_SELF"] ;
634          $webRoot  = "http://" . $GLOBALS["SERVER_NAME"] ;          if (isset($GLOBALS["HTTPS"]) && $GLOBALS["HTTPS"] == "on") {
635                    $webRoot  = "https://" . $GLOBALS["SERVER_NAME"] ;
636            } else {
637                    $webRoot  = "http://" . $GLOBALS["SERVER_NAME"] ;
638            }
639          $fsDir    = $fsRoot . $relDir . "/" ; // current directory          $fsDir    = $fsRoot . $relDir . "/" ; // current directory
640    
641          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 644  function Navigate($fsRoot,$relDir) {
644          if ( !($dir = @opendir($fsDir)) )          if ( !($dir = @opendir($fsDir)) )
645                  Error("Read Access denied",$relDir) ;                  Error("Read Access denied",$relDir) ;
646          while ($item = readdir($dir)) {          while ($item = readdir($dir)) {
647                  if ( $item == ".." || $item == "." ) continue ;                  if ( $item == ".." || $item == "." || substr($item,0,1) == "." ) continue ;
648                  if ( is_dir($fsDir . $item) ) {                  if ( is_dir($fsDir . $item) ) {
649                          $dirList[] = $item ;                          $dirList[] = $item ;
650                  }                  } else if ( is_file($fsDir . $item) ) {
                 else if ( is_file($fsDir . $item) ) {  
651                          $fileList[] = $item ;                                    $fileList[] = $item ;          
652                  }                  } else if ( is_link($fsDir . $item) ) {
653                  else {                          $dirList[] = $item ;
654                    } else {
655                    // unknown file type                    // unknown file type
656                    // $text = "Could not determine file type of " ;                    // $text = "Could not determine file type of " ;
657                    // Error("File Error", $text.$relDir."/".$item) ;                    // Error("File Error", $text.$relDir."/".$item) ;
# Line 510  function Navigate($fsRoot,$relDir) { Line 659  function Navigate($fsRoot,$relDir) {
659                  }                  }
660          }          }
661          closedir($dir) ;          closedir($dir) ;
662    
663            // scan deleted files
664            if ( $GLOBALS[show_deleted] == 1 && ($dir = @opendir("$fsDir/.del")) ) {
665                    while ($item = readdir($dir)) {
666                            if ( substr($item,0,1) == "." ) continue ;
667                            $fileList[] = ".del/$item" ;            
668                    }
669                    closedir($dir) ;
670            }
671    
672          $emptyDir = ! (sizeof($dirList) || sizeof($fileList)) ;          $emptyDir = ! (sizeof($dirList) || sizeof($fileList)) ;
673    
674          // start navigation page          // start navigation page
675          $text  = "Use this page to add, delete or " ;          $text  = "Use this page to add, delete";
676          $text .= "revise files on this web site." ;          if (! isset($show_deleted)) {
677                    $text .= ", <a href=$self?D=".urlencode($relDir)."&show_deleted=1>undelete</a>";
678            }
679            $text .= " or revise files on this web site." ;
680          StartHTML("(Navigate)",$text) ;          StartHTML("(Navigate)",$text) ;
681    
682          echo "<TABLE BORDER=0 CELLPADDING=2          echo "<TABLE BORDER=0 CELLPADDING=2
# Line 527  function Navigate($fsRoot,$relDir) { Line 688  function Navigate($fsRoot,$relDir) {
688                  if ($parent == "") $parent = "/" ;                  if ($parent == "") $parent = "/" ;
689  ?>  ?>
690    
691  <TR><TD><?php echo $gblIcon("up") ?></TD><TD COLSPAN=4 CLASS=LST>  <TR><TD><?= $gblIcon("up") ?></TD><TD COLSPAN=5 CLASS=LST>
692  <A HREF="<?php echo $self ?>?D=<?php echo urlencode($parent) ?>">  <A HREF="<?= $self ?>?D=<?= urlencode($parent) ?>">
693  <B><?php echo $parent ?></B></A></TD></TR>  <B><?= $parent ?></B></A></TD></TR>
694    
695  <?php  <?php
696          }          }
# Line 539  function Navigate($fsRoot,$relDir) { Line 700  function Navigate($fsRoot,$relDir) {
700                  sort($dirList) ;                  sort($dirList) ;
701  ?>  ?>
702    
703  <TR><TD></TD><TD COLSPAN=4 CLASS=TOP><HR>DIRECTORY NAME</TD></TR>  <TR><TD></TD><TD COLSPAN=5 CLASS=TOP><HR>DIRECTORY NAME</TD></TR>
704    
705  <?php  <?php
706                  while (list($key,$dir) = each($dirList)) {                  while (list($key,$dir) = each($dirList)) {
# Line 549  function Navigate($fsRoot,$relDir) { Line 710  function Navigate($fsRoot,$relDir) {
710                          $tstr .= "\">" . $dir . "/</A>" ;                          $tstr .= "\">" . $dir . "/</A>" ;
711  ?>  ?>
712    
713  <TR><TD><?php echo $gblIcon("fldr") ?></TD>  <TR><TD><?= $gblIcon("fldr") ?></TD>
714  <TD COLSPAN=4 CLASS=LST><?php echo $tstr ?></TD></TR>  <TD COLSPAN=5 CLASS=LST><?= $tstr ?></TD></TR>
715    
716  <?php  <?php
717                  }  // iterate over dirs                  }  // iterate over dirs
718          }  // end if no dirs          }  // end if no dirs
719  ?>  ?>
720    
721  <TR><TD></TD><TD COLSPAN=4><HR><B><?php echo $webRoot . $relDir ?>  <TR><TD></TD><TD COLSPAN=5><HR><B><?= $webRoot . $relDir ?>
722  </B></TD></TR>  </B></TD></TR>
723  <TR><TD></TD><TD CLASS=TOP>DOCUMENT NAME</TD>  <TR><TD></TD><TD CLASS=TOP>DOCUMENT NAME</TD>
724  <TD><?php echo $gblIcon("blank") ?></TD>  <TD><?= $gblIcon("blank").$gblIcon("blank") ?></TD>
725    <TD CLASS=TOP>NOTE</TD>
726  <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>
727    
728  <?php  <?php
729          if (sizeof($fileList) > 0) {          if (sizeof($fileList) > 0) {
730            sort($fileList) ;            sort($fileList) ;
731            while (list($key,$file) = each($fileList)) {              while (list($key,$file) = each($fileList)) {  
732              $path = $fsDir."/".$file ;                  $path = $fsDir."/".$file ;
733              $mod  = filemtime($path) ;                  $mod  = filemtime($path) ;
734              $sz   = filesize($path) ;                  $sz   = filesize($path) ;
735    
736              if ($sz >= 10240) {                  if ($sz >= 10240) {
737                $sz = (int)(($sz+1023)/1024) . " k" ;                          $sz = (int)(($sz+1023)/1024) . " k" ;
738              }                  } else {
739              else {                          $sz .= " " ;
740                $sz .= " " ;                  } // end size
741              } // end size  
742                    $a = $b = "" ;
743              $a = $b = "" ;  
744                    $info_url=$self."?A=E&F=".urlencode($file)."&D=".urlencode($relDir);
745              if ( ($mod + 30*86400) > time() ) {  
746                $a  = "<SPAN CLASS=RED TITLE=\"Newer" ;                  if ( ($mod + 30*86400) > time() ) {
747                $a .= " than 30 days\"> * </SPAN>" ;                          $a  = "<SPAN CLASS=RED TITLE=\"Newer" ;
748              }                          $a .= " than 30 days\"> * </SPAN>" ;
749                    }
750              $tstr = $webRoot . $relDir . "/" . $file ;  
751              $tstr  = "<A HREF=\"" . $tstr . "\">" ;                  $file_lock=CheckLock($path);
752              $tstr .= $file . "</A>" . $a ;  
753                    $file_url_html="<A HREF=\"$self?A=V&F=".urlencode($file);
754              $ext = strtolower(strrchr($file,".")) ;                  $file_url_html.="&D=".urlencode($relDir);
755              if ( $ext=="" ||                  $file_url_html.="\" TITLE=\"View file\">" ;
756                   strstr(join(" ",$gblEditable),$ext) )  
757              {                    if (substr($file,0,5) != ".del/") {
758                $b  = "<A HREF=\"" . $self . "?A=C&F=" ;                          $file_url_html .= $file . "</A>" . $a ;
759                $b .= urlencode($file) . "&D=" . urlencode($relDir) ;                  } else {
760                $b .= "\" TITLE=\"List contents\">" ;                          $file_url_html .= substr($file,5,strlen($file)-5) . "</a> <SPAN CLASS=RED TITLE=\"deleted\"> <a href=\"$info_url#undelete\">deleted</a> </span>";
761                $b .= $gblIcon("view") . "</A>" ;                  }
762              }  
763                    $note_html="<a href=\"$info_url#note\">".$gblIcon("note")."</a>".ReadNote($path);
764    
765                    $ext = strtolower(strrchr($file,".")) ;
766    
767                    if ($file_lock) {
768                            if ($file_lock == $GLOBALS[gblUserName]) {
769                                    $b.="<A HREF=\"$self?A=Ci&F=".urlencode($file);
770                                    $b.="&D=".urlencode($relDir);
771                                    $b.="\" TITLE=\"Checkin (update) file on server\">" ;
772                                    $file_url_html=$b;
773                                    $b.=$gblIcon("checkin")."</A>" ;
774                                    $b.= $gblIcon("blank");
775                                    $file_url_html.="$file</a> $a";
776                                    $note_html = $gblIcon("blank")."<b>Please check-in (update) this file</b>";
777                            } else {
778                                    $b = $gblIcon("locked");
779                                    $b.= $gblIcon("blank");
780                                    $note_html = $gblIcon("blank")."<b>File locked by $file_lock</b>";
781                                    $file_url_html = "$file $a";
782                            }
783                    } else {
784                            $b.="<A HREF=\"$self?A=Co&F=".urlencode($file);
785                            $b.="&D=".urlencode($relDir);
786                            $b.="\" TITLE=\"Checkout file for edit\">" ;
787                            $b.=$gblIcon("checkout")."</A>" ;
788    
789                            if ( $ext=="" || strstr(join(" ",$gblEditable),$ext) ) {  
790                                    $b.="<A HREF=\"$self?A=C&F=".urlencode($file);
791                                    $b.="&D=".urlencode($relDir);
792                                    $b.="\" TITLE=\"List contents\">" ;
793                                    $b.=$gblIcon("view")."</A>" ;
794                            } else {
795                                    $b.= $gblIcon("blank");
796                            }
797                    }
798    
799    
800  ?>  ?>
801    
802  <TR><TD>  <TR><TD>
803  <A HREF="<?php echo $self ?>?A=E&F=<?php echo urlencode($file)  <A HREF="<?= $info_url ?>" TITLE="View/Edit">
804  ?>&D=<?php echo urlencode($relDir) ?>" TITLE="View/Edit">  <?= $gblIcon($ext) ?></A></TD>
805  <?php echo $gblIcon($ext) ?></A></TD>  <TD CLASS=LST><?= $file_url_html ?></TD>
806  <TD CLASS=LST><?php echo $tstr ?></TD>  <TD CLASS=LST ALIGN=center><?= $b ?></TD>
807  <TD CLASS=LST ALIGN=center><?php echo $b ?></TD>  <TD CLASS=LST ALIGN=left><?= $note_html ?></TD>
808  <TD CLASS=LST><?php echo date("d/M/y G:i:s",$mod) ?></TD>  <TD CLASS=LST><?= date("$GLOBALS[gblDateFmt] $GLOBALS[gblTimeFmt]",$mod) ?></TD>
809  <TD CLASS=LST><?php echo $sz ?>Bytes</TD></TR>  <TD CLASS=LST><?= $sz ?>Bytes</TD></TR>
810    
811  <?php  <?php
812            }  // iterate over files            }  // iterate over files
# Line 617  function Navigate($fsRoot,$relDir) { Line 815  function Navigate($fsRoot,$relDir) {
815          if ($emptyDir) {          if ($emptyDir) {
816  ?>  ?>
817    
818  <FORM METHOD="POST" ACTION="<?php echo $self ?>">  <FORM METHOD="POST" ACTION="<?= $self ?>">
819   <TR><TD></TD><TD COLSPAN=4 CLASS=BAR>   <TR><TD></TD><TD COLSPAN=5 CLASS=BAR>
820    <INPUT TYPE="HIDDEN" NAME="DIR" VALUE="<?php echo $relDir ?>">    <INPUT TYPE="HIDDEN" NAME="DIR" VALUE="<?= $relDir ?>">
821    OK TO DELETE THIS EMPTY FOLDER?    OK TO DELETE THIS EMPTY FOLDER?
822    <INPUT TYPE="CHECKBOX" NAME="CONFIRM">    <INPUT TYPE="CHECKBOX" NAME="CONFIRM">
823    <INPUT TYPE="SUBMIT" NAME="POSTACTION" VALUE="DELETE">    <INPUT TYPE="SUBMIT" NAME="POSTACTION" VALUE="DELETE">
# Line 630  function Navigate($fsRoot,$relDir) { Line 828  function Navigate($fsRoot,$relDir) {
828          } // end if emptyDir          } // end if emptyDir
829  ?>  ?>
830    
831  <TR><TD></TD><TD COLSPAN=4><HR></TD></TR>  <TR><TD></TD><TD COLSPAN=5><HR></TD></TR>
832    
833    <TR><TD></TD><TD COLSPAN=5>
834    To just view file without editing, select it's filename (<b>don't edit files which are opened this way!</b>)<br>
835    To <b>edit</b> file select <?= $gblIcon("checkout") ?> to check-out
836    and edit it locally. After editing is over, select filename or <?= $gblIcon("checkin") ?> to check-in (update copy of file on server).<br>
837    <by>If you select icon left from filename, you will get detailed information
838    about file, as well as delete, rename and annotation options.
839    </TD></TR>
840    
841    <TR><TD></TD><TD COLSPAN=5><HR></TD></TR>
842    
843  <FORM METHOD="POST" ACTION="<?php echo $self ?>">  <FORM METHOD="POST" ACTION="<?= $self ?>">
844  <TR><TD></TD><TD COLSPAN=4 CLASS=BAR>CREATE NEW  <TR><TD></TD><TD COLSPAN=5 CLASS=BAR>CREATE NEW
845   <INPUT TYPE="RADIO" NAME="T" VALUE="D" CHECKED>DIRECTORY -OR-   <INPUT TYPE="RADIO" NAME="T" VALUE="D" CHECKED>DIRECTORY -OR-
846   <INPUT TYPE="RADIO" NAME="T" VALUE="F">FILE : &nbsp;&nbsp;   <INPUT TYPE="RADIO" NAME="T" VALUE="F">FILE : &nbsp;&nbsp;
847   <NOBR>NAME <INPUT TYPE="TEXT" NAME="FN" SIZE=14>   <NOBR>NAME <INPUT TYPE="TEXT" NAME="FN" SIZE=14>
848   <INPUT TYPE="HIDDEN" NAME="POSTACTION" VALUE="CREATE">   <INPUT TYPE="HIDDEN" NAME="POSTACTION" VALUE="CREATE">
849   <INPUT TYPE="HIDDEN" NAME="DIR" VALUE="<?php echo $relDir ?>">   <INPUT TYPE="HIDDEN" NAME="DIR" VALUE="<?= $relDir ?>">
850   <INPUT TYPE="SUBMIT" VALUE="CREATE"></NOBR>   <INPUT TYPE="SUBMIT" VALUE="CREATE"></NOBR>
851   <NOBR>OR <A HREF="<?php echo $self   <NOBR>OR <A HREF="<?= $self ?>?A=U&D=<?= urlencode($relDir) ?>">UPLOAD</A> A FILE
         ?>?A=U&D=<?php echo urlencode($relDir) ?>">UPLOAD</A> A FILE  
852   </NOBR>   </NOBR>
853  </TD></TR>  </TD></TR>
854  </FORM>  </FORM>
# Line 653  function Navigate($fsRoot,$relDir) { Line 860  function Navigate($fsRoot,$relDir) {
860    
861  //////////////////////////////////////////////////////////////////  //////////////////////////////////////////////////////////////////
862    
863  function UploadPage($fsRoot, $relDir) {  function UploadPage($fsRoot, $relDir, $filename) {
864    
865          $self = $GLOBALS["PHP_SELF"] ;          $self = $GLOBALS["PHP_SELF"] ;
866          if ($relDir == "") $relDir = "/" ;          if ($relDir == "") $relDir = "/" ;
# Line 661  function UploadPage($fsRoot, $relDir) { Line 868  function UploadPage($fsRoot, $relDir) {
868    
869  <P><TABLE BORDER=0 CELLPADDING=5><TR><TD WIDTH=5></TD><TD CLASS=BAR>  <P><TABLE BORDER=0 CELLPADDING=5><TR><TD WIDTH=5></TD><TD CLASS=BAR>
870  <FORM ENCTYPE="multipart/form-data" METHOD="POST"  <FORM ENCTYPE="multipart/form-data" METHOD="POST"
871   ACTION="<?php echo $self ?>">   ACTION="<?= $self ?>">
872  DESTINATION DIRECTORY:<B><?php echo " " . $relDir ?></B>  DESTINATION DIRECTORY:<B><?= " " . $relDir ?></B>
873    <? if (isset($filename)) { ?>
874    <br>DESTINATION FILE:<B><?= " " . $filename ?></B>
875    <INPUT TYPE="HIDDEN" NAME="FILENAME" VALUE="<?= $filename ?>">
876    <? } ?>
877  <P>PATHNAME OF LOCAL FILE<BR>  <P>PATHNAME OF LOCAL FILE<BR>
878  <INPUT TYPE="HIDDEN" NAME="DIR" VALUE="<?php echo $relDir ?>">  <INPUT TYPE="HIDDEN" NAME="DIR" VALUE="<?= $relDir ?>">
879  <INPUT TYPE="HIDDEN" NAME="POSTACTION" VALUE="UPLOAD">  <INPUT TYPE="HIDDEN" NAME="POSTACTION" VALUE="UPLOAD">
880  <INPUT SIZE=30 TYPE="FILE" NAME="FN"></P>  <INPUT SIZE=30 TYPE="FILE" NAME="FN"></P>
881  <P><INPUT TYPE="SUBMIT" VALUE="UPLOAD"></P>  <P><INPUT TYPE="SUBMIT" VALUE="UPLOAD"></P>
882  <P>If the <B>[BROWSE...]</B> button is not displayed,<BR>  <P>If the <B>[BROWSE...]</B> button is not displayed,<BR>
883  you must upgrade to an RFC1867-compliant browser.</P>  you must upgrade to an RFC1867-compliant browser.</P>
884  <P>Your browser:<BR><?php echo $GLOBALS["HTTP_USER_AGENT"] ?></P>  <P>Your browser:<BR><?= $GLOBALS["HTTP_USER_AGENT"] ?></P>
885  </FORM>  </FORM>
886  </TD></TR>  </TD></TR>
887  <TR><TD></TD><TD>  <TR><TD></TD><TD>
888  <FORM METHOD="POST" ACTION="<?php echo $self ?>">  <FORM METHOD="POST" ACTION="<?= $self ?>">
889  <INPUT TYPE="HIDDEN" NAME="DIR" VALUE="<?php echo $relDir ?>"><BR>  <INPUT TYPE="HIDDEN" NAME="DIR" VALUE="<?= $relDir ?>"><BR>
890  <INPUT TYPE="SUBMIT" NAME="POSTACTION" VALUE="CANCEL">  <INPUT TYPE="SUBMIT" NAME="POSTACTION" VALUE="CANCEL">
891  </FORM>  </FORM>
892  </TD></TR></TABLE></P>  </TD></TR></TABLE></P>
# Line 694  function Error($title,$text="") { Line 905  function Error($title,$text="") {
905    
906  //////////////////////////////////////////////////////////////////  //////////////////////////////////////////////////////////////////
907    
 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  
   
 //////////////////////////////////////////////////////////////////  
   
908  function CreateHash($user, $pw) {  function CreateHash($user, $pw) {
909    
910          global $gblHash ;  // hash function to use          global $gblHash ;  // hash function to use
# Line 749  function NoEntry() { Line 939  function NoEntry() {
939          StartHTML($title,$text) ;          StartHTML($title,$text) ;
940  ?>  ?>
941    
942  <FORM ACTION="<?php echo $self ?>?HASH=create" METHOD="POST">  <FORM ACTION="<?= $self ?>?HASH=create" METHOD="POST">
943  <INPUT TYPE="HIDDEN" NAME="USER" VALUE="<?php echo $user ?>">  <INPUT TYPE="HIDDEN" NAME="USER" VALUE="<?= $user ?>">
944  <INPUT TYPE="HIDDEN" NAME="PW" VALUE="<?php echo $pw ?>">  <INPUT TYPE="HIDDEN" NAME="PW" VALUE="<?= $pw ?>">
945    
946  <BLOCKQUOTE><B>If you are a site administrator:</B><BR><BR>  <BLOCKQUOTE><B>If you are a site administrator:</B><BR><BR>
947  Click below to <B>generate a password hash</B><BR>from  Click below to <B>generate a password hash</B><BR>from
# Line 767  the source<BR>of this file.<BR><BR> Line 957  the source<BR>of this file.<BR><BR>
957    
958  //////////////////////////////////////////////////////////////////  //////////////////////////////////////////////////////////////////
959    
960    function Logit($target,$msg) {
961    
962            $dir=dirname($target);
963            if (! file_exists($dir."/.log")) {
964                    mkdir($dir."/.log",0700);
965            }
966            $file=basename($target);
967    
968            $log=fopen("$dir/.log/$file","a+");
969            fputs($log,date("$GLOBALS[gblDateFmt]\t$GLOBALS[gblTimeFmt]").
970                    "\t$GLOBALS[gblUserName]\t$msg\n");
971            fclose($log);
972    
973    }
974    
975    
976    //////////////////////////////////////////////////////////////////
977    
978    function WriteNote($target,$msg) {
979    
980            $dir=dirname($target);
981            if (! file_exists($dir."/.note")) {
982                    mkdir($dir."/.note",0700);
983            }
984            $file=basename($target);
985    
986            $note=fopen("$dir/.note/$file","w");
987            fputs($note,"$msg\n");
988            fclose($note);
989    
990            Logit($target,"added note $msg");
991    
992    }
993    
994    function ReadNote($target) {
995    
996            $dir=dirname($target);
997            $file=basename($target);
998            $msg="";
999            if (file_exists($dir."/.note/$file")) {
1000                    $note=fopen("$dir/.note/$file","r");
1001                    $msg=fgets($note,4096);
1002                    fclose($note);
1003            }
1004            return StripSlashes($msg);
1005    
1006    }
1007    
1008    //////////////////////////////////////////////////////////////////
1009    
1010    function MoveTo($source,$folder) {
1011    
1012            $file=basename($source);
1013            if (! file_exists($folder)) {
1014                    mkdir($folder,0700);
1015            }
1016            if (file_exists($source)) {
1017                    rename($source,"$folder/$file");
1018            }
1019    }
1020    
1021    //////////////////////////////////////////////////////////////////
1022    
1023    function Lock($target) {
1024    
1025            $dir=dirname($target);
1026            if (! file_exists($dir."/.lock")) {
1027                    mkdir($dir."/.lock",0700);
1028            }
1029            $file=basename($target);
1030    
1031            if (file_exists("$dir/.lock/$file")) {
1032                    Logit($target,"attempt to locked allready locked file!");
1033            } else {
1034                    $lock=fopen("$dir/.lock/$file","w");
1035                    fputs($lock,"$GLOBALS[gblUserName]\n");
1036                    fclose($lock);
1037    
1038                    Logit($target,"file locked");
1039            }
1040    
1041    }
1042    
1043    function CheckLock($target) {
1044    
1045            $dir=dirname($target);
1046            $file=basename($target);
1047            $msg=0;
1048            if (file_exists($dir."/.lock/$file")) {
1049                    $lock=fopen("$dir/.lock/$file","r");
1050                    $msg=fgets($lock,4096);
1051                    fclose($lock);
1052            }
1053            return chop($msg);
1054    
1055    }
1056    
1057    function Unlock($target) {
1058    
1059            $dir=dirname($target);
1060            $file=basename($target);
1061            if (file_exists($dir."/.lock/$file")) {
1062                    unlink("$dir/.lock/$file");
1063                    Logit($target,"file unlocked");
1064            } else {
1065                    Logit($target,"attempt to unlocked non-locked file!");
1066            }
1067    
1068    }
1069    
1070    //////////////////////////////////////////////////////////////////
1071    
1072    function urlpath($url) {
1073            $url=urlencode(StripSlashes("$url"));
1074            $url=str_replace("%2F","/",$url);
1075            $url=str_replace("+","%20",$url);
1076            return($url);
1077    }
1078    
1079    //////////////////////////////////////////////////////////////////
1080    
1081    function safe_rename($from,$to) {
1082            if (file_exists($from) && is_writable(dirname($to))) {
1083                    rename($from,$to);
1084            }
1085    }
1086    
1087    //////////////////////////////////////////////////////////////////
1088    
1089  // MAIN PROGRAM  // MAIN PROGRAM
1090  // ============  // ============
1091  // query parameters: capital letters  // query parameters: capital letters
1092  // local functions : begin with capital letters  // local functions : begin with capital letters
1093  // global constants: begin with gbl  // global constants: begin with gbl
1094    
1095          $gblFilePerms = "644" ;         // default for new files          $gblFilePerms = 0640 ;         // default for new files
1096          $gblDirPerms  = 0755 ;          // default for new dirs          $gblDirPerms  = 0750 ;          // default for new dirs
1097    
1098          // phpinfo() ;          // phpinfo() ;
1099          // exit ;          // exit ;
# Line 788  the source<BR>of this file.<BR><BR> Line 1107  the source<BR>of this file.<BR><BR>
1107          }          }
1108    
1109          // authentication if $gblAuth == true          // authentication if $gblAuth == true
1110          if ( $gblAuth &&          if ( $gblAuth && $gblHash($PHP_AUTH_USER.$PHP_AUTH_PW) != $gblPw ||
1111               $gblHash($PHP_AUTH_USER.$PHP_AUTH_PW) != $gblPw ) {                  isset($relogin) && $gblPw == $relogin ) {
1112                  header("WWW-authenticate: basic realm=\"$SERVER_NAME\"") ;                  header("WWW-authenticate: basic realm=\"$SERVER_NAME\"") ;
1113                  header("HTTP/1.0 401 Unauthorized") ;                  header("HTTP/1.0 401 Unauthorized") ;
1114                  NoEntry() ;                  NoEntry() ;
# Line 827  the source<BR>of this file.<BR><BR> Line 1146  the source<BR>of this file.<BR><BR>
1146                    
1147          switch ($POSTACTION) {          switch ($POSTACTION) {
1148          case "UPLOAD" :          case "UPLOAD" :
1149                  if (!Writeable($fsDir)) Error("Write denied",$relDir) ;                  if (!is_writeable($fsDir)) Error("Write denied",$relDir) ;
1150                  if (strstr($FN_name,"/"))                  if (strstr($FN_name,"/"))
1151                          Error("Non-conforming filename") ;                          Error("Non-conforming filename") ;
1152                  // TODO : should rather check for escapeshellcmds                  // TODO : should rather check for escapeshellcmds
1153                  // but maybe RFC 18xx asserts safe filenames ....                  // but maybe RFC 18xx asserts safe filenames ....
1154                  $source = $FN ;                  $source = $FN ;
1155                  $target = $fsDir . "/" . $FN_name ;                  if (! isset($FILENAME)) {       // from update file
1156                  exec("cp $source $target") ;                          $target = "$fsDir/$FN_name" ;
1157                  exec("chmod $gblFilePerms $target") ;                  } else {
1158                            $target = "$fsDir/$FILENAME";
1159                    }
1160    
1161                    // backup old files first
1162                    $dir=dirname($target);
1163                    if (! file_exists($dir."/.bak")) {
1164                            mkdir($dir."/.bak",0700);
1165                    }
1166                    if (! file_exists($dir."/.bak/$GLOBALS[gblNumBackups]")) {
1167                            mkdir($dir."/.bak/$GLOBALS[gblNumBackups]",0700);
1168                    }
1169                    $file=basename($target);
1170                    for($i=$GLOBALS[gblNumBackups]-1;$i>0;$i--) {
1171                            MoveTo("$dir/.bak/$i/$file","$dir/.bak/".($i+1)."/");
1172                    }
1173                    MoveTo($target,$dir."/.bak/1/");
1174    
1175                    copy($source,$target) ;
1176                    chmod($target,$gblFilePerms) ;
1177                  clearstatcache() ;                  clearstatcache() ;
1178                    Logit($target,"uploaded");
1179                    if (isset($FILENAME)) {
1180                            Unlock($target);
1181                    }
1182                  break ;                  break ;
1183    
1184          case "SAVE" :          case "SAVE" :
1185                  $path = $gblFsRoot . escapeshellcmd($RELPATH) ;                  $path = $gblFsRoot . escapeshellcmd($RELPATH) ;
1186                  $writable = Writeable($path) ;                  $writable = is_writeable($path) ;
1187                  $legaldir = Writeable(dirname($path)) ;                  $legaldir = is_writeable(dirname($path)) ;
1188                  $exists   = (file_exists($path)) ? 1 : 0 ;                  $exists   = (file_exists($path)) ? 1 : 0 ;
1189  // check for legal extension here as well  // check for legal extension here as well
1190                  if (!($writable || (!$exists && $legaldir)))                  if (!($writable || (!$exists && $legaldir)))
# Line 851  the source<BR>of this file.<BR><BR> Line 1193  the source<BR>of this file.<BR><BR>
1193                  fwrite($fh,$FILEDATA) ;                  fwrite($fh,$FILEDATA) ;
1194                  fclose($fh) ;                  fclose($fh) ;
1195                  clearstatcache() ;                  clearstatcache() ;
1196                    Logit($path,"saved changes");
1197                  break ;                  break ;
1198    
1199          case "CREATE" :          case "CREATE" :
1200                  // we know $fsDir exists                  // we know $fsDir exists
1201                  if (!Writeable($fsDir)) Error("Write denied",$relDir) ;                  if ($FN == "") break;           // no filename!
1202                    if (!is_writeable($fsDir)) Error("Write denied",$relDir) ;
1203                  $path = $fsDir . "/" . $FN ;  // file or dir to create                  $path = $fsDir . "/" . $FN ;  // file or dir to create
1204                  $relPath = $relDir . "/" . $FN ;                  $relPath = $relDir . "/" . $FN ;
1205                  switch ( $T ) {                  switch ( $T ) {
1206                  case "D" :  // create a directory                  case "D" :  // create a directory
1207                    if ( ! @mkdir($path,$gblDirPerms) )                          if ( ! @mkdir($path,$gblDirPerms) )
1208                      Error("Mkdir failed",$relPath) ; // eg. if it exists                                  Error("Mkdir failed",$relPath) ; // eg. if it exists
1209                    clearstatcache() ;                          clearstatcache() ;
1210                    break ;                          break ;
1211                  case "F" :  // create a new file                  case "F" :  // create a new file
1212  // this functionality is doubled in DetailView().  // this functionality is doubled in DetailView().
1213  // better keep it here altogether  // better keep it here altogether
1214  // chmod perms to $gblFilePerms  // chmod perms to $gblFilePerms
1215                    if ( file_exists($path) && !Writable($path) )                          if ( file_exists($path) && !is_writable($path) )
1216                      Error("File not writable", $relPath) ;                                  Error("File not writable", $relPath) ;
1217                    $tstr = $PHP_SELF . "?A=E&D=" . $relDir . "&F=" . $FN ;                          $fh = fopen($path, "w+") ;
1218                    header("Location: " . $tstr) ;                          if ($fh) {
1219                    exit ;                                  fputs($fh,"\n");
1220                                    fclose($fh) ;
1221                                    LogIt($path,"file created");
1222                            } else {
1223                                    Error("Creation of file $relPath failed -- $path");
1224                            }
1225                            $tstr = "$PHP_SELF?A=E&D=".urlencode($relDir)."&F=".urlencode($FN) ;
1226                            header("Location: " . $tstr) ;
1227                            exit ;
1228                  }                  }
1229                  break ;                  break ;
1230    
# Line 883  the source<BR>of this file.<BR><BR> Line 1235  the source<BR>of this file.<BR><BR>
1235                  $tstr .= "insufficient privileges: " ;                  $tstr .= "insufficient privileges: " ;
1236    
1237                  if ( $FN != "") {  // delete file                  if ( $FN != "") {  // delete file
1238                    $path =  $fsDir . "/" . $FN ;                          $path =  $fsDir . "/" . $FN ;
1239                    if ( ! @unlink($path) ) {                  
1240                      Error("File delete failed", $tstr . $path) ;                          $dir=dirname($path);
1241                      exit ;                          $file=basename($path);
1242                    }                                              if (! file_exists("$dir/.del")) {
1243                                    mkdir("$dir/.del",0700);
1244                            }
1245    
1246    //                      if ( ! @unlink($path) ) {
1247                            if ( ! rename($path,"$dir/.del/$file") ) {
1248                                    Error("File delete failed", $tstr . $path) ;
1249                                    Logit($path,"file delete failed");
1250                                    exit ;
1251                            } else {
1252                                    Logit($path,"file deleted");
1253                                    MoveTo("$dir/.log/$file","$dir/.del/.log/");
1254                                    MoveTo("$dir/.note/$file","$dir/.del/.note/");
1255                                    MoveTo("$dir/.lock/$file","$dir/.del/.lock/");
1256                            }
1257                  }                  }
1258                  else {  // delete directory                  else {  // delete directory
1259                    if ( ! @rmdir($fsDir) ) {                    if ( ! @rmdir($fsDir) ) {
# Line 899  the source<BR>of this file.<BR><BR> Line 1265  the source<BR>of this file.<BR><BR>
1265                  }                  }
1266                  break ;                  break ;
1267    
1268            case "UNDELETE" :  
1269                    if ( $CONFIRM != "on" ) break ;
1270    
1271                    if (substr($FN,0,4) != ".del") break ;
1272                    $file=substr($FN,4,strlen($FN)-4);
1273    
1274                    Logit("$fsDir/.del/$file","undeleted");
1275                    MoveTo("$fsDir/.del/$file","$fsDir/");
1276                    MoveTo("$fsDir/.del/.log/$file","$fsDir/.log/");
1277                    MoveTo("$fsDir/.del/.note/$file","$fsDir/.note/");
1278                    MoveTo("$fsDir/.del/.lock/$file","$fsDir/.lock/");
1279    
1280                    break ;
1281    
1282            case "RENAME" :  
1283                    if ( $CONFIRM != "on" ) break ;
1284    
1285                    Logit("$fsDir/$FN","renamed $FN to $NEWNAME");
1286                    safe_rename("$fsDir/$FN","$fsDir/$NEWNAME");
1287                    safe_rename("$fsDir/.log/$FN","$fsDir/.log/$NEWNAME");
1288                    safe_rename("$fsDir/.note/$FN","$fsDir/.note/$NEWNAME");
1289                    safe_rename("$fsDir/.lock/$FN","$fsDir/.lock/$NEWNAME");
1290    
1291                    break ;
1292    
1293            case "NOTE" :  
1294                    WriteNote("$fsDir/$FN","$NOTE");
1295                    break ;
1296    
1297            case "UNLOCK" :  
1298                    if ( $CONFIRM != "on" ) break ;
1299                    Unlock("$fsDir/$FN");
1300                    break ;
1301    
1302          default :          default :
1303                  // user hit "CANCEL" or undefined action                  // user hit "CANCEL" or undefined action
1304          }          }
# Line 914  the source<BR>of this file.<BR><BR> Line 1314  the source<BR>of this file.<BR><BR>
1314          // $A=U : upload to path given in $D          // $A=U : upload to path given in $D
1315          // $A=E : display detail of file $D/$F and edit          // $A=E : display detail of file $D/$F and edit
1316          // $A=C : display code in file $D/$F          // $A=C : display code in file $D/$F
1317            // $A=Co : checkout file $D/$F
1318            // $A=Ci : checkin file $D/$F
1319            // $A=V : view file (do nothing except log)
1320          // default : display directory $D          // default : display directory $D
1321                    
1322          switch ($A) {          switch ($A) {
1323          case "U" :          case "U" :
1324                  // upload to $relDir                  // upload to $relDir
1325                  if (!Writeable($gblFsRoot . $relDir))                  if (!is_writeable($gblFsRoot . $relDir))
1326                          Error("Write access denied",$relDir) ;                          Error("Write access denied",$relDir) ;
1327                  $text  = "Use this page to upload a single " ;                  $text  = "Use this page to upload a single " ;
1328                  $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 1332  the source<BR>of this file.<BR><BR>
1332                  exit ;                  exit ;
1333          case "E" :          case "E" :
1334                  // detail of $relDir/$F                  // detail of $relDir/$F
1335                  DetailPage($gblFsRoot, $relDir, $F) ;                  if (is_file("$gblFsRoot/$relDir/$F")) DetailPage($gblFsRoot, $relDir, $F) ;
1336                  exit ;                  exit ;
1337          case "C" :          case "C" :
1338                  // listing of $relDir/$F                  // listing of $relDir/$F
1339                  DisplayCode($gblFsRoot, $relDir, $F) ;                  DisplayCode($gblFsRoot, $relDir, $F) ;
1340                  exit ;                  exit ;
1341            case "Co" :
1342                    // checkout
1343                    Lock("$gblFsRoot/$relDir/$F");
1344                    Header("Location: ".urlpath("$relDir/$F"));
1345                    exit;
1346            case "Ci" :
1347                    // upload && update to $relDir
1348                    if (!is_writeable($gblFsRoot . $relDir))
1349                            Error("Write access denied",$relDir) ;
1350                    $text  = "Use this page to update a single " ;
1351                    $text .= "file to <B>$SERVER_NAME</B>." ;
1352                    StartHTML("(Update file Page)", $text) ;
1353                    UploadPage($gblFsRoot, $relDir, $F) ;
1354                    EndHTML() ;
1355                    exit ;
1356            case "V" :
1357                    // view
1358                    LogIt("$gblFsRoot/$relDir/$F","viewed");
1359                    Header("Location: ".urlpath("$relDir/$F"));
1360                    exit;
1361          }          }
1362    
1363          // default: display directory $relDir          // default: display directory $relDir

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

  ViewVC Help
Powered by ViewVC 1.1.26